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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 06/03/2010 Added this text. :-)
17 #include "actiondimradial.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 ActionDimRadial::ActionDimRadial(RS_EntityContainer & container, GraphicView & graphicView):
25 ActionDimension("Draw Radial Dimensions", container, graphicView)
30 ActionDimRadial::~ActionDimRadial()
34 /*virtual*/ RS2::ActionType ActionDimRadial::rtti()
36 return RS2::ActionDimRadial;
39 void ActionDimRadial::reset()
41 ActionDimension::reset();
43 edata = RS_DimRadialData(Vector(false), 0.0);
46 RS_DIALOGFACTORY->requestOptions(this, true, true);
49 void ActionDimRadial::trigger()
51 ActionDimension::trigger();
57 RS_DimRadial * newEntity = new RS_DimRadial(container, data, edata);
58 newEntity->setLayerToActive();
59 newEntity->setPenToActive();
61 container->addEntity(newEntity);
66 document->startUndoCycle();
67 document->addUndoable(newEntity);
68 document->endUndoCycle();
72 Vector rz = graphicView->getRelativeZero();
73 graphicView->moveRelativeZero(Vector(0.0, 0.0));
74 graphicView->drawEntity(newEntity);
75 graphicView->moveRelativeZero(rz);
79 RS_DEBUG->print("ActionDimRadial::trigger: Entity is NULL\n");
82 void ActionDimRadial::preparePreview()
86 double angle = data.definitionPoint.angleTo(pos);
89 if (entity->rtti() == RS2::EntityArc)
90 radius = ((RS_Arc *)entity)->getRadius();
91 else if (entity->rtti() == RS2::EntityCircle)
92 radius = ((RS_Circle *)entity)->getRadius();
94 edata.definitionPoint.setPolar(radius, angle);
95 edata.definitionPoint += data.definitionPoint;
99 void ActionDimRadial::mouseMoveEvent(QMouseEvent * e)
101 RS_DEBUG->print("ActionDimRadial::mouseMoveEvent begin");
106 entity = catchEntity(e, RS2::ResolveAll);
117 // RS_DimRadial * d = new RS_DimRadial(preview, data, edata);
122 // preview->addEntity(d);
131 RS_DEBUG->print("ActionDimRadial::mouseMoveEvent end");
134 void ActionDimRadial::mouseReleaseEvent(QMouseEvent * e)
136 if (e->button() == Qt::LeftButton)
141 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
145 if (en->rtti() == RS2::EntityArc
146 || en->rtti() == RS2::EntityCircle)
150 if (entity->rtti() == RS2::EntityArc)
151 data.definitionPoint =
152 ((RS_Arc *)entity)->getCenter();
153 else if (entity->rtti() == RS2::EntityCircle)
154 data.definitionPoint =
155 ((RS_Circle *)entity)->getCenter();
156 graphicView->moveRelativeZero(data.definitionPoint);
160 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
167 Vector ce(snapPoint(e));
168 coordinateEvent(&ce);
176 else if (e->button() == Qt::RightButton)
181 init(getStatus() - 1);
185 void ActionDimRadial::coordinateEvent(Vector * e)
196 setStatus(SetEntity);
204 void ActionDimRadial::commandEvent(RS_CommandEvent * e)
206 QString c = e->getCommand().toLower();
208 if (checkCommand("help", c))
210 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
211 + getAvailableCommands().join(", "));
215 // setting new text label:
216 if (getStatus() == SetText)
219 RS_DIALOGFACTORY->requestOptions(this, true, true);
220 graphicView->enableCoordinateInput();
221 setStatus(lastStatus);
226 if (checkCommand("text", c))
228 lastStatus = (Status)getStatus();
229 graphicView->disableCoordinateInput();
234 if (getStatus() == SetPos)
237 double a = RS_Math::eval(c, &ok);
241 pos.setPolar(1.0, RS_Math::deg2rad(a));
242 pos += data.definitionPoint;
245 setStatus(SetEntity);
248 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
254 QStringList ActionDimRadial::getAvailableCommands()
262 cmd += command("text");
272 void ActionDimRadial::updateMouseButtonHints()
277 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
282 RS_DIALOGFACTORY->updateMouseWidget(
283 tr("Specify dimension line position or enter angle:"),
288 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
292 RS_DIALOGFACTORY->updateMouseWidget("", "");
297 void ActionDimRadial::showOptions()
299 ActionInterface::showOptions();
301 RS_DIALOGFACTORY->requestOptions(this, true);
302 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, true);
305 void ActionDimRadial::hideOptions()
307 ActionInterface::hideOptions();
309 //RS_DIALOGFACTORY->requestDimRadialOptions(edata, false);
310 RS_DIALOGFACTORY->requestOptions(this, false);