]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondimaligned.cpp
Initial removal of unnecessary rs_ prefixes from files.
[architektonas] / src / actions / actiondimaligned.cpp
1 // actiondimaligned.cpp
2 //
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
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/03/2010  Added this text. :-)
15 //
16
17 #include "actiondimaligned.h"
18
19 #include "commandevent.h"
20 #include "constructionline.h"
21 #include "debug.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
24 #include "preview.h"
25 #include "snapper.h"
26
27 ActionDimAligned::ActionDimAligned(RS_EntityContainer & container, GraphicView & graphicView): ActionDimension("Draw aligned dimensions",
28                 container, graphicView)
29 {
30         reset();
31 }
32
33 ActionDimAligned::~ActionDimAligned()
34 {
35 }
36
37 /*virtual*/ RS2::ActionType ActionDimAligned::rtti()
38 {
39         return RS2::ActionDimAligned;
40 }
41
42 void ActionDimAligned::reset()
43 {
44         ActionDimension::reset();
45         edata = RS_DimAlignedData(Vector(false), Vector(false));
46         lastStatus = SetExtPoint1;
47
48         if (RS_DIALOGFACTORY != NULL)
49                 RS_DIALOGFACTORY->requestOptions(this, true, true);
50 }
51
52 void ActionDimAligned::trigger()
53 {
54         ActionDimension::trigger();
55         preparePreview();
56         graphicView->moveRelativeZero(data.definitionPoint);
57
58         //data.text = getText();
59         RS_DimAligned * dim = new RS_DimAligned(container, data, edata);
60         dim->setLayerToActive();
61         dim->setPenToActive();
62         dim->update();
63         container->addEntity(dim);
64
65         // upd. undo list:
66         if (document != NULL)
67         {
68                 document->startUndoCycle();
69                 document->addUndoable(dim);
70                 document->endUndoCycle();
71         }
72
73         deleteSnapper();
74         Vector rz = graphicView->getRelativeZero();
75         graphicView->moveRelativeZero(Vector(0.0, 0.0));
76         graphicView->drawEntity(dim);
77         graphicView->moveRelativeZero(rz);
78         drawSnapper();
79
80         RS_DEBUG->print("ActionDimAligned::trigger(): dim added: %d", dim->getId());
81 }
82
83 void ActionDimAligned::preparePreview()
84 {
85         Vector dirV;
86         dirV.setPolar(100.0, edata.extensionPoint1.angleTo(edata.extensionPoint2) + M_PI / 2.0);
87         RS_ConstructionLine cl(NULL, RS_ConstructionLineData(edata.extensionPoint2,
88                 edata.extensionPoint2 + dirV));
89         data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint);
90 }
91
92 void ActionDimAligned::mouseMoveEvent(QMouseEvent * e)
93 {
94         RS_DEBUG->print("ActionDimAligned::mouseMoveEvent begin");
95         Vector mouse = snapPoint(e);
96
97         switch (getStatus())
98         {
99         case SetExtPoint1:
100                 break;
101
102         case SetExtPoint2:
103
104                 if (edata.extensionPoint1.valid)
105                 {
106                         deletePreview();
107                         clearPreview();
108 //                      preview->addEntity(new RS_Line(preview, RS_LineData(edata.extensionPoint1, mouse)));
109                         drawPreview();
110                 }
111                 break;
112
113         case SetDefPoint:
114
115                 if (edata.extensionPoint1.valid && edata.extensionPoint2.valid)
116                 {
117                         deletePreview();
118                         clearPreview();
119                         data.definitionPoint = mouse;
120
121                         preparePreview();
122
123                         //data.text = getText();
124 //                      RS_DimAligned * dim = new RS_DimAligned(preview, data, edata);
125 //                      dim->update();
126 //                      preview->addEntity(dim);
127                         drawPreview();
128                 }
129                 break;
130
131         default:
132                 break;
133         }
134
135         RS_DEBUG->print("ActionDimAligned::mouseMoveEvent end");
136 }
137
138 void ActionDimAligned::mouseReleaseEvent(QMouseEvent * e)
139 {
140 //      if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
141         if (e->button() == Qt::LeftButton)
142         {
143                 Vector ce(snapPoint(e));
144                 coordinateEvent(&ce);
145         }
146 //      else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
147         else if (e->button() == Qt::RightButton)
148         {
149                 deletePreview();
150                 deleteSnapper();
151                 init(getStatus() - 1);
152         }
153 }
154
155 void ActionDimAligned::coordinateEvent(Vector * e)
156 {
157         if (e == NULL)
158                 return;
159
160         Vector pos = *e; //->getCoordinate();
161
162         switch (getStatus())
163         {
164         case SetExtPoint1:
165                 edata.extensionPoint1 = pos;
166                 graphicView->moveRelativeZero(pos);
167                 setStatus(SetExtPoint2);
168                 break;
169
170         case SetExtPoint2:
171                 edata.extensionPoint2 = pos;
172                 graphicView->moveRelativeZero(pos);
173                 setStatus(SetDefPoint);
174                 break;
175
176         case SetDefPoint:
177                 data.definitionPoint = pos;
178                 trigger();
179                 reset();
180                 setStatus(SetExtPoint1);
181                 break;
182
183         default:
184                 break;
185         }
186 }
187
188 void ActionDimAligned::commandEvent(RS_CommandEvent * e)
189 {
190         QString c = e->getCommand().toLower();
191
192         if (checkCommand("help", c))
193         {
194                 if (RS_DIALOGFACTORY != NULL)
195                         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
196                                 + getAvailableCommands().join(", "));
197
198                 return;
199         }
200
201         switch (getStatus())
202         {
203         case SetText:
204                 setText(c);
205
206                 if (RS_DIALOGFACTORY != NULL)
207                         RS_DIALOGFACTORY->requestOptions(this, true, true);
208
209                 setStatus(lastStatus);
210                 graphicView->enableCoordinateInput();
211                 break;
212
213         default:
214
215                 if (checkCommand("text", c))
216                 {
217                         lastStatus = (Status)getStatus();
218                         graphicView->disableCoordinateInput();
219                         setStatus(SetText);
220                 }
221                 break;
222         }
223 }
224
225 QStringList ActionDimAligned::getAvailableCommands()
226 {
227         QStringList cmd;
228
229         switch (getStatus())
230         {
231         case SetExtPoint1:
232         case SetExtPoint2:
233         case SetDefPoint:
234                 cmd += command("text");
235                 break;
236
237         default:
238                 break;
239         }
240
241         return cmd;
242 }
243
244 void ActionDimAligned::updateMouseButtonHints()
245 {
246         if (RS_DIALOGFACTORY != NULL)
247         {
248                 switch (getStatus())
249                 {
250                 case SetExtPoint1:
251                         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first extension line origin"), tr("Cancel"));
252                         break;
253
254                 case SetExtPoint2:
255                         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second extension line origin"), tr("Back"));
256                         break;
257
258                 case SetDefPoint:
259                         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify dimension line location"), tr("Back"));
260                         break;
261
262                 case SetText:
263                         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
264                         break;
265
266                 default:
267                         RS_DIALOGFACTORY->updateMouseWidget("", "");
268                         break;
269                 }
270         }
271 }
272
273 void ActionDimAligned::hideOptions()
274 {
275         if (RS_DIALOGFACTORY != NULL)
276                 RS_DIALOGFACTORY->requestOptions(this, false);
277
278         ActionDimension::hideOptions();
279 }
280
281 void ActionDimAligned::showOptions()
282 {
283         ActionDimension::showOptions();
284
285         if (RS_DIALOGFACTORY != NULL)
286                 RS_DIALOGFACTORY->requestOptions(this, true);
287 }
288