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