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