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