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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 06/03/2010 Added this text. :-)
15 #include "actiondimaligned.h"
17 #include "rs_commandevent.h"
18 #include "rs_constructionline.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_preview.h"
22 #include "rs_snapper.h"
24 ActionDimAligned::ActionDimAligned(RS_EntityContainer & container, GraphicView & graphicView): ActionDimension("Draw aligned dimensions",
25 container, graphicView)
30 ActionDimAligned::~ActionDimAligned()
34 /*virtual*/ RS2::ActionType ActionDimAligned::rtti()
36 return RS2::ActionDimAligned;
39 void ActionDimAligned::reset()
41 ActionDimension::reset();
42 edata = RS_DimAlignedData(Vector(false), Vector(false));
43 lastStatus = SetExtPoint1;
45 if (RS_DIALOGFACTORY != NULL)
46 RS_DIALOGFACTORY->requestOptions(this, true, true);
49 void ActionDimAligned::trigger()
51 ActionDimension::trigger();
53 graphicView->moveRelativeZero(data.definitionPoint);
55 //data.text = getText();
56 RS_DimAligned * dim = new RS_DimAligned(container, data, edata);
57 dim->setLayerToActive();
58 dim->setPenToActive();
60 container->addEntity(dim);
65 document->startUndoCycle();
66 document->addUndoable(dim);
67 document->endUndoCycle();
71 Vector rz = graphicView->getRelativeZero();
72 graphicView->moveRelativeZero(Vector(0.0, 0.0));
73 graphicView->drawEntity(dim);
74 graphicView->moveRelativeZero(rz);
77 RS_DEBUG->print("ActionDimAligned::trigger(): dim added: %d", dim->getId());
80 void ActionDimAligned::preparePreview()
83 dirV.setPolar(100.0, edata.extensionPoint1.angleTo(edata.extensionPoint2) + M_PI / 2.0);
84 RS_ConstructionLine cl(NULL, RS_ConstructionLineData(edata.extensionPoint2,
85 edata.extensionPoint2 + dirV));
86 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
89 void ActionDimAligned::mouseMoveEvent(QMouseEvent * e)
91 RS_DEBUG->print("ActionDimAligned::mouseMoveEvent begin");
92 Vector mouse = snapPoint(e);
101 if (edata.extensionPoint1.valid)
105 // preview->addEntity(new RS_Line(preview, RS_LineData(edata.extensionPoint1, mouse)));
112 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
116 data.definitionPoint = mouse;
120 //data.text = getText();
121 // RS_DimAligned * dim = new RS_DimAligned(preview, data, edata);
123 // preview->addEntity(dim);
132 RS_DEBUG->print("ActionDimAligned::mouseMoveEvent end");
135 void ActionDimAligned::mouseReleaseEvent(QMouseEvent * e)
137 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
138 if (e->button() == Qt::LeftButton)
140 Vector ce(snapPoint(e));
141 coordinateEvent(&ce);
143 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
144 else if (e->button() == Qt::RightButton)
148 init(getStatus() - 1);
152 void ActionDimAligned::coordinateEvent(Vector * e)
157 Vector pos = *e; //->getCoordinate();
162 edata.extensionPoint1 = pos;
163 graphicView->moveRelativeZero(pos);
164 setStatus(SetExtPoint2);
168 edata.extensionPoint2 = pos;
169 graphicView->moveRelativeZero(pos);
170 setStatus(SetDefPoint);
174 data.definitionPoint = pos;
177 setStatus(SetExtPoint1);
185 void ActionDimAligned::commandEvent(RS_CommandEvent * e)
187 QString c = e->getCommand().toLower();
189 if (checkCommand("help", c))
191 if (RS_DIALOGFACTORY != NULL)
192 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
193 + getAvailableCommands().join(", "));
203 if (RS_DIALOGFACTORY != NULL)
204 RS_DIALOGFACTORY->requestOptions(this, true, true);
206 setStatus(lastStatus);
207 graphicView->enableCoordinateInput();
212 if (checkCommand("text", c))
214 lastStatus = (Status)getStatus();
215 graphicView->disableCoordinateInput();
222 QStringList ActionDimAligned::getAvailableCommands()
231 cmd += command("text");
241 void ActionDimAligned::updateMouseButtonHints()
243 if (RS_DIALOGFACTORY != NULL)
248 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first extension line origin"), tr("Cancel"));
252 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second extension line origin"), tr("Back"));
256 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify dimension line location"), tr("Back"));
260 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
264 RS_DIALOGFACTORY->updateMouseWidget("", "");
270 void ActionDimAligned::hideOptions()
272 if (RS_DIALOGFACTORY != NULL)
273 RS_DIALOGFACTORY->requestOptions(this, false);
275 ActionDimension::hideOptions();
278 void ActionDimAligned::showOptions()
280 ActionDimension::showOptions();
282 if (RS_DIALOGFACTORY != NULL)
283 RS_DIALOGFACTORY->requestOptions(this, true);