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