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