]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionsnapintersectionmanual.cpp
Initial import
[architektonas] / src / actions / rs_actionsnapintersectionmanual.cpp
1 /****************************************************************************
2 ** $Id: rs_actionsnapintersectionmanual.cpp 1161 2004-12-09 23:10:09Z 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_actionsnapintersectionmanual.h"
28
29 #include "rs_information.h"
30 #include "rs_snapper.h"
31
32 /**
33  * @param both Trim both entities.
34  */
35 RS_ActionSnapIntersectionManual::RS_ActionSnapIntersectionManual(
36         RS_EntityContainer& container, RS_GraphicView& graphicView):
37         RS_PreviewActionInterface("Trim Entity", container, graphicView)
38 {
39         entity2 = NULL;
40         entity1 = NULL;
41         coord = Vector(false);
42 }
43
44 QAction * RS_ActionSnapIntersectionManual::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
45 {
46         QAction * action = new QAction(tr("I&ntersection Manually"), 0);
47         action->setCheckable(true);
48 //      QAction* action = new QAction(tr("Intersection Manually"), tr("I&ntersection Manually"),
49 //                                                                      QKeySequence(), NULL, 0, true);
50         action->setStatusTip(tr("Snap to intersection points manually"));
51         return action;
52 }
53
54 void RS_ActionSnapIntersectionManual::init(int status)
55 {
56         RS_ActionInterface::init(status);
57
58         snapMode = RS2::SnapFree;
59         snapRes = RS2::RestrictNothing;
60 }
61
62 void RS_ActionSnapIntersectionManual::trigger()
63 {
64     RS_DEBUG->print("RS_ActionSnapIntersectionManual::trigger()");
65
66     if (entity2!=NULL && entity2->isAtomic() &&
67             entity1!=NULL && entity1->isAtomic())
68         {
69         VectorSolutions sol =
70             RS_Information::getIntersection(entity1, entity2, false);
71
72         entity2 = NULL;
73         entity1 = NULL;
74         if (predecessor!=NULL) {
75             Vector ip = sol.getClosest(coord);
76
77             if (ip.valid) {
78                 RS_CoordinateEvent e(ip);
79                 predecessor->coordinateEvent(&e);
80             }
81         }
82         finish();
83     }
84 }
85
86
87
88 void RS_ActionSnapIntersectionManual::mouseMoveEvent(QMouseEvent* e) {
89     RS_DEBUG->print("RS_ActionSnapIntersectionManual::mouseMoveEvent begin");
90
91     RS_Entity* se = catchEntity(e);
92     Vector mouse = graphicView->toGraph(e->x(), e->y());
93
94     switch (getStatus()) {
95     case ChooseEntity1:
96         entity1 = se;
97         break;
98
99     case ChooseEntity2: {
100             entity2 = se;
101             coord = mouse;
102
103             VectorSolutions sol =
104                 RS_Information::getIntersection(entity1, entity2, false);
105
106             //for (int i=0; i<sol.getNumber(); i++) {
107             //    ip = sol.get(i);
108             //    break;
109             //}
110
111             Vector ip = sol.getClosest(coord);
112
113             if (ip.valid) {
114                 deletePreview();
115                 clearPreview();
116                 preview->addEntity(
117                     new RS_Circle(preview,
118                                   RS_CircleData(
119                                       ip,
120                                       graphicView->toGraphDX(4))));
121                 drawPreview();
122
123                 RS_DIALOGFACTORY->updateCoordinateWidget(ip,
124                         ip - graphicView->getRelativeZero());
125
126             }
127         }
128         break;
129
130     default:
131         break;
132     }
133
134     RS_DEBUG->print("RS_ActionSnapIntersectionManual::mouseMoveEvent end");
135 }
136
137
138
139 void RS_ActionSnapIntersectionManual::mouseReleaseEvent(QMouseEvent* e) {
140     if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
141
142         Vector mouse = graphicView->toGraph(e->x(), e->y());
143         RS_Entity* se = catchEntity(e);
144
145         switch (getStatus()) {
146         case ChooseEntity1:
147             entity1 = se;
148             if (entity1!=NULL && entity1->isAtomic()) {
149                 setStatus(ChooseEntity2);
150             }
151             break;
152
153         case ChooseEntity2:
154             entity2 = se;
155             coord = mouse;
156             if (entity2!=NULL && entity2->isAtomic() && coord.valid) {
157                 trigger();
158             }
159             break;
160
161         default:
162             break;
163         }
164     } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
165         deletePreview();
166         deleteSnapper();
167         init(getStatus()-1);
168     }
169 }
170
171
172
173 void RS_ActionSnapIntersectionManual::updateMouseButtonHints() {
174     switch (getStatus()) {
175     case ChooseEntity1:
176         RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
177                                             tr("Back"));
178         break;
179     case ChooseEntity2:
180         RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
181                                             tr("Back"));
182         break;
183     default:
184         RS_DIALOGFACTORY->updateMouseWidget("", "");
185         break;
186     }
187 }
188
189
190
191 void RS_ActionSnapIntersectionManual::updateMouseCursor() {
192     graphicView->setMouseCursor(RS2::CadCursor);
193 }
194
195
196
197 void RS_ActionSnapIntersectionManual::updateToolBar() {
198     RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
199 }
200
201
202 // EOF