1 // actiondimangular.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/03/2010 Added this text. :-)
17 #include "actiondimangular.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_information.h"
23 #include "rs_preview.h"
25 ActionDimAngular::ActionDimAngular(RS_EntityContainer & container, GraphicView & graphicView): ActionDimension("Draw Angular Dimensions",
26 container, graphicView)
31 ActionDimAngular::~ActionDimAngular()
35 /*virtual*/ RS2::ActionType ActionDimAngular::rtti()
37 return RS2::ActionDimAngular;
40 void ActionDimAngular::reset()
42 ActionDimension::reset();
43 edata = RS_DimAngularData(Vector(false), Vector(false), Vector(false), Vector(false));
46 center = Vector(false);
47 RS_DIALOGFACTORY->requestOptions(this, true, true);
50 void ActionDimAngular::trigger()
52 ActionInterface::trigger();
54 if (line1 != NULL && line2 != NULL)
56 RS_DimAngular * newEntity = NULL;
58 newEntity = new RS_DimAngular(container,
62 newEntity->setLayerToActive();
63 newEntity->setPenToActive();
65 container->addEntity(newEntity);
70 document->startUndoCycle();
71 document->addUndoable(newEntity);
72 document->endUndoCycle();
75 Vector rz = graphicView->getRelativeZero();
76 graphicView->moveRelativeZero(Vector(0.0, 0.0));
77 graphicView->drawEntity(newEntity);
78 graphicView->moveRelativeZero(rz);
81 RS_DEBUG->print("ActionDimAngular::trigger:"
85 void ActionDimAngular::mouseMoveEvent(QMouseEvent * e)
87 RS_DEBUG->print("ActionDimAngular::mouseMoveEvent begin");
89 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
101 if (line1 && line2 && center.valid)
103 Vector mouse = snapPoint(e);
104 edata.definitionPoint4 = mouse;
106 // RS_DimAngular * d = new RS_DimAngular(preview, data, edata);
111 // preview->addEntity(d);
120 RS_DEBUG->print("ActionDimAngular::mouseMoveEvent end");
123 void ActionDimAngular::mouseReleaseEvent(QMouseEvent * e)
125 if (e->button() == Qt::LeftButton)
131 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
134 && en->rtti() == RS2::EntityLine)
136 line1 = (RS_Line *)en;
144 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
147 && en->rtti() == RS2::EntityLine)
149 line2 = (RS_Line *)en;
151 VectorSolutions sol =
152 RS_Information::getIntersectionLineLine(line1, line2);
154 if (sol.get(0).valid)
158 if (center.distanceTo(line1->getStartpoint())
159 < center.distanceTo(line1->getEndpoint()))
161 edata.definitionPoint1 = line1->getStartpoint();
162 edata.definitionPoint2 = line1->getEndpoint();
166 edata.definitionPoint1 = line1->getEndpoint();
167 edata.definitionPoint2 = line1->getStartpoint();
170 if (center.distanceTo(line2->getStartpoint())
171 < center.distanceTo(line2->getEndpoint()))
173 edata.definitionPoint3 = line2->getStartpoint();
174 data.definitionPoint = line2->getEndpoint();
178 edata.definitionPoint3 = line2->getEndpoint();
179 data.definitionPoint = line2->getStartpoint();
181 graphicView->moveRelativeZero(center);
190 Vector ce(snapPoint(e));
191 coordinateEvent(&ce);
196 else if (e->button() == Qt::RightButton)
201 init(getStatus() - 1);
205 void ActionDimAngular::coordinateEvent(Vector * e)
213 edata.definitionPoint4 = *e;
224 void ActionDimAngular::commandEvent(RS_CommandEvent * e)
226 QString c = e->getCommand().toLower();
228 if (checkCommand("help", c))
230 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
231 + getAvailableCommands().join(", "));
235 // setting new text label:
236 if (getStatus() == SetText)
239 RS_DIALOGFACTORY->requestOptions(this, true, true);
240 graphicView->enableCoordinateInput();
241 setStatus(lastStatus);
246 if (checkCommand("text", c))
248 lastStatus = (Status)getStatus();
249 graphicView->disableCoordinateInput();
254 QStringList ActionDimAngular::getAvailableCommands()
263 cmd += command("text");
273 void ActionDimAngular::showOptions()
275 ActionInterface::showOptions();
277 RS_DIALOGFACTORY->requestOptions(this, true);
280 void ActionDimAngular::hideOptions()
282 ActionInterface::hideOptions();
284 RS_DIALOGFACTORY->requestOptions(this, false);
287 void ActionDimAngular::updateMouseButtonHints()
292 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
297 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
302 RS_DIALOGFACTORY->updateMouseWidget(
303 tr("Specify dimension arc line location"), tr("Cancel"));
307 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
311 RS_DIALOGFACTORY->updateMouseWidget("", "");