]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondimangular.cpp
57c16b44d0e9c918882f1c6cae15df53bde47228
[architektonas] / src / actions / rs_actiondimangular.cpp
1 /****************************************************************************
2 ** $Id: rs_actiondimangular.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_actiondimangular.h"
28
29 #include "rs_creation.h"
30 #include "rs_information.h"
31 #include "rs_snapper.h"
32 #include "rs_dialogfactory.h"
33
34
35
36 RS_ActionDimAngular::RS_ActionDimAngular(
37     RS_EntityContainer& container,
38     RS_GraphicView& graphicView)
39         :RS_ActionDimension("Draw Angular Dimensions",
40                     container, graphicView) {
41     reset();
42 }
43
44 QAction * RS_ActionDimAngular::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
45 {
46         QAction * action = new QAction(tr("&Angular"), 0);
47 //    QAction* action = new QAction(tr("Angular"), tr("&Angular"),
48 //                                  QKeySequence(), NULL);
49         action->setStatusTip(tr("Angular Dimension"));
50
51         return action;
52 }
53
54
55 void RS_ActionDimAngular::reset() {
56     RS_ActionDimension::reset();
57
58     edata = RS_DimAngularData(Vector(false),
59                               Vector(false),
60                               Vector(false),
61                               Vector(false));
62     line1 = NULL;
63     line2 = NULL;
64     center = Vector(false);
65     RS_DIALOGFACTORY->requestOptions(this, true, true);
66 }
67
68
69
70 void RS_ActionDimAngular::trigger() {
71     RS_PreviewActionInterface::trigger();
72
73     if (line1!=NULL && line2!=NULL) {
74         RS_DimAngular* newEntity = NULL;
75
76         newEntity = new RS_DimAngular(container,
77                                       data,
78                                       edata);
79
80         newEntity->setLayerToActive();
81         newEntity->setPenToActive();
82         newEntity->update();
83         container->addEntity(newEntity);
84
85         // upd. undo list:
86         if (document!=NULL) {
87             document->startUndoCycle();
88             document->addUndoable(newEntity);
89             document->endUndoCycle();
90         }
91         deleteSnapper();
92         Vector rz = graphicView->getRelativeZero();
93         graphicView->moveRelativeZero(Vector(0.0,0.0));
94         graphicView->drawEntity(newEntity);
95         graphicView->moveRelativeZero(rz);
96
97     } else {
98         RS_DEBUG->print("RS_ActionDimAngular::trigger:"
99                         " Entity is NULL\n");
100     }
101 }
102
103
104
105 void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent* e) {
106     RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin");
107
108     Vector mouse(graphicView->toGraphX(e->x()),
109                     graphicView->toGraphY(e->y()));
110
111     switch (getStatus()) {
112     case SetLine1:
113         break;
114
115     case SetLine2:
116         break;
117
118     case SetPos:
119         if (line1!=NULL && line2!=NULL && center.valid) {
120             Vector mouse = snapPoint(e);
121             edata.definitionPoint4 = mouse;
122
123             RS_DimAngular* d = new RS_DimAngular(preview, data, edata);
124             d->update();
125
126             deletePreview();
127             clearPreview();
128             preview->addEntity(d);
129             drawPreview();
130         }
131         break;
132
133     default:
134         break;
135     }
136
137     RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end");
138 }
139
140
141
142 void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent* e) {
143
144     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
145         switch (getStatus()) {
146         case SetLine1: {
147                 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
148                 if (en!=NULL &&
149                         en->rtti()==RS2::EntityLine) {
150                     line1 = (RS_Line*)en;
151                     setStatus(SetLine2);
152                 }
153             }
154             break;
155
156         case SetLine2: {
157                 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
158                 if (en!=NULL &&
159                         en->rtti()==RS2::EntityLine) {
160                     line2 = (RS_Line*)en;
161
162                     VectorSolutions sol =
163                         RS_Information::getIntersectionLineLine(line1, line2);
164
165                     if (sol.get(0).valid) {
166                         center = sol.get(0);
167
168                         if (center.distanceTo(line1->getStartpoint()) <
169                                 center.distanceTo(line1->getEndpoint())) {
170                             edata.definitionPoint1 = line1->getStartpoint();
171                             edata.definitionPoint2 = line1->getEndpoint();
172                         } else {
173                             edata.definitionPoint1 = line1->getEndpoint();
174                             edata.definitionPoint2 = line1->getStartpoint();
175                         }
176
177                         if (center.distanceTo(line2->getStartpoint()) <
178                                 center.distanceTo(line2->getEndpoint())) {
179                             edata.definitionPoint3 = line2->getStartpoint();
180                             data.definitionPoint = line2->getEndpoint();
181                         } else {
182                             edata.definitionPoint3 = line2->getEndpoint();
183                             data.definitionPoint = line2->getStartpoint();
184                         }
185                         graphicView->moveRelativeZero(center);
186                         setStatus(SetPos);
187                     }
188                 }
189             }
190             break;
191
192         case SetPos: {
193                 RS_CoordinateEvent ce(snapPoint(e));
194                 coordinateEvent(&ce);
195             }
196             break;
197         }
198     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
199         deletePreview();
200         deleteSnapper();
201         clearPreview();
202         init(getStatus()-1);
203     }
204
205 }
206
207
208
209 void RS_ActionDimAngular::coordinateEvent(RS_CoordinateEvent* e) {
210     if (e==NULL) {
211         return;
212     }
213
214     switch (getStatus()) {
215     case SetPos:
216         edata.definitionPoint4 = e->getCoordinate();
217         trigger();
218         reset();
219         setStatus(SetLine1);
220         break;
221
222     default:
223         break;
224     }
225 }
226
227
228 void RS_ActionDimAngular::commandEvent(RS_CommandEvent* e) {
229     QString c = e->getCommand().toLower();
230
231     if (checkCommand("help", c)) {
232         RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
233                                          + getAvailableCommands().join(", "));
234         return;
235     }
236
237     // setting new text label:
238     if (getStatus()==SetText) {
239         setText(c);
240         RS_DIALOGFACTORY->requestOptions(this, true, true);
241         graphicView->enableCoordinateInput();
242         setStatus(lastStatus);
243         return;
244     }
245
246     // command: text
247     if (checkCommand("text", c)) {
248         lastStatus = (Status)getStatus();
249         graphicView->disableCoordinateInput();
250         setStatus(SetText);
251     }
252 }
253
254
255
256 QStringList RS_ActionDimAngular::getAvailableCommands() {
257     QStringList cmd;
258
259     switch (getStatus()) {
260     case SetLine1:
261     case SetLine2:
262     case SetPos:
263         cmd += command("text");
264         break;
265
266     default:
267         break;
268     }
269
270     return cmd;
271 }
272
273
274
275 void RS_ActionDimAngular::showOptions() {
276     RS_ActionInterface::showOptions();
277
278     RS_DIALOGFACTORY->requestOptions(this, true);
279 }
280
281
282
283 void RS_ActionDimAngular::hideOptions() {
284     RS_ActionInterface::hideOptions();
285
286     RS_DIALOGFACTORY->requestOptions(this, false);
287 }
288
289
290
291 void RS_ActionDimAngular::updateMouseButtonHints() {
292     switch (getStatus()) {
293     case SetLine1:
294         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
295                                             tr("Cancel"));
296         break;
297     case SetLine2:
298         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
299                                             tr("Cancel"));
300         break;
301     case SetPos:
302         RS_DIALOGFACTORY->updateMouseWidget(
303             tr("Specify dimension arc line location"), tr("Cancel"));
304         break;
305     case SetText:
306         RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), "");
307         break;
308     default:
309         RS_DIALOGFACTORY->updateMouseWidget("", "");
310         break;
311     }
312 }
313
314
315
316 // EOF