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