1 // rs_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 "rs_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 RS_ActionDimAligned::RS_ActionDimAligned(RS_EntityContainer & container, GraphicView & graphicView): RS_ActionDimension("Draw aligned dimensions",
25 container, graphicView)
30 RS_ActionDimAligned::~RS_ActionDimAligned()
34 /*virtual*/ RS2::ActionType RS_ActionDimAligned::rtti()
36 return RS2::ActionDimAligned;
39 void RS_ActionDimAligned::reset()
41 RS_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 RS_ActionDimAligned::trigger()
51 RS_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("RS_ActionDimAligned::trigger(): dim added: %d", dim->getId());
80 void RS_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 RS_ActionDimAligned::mouseMoveEvent(QMouseEvent * e)
91 RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent begin");
92 Vector mouse = snapPoint(e);
101 if (edata.extensionPoint1.valid)
105 preview->addEntity(new RS_Line(preview,
106 RS_LineData(edata.extensionPoint1, mouse)));
113 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
117 data.definitionPoint = mouse;
121 //data.text = getText();
122 RS_DimAligned * dim = new RS_DimAligned(preview, data, edata);
124 preview->addEntity(dim);
133 RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent end");
136 void RS_ActionDimAligned::mouseReleaseEvent(QMouseEvent * e)
138 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
139 if (e->button() == Qt::LeftButton)
141 Vector ce(snapPoint(e));
142 coordinateEvent(&ce);
144 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
145 else if (e->button() == Qt::RightButton)
149 init(getStatus() - 1);
153 void RS_ActionDimAligned::coordinateEvent(Vector * e)
158 Vector pos = *e; //->getCoordinate();
163 edata.extensionPoint1 = pos;
164 graphicView->moveRelativeZero(pos);
165 setStatus(SetExtPoint2);
169 edata.extensionPoint2 = pos;
170 graphicView->moveRelativeZero(pos);
171 setStatus(SetDefPoint);
175 data.definitionPoint = pos;
178 setStatus(SetExtPoint1);
186 void RS_ActionDimAligned::commandEvent(RS_CommandEvent * e)
188 QString c = e->getCommand().toLower();
190 if (checkCommand("help", c))
192 if (RS_DIALOGFACTORY != NULL)
193 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
194 + getAvailableCommands().join(", "));
204 if (RS_DIALOGFACTORY != NULL)
205 RS_DIALOGFACTORY->requestOptions(this, true, true);
207 setStatus(lastStatus);
208 graphicView->enableCoordinateInput();
213 if (checkCommand("text", c))
215 lastStatus = (Status)getStatus();
216 graphicView->disableCoordinateInput();
223 QStringList RS_ActionDimAligned::getAvailableCommands()
232 cmd += command("text");
242 void RS_ActionDimAligned::updateMouseButtonHints()
244 if (RS_DIALOGFACTORY != NULL)
249 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first extension line origin"), tr("Cancel"));
253 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second extension line origin"), tr("Back"));
257 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify dimension line location"), tr("Back"));
261 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
265 RS_DIALOGFACTORY->updateMouseWidget("", "");
271 void RS_ActionDimAligned::hideOptions()
273 if (RS_DIALOGFACTORY != NULL)
274 RS_DIALOGFACTORY->requestOptions(this, false);
276 RS_ActionDimension::hideOptions();
279 void RS_ActionDimAligned::showOptions()
281 RS_ActionDimension::showOptions();
283 if (RS_DIALOGFACTORY != NULL)
284 RS_DIALOGFACTORY->requestOptions(this, true);