]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifymoverotate.cpp
Initial import
[architektonas] / src / actions / rs_actionmodifymoverotate.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifymoverotate.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionmodifymoverotate.h"
28
29 #include "rs_snapper.h"
30
31 RS_ActionModifyMoveRotate::RS_ActionModifyMoveRotate(
32         RS_EntityContainer& container, RS_GraphicView& graphicView):
33         RS_PreviewActionInterface("Move and Rotate Entities", container, graphicView)
34 {
35 }
36
37 QAction * RS_ActionModifyMoveRotate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
38 {
39         QAction * action = new QAction(tr("M&ove and Rotate"), 0);
40 //      QAction* action = new QAction(tr("Move and Rotate"), tr("M&ove and Rotate"),
41 //                                                                      QKeySequence(), NULL);
42         action->setStatusTip(tr("Move and Rotate Entities"));
43         return action;
44 }
45
46 void RS_ActionModifyMoveRotate::init(int status)
47 {
48     RS_ActionInterface::init(status);
49 }
50
51 void RS_ActionModifyMoveRotate::trigger()
52 {
53     RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()");
54
55     RS_Modification m(*container, graphicView);
56     m.moveRotate(data);
57
58     finish();
59
60     RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
61 }
62
63 void RS_ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e)
64 {
65     RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent begin");
66
67     if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint)
68         {
69
70         Vector mouse = snapPoint(e);
71         switch (getStatus())
72                 {
73         case SetReferencePoint:
74             data.referencePoint = mouse;
75             break;
76
77         case SetTargetPoint:
78             if (data.referencePoint.valid)
79                         {
80                 targetPoint = mouse;
81                 data.offset = targetPoint-data.referencePoint;
82
83                 deletePreview();
84                 clearPreview();
85                 preview->addSelectionFrom(*container);
86                 preview->rotate(data.referencePoint, data.angle);
87                 preview->move(data.offset);
88                 drawPreview();
89             }
90             break;
91
92         default:
93             break;
94         }
95     }
96
97     RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent end");
98 }
99
100 void RS_ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e)
101 {
102         if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
103         {
104                 RS_CoordinateEvent ce(snapPoint(e));
105                 coordinateEvent(&ce);
106         }
107         else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
108         {
109                 deletePreview();
110                 deleteSnapper();
111                 init(getStatus() - 1);
112         }
113 }
114
115 void RS_ActionModifyMoveRotate::coordinateEvent(RS_CoordinateEvent * e)
116 {
117     if (e == NULL)
118         return;
119
120     Vector pos = e->getCoordinate();
121
122     switch (getStatus())
123         {
124     case SetReferencePoint:
125         data.referencePoint = pos;
126         setStatus(SetTargetPoint);
127         break;
128
129     case SetTargetPoint:
130         targetPoint = pos;
131
132         setStatus(ShowDialog);
133         data.offset = targetPoint - data.referencePoint;
134         if (RS_DIALOGFACTORY->requestMoveRotateDialog(data))
135                 {
136             trigger();
137             //finish();
138         }
139         break;
140
141     default:
142         break;
143     }
144 }
145
146 void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e)
147 {
148         QString c = e->getCommand().toLower();
149
150         if (checkCommand("help", c))
151         {
152                 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", "));
153                 return;
154         }
155
156         switch (getStatus())
157         {
158         case SetReferencePoint:
159         case SetTargetPoint:
160 #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!"
161                 if (!c.isEmpty() && checkCommand("angle", c))
162 //              if (c == checkCommand("angle", c))
163                 {
164                         deleteSnapper();
165                         deletePreview();
166                         clearPreview();
167                         lastStatus = (Status)getStatus();
168                         setStatus(SetAngle);
169                 }
170                 break;
171
172         case SetAngle:
173                 {
174                         bool ok;
175                         double a = RS_Math::eval(c, &ok);
176
177                         if (ok)
178                                 data.angle = RS_Math::deg2rad(a);
179                         else
180                                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
181
182                         RS_DIALOGFACTORY->requestOptions(this, true, true);
183                         setStatus(lastStatus);
184                 }
185                 break;
186         }
187 }
188
189 QStringList RS_ActionModifyMoveRotate::getAvailableCommands()
190 {
191     QStringList cmd;
192
193     switch (getStatus())
194         {
195     case SetReferencePoint:
196     case SetTargetPoint:
197         cmd += command("angle");
198         break;
199
200     default:
201         break;
202     }
203
204     return cmd;
205 }
206
207 void RS_ActionModifyMoveRotate::showOptions()
208 {
209     //std::cout << "RS_ActionModifyMoveRotate::showOptions()\n";
210
211     RS_ActionInterface::showOptions();
212
213     RS_DIALOGFACTORY->requestOptions(this, true);
214 }
215
216 void RS_ActionModifyMoveRotate::hideOptions()
217 {
218     //std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n";
219
220     RS_ActionInterface::hideOptions();
221
222     RS_DIALOGFACTORY->requestOptions(this, false);
223 }
224
225 void RS_ActionModifyMoveRotate::updateMouseButtonHints()
226 {
227     switch (getStatus())
228         {
229     case SetReferencePoint:
230         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel"));
231         break;
232     case SetTargetPoint:
233         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back"));
234         break;
235     case SetAngle:
236         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back"));
237         break;
238     default:
239         RS_DIALOGFACTORY->updateMouseWidget("", "");
240         break;
241     }
242 }
243
244 void RS_ActionModifyMoveRotate::updateMouseCursor()
245 {
246     graphicView->setMouseCursor(RS2::CadCursor);
247 }
248
249 void RS_ActionModifyMoveRotate::updateToolBar()
250 {
251     switch (getStatus())
252         {
253     case SetReferencePoint:
254     case SetTargetPoint:
255         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
256         break;
257     default:
258         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
259         break;
260     }
261 }
262
263
264 // EOF