]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifystretch.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionmodifystretch.cpp
1 // rs_actionmodifystretch.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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/04/2010  Added this text. :-)
13 //
14
15 #include "rs_actionmodifystretch.h"
16
17 #include "rs_dialogfactory.h"
18 #include "rs_modification.h"
19 #include "rs_preview.h"
20
21 RS_ActionModifyStretch::RS_ActionModifyStretch(RS_EntityContainer & container,
22         RS_GraphicView & graphicView): RS_PreviewActionInterface("Stretch Entities",
23                 container, graphicView)
24 {
25         firstCorner = Vector(false);
26         secondCorner = Vector(false);
27         referencePoint = Vector(false);
28         targetPoint = Vector(false);
29 }
30
31 RS_ActionModifyStretch::~RS_ActionModifyStretch()
32 {
33 }
34
35 void RS_ActionModifyStretch::init(int status)
36 {
37         RS_ActionInterface::init(status);
38 }
39
40 void RS_ActionModifyStretch::trigger()
41 {
42         RS_DEBUG->print("RS_ActionModifyStretch::trigger()");
43
44         deletePreview();
45         clearPreview();
46
47         deleteSnapper();
48
49         RS_Modification m(*container, graphicView);
50         m.stretch(firstCorner, secondCorner, targetPoint - referencePoint);
51
52         drawSnapper();
53
54         setStatus(SetFirstCorner);
55
56         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
57 }
58
59 void RS_ActionModifyStretch::mouseMoveEvent(QMouseEvent * e)
60 {
61         RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent begin");
62
63         Vector mouse = snapPoint(e);
64
65         switch (getStatus())
66         {
67         case SetFirstCorner:
68                 break;
69
70         case SetSecondCorner:
71
72                 if (firstCorner.valid)
73                 {
74                         secondCorner = snapPoint(e);
75                         deletePreview();
76                         clearPreview();
77                         preview->addEntity(
78                                 new RS_Line(preview,
79                                         RS_LineData(Vector(firstCorner.x,
80                                                         firstCorner.y),
81                                                 Vector(secondCorner.x,
82                                                         firstCorner.y))));
83                         preview->addEntity(
84                                 new RS_Line(preview,
85                                         RS_LineData(Vector(secondCorner.x,
86                                                         firstCorner.y),
87                                                 Vector(secondCorner.x,
88                                                         secondCorner.y))));
89                         preview->addEntity(
90                                 new RS_Line(preview,
91                                         RS_LineData(Vector(secondCorner.x,
92                                                         secondCorner.y),
93                                                 Vector(firstCorner.x,
94                                                         secondCorner.y))));
95                         preview->addEntity(
96                                 new RS_Line(preview,
97                                         RS_LineData(Vector(firstCorner.x,
98                                                         secondCorner.y),
99                                                 Vector(firstCorner.x,
100                                                         firstCorner.y))));
101                         drawPreview();
102                 }
103                 break;
104
105         case SetReferencePoint:
106                 break;
107
108         case SetTargetPoint:
109
110                 if (referencePoint.valid)
111                 {
112                         targetPoint = mouse;
113
114                         deletePreview();
115                         clearPreview();
116                         preview->addStretchablesFrom(*container, firstCorner, secondCorner);
117                         //preview->move(targetPoint-referencePoint);
118                         preview->stretch(firstCorner, secondCorner,
119                                 targetPoint - referencePoint);
120                         drawPreview();
121                 }
122                 break;
123
124         default:
125                 break;
126         }
127
128         RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent end");
129 }
130
131 void RS_ActionModifyStretch::mouseReleaseEvent(QMouseEvent * e)
132 {
133         if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton)
134         {
135                 Vector ce(snapPoint(e));
136                 coordinateEvent(&ce);
137         }
138         else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton)
139         {
140                 deletePreview();
141                 deleteSnapper();
142                 init(getStatus() - 1);
143         }
144 }
145
146 void RS_ActionModifyStretch::coordinateEvent(Vector * e)
147 {
148         if (e == NULL)
149                 return;
150
151         Vector mouse = *e;
152
153         switch (getStatus())
154         {
155         case SetFirstCorner:
156                 firstCorner = mouse;
157                 setStatus(SetSecondCorner);
158                 break;
159
160         case SetSecondCorner:
161                 secondCorner = mouse;
162                 deletePreview();
163                 clearPreview();
164                 setStatus(SetReferencePoint);
165                 break;
166
167         case SetReferencePoint:
168                 referencePoint = mouse;
169                 graphicView->moveRelativeZero(referencePoint);
170                 setStatus(SetTargetPoint);
171                 break;
172
173         case SetTargetPoint:
174                 targetPoint = mouse;
175                 graphicView->moveRelativeZero(targetPoint);
176                 trigger();
177                 //finish();
178                 break;
179
180         default:
181                 break;
182         }
183 }
184
185 void RS_ActionModifyStretch::updateMouseButtonHints()
186 {
187         switch (getStatus())
188         {
189         case SetFirstCorner:
190                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"),
191                         tr("Cancel"));
192                 break;
193
194         case SetSecondCorner:
195                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"),
196                         tr("Back"));
197                 break;
198
199         case SetReferencePoint:
200                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
201                         tr("Back"));
202                 break;
203
204         case SetTargetPoint:
205                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"),
206                         tr("Back"));
207                 break;
208
209         default:
210                 RS_DIALOGFACTORY->updateMouseWidget("", "");
211                 break;
212         }
213 }
214
215 void RS_ActionModifyStretch::updateMouseCursor()
216 {
217         graphicView->setMouseCursor(RS2::CadCursor);
218 }
219
220 void RS_ActionModifyStretch::updateToolBar()
221 {
222         if (!isFinished())
223                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
224         else
225                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
226 }
227
228 // EOF