1 // rs_actiondimradial.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_actiondimradial.h"
17 #include "rs_dialogfactory.h"
18 #include "rs_graphicview.h"
19 #include "rs_preview.h"
21 RS_ActionDimRadial::RS_ActionDimRadial(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw Radial Dimensions",
22 container, graphicView)
27 RS_ActionDimRadial::~RS_ActionDimRadial()
31 /*virtual*/ RS2::ActionType RS_ActionDimRadial::rtti()
33 return RS2::ActionDimRadial;
36 void RS_ActionDimRadial::reset()
38 RS_ActionDimension::reset();
40 edata = RS_DimRadialData(Vector(false),
44 RS_DIALOGFACTORY->requestOptions(this, true, true);
47 void RS_ActionDimRadial::trigger()
49 RS_ActionDimension::trigger();
55 RS_DimRadial * newEntity = NULL;
57 newEntity = new RS_DimRadial(container,
61 newEntity->setLayerToActive();
62 newEntity->setPenToActive();
64 container->addEntity(newEntity);
69 document->startUndoCycle();
70 document->addUndoable(newEntity);
71 document->endUndoCycle();
74 Vector rz = graphicView->getRelativeZero();
75 graphicView->moveRelativeZero(Vector(0.0, 0.0));
76 graphicView->drawEntity(newEntity);
77 graphicView->moveRelativeZero(rz);
81 RS_DEBUG->print("RS_ActionDimRadial::trigger:"
85 void RS_ActionDimRadial::preparePreview()
89 double angle = data.definitionPoint.angleTo(pos);
92 if (entity->rtti() == RS2::EntityArc)
93 radius = ((RS_Arc *)entity)->getRadius();
94 else if (entity->rtti() == RS2::EntityCircle)
95 radius = ((RS_Circle *)entity)->getRadius();
97 edata.definitionPoint.setPolar(radius, angle);
98 edata.definitionPoint += data.definitionPoint;
102 void RS_ActionDimRadial::mouseMoveEvent(QMouseEvent * e)
104 RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent begin");
106 //Vector mouse(graphicView->toGraphX(e->x()),
107 // graphicView->toGraphY(e->y()));
112 entity = catchEntity(e, RS2::ResolveAll);
123 RS_DimRadial * d = new RS_DimRadial(preview, data, edata);
128 preview->addEntity(d);
137 RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent end");
140 void RS_ActionDimRadial::mouseReleaseEvent(QMouseEvent * e)
142 if (e->button() == Qt::LeftButton)
147 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
151 if (en->rtti() == RS2::EntityArc
152 || en->rtti() == RS2::EntityCircle)
156 if (entity->rtti() == RS2::EntityArc)
157 data.definitionPoint =
158 ((RS_Arc *)entity)->getCenter();
159 else if (entity->rtti() == RS2::EntityCircle)
160 data.definitionPoint =
161 ((RS_Circle *)entity)->getCenter();
162 graphicView->moveRelativeZero(data.definitionPoint);
166 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
173 Vector ce(snapPoint(e));
174 coordinateEvent(&ce);
182 else if (e->button() == Qt::RightButton)
187 init(getStatus() - 1);
191 void RS_ActionDimRadial::coordinateEvent(Vector * e)
202 setStatus(SetEntity);
210 void RS_ActionDimRadial::commandEvent(RS_CommandEvent * e)
212 QString c = e->getCommand().toLower();
214 if (checkCommand("help", c))
216 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
217 + getAvailableCommands().join(", "));
221 // setting new text label:
222 if (getStatus() == SetText)
225 RS_DIALOGFACTORY->requestOptions(this, true, true);
226 graphicView->enableCoordinateInput();
227 setStatus(lastStatus);
232 if (checkCommand("text", c))
234 lastStatus = (Status)getStatus();
235 graphicView->disableCoordinateInput();
240 if (getStatus() == SetPos)
243 double a = RS_Math::eval(c, &ok);
247 pos.setPolar(1.0, RS_Math::deg2rad(a));
248 pos += data.definitionPoint;
251 setStatus(SetEntity);
254 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
260 QStringList RS_ActionDimRadial::getAvailableCommands()
268 cmd += command("text");
278 void RS_ActionDimRadial::updateMouseButtonHints()
283 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
288 RS_DIALOGFACTORY->updateMouseWidget(
289 tr("Specify dimension line position or enter angle:"),
294 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
298 RS_DIALOGFACTORY->updateMouseWidget("", "");
303 void RS_ActionDimRadial::showOptions()
305 RS_ActionInterface::showOptions();
307 RS_DIALOGFACTORY->requestOptions(this, true);
308 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, true);
311 void RS_ActionDimRadial::hideOptions()
313 RS_ActionInterface::hideOptions();
315 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, false);
316 RS_DIALOGFACTORY->requestOptions(this, false);