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