]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawlinebisector.cpp
d5c03f5bb9c3f4d429b41288ff164069b8fb205d
[architektonas] / src / actions / rs_actiondrawlinebisector.cpp
1 /****************************************************************************
2 ** $Id: rs_actiondrawlinebisector.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinebisector.h"
28
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
31
32
33
34 RS_ActionDrawLineBisector::RS_ActionDrawLineBisector(
35     RS_EntityContainer& container,
36     RS_GraphicView& graphicView)
37         :RS_PreviewActionInterface("Draw Bisectors", container, graphicView) {
38
39     bisector = NULL;
40     length = 10.0;
41     line1 = NULL;
42     line2 = NULL;
43     number = 1;
44     coord1 = Vector(false);
45     coord2 = Vector(false);
46     lastStatus = SetLine1;
47 }
48
49 QAction* RS_ActionDrawLineBisector::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
50 {
51         QAction * action = new QAction(tr("&Bisector"), 0);
52 //      QAction* action = new QAction(tr("Bisector"), tr("&Bisector"),
53 //                                                                      QKeySequence(), NULL);
54         action->setStatusTip(tr("Draw bisectors"));
55         return action;
56 }
57
58
59 void RS_ActionDrawLineBisector::trigger() {
60     RS_PreviewActionInterface::trigger();
61
62     //if (bisector!=NULL) {
63     RS_Creation creation(container, graphicView);
64     creation.createBisector(coord1,
65                             coord2,
66                             length,
67                             number,
68                             line1,
69                             line2);
70     /*RS_Entity* newEntity = NULL;
71
72     newEntity = new RS_Line(container,
73                             bisector->getData());
74
75     if (newEntity!=NULL) {
76         newEntity->setLayerToActive();
77         newEntity->setPenToActive();
78         container->addEntity(newEntity);
79
80         // upd. undo list:
81         if (document!=NULL) {
82             document->startUndoCycle();
83             document->addUndoable(newEntity);
84             document->endUndoCycle();
85         }
86         graphicView->drawEntity(newEntity);
87         setStatus(SetLine1);
88 }
89     //reset();
90     delete bisector;
91     bisector = NULL;
92     */
93     /*} else {
94         RS_DEBUG->print("RS_ActionDrawLineBisector::trigger:"
95                         " Entity is NULL\n");
96 }*/
97 }
98
99
100
101 void RS_ActionDrawLineBisector::mouseMoveEvent(QMouseEvent* e) {
102     RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent begin");
103
104     Vector mouse = Vector(graphicView->toGraphX(e->x()),
105                                 graphicView->toGraphY(e->y()));
106
107     switch (getStatus()) {
108     case SetLine1:
109         break;
110
111     case SetLine2: {
112             coord2 = mouse;
113             RS_Entity* en = catchEntity(e, RS2::ResolveAll);
114             if (en!=NULL && en->rtti()==RS2::EntityLine) {
115                 line2 = (RS_Line*)en;
116
117                 deletePreview();
118                 clearPreview();
119
120                 RS_Creation creation(preview, NULL, false);
121                 creation.createBisector(coord1,
122                                         coord2,
123                                         length,
124                                         number,
125                                         line1,
126                                         line2);
127                 drawPreview();
128             }
129         }
130         break;
131
132     default:
133         break;
134     }
135
136     RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent end");
137 }
138
139
140
141 void RS_ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent* e) {
142
143     if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
144         deletePreview();
145         clearPreview();
146         init(getStatus()-1);
147     } else {
148
149         Vector mouse = Vector(graphicView->toGraphX(e->x()),
150                                     graphicView->toGraphY(e->y()));
151
152         switch (getStatus()) {
153         case SetLine1: {
154                 coord1 = mouse;
155                 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
156                 if (en!=NULL && en->rtti()==RS2::EntityLine) {
157                     line1 = (RS_Line*)en;
158                 }
159             }
160             setStatus(SetLine2);
161             break;
162
163         case SetLine2:
164             coord2 = mouse;
165             trigger();
166             setStatus(SetLine1);
167             break;
168         }
169     }
170
171 }
172
173
174 void RS_ActionDrawLineBisector::commandEvent(RS_CommandEvent* e) {
175     QString c = e->getCommand().toLower();
176
177     if (checkCommand("help", c)) {
178         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
179                                          + getAvailableCommands().join(", "));
180         return;
181     }
182
183     switch (getStatus()) {
184     case SetLine1:
185     case SetLine2:
186         lastStatus = (Status)getStatus();
187         if (checkCommand("length", c)) {
188             deleteSnapper();
189             deletePreview();
190             clearPreview();
191             setStatus(SetLength);
192         } else if (checkCommand("number", c)) {
193             deleteSnapper();
194             deletePreview();
195             clearPreview();
196             setStatus(SetNumber);
197         }
198         break;
199
200     case SetLength: {
201             bool ok;
202             double l = RS_Math::eval(c, &ok);
203             if (ok==true) {
204                 length = l;
205             } else {
206                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
207             }
208             RS_DIALOGFACTORY->requestOptions(this, true, true);
209             setStatus(lastStatus);
210         }
211         break;
212
213     case SetNumber: {
214             bool ok;
215             int n = (int)RS_Math::eval(c, &ok);
216             if (ok==true) {
217                 number = n;
218             } else {
219                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
220             }
221             RS_DIALOGFACTORY->requestOptions(this, true, true);
222             setStatus(lastStatus);
223         }
224         break;
225
226
227     default:
228         break;
229     }
230 }
231
232
233
234 QStringList RS_ActionDrawLineBisector::getAvailableCommands() {
235     QStringList cmd;
236
237     switch (getStatus()) {
238     case SetLine1:
239     case SetLine2:
240         cmd += command("length");
241         cmd += command("number");
242         break;
243     default:
244         break;
245     }
246
247     return cmd;
248 }
249
250
251 void RS_ActionDrawLineBisector::updateMouseButtonHints() {
252     switch (getStatus()) {
253     case SetLine1:
254         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
255                                             tr("Cancel"));
256         break;
257     case SetLine2:
258         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
259                                             tr("Back"));
260         break;
261     case SetLength:
262         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"),
263                                             tr("Back"));
264         break;
265     case SetNumber:
266         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"),
267                                             tr("Back"));
268         break;
269     default:
270         RS_DIALOGFACTORY->updateMouseWidget("", "");
271         break;
272     }
273 }
274
275
276
277 void RS_ActionDrawLineBisector::showOptions() {
278     RS_ActionInterface::showOptions();
279
280     RS_DIALOGFACTORY->requestOptions(this, true);
281 }
282
283
284
285 void RS_ActionDrawLineBisector::hideOptions() {
286     RS_ActionInterface::hideOptions();
287
288     RS_DIALOGFACTORY->requestOptions(this, false);
289 }
290
291
292
293 void RS_ActionDrawLineBisector::updateMouseCursor() {
294     graphicView->setMouseCursor(RS2::CadCursor);
295 }
296
297
298
299 void RS_ActionDrawLineBisector::updateToolBar() {
300     RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
301 }
302
303
304
305 // EOF