]> Shamusworld >> Repos - architektonas/blob - src/actions/actionselectintersected.cpp
In the middle of major refactoring...
[architektonas] / src / actions / actionselectintersected.cpp
1 // actionselectintersected.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  05/22/2010  Added this text. :-)
13 //
14
15 #include "actionselectintersected.h"
16
17 #include "rs_dialogfactory.h"
18 #include "rs_selection.h"
19 #include "rs_preview.h"
20
21 /**
22  * Constructor.
23  *
24  * @param select true: select window. false: deselect window
25  */
26 ActionSelectIntersected::ActionSelectIntersected(
27         RS_EntityContainer & container, GraphicView & graphicView, bool select):
28         ActionInterface("Select Intersected", container, graphicView)
29 {
30         this->select = select;
31 }
32
33 ActionSelectIntersected::~ActionSelectIntersected()
34 {
35 }
36
37 /*virtual*/ RS2::ActionType ActionSelectIntersected::rtti()
38 {
39         return RS2::ActionSelectIntersected;
40 }
41
42 void ActionSelectIntersected::init(int status)
43 {
44         ActionInterface::init(status);
45         v1 = v2 = Vector(false);
46 /*      snapMode = RS2::SnapFree;
47         snapRes = RS2::RestrictNothing;*/
48 }
49
50 void ActionSelectIntersected::trigger()
51 {
52         ActionInterface::trigger();
53
54         if (v1.valid && v2.valid)
55         {
56                 if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10)
57                 {
58                         deleteSnapper();
59                         RS_Selection s(*container, graphicView);
60                         s.selectIntersected(v1, v2, select);
61
62                         if (RS_DIALOGFACTORY)
63                                 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
64
65                         init();
66                 }
67         }
68 }
69
70 void ActionSelectIntersected::mouseMoveEvent(QMouseEvent * e)
71 {
72         if (getStatus() == SetPoint2 && v1.valid)
73         {
74                 v2 = snapPoint(e);
75                 deletePreview();
76                 clearPreview();
77 //              preview->addEntity(new RS_Line(preview, RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v2.y))));
78                 drawPreview();
79         }
80 }
81
82 void ActionSelectIntersected::mousePressEvent(QMouseEvent * e)
83 {
84         if (e->button() == Qt::LeftButton)
85         {
86                 switch (getStatus())
87                 {
88                 case SetPoint1:
89                         v1 = snapPoint(e);
90                         setStatus(SetPoint2);
91                         break;
92
93                 default:
94                         break;
95                 }
96         }
97
98         RS_DEBUG->print("ActionSelectIntersected::mousePressEvent(): %f %f",
99                 v1.x, v1.y);
100 }
101
102 void ActionSelectIntersected::mouseReleaseEvent(QMouseEvent * e)
103 {
104         RS_DEBUG->print("ActionSelectIntersected::mouseReleaseEvent()");
105
106         if (e->button() == Qt::RightButton)
107         {
108                 if (getStatus() == SetPoint2)
109                         deletePreview();
110
111                 deleteSnapper();
112                 init(getStatus() - 1);
113         }
114         else if (e->button() == Qt::LeftButton)
115         {
116                 if (getStatus() == SetPoint2)
117                 {
118                         v2 = snapPoint(e);
119                         trigger();
120                 }
121         }
122 }
123
124 void ActionSelectIntersected::updateMouseButtonHints()
125 {
126         if (RS_DIALOGFACTORY != NULL)
127         {
128                 switch (getStatus())
129                 {
130                 case SetPoint1:
131                         RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first point of intersection line"), tr("Cancel"));
132                         break;
133
134                 case SetPoint2:
135                         RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second point of intersection line"), tr("Back"));
136                         break;
137
138                 default:
139                         RS_DIALOGFACTORY->updateMouseWidget("", "");
140                         break;
141                 }
142         }
143 }
144
145 void ActionSelectIntersected::updateMouseCursor()
146 {
147         graphicView->setMouseCursor(RS2::SelectCursor);
148 }
149
150 void ActionSelectIntersected::updateToolBar()
151 {
152         if (RS_DIALOGFACTORY != NULL)
153         {
154                 if (!isFinished())
155                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
156                 else
157                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect);
158         }
159 }
160
161