1 // 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 // 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 "actiondimdiametric.h"
19 #include "rs_commandevent.h"
20 #include "rs_dialogfactory.h"
21 #include "graphicview.h"
22 #include "rs_preview.h"
24 ActionDimDiametric::ActionDimDiametric(RS_EntityContainer & container,
25 GraphicView & graphicView): ActionDimension("Draw Diametric Dimensions",
26 container, graphicView)
31 ActionDimDiametric::~ActionDimDiametric()
35 /*virtual*/ RS2::ActionType ActionDimDiametric::rtti()
37 return RS2::ActionDimDiametric;
40 void ActionDimDiametric::reset()
42 ActionDimension::reset();
43 edata = RS_DimDiametricData(Vector(false), 0.0);
46 RS_DIALOGFACTORY->requestOptions(this, true, true);
49 void ActionDimDiametric::trigger()
51 ActionInterface::trigger();
56 RS_DimDiametric * newEntity = NULL;
58 newEntity = new RS_DimDiametric(container,
62 newEntity->setLayerToActive();
63 newEntity->setPenToActive();
65 container->addEntity(newEntity);
70 document->startUndoCycle();
71 document->addUndoable(newEntity);
72 document->endUndoCycle();
76 Vector rz = graphicView->getRelativeZero();
77 graphicView->moveRelativeZero(Vector(0.0, 0.0));
78 graphicView->drawEntity(newEntity);
79 graphicView->moveRelativeZero(rz);
82 RS_DEBUG->print("ActionDimDiametric::trigger: Entity is NULL\n");
85 void ActionDimDiametric::preparePreview()
90 Vector center = Vector(false);
92 if (entity->rtti() == RS2::EntityArc)
94 radius = ((RS_Arc *)entity)->getRadius();
95 center = ((RS_Arc *)entity)->getCenter();
97 else if (entity->rtti() == RS2::EntityCircle)
99 radius = ((RS_Circle *)entity)->getRadius();
100 center = ((RS_Circle *)entity)->getCenter();
102 double angle = center.angleTo(pos);
104 data.definitionPoint.setPolar(radius, angle + M_PI);
105 data.definitionPoint += center;
107 edata.definitionPoint.setPolar(radius, angle);
108 edata.definitionPoint += center;
112 void ActionDimDiametric::mouseMoveEvent(QMouseEvent * e)
114 RS_DEBUG->print("ActionDimDiametric::mouseMoveEvent begin");
116 Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
121 entity = catchEntity(e, RS2::ResolveAll);
131 // RS_DimDiametric * d = new RS_DimDiametric(preview, data, edata);
136 // preview->addEntity(d);
145 RS_DEBUG->print("ActionDimDiametric::mouseMoveEvent end");
148 void ActionDimDiametric::mouseReleaseEvent(QMouseEvent * e)
150 if (e->button() == Qt::LeftButton)
155 RS_Entity * en = catchEntity(e, RS2::ResolveAll);
159 if (en->rtti() == RS2::EntityArc
160 || en->rtti() == RS2::EntityCircle)
165 if (entity->rtti() == RS2::EntityArc)
167 ((RS_Arc *)entity)->getCenter();
168 else if (entity->rtti() == RS2::EntityCircle)
170 ((RS_Circle *)entity)->getCenter();
171 graphicView->moveRelativeZero(center);
175 RS_DIALOGFACTORY->commandMessage(tr("Not a circle "
182 Vector ce(snapPoint(e));
183 coordinateEvent(&ce);
191 else if (e->button() == Qt::RightButton)
196 init(getStatus() - 1);
200 void ActionDimDiametric::coordinateEvent(Vector * e)
211 setStatus(SetEntity);
219 void ActionDimDiametric::commandEvent(RS_CommandEvent * e)
221 QString c = e->getCommand().toLower();
223 if (checkCommand("help", c))
225 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
226 + getAvailableCommands().join(", "));
230 // setting new text label:
231 if (getStatus() == SetText)
234 RS_DIALOGFACTORY->requestOptions(this, true, true);
235 graphicView->enableCoordinateInput();
236 setStatus(lastStatus);
241 if (checkCommand("text", c))
243 lastStatus = (Status)getStatus();
244 graphicView->disableCoordinateInput();
249 if (getStatus() == SetPos)
252 double a = RS_Math::eval(c, &ok);
256 pos.setPolar(1.0, RS_Math::deg2rad(a));
257 pos += data.definitionPoint;
260 setStatus(SetEntity);
263 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
268 QStringList ActionDimDiametric::getAvailableCommands()
276 cmd += command("text");
286 void ActionDimDiametric::updateMouseButtonHints()
291 RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"),
296 RS_DIALOGFACTORY->updateMouseWidget(
297 tr("Specify dimension line location"), tr("Cancel"));
301 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
305 RS_DIALOGFACTORY->updateMouseWidget("", "");
310 void ActionDimDiametric::showOptions()
312 ActionInterface::showOptions();
314 RS_DIALOGFACTORY->requestOptions(this, true);
317 void ActionDimDiametric::hideOptions()
319 ActionInterface::hideOptions();
321 //RS_DIALOGFACTORY->requestDimDiametricOptions(edata, false);
322 RS_DIALOGFACTORY->requestOptions(this, false);