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