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 05/22/2010 Added this text. :-)
17 #include "actiondimlinear.h"
19 #include "rs_commandevent.h"
20 #include "rs_constructionline.h"
21 #include "rs_dialogfactory.h"
22 #include "graphicview.h"
23 #include "rs_preview.h"
28 * @param angle Initial angle in rad.
29 * @param fixedAngle true: The user can't change the angle.
30 * false: The user can change the angle in a option widget.
32 ActionDimLinear::ActionDimLinear(RS_EntityContainer & container,
33 GraphicView & graphicView, double angle, bool fixedAngle):
34 ActionDimension("Draw linear dimensions", container, graphicView)
37 this->fixedAngle = fixedAngle;
38 lastStatus = SetExtPoint1;
40 graphicView.snapper.SetVisible();
44 ActionDimLinear::~ActionDimLinear()
48 /*virtual*/ RS2::ActionType ActionDimLinear::rtti()
50 return RS2::ActionDimLinear;
53 void ActionDimLinear::reset()
55 ActionDimension::reset();
56 edata = RS_DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
59 RS_DIALOGFACTORY->requestOptions(this, true, true);
62 void ActionDimLinear::trigger()
64 ActionDimension::trigger();
66 RS_DimLinear * dim = new RS_DimLinear(container, data, edata);
67 dim->setLayerToActive();
68 dim->setPenToActive();
70 container->addEntity(dim);
75 document->startUndoCycle();
76 document->addUndoable(dim);
77 document->endUndoCycle();
81 // Vector rz = graphicView->getRelativeZero();
82 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
83 // graphicView->drawEntity(dim);
84 // graphicView->moveRelativeZero(rz);
86 graphicView->snapper.SetVisible(false);
87 graphicView->redraw();
89 RS_DEBUG->print("ActionDimLinear::trigger(): dim added: %d", dim->getId());
92 void ActionDimLinear::preparePreview()
95 dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
97 RS_ConstructionLine cl(NULL, RS_ConstructionLineData(edata.extensionPoint2,
98 edata.extensionPoint2 + dirV));
100 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
103 void ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
105 RS_DEBUG->print("ActionDimLinear::mouseMoveEvent begin");
107 Vector mouse = snapPoint(e);
112 // graphicView->snapper.SetVisible();
113 // graphicView->redraw();
118 if (edata.extensionPoint1.valid)
122 // preview->addEntity(new RS_Line(preview,
123 // RS_LineData(edata.extensionPoint1, mouse)));
125 graphicView->preview.clear();
126 graphicView->preview.addEntity(new RS_Line(&(graphicView->preview),
127 RS_LineData(edata.extensionPoint1, mouse)));
128 graphicView->preview.SetVisible();
129 graphicView->redraw();
136 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
140 data.definitionPoint = mouse;
142 // RS_DimLinear * dim = new RS_DimLinear(preview, data, edata);
144 // preview->addEntity(dim);
146 graphicView->preview.clear();
148 RS_DimLinear * dim = new RS_DimLinear(&(graphicView->preview), data, edata);
150 graphicView->preview.addEntity(dim);
151 graphicView->preview.SetVisible();
152 graphicView->redraw();
158 RS_DEBUG->print("ActionDimLinear::mouseMoveEvent end");
161 void ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
163 if (e->button() == Qt::LeftButton)
165 Vector ce(snapPoint(e));
166 coordinateEvent(&ce);
167 graphicView->snapper.SetVisible();
169 else if (e->button() == Qt::RightButton)
171 if (getStatus() == 0)
173 graphicView->preview.SetVisible(false);
174 graphicView->snapper.SetVisible(false);
179 init(getStatus() - 1);
183 void ActionDimLinear::coordinateEvent(Vector * e)
193 edata.extensionPoint1 = pos;
194 graphicView->moveRelativeZero(pos);
195 setStatus(SetExtPoint2);
199 edata.extensionPoint2 = pos;
200 graphicView->moveRelativeZero(pos);
201 setStatus(SetDefPoint);
205 data.definitionPoint = pos;
208 setStatus(SetExtPoint1);
216 void ActionDimLinear::commandEvent(RS_CommandEvent * e)
218 QString c = e->getCommand().toLower();
220 if (checkCommand("help", c))
222 if (RS_DIALOGFACTORY)
223 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
224 + getAvailableCommands().join(", "));
233 if (RS_DIALOGFACTORY)
234 RS_DIALOGFACTORY->requestOptions(this, true, true);
236 graphicView->enableCoordinateInput();
237 setStatus(lastStatus);
243 double a = RS_Math::eval(c, &ok);
246 setAngle(RS_Math::deg2rad(a));
247 else if (RS_DIALOGFACTORY)
248 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
250 if (RS_DIALOGFACTORY)
251 RS_DIALOGFACTORY->requestOptions(this, true, true);
253 setStatus(lastStatus);
258 lastStatus = (Status)getStatus();
263 if (checkCommand("text", c))
265 graphicView->disableCoordinateInput();
269 else if (!fixedAngle && (checkCommand("angle", c)))
276 QStringList ActionDimLinear::getAvailableCommands()
285 cmd += command("text");
288 cmd += command("angle");
299 void ActionDimLinear::updateMouseButtonHints()
301 if (RS_DIALOGFACTORY)
306 RS_DIALOGFACTORY->updateMouseWidget(
307 tr("Specify first extension line origin"), tr("Cancel"));
311 RS_DIALOGFACTORY->updateMouseWidget(
312 tr("Specify second extension line origin"), tr("Back"));
316 RS_DIALOGFACTORY->updateMouseWidget(
317 tr("Specify dimension line location"), tr("Back"));
321 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
325 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension line angle:"), "");
329 RS_DIALOGFACTORY->updateMouseWidget("", "");
335 void ActionDimLinear::showOptions()
337 ActionInterface::showOptions();
339 if (RS_DIALOGFACTORY)
340 RS_DIALOGFACTORY->requestOptions(this, true, true);
343 void ActionDimLinear::hideOptions()
345 ActionInterface::hideOptions();
347 if (RS_DIALOGFACTORY)
348 RS_DIALOGFACTORY->requestOptions(this, false);
351 double ActionDimLinear::getAngle()
356 void ActionDimLinear::setAngle(double a)
361 bool ActionDimLinear::hasFixedAngle()