]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionsnapintersectionmanual.cpp
Last checkin before major refactor...
[architektonas] / src / actions / rs_actionsnapintersectionmanual.cpp
1 // rs_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 "rs_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 RS_ActionSnapIntersectionManual::RS_ActionSnapIntersectionManual(
26         RS_EntityContainer & container, GraphicView & graphicView):
27         RS_PreviewActionInterface("Trim Entity", container, graphicView)
28 {
29         entity2 = NULL;
30         entity1 = NULL;
31         coord = Vector(false);
32 }
33
34 RS_ActionSnapIntersectionManual::~RS_ActionSnapIntersectionManual()
35 {
36 }
37
38 void RS_ActionSnapIntersectionManual::init(int status)
39 {
40         RS_ActionInterface::init(status);
41
42         snapMode = RS2::SnapFree;
43         snapRes = RS2::RestrictNothing;
44 }
45
46 void RS_ActionSnapIntersectionManual::trigger()
47 {
48         RS_DEBUG->print("RS_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 RS_ActionSnapIntersectionManual::mouseMoveEvent(QMouseEvent * e)
73 {
74         RS_DEBUG->print("RS_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                 entity2 = se;
87                 coord = mouse;
88
89                 VectorSolutions sol =
90                         RS_Information::getIntersection(entity1, entity2, false);
91
92                 //for (int i=0; i<sol.getNumber(); i++) {
93                 //    ip = sol.get(i);
94                 //    break;
95                 //}
96
97                 Vector ip = sol.getClosest(coord);
98
99                 if (ip.valid)
100                 {
101                         deletePreview();
102                         clearPreview();
103                         preview->addEntity(
104                                 new RS_Circle(preview,
105                                         RS_CircleData(
106                                                 ip,
107                                                 graphicView->toGraphDX(4))));
108                         drawPreview();
109
110                         RS_DIALOGFACTORY->updateCoordinateWidget(ip,
111                                 ip - graphicView->getRelativeZero());
112                 }
113         }
114         break;
115
116         default:
117                 break;
118         }
119
120         RS_DEBUG->print("RS_ActionSnapIntersectionManual::mouseMoveEvent end");
121 }
122
123 void RS_ActionSnapIntersectionManual::mouseReleaseEvent(QMouseEvent * e)
124 {
125         if (e->button() == Qt::LeftButton)
126         {
127                 Vector mouse = graphicView->toGraph(e->x(), e->y());
128                 RS_Entity * se = catchEntity(e);
129
130                 switch (getStatus())
131                 {
132                 case ChooseEntity1:
133                         entity1 = se;
134
135                         if (entity1 != NULL && entity1->isAtomic())
136                                 setStatus(ChooseEntity2);
137                         break;
138
139                 case ChooseEntity2:
140                         entity2 = se;
141                         coord = mouse;
142
143                         if (entity2 != NULL && entity2->isAtomic() && coord.valid)
144                                 trigger();
145                         break;
146
147                 default:
148                         break;
149                 }
150         }
151         else if (e->button() == Qt::RightButton)
152         {
153                 deletePreview();
154                 deleteSnapper();
155                 init(getStatus() - 1);
156         }
157 }
158
159 void RS_ActionSnapIntersectionManual::updateMouseButtonHints()
160 {
161         switch (getStatus())
162         {
163         case ChooseEntity1:
164                 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"),
165                         tr("Back"));
166                 break;
167
168         case ChooseEntity2:
169                 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"),
170                         tr("Back"));
171                 break;
172
173         default:
174                 RS_DIALOGFACTORY->updateMouseWidget("", "");
175                 break;
176         }
177 }
178
179 void RS_ActionSnapIntersectionManual::updateMouseCursor()
180 {
181         graphicView->setMouseCursor(RS2::CadCursor);
182 }
183
184 void RS_ActionSnapIntersectionManual::updateToolBar()
185 {
186         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
187 }
188
189 // EOF