]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifymoverotate.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actionmodifymoverotate.cpp
1 // actionmodifymoverotate.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/04/2010  Added this text. :-)
15 //
16
17 #include "actionmodifymoverotate.h"
18
19 #include "commandevent.h"
20 #include "debug.h"
21 #include "dialogfactory.h"
22 #include "preview.h"
23
24 ActionModifyMoveRotate::ActionModifyMoveRotate(
25         EntityContainer & container, GraphicView & graphicView):
26         ActionInterface("Move and Rotate Entities", container, graphicView)
27 {
28 }
29
30 ActionModifyMoveRotate::~ActionModifyMoveRotate()
31 {
32 }
33
34 /*virtual*/ RS2::ActionType ActionModifyMoveRotate::rtti()
35 {
36         return RS2::ActionModifyMoveRotate;
37 }
38
39 void ActionModifyMoveRotate::init(int status)
40 {
41         ActionInterface::init(status);
42 }
43
44 void ActionModifyMoveRotate::trigger()
45 {
46         DEBUG->print("ActionModifyMoveRotate::trigger()");
47
48         Modification m(*container, graphicView);
49         m.moveRotate(data);
50
51         finish();
52
53         DIALOGFACTORY->updateSelectionWidget(container->countSelected());
54 }
55
56 void ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
57 {
58         DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent begin");
59
60         if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint)
61         {
62                 Vector mouse = snapPoint(e);
63
64                 switch (getStatus())
65                 {
66                 case SetReferencePoint:
67                         data.referencePoint = mouse;
68                         break;
69
70                 case SetTargetPoint:
71
72                         if (data.referencePoint.valid)
73                         {
74                                 targetPoint = mouse;
75                                 data.offset = targetPoint - data.referencePoint;
76
77                                 deletePreview();
78                                 clearPreview();
79 /*                              preview->addSelectionFrom(*container);
80                                 preview->rotate(data.referencePoint, data.angle);
81                                 preview->move(data.offset);*/
82                                 drawPreview();
83                         }
84                         break;
85
86                 default:
87                         break;
88                 }
89         }
90
91         DEBUG->print("ActionModifyMoveRotate::mouseMoveEvent end");
92 }
93
94 void ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e)
95 {
96         if (e->button() == Qt::LeftButton)
97         {
98                 Vector ce(snapPoint(e));
99                 coordinateEvent(&ce);
100         }
101         else if (e->button() == Qt::RightButton)
102         {
103                 deletePreview();
104                 deleteSnapper();
105                 init(getStatus() - 1);
106         }
107 }
108
109 void ActionModifyMoveRotate::coordinateEvent(Vector * e)
110 {
111         if (e == NULL)
112                 return;
113
114         Vector pos = *e;
115
116         switch (getStatus())
117         {
118         case SetReferencePoint:
119                 data.referencePoint = pos;
120                 setStatus(SetTargetPoint);
121                 break;
122
123         case SetTargetPoint:
124                 targetPoint = pos;
125
126                 setStatus(ShowDialog);
127                 data.offset = targetPoint - data.referencePoint;
128
129                 if (DIALOGFACTORY->requestMoveRotateDialog(data))
130                         trigger();
131                         //finish();
132                 break;
133
134         default:
135                 break;
136         }
137 }
138
139 void ActionModifyMoveRotate::commandEvent(CommandEvent * e)
140 {
141         QString c = e->getCommand().toLower();
142
143         if (checkCommand("help", c))
144         {
145                 DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
146                 return;
147         }
148
149         switch (getStatus())
150         {
151         case SetReferencePoint:
152         case SetTargetPoint:
153 #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!"
154
155                 if (!c.isEmpty() && checkCommand("angle", c))
156 //              if (c == checkCommand("angle", c))
157                 {
158                         deleteSnapper();
159                         deletePreview();
160                         clearPreview();
161                         lastStatus = (Status)getStatus();
162                         setStatus(SetAngle);
163                 }
164                 break;
165
166         case SetAngle:
167         {
168                 bool ok;
169                 double a = Math::eval(c, &ok);
170
171                 if (ok)
172                         data.angle = Math::deg2rad(a);
173                 else
174                         DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
175
176                 DIALOGFACTORY->requestOptions(this, true, true);
177                 setStatus(lastStatus);
178         }
179         break;
180         }
181 }
182
183 QStringList ActionModifyMoveRotate::getAvailableCommands()
184 {
185         QStringList cmd;
186
187         switch (getStatus())
188         {
189         case SetReferencePoint:
190         case SetTargetPoint:
191                 cmd += command("angle");
192                 break;
193
194         default:
195                 break;
196         }
197
198         return cmd;
199 }
200
201 void ActionModifyMoveRotate::showOptions()
202 {
203         //std::cout << "ActionModifyMoveRotate::showOptions()\n";
204
205         ActionInterface::showOptions();
206
207         DIALOGFACTORY->requestOptions(this, true);
208 }
209
210 void ActionModifyMoveRotate::hideOptions()
211 {
212         //std::cout << "ActionModifyMoveRotate::hideOptions()\n";
213
214         ActionInterface::hideOptions();
215
216         DIALOGFACTORY->requestOptions(this, false);
217 }
218
219 void ActionModifyMoveRotate::updateMouseButtonHints()
220 {
221         switch (getStatus())
222         {
223         case SetReferencePoint:
224                 DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
225                 break;
226
227         case SetTargetPoint:
228                 DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back"));
229                 break;
230
231         case SetAngle:
232                 DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back"));
233                 break;
234
235         default:
236                 DIALOGFACTORY->updateMouseWidget("", "");
237                 break;
238         }
239 }
240
241 void ActionModifyMoveRotate::updateMouseCursor()
242 {
243         graphicView->setMouseCursor(RS2::CadCursor);
244 }
245
246 void ActionModifyMoveRotate::updateToolBar()
247 {
248         switch (getStatus())
249         {
250         case SetReferencePoint:
251         case SetTargetPoint:
252                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
253                 break;
254
255         default:
256                 DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
257                 break;
258         }
259 }
260
261 void ActionModifyMoveRotate::setAngle(double a)
262 {
263         data.angle = a;
264 }
265
266 double ActionModifyMoveRotate::getAngle()
267 {
268         return data.angle;
269 }