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