]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifystretch.cpp
aeeecb9284b71fa2dcef3cf0cb5a67c01346334b
[architektonas] / src / actions / rs_actionmodifystretch.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifystretch.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_actionmodifystretch.h"
28
29 #include "rs_snapper.h"
30
31
32
33 RS_ActionModifyStretch::RS_ActionModifyStretch(RS_EntityContainer& container,
34         RS_GraphicView& graphicView)
35         :RS_PreviewActionInterface("Stretch Entities",
36                            container, graphicView) {
37
38     firstCorner = Vector(false);
39     secondCorner = Vector(false);
40     referencePoint = Vector(false);
41     targetPoint = Vector(false);
42 }
43
44 QAction* RS_ActionModifyStretch::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
45 {
46         QAction * action = new QAction(tr("&Stretch"), 0);
47 //      QAction* action = new QAction(tr("Stretch"), tr("&Stretch"),
48 //                                                                      QKeySequence(), NULL);
49         action->setStatusTip(tr("Stretch Entities"));
50         return action;
51 }
52
53
54 void RS_ActionModifyStretch::init(int status) {
55     RS_ActionInterface::init(status);
56
57 }
58
59
60
61 void RS_ActionModifyStretch::trigger() {
62
63     RS_DEBUG->print("RS_ActionModifyStretch::trigger()");
64
65     deletePreview();
66     clearPreview();
67
68     deleteSnapper();
69
70     RS_Modification m(*container, graphicView);
71     m.stretch(firstCorner, secondCorner, targetPoint-referencePoint);
72
73     drawSnapper();
74
75     setStatus(SetFirstCorner);
76
77     RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
78 }
79
80
81
82 void RS_ActionModifyStretch::mouseMoveEvent(QMouseEvent* e) {
83     RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent begin");
84
85     Vector mouse = snapPoint(e);
86     switch (getStatus()) {
87     case SetFirstCorner:
88         break;
89
90     case SetSecondCorner:
91         if (firstCorner.valid) {
92             secondCorner = snapPoint(e);
93             deletePreview();
94             clearPreview();
95             preview->addEntity(
96                 new RS_Line(preview,
97                             RS_LineData(Vector(firstCorner.x,
98                                                   firstCorner.y),
99                                         Vector(secondCorner.x,
100                                                   firstCorner.y))));
101             preview->addEntity(
102                 new RS_Line(preview,
103                             RS_LineData(Vector(secondCorner.x,
104                                                   firstCorner.y),
105                                         Vector(secondCorner.x,
106                                                   secondCorner.y))));
107             preview->addEntity(
108                 new RS_Line(preview,
109                             RS_LineData(Vector(secondCorner.x,
110                                                   secondCorner.y),
111                                         Vector(firstCorner.x,
112                                                   secondCorner.y))));
113             preview->addEntity(
114                 new RS_Line(preview,
115                             RS_LineData(Vector(firstCorner.x,
116                                                   secondCorner.y),
117                                         Vector(firstCorner.x,
118                                                   firstCorner.y))));
119             drawPreview();
120         }
121         break;
122
123     case SetReferencePoint:
124         break;
125
126     case SetTargetPoint:
127         if (referencePoint.valid) {
128             targetPoint = mouse;
129
130             deletePreview();
131             clearPreview();
132             preview->addStretchablesFrom(*container, firstCorner, secondCorner);
133             //preview->move(targetPoint-referencePoint);
134             preview->stretch(firstCorner, secondCorner,
135                              targetPoint-referencePoint);
136             drawPreview();
137         }
138         break;
139
140     default:
141         break;
142     }
143
144     RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent end");
145 }
146
147
148
149 void RS_ActionModifyStretch::mouseReleaseEvent(QMouseEvent* e) {
150     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
151         RS_CoordinateEvent ce(snapPoint(e));
152         coordinateEvent(&ce);
153     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
154         deletePreview();
155         deleteSnapper();
156         init(getStatus()-1);
157     }
158 }
159
160
161
162 void RS_ActionModifyStretch::coordinateEvent(RS_CoordinateEvent* e) {
163     if (e==NULL) {
164         return;
165     }
166
167     Vector mouse = e->getCoordinate();
168
169     switch (getStatus()) {
170     case SetFirstCorner:
171         firstCorner = mouse;
172         setStatus(SetSecondCorner);
173         break;
174
175     case SetSecondCorner:
176         secondCorner = mouse;
177         deletePreview();
178         clearPreview();
179         setStatus(SetReferencePoint);
180         break;
181
182     case SetReferencePoint:
183         referencePoint = mouse;
184         graphicView->moveRelativeZero(referencePoint);
185         setStatus(SetTargetPoint);
186         break;
187
188     case SetTargetPoint:
189         targetPoint = mouse;
190         graphicView->moveRelativeZero(targetPoint);
191         trigger();
192         //finish();
193         break;
194
195     default:
196         break;
197     }
198
199 }
200
201
202 void RS_ActionModifyStretch::updateMouseButtonHints() {
203     switch (getStatus()) {
204     case SetFirstCorner:
205         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
206                                             tr("Cancel"));
207         break;
208     case SetSecondCorner:
209         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
210                                             tr("Back"));
211         break;
212     case SetReferencePoint:
213         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
214                                             tr("Back"));
215         break;
216     case SetTargetPoint:
217         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
218                                             tr("Back"));
219         break;
220     default:
221         RS_DIALOGFACTORY->updateMouseWidget("", "");
222         break;
223     }
224 }
225
226
227
228 void RS_ActionModifyStretch::updateMouseCursor() {
229     graphicView->setMouseCursor(RS2::CadCursor);
230 }
231
232
233
234 void RS_ActionModifyStretch::updateToolBar() {
235     if (!isFinished()) {
236         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
237     } else {
238         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
239     }
240 }
241
242
243 // EOF