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