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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
15 #include "actiondimdiametric.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 ActionDimDiametric::ActionDimDiametric(RS_EntityContainer & container,
23 GraphicView & graphicView): ActionDimension("Draw Diametric Dimensions",
24 container, graphicView)
29 ActionDimDiametric::~ActionDimDiametric()
33 /*virtual*/ RS2::ActionType ActionDimDiametric::rtti()
35 return RS2::ActionDimDiametric;
38 void ActionDimDiametric::reset()
40 ActionDimension::reset();
41 edata = RS_DimDiametricData(Vector(false), 0.0);
44 RS_DIALOGFACTORY->requestOptions(this, true, true);
47 void ActionDimDiametric::trigger()
49 ActionInterface::trigger();
54 RS_DimDiametric * newEntity = NULL;
56 newEntity = new RS_DimDiametric(container,
60 newEntity->setLayerToActive();
61 newEntity->setPenToActive();
63 container->addEntity(newEntity);
68 document->startUndoCycle();
69 document->addUndoable(newEntity);
70 document->endUndoCycle();
74 Vector rz = graphicView->getRelativeZero();
75 graphicView->moveRelativeZero(Vector(0.0, 0.0));
76 graphicView->drawEntity(newEntity);
77 graphicView->moveRelativeZero(rz);
80 RS_DEBUG->print("ActionDimDiametric::trigger: Entity is NULL\n");
83 void ActionDimDiametric::preparePreview()
88 Vector center = Vector(false);
90 if (entity->rtti() == RS2::EntityArc)
92 radius = ((RS_Arc *)entity)->getRadius();
93 center = ((RS_Arc *)entity)->getCenter();
95 else if (entity->rtti() == RS2::EntityCircle)
97 radius = ((RS_Circle *)entity)->getRadius();
98 center = ((RS_Circle *)entity)->getCenter();
100 double angle = center.angleTo(pos);
102 data.definitionPoint.setPolar(radius, angle + M_PI);
103 data.definitionPoint += center;
105 edata.definitionPoint.setPolar(radius, angle);
106 edata.definitionPoint += center;
110 void ActionDimDiametric::mouseMoveEvent(QMouseEvent * e)
112 RS_DEBUG->print("ActionDimDiametric::mouseMoveEvent begin");
114 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
119 entity = catchEntity(e, RS2::ResolveAll);
129 // RS_DimDiametric * d = new RS_DimDiametric(preview, data, edata);
134 // preview->addEntity(d);
143 RS_DEBUG->print("ActionDimDiametric::mouseMoveEvent end");
146 void ActionDimDiametric::mouseReleaseEvent(QMouseEvent * e)
148 if (e->button() == Qt::LeftButton)
153 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
157 if (en->rtti() == RS2::EntityArc
158 || en->rtti() == RS2::EntityCircle)
163 if (entity->rtti() == RS2::EntityArc)
165 ((RS_Arc *)entity)->getCenter();
166 else if (entity->rtti() == RS2::EntityCircle)
168 ((RS_Circle *)entity)->getCenter();
169 graphicView->moveRelativeZero(center);
173 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
180 Vector ce(snapPoint(e));
181 coordinateEvent(&ce);
189 else if (e->button() == Qt::RightButton)
194 init(getStatus() - 1);
198 void ActionDimDiametric::coordinateEvent(Vector * e)
209 setStatus(SetEntity);
217 void ActionDimDiametric::commandEvent(RS_CommandEvent * e)
219 QString c = e->getCommand().toLower();
221 if (checkCommand("help", c))
223 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
224 + getAvailableCommands().join(", "));
228 // setting new text label:
229 if (getStatus() == SetText)
232 RS_DIALOGFACTORY->requestOptions(this, true, true);
233 graphicView->enableCoordinateInput();
234 setStatus(lastStatus);
239 if (checkCommand("text", c))
241 lastStatus = (Status)getStatus();
242 graphicView->disableCoordinateInput();
247 if (getStatus() == SetPos)
250 double a = RS_Math::eval(c, &ok);
254 pos.setPolar(1.0, RS_Math::deg2rad(a));
255 pos += data.definitionPoint;
258 setStatus(SetEntity);
261 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
266 QStringList ActionDimDiametric::getAvailableCommands()
274 cmd += command("text");
284 void ActionDimDiametric::updateMouseButtonHints()
289 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
294 RS_DIALOGFACTORY->updateMouseWidget(
295 tr("Specify dimension line location"), tr("Cancel"));
299 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
303 RS_DIALOGFACTORY->updateMouseWidget("", "");
308 void ActionDimDiametric::showOptions()
310 ActionInterface::showOptions();
312 RS_DIALOGFACTORY->requestOptions(this, true);
315 void ActionDimDiametric::hideOptions()
317 ActionInterface::hideOptions();
319 //RS_DIALOGFACTORY->requestDimDiametricOptions(edata, false);
320 RS_DIALOGFACTORY->requestOptions(this, false);