1 // rs_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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
15 #include "rs_actiondimangular.h"
17 #include "rs_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_information.h"
20 #include "rs_preview.h"
22 RS_ActionDimAngular::RS_ActionDimAngular(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw Angular Dimensions",
23 container, graphicView)
28 RS_ActionDimAngular::~RS_ActionDimAngular()
32 /*virtual*/ RS2::ActionType RS_ActionDimAngular::rtti()
34 return RS2::ActionDimAngular;
37 void RS_ActionDimAngular::reset()
39 RS_ActionDimension::reset();
40 edata = RS_DimAngularData(Vector(false), Vector(false), Vector(false), Vector(false));
43 center = Vector(false);
44 RS_DIALOGFACTORY->requestOptions(this, true, true);
47 void RS_ActionDimAngular::trigger()
49 RS_PreviewActionInterface::trigger();
51 if (line1 != NULL && line2 != NULL)
53 RS_DimAngular * newEntity = NULL;
55 newEntity = new RS_DimAngular(container,
59 newEntity->setLayerToActive();
60 newEntity->setPenToActive();
62 container->addEntity(newEntity);
67 document->startUndoCycle();
68 document->addUndoable(newEntity);
69 document->endUndoCycle();
72 Vector rz = graphicView->getRelativeZero();
73 graphicView->moveRelativeZero(Vector(0.0, 0.0));
74 graphicView->drawEntity(newEntity);
75 graphicView->moveRelativeZero(rz);
78 RS_DEBUG->print("RS_ActionDimAngular::trigger:"
82 void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent * e)
84 RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin");
86 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
98 if (line1 != NULL && line2 != NULL && center.valid)
100 Vector mouse = snapPoint(e);
101 edata.definitionPoint4 = mouse;
103 RS_DimAngular * d = new RS_DimAngular(preview, data, edata);
108 preview->addEntity(d);
117 RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end");
120 void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent * e)
122 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
127 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
130 && en->rtti() == RS2::EntityLine)
132 line1 = (RS_Line *)en;
139 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
142 && en->rtti() == RS2::EntityLine)
144 line2 = (RS_Line *)en;
146 VectorSolutions sol =
147 RS_Information::getIntersectionLineLine(line1, line2);
149 if (sol.get(0).valid)
153 if (center.distanceTo(line1->getStartpoint())
154 < center.distanceTo(line1->getEndpoint()))
156 edata.definitionPoint1 = line1->getStartpoint();
157 edata.definitionPoint2 = line1->getEndpoint();
161 edata.definitionPoint1 = line1->getEndpoint();
162 edata.definitionPoint2 = line1->getStartpoint();
165 if (center.distanceTo(line2->getStartpoint())
166 < center.distanceTo(line2->getEndpoint()))
168 edata.definitionPoint3 = line2->getStartpoint();
169 data.definitionPoint = line2->getEndpoint();
173 edata.definitionPoint3 = line2->getEndpoint();
174 data.definitionPoint = line2->getStartpoint();
176 graphicView->moveRelativeZero(center);
184 Vector ce(snapPoint(e));
185 coordinateEvent(&ce);
190 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
195 init(getStatus() - 1);
199 void RS_ActionDimAngular::coordinateEvent(Vector * e)
207 edata.definitionPoint4 = *e;
218 void RS_ActionDimAngular::commandEvent(RS_CommandEvent * e)
220 QString c = e->getCommand().toLower();
222 if (checkCommand("help", c))
224 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
225 + getAvailableCommands().join(", "));
229 // setting new text label:
230 if (getStatus() == SetText)
233 RS_DIALOGFACTORY->requestOptions(this, true, true);
234 graphicView->enableCoordinateInput();
235 setStatus(lastStatus);
240 if (checkCommand("text", c))
242 lastStatus = (Status)getStatus();
243 graphicView->disableCoordinateInput();
248 QStringList RS_ActionDimAngular::getAvailableCommands()
257 cmd += command("text");
267 void RS_ActionDimAngular::showOptions()
269 RS_ActionInterface::showOptions();
271 RS_DIALOGFACTORY->requestOptions(this, true);
274 void RS_ActionDimAngular::hideOptions()
276 RS_ActionInterface::hideOptions();
278 RS_DIALOGFACTORY->requestOptions(this, false);
281 void RS_ActionDimAngular::updateMouseButtonHints()
286 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
291 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
296 RS_DIALOGFACTORY->updateMouseWidget(
297 tr("Specify dimension arc line location"), tr("Cancel"));
301 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
305 RS_DIALOGFACTORY->updateMouseWidget("", "");