]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawcircle3p.cpp
ce4f29ee6415f63d52a000cc4c80f23f79dcf9f1
[architektonas] / src / actions / rs_actiondrawcircle3p.cpp
1 /****************************************************************************
2 ** $Id: rs_actiondrawcircle3p.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_actiondrawcircle3p.h"
28
29 #include "rs_snapper.h"
30
31
32
33 RS_ActionDrawCircle3P::RS_ActionDrawCircle3P(RS_EntityContainer& container,
34         RS_GraphicView& graphicView)
35         :RS_PreviewActionInterface("Draw circles",
36                            container, graphicView) {
37     reset();
38 }
39
40
41
42 RS_ActionDrawCircle3P::~RS_ActionDrawCircle3P() {}
43
44
45 QAction* RS_ActionDrawCircle3P::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
46 {
47         QAction * action = new QAction(tr("3 Points"), 0);
48 //      QAction* action = new QAction(tr("Circle: 3 Points"), tr("3 Points"),
49 //                                                                      QKeySequence(), NULL);
50         action->setStatusTip(tr("Draw circles with 3 points"));
51
52         return action;
53 }
54
55
56
57 void RS_ActionDrawCircle3P::reset() {
58     data.reset();
59     point1 = Vector(false);
60     point2 = Vector(false);
61     point3 = Vector(false);
62 }
63
64
65
66 void RS_ActionDrawCircle3P::init(int status) {
67     RS_PreviewActionInterface::init(status);
68
69     reset();
70 }
71
72
73
74 void RS_ActionDrawCircle3P::trigger() {
75     RS_PreviewActionInterface::trigger();
76
77     preparePreview();
78     if (data.isValid()) {
79         RS_Circle* circle = new RS_Circle(container,
80                                           data);
81         circle->setLayerToActive();
82         circle->setPenToActive();
83         container->addEntity(circle);
84
85         // upd. undo list:
86         if (document!=NULL) {
87             document->startUndoCycle();
88             document->addUndoable(circle);
89             document->endUndoCycle();
90         }
91         deleteSnapper();
92         Vector rz = graphicView->getRelativeZero();
93         graphicView->moveRelativeZero(Vector(0.0,0.0));
94         graphicView->drawEntity(circle);
95         graphicView->moveRelativeZero(rz);
96         drawSnapper();
97
98         setStatus(SetPoint1);
99         reset();
100     } else {
101         RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid circle data."));
102     }
103 }
104
105
106 void RS_ActionDrawCircle3P::preparePreview() {
107     data.reset();
108     if (point1.valid && point2.valid && point3.valid) {
109         RS_Circle circle(NULL, data);
110         bool suc = circle.createFrom3P(point1, point2, point3);
111         if (suc) {
112             data = circle.getData();
113         }
114     }
115 }
116
117
118
119 void RS_ActionDrawCircle3P::mouseMoveEvent(QMouseEvent* e) {
120     Vector mouse = snapPoint(e);
121
122     switch (getStatus()) {
123     case SetPoint1:
124         point1 = mouse;
125         break;
126
127     case SetPoint2:
128         point2 = mouse;
129         break;
130
131     case SetPoint3:
132         point3 = mouse;
133         preparePreview();
134         if (data.isValid()) {
135             RS_Circle* circle = new RS_Circle(preview, data);
136
137             deletePreview();
138             clearPreview();
139             preview->addEntity(circle);
140             drawPreview();
141         }
142         break;
143     }
144 }
145
146
147
148 void RS_ActionDrawCircle3P::mouseReleaseEvent(QMouseEvent* e) {
149     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
150         RS_CoordinateEvent ce(snapPoint(e));
151         coordinateEvent(&ce);
152     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
153         deletePreview();
154         deleteSnapper();
155         init(getStatus()-1);
156     }
157 }
158
159
160
161 void RS_ActionDrawCircle3P::coordinateEvent(RS_CoordinateEvent* e) {
162     if (e==NULL) {
163         return;
164     }
165     Vector mouse = e->getCoordinate();
166
167     switch (getStatus()) {
168     case SetPoint1:
169         point1 = mouse;
170         graphicView->moveRelativeZero(mouse);
171         setStatus(SetPoint2);
172         break;
173
174     case SetPoint2:
175         point2 = mouse;
176         graphicView->moveRelativeZero(mouse);
177         setStatus(SetPoint3);
178         break;
179
180     case SetPoint3:
181         point3 = mouse;
182         trigger();
183         break;
184
185     default:
186         break;
187     }
188 }
189
190
191
192 void RS_ActionDrawCircle3P::commandEvent(RS_CommandEvent* e) {
193     QString c = e->getCommand().toLower();
194
195     if (checkCommand("help", c)) {
196         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
197                                          + getAvailableCommands().join(", "));
198         return;
199     }
200 }
201
202
203
204 QStringList RS_ActionDrawCircle3P::getAvailableCommands() {
205     QStringList cmd;
206     return cmd;
207 }
208
209
210 void RS_ActionDrawCircle3P::updateMouseButtonHints() {
211     switch (getStatus()) {
212     case SetPoint1:
213         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"),
214                                             tr("Cancel"));
215         break;
216     case SetPoint2:
217         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"),
218                                             tr("Back"));
219         break;
220     case SetPoint3:
221         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify third point"),
222                                             tr("Back"));
223         break;
224     default:
225         RS_DIALOGFACTORY->updateMouseWidget("", "");
226         break;
227     }
228 }
229
230
231
232 void RS_ActionDrawCircle3P::updateMouseCursor() {
233     graphicView->setMouseCursor(RS2::CadCursor);
234 }
235
236
237
238 void RS_ActionDrawCircle3P::updateToolBar() {
239     if (!isFinished()) {
240         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
241     } else {
242         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);
243     }
244 }
245
246
247 // EOF
248