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