]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifyround.cpp
Initial import
[architektonas] / src / actions / rs_actionmodifyround.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifyround.cpp 1161 2004-12-09 23:10:09Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actionmodifyround.h"
28
29 #include "rs_information.h"
30 #include "rs_snapper.h"
31
32 RS_ActionModifyRound::RS_ActionModifyRound(RS_EntityContainer& container,
33         RS_GraphicView& graphicView)
34         :RS_PreviewActionInterface("Round Entities", container, graphicView)
35 {
36         entity1 = NULL;
37         entity2 = NULL;
38         coord1 = Vector(false);
39         coord2 = Vector(false);
40 }
41
42 QAction * RS_ActionModifyRound::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
43 {
44         QAction * action = new QAction(tr("&Round"), 0);
45 //      QAction* action = new QAction(tr("Round"), tr("&Round"),
46 //                                                      QKeySequence(), NULL);
47         action->setStatusTip(tr("Round Entities"));
48         return action;
49 }
50
51 void RS_ActionModifyRound::init(int status)
52 {
53     RS_ActionInterface::init(status);
54
55     snapMode = RS2::SnapFree;
56     snapRes = RS2::RestrictNothing;
57 }
58
59 void RS_ActionModifyRound::trigger()
60 {
61     RS_DEBUG->print("RS_ActionModifyRound::trigger()");
62
63     if (entity1!=NULL && entity1->isAtomic() &&
64             entity2!=NULL && entity2->isAtomic())
65         {
66         deletePreview();
67
68         RS_Modification m(*container, graphicView);
69         m.round(coord2,
70                 coord1,
71                 (RS_AtomicEntity*)entity1,
72                 coord2,
73                 (RS_AtomicEntity*)entity2,
74                 data);
75
76         //coord = Vector(false);
77         coord1 = Vector(false);
78         entity1 = NULL;
79         coord2 = Vector(false);
80         entity2 = NULL;
81         setStatus(SetEntity1);
82
83         clearPreview();
84
85         if (RS_DIALOGFACTORY!=NULL) {
86             RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
87         }
88     }
89 }
90
91
92
93 void RS_ActionModifyRound::mouseMoveEvent(QMouseEvent* e) {
94     RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent begin");
95
96     Vector mouse = graphicView->toGraph(e->x(), e->y());
97     RS_Entity* se = catchEntity(e, RS2::ResolveAll);
98
99     switch (getStatus()) {
100     case SetEntity1:
101         entity1 = se;
102         coord1 = mouse;
103         break;
104
105     case SetEntity2:
106         entity2 = se;
107         coord2 = mouse;
108
109         if (entity1!=NULL && entity2!=NULL && entity2->isAtomic() &&
110                         RS_Information::isTrimmable(entity1, entity2)) {
111
112             deletePreview();
113             clearPreview();
114             //preview->addSelectionFrom(*container);
115             //preview->move(targetPoint-referencePoint);
116             RS_Entity* tmp1 = entity1->clone();
117             RS_Entity* tmp2 = entity2->clone();
118             tmp1->reparent(preview);
119             tmp2->reparent(preview);
120             preview->addEntity(tmp1);
121             preview->addEntity(tmp2);
122
123             bool trim = data.trim;
124             data.trim = false;
125             RS_Modification m(*preview, NULL, false);
126             m.round(coord2,
127                     coord1,
128                     (RS_AtomicEntity*)tmp1,
129                     coord2,
130                     (RS_AtomicEntity*)tmp2,
131                     data);
132             data.trim = trim;
133
134             preview->removeEntity(tmp1);
135             preview->removeEntity(tmp2);
136             drawPreview();
137         }
138         break;
139
140     default:
141         break;
142     }
143
144     RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent end");
145 }
146
147
148
149 void RS_ActionModifyRound::mouseReleaseEvent(QMouseEvent* e) {
150     Vector mouse = graphicView->toGraph(e->x(), e->y());
151     RS_Entity* se = catchEntity(e, RS2::ResolveAll);
152
153     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
154         switch (getStatus()) {
155         case SetEntity1:
156             entity1 = se;
157             coord1 = mouse;
158             if (entity1!=NULL && entity1->isAtomic() &&
159                                 RS_Information::isTrimmable(entity1)) {
160                 setStatus(SetEntity2);
161             }
162             break;
163
164         case SetEntity2:
165             entity2 = se;
166             coord2 = mouse;
167             if (entity2!=NULL && entity2->isAtomic() &&
168                             RS_Information::isTrimmable(entity1, entity2)) {
169                 //setStatus(ChooseRounding);
170                 trigger();
171             }
172             break;
173
174         default:
175             break;
176         }
177     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
178         deletePreview();
179         deleteSnapper();
180         init(getStatus()-1);
181     }
182 }
183
184
185
186 void RS_ActionModifyRound::commandEvent(RS_CommandEvent* e) {
187     QString c = e->getCommand().toLower();
188
189     if (checkCommand("help", c)) {
190         if (RS_DIALOGFACTORY!=NULL) {
191             RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
192                                              + getAvailableCommands().join(", "));
193         }
194         return;
195     }
196
197     switch (getStatus()) {
198     case SetEntity1:
199     case SetEntity2:
200         if (checkCommand("radius", c)) {
201             deleteSnapper();
202             deletePreview();
203             clearPreview();
204             lastStatus = (Status)getStatus();
205             setStatus(SetRadius);
206         } else if (checkCommand("trim", c)) {
207             /*deleteSnapper();
208             deletePreview();
209             clearPreview();
210             lastStatus = (Status)getStatus();
211             setStatus(SetTrim);
212             */
213             data.trim = !data.trim;
214             if (RS_DIALOGFACTORY!=NULL) {
215                 RS_DIALOGFACTORY->requestOptions(this, true, true);
216             }
217         }
218         break;
219
220     case SetRadius: {
221             bool ok;
222             double r = RS_Math::eval(c, &ok);
223             if (ok==true) {
224                 data.radius = r;
225             } else {
226                 if (RS_DIALOGFACTORY!=NULL) {
227                     RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
228                 }
229             }
230             if (RS_DIALOGFACTORY!=NULL) {
231                 RS_DIALOGFACTORY->requestOptions(this, true, true);
232             }
233             setStatus(lastStatus);
234         }
235         break;
236
237         /*case SetTrim: {
238         if (c==cmdYes.toLower() || c==cmdYes2) {
239         data.trim = true;
240     } else if (c==cmdNo.toLower() || c==cmdNo2) {
241         data.trim = false;
242                 } else {
243                     RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
244                "or 'No'"));
245                 }
246                 RS_DIALOGFACTORY->requestOptions(this, true, true);
247                 setStatus(lastStatus);
248             }
249             break;*/
250
251     default:
252         break;
253     }
254 }
255
256
257
258 QStringList RS_ActionModifyRound::getAvailableCommands() {
259     QStringList cmd;
260     switch (getStatus()) {
261     case SetEntity1:
262     case SetEntity2:
263         cmd += command("radius");
264         cmd += command("trim");
265         break;
266     default:
267         break;
268     }
269     return cmd;
270 }
271
272
273
274 void RS_ActionModifyRound::showOptions() {
275     RS_ActionInterface::showOptions();
276
277     if (RS_DIALOGFACTORY!=NULL) {
278         RS_DIALOGFACTORY->requestOptions(this, true);
279     }
280 }
281
282
283
284 void RS_ActionModifyRound::hideOptions() {
285     RS_ActionInterface::hideOptions();
286
287     if (RS_DIALOGFACTORY!=NULL) {
288         RS_DIALOGFACTORY->requestOptions(this, false);
289     }
290 }
291
292
293
294 void RS_ActionModifyRound::updateMouseButtonHints() {
295     if (RS_DIALOGFACTORY!=NULL) {
296         switch (getStatus()) {
297         case SetEntity1:
298             RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"),
299                                                 tr("Back"));
300             break;
301         case SetEntity2:
302             RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"),
303                                                 tr("Back"));
304             break;
305         case SetRadius:
306             RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"),
307                                                 tr("Cancel"));
308             break;
309             /*case SetTrim:
310                 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
311                                                     "");
312                 break;*/
313         default:
314             RS_DIALOGFACTORY->updateMouseWidget("", "");
315             break;
316         }
317     }
318 }
319
320
321
322 void RS_ActionModifyRound::updateMouseCursor() {
323     graphicView->setMouseCursor(RS2::CadCursor);
324 }
325
326
327
328 void RS_ActionModifyRound::updateToolBar() {
329     if (RS_DIALOGFACTORY!=NULL) {
330         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
331     }
332 }
333
334
335 // EOF