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