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 "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
23 #include "information.h"
26 ActionDimAngular::ActionDimAngular(EntityContainer & container, GraphicView & graphicView): ActionDimension("Draw Angular Dimensions",
27 container, graphicView)
32 ActionDimAngular::~ActionDimAngular()
36 /*virtual*/ RS2::ActionType ActionDimAngular::rtti()
38 return RS2::ActionDimAngular;
41 void ActionDimAngular::reset()
43 ActionDimension::reset();
44 edata = DimAngularData(Vector(false), Vector(false), Vector(false), Vector(false));
47 center = Vector(false);
48 DIALOGFACTORY->requestOptions(this, true, true);
51 void ActionDimAngular::trigger()
53 ActionInterface::trigger();
55 if (line1 != NULL && line2 != NULL)
57 DimAngular * newEntity = NULL;
59 newEntity = new DimAngular(container,
63 newEntity->setLayerToActive();
64 newEntity->setPenToActive();
66 container->addEntity(newEntity);
71 document->startUndoCycle();
72 document->addUndoable(newEntity);
73 document->endUndoCycle();
76 Vector rz = graphicView->getRelativeZero();
77 graphicView->moveRelativeZero(Vector(0.0, 0.0));
78 graphicView->drawEntity(newEntity);
79 graphicView->moveRelativeZero(rz);
82 DEBUG->print("ActionDimAngular::trigger:"
86 void ActionDimAngular::mouseMoveEvent(QMouseEvent * e)
88 DEBUG->print("ActionDimAngular::mouseMoveEvent begin");
90 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
102 if (line1 && line2 && center.valid)
104 Vector mouse = snapPoint(e);
105 edata.definitionPoint4 = mouse;
107 // DimAngular * d = new DimAngular(preview, data, edata);
112 // preview->addEntity(d);
121 DEBUG->print("ActionDimAngular::mouseMoveEvent end");
124 void ActionDimAngular::mouseReleaseEvent(QMouseEvent * e)
126 if (e->button() == Qt::LeftButton)
132 Entity * en = catchEntity(e, RS2::ResolveAll);
135 && en->rtti() == RS2::EntityLine)
145 Entity * en = catchEntity(e, RS2::ResolveAll);
148 && en->rtti() == RS2::EntityLine)
152 VectorSolutions sol =
153 Information::getIntersectionLineLine(line1, line2);
155 if (sol.get(0).valid)
159 if (center.distanceTo(line1->getStartpoint())
160 < center.distanceTo(line1->getEndpoint()))
162 edata.definitionPoint1 = line1->getStartpoint();
163 edata.definitionPoint2 = line1->getEndpoint();
167 edata.definitionPoint1 = line1->getEndpoint();
168 edata.definitionPoint2 = line1->getStartpoint();
171 if (center.distanceTo(line2->getStartpoint())
172 < center.distanceTo(line2->getEndpoint()))
174 edata.definitionPoint3 = line2->getStartpoint();
175 data.definitionPoint = line2->getEndpoint();
179 edata.definitionPoint3 = line2->getEndpoint();
180 data.definitionPoint = line2->getStartpoint();
182 graphicView->moveRelativeZero(center);
191 Vector ce(snapPoint(e));
192 coordinateEvent(&ce);
197 else if (e->button() == Qt::RightButton)
202 init(getStatus() - 1);
206 void ActionDimAngular::coordinateEvent(Vector * e)
214 edata.definitionPoint4 = *e;
225 void ActionDimAngular::commandEvent(CommandEvent * e)
227 QString c = e->getCommand().toLower();
229 if (checkCommand("help", c))
231 DIALOGFACTORY->commandMessage(msgAvailableCommands()
232 + getAvailableCommands().join(", "));
236 // setting new text label:
237 if (getStatus() == SetText)
240 DIALOGFACTORY->requestOptions(this, true, true);
241 graphicView->enableCoordinateInput();
242 setStatus(lastStatus);
247 if (checkCommand("text", c))
249 lastStatus = (Status)getStatus();
250 graphicView->disableCoordinateInput();
255 QStringList ActionDimAngular::getAvailableCommands()
264 cmd += command("text");
274 void ActionDimAngular::showOptions()
276 ActionInterface::showOptions();
278 DIALOGFACTORY->requestOptions(this, true);
281 void ActionDimAngular::hideOptions()
283 ActionInterface::hideOptions();
285 DIALOGFACTORY->requestOptions(this, false);
288 void ActionDimAngular::updateMouseButtonHints()
293 DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
298 DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
303 DIALOGFACTORY->updateMouseWidget(
304 tr("Specify dimension arc line location"), tr("Cancel"));
308 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
312 DIALOGFACTORY->updateMouseWidget("", "");