]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawlineparallelthrough.cpp
Initial import
[architektonas] / src / actions / rs_actiondrawlineparallelthrough.cpp
1 /****************************************************************************
2 ** $Id: rs_actiondrawlineparallelthrough.cpp 1134 2004-07-13 23:26:13Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #include "rs_actiondrawlineparallelthrough.h"
28
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
31
32
33
34 RS_ActionDrawLineParallelThrough::RS_ActionDrawLineParallelThrough(
35     RS_EntityContainer& container,
36     RS_GraphicView& graphicView)
37         :RS_PreviewActionInterface("Draw Parallels", container, graphicView) {
38
39     parallel = NULL;
40     entity = NULL;
41     distance = 1.0;
42     number = 1;
43     coord = Vector(false);
44 }
45
46
47 QAction* RS_ActionDrawLineParallelThrough::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
48 {
49         QAction * action = new QAction(tr("Par&allel through point"), 0);
50 //      QAction* action = new QAction(tr("Parallel through point"),
51 //                                                                      tr("Par&allel through point"),
52 //                                                                      QKeySequence(), NULL);
53         action->setStatusTip(tr("Draw parallel through a given point"));
54         return action;
55 }
56
57 void RS_ActionDrawLineParallelThrough::trigger() {
58     RS_PreviewActionInterface::trigger();
59     deleteSnapper();
60
61     if (entity!=NULL) {
62         RS_Creation creation(container, graphicView);
63         RS_Entity* e = creation.createParallelThrough(coord,
64                        number,
65                        entity);
66
67         if (e==NULL) {
68             RS_DEBUG->print("RS_ActionDrawLineParallelThrough::trigger:"
69                             " No parallels added\n");
70         }
71     }
72 }
73
74
75
76 void RS_ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent* e) {
77     RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent begin");
78
79
80     switch (getStatus()) {
81     case SetEntity: {
82             entity = catchEntity(e, RS2::ResolveAll);
83             /*deletePreview();
84             clearPreview();
85
86             RS_Creation creation(preview, NULL, false);
87             creation.createParallelThrough(coord,
88                                            number,
89                                            entity);
90
91             drawPreview();*/
92         }
93         break;
94
95     case SetPos: {
96             coord = snapPoint(e);
97             //Vector(graphicView->toGraphX(e->x()),
98             //                  graphicView->toGraphY(e->y()));
99             deletePreview();
100             clearPreview();
101
102             RS_Creation creation(preview, NULL, false);
103             creation.createParallelThrough(coord,
104                                            number,
105                                            entity);
106
107             drawPreview();
108         }
109         break;
110
111     default:
112         break;
113     }
114
115     RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent end");
116 }
117
118
119
120 void RS_ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent* e) {
121     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
122         switch (getStatus()) {
123         case SetEntity:
124             entity = catchEntity(e, RS2::ResolveAll);
125             if (entity!=NULL) {
126                 entity->setHighlighted(true);
127                 graphicView->drawEntity(entity);
128                 setStatus(SetPos);
129             }
130             break;
131         case SetPos: {
132                 RS_CoordinateEvent ce(snapPoint(e));
133                 coordinateEvent(&ce);
134             }
135             break;
136         default:
137             break;
138         }
139     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
140         deletePreview();
141         deleteSnapper();
142         if (entity!=NULL) {
143             entity->setHighlighted(false);
144             graphicView->drawEntity(entity);
145             entity=NULL;
146         }
147         init(getStatus()-1);
148     }
149 }
150
151
152
153 void RS_ActionDrawLineParallelThrough::coordinateEvent(RS_CoordinateEvent* e) {
154     if (e==NULL) {
155         return;
156     }
157
158     Vector mouse = e->getCoordinate();
159
160     switch (getStatus()) {
161     case SetPos:
162         coord = mouse;
163         trigger();
164         break;
165
166     default:
167         break;
168     }
169 }
170
171
172
173 void RS_ActionDrawLineParallelThrough::updateMouseButtonHints() {
174     switch (getStatus()) {
175     case SetEntity:
176         RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel"));
177         break;
178
179     case SetPos:
180         RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"),
181                                             tr("Back"));
182         break;
183
184     case SetNumber:
185         RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back"));
186         break;
187
188     default:
189         RS_DIALOGFACTORY->updateMouseWidget("", "");
190         break;
191     }
192 }
193
194
195
196 void RS_ActionDrawLineParallelThrough::showOptions() {
197     RS_ActionInterface::showOptions();
198
199     RS_DIALOGFACTORY->requestOptions(this, true);
200     updateMouseButtonHints();
201 }
202
203
204
205 void RS_ActionDrawLineParallelThrough::hideOptions() {
206     RS_ActionInterface::hideOptions();
207
208     RS_DIALOGFACTORY->requestOptions(this, false);
209 }
210
211
212
213 void RS_ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent* e) {
214     QString c = e->getCommand().toLower();
215
216     if (checkCommand("help", c)) {
217         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
218                                          + getAvailableCommands().join(", "));
219         return;
220     }
221
222     switch (getStatus()) {
223     case SetEntity:
224     case SetPos: {
225             if (checkCommand("number", c)) {
226                 deleteSnapper();
227                 deletePreview();
228                 clearPreview();
229                 lastStatus = (Status)getStatus();
230                 setStatus(SetNumber);
231             }
232         }
233         break;
234
235     case SetNumber: {
236             bool ok;
237             int n = c.toInt(&ok);
238             if (ok==true) {
239                 if (n>0 && n<100) {
240                     number = n;
241                 } else {
242                     RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
243                                                         "Try 1..99"));
244                 }
245             } else {
246                 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
247             }
248             RS_DIALOGFACTORY->requestOptions(this, true, true);
249             setStatus(lastStatus);
250         }
251         break;
252
253     default:
254         break;
255     }
256 }
257
258
259
260 QStringList RS_ActionDrawLineParallelThrough::getAvailableCommands() {
261     QStringList cmd;
262
263     switch (getStatus()) {
264     case SetEntity:
265         cmd += command("number");
266         break;
267     default:
268         break;
269     }
270
271     return cmd;
272 }
273
274
275
276 void RS_ActionDrawLineParallelThrough::updateMouseCursor() {
277     graphicView->setMouseCursor(RS2::CadCursor);
278 }
279
280
281
282 void RS_ActionDrawLineParallelThrough::updateToolBar() {
283     if (getStatus()==SetPos && !isFinished()) {
284         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
285     } else {
286         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
287     }
288 }
289
290
291 // EOF