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