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"
26 ActionDimAligned::ActionDimAligned(EntityContainer & container, GraphicView & graphicView): ActionDimension("Draw aligned dimensions",
27 container, graphicView)
32 ActionDimAligned::~ActionDimAligned()
36 /*virtual*/ RS2::ActionType ActionDimAligned::rtti()
38 return RS2::ActionDimAligned;
41 void ActionDimAligned::reset()
43 ActionDimension::reset();
44 edata = DimAlignedData(Vector(false), Vector(false));
45 lastStatus = SetExtPoint1;
47 if (DIALOGFACTORY != NULL)
48 DIALOGFACTORY->requestOptions(this, true, true);
51 void ActionDimAligned::trigger()
53 ActionDimension::trigger();
55 graphicView->moveRelativeZero(data.definitionPoint);
57 //data.text = getText();
58 DimAligned * dim = new DimAligned(container, data, edata);
59 dim->setLayerToActive();
60 dim->setPenToActive();
62 container->addEntity(dim);
67 document->startUndoCycle();
68 document->addUndoable(dim);
69 document->endUndoCycle();
73 Vector rz = graphicView->getRelativeZero();
74 graphicView->moveRelativeZero(Vector(0.0, 0.0));
75 graphicView->drawEntity(dim);
76 graphicView->moveRelativeZero(rz);
79 DEBUG->print("ActionDimAligned::trigger(): dim added: %d", dim->getId());
82 void ActionDimAligned::preparePreview()
85 dirV.setPolar(100.0, edata.extensionPoint1.angleTo(edata.extensionPoint2) + M_PI / 2.0);
86 ConstructionLine cl(NULL, ConstructionLineData(edata.extensionPoint2,
87 edata.extensionPoint2 + dirV));
88 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
91 void ActionDimAligned::mouseMoveEvent(QMouseEvent * e)
93 DEBUG->print("ActionDimAligned::mouseMoveEvent begin");
94 Vector mouse = snapPoint(e);
103 if (edata.extensionPoint1.valid)
107 // preview->addEntity(new Line(preview, LineData(edata.extensionPoint1, mouse)));
114 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
118 data.definitionPoint = mouse;
122 //data.text = getText();
123 // DimAligned * dim = new DimAligned(preview, data, edata);
125 // preview->addEntity(dim);
134 DEBUG->print("ActionDimAligned::mouseMoveEvent end");
137 void ActionDimAligned::mouseReleaseEvent(QMouseEvent * e)
139 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
140 if (e->button() == Qt::LeftButton)
142 Vector ce(snapPoint(e));
143 coordinateEvent(&ce);
145 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
146 else if (e->button() == Qt::RightButton)
150 init(getStatus() - 1);
154 void ActionDimAligned::coordinateEvent(Vector * e)
159 Vector pos = *e; //->getCoordinate();
164 edata.extensionPoint1 = pos;
165 graphicView->moveRelativeZero(pos);
166 setStatus(SetExtPoint2);
170 edata.extensionPoint2 = pos;
171 graphicView->moveRelativeZero(pos);
172 setStatus(SetDefPoint);
176 data.definitionPoint = pos;
179 setStatus(SetExtPoint1);
187 void ActionDimAligned::commandEvent(CommandEvent * e)
189 QString c = e->getCommand().toLower();
191 if (checkCommand("help", c))
193 if (DIALOGFACTORY != NULL)
194 DIALOGFACTORY->commandMessage(msgAvailableCommands()
195 + getAvailableCommands().join(", "));
205 if (DIALOGFACTORY != NULL)
206 DIALOGFACTORY->requestOptions(this, true, true);
208 setStatus(lastStatus);
209 graphicView->enableCoordinateInput();
214 if (checkCommand("text", c))
216 lastStatus = (Status)getStatus();
217 graphicView->disableCoordinateInput();
224 QStringList ActionDimAligned::getAvailableCommands()
233 cmd += command("text");
243 void ActionDimAligned::updateMouseButtonHints()
245 if (DIALOGFACTORY != NULL)
250 DIALOGFACTORY->updateMouseWidget(tr("Specify first extension line origin"), tr("Cancel"));
254 DIALOGFACTORY->updateMouseWidget(tr("Specify second extension line origin"), tr("Back"));
258 DIALOGFACTORY->updateMouseWidget(tr("Specify dimension line location"), tr("Back"));
262 DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
266 DIALOGFACTORY->updateMouseWidget("", "");
272 void ActionDimAligned::hideOptions()
274 if (DIALOGFACTORY != NULL)
275 DIALOGFACTORY->requestOptions(this, false);
277 ActionDimension::hideOptions();
280 void ActionDimAligned::showOptions()
282 ActionDimension::showOptions();
284 if (DIALOGFACTORY != NULL)
285 DIALOGFACTORY->requestOptions(this, true);