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