1 // actiondimdiametric.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 "actiondimdiametric.h"
19 #include "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
25 ActionDimDiametric::ActionDimDiametric(EntityContainer & container,
26 GraphicView & graphicView): ActionDimension("Draw Diametric Dimensions",
27 container, graphicView)
32 ActionDimDiametric::~ActionDimDiametric()
36 /*virtual*/ RS2::ActionType ActionDimDiametric::rtti()
38 return RS2::ActionDimDiametric;
41 void ActionDimDiametric::reset()
43 ActionDimension::reset();
44 edata = DimDiametricData(Vector(false), 0.0);
47 DIALOGFACTORY->requestOptions(this, true, true);
50 void ActionDimDiametric::trigger()
52 ActionInterface::trigger();
57 DimDiametric * newEntity = NULL;
59 newEntity = new DimDiametric(container,
63 newEntity->setLayerToActive();
64 newEntity->setPenToActive();
66 container->addEntity(newEntity);
71 document->startUndoCycle();
72 document->addUndoable(newEntity);
73 document->endUndoCycle();
77 Vector rz = graphicView->getRelativeZero();
78 graphicView->moveRelativeZero(Vector(0.0, 0.0));
79 graphicView->drawEntity(newEntity);
80 graphicView->moveRelativeZero(rz);
83 DEBUG->print("ActionDimDiametric::trigger: Entity is NULL\n");
86 void ActionDimDiametric::preparePreview()
91 Vector center = Vector(false);
93 if (entity->rtti() == RS2::EntityArc)
95 radius = ((Arc *)entity)->getRadius();
96 center = ((Arc *)entity)->getCenter();
98 else if (entity->rtti() == RS2::EntityCircle)
100 radius = ((Circle *)entity)->getRadius();
101 center = ((Circle *)entity)->getCenter();
103 double angle = center.angleTo(pos);
105 data.definitionPoint.setPolar(radius, angle + M_PI);
106 data.definitionPoint += center;
108 edata.definitionPoint.setPolar(radius, angle);
109 edata.definitionPoint += center;
113 void ActionDimDiametric::mouseMoveEvent(QMouseEvent * e)
115 DEBUG->print("ActionDimDiametric::mouseMoveEvent begin");
117 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
122 entity = catchEntity(e, RS2::ResolveAll);
132 // DimDiametric * d = new DimDiametric(preview, data, edata);
137 // preview->addEntity(d);
146 DEBUG->print("ActionDimDiametric::mouseMoveEvent end");
149 void ActionDimDiametric::mouseReleaseEvent(QMouseEvent * e)
151 if (e->button() == Qt::LeftButton)
156 Entity * en = catchEntity(e, RS2::ResolveAll);
160 if (en->rtti() == RS2::EntityArc
161 || en->rtti() == RS2::EntityCircle)
166 if (entity->rtti() == RS2::EntityArc)
168 ((Arc *)entity)->getCenter();
169 else if (entity->rtti() == RS2::EntityCircle)
171 ((Circle *)entity)->getCenter();
172 graphicView->moveRelativeZero(center);
176 DIALOGFACTORY->commandMessage(tr("Not a circle "
183 Vector ce(snapPoint(e));
184 coordinateEvent(&ce);
192 else if (e->button() == Qt::RightButton)
197 init(getStatus() - 1);
201 void ActionDimDiametric::coordinateEvent(Vector * e)
212 setStatus(SetEntity);
220 void ActionDimDiametric::commandEvent(CommandEvent * e)
222 QString c = e->getCommand().toLower();
224 if (checkCommand("help", c))
226 DIALOGFACTORY->commandMessage(msgAvailableCommands()
227 + getAvailableCommands().join(", "));
231 // setting new text label:
232 if (getStatus() == SetText)
235 DIALOGFACTORY->requestOptions(this, true, true);
236 graphicView->enableCoordinateInput();
237 setStatus(lastStatus);
242 if (checkCommand("text", c))
244 lastStatus = (Status)getStatus();
245 graphicView->disableCoordinateInput();
250 if (getStatus() == SetPos)
253 double a = Math::eval(c, &ok);
257 pos.setPolar(1.0, Math::deg2rad(a));
258 pos += data.definitionPoint;
261 setStatus(SetEntity);
264 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
269 QStringList ActionDimDiametric::getAvailableCommands()
277 cmd += command("text");
287 void ActionDimDiametric::updateMouseButtonHints()
292 DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
297 DIALOGFACTORY->updateMouseWidget(
298 tr("Specify dimension line location"), tr("Cancel"));
302 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
306 DIALOGFACTORY->updateMouseWidget("", "");
311 void ActionDimDiametric::showOptions()
313 ActionInterface::showOptions();
315 DIALOGFACTORY->requestOptions(this, true);
318 void ActionDimDiametric::hideOptions()
320 ActionInterface::hideOptions();
322 //DIALOGFACTORY->requestDimDiametricOptions(edata, false);
323 DIALOGFACTORY->requestOptions(this, false);