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_commandevent.h"
18 #include "rs_dialogfactory.h"
19 #include "graphicview.h"
20 #include "rs_preview.h"
22 RS_ActionDimRadial::RS_ActionDimRadial(RS_EntityContainer & container, GraphicView & graphicView): RS_ActionDimension("Draw Radial Dimensions",
23 container, graphicView)
28 RS_ActionDimRadial::~RS_ActionDimRadial()
32 /*virtual*/ RS2::ActionType RS_ActionDimRadial::rtti()
34 return RS2::ActionDimRadial;
37 void RS_ActionDimRadial::reset()
39 RS_ActionDimension::reset();
41 edata = RS_DimRadialData(Vector(false),
45 RS_DIALOGFACTORY->requestOptions(this, true, true);
48 void RS_ActionDimRadial::trigger()
50 RS_ActionDimension::trigger();
56 RS_DimRadial * newEntity = NULL;
58 newEntity = new RS_DimRadial(container,
62 newEntity->setLayerToActive();
63 newEntity->setPenToActive();
65 container->addEntity(newEntity);
70 document->startUndoCycle();
71 document->addUndoable(newEntity);
72 document->endUndoCycle();
75 Vector rz = graphicView->getRelativeZero();
76 graphicView->moveRelativeZero(Vector(0.0, 0.0));
77 graphicView->drawEntity(newEntity);
78 graphicView->moveRelativeZero(rz);
82 RS_DEBUG->print("RS_ActionDimRadial::trigger:"
86 void RS_ActionDimRadial::preparePreview()
90 double angle = data.definitionPoint.angleTo(pos);
93 if (entity->rtti() == RS2::EntityArc)
94 radius = ((RS_Arc *)entity)->getRadius();
95 else if (entity->rtti() == RS2::EntityCircle)
96 radius = ((RS_Circle *)entity)->getRadius();
98 edata.definitionPoint.setPolar(radius, angle);
99 edata.definitionPoint += data.definitionPoint;
103 void RS_ActionDimRadial::mouseMoveEvent(QMouseEvent * e)
105 RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent begin");
107 //Vector mouse(graphicView->toGraphX(e->x()),
108 // graphicView->toGraphY(e->y()));
113 entity = catchEntity(e, RS2::ResolveAll);
124 RS_DimRadial * d = new RS_DimRadial(preview, data, edata);
129 preview->addEntity(d);
138 RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent end");
141 void RS_ActionDimRadial::mouseReleaseEvent(QMouseEvent * e)
143 if (e->button() == Qt::LeftButton)
148 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
152 if (en->rtti() == RS2::EntityArc
153 || en->rtti() == RS2::EntityCircle)
157 if (entity->rtti() == RS2::EntityArc)
158 data.definitionPoint =
159 ((RS_Arc *)entity)->getCenter();
160 else if (entity->rtti() == RS2::EntityCircle)
161 data.definitionPoint =
162 ((RS_Circle *)entity)->getCenter();
163 graphicView->moveRelativeZero(data.definitionPoint);
167 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
174 Vector ce(snapPoint(e));
175 coordinateEvent(&ce);
183 else if (e->button() == Qt::RightButton)
188 init(getStatus() - 1);
192 void RS_ActionDimRadial::coordinateEvent(Vector * e)
203 setStatus(SetEntity);
211 void RS_ActionDimRadial::commandEvent(RS_CommandEvent * e)
213 QString c = e->getCommand().toLower();
215 if (checkCommand("help", c))
217 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
218 + getAvailableCommands().join(", "));
222 // setting new text label:
223 if (getStatus() == SetText)
226 RS_DIALOGFACTORY->requestOptions(this, true, true);
227 graphicView->enableCoordinateInput();
228 setStatus(lastStatus);
233 if (checkCommand("text", c))
235 lastStatus = (Status)getStatus();
236 graphicView->disableCoordinateInput();
241 if (getStatus() == SetPos)
244 double a = RS_Math::eval(c, &ok);
248 pos.setPolar(1.0, RS_Math::deg2rad(a));
249 pos += data.definitionPoint;
252 setStatus(SetEntity);
255 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
261 QStringList RS_ActionDimRadial::getAvailableCommands()
269 cmd += command("text");
279 void RS_ActionDimRadial::updateMouseButtonHints()
284 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
289 RS_DIALOGFACTORY->updateMouseWidget(
290 tr("Specify dimension line position or enter angle:"),
295 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
299 RS_DIALOGFACTORY->updateMouseWidget("", "");
304 void RS_ActionDimRadial::showOptions()
306 RS_ActionInterface::showOptions();
308 RS_DIALOGFACTORY->requestOptions(this, true);
309 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, true);
312 void RS_ActionDimRadial::hideOptions()
314 RS_ActionInterface::hideOptions();
316 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, false);
317 RS_DIALOGFACTORY->requestOptions(this, false);