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_graphicview.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_preview.h"
21 RS_ActionDimDiametric::RS_ActionDimDiametric(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw Diametric Dimensions",
22 container, graphicView)
27 RS_ActionDimDiametric::~RS_ActionDimDiametric()
31 /*virtual*/ RS2::ActionType RS_ActionDimDiametric::rtti()
33 return RS2::ActionDimDiametric;
36 void RS_ActionDimDiametric::reset()
38 RS_ActionDimension::reset();
39 edata = RS_DimDiametricData(Vector(false), 0.0);
42 RS_DIALOGFACTORY->requestOptions(this, true, true);
45 void RS_ActionDimDiametric::trigger()
47 RS_PreviewActionInterface::trigger();
53 RS_DimDiametric * newEntity = NULL;
55 newEntity = new RS_DimDiametric(container,
59 newEntity->setLayerToActive();
60 newEntity->setPenToActive();
62 container->addEntity(newEntity);
67 document->startUndoCycle();
68 document->addUndoable(newEntity);
69 document->endUndoCycle();
72 Vector rz = graphicView->getRelativeZero();
73 graphicView->moveRelativeZero(Vector(0.0, 0.0));
74 graphicView->drawEntity(newEntity);
75 graphicView->moveRelativeZero(rz);
78 RS_DEBUG->print("RS_ActionDimDiametric::trigger:"
82 void RS_ActionDimDiametric::preparePreview()
87 Vector center = Vector(false);
89 if (entity->rtti() == RS2::EntityArc)
91 radius = ((RS_Arc *)entity)->getRadius();
92 center = ((RS_Arc *)entity)->getCenter();
94 else if (entity->rtti() == RS2::EntityCircle)
96 radius = ((RS_Circle *)entity)->getRadius();
97 center = ((RS_Circle *)entity)->getCenter();
99 double angle = center.angleTo(pos);
101 data.definitionPoint.setPolar(radius, angle + M_PI);
102 data.definitionPoint += center;
104 edata.definitionPoint.setPolar(radius, angle);
105 edata.definitionPoint += center;
109 void RS_ActionDimDiametric::mouseMoveEvent(QMouseEvent * e)
111 RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent begin");
113 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
118 entity = catchEntity(e, RS2::ResolveAll);
128 RS_DimDiametric * d = new RS_DimDiametric(preview, data, edata);
133 preview->addEntity(d);
142 RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent end");
145 void RS_ActionDimDiametric::mouseReleaseEvent(QMouseEvent * e)
147 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
152 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
156 if (en->rtti() == RS2::EntityArc
157 || en->rtti() == RS2::EntityCircle)
162 if (entity->rtti() == RS2::EntityArc)
164 ((RS_Arc *)entity)->getCenter();
165 else if (entity->rtti() == RS2::EntityCircle)
167 ((RS_Circle *)entity)->getCenter();
168 graphicView->moveRelativeZero(center);
172 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
179 Vector ce(snapPoint(e));
180 coordinateEvent(&ce);
188 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
193 init(getStatus() - 1);
197 void RS_ActionDimDiametric::coordinateEvent(Vector * e)
208 setStatus(SetEntity);
216 void RS_ActionDimDiametric::commandEvent(RS_CommandEvent * e)
218 QString c = e->getCommand().toLower();
220 if (checkCommand("help", c))
222 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
223 + getAvailableCommands().join(", "));
227 // setting new text label:
228 if (getStatus() == SetText)
231 RS_DIALOGFACTORY->requestOptions(this, true, true);
232 graphicView->enableCoordinateInput();
233 setStatus(lastStatus);
238 if (checkCommand("text", c))
240 lastStatus = (Status)getStatus();
241 graphicView->disableCoordinateInput();
246 if (getStatus() == SetPos)
249 double a = RS_Math::eval(c, &ok);
253 pos.setPolar(1.0, RS_Math::deg2rad(a));
254 pos += data.definitionPoint;
257 setStatus(SetEntity);
260 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
265 QStringList RS_ActionDimDiametric::getAvailableCommands()
273 cmd += command("text");
283 void RS_ActionDimDiametric::updateMouseButtonHints()
288 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
293 RS_DIALOGFACTORY->updateMouseWidget(
294 tr("Specify dimension line location"), tr("Cancel"));
298 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
302 RS_DIALOGFACTORY->updateMouseWidget("", "");
307 void RS_ActionDimDiametric::showOptions()
309 RS_ActionInterface::showOptions();
311 RS_DIALOGFACTORY->requestOptions(this, true);
314 void RS_ActionDimDiametric::hideOptions()
316 RS_ActionInterface::hideOptions();
318 //RS_DIALOGFACTORY->requestDimDiametricOptions(edata, false);
319 RS_DIALOGFACTORY->requestOptions(this, false);