]> Shamusworld >> Repos - architektonas/blob - src/actions/actionsnapintersectionmanual.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / actions / actionsnapintersectionmanual.cpp
1 // actionsetsnapintersectionmanual.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  06/05/2010  Added this text. :-)
15 //
16
17 #include "actionsnapintersectionmanual.h"
18
19 #include "debug.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "information.h"
23 #include "preview.h"
24
25 /**
26  * @param both Trim both entities.
27  */
28 ActionSnapIntersectionManual::ActionSnapIntersectionManual(
29         EntityContainer & container, GraphicView & graphicView):
30         ActionInterface("Trim Entity", container, graphicView)
31 {
32         entity2 = NULL;
33         entity1 = NULL;
34         coord = Vector(false);
35 }
36
37 ActionSnapIntersectionManual::~ActionSnapIntersectionManual()
38 {
39 }
40
41 void ActionSnapIntersectionManual::init(int status)
42 {
43         ActionInterface::init(status);
44
45 /*      snapMode = RS2::SnapFree;
46         snapRes = RS2::RestrictNothing;*/
47 }
48
49 void ActionSnapIntersectionManual::trigger()
50 {
51         DEBUG->print("ActionSnapIntersectionManual::trigger()");
52
53         if (entity2 != NULL && entity2->isAtomic()
54             && entity1 != NULL && entity1->isAtomic())
55         {
56                 VectorSolutions sol = Information::getIntersection(entity1, entity2, false);
57
58                 entity2 = NULL;
59                 entity1 = NULL;
60
61                 if (predecessor != NULL)
62                 {
63                         Vector ip = sol.getClosest(coord);
64
65                         if (ip.valid)
66                         {
67                                 Vector e(ip);
68                                 predecessor->coordinateEvent(&e);
69                         }
70                 }
71                 finish();
72         }
73 }
74
75 void ActionSnapIntersectionManual::mouseMoveEvent(QMouseEvent * e)
76 {
77         DEBUG->print("ActionSnapIntersectionManual::mouseMoveEvent begin");
78
79         Entity * se = catchEntity(e);
80         Vector mouse = graphicView->toGraph(e->x(), e->y());
81
82         switch (getStatus())
83         {
84         case ChooseEntity1:
85                 entity1 = se;
86                 break;
87
88         case ChooseEntity2:
89         {
90                 entity2 = se;
91                 coord = mouse;
92
93                 VectorSolutions sol = Information::getIntersection(entity1, entity2, false);
94                 Vector ip = sol.getClosest(coord);
95
96                 if (ip.valid)
97                 {
98                         deletePreview();
99                         clearPreview();
100 //                      preview->addEntity(new Circle(preview, CircleData(ip, graphicView->toGraphDX(4))));
101                         drawPreview();
102
103                         DIALOGFACTORY->updateCoordinateWidget(ip, ip - graphicView->getRelativeZero());
104                 }
105         }
106                 break;
107
108         default:
109                 break;
110         }
111
112         DEBUG->print("ActionSnapIntersectionManual::mouseMoveEvent end");
113 }
114
115 void ActionSnapIntersectionManual::mouseReleaseEvent(QMouseEvent * e)
116 {
117         if (e->button() == Qt::LeftButton)
118         {
119                 Vector mouse = graphicView->toGraph(e->x(), e->y());
120                 Entity * se = catchEntity(e);
121
122                 switch (getStatus())
123                 {
124                 case ChooseEntity1:
125                         entity1 = se;
126
127                         if (entity1 != NULL && entity1->isAtomic())
128                                 setStatus(ChooseEntity2);
129
130                         break;
131
132                 case ChooseEntity2:
133                         entity2 = se;
134                         coord = mouse;
135
136                         if (entity2 != NULL && entity2->isAtomic() && coord.valid)
137                                 trigger();
138                         break;
139
140                 default:
141                         break;
142                 }
143         }
144         else if (e->button() == Qt::RightButton)
145         {
146                 deletePreview();
147                 deleteSnapper();
148                 init(getStatus() - 1);
149         }
150 }
151
152 void ActionSnapIntersectionManual::updateMouseButtonHints()
153 {
154         switch (getStatus())
155         {
156         case ChooseEntity1:
157                 DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
158                         tr("Back"));
159                 break;
160
161         case ChooseEntity2:
162                 DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
163                         tr("Back"));
164                 break;
165
166         default:
167                 DIALOGFACTORY->updateMouseWidget("", "");
168                 break;
169         }
170 }
171
172 void ActionSnapIntersectionManual::updateMouseCursor()
173 {
174         graphicView->setMouseCursor(RS2::CadCursor);
175 }
176
177 void ActionSnapIntersectionManual::updateToolBar()
178 {
179         DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
180 }
181
182