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_constructionline.h"
18 #include "rs_dialogfactory.h"
19 #include "rs_graphicview.h"
20 #include "rs_preview.h"
21 #include "rs_snapper.h"
23 RS_ActionDimAligned::RS_ActionDimAligned(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw aligned dimensions",
24 container, graphicView)
29 RS_ActionDimAligned::~RS_ActionDimAligned()
33 /*virtual*/ RS2::ActionType RS_ActionDimAligned::rtti()
35 return RS2::ActionDimAligned;
38 void RS_ActionDimAligned::reset()
40 RS_ActionDimension::reset();
41 edata = RS_DimAlignedData(Vector(false), Vector(false));
42 lastStatus = SetExtPoint1;
44 if (RS_DIALOGFACTORY != NULL)
45 RS_DIALOGFACTORY->requestOptions(this, true, true);
48 void RS_ActionDimAligned::trigger()
50 RS_ActionDimension::trigger();
52 graphicView->moveRelativeZero(data.definitionPoint);
54 //data.text = getText();
55 RS_DimAligned * dim = new RS_DimAligned(container, data, edata);
56 dim->setLayerToActive();
57 dim->setPenToActive();
59 container->addEntity(dim);
64 document->startUndoCycle();
65 document->addUndoable(dim);
66 document->endUndoCycle();
70 Vector rz = graphicView->getRelativeZero();
71 graphicView->moveRelativeZero(Vector(0.0, 0.0));
72 graphicView->drawEntity(dim);
73 graphicView->moveRelativeZero(rz);
76 RS_DEBUG->print("RS_ActionDimAligned::trigger(): dim added: %d", dim->getId());
79 void RS_ActionDimAligned::preparePreview()
82 dirV.setPolar(100.0, edata.extensionPoint1.angleTo(edata.extensionPoint2) + M_PI / 2.0);
83 RS_ConstructionLine cl(NULL, RS_ConstructionLineData(edata.extensionPoint2,
84 edata.extensionPoint2 + dirV));
85 data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
88 void RS_ActionDimAligned::mouseMoveEvent(QMouseEvent * e)
90 RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent begin");
91 Vector mouse = snapPoint(e);
100 if (edata.extensionPoint1.valid)
104 preview->addEntity(new RS_Line(preview,
105 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("RS_ActionDimAligned::mouseMoveEvent end");
135 void RS_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 RS_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 RS_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 RS_ActionDimAligned::getAvailableCommands()
231 cmd += command("text");
241 void RS_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 RS_ActionDimAligned::hideOptions()
272 if (RS_DIALOGFACTORY != NULL)
273 RS_DIALOGFACTORY->requestOptions(this, false);
275 RS_ActionDimension::hideOptions();
278 void RS_ActionDimAligned::showOptions()
280 RS_ActionDimension::showOptions();
282 if (RS_DIALOGFACTORY != NULL)
283 RS_DIALOGFACTORY->requestOptions(this, true);