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 05/22/2010 Added this text. :-)
15 #include "actiondimlinear.h"
17 #include "rs_commandevent.h"
18 #include "rs_constructionline.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
26 * @param angle Initial angle in rad.
27 * @param fixedAngle true: The user can't change the angle.
28 * false: The user can change the angle in a option widget.
30 ActionDimLinear::ActionDimLinear(RS_EntityContainer & container, GraphicView & graphicView, double angle, bool fixedAngle):
31 ActionDimension("Draw linear dimensions", container, graphicView)
34 this->fixedAngle = fixedAngle;
35 lastStatus = SetExtPoint1;
39 ActionDimLinear::~ActionDimLinear()
43 /*virtual*/ RS2::ActionType ActionDimLinear::rtti()
45 return RS2::ActionDimLinear;
48 void ActionDimLinear::reset()
50 ActionDimension::reset();
51 edata = RS_DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
53 if (RS_DIALOGFACTORY != NULL)
54 RS_DIALOGFACTORY->requestOptions(this, true, true);
57 void ActionDimLinear::trigger()
59 ActionDimension::trigger();
61 RS_DimLinear * dim = new RS_DimLinear(container, data, edata);
62 dim->setLayerToActive();
63 dim->setPenToActive();
65 container->addEntity(dim);
70 document->startUndoCycle();
71 document->addUndoable(dim);
72 document->endUndoCycle();
76 Vector rz = graphicView->getRelativeZero();
77 graphicView->moveRelativeZero(Vector(0.0, 0.0));
78 graphicView->drawEntity(dim);
79 graphicView->moveRelativeZero(rz);
82 RS_DEBUG->print("ActionDimLinear::trigger(): dim added: %d", dim->getId());
85 void ActionDimLinear::preparePreview()
88 dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
90 RS_ConstructionLine cl(
91 NULL, RS_ConstructionLineData(
92 edata.extensionPoint2,
93 edata.extensionPoint2 + dirV));
95 data.definitionPoint =
96 cl.getNearestPointOnEntity(data.definitionPoint);
99 void ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
101 RS_DEBUG->print("ActionDimLinear::mouseMoveEvent begin");
103 Vector mouse = snapPoint(e);
112 if (edata.extensionPoint1.valid)
116 // preview->addEntity(new RS_Line(preview,
117 // RS_LineData(edata.extensionPoint1, mouse)));
124 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
128 data.definitionPoint = mouse;
132 // RS_DimLinear * dim = new RS_DimLinear(preview, data, edata);
134 // preview->addEntity(dim);
140 RS_DEBUG->print("ActionDimLinear::mouseMoveEvent end");
143 void ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
145 if (e->button() == Qt::LeftButton)
147 Vector ce(snapPoint(e));
148 coordinateEvent(&ce);
150 else if (e->button() == Qt::RightButton)
154 init(getStatus() - 1);
158 void ActionDimLinear::coordinateEvent(Vector * e)
168 edata.extensionPoint1 = pos;
169 graphicView->moveRelativeZero(pos);
170 setStatus(SetExtPoint2);
174 edata.extensionPoint2 = pos;
175 graphicView->moveRelativeZero(pos);
176 setStatus(SetDefPoint);
180 data.definitionPoint = pos;
183 setStatus(SetExtPoint1);
191 void ActionDimLinear::commandEvent(RS_CommandEvent * e)
193 QString c = e->getCommand().toLower();
195 if (checkCommand("help", c))
197 if (RS_DIALOGFACTORY != NULL)
198 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
199 + getAvailableCommands().join(", "));
208 if (RS_DIALOGFACTORY != NULL)
209 RS_DIALOGFACTORY->requestOptions(this, true, true);
210 graphicView->enableCoordinateInput();
211 setStatus(lastStatus);
216 double a = RS_Math::eval(c, &ok);
219 setAngle(RS_Math::deg2rad(a));
220 else if (RS_DIALOGFACTORY != NULL)
221 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
223 if (RS_DIALOGFACTORY != NULL)
224 RS_DIALOGFACTORY->requestOptions(this, true, true);
225 setStatus(lastStatus);
230 lastStatus = (Status)getStatus();
235 if (checkCommand("text", c))
237 graphicView->disableCoordinateInput();
241 else if (!fixedAngle && (checkCommand("angle", c)))
247 QStringList ActionDimLinear::getAvailableCommands()
256 cmd += command("text");
259 cmd += command("angle");
269 void ActionDimLinear::updateMouseButtonHints()
271 if (RS_DIALOGFACTORY != NULL)
276 RS_DIALOGFACTORY->updateMouseWidget(
277 tr("Specify first extension line origin"), tr("Cancel"));
281 RS_DIALOGFACTORY->updateMouseWidget(
282 tr("Specify second extension line origin"), tr("Back"));
286 RS_DIALOGFACTORY->updateMouseWidget(
287 tr("Specify dimension line location"), tr("Back"));
291 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
295 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension line angle:"), "");
299 RS_DIALOGFACTORY->updateMouseWidget("", "");
305 void ActionDimLinear::showOptions()
307 ActionInterface::showOptions();
309 if (RS_DIALOGFACTORY != NULL)
310 RS_DIALOGFACTORY->requestOptions(this, true, true);
313 void ActionDimLinear::hideOptions()
315 ActionInterface::hideOptions();
317 if (RS_DIALOGFACTORY != NULL)
318 RS_DIALOGFACTORY->requestOptions(this, false);
321 double ActionDimLinear::getAngle()
326 void ActionDimLinear::setAngle(double a)
331 bool ActionDimLinear::hasFixedAngle()