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 "commandevent.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
25 ActionDimRadial::ActionDimRadial(EntityContainer & container, GraphicView & graphicView):
26 ActionDimension("Draw Radial Dimensions", container, graphicView)
31 ActionDimRadial::~ActionDimRadial()
35 /*virtual*/ RS2::ActionType ActionDimRadial::rtti()
37 return RS2::ActionDimRadial;
40 void ActionDimRadial::reset()
42 ActionDimension::reset();
44 edata = DimRadialData(Vector(false), 0.0);
47 DIALOGFACTORY->requestOptions(this, true, true);
50 void ActionDimRadial::trigger()
52 ActionDimension::trigger();
58 DimRadial * newEntity = new DimRadial(container, data, edata);
59 newEntity->setLayerToActive();
60 newEntity->setPenToActive();
62 container->addEntity(newEntity);
67 document->startUndoCycle();
68 document->addUndoable(newEntity);
69 document->endUndoCycle();
73 Vector rz = graphicView->getRelativeZero();
74 graphicView->moveRelativeZero(Vector(0.0, 0.0));
75 graphicView->drawEntity(newEntity);
76 graphicView->moveRelativeZero(rz);
80 DEBUG->print("ActionDimRadial::trigger: Entity is NULL\n");
83 void ActionDimRadial::preparePreview()
87 double angle = data.definitionPoint.angleTo(pos);
90 if (entity->rtti() == RS2::EntityArc)
91 radius = ((Arc *)entity)->getRadius();
92 else if (entity->rtti() == RS2::EntityCircle)
93 radius = ((Circle *)entity)->getRadius();
95 edata.definitionPoint.setPolar(radius, angle);
96 edata.definitionPoint += data.definitionPoint;
100 void ActionDimRadial::mouseMoveEvent(QMouseEvent * e)
102 DEBUG->print("ActionDimRadial::mouseMoveEvent begin");
107 entity = catchEntity(e, RS2::ResolveAll);
118 // DimRadial * d = new DimRadial(preview, data, edata);
123 // preview->addEntity(d);
132 DEBUG->print("ActionDimRadial::mouseMoveEvent end");
135 void ActionDimRadial::mouseReleaseEvent(QMouseEvent * e)
137 if (e->button() == Qt::LeftButton)
142 Entity * en = catchEntity(e, RS2::ResolveAll);
146 if (en->rtti() == RS2::EntityArc
147 || en->rtti() == RS2::EntityCircle)
151 if (entity->rtti() == RS2::EntityArc)
152 data.definitionPoint =
153 ((Arc *)entity)->getCenter();
154 else if (entity->rtti() == RS2::EntityCircle)
155 data.definitionPoint =
156 ((Circle *)entity)->getCenter();
157 graphicView->moveRelativeZero(data.definitionPoint);
161 DIALOGFACTORY->commandMessage(tr("Not a circle "
168 Vector ce(snapPoint(e));
169 coordinateEvent(&ce);
177 else if (e->button() == Qt::RightButton)
182 init(getStatus() - 1);
186 void ActionDimRadial::coordinateEvent(Vector * e)
197 setStatus(SetEntity);
205 void ActionDimRadial::commandEvent(CommandEvent * e)
207 QString c = e->getCommand().toLower();
209 if (checkCommand("help", c))
211 DIALOGFACTORY->commandMessage(msgAvailableCommands()
212 + getAvailableCommands().join(", "));
216 // setting new text label:
217 if (getStatus() == SetText)
220 DIALOGFACTORY->requestOptions(this, true, true);
221 graphicView->enableCoordinateInput();
222 setStatus(lastStatus);
227 if (checkCommand("text", c))
229 lastStatus = (Status)getStatus();
230 graphicView->disableCoordinateInput();
235 if (getStatus() == SetPos)
238 double a = Math::eval(c, &ok);
242 pos.setPolar(1.0, Math::deg2rad(a));
243 pos += data.definitionPoint;
246 setStatus(SetEntity);
249 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
255 QStringList ActionDimRadial::getAvailableCommands()
263 cmd += command("text");
273 void ActionDimRadial::updateMouseButtonHints()
278 DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
283 DIALOGFACTORY->updateMouseWidget(
284 tr("Specify dimension line position or enter angle:"),
289 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
293 DIALOGFACTORY->updateMouseWidget("", "");
298 void ActionDimRadial::showOptions()
300 ActionInterface::showOptions();
302 DIALOGFACTORY->requestOptions(this, true);
303 //DIALOGFACTORY->requestDimRadialOptions(edata, true);
306 void ActionDimRadial::hideOptions()
308 ActionInterface::hideOptions();
310 //DIALOGFACTORY->requestDimRadialOptions(edata, false);
311 DIALOGFACTORY->requestOptions(this, false);