]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actiondrawlinetangent1.cpp
37dd3fd2c4c07c817167db6e742c3317ade5f53b
[architektonas] / src / actions / rs_actiondrawlinetangent1.cpp
1 /****************************************************************************
2 ** $Id: rs_actiondrawlinetangent1.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_actiondrawlinetangent1.h"
28
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
31
32
33
34 RS_ActionDrawLineTangent1::RS_ActionDrawLineTangent1(
35     RS_EntityContainer& container,
36     RS_GraphicView& graphicView)
37         :RS_PreviewActionInterface("Draw Tangents 1", container, graphicView) {
38
39     tangent = NULL;
40     point = Vector(false);
41     circle = NULL;
42 }
43
44
45 QAction* RS_ActionDrawLineTangent1::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
46 {
47         QAction * action = new QAction(tr("&Tangent (P,C)"), 0);
48 //      QAction* action = new QAction(tr("Tangent (P,C)"), tr("&Tangent (P,C)"),
49 //                                                                      QKeySequence(), NULL);
50         action->setStatusTip(tr("Draw tangent (point, circle)"));
51         return action;
52 }
53
54 void RS_ActionDrawLineTangent1::trigger() {
55     RS_PreviewActionInterface::trigger();
56
57     if (tangent!=NULL) {
58         RS_Entity* newEntity = NULL;
59
60         newEntity = new RS_Line(container,
61                                 tangent->getData());
62
63         if (newEntity!=NULL) {
64             newEntity->setLayerToActive();
65             newEntity->setPenToActive();
66             container->addEntity(newEntity);
67
68             // upd. undo list:
69             if (document!=NULL) {
70                 document->startUndoCycle();
71                 document->addUndoable(newEntity);
72                 document->endUndoCycle();
73             }
74
75             deleteSnapper();
76             graphicView->drawEntity(newEntity);
77
78             setStatus(SetPoint);
79         }
80         delete tangent;
81         tangent = NULL;
82     } else {
83         RS_DEBUG->print("RS_ActionDrawLineTangent1::trigger:"
84                         " Entity is NULL\n");
85     }
86 }
87
88
89
90 void RS_ActionDrawLineTangent1::mouseMoveEvent(QMouseEvent* e) {
91     RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent begin");
92
93     Vector mouse(graphicView->toGraphX(e->x()),
94                     graphicView->toGraphY(e->y()));
95
96     switch (getStatus()) {
97     case SetPoint:
98         point = snapPoint(e);
99         break;
100
101     case SetCircle: {
102             RS_Entity* en = catchEntity(e, RS2::ResolveAll);
103             if (en!=NULL && (en->rtti()==RS2::EntityCircle ||
104                              en->rtti()==RS2::EntityArc ||
105                              en->rtti()==RS2::EntityEllipse)) {
106                 circle = en;
107
108                 RS_Creation creation(NULL, NULL);
109                 RS_Line* t = creation.createTangent1(mouse,
110                                                      point,
111                                                      circle);
112
113                 if (t!=NULL) {
114                     if (tangent!=NULL) {
115                         delete tangent;
116                     }
117                     tangent = (RS_Line*)t->clone();
118
119                     deletePreview();
120                     clearPreview();
121                     preview->addEntity(t);
122                     drawPreview();
123                 }
124             }
125         }
126         break;
127
128     default:
129         break;
130     }
131
132     RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent end");
133 }
134
135
136
137 void RS_ActionDrawLineTangent1::mouseReleaseEvent(QMouseEvent* e) {
138
139     if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
140         deletePreview();
141         clearPreview();
142         deleteSnapper();
143         init(getStatus()-1);
144     } else {
145         switch (getStatus()) {
146         case SetPoint: {
147                 RS_CoordinateEvent ce(snapPoint(e));
148                 coordinateEvent(&ce);
149             }
150             break;
151
152         case SetCircle:
153             trigger();
154             break;
155         }
156     }
157
158 }
159
160
161 void RS_ActionDrawLineTangent1::coordinateEvent(RS_CoordinateEvent* e) {
162     if (e==NULL) {
163         return;
164     }
165
166     switch (getStatus()) {
167     case SetPoint:
168         point = e->getCoordinate();
169         deleteSnapper();
170         graphicView->moveRelativeZero(point);
171         setStatus(SetCircle);
172         break;
173
174     default:
175         break;
176     }
177 }
178
179
180 void RS_ActionDrawLineTangent1::updateMouseButtonHints() {
181     if (RS_DIALOGFACTORY!=NULL) {
182         switch (getStatus()) {
183         case SetPoint:
184             RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"),
185                                                 tr("Cancel"));
186             break;
187         case SetCircle:
188             RS_DIALOGFACTORY->updateMouseWidget(tr("Select circle, arc or ellipse"),
189                                                 tr("Back"));
190             break;
191         default:
192             RS_DIALOGFACTORY->updateMouseWidget("", "");
193             break;
194         }
195     }
196 }
197
198
199
200 void RS_ActionDrawLineTangent1::updateMouseCursor() {
201     graphicView->setMouseCursor(RS2::CadCursor);
202 }
203
204
205
206 void RS_ActionDrawLineTangent1::updateToolBar() {
207     if (RS_DIALOGFACTORY!=NULL) {
208         if (!isFinished()) {
209             RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
210         } else {
211             RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);
212         }
213     }
214 }
215
216
217
218 // EOF