1 // rs_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 "rs_actiondimdiametric.h"
17 #include "rs_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDimDiametric::RS_ActionDimDiametric(RS_EntityContainer & container, GraphicView & graphicView): RS_ActionDimension("Draw Diametric Dimensions",
23 container, graphicView)
28 RS_ActionDimDiametric::~RS_ActionDimDiametric()
32 /*virtual*/ RS2::ActionType RS_ActionDimDiametric::rtti()
34 return RS2::ActionDimDiametric;
37 void RS_ActionDimDiametric::reset()
39 RS_ActionDimension::reset();
40 edata = RS_DimDiametricData(Vector(false), 0.0);
43 RS_DIALOGFACTORY->requestOptions(this, true, true);
46 void RS_ActionDimDiametric::trigger()
48 RS_PreviewActionInterface::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();
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_ActionDimDiametric::trigger:"
83 void RS_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 RS_ActionDimDiametric::mouseMoveEvent(QMouseEvent * e)
112 RS_DEBUG->print("RS_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("RS_ActionDimDiametric::mouseMoveEvent end");
146 void RS_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 RS_ActionDimDiametric::coordinateEvent(Vector * e)
209 setStatus(SetEntity);
217 void RS_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 RS_ActionDimDiametric::getAvailableCommands()
274 cmd += command("text");
284 void RS_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 RS_ActionDimDiametric::showOptions()
310 RS_ActionInterface::showOptions();
312 RS_DIALOGFACTORY->requestOptions(this, true);
315 void RS_ActionDimDiametric::hideOptions()
317 RS_ActionInterface::hideOptions();
319 //RS_DIALOGFACTORY->requestDimDiametricOptions(edata, false);
320 RS_DIALOGFACTORY->requestOptions(this, false);