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();
42 graphicView.SetSnapperVisible();
46 ActionDimLinear::~ActionDimLinear()
50 /*virtual*/ RS2::ActionType ActionDimLinear::rtti()
52 return RS2::ActionDimLinear;
55 void ActionDimLinear::reset()
57 ActionDimension::reset();
58 edata = DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0);
61 DIALOGFACTORY->requestOptions(this, true, true);
64 void ActionDimLinear::trigger()
66 ActionDimension::trigger();
68 DimLinear * dim = new DimLinear(container, data, edata);
69 dim->setLayerToActive();
70 dim->setPenToActive();
72 container->addEntity(dim);
77 document->startUndoCycle();
78 document->addUndoable(dim);
79 document->endUndoCycle();
83 // Vector rz = graphicView->getRelativeZero();
84 // graphicView->moveRelativeZero(Vector(0.0, 0.0));
85 // graphicView->drawEntity(dim);
86 // graphicView->moveRelativeZero(rz);
88 graphicView->SetSnapperVisible(false);
89 graphicView->redraw();
91 DEBUG->print("ActionDimLinear::trigger(): dim added: %d", dim->getId());
94 void ActionDimLinear::preparePreview()
97 dirV.setPolar(100.0, edata.angle + M_PI / 2.0);
99 ConstructionLine cl(NULL, ConstructionLineData(edata.extensionPoint2,
100 edata.extensionPoint2 + dirV));
102 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
105 void ActionDimLinear::mouseMoveEvent(QMouseEvent * e)
107 DEBUG->print("ActionDimLinear::mouseMoveEvent begin");
109 Vector mouse = snapPoint(e);
114 // graphicView->snapper.SetVisible();
115 // graphicView->redraw();
120 if (edata.extensionPoint1.valid)
124 // preview->addEntity(new Line(preview,
125 // LineData(edata.extensionPoint1, mouse)));
127 graphicView->preview.clear();
128 graphicView->preview.addEntity(new Line(&(graphicView->preview),
129 LineData(edata.extensionPoint1, mouse)));
130 graphicView->preview.SetVisible();
131 graphicView->redraw();
138 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
142 data.definitionPoint = mouse;
144 // DimLinear * dim = new DimLinear(preview, data, edata);
146 // preview->addEntity(dim);
148 graphicView->preview.clear();
150 DimLinear * dim = new DimLinear(&(graphicView->preview), data, edata);
152 graphicView->preview.addEntity(dim);
153 graphicView->preview.SetVisible();
154 graphicView->redraw();
160 DEBUG->print("ActionDimLinear::mouseMoveEvent end");
163 void ActionDimLinear::mouseReleaseEvent(QMouseEvent * e)
165 if (e->button() == Qt::LeftButton)
167 Vector ce(snapPoint(e));
168 coordinateEvent(&ce);
169 // graphicView->snapper.SetVisible();
170 graphicView->SetSnapperVisible();
172 else if (e->button() == Qt::RightButton)
174 if (getStatus() == 0)
176 graphicView->preview.SetVisible(false);
177 // graphicView->snapper.SetVisible(false);
178 graphicView->SetSnapperVisible(false);
183 init(getStatus() - 1);
187 void ActionDimLinear::coordinateEvent(Vector * e)
197 edata.extensionPoint1 = pos;
198 graphicView->moveRelativeZero(pos);
199 setStatus(SetExtPoint2);
203 edata.extensionPoint2 = pos;
204 graphicView->moveRelativeZero(pos);
205 setStatus(SetDefPoint);
209 data.definitionPoint = pos;
212 setStatus(SetExtPoint1);
220 void ActionDimLinear::commandEvent(CommandEvent * e)
222 QString c = e->getCommand().toLower();
224 if (checkCommand("help", c))
227 DIALOGFACTORY->commandMessage(msgAvailableCommands()
228 + getAvailableCommands().join(", "));
238 DIALOGFACTORY->requestOptions(this, true, true);
240 graphicView->enableCoordinateInput();
241 setStatus(lastStatus);
247 double a = Math::eval(c, &ok);
250 setAngle(Math::deg2rad(a));
251 else if (DIALOGFACTORY)
252 DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
255 DIALOGFACTORY->requestOptions(this, true, true);
257 setStatus(lastStatus);
262 lastStatus = (Status)getStatus();
267 if (checkCommand("text", c))
269 graphicView->disableCoordinateInput();
273 else if (!fixedAngle && (checkCommand("angle", c)))
280 QStringList ActionDimLinear::getAvailableCommands()
289 cmd += command("text");
292 cmd += command("angle");
303 void ActionDimLinear::updateMouseButtonHints()
310 DIALOGFACTORY->updateMouseWidget(
311 tr("Specify first extension line origin"), tr("Cancel"));
315 DIALOGFACTORY->updateMouseWidget(
316 tr("Specify second extension line origin"), tr("Back"));
320 DIALOGFACTORY->updateMouseWidget(
321 tr("Specify dimension line location"), tr("Back"));
325 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
329 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension line angle:"), "");
333 DIALOGFACTORY->updateMouseWidget("", "");
339 void ActionDimLinear::showOptions()
341 ActionInterface::showOptions();
344 DIALOGFACTORY->requestOptions(this, true, true);
347 void ActionDimLinear::hideOptions()
349 ActionInterface::hideOptions();
352 DIALOGFACTORY->requestOptions(this, false);
355 double ActionDimLinear::getAngle()
360 void ActionDimLinear::setAngle(double a)
365 bool ActionDimLinear::hasFixedAngle()