]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondrawlineparallelthrough.cpp
Removed unnecessary RS_ prefix from classes and whatnot.
[architektonas] / src / actions / actiondrawlineparallelthrough.cpp
1 // actiondrawlineparallelthrough.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/04/2010  Added this text. :-)
15 //
16
17 #include "actiondrawlineparallelthrough.h"
18
19 #include "commandevent.h"
20 #include "creation.h"
21 #include "debug.h"
22 #include "dialogfactory.h"
23 #include "graphicview.h"
24 #include "preview.h"
25
26 ActionDrawLineParallelThrough::ActionDrawLineParallelThrough(
27         EntityContainer & container, GraphicView & graphicView):
28         ActionInterface("Draw Parallels", container, graphicView)
29 {
30         parallel = NULL;
31         entity = NULL;
32 //???   distance = 1.0;
33         number = 1;
34         coord = Vector(false);
35 }
36
37 ActionDrawLineParallelThrough::~ActionDrawLineParallelThrough()
38 {
39 }
40
41 /*virtual*/ RS2::ActionType ActionDrawLineParallelThrough::rtti()
42 {
43         return RS2::ActionDrawLineParallelThrough;
44 }
45
46 void ActionDrawLineParallelThrough::trigger()
47 {
48         ActionInterface::trigger();
49         deleteSnapper();
50
51         if (entity)
52         {
53                 Creation creation(container, graphicView);
54                 Entity * e = creation.createParallelThrough(coord, number, entity);
55
56                 if (!e)
57                         DEBUG->print("ActionDrawLineParallelThrough::trigger:"
58                                 " No parallels added\n");
59         }
60 }
61
62 void ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent * e)
63 {
64         DEBUG->print("ActionDrawLineParallelThrough::mouseMoveEvent begin");
65
66         switch (getStatus())
67         {
68         case SetEntity:
69                 entity = catchEntity(e, RS2::ResolveAll);
70                 break;
71
72         case SetPos:
73         {
74                 coord = snapPoint(e);
75                 deletePreview();
76                 clearPreview();
77
78 //              Creation creation(preview, NULL, false);
79 //              creation.createParallelThrough(coord, number, entity);
80
81                 drawPreview();
82         }
83         break;
84
85         default:
86                 break;
87         }
88
89         DEBUG->print("ActionDrawLineParallelThrough::mouseMoveEvent end");
90 }
91
92 void ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent * e)
93 {
94         if (e->button() == Qt::LeftButton)
95         {
96                 switch (getStatus())
97                 {
98                 case SetEntity:
99                         entity = catchEntity(e, RS2::ResolveAll);
100
101                         if (entity)
102                         {
103                                 entity->setHighlighted(true);
104                                 graphicView->drawEntity(entity);
105                                 setStatus(SetPos);
106                         }
107
108                         break;
109
110                 case SetPos:
111                 {
112                         Vector ce(snapPoint(e));
113                         coordinateEvent(&ce);
114                 }
115                 break;
116
117                 default:
118                         break;
119                 }
120         }
121         else if (e->button() == Qt::RightButton)
122         {
123                 deletePreview();
124                 deleteSnapper();
125
126                 if (entity)
127                 {
128                         entity->setHighlighted(false);
129                         graphicView->drawEntity(entity);
130                         entity = NULL;
131                 }
132
133                 init(getStatus() - 1);
134         }
135 }
136
137 void ActionDrawLineParallelThrough::coordinateEvent(Vector * e)
138 {
139         if (e == NULL)
140                 return;
141
142         Vector mouse = *e;
143
144         switch (getStatus())
145         {
146         case SetPos:
147                 coord = mouse;
148                 trigger();
149                 break;
150
151         default:
152                 break;
153         }
154 }
155
156 void ActionDrawLineParallelThrough::updateMouseButtonHints()
157 {
158         switch (getStatus())
159         {
160         case SetEntity:
161                 DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel"));
162                 break;
163
164         case SetPos:
165                 DIALOGFACTORY->updateMouseWidget(tr("Specify through point"), tr("Back"));
166                 break;
167
168         case SetNumber:
169                 DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
170                 break;
171
172         default:
173                 DIALOGFACTORY->updateMouseWidget("", "");
174                 break;
175         }
176 }
177
178 void ActionDrawLineParallelThrough::showOptions()
179 {
180         ActionInterface::showOptions();
181         DIALOGFACTORY->requestOptions(this, true);
182         updateMouseButtonHints();
183 }
184
185 void ActionDrawLineParallelThrough::hideOptions()
186 {
187         ActionInterface::hideOptions();
188         DIALOGFACTORY->requestOptions(this, false);
189 }
190
191 void ActionDrawLineParallelThrough::commandEvent(CommandEvent * e)
192 {
193         QString c = e->getCommand().toLower();
194
195         if (checkCommand("help", c))
196         {
197                 DIALOGFACTORY->commandMessage(msgAvailableCommands()
198                         + getAvailableCommands().join(", "));
199                 return;
200         }
201
202         switch (getStatus())
203         {
204         case SetEntity:
205         case SetPos:
206
207                 if (checkCommand("number", c))
208                 {
209                         deleteSnapper();
210                         deletePreview();
211                         clearPreview();
212                         lastStatus = (Status)getStatus();
213                         setStatus(SetNumber);
214                 }
215                 break;
216
217         case SetNumber:
218         {
219                 bool ok;
220                 int n = c.toInt(&ok);
221
222                 if (ok == true)
223                 {
224                         if (n > 0 && n < 100)
225                                 number = n;
226                         else
227                                 DIALOGFACTORY->commandMessage(tr("Not a valid number. "
228                                                 "Try 1..99"));
229                 }
230                 else
231                         DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
232                 DIALOGFACTORY->requestOptions(this, true, true);
233                 setStatus(lastStatus);
234         }
235                 break;
236
237         default:
238                 break;
239         }
240 }
241
242 QStringList ActionDrawLineParallelThrough::getAvailableCommands()
243 {
244         QStringList cmd;
245
246         switch (getStatus())
247         {
248         case SetEntity:
249                 cmd += command("number");
250                 break;
251
252         default:
253                 break;
254         }
255
256         return cmd;
257 }
258
259 void ActionDrawLineParallelThrough::updateMouseCursor()
260 {
261         graphicView->setMouseCursor(RS2::CadCursor);
262 }
263
264 void ActionDrawLineParallelThrough::updateToolBar()
265 {
266         if (getStatus() == SetPos && !isFinished())
267                 DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
268         else
269                 DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
270 }
271
272 int ActionDrawLineParallelThrough::getNumber()
273 {
274         return number;
275 }
276
277 void ActionDrawLineParallelThrough::setNumber(int n)
278 {
279         number = n;
280 }