1 // actiondimaligned.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 // 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 06/03/2010 Added this text. :-)
17 #include "actiondimaligned.h"
19 #include "commandevent.h"
20 #include "constructionline.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
27 ActionDimAligned::ActionDimAligned(EntityContainer & container, GraphicView & graphicView): ActionDimension("Draw aligned dimensions",
28 container, graphicView)
33 ActionDimAligned::~ActionDimAligned()
37 /*virtual*/ RS2::ActionType ActionDimAligned::rtti()
39 return RS2::ActionDimAligned;
42 void ActionDimAligned::reset()
44 ActionDimension::reset();
45 edata = DimAlignedData(Vector(false), Vector(false));
46 lastStatus = SetExtPoint1;
48 if (DIALOGFACTORY != NULL)
49 DIALOGFACTORY->requestOptions(this, true, true);
52 void ActionDimAligned::trigger()
54 ActionDimension::trigger();
56 graphicView->moveRelativeZero(data.definitionPoint);
58 //data.text = getText();
59 DimAligned * dim = new DimAligned(container, data, edata);
60 dim->setLayerToActive();
61 dim->setPenToActive();
63 container->addEntity(dim);
68 document->startUndoCycle();
69 document->addUndoable(dim);
70 document->endUndoCycle();
74 Vector rz = graphicView->getRelativeZero();
75 graphicView->moveRelativeZero(Vector(0.0, 0.0));
76 graphicView->drawEntity(dim);
77 graphicView->moveRelativeZero(rz);
80 DEBUG->print("ActionDimAligned::trigger(): dim added: %d", dim->getId());
83 void ActionDimAligned::preparePreview()
86 dirV.setPolar(100.0, edata.extensionPoint1.angleTo(edata.extensionPoint2) + M_PI / 2.0);
87 ConstructionLine cl(NULL, ConstructionLineData(edata.extensionPoint2,
88 edata.extensionPoint2 + dirV));
89 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
92 void ActionDimAligned::mouseMoveEvent(QMouseEvent * e)
94 DEBUG->print("ActionDimAligned::mouseMoveEvent begin");
95 Vector mouse = snapPoint(e);
104 if (edata.extensionPoint1.valid)
108 // preview->addEntity(new Line(preview, LineData(edata.extensionPoint1, mouse)));
115 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
119 data.definitionPoint = mouse;
123 //data.text = getText();
124 // DimAligned * dim = new DimAligned(preview, data, edata);
126 // preview->addEntity(dim);
135 DEBUG->print("ActionDimAligned::mouseMoveEvent end");
138 void ActionDimAligned::mouseReleaseEvent(QMouseEvent * e)
140 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
141 if (e->button() == Qt::LeftButton)
143 Vector ce(snapPoint(e));
144 coordinateEvent(&ce);
146 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
147 else if (e->button() == Qt::RightButton)
151 init(getStatus() - 1);
155 void ActionDimAligned::coordinateEvent(Vector * e)
160 Vector pos = *e; //->getCoordinate();
165 edata.extensionPoint1 = pos;
166 graphicView->moveRelativeZero(pos);
167 setStatus(SetExtPoint2);
171 edata.extensionPoint2 = pos;
172 graphicView->moveRelativeZero(pos);
173 setStatus(SetDefPoint);
177 data.definitionPoint = pos;
180 setStatus(SetExtPoint1);
188 void ActionDimAligned::commandEvent(CommandEvent * e)
190 QString c = e->getCommand().toLower();
192 if (checkCommand("help", c))
194 if (DIALOGFACTORY != NULL)
195 DIALOGFACTORY->commandMessage(msgAvailableCommands()
196 + getAvailableCommands().join(", "));
206 if (DIALOGFACTORY != NULL)
207 DIALOGFACTORY->requestOptions(this, true, true);
209 setStatus(lastStatus);
210 graphicView->enableCoordinateInput();
215 if (checkCommand("text", c))
217 lastStatus = (Status)getStatus();
218 graphicView->disableCoordinateInput();
225 QStringList ActionDimAligned::getAvailableCommands()
234 cmd += command("text");
244 void ActionDimAligned::updateMouseButtonHints()
246 if (DIALOGFACTORY != NULL)
251 DIALOGFACTORY->updateMouseWidget(tr("Specify first extension line origin"), tr("Cancel"));
255 DIALOGFACTORY->updateMouseWidget(tr("Specify second extension line origin"), tr("Back"));
259 DIALOGFACTORY->updateMouseWidget(tr("Specify dimension line location"), tr("Back"));
263 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
267 DIALOGFACTORY->updateMouseWidget("", "");
273 void ActionDimAligned::hideOptions()
275 if (DIALOGFACTORY != NULL)
276 DIALOGFACTORY->requestOptions(this, false);
278 ActionDimension::hideOptions();
281 void ActionDimAligned::showOptions()
283 ActionDimension::showOptions();
285 if (DIALOGFACTORY != NULL)
286 DIALOGFACTORY->requestOptions(this, true);