b311480e |
1 | // Created on: 1998-08-27 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <AIS_InteractiveContext.hxx> |
679ecdee |
19 | #include <Aspect_Grid.hxx> |
42cf5bc1 |
20 | #include <Standard_Type.hxx> |
d09dda09 |
21 | #include <V3d_View.hxx> |
42cf5bc1 |
22 | #include <ViewerTest_EventManager.hxx> |
7fd59977 |
23 | |
92efcf78 |
24 | IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,MMgt_TShared) |
25 | |
7fd59977 |
26 | //======================================================================= |
27 | //function : ViewerTest_EventManager |
679ecdee |
28 | //purpose : |
7fd59977 |
29 | //======================================================================= |
679ecdee |
30 | ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView, |
31 | const Handle(AIS_InteractiveContext)& theCtx) |
32 | : myCtx (theCtx), |
33 | myView (theView), |
34 | myX (-1), |
35 | myY (-1) |
7fd59977 |
36 | {} |
37 | |
38 | //======================================================================= |
39 | //function : MoveTo |
679ecdee |
40 | //purpose : |
7fd59977 |
41 | //======================================================================= |
42 | |
679ecdee |
43 | void ViewerTest_EventManager::MoveTo (const Standard_Integer theXPix, |
44 | const Standard_Integer theYPix) |
7fd59977 |
45 | { |
679ecdee |
46 | Standard_Real aPnt3d[3] = {0.0, 0.0, 0.0}; |
47 | if (!myCtx.IsNull() |
48 | && !myView.IsNull()) |
49 | { |
50 | const Standard_Boolean toEchoGrid = myView->Viewer()->Grid()->IsActive() |
51 | && myView->Viewer()->GridEcho(); |
52 | switch (myCtx->MoveTo (theXPix, theYPix, myView, !toEchoGrid)) |
53 | { |
54 | case AIS_SOD_Nothing: |
55 | { |
56 | if (toEchoGrid) |
57 | { |
58 | myView->ConvertToGrid (theXPix, theYPix, aPnt3d[0], aPnt3d[1], aPnt3d[2]); |
59 | myView->Viewer()->ShowGridEcho (myView, Graphic3d_Vertex (aPnt3d[0], aPnt3d[1], aPnt3d[2])); |
60 | myView->RedrawImmediate(); |
61 | } |
62 | break; |
63 | } |
64 | default: |
65 | { |
66 | if (toEchoGrid) |
67 | { |
68 | myView->Viewer()->HideGridEcho (myView); |
69 | myView->RedrawImmediate(); |
70 | } |
71 | break; |
72 | } |
73 | } |
74 | } |
75 | |
76 | myX = theXPix; |
77 | myY = theYPix; |
7fd59977 |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : Select |
679ecdee |
82 | //purpose : |
7fd59977 |
83 | //======================================================================= |
84 | |
2157d6ac |
85 | void ViewerTest_EventManager::Select (const Standard_Integer theXPressed, |
86 | const Standard_Integer theYPressed, |
87 | const Standard_Integer theXMotion, |
88 | const Standard_Integer theYMotion, |
89 | const Standard_Boolean theIsAutoAllowOverlap) |
7fd59977 |
90 | { |
679ecdee |
91 | #define IS_FULL_INCLUSION Standard_True |
8abada55 |
92 | if (myView.IsNull() |
2157d6ac |
93 | || Abs (theXPressed - theXMotion) < 2 |
94 | || Abs (theYPressed - theYMotion) < 2) |
679ecdee |
95 | { |
96 | return; |
97 | } |
98 | else if (!myCtx.IsNull()) |
99 | { |
2157d6ac |
100 | if (theIsAutoAllowOverlap) |
101 | { |
102 | if (theYPressed == Min (theYPressed, theYMotion)) |
103 | { |
104 | myCtx->MainSelector()->AllowOverlapDetection (Standard_False); |
105 | } |
106 | else |
107 | { |
108 | myCtx->MainSelector()->AllowOverlapDetection (Standard_True); |
109 | } |
110 | } |
111 | myCtx->Select (Min (theXPressed, theXMotion), |
112 | Min (theYPressed, theYMotion), |
113 | Max (theXPressed, theXMotion), |
114 | Max (theYPressed, theYMotion), |
115 | myView, |
116 | Standard_False); |
117 | |
118 | // to restore default state of viewer selector |
119 | if (theIsAutoAllowOverlap) |
120 | { |
121 | myCtx->MainSelector()->AllowOverlapDetection (Standard_False); |
122 | } |
679ecdee |
123 | } |
124 | |
679ecdee |
125 | myView->Redraw(); |
7fd59977 |
126 | } |
127 | |
128 | //======================================================================= |
129 | //function : ShiftSelect |
679ecdee |
130 | //purpose : |
7fd59977 |
131 | //======================================================================= |
132 | |
2157d6ac |
133 | void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPressed, |
134 | const Standard_Integer theYPressed, |
135 | const Standard_Integer theXMotion, |
136 | const Standard_Integer theYMotion, |
137 | const Standard_Boolean theIsAutoAllowOverlap) |
679ecdee |
138 | { |
8abada55 |
139 | if (myView.IsNull() |
2157d6ac |
140 | || Abs (theXPressed - theXMotion) < 2 |
141 | || Abs (theYPressed - theYMotion) < 2) |
679ecdee |
142 | { |
143 | return; |
144 | } |
145 | else if (!myCtx.IsNull()) |
146 | { |
2157d6ac |
147 | if (theIsAutoAllowOverlap) |
148 | { |
149 | if (theYPressed == Min (theYPressed, theYMotion)) |
150 | { |
151 | myCtx->MainSelector()->AllowOverlapDetection (Standard_False); |
152 | } |
153 | else |
154 | { |
155 | myCtx->MainSelector()->AllowOverlapDetection (Standard_True); |
156 | } |
157 | } |
158 | myCtx->ShiftSelect (Min (theXPressed, theXMotion), |
159 | Min (theYPressed, theYMotion), |
160 | Max (theXPressed, theXMotion), |
161 | Max (theYPressed, theYMotion), |
162 | myView, |
163 | Standard_False); |
164 | |
165 | // to restore default state of viewer selector |
166 | if (theIsAutoAllowOverlap) |
167 | { |
168 | myCtx->MainSelector()->AllowOverlapDetection (Standard_False); |
169 | } |
679ecdee |
170 | } |
679ecdee |
171 | myView->Redraw(); |
7fd59977 |
172 | } |
173 | |
174 | //======================================================================= |
175 | //function : Select |
679ecdee |
176 | //purpose : |
7fd59977 |
177 | //======================================================================= |
178 | |
179 | void ViewerTest_EventManager::Select() |
180 | { |
679ecdee |
181 | if (myView.IsNull()) |
182 | { |
183 | return; |
184 | } |
185 | else if (!myCtx.IsNull()) |
186 | { |
187 | myCtx->Select (Standard_False); |
188 | } |
189 | |
679ecdee |
190 | myView->Redraw(); |
7fd59977 |
191 | } |
192 | |
193 | //======================================================================= |
194 | //function : ShiftSelect |
679ecdee |
195 | //purpose : |
7fd59977 |
196 | //======================================================================= |
197 | |
198 | void ViewerTest_EventManager::ShiftSelect() |
199 | { |
679ecdee |
200 | if (myView.IsNull()) |
201 | { |
202 | return; |
203 | } |
204 | else if (!myCtx.IsNull()) |
205 | { |
206 | myCtx->ShiftSelect (Standard_False); |
207 | } |
208 | |
679ecdee |
209 | myView->Redraw(); |
7fd59977 |
210 | } |
4754e164 |
211 | |
212 | //======================================================================= |
213 | //function : Select |
214 | //purpose : Selection with polyline |
215 | //======================================================================= |
216 | |
679ecdee |
217 | void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline) |
4754e164 |
218 | { |
679ecdee |
219 | if (myView.IsNull()) |
220 | { |
221 | return; |
222 | } |
223 | else if (!myCtx.IsNull()) |
224 | { |
225 | myCtx->Select (thePolyline, myView, Standard_False); |
226 | } |
227 | |
679ecdee |
228 | myView->Redraw(); |
4754e164 |
229 | } |
230 | |
231 | //======================================================================= |
232 | //function : ShiftSelect |
233 | //purpose : Selection with polyline without erasing of current selection |
234 | //======================================================================= |
235 | |
679ecdee |
236 | void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline) |
4754e164 |
237 | { |
679ecdee |
238 | if (myView.IsNull()) |
239 | { |
240 | return; |
241 | } |
242 | else if (!myCtx.IsNull()) |
243 | { |
244 | myCtx->ShiftSelect (thePolyline, myView, Standard_False); |
245 | } |
246 | |
679ecdee |
247 | myView->Redraw(); |
4754e164 |
248 | } |
c398b00e |
249 | |
250 | void ViewerTest_EventManager::GetCurrentPosition (Standard_Integer& theXPix, Standard_Integer& theYPix) const |
251 | { |
252 | theXPix = myX; |
253 | theYPix = myY; |
254 | } |