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 "commandevent.h"
20 #include "constructionline.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
29 * @param angle Initial angle in rad.
30 * @param fixedAngle true: The user can't change the angle.
31 * false: The user can change the angle in a option widget.
33 ActionDimLinear::ActionDimLinear(EntityContainer & container,
34 GraphicView & graphicView, double angle, bool fixedAngle):
35 ActionDimension("Draw linear dimensions", container, graphicView)
38 this->fixedAngle = fixedAngle;
39 lastStatus = SetExtPoint1;
41 graphicView.snapper.SetVisible();
45 ActionDimLinear::~ActionDimLinear()
49 /*virtual*/ RS2::ActionType ActionDimLinear::rtti()
51 return RS2::ActionDimLinear;
54 void ActionDimLinear::reset()
56 ActionDimension::reset();
57 edata = DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
60 DIALOGFACTORY->requestOptions(this, true, true);
63 void ActionDimLinear::trigger()
65 ActionDimension::trigger();
67 DimLinear * dim = new DimLinear(container, data, edata);
68 dim->setLayerToActive();
69 dim->setPenToActive();
71 container->addEntity(dim);
76 document->startUndoCycle();
77 document->addUndoable(dim);
78 document->endUndoCycle();
82 // Vector rz = graphicView->getRelativeZero();
83 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
84 // graphicView->drawEntity(dim);
85 // graphicView->moveRelativeZero(rz);
87 graphicView->snapper.SetVisible(false);
88 graphicView->redraw();
90 DEBUG->print("ActionDimLinear::trigger(): dim added: %d", dim->getId());
93 void ActionDimLinear::preparePreview()
96 dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
98 ConstructionLine cl(NULL, ConstructionLineData(edata.extensionPoint2,
99 edata.extensionPoint2 + dirV));
101 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
104 void ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
106 DEBUG->print("ActionDimLinear::mouseMoveEvent begin");
108 Vector mouse = snapPoint(e);
113 // graphicView->snapper.SetVisible();
114 // graphicView->redraw();
119 if (edata.extensionPoint1.valid)
123 // preview->addEntity(new Line(preview,
124 // LineData(edata.extensionPoint1, mouse)));
126 graphicView->preview.clear();
127 graphicView->preview.addEntity(new Line(&(graphicView->preview),
128 LineData(edata.extensionPoint1, mouse)));
129 graphicView->preview.SetVisible();
130 graphicView->redraw();
137 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
141 data.definitionPoint = mouse;
143 // DimLinear * dim = new DimLinear(preview, data, edata);
145 // preview->addEntity(dim);
147 graphicView->preview.clear();
149 DimLinear * dim = new DimLinear(&(graphicView->preview), data, edata);
151 graphicView->preview.addEntity(dim);
152 graphicView->preview.SetVisible();
153 graphicView->redraw();
159 DEBUG->print("ActionDimLinear::mouseMoveEvent end");
162 void ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
164 if (e->button() == Qt::LeftButton)
166 Vector ce(snapPoint(e));
167 coordinateEvent(&ce);
168 graphicView->snapper.SetVisible();
170 else if (e->button() == Qt::RightButton)
172 if (getStatus() == 0)
174 graphicView->preview.SetVisible(false);
175 graphicView->snapper.SetVisible(false);
180 init(getStatus() - 1);
184 void ActionDimLinear::coordinateEvent(Vector * e)
194 edata.extensionPoint1 = pos;
195 graphicView->moveRelativeZero(pos);
196 setStatus(SetExtPoint2);
200 edata.extensionPoint2 = pos;
201 graphicView->moveRelativeZero(pos);
202 setStatus(SetDefPoint);
206 data.definitionPoint = pos;
209 setStatus(SetExtPoint1);
217 void ActionDimLinear::commandEvent(CommandEvent * e)
219 QString c = e->getCommand().toLower();
221 if (checkCommand("help", c))
224 DIALOGFACTORY->commandMessage(msgAvailableCommands()
225 + getAvailableCommands().join(", "));
235 DIALOGFACTORY->requestOptions(this, true, true);
237 graphicView->enableCoordinateInput();
238 setStatus(lastStatus);
244 double a = Math::eval(c, &ok);
247 setAngle(Math::deg2rad(a));
248 else if (DIALOGFACTORY)
249 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
252 DIALOGFACTORY->requestOptions(this, true, true);
254 setStatus(lastStatus);
259 lastStatus = (Status)getStatus();
264 if (checkCommand("text", c))
266 graphicView->disableCoordinateInput();
270 else if (!fixedAngle && (checkCommand("angle", c)))
277 QStringList ActionDimLinear::getAvailableCommands()
286 cmd += command("text");
289 cmd += command("angle");
300 void ActionDimLinear::updateMouseButtonHints()
307 DIALOGFACTORY->updateMouseWidget(
308 tr("Specify first extension line origin"), tr("Cancel"));
312 DIALOGFACTORY->updateMouseWidget(
313 tr("Specify second extension line origin"), tr("Back"));
317 DIALOGFACTORY->updateMouseWidget(
318 tr("Specify dimension line location"), tr("Back"));
322 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
326 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension line angle:"), "");
330 DIALOGFACTORY->updateMouseWidget("", "");
336 void ActionDimLinear::showOptions()
338 ActionInterface::showOptions();
341 DIALOGFACTORY->requestOptions(this, true, true);
344 void ActionDimLinear::hideOptions()
346 ActionInterface::hideOptions();
349 DIALOGFACTORY->requestOptions(this, false);
352 double ActionDimLinear::getAngle()
357 void ActionDimLinear::setAngle(double a)
362 bool ActionDimLinear::hasFixedAngle()