]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondrawcirclecr.cpp
Initial removal of unnecessary rs_ prefixes from files.
[architektonas] / src / actions / actiondrawcirclecr.cpp
1 // actiondrawcirclecr.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/03/2010  Added this text. :-)
15 //
16
17 #include "actiondrawcirclecr.h"
18
19 #include "commandevent.h"
20 #include "debug.h"
21 #include "dialogfactory.h"
22 #include "graphicview.h"
23 #include "preview.h"
24
25 /**
26  * Constructor.
27  */
28 ActionDrawCircleCR::ActionDrawCircleCR(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Draw circles CR",
29                 container, graphicView)
30 {
31         reset();
32 }
33
34 ActionDrawCircleCR::~ActionDrawCircleCR()
35 {
36 }
37
38 /*virtual*/ RS2::ActionType ActionDrawCircleCR::rtti()
39 {
40         return RS2::ActionDrawCircleCR;
41 }
42
43 void ActionDrawCircleCR::reset()
44 {
45         data = RS_CircleData(Vector(false), 0.0);
46 }
47
48 void ActionDrawCircleCR::init(int status)
49 {
50         ActionInterface::init(status);
51 }
52
53 void ActionDrawCircleCR::trigger()
54 {
55         ActionInterface::trigger();
56
57         RS_Circle * circle = new RS_Circle(container, data);
58         circle->setLayerToActive();
59         circle->setPenToActive();
60         container->addEntity(circle);
61
62         // upd. undo list:
63         if (document != NULL)
64         {
65                 document->startUndoCycle();
66                 document->addUndoable(circle);
67                 document->endUndoCycle();
68         }
69
70         deleteSnapper();
71         Vector rz = graphicView->getRelativeZero();
72         graphicView->moveRelativeZero(Vector(0.0, 0.0));
73         graphicView->drawEntity(circle);
74         graphicView->moveRelativeZero(circle->getCenter());
75         drawSnapper();
76
77         setStatus(SetCenter);
78
79         RS_DEBUG->print("ActionDrawCircleCR::trigger(): circle added: %d", circle->getId());
80 }
81
82 void ActionDrawCircleCR::mouseMoveEvent(QMouseEvent * e)
83 {
84         RS_DEBUG->print("ActionDrawCircleCR::mouseMoveEvent begin");
85         Vector mouse = snapPoint(e);
86
87         switch (getStatus())
88         {
89         case SetCenter:
90                 data.center = mouse;
91                 deletePreview();
92                 clearPreview();
93 //              preview->addEntity(new RS_Circle(preview, data));
94                 drawPreview();
95                 break;
96         }
97
98         RS_DEBUG->print("ActionDrawCircleCR::mouseMoveEvent end");
99 }
100
101 void ActionDrawCircleCR::mouseReleaseEvent(QMouseEvent * e)
102 {
103         if (e->button() == Qt::LeftButton)
104         {
105                 Vector ce(snapPoint(e));
106                 coordinateEvent(&ce);
107         }
108         else if (e->button() == Qt::RightButton)
109         {
110                 deletePreview();
111                 deleteSnapper();
112                 init(getStatus() - 1);
113         }
114 }
115
116 void ActionDrawCircleCR::coordinateEvent(Vector * e)
117 {
118         if (e == NULL)
119                 return;
120
121         Vector mouse = *e;
122
123         switch (getStatus())
124         {
125         case SetCenter:
126                 data.center = mouse;
127                 trigger();
128                 break;
129
130         default:
131                 break;
132         }
133 }
134
135 void ActionDrawCircleCR::commandEvent(RS_CommandEvent * e)
136 {
137         QString c = e->getCommand().toLower();
138
139         if (checkCommand("help", c))
140         {
141                 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
142                         + getAvailableCommands().join(", "));
143                 return;
144         }
145
146         switch (getStatus())
147         {
148         case SetCenter:
149
150                 if (checkCommand("radius", c))
151                 {
152                         deleteSnapper();
153                         deletePreview();
154                         clearPreview();
155                         setStatus(SetRadius);
156                 }
157                 break;
158
159         case SetRadius:
160         {
161                 bool ok;
162                 double r = RS_Math::eval(c, &ok);
163
164                 if (ok == true)
165                         data.radius = r;
166                 else
167                         RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
168
169                 RS_DIALOGFACTORY->requestOptions(this, true, true);
170                 setStatus(SetCenter);
171         }
172         break;
173
174         default:
175                 break;
176         }
177 }
178
179 QStringList ActionDrawCircleCR::getAvailableCommands()
180 {
181         QStringList cmd;
182
183         switch (getStatus())
184         {
185         case SetCenter:
186                 cmd += command("radius");
187                 break;
188
189         default:
190                 break;
191         }
192
193         return cmd;
194 }
195
196 void ActionDrawCircleCR::updateMouseButtonHints()
197 {
198         switch (getStatus())
199         {
200         case SetCenter:
201                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle center"), tr("Cancel"));
202                 break;
203
204         case SetRadius:
205                 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle radius"), tr("Back"));
206                 break;
207
208         default:
209                 RS_DIALOGFACTORY->updateMouseWidget("", "");
210                 break;
211         }
212 }
213
214 void ActionDrawCircleCR::showOptions()
215 {
216         ActionInterface::showOptions();
217
218         RS_DIALOGFACTORY->requestOptions(this, true);
219 }
220
221 void ActionDrawCircleCR::hideOptions()
222 {
223         ActionInterface::hideOptions();
224
225         RS_DIALOGFACTORY->requestOptions(this, false);
226 }
227
228 void ActionDrawCircleCR::updateMouseCursor()
229 {
230         graphicView->setMouseCursor(RS2::CadCursor);
231 }
232
233 void ActionDrawCircleCR::updateToolBar()
234 {
235         if (!isFinished())
236                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
237         else
238                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles);
239 }
240
241 double ActionDrawCircleCR::getRadius()
242 {
243         return data.radius;
244 }
245
246 void ActionDrawCircleCR::setRadius(double r)
247 {
248         data.radius = r;
249 }