]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionmodifybevel.cpp
Initial import
[architektonas] / src / actions / rs_actionmodifybevel.cpp
1 /****************************************************************************
2 ** $Id: rs_actionmodifybevel.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_actionmodifybevel.h"
28
29 #include "rs_snapper.h"
30 #include "rs_information.h"
31
32
33 RS_ActionModifyBevel::RS_ActionModifyBevel(RS_EntityContainer& container,
34         RS_GraphicView& graphicView)
35         :RS_PreviewActionInterface("Bevel Entities",
36                            container, graphicView) {
37
38     entity1 = NULL;
39     coord1 = Vector(false);
40     entity2 = NULL;
41     coord2 = Vector(false);
42 }
43
44
45 QAction* RS_ActionModifyBevel::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
46 {
47         QAction * action = new QAction(tr("&Bevel"), 0);
48 //      QAction* action = new QAction(tr("Bevel"), tr("&Bevel"),
49 //                                                                      QKeySequence(), NULL);
50         action->setStatusTip(tr("Bevel Entities"));
51         return action;
52 }
53
54
55 void RS_ActionModifyBevel::init(int status) {
56     RS_ActionInterface::init(status);
57
58     snapMode = RS2::SnapFree;
59     snapRes = RS2::RestrictNothing;
60 }
61
62
63
64 void RS_ActionModifyBevel::trigger() {
65
66     RS_DEBUG->print("RS_ActionModifyBevel::trigger()");
67
68     if (entity1!=NULL && entity1->isAtomic() &&
69             entity2!=NULL && entity2->isAtomic()) {
70
71         RS_Modification m(*container, graphicView);
72         m.bevel(coord1, (RS_AtomicEntity*)entity1,
73                 coord2, (RS_AtomicEntity*)entity2,
74                 data);
75
76         entity1 = NULL;
77         entity2 = NULL;
78         setStatus(SetEntity1);
79
80         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
81     }
82 }
83
84
85
86 void RS_ActionModifyBevel::mouseMoveEvent(QMouseEvent* e) {
87     RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent begin");
88
89     Vector mouse = graphicView->toGraph(e->x(), e->y());
90     RS_Entity* se = catchEntity(e, RS2::ResolveAll);
91
92     switch (getStatus()) {
93     case SetEntity1:
94         coord1 = mouse;
95         entity1 = se;
96         break;
97
98     case SetEntity2:
99                 if (entity1!=NULL && RS_Information::isTrimmable(entity1)) {
100                 coord2 = mouse;
101                 entity2 = se;
102                 }
103         break;
104
105     default:
106         break;
107     }
108
109     RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent end");
110 }
111
112
113
114 void RS_ActionModifyBevel::mouseReleaseEvent(QMouseEvent* e) {
115     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
116         switch (getStatus()) {
117         case SetEntity1:
118             if (entity1!=NULL && entity1->isAtomic()) {
119                 setStatus(SetEntity2);
120             }
121             break;
122
123         case SetEntity2:
124             if (entity2!=NULL && entity2->isAtomic() &&
125                             RS_Information::isTrimmable(entity1, entity2)) {
126                 trigger();
127             }
128             break;
129
130         default:
131             break;
132         }
133     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
134         deletePreview();
135         deleteSnapper();
136         init(getStatus()-1);
137     }
138 }
139
140
141
142 void RS_ActionModifyBevel::commandEvent(RS_CommandEvent* e) {
143     QString c = e->getCommand().toLower();
144
145     if (checkCommand("help", c)) {
146         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
147                                          + getAvailableCommands().join(", "));
148         return;
149     }
150
151     switch (getStatus()) {
152     case SetEntity1:
153     case SetEntity2:
154         if (checkCommand("length1", c)) {
155             deleteSnapper();
156             deletePreview();
157             clearPreview();
158             lastStatus = (Status)getStatus();
159             setStatus(SetLength1);
160         } else if (checkCommand("length2", c)) {
161             deleteSnapper();
162             deletePreview();
163             clearPreview();
164             lastStatus = (Status)getStatus();
165             setStatus(SetLength2);
166         } else if (checkCommand("trim", c)) {
167             //deleteSnapper();
168             //deletePreview();
169             //clearPreview();
170             //lastStatus = (Status)getStatus();
171             //setStatus(SetTrim);
172             data.trim = !data.trim;
173             RS_DIALOGFACTORY->requestOptions(this, true, true);
174         }
175         break;
176
177     case SetLength1: {
178             bool ok;
179             double l = RS_Math::eval(c, &ok);
180             if (ok==true) {
181                 data.length1 = l;
182             } else {
183                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
184             }
185             RS_DIALOGFACTORY->requestOptions(this, true, true);
186             setStatus(lastStatus);
187         }
188         break;
189
190     case SetLength2: {
191             bool ok;
192             double l = RS_Math::eval(c, &ok);
193             if (ok==true) {
194                 data.length2 = l;
195             } else {
196                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
197             }
198             RS_DIALOGFACTORY->requestOptions(this, true, true);
199             setStatus(lastStatus);
200         }
201         break;
202
203         /*case SetTrim: {
204         if (checkCommand()) {
205         data.trim = true;
206     } else if (c==cmdNo.toLower() || c==cmdNo2) {
207         data.trim = false;
208                 } else {
209                     RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
210                "or 'No'"));
211                 }
212                 RS_DIALOGFACTORY->requestOptions(this, true, true);
213                 setStatus(lastStatus);
214             }
215             break;*/
216
217     default:
218         break;
219     }
220 }
221
222
223
224 QStringList RS_ActionModifyBevel::getAvailableCommands() {
225     QStringList cmd;
226     switch (getStatus()) {
227     case SetEntity1:
228     case SetEntity2:
229         cmd += command("length1");
230         cmd += command("length2");
231         cmd += command("trim");
232         break;
233     default:
234         break;
235     }
236     return cmd;
237 }
238
239
240
241 void RS_ActionModifyBevel::showOptions() {
242     RS_ActionInterface::showOptions();
243
244     RS_DIALOGFACTORY->requestOptions(this, true);
245 }
246
247
248
249 void RS_ActionModifyBevel::hideOptions() {
250     RS_ActionInterface::hideOptions();
251
252     RS_DIALOGFACTORY->requestOptions(this, false);
253 }
254
255
256
257 void RS_ActionModifyBevel::updateMouseButtonHints() {
258     switch (getStatus()) {
259     case SetEntity1:
260         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
261                                             tr("Cancel"));
262         break;
263     case SetEntity2:
264         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
265                                             tr("Back"));
266         break;
267     case SetLength1:
268         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"),
269                                             tr("Back"));
270         break;
271     case SetLength2:
272         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"),
273                                             tr("Back"));
274         break;
275         /*case SetTrim:
276             RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
277                                                 "");
278             break;*/
279     default:
280         RS_DIALOGFACTORY->updateMouseWidget("", "");
281         break;
282     }
283 }
284
285
286
287 void RS_ActionModifyBevel::updateMouseCursor() {
288     graphicView->setMouseCursor(RS2::CadCursor);
289 }
290
291
292
293 void RS_ActionModifyBevel::updateToolBar() {
294     RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);
295 }
296
297
298 // EOF