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