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,
31 GraphicView & graphicView, double angle, bool fixedAngle):
32 ActionDimension("Draw linear dimensions", container, graphicView)
35 this->fixedAngle = fixedAngle;
36 lastStatus = SetExtPoint1;
38 graphicView.snapper.SetVisible();
42 ActionDimLinear::~ActionDimLinear()
46 /*virtual*/ RS2::ActionType ActionDimLinear::rtti()
48 return RS2::ActionDimLinear;
51 void ActionDimLinear::reset()
53 ActionDimension::reset();
54 edata = RS_DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
57 RS_DIALOGFACTORY->requestOptions(this, true, true);
60 void ActionDimLinear::trigger()
62 ActionDimension::trigger();
64 RS_DimLinear * dim = new RS_DimLinear(container, data, edata);
65 dim->setLayerToActive();
66 dim->setPenToActive();
68 container->addEntity(dim);
73 document->startUndoCycle();
74 document->addUndoable(dim);
75 document->endUndoCycle();
79 // Vector rz = graphicView->getRelativeZero();
80 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
81 // graphicView->drawEntity(dim);
82 // graphicView->moveRelativeZero(rz);
84 graphicView->snapper.SetVisible(false);
85 graphicView->redraw();
87 RS_DEBUG->print("ActionDimLinear::trigger(): dim added: %d", dim->getId());
90 void ActionDimLinear::preparePreview()
93 dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
95 RS_ConstructionLine cl(NULL, RS_ConstructionLineData(edata.extensionPoint2,
96 edata.extensionPoint2 + dirV));
98 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
101 void ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
103 RS_DEBUG->print("ActionDimLinear::mouseMoveEvent begin");
105 Vector mouse = snapPoint(e);
110 // graphicView->snapper.SetVisible();
111 // graphicView->redraw();
116 if (edata.extensionPoint1.valid)
120 // preview->addEntity(new RS_Line(preview,
121 // RS_LineData(edata.extensionPoint1, mouse)));
123 graphicView->preview.clear();
124 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
125 RS_LineData(edata.extensionPoint1, mouse)));
126 graphicView->preview.SetVisible();
127 graphicView->redraw();
134 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
138 data.definitionPoint = mouse;
140 // RS_DimLinear * dim = new RS_DimLinear(preview, data, edata);
142 // preview->addEntity(dim);
144 graphicView->preview.clear();
146 RS_DimLinear * dim = new RS_DimLinear(&(graphicView->preview), data, edata);
148 graphicView->preview.addEntity(dim);
149 graphicView->preview.SetVisible();
150 graphicView->redraw();
156 RS_DEBUG->print("ActionDimLinear::mouseMoveEvent end");
159 void ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
161 if (e->button() == Qt::LeftButton)
163 Vector ce(snapPoint(e));
164 coordinateEvent(&ce);
165 graphicView->snapper.SetVisible();
167 else if (e->button() == Qt::RightButton)
169 if (getStatus() == 0)
171 graphicView->preview.SetVisible(false);
172 graphicView->snapper.SetVisible(false);
177 init(getStatus() - 1);
181 void ActionDimLinear::coordinateEvent(Vector * e)
191 edata.extensionPoint1 = pos;
192 graphicView->moveRelativeZero(pos);
193 setStatus(SetExtPoint2);
197 edata.extensionPoint2 = pos;
198 graphicView->moveRelativeZero(pos);
199 setStatus(SetDefPoint);
203 data.definitionPoint = pos;
206 setStatus(SetExtPoint1);
214 void ActionDimLinear::commandEvent(RS_CommandEvent * e)
216 QString c = e->getCommand().toLower();
218 if (checkCommand("help", c))
220 if (RS_DIALOGFACTORY)
221 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
222 + getAvailableCommands().join(", "));
231 if (RS_DIALOGFACTORY)
232 RS_DIALOGFACTORY->requestOptions(this, true, true);
234 graphicView->enableCoordinateInput();
235 setStatus(lastStatus);
241 double a = RS_Math::eval(c, &ok);
244 setAngle(RS_Math::deg2rad(a));
245 else if (RS_DIALOGFACTORY)
246 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
248 if (RS_DIALOGFACTORY)
249 RS_DIALOGFACTORY->requestOptions(this, true, true);
251 setStatus(lastStatus);
256 lastStatus = (Status)getStatus();
261 if (checkCommand("text", c))
263 graphicView->disableCoordinateInput();
267 else if (!fixedAngle && (checkCommand("angle", c)))
274 QStringList ActionDimLinear::getAvailableCommands()
283 cmd += command("text");
286 cmd += command("angle");
297 void ActionDimLinear::updateMouseButtonHints()
299 if (RS_DIALOGFACTORY)
304 RS_DIALOGFACTORY->updateMouseWidget(
305 tr("Specify first extension line origin"), tr("Cancel"));
309 RS_DIALOGFACTORY->updateMouseWidget(
310 tr("Specify second extension line origin"), tr("Back"));
314 RS_DIALOGFACTORY->updateMouseWidget(
315 tr("Specify dimension line location"), tr("Back"));
319 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
323 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension line angle:"), "");
327 RS_DIALOGFACTORY->updateMouseWidget("", "");
333 void ActionDimLinear::showOptions()
335 ActionInterface::showOptions();
337 if (RS_DIALOGFACTORY)
338 RS_DIALOGFACTORY->requestOptions(this, true, true);
341 void ActionDimLinear::hideOptions()
343 ActionInterface::hideOptions();
345 if (RS_DIALOGFACTORY)
346 RS_DIALOGFACTORY->requestOptions(this, false);
349 double ActionDimLinear::getAngle()
354 void ActionDimLinear::setAngle(double a)
359 bool ActionDimLinear::hasFixedAngle()