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