]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondrawlineparallel.cpp
Sanity check stage II: rename classes...
[architektonas] / src / actions / actiondrawlineparallel.cpp
1 // actiondrawlineparallel.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  05/22/2010  Added this text. :-)
15 //
16
17 #include "actiondrawlineparallel.h"
18
19 #include "actiondrawlineparallelthrough.h"
20 #include "rs_commandevent.h"
21 #include "commands.h"
22 #include "rs_creation.h"
23 #include "rs_debug.h"
24 #include "rs_dialogfactory.h"
25 #include "graphicview.h"
26 #include "rs_preview.h"
27
28 ActionDrawLineParallel::ActionDrawLineParallel(RS_EntityContainer & container,
29         GraphicView & graphicView): ActionInterface("Draw Parallels",
30         container, graphicView)
31 {
32         parallel = NULL;
33         entity = NULL;
34         distance = 1.0;
35         number = 1;
36         coord = Vector(false);
37 }
38
39 ActionDrawLineParallel::~ActionDrawLineParallel()
40 {
41 }
42
43 /*virtual*/ RS2::ActionType ActionDrawLineParallel::rtti()
44 {
45         return RS2::ActionDrawLineParallel;
46 }
47
48 void ActionDrawLineParallel::trigger()
49 {
50         ActionInterface::trigger();
51
52         RS_Creation creation(container, graphicView);
53         RS_Entity * e = creation.createParallel(coord, distance, number, entity);
54
55         if (!e)
56                 RS_DEBUG->print("ActionDrawLineParallel::trigger: No parallels added\n");
57 }
58
59 void ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e)
60 {
61         RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent begin");
62         coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y()));
63         entity = catchEntity(e, RS2::ResolveAll);
64
65         switch (getStatus())
66         {
67         case SetEntity:
68         {
69                 deletePreview();
70                 clearPreview();
71 //              RS_Creation creation(preview, NULL, false);
72 //              creation.createParallel(coord, distance, number, entity);
73                 drawPreview();
74         }
75         break;
76
77         default:
78                 break;
79         }
80
81         RS_DEBUG->print("ActionDrawLineParallel::mouseMoveEvent end");
82 }
83
84 void ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e)
85 {
86         if (e->button() == Qt::RightButton)
87                 init(getStatus() - 1);
88         else
89                 trigger();
90 }
91
92 void ActionDrawLineParallel::updateMouseButtonHints()
93 {
94         if (RS_DIALOGFACTORY != NULL)
95         {
96                 switch (getStatus())
97                 {
98                 case SetEntity:
99                         RS_DIALOGFACTORY->updateMouseWidget(
100                                 tr("Specify Distance <%1> or select entity or [%2]")
101                                 .arg(distance).arg(RS_COMMANDS->command("through")),
102                                 tr("Cancel"));
103                         break;
104
105                 case SetNumber:
106                         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
107                         break;
108
109                 default:
110                         RS_DIALOGFACTORY->updateMouseWidget("", "");
111                         break;
112                 }
113         }
114 }
115
116 void ActionDrawLineParallel::showOptions()
117 {
118         ActionInterface::showOptions();
119
120         if (RS_DIALOGFACTORY != NULL)
121                 RS_DIALOGFACTORY->requestOptions(this, true);
122
123         updateMouseButtonHints();
124 }
125
126 void ActionDrawLineParallel::hideOptions()
127 {
128         ActionInterface::hideOptions();
129
130         if (RS_DIALOGFACTORY != NULL)
131                 RS_DIALOGFACTORY->requestOptions(this, false);
132 }
133
134 void ActionDrawLineParallel::commandEvent(RS_CommandEvent * e)
135 {
136         QString c = e->getCommand().toLower();
137
138         if (checkCommand("help", c))
139         {
140                 if (RS_DIALOGFACTORY != NULL)
141                         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
142                                 + getAvailableCommands().join(", "));
143
144                 return;
145         }
146
147         switch (getStatus())
148         {
149         case SetEntity:
150                 if (checkCommand("through", c))
151                 {
152                         finish();
153                         graphicView->setCurrentAction(new ActionDrawLineParallelThrough(*container,
154                                         *graphicView));
155                 }
156                 else if (checkCommand("number", c))
157                 {
158                         deleteSnapper();
159                         deletePreview();
160                         clearPreview();
161                         setStatus(SetNumber);
162                 }
163                 else
164                 {
165                         bool ok;
166                         double d = RS_Math::eval(c, &ok);
167
168                         if (ok && d > 1.0e-10)
169                                 distance = d;
170                         else    if (RS_DIALOGFACTORY != NULL)
171                                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
172
173
174                         if (RS_DIALOGFACTORY != NULL)
175                                 RS_DIALOGFACTORY->requestOptions(this, true, true);
176
177                         updateMouseButtonHints();
178                         //setStatus(SetEntity);
179                 }
180                 break;
181
182         case SetNumber:
183         {
184                 bool ok;
185                 int n = c.toInt(&ok);
186
187                 if (ok)
188                 {
189                         if (n > 0 && n < 100)
190                                 number = n;
191                         else    if (RS_DIALOGFACTORY != NULL)
192                                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99"));
193
194                 }
195                 else    if (RS_DIALOGFACTORY != NULL)
196                         RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
197
198
199                 if (RS_DIALOGFACTORY != NULL)
200                         RS_DIALOGFACTORY->requestOptions(this, true, true);
201
202                 setStatus(SetEntity);
203         }
204         break;
205
206         default:
207                 break;
208         }
209 }
210
211 QStringList ActionDrawLineParallel::getAvailableCommands()
212 {
213         QStringList cmd;
214
215         switch (getStatus())
216         {
217         case SetEntity:
218                 cmd += command("number");
219                 cmd += command("through");
220                 break;
221
222         default:
223                 break;
224         }
225
226         return cmd;
227 }
228
229 void ActionDrawLineParallel::updateMouseCursor()
230 {
231         graphicView->setMouseCursor(RS2::CadCursor);
232 }
233
234 void ActionDrawLineParallel::updateToolBar()
235 {
236         if (RS_DIALOGFACTORY != NULL)
237                 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
238 }
239
240 double ActionDrawLineParallel::getDistance()
241 {
242         return distance;
243 }
244
245 void ActionDrawLineParallel::setDistance(double d)
246 {
247         distance = d;
248 }
249
250 int ActionDrawLineParallel::getNumber()
251 {
252         return number;
253 }
254
255 void ActionDrawLineParallel::setNumber(int n)
256 {
257         number = n;
258 }