1 // rs_actiondimlinear.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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "rs_actiondimlinear.h"
17 #include "rs_constructionline.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
25 * @param angle Initial angle in rad.
26 * @param fixedAngle true: The user can't change the angle.
27 * false: The user can change the angle in a option widget.
29 RS_ActionDimLinear::RS_ActionDimLinear(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle, bool fixedAngle):
30 RS_ActionDimension("Draw linear dimensions", container, graphicView)
33 this->fixedAngle = fixedAngle;
34 lastStatus = SetExtPoint1;
38 RS_ActionDimLinear::~RS_ActionDimLinear()
42 /*virtual*/ RS2::ActionType RS_ActionDimLinear::rtti()
44 return RS2::ActionDimLinear;
47 void RS_ActionDimLinear::reset()
49 RS_ActionDimension::reset();
50 edata = RS_DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
52 if (RS_DIALOGFACTORY != NULL)
53 RS_DIALOGFACTORY->requestOptions(this, true, true);
56 void RS_ActionDimLinear::trigger()
58 RS_ActionDimension::trigger();
60 RS_DimLinear * dim = new RS_DimLinear(container, data, edata);
61 dim->setLayerToActive();
62 dim->setPenToActive();
64 container->addEntity(dim);
69 document->startUndoCycle();
70 document->addUndoable(dim);
71 document->endUndoCycle();
75 Vector rz = graphicView->getRelativeZero();
76 graphicView->moveRelativeZero(Vector(0.0, 0.0));
77 graphicView->drawEntity(dim);
78 graphicView->moveRelativeZero(rz);
81 RS_DEBUG->print("RS_ActionDimLinear::trigger(): dim added: %d", dim->getId());
84 void RS_ActionDimLinear::preparePreview()
87 dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
89 RS_ConstructionLine cl(
90 NULL, RS_ConstructionLineData(
91 edata.extensionPoint2,
92 edata.extensionPoint2 + dirV));
94 data.definitionPoint =
95 cl.getNearestPointOnEntity(data.definitionPoint);
98 void RS_ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
100 RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent begin");
102 Vector mouse = snapPoint(e);
111 if (edata.extensionPoint1.valid)
115 preview->addEntity(new RS_Line(preview,
116 RS_LineData(edata.extensionPoint1,
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("RS_ActionDimLinear::mouseMoveEvent end");
143 void RS_ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
145 if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
147 Vector ce(snapPoint(e));
148 coordinateEvent(&ce);
150 else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
154 init(getStatus() - 1);
158 void RS_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 RS_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 RS_ActionDimLinear::getAvailableCommands()
256 cmd += command("text");
259 cmd += command("angle");
269 void RS_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 RS_ActionDimLinear::showOptions()
307 RS_ActionInterface::showOptions();
309 if (RS_DIALOGFACTORY != NULL)
310 RS_DIALOGFACTORY->requestOptions(this, true, true);
313 void RS_ActionDimLinear::hideOptions()
315 RS_ActionInterface::hideOptions();
317 if (RS_DIALOGFACTORY != NULL)
318 RS_DIALOGFACTORY->requestOptions(this, false);
321 double RS_ActionDimLinear::getAngle()
326 void RS_ActionDimLinear::setAngle(double a)
331 bool RS_ActionDimLinear::hasFixedAngle()