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