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_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_information.h"
21 #include "rs_preview.h"
23 RS_ActionDimAngular::RS_ActionDimAngular(RS_EntityContainer & container, GraphicView & graphicView): RS_ActionDimension("Draw Angular Dimensions",
24 container, graphicView)
29 RS_ActionDimAngular::~RS_ActionDimAngular()
33 /*virtual*/ RS2::ActionType RS_ActionDimAngular::rtti()
35 return RS2::ActionDimAngular;
38 void RS_ActionDimAngular::reset()
40 RS_ActionDimension::reset();
41 edata = RS_DimAngularData(Vector(false), Vector(false), Vector(false), Vector(false));
44 center = Vector(false);
45 RS_DIALOGFACTORY->requestOptions(this, true, true);
48 void RS_ActionDimAngular::trigger()
50 RS_PreviewActionInterface::trigger();
52 if (line1 != NULL && line2 != NULL)
54 RS_DimAngular * newEntity = NULL;
56 newEntity = new RS_DimAngular(container,
60 newEntity->setLayerToActive();
61 newEntity->setPenToActive();
63 container->addEntity(newEntity);
68 document->startUndoCycle();
69 document->addUndoable(newEntity);
70 document->endUndoCycle();
73 Vector rz = graphicView->getRelativeZero();
74 graphicView->moveRelativeZero(Vector(0.0, 0.0));
75 graphicView->drawEntity(newEntity);
76 graphicView->moveRelativeZero(rz);
79 RS_DEBUG->print("RS_ActionDimAngular::trigger:"
83 void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent * e)
85 RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin");
87 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
99 if (line1 != NULL && line2 != NULL && center.valid)
101 Vector mouse = snapPoint(e);
102 edata.definitionPoint4 = mouse;
104 RS_DimAngular * d = new RS_DimAngular(preview, data, edata);
109 preview->addEntity(d);
118 RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end");
121 void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent * e)
123 if (e->button() == Qt::LeftButton)
128 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
131 && en->rtti() == RS2::EntityLine)
133 line1 = (RS_Line *)en;
140 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
143 && en->rtti() == RS2::EntityLine)
145 line2 = (RS_Line *)en;
147 VectorSolutions sol =
148 RS_Information::getIntersectionLineLine(line1, line2);
150 if (sol.get(0).valid)
154 if (center.distanceTo(line1->getStartpoint())
155 < center.distanceTo(line1->getEndpoint()))
157 edata.definitionPoint1 = line1->getStartpoint();
158 edata.definitionPoint2 = line1->getEndpoint();
162 edata.definitionPoint1 = line1->getEndpoint();
163 edata.definitionPoint2 = line1->getStartpoint();
166 if (center.distanceTo(line2->getStartpoint())
167 < center.distanceTo(line2->getEndpoint()))
169 edata.definitionPoint3 = line2->getStartpoint();
170 data.definitionPoint = line2->getEndpoint();
174 edata.definitionPoint3 = line2->getEndpoint();
175 data.definitionPoint = line2->getStartpoint();
177 graphicView->moveRelativeZero(center);
185 Vector ce(snapPoint(e));
186 coordinateEvent(&ce);
191 else if (e->button() == Qt::RightButton)
196 init(getStatus() - 1);
200 void RS_ActionDimAngular::coordinateEvent(Vector * e)
208 edata.definitionPoint4 = *e;
219 void RS_ActionDimAngular::commandEvent(RS_CommandEvent * e)
221 QString c = e->getCommand().toLower();
223 if (checkCommand("help", c))
225 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
226 + getAvailableCommands().join(", "));
230 // setting new text label:
231 if (getStatus() == SetText)
234 RS_DIALOGFACTORY->requestOptions(this, true, true);
235 graphicView->enableCoordinateInput();
236 setStatus(lastStatus);
241 if (checkCommand("text", c))
243 lastStatus = (Status)getStatus();
244 graphicView->disableCoordinateInput();
249 QStringList RS_ActionDimAngular::getAvailableCommands()
258 cmd += command("text");
268 void RS_ActionDimAngular::showOptions()
270 RS_ActionInterface::showOptions();
272 RS_DIALOGFACTORY->requestOptions(this, true);
275 void RS_ActionDimAngular::hideOptions()
277 RS_ActionInterface::hideOptions();
279 RS_DIALOGFACTORY->requestOptions(this, false);
282 void RS_ActionDimAngular::updateMouseButtonHints()
287 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
292 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
297 RS_DIALOGFACTORY->updateMouseWidget(
298 tr("Specify dimension arc line location"), tr("Cancel"));
302 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
306 RS_DIALOGFACTORY->updateMouseWidget("", "");