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