]> Shamusworld >> Repos - architektonas/blob - src/actions/actionmodifybevel.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actionmodifybevel.cpp
1 // actionmodifybevel.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 "actionmodifybevel.h"
18
19 #include "commandevent.h"
20 #include "debug.h"
21 #include "dialogfactory.h"
22 #include "information.h"
23
24 ActionModifyBevel::ActionModifyBevel(EntityContainer & container, GraphicView & graphicView): ActionInterface("Bevel Entities",
25                 container, graphicView)
26 {
27         entity1 = NULL;
28         coord1 = Vector(false);
29         entity2 = NULL;
30         coord2 = Vector(false);
31 }
32
33 ActionModifyBevel::~ActionModifyBevel()
34 {
35 }
36
37 /*virtual*/ RS2::ActionType ActionModifyBevel::rtti()
38 {
39         return RS2::ActionModifyBevel;
40 }
41
42 void ActionModifyBevel::init(int status)
43 {
44         ActionInterface::init(status);
45
46 /*      snapMode = RS2::SnapFree;
47         snapRes = RS2::RestrictNothing;*/
48 }
49
50 void ActionModifyBevel::trigger()
51 {
52         DEBUG->print("ActionModifyBevel::trigger()");
53
54         if (entity1 && entity1->isAtomic()
55             && entity2 && entity2->isAtomic())
56         {
57                 Modification m(*container, graphicView);
58                 m.bevel(coord1, (AtomicEntity *)entity1, coord2, (AtomicEntity *)entity2, data);
59
60                 entity1 = NULL;
61                 entity2 = NULL;
62                 setStatus(SetEntity1);
63
64                 DIALOGFACTORY->updateSelectionWidget(container->countSelected());
65         }
66 }
67
68 void ActionModifyBevel::mouseMoveEvent(QMouseEvent * e)
69 {
70         DEBUG->print("ActionModifyBevel::mouseMoveEvent begin");
71
72         Vector mouse = graphicView->toGraph(e->x(), e->y());
73         Entity * se = catchEntity(e, RS2::ResolveAll);
74
75         switch (getStatus())
76         {
77         case SetEntity1:
78                 coord1 = mouse;
79                 entity1 = se;
80                 break;
81
82         case SetEntity2:
83
84                 if (entity1 != NULL && Information::isTrimmable(entity1))
85                 {
86                         coord2 = mouse;
87                         entity2 = se;
88                 }
89                 break;
90
91         default:
92                 break;
93         }
94
95         DEBUG->print("ActionModifyBevel::mouseMoveEvent end");
96 }
97
98 void ActionModifyBevel::mouseReleaseEvent(QMouseEvent * e)
99 {
100         if (e->button() == Qt::LeftButton)
101         {
102                 switch (getStatus())
103                 {
104                 case SetEntity1:
105
106                         if (entity1 != NULL && entity1->isAtomic())
107                                 setStatus(SetEntity2);
108                         break;
109
110                 case SetEntity2:
111
112                         if (entity2 != NULL && entity2->isAtomic()
113                             && Information::isTrimmable(entity1, entity2))
114                                 trigger();
115                         break;
116
117                 default:
118                         break;
119                 }
120         }
121         else if (e->button() == Qt::RightButton)
122         {
123                 deletePreview();
124                 deleteSnapper();
125                 init(getStatus() - 1);
126         }
127 }
128
129 void ActionModifyBevel::commandEvent(CommandEvent * e)
130 {
131         QString c = e->getCommand().toLower();
132
133         if (checkCommand("help", c))
134         {
135                 DIALOGFACTORY->commandMessage(msgAvailableCommands()
136                         + getAvailableCommands().join(", "));
137                 return;
138         }
139
140         switch (getStatus())
141         {
142         case SetEntity1:
143         case SetEntity2:
144
145                 if (checkCommand("length1", c))
146                 {
147                         deleteSnapper();
148                         deletePreview();
149                         clearPreview();
150                         lastStatus = (Status)getStatus();
151                         setStatus(SetLength1);
152                 }
153                 else if (checkCommand("length2", c))
154                 {
155                         deleteSnapper();
156                         deletePreview();
157                         clearPreview();
158                         lastStatus = (Status)getStatus();
159                         setStatus(SetLength2);
160                 }
161                 else if (checkCommand("trim", c))
162                 {
163                         //deleteSnapper();
164                         //deletePreview();
165                         //clearPreview();
166                         //lastStatus = (Status)getStatus();
167                         //setStatus(SetTrim);
168                         data.trim = !data.trim;
169                         DIALOGFACTORY->requestOptions(this, true, true);
170                 }
171                 break;
172
173         case SetLength1: {
174                 bool ok;
175                 double l = Math::eval(c, &ok);
176
177                 if (ok == true)
178                         data.length1 = l;
179                 else
180                         DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
181                 DIALOGFACTORY->requestOptions(this, true, true);
182                 setStatus(lastStatus);
183         }
184         break;
185
186         case SetLength2: {
187                 bool ok;
188                 double l = Math::eval(c, &ok);
189
190                 if (ok == true)
191                         data.length2 = l;
192                 else
193                         DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
194                 DIALOGFACTORY->requestOptions(this, true, true);
195                 setStatus(lastStatus);
196         }
197         break;
198
199         /*case SetTrim: {
200            if (checkCommand()) {
201            data.trim = true;
202            } else if (c==cmdNo.toLower() || c==cmdNo2) {
203            data.trim = false;
204                 } else {
205                     DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
206                "or 'No'"));
207                 }
208                 DIALOGFACTORY->requestOptions(this, true, true);
209                 setStatus(lastStatus);
210             }
211             break;*/
212
213         default:
214                 break;
215         }
216 }
217
218 QStringList ActionModifyBevel::getAvailableCommands()
219 {
220         QStringList cmd;
221
222         switch (getStatus())
223         {
224         case SetEntity1:
225         case SetEntity2:
226                 cmd += command("length1");
227                 cmd += command("length2");
228                 cmd += command("trim");
229                 break;
230
231         default:
232                 break;
233         }
234         return cmd;
235 }
236
237 void ActionModifyBevel::showOptions()
238 {
239         ActionInterface::showOptions();
240
241         DIALOGFACTORY->requestOptions(this, true);
242 }
243
244 void ActionModifyBevel::hideOptions()
245 {
246         ActionInterface::hideOptions();
247
248         DIALOGFACTORY->requestOptions(this, false);
249 }
250
251 void ActionModifyBevel::updateMouseButtonHints()
252 {
253         switch (getStatus())
254         {
255         case SetEntity1:
256                 DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
257                         tr("Cancel"));
258                 break;
259
260         case SetEntity2:
261                 DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
262                         tr("Back"));
263                 break;
264
265         case SetLength1:
266                 DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"),
267                         tr("Back"));
268                 break;
269
270         case SetLength2:
271                 DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"),
272                         tr("Back"));
273                 break;
274
275         /*case SetTrim:
276             DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
277                                                 "");
278             break;*/
279         default:
280                 DIALOGFACTORY->updateMouseWidget("", "");
281                 break;
282         }
283 }
284
285 void ActionModifyBevel::updateMouseCursor()
286 {
287         graphicView->setMouseCursor(RS2::CadCursor);
288 }
289
290 void ActionModifyBevel::updateToolBar()
291 {
292         DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
293 }
294
295 void ActionModifyBevel::setLength1(double l1)
296 {
297         data.length1 = l1;
298 }
299
300 double ActionModifyBevel::getLength1()
301 {
302         return data.length1;
303 }
304
305 void ActionModifyBevel::setLength2(double l2)
306 {
307         data.length2 = l2;
308 }
309
310 double ActionModifyBevel::getLength2()
311 {
312         return data.length2;
313 }
314
315 void ActionModifyBevel::setTrim(bool t)
316 {
317         data.trim = t;
318 }
319
320 bool ActionModifyBevel::isTrimOn()
321 {
322         return data.trim;
323 }