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