49582f9d |
1 | // Copyright (c) 2016-2019 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #include "AIS_ViewController.hxx" |
15 | |
2108d9a2 |
16 | #include <AIS_AnimationCamera.hxx> |
49582f9d |
17 | #include <AIS_InteractiveContext.hxx> |
49582f9d |
18 | #include <AIS_Point.hxx> |
19 | #include <AIS_RubberBand.hxx> |
b40cdc2b |
20 | #include <AIS_XRTrackedDevice.hxx> |
21 | #include <Aspect_XRSession.hxx> |
49582f9d |
22 | #include <Aspect_Grid.hxx> |
23 | #include <Geom_CartesianPoint.hxx> |
24 | #include <Message.hxx> |
49582f9d |
25 | #include <gp_Quaternion.hxx> |
26 | #include <V3d_View.hxx> |
1a96d253 |
27 | #include <V3d_Viewer.hxx> |
d6fbb2ab |
28 | #include <WNT_HIDSpaceMouse.hxx> |
49582f9d |
29 | |
30 | // ======================================================================= |
31 | // function : AIS_ViewController |
32 | // purpose : |
33 | // ======================================================================= |
34 | AIS_ViewController::AIS_ViewController() |
35 | : myLastEventsTime (0.0), |
36 | myToAskNextFrame (false), |
f227f3dc |
37 | myIsContinuousRedraw(false), |
49582f9d |
38 | myMinCamDistance (1.0), |
39 | myRotationMode (AIS_RotationMode_BndBoxActive), |
40 | myNavigationMode (AIS_NavigationMode_Orbit), |
41 | myMouseAccel (1.0f), |
42 | myOrbitAccel (1.0f), |
43 | myToShowPanAnchorPoint (true), |
44 | myToShowRotateCenter (true), |
45 | myToLockOrbitZUp (false), |
46 | myToInvertPitch (false), |
47 | myToAllowTouchZRotation(false), |
48 | myToAllowRotation (true), |
49 | myToAllowPanning (true), |
50 | myToAllowZooming (true), |
51 | myToAllowZFocus (true), |
52 | myToAllowHighlight (true), |
53 | myToAllowDragging (true), |
9460f8c0 |
54 | myToStickToRayOnZoom (true), |
55 | myToStickToRayOnRotation (true), |
49582f9d |
56 | // |
57 | myWalkSpeedAbsolute (1.5f), |
58 | myWalkSpeedRelative (0.1f), |
59 | myThrustSpeed (0.0f), |
60 | myHasThrust (false), |
61 | // |
2108d9a2 |
62 | myViewAnimation (new AIS_AnimationCamera ("AIS_ViewController_ViewAnimation", Handle(V3d_View)())), |
8f709595 |
63 | myObjAnimation (new AIS_Animation ("AIS_ViewController_ObjectsAnimation")), |
64 | myToPauseObjAnimation (false), |
49582f9d |
65 | myPrevMoveTo (-1, -1), |
66 | myHasHlrOnBeforeRotation (false), |
67 | // |
b40cdc2b |
68 | myXRPrsDevices (0, 0), |
69 | myXRLaserTeleColor (Quantity_NOC_GREEN), |
70 | myXRLaserPickColor (Quantity_NOC_BLUE), |
71 | myXRLastTeleportHand(Aspect_XRTrackedDeviceRole_Other), |
72 | myXRLastPickingHand (Aspect_XRTrackedDeviceRole_Other), |
73 | myXRLastPickDepthLeft (Precision::Infinite()), |
74 | myXRLastPickDepthRight(Precision::Infinite()), |
75 | myXRTurnAngle (M_PI_4), |
76 | myToDisplayXRAuxDevices (false), |
77 | myToDisplayXRHands (true), |
78 | // |
49582f9d |
79 | myMouseClickThreshold (3.0), |
80 | myMouseDoubleClickInt (0.4), |
81 | myScrollZoomRatio (15.0f), |
82 | myMouseActiveGesture (AIS_MouseGesture_NONE), |
83 | myMouseActiveIdleRotation (false), |
84 | myMouseClickCounter (0), |
49582f9d |
85 | myMouseSingleButton (-1), |
215dd331 |
86 | myMouseStopDragOnUnclick (false), |
49582f9d |
87 | // |
88 | myTouchToleranceScale (1.0f), |
f9ab9f7f |
89 | myTouchClickThresholdPx (3.0f), |
49582f9d |
90 | myTouchRotationThresholdPx (6.0f), |
91 | myTouchZRotationThreshold (float(2.0 * M_PI / 180.0)), |
92 | myTouchPanThresholdPx (4.0f), |
93 | myTouchZoomThresholdPx (6.0f), |
94 | myTouchZoomRatio (0.13f), |
e3fd3d83 |
95 | myTouchDraggingThresholdPx (6.0f), |
49582f9d |
96 | // |
97 | myNbTouchesLast (0), |
98 | myUpdateStartPointPan (true), |
99 | myUpdateStartPointRot (true), |
100 | myUpdateStartPointZRot (true), |
101 | // |
102 | myPanPnt3d (Precision::Infinite(), 0.0, 0.0) |
103 | { |
d6fbb2ab |
104 | myViewAnimation->SetOwnDuration (0.5); |
49582f9d |
105 | |
106 | myAnchorPointPrs1 = new AIS_Point (new Geom_CartesianPoint (0.0, 0.0, 0.0)); |
107 | myAnchorPointPrs1->SetZLayer (Graphic3d_ZLayerId_Top); |
108 | myAnchorPointPrs1->SetMutable (true); |
109 | |
110 | myAnchorPointPrs2 = new AIS_Point (new Geom_CartesianPoint (0.0, 0.0, 0.0)); |
111 | myAnchorPointPrs2->SetZLayer (Graphic3d_ZLayerId_Topmost); |
112 | myAnchorPointPrs2->SetMutable (true); |
113 | |
9f013fee |
114 | myRubberBand = new AIS_RubberBand (Quantity_NOC_LIGHTBLUE, Aspect_TOL_SOLID, Quantity_NOC_LIGHTBLUE4, 0.5, 1.0); |
49582f9d |
115 | myRubberBand->SetZLayer (Graphic3d_ZLayerId_TopOSD); |
116 | myRubberBand->SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_UPPER)); |
117 | myRubberBand->SetDisplayMode (0); |
118 | myRubberBand->SetMutable (true); |
119 | |
9416ba5f |
120 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton, |
121 | AIS_MouseGesture_RotateOrbit); |
122 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton | (Standard_UInteger )Aspect_VKeyFlags_CTRL, |
123 | AIS_MouseGesture_Zoom); |
124 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton | (Standard_UInteger )Aspect_VKeyFlags_SHIFT, |
125 | AIS_MouseGesture_Pan); |
126 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton | (Standard_UInteger )Aspect_VKeyFlags_ALT, |
127 | AIS_MouseGesture_SelectRectangle); |
128 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton | (Standard_UInteger )Aspect_VKeyFlags_ALT | (Standard_UInteger )Aspect_VKeyFlags_SHIFT, |
129 | AIS_MouseGesture_SelectRectangle); |
e3d4b879 |
130 | |
9416ba5f |
131 | myMouseSelectionSchemes.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton, |
132 | AIS_SelectionScheme_Replace); |
133 | myMouseSelectionSchemes.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton | (Standard_UInteger )Aspect_VKeyFlags_ALT, |
134 | AIS_SelectionScheme_Replace); |
135 | myMouseSelectionSchemes.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton | (Standard_UInteger )Aspect_VKeyFlags_SHIFT, |
136 | AIS_SelectionScheme_XOR); |
137 | myMouseSelectionSchemes.Bind ((Standard_UInteger )Aspect_VKeyMouse_LeftButton | (Standard_UInteger )Aspect_VKeyFlags_ALT | (Standard_UInteger )Aspect_VKeyFlags_SHIFT, |
138 | AIS_SelectionScheme_XOR); |
49582f9d |
139 | |
9416ba5f |
140 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_RightButton, |
141 | AIS_MouseGesture_Zoom); |
142 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_RightButton | (Standard_UInteger )Aspect_VKeyFlags_CTRL, |
143 | AIS_MouseGesture_RotateOrbit); |
49582f9d |
144 | |
9416ba5f |
145 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_MiddleButton, |
146 | AIS_MouseGesture_Pan); |
147 | myMouseGestureMap.Bind ((Standard_UInteger )Aspect_VKeyMouse_MiddleButton | (Standard_UInteger )Aspect_VKeyFlags_CTRL, |
148 | AIS_MouseGesture_Pan); |
b40cdc2b |
149 | |
9416ba5f |
150 | myMouseGestureMapDrag.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Drag); |
e3fd3d83 |
151 | |
b40cdc2b |
152 | myXRTeleportHaptic.Duration = 3600.0f; |
153 | myXRTeleportHaptic.Frequency = 0.1f; |
154 | myXRTeleportHaptic.Amplitude = 0.2f; |
155 | |
156 | myXRPickingHaptic.Duration = 0.1f; |
157 | myXRPickingHaptic.Frequency = 4.0f; |
158 | myXRPickingHaptic.Amplitude = 0.1f; |
159 | |
160 | myXRSelectHaptic.Duration = 0.2f; |
161 | myXRSelectHaptic.Frequency = 4.0f; |
162 | myXRSelectHaptic.Amplitude = 0.5f; |
49582f9d |
163 | } |
164 | |
00ea7f26 |
165 | // ======================================================================= |
166 | // function : ~AIS_ViewController |
167 | // purpose : |
168 | // ======================================================================= |
169 | AIS_ViewController::~AIS_ViewController() |
170 | { |
171 | // |
172 | } |
173 | |
49582f9d |
174 | // ======================================================================= |
175 | // function : ResetViewInput |
176 | // purpose : |
177 | // ======================================================================= |
178 | void AIS_ViewController::ResetViewInput() |
179 | { |
180 | myKeys.Reset(); |
181 | myMousePressed = Aspect_VKeyMouse_NONE; |
182 | myMouseModifiers = Aspect_VKeyFlags_NONE; |
183 | myMouseSingleButton = -1; |
184 | myUI.Dragging.ToAbort = true; |
185 | myMouseActiveGesture = AIS_MouseGesture_NONE; |
186 | myMouseClickTimer.Stop(); |
187 | myMouseClickCounter = 0; |
188 | } |
189 | |
190 | // ======================================================================= |
191 | // function : FlushViewEvents |
192 | // purpose : |
193 | // ======================================================================= |
194 | void AIS_ViewController::FlushViewEvents (const Handle(AIS_InteractiveContext)& theCtx, |
195 | const Handle(V3d_View)& theView, |
196 | Standard_Boolean theToHandle) |
197 | { |
198 | flushBuffers (theCtx, theView); |
199 | flushGestures(theCtx, theView); |
879768fb |
200 | |
201 | if (theView->IsSubview()) |
202 | { |
203 | // move input coordinates inside the view |
204 | const Graphic3d_Vec2i aDelta = theView->View()->SubviewTopLeft(); |
205 | if (myGL.MoveTo.ToHilight || myGL.Dragging.ToStart) |
206 | { |
207 | myGL.MoveTo.Point -= aDelta; |
208 | } |
209 | if (myGL.Panning.ToStart) |
210 | { |
211 | myGL.Panning.PointStart -= aDelta; |
212 | } |
213 | if (myGL.Dragging.ToStart) |
214 | { |
215 | myGL.Dragging.PointStart -= aDelta; |
216 | } |
217 | if (myGL.Dragging.ToMove) |
218 | { |
219 | myGL.Dragging.PointTo -= aDelta; |
220 | } |
221 | if (myGL.OrbitRotation.ToStart) |
222 | { |
223 | myGL.OrbitRotation.PointStart -= Graphic3d_Vec2d (aDelta); |
224 | } |
225 | if (myGL.OrbitRotation.ToRotate) |
226 | { |
227 | myGL.OrbitRotation.PointTo -= Graphic3d_Vec2d (aDelta); |
228 | } |
229 | if (myGL.ViewRotation.ToStart) |
230 | { |
231 | myGL.ViewRotation.PointStart -= Graphic3d_Vec2d (aDelta); |
232 | } |
233 | if (myGL.ViewRotation.ToRotate) |
234 | { |
235 | myGL.ViewRotation.PointTo -= Graphic3d_Vec2d (aDelta); |
236 | } |
237 | for (Graphic3d_Vec2i& aPntIter : myGL.Selection.Points) |
238 | { |
239 | aPntIter -= aDelta; |
240 | } |
241 | for (Aspect_ScrollDelta& aZoomIter : myGL.ZoomActions) |
242 | { |
243 | aZoomIter.Point -= aDelta; |
244 | } |
245 | } |
246 | |
49582f9d |
247 | if (theToHandle) |
248 | { |
249 | HandleViewEvents (theCtx, theView); |
250 | } |
251 | } |
252 | |
253 | // ======================================================================= |
254 | // function : flushBuffers |
255 | // purpose : |
256 | // ======================================================================= |
257 | void AIS_ViewController::flushBuffers (const Handle(AIS_InteractiveContext)& , |
258 | const Handle(V3d_View)& ) |
259 | { |
260 | myToAskNextFrame = false; |
261 | |
262 | myGL.IsNewGesture = myUI.IsNewGesture; |
263 | myUI.IsNewGesture = false; |
264 | |
265 | myGL.ZoomActions.Clear(); |
266 | myGL.ZoomActions.Append (myUI.ZoomActions); |
267 | myUI.ZoomActions.Clear(); |
268 | |
269 | myGL.Orientation.ToFitAll = myUI.Orientation.ToFitAll; |
270 | myUI.Orientation.ToFitAll = false; |
271 | if (myUI.Orientation.ToSetViewOrient) |
272 | { |
273 | myUI.Orientation.ToSetViewOrient = false; |
274 | myGL.Orientation.ToSetViewOrient = true; |
275 | myGL.Orientation.ViewOrient = myUI.Orientation.ViewOrient; |
276 | } |
277 | |
278 | if (myUI.MoveTo.ToHilight) |
279 | { |
280 | myUI.MoveTo.ToHilight = false; |
281 | myGL.MoveTo.ToHilight = true; |
282 | myGL.MoveTo.Point = myUI.MoveTo.Point; |
283 | } |
284 | |
285 | { |
286 | myGL.Selection.Tool = myUI.Selection.Tool; |
e3d4b879 |
287 | myGL.Selection.Scheme = myUI.Selection.Scheme; |
49582f9d |
288 | myGL.Selection.Points = myUI.Selection.Points; |
e3d4b879 |
289 | //myGL.Selection.Scheme = AIS_SelectionScheme_UNKNOWN; // no need |
49582f9d |
290 | if (myUI.Selection.Tool == AIS_ViewSelectionTool_Picking) |
291 | { |
292 | myUI.Selection.Points.Clear(); |
293 | } |
294 | } |
295 | |
296 | if (myUI.Selection.ToApplyTool) |
297 | { |
298 | myGL.Selection.ToApplyTool = true; |
299 | myUI.Selection.ToApplyTool = false; |
300 | myUI.Selection.Points.Clear(); |
301 | } |
302 | |
303 | if (myUI.Panning.ToStart) |
304 | { |
305 | myUI.Panning.ToStart = false; |
306 | myGL.Panning.ToStart = true; |
307 | myGL.Panning.PointStart = myUI.Panning.PointStart; |
308 | } |
309 | |
310 | if (myUI.Panning.ToPan) |
311 | { |
312 | myUI.Panning.ToPan = false; |
313 | myGL.Panning.ToPan = true; |
314 | myGL.Panning.Delta = myUI.Panning.Delta; |
315 | } |
316 | |
317 | if (myUI.Dragging.ToAbort) |
318 | { |
319 | myUI.Dragging.ToAbort = false; |
320 | myGL.Dragging.ToAbort = true; |
321 | } |
322 | else if (myUI.Dragging.ToStop) |
323 | { |
324 | myUI.Dragging.ToStop = false; |
325 | myGL.Dragging.ToStop = true; |
326 | } |
e3fd3d83 |
327 | else |
49582f9d |
328 | { |
e3fd3d83 |
329 | if (myUI.Dragging.ToStart) |
330 | { |
331 | myUI.Dragging.ToStart = false; |
332 | myGL.Dragging.ToStart = true; |
333 | myGL.Dragging.PointStart = myUI.Dragging.PointStart; |
334 | } |
6ef56849 |
335 | if (myUI.Dragging.ToConfirm) |
336 | { |
337 | myUI.Dragging.ToConfirm = false; |
338 | myGL.Dragging.ToConfirm = true; |
339 | } |
e3fd3d83 |
340 | if (myUI.Dragging.ToMove) |
341 | { |
342 | myUI.Dragging.ToMove = false; |
343 | myGL.Dragging.ToMove = true; |
344 | } |
49582f9d |
345 | } |
e3fd3d83 |
346 | |
49582f9d |
347 | myGL.Dragging.PointTo = myUI.Dragging.PointTo; |
348 | |
349 | if (myUI.OrbitRotation.ToStart) |
350 | { |
351 | myUI.OrbitRotation.ToStart = false; |
352 | myGL.OrbitRotation.ToStart = true; |
353 | myGL.OrbitRotation.PointStart = myUI.OrbitRotation.PointStart; |
354 | } |
355 | |
356 | if (myUI.OrbitRotation.ToRotate) |
357 | { |
358 | myUI.OrbitRotation.ToRotate = false; |
359 | myGL.OrbitRotation.ToRotate = true; |
360 | myGL.OrbitRotation.PointTo = myUI.OrbitRotation.PointTo; |
361 | } |
362 | |
363 | if (myUI.ViewRotation.ToStart) |
364 | { |
365 | myUI.ViewRotation.ToStart = false; |
366 | myGL.ViewRotation.ToStart = true; |
367 | myGL.ViewRotation.PointStart = myUI.ViewRotation.PointStart; |
368 | } |
369 | |
370 | if (myUI.ViewRotation.ToRotate) |
371 | { |
372 | myUI.ViewRotation.ToRotate = false; |
373 | myGL.ViewRotation.ToRotate = true; |
374 | myGL.ViewRotation.PointTo = myUI.ViewRotation.PointTo; |
375 | } |
376 | |
377 | if (myUI.ZRotate.ToRotate) |
378 | { |
379 | myGL.ZRotate = myUI.ZRotate; |
380 | myUI.ZRotate.ToRotate = false; |
381 | } |
382 | } |
383 | |
384 | // ======================================================================= |
385 | // function : flushGestures |
386 | // purpose : |
387 | // ======================================================================= |
388 | void AIS_ViewController::flushGestures (const Handle(AIS_InteractiveContext)& , |
389 | const Handle(V3d_View)& theView) |
390 | { |
391 | const Standard_Real aTolScale = myTouchToleranceScale; |
392 | const Standard_Integer aTouchNb = myTouchPoints.Extent(); |
393 | if (myNbTouchesLast != aTouchNb) |
394 | { |
395 | myNbTouchesLast = aTouchNb; |
396 | myGL.IsNewGesture = true; |
397 | } |
398 | if (aTouchNb == 1) // touch |
399 | { |
400 | Aspect_Touch& aTouch = myTouchPoints.ChangeFromIndex (1); |
401 | if (myUpdateStartPointRot) |
402 | { |
403 | // skip rotation if have active dragged object |
404 | if (myNavigationMode == AIS_NavigationMode_Orbit) |
405 | { |
406 | myGL.OrbitRotation.ToStart = true; |
407 | myGL.OrbitRotation.PointStart = myStartRotCoord; |
408 | } |
409 | else |
410 | { |
411 | myGL.ViewRotation.ToStart = true; |
412 | myGL.ViewRotation.PointStart = myStartRotCoord; |
413 | } |
414 | |
415 | myUpdateStartPointRot = false; |
416 | theView->Invalidate(); |
417 | } |
418 | |
419 | // rotation |
420 | const Standard_Real aRotTouchTol = !aTouch.IsPreciseDevice |
421 | ? aTolScale * myTouchRotationThresholdPx |
422 | : gp::Resolution(); |
423 | if (Abs (aTouch.Delta().x()) + Abs(aTouch.Delta().y()) > aRotTouchTol) |
424 | { |
425 | const Standard_Real aRotAccel = myNavigationMode == AIS_NavigationMode_FirstPersonWalk ? myMouseAccel : myOrbitAccel; |
426 | if (myNavigationMode == AIS_NavigationMode_Orbit) |
427 | { |
428 | const Graphic3d_Vec2d aRotDelta = aTouch.To - myGL.OrbitRotation.PointStart; |
429 | myGL.OrbitRotation.ToRotate = true; |
430 | myGL.OrbitRotation.PointTo = myGL.OrbitRotation.PointStart + aRotDelta * aRotAccel; |
e3fd3d83 |
431 | myGL.Dragging.ToMove = true; |
49582f9d |
432 | myGL.Dragging.PointTo.SetValues ((int )aTouch.To.x(), (int )aTouch.To.y()); |
433 | } |
434 | else |
435 | { |
436 | const Graphic3d_Vec2d aRotDelta = aTouch.To - myGL.ViewRotation.PointStart; |
437 | myGL.ViewRotation.ToRotate = true; |
438 | myGL.ViewRotation.PointTo = myGL.ViewRotation.PointStart + aRotDelta * aRotAccel; |
e3fd3d83 |
439 | myGL.Dragging.ToMove = true; |
49582f9d |
440 | myGL.Dragging.PointTo.SetValues ((int )aTouch.To.x(), (int )aTouch.To.y()); |
441 | } |
442 | |
443 | aTouch.From = aTouch.To; |
444 | } |
445 | } |
446 | else if (aTouchNb == 2) // pinch |
447 | { |
448 | Aspect_Touch& aFirstTouch = myTouchPoints.ChangeFromIndex (1); |
449 | Aspect_Touch& aLastTouch = myTouchPoints.ChangeFromIndex (2); |
450 | const Graphic3d_Vec2d aFrom[2] = { aFirstTouch.From, aLastTouch.From }; |
451 | const Graphic3d_Vec2d aTo[2] = { aFirstTouch.To, aLastTouch.To }; |
452 | |
453 | Graphic3d_Vec2d aPinchCenterStart ((aFrom[0].x() + aFrom[1].x()) / 2.0, |
454 | (aFrom[0].y() + aFrom[1].y()) / 2.0); |
455 | |
456 | Standard_Real aPinchCenterXEnd = (aTo[0].x() + aTo[1].x()) / 2.0; |
457 | Standard_Real aPinchCenterYEnd = (aTo[0].y() + aTo[1].y()) / 2.0; |
458 | |
459 | Standard_Real aPinchCenterXDev = aPinchCenterXEnd - aPinchCenterStart.x(); |
460 | Standard_Real aPinchCenterYDev = aPinchCenterYEnd - aPinchCenterStart.y(); |
461 | |
462 | Standard_Real aStartSize = (aFrom[0] - aFrom[1]).Modulus(); |
463 | Standard_Real anEndSize = ( aTo[0] - aTo[1]).Modulus(); |
464 | |
465 | Standard_Real aDeltaSize = anEndSize - aStartSize; |
466 | |
467 | bool anIsClearDev = false; |
468 | |
469 | if (myToAllowTouchZRotation) |
470 | { |
471 | Standard_Real A1 = aFrom[0].y() - aFrom[1].y(); |
472 | Standard_Real B1 = aFrom[1].x() - aFrom[0].x(); |
473 | |
474 | Standard_Real A2 = aTo[0].y() - aTo[1].y(); |
475 | Standard_Real B2 = aTo[1].x() - aTo[0].x(); |
476 | |
477 | Standard_Real aRotAngle = 0.0; |
478 | |
479 | Standard_Real aDenomenator = A1*A2 + B1*B2; |
480 | if (aDenomenator <= Precision::Confusion()) |
481 | { |
482 | aRotAngle = 0.0; |
483 | } |
484 | else |
485 | { |
486 | Standard_Real aNumerator = A1*B2 - A2*B1; |
487 | aRotAngle = ATan (aNumerator / aDenomenator); |
488 | } |
489 | |
490 | if (Abs(aRotAngle) > Standard_Real(myTouchZRotationThreshold)) |
491 | { |
492 | myGL.ZRotate.ToRotate = true; |
493 | myGL.ZRotate.Angle = aRotAngle; |
494 | anIsClearDev = true; |
495 | } |
496 | } |
497 | |
498 | if (Abs(aDeltaSize) > aTolScale * myTouchZoomThresholdPx) |
499 | { |
500 | // zoom |
501 | aDeltaSize *= Standard_Real(myTouchZoomRatio); |
502 | Aspect_ScrollDelta aParams (Graphic3d_Vec2i (aPinchCenterStart), aDeltaSize); |
503 | myGL.ZoomActions.Append (aParams); |
504 | anIsClearDev = true; |
505 | } |
506 | |
507 | const Standard_Real aPanTouchTol = !aFirstTouch.IsPreciseDevice |
508 | ? aTolScale * myTouchPanThresholdPx |
509 | : gp::Resolution(); |
510 | if (Abs(aPinchCenterXDev) + Abs(aPinchCenterYDev) > aPanTouchTol) |
511 | { |
512 | // pan |
513 | if (myUpdateStartPointPan) |
514 | { |
515 | myGL.Panning.ToStart = true; |
516 | myGL.Panning.PointStart = Graphic3d_Vec2i (myStartPanCoord); |
517 | myUpdateStartPointPan = false; |
518 | theView->Invalidate(); |
519 | } |
520 | |
521 | myGL.Panning.ToPan = true; |
522 | myGL.Panning.Delta.x() = int( aPinchCenterXDev); |
523 | myGL.Panning.Delta.y() = int(-aPinchCenterYDev); |
524 | anIsClearDev = true; |
525 | } |
526 | |
527 | if (anIsClearDev) |
528 | { |
529 | aFirstTouch.From = aFirstTouch.To; |
530 | aLastTouch .From = aLastTouch.To; |
531 | } |
532 | } |
533 | } |
534 | |
535 | // ======================================================================= |
536 | // function : UpdateViewOrientation |
537 | // purpose : |
538 | // ======================================================================= |
539 | void AIS_ViewController::UpdateViewOrientation (V3d_TypeOfOrientation theOrientation, |
540 | bool theToFitAll) |
541 | { |
542 | myUI.Orientation.ToFitAll = theToFitAll; |
543 | myUI.Orientation.ToSetViewOrient = true; |
544 | myUI.Orientation.ViewOrient = theOrientation; |
545 | } |
546 | |
547 | // ======================================================================= |
548 | // function : SelectInViewer |
549 | // purpose : |
550 | // ======================================================================= |
551 | void AIS_ViewController::SelectInViewer (const Graphic3d_Vec2i& thePnt, |
e3d4b879 |
552 | const AIS_SelectionScheme theScheme) |
49582f9d |
553 | { |
554 | if (myUI.Selection.Tool != AIS_ViewSelectionTool_Picking) |
555 | { |
556 | myUI.Selection.Tool = AIS_ViewSelectionTool_Picking; |
557 | myUI.Selection.Points.Clear(); |
558 | } |
559 | |
e3d4b879 |
560 | myUI.Selection.Scheme = theScheme; |
49582f9d |
561 | myUI.Selection.Points.Append (thePnt); |
562 | } |
563 | |
564 | // ======================================================================= |
565 | // function : SelectInViewer |
566 | // purpose : |
567 | // ======================================================================= |
568 | void AIS_ViewController::SelectInViewer (const NCollection_Sequence<Graphic3d_Vec2i>& thePnts, |
e3d4b879 |
569 | const AIS_SelectionScheme theScheme) |
49582f9d |
570 | { |
e3d4b879 |
571 | myUI.Selection.Scheme = theScheme; |
49582f9d |
572 | myUI.Selection.Points = thePnts; |
573 | myUI.Selection.ToApplyTool = true; |
574 | if (thePnts.Length() == 1) |
575 | { |
576 | myUI.Selection.Tool = AIS_ViewSelectionTool_Picking; |
577 | } |
578 | else if (thePnts.Length() == 2) |
579 | { |
580 | myUI.Selection.Tool = AIS_ViewSelectionTool_RubberBand; |
581 | } |
582 | else |
583 | { |
584 | myUI.Selection.Tool = AIS_ViewSelectionTool_Polygon; |
585 | } |
586 | } |
587 | |
588 | // ======================================================================= |
589 | // function : UpdateRubberBand |
590 | // purpose : |
591 | // ======================================================================= |
592 | void AIS_ViewController::UpdateRubberBand (const Graphic3d_Vec2i& thePntFrom, |
e3d4b879 |
593 | const Graphic3d_Vec2i& thePntTo) |
49582f9d |
594 | { |
595 | myUI.Selection.Tool = AIS_ViewSelectionTool_RubberBand; |
49582f9d |
596 | myUI.Selection.Points.Clear(); |
597 | myUI.Selection.Points.Append (thePntFrom); |
598 | myUI.Selection.Points.Append (thePntTo); |
599 | } |
600 | |
601 | // ======================================================================= |
602 | // function : UpdatePolySelection |
603 | // purpose : |
604 | // ======================================================================= |
605 | void AIS_ViewController::UpdatePolySelection (const Graphic3d_Vec2i& thePnt, |
606 | bool theToAppend) |
607 | { |
608 | if (myUI.Selection.Tool != AIS_ViewSelectionTool_Polygon) |
609 | { |
610 | myUI.Selection.Tool = AIS_ViewSelectionTool_Polygon; |
611 | myUI.Selection.Points.Clear(); |
612 | } |
613 | |
614 | if (myUI.Selection.Points.IsEmpty()) |
615 | { |
616 | myUI.Selection.Points.Append (thePnt); |
617 | } |
618 | else if (theToAppend |
619 | && myUI.Selection.Points.Last() != thePnt) |
620 | { |
621 | myUI.Selection.Points.Append (thePnt); |
622 | } |
623 | else |
624 | { |
625 | myUI.Selection.Points.ChangeLast() = thePnt; |
626 | } |
627 | } |
628 | |
629 | // ======================================================================= |
630 | // function : UpdateZoom |
631 | // purpose : |
632 | // ======================================================================= |
633 | bool AIS_ViewController::UpdateZoom (const Aspect_ScrollDelta& theDelta) |
634 | { |
635 | if (!myUI.ZoomActions.IsEmpty()) |
636 | { |
637 | if (myUI.ZoomActions.ChangeLast().Point == theDelta.Point) |
638 | { |
639 | myUI.ZoomActions.ChangeLast().Delta += theDelta.Delta; |
640 | return false; |
641 | } |
642 | } |
643 | |
644 | myUI.ZoomActions.Append (theDelta); |
645 | return true; |
646 | } |
647 | |
648 | // ======================================================================= |
649 | // function : UpdateZRotation |
650 | // purpose : |
651 | // ======================================================================= |
652 | bool AIS_ViewController::UpdateZRotation (double theAngle) |
653 | { |
654 | if (!ToAllowTouchZRotation()) |
655 | { |
656 | return false; |
657 | } |
658 | |
659 | myUI.ZRotate.Angle = myUI.ZRotate.ToRotate |
660 | ? myUI.ZRotate.Angle + theAngle |
661 | : theAngle; |
662 | if (myUI.ZRotate.ToRotate) |
663 | { |
664 | return false; |
665 | } |
666 | myUI.ZRotate.ToRotate = true; |
667 | return true; |
668 | } |
669 | |
670 | // ======================================================================= |
671 | // function : UpdateMouseScroll |
672 | // purpose : |
673 | // ======================================================================= |
674 | bool AIS_ViewController::UpdateMouseScroll (const Aspect_ScrollDelta& theDelta) |
675 | { |
676 | Aspect_ScrollDelta aDelta = theDelta; |
677 | aDelta.Delta *= myScrollZoomRatio; |
678 | return UpdateZoom (aDelta); |
679 | } |
680 | |
681 | // ======================================================================= |
682 | // function : UpdateMouseClick |
683 | // purpose : |
684 | // ======================================================================= |
685 | bool AIS_ViewController::UpdateMouseClick (const Graphic3d_Vec2i& thePoint, |
686 | Aspect_VKeyMouse theButton, |
687 | Aspect_VKeyFlags theModifiers, |
688 | bool theIsDoubleClick) |
689 | { |
690 | (void )theIsDoubleClick; |
8f709595 |
691 | |
692 | if (myToPauseObjAnimation |
693 | && !myObjAnimation.IsNull() |
694 | && !myObjAnimation->IsStopped()) |
695 | { |
696 | myObjAnimation->Pause(); |
697 | } |
698 | |
e3d4b879 |
699 | AIS_SelectionScheme aScheme = AIS_SelectionScheme_UNKNOWN; |
700 | if (myMouseSelectionSchemes.Find (theButton | theModifiers, aScheme)) |
49582f9d |
701 | { |
e3d4b879 |
702 | SelectInViewer (thePoint, aScheme); |
49582f9d |
703 | return true; |
704 | } |
705 | return false; |
706 | } |
707 | |
708 | // ======================================================================= |
709 | // function : UpdateMouseButtons |
710 | // purpose : |
711 | // ======================================================================= |
712 | bool AIS_ViewController::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint, |
713 | Aspect_VKeyMouse theButtons, |
714 | Aspect_VKeyFlags theModifiers, |
715 | bool theIsEmulated) |
716 | { |
717 | bool toUpdateView = false; |
718 | const double aTolClick = (theIsEmulated ? myTouchToleranceScale : 1.0) * myMouseClickThreshold; |
719 | if (theButtons == Aspect_VKeyMouse_NONE |
720 | && myMouseSingleButton > 0) |
721 | { |
722 | const Graphic3d_Vec2i aDelta = thePoint - myMousePressPoint; |
723 | if (double(aDelta.cwiseAbs().maxComp()) < aTolClick) |
724 | { |
725 | ++myMouseClickCounter; |
726 | const bool isDoubleClick = myMouseClickCounter == 2 |
727 | && myMouseClickTimer.IsStarted() |
728 | && myMouseClickTimer.ElapsedTime() <= myMouseDoubleClickInt; |
729 | |
730 | myMouseClickTimer.Stop(); |
731 | myMouseClickTimer.Reset(); |
732 | myMouseClickTimer.Start(); |
733 | if (isDoubleClick) |
734 | { |
735 | myMouseClickCounter = 0; |
736 | } |
737 | toUpdateView = UpdateMouseClick (thePoint, (Aspect_VKeyMouse )myMouseSingleButton, theModifiers, isDoubleClick) || toUpdateView; |
738 | } |
739 | else |
740 | { |
741 | myMouseClickTimer.Stop(); |
742 | myMouseClickCounter = 0; |
215dd331 |
743 | myMouseStopDragOnUnclick = false; |
49582f9d |
744 | myUI.Dragging.ToStop = true; |
745 | toUpdateView = true; |
746 | } |
747 | myMouseSingleButton = -1; |
748 | } |
749 | else if (theButtons == Aspect_VKeyMouse_NONE) |
750 | { |
751 | myMouseSingleButton = -1; |
215dd331 |
752 | if (myMouseStopDragOnUnclick) |
753 | { |
754 | myMouseStopDragOnUnclick = false; |
755 | myUI.Dragging.ToStop = true; |
756 | toUpdateView = true; |
757 | } |
49582f9d |
758 | } |
759 | else if (myMouseSingleButton == -1) |
760 | { |
761 | if ((theButtons & Aspect_VKeyMouse_LeftButton) == Aspect_VKeyMouse_LeftButton) |
762 | { |
763 | myMouseSingleButton = Aspect_VKeyMouse_LeftButton; |
764 | } |
765 | else if ((theButtons & Aspect_VKeyMouse_RightButton) == Aspect_VKeyMouse_RightButton) |
766 | { |
767 | myMouseSingleButton = Aspect_VKeyMouse_RightButton; |
768 | } |
769 | else if ((theButtons & Aspect_VKeyMouse_MiddleButton) == Aspect_VKeyMouse_MiddleButton) |
770 | { |
771 | myMouseSingleButton = Aspect_VKeyMouse_MiddleButton; |
772 | } |
773 | else |
774 | { |
775 | myMouseSingleButton = 0; |
776 | } |
777 | if (myMouseSingleButton != 0) |
778 | { |
779 | if (myMouseClickCounter == 1) |
780 | { |
781 | const Graphic3d_Vec2i aDelta = thePoint - myMousePressPoint; |
782 | if (double(aDelta.cwiseAbs().maxComp()) >= aTolClick) |
783 | { |
784 | myMouseClickTimer.Stop(); |
785 | myMouseClickCounter = 0; |
786 | } |
787 | } |
788 | myMousePressPoint = thePoint; |
789 | } |
790 | } |
791 | else |
792 | { |
793 | myMouseSingleButton = 0; |
794 | |
795 | myUI.Dragging.ToAbort = true; |
796 | toUpdateView = true; |
797 | } |
798 | |
799 | const AIS_MouseGesture aPrevGesture = myMouseActiveGesture; |
e3d4b879 |
800 | const Aspect_VKeyMouse aPrevButtons = myMousePressed; |
801 | const Aspect_VKeyFlags aPrevModifiers = myMouseModifiers; |
49582f9d |
802 | myMouseModifiers = theModifiers; |
803 | myMousePressed = theButtons; |
804 | if (theIsEmulated |
805 | || myNavigationMode != AIS_NavigationMode_FirstPersonWalk) |
806 | { |
807 | myMouseActiveIdleRotation = false; |
808 | myMouseActiveGesture = AIS_MouseGesture_NONE; |
809 | if (theButtons != 0) |
810 | { |
811 | myMousePressPoint = thePoint; |
812 | myMouseProgressPoint = myMousePressPoint; |
813 | } |
814 | |
815 | if (myMouseGestureMap.Find (theButtons | theModifiers, myMouseActiveGesture)) |
816 | { |
817 | switch (myMouseActiveGesture) |
818 | { |
819 | case AIS_MouseGesture_RotateView: |
820 | case AIS_MouseGesture_RotateOrbit: |
821 | { |
822 | if (myToAllowRotation) |
823 | { |
824 | myUpdateStartPointRot = true; |
825 | } |
826 | else |
827 | { |
828 | myMouseActiveGesture = AIS_MouseGesture_NONE; |
829 | } |
830 | break; |
831 | } |
832 | case AIS_MouseGesture_Pan: |
833 | { |
834 | if (myToAllowPanning) |
835 | { |
836 | myUpdateStartPointPan = true; |
837 | } |
838 | else |
839 | { |
840 | myMouseActiveGesture = AIS_MouseGesture_NONE; |
841 | } |
842 | break; |
843 | } |
844 | case AIS_MouseGesture_Zoom: |
e1c9a103 |
845 | case AIS_MouseGesture_ZoomWindow: |
49582f9d |
846 | { |
847 | if (!myToAllowZooming) |
848 | { |
849 | myMouseActiveGesture = AIS_MouseGesture_NONE; |
850 | } |
851 | break; |
852 | } |
853 | case AIS_MouseGesture_SelectRectangle: |
854 | { |
855 | break; |
856 | } |
857 | case AIS_MouseGesture_SelectLasso: |
858 | { |
859 | UpdatePolySelection (thePoint, true); |
860 | break; |
861 | } |
e3fd3d83 |
862 | case AIS_MouseGesture_Drag: |
863 | { |
864 | if (myToAllowDragging) |
865 | { |
866 | myUI.Dragging.ToStart = true; |
867 | myUI.Dragging.PointStart = thePoint; |
868 | } |
869 | else |
870 | { |
871 | myMouseActiveGesture = AIS_MouseGesture_NONE; |
872 | } |
873 | break; |
874 | } |
49582f9d |
875 | case AIS_MouseGesture_NONE: |
876 | { |
877 | break; |
878 | } |
879 | } |
880 | } |
881 | |
e3fd3d83 |
882 | AIS_MouseGesture aSecGesture = AIS_MouseGesture_NONE; |
883 | if (myMouseGestureMapDrag.Find (theButtons | theModifiers, aSecGesture)) |
49582f9d |
884 | { |
e3fd3d83 |
885 | if (aSecGesture == AIS_MouseGesture_Drag |
886 | && myToAllowDragging) |
887 | { |
888 | myUI.Dragging.ToStart = true; |
889 | myUI.Dragging.PointStart = thePoint; |
890 | if (myMouseActiveGesture == AIS_MouseGesture_NONE) |
891 | { |
892 | myMouseActiveGesture = aSecGesture; |
893 | } |
894 | } |
49582f9d |
895 | } |
896 | } |
897 | |
898 | if (aPrevGesture != myMouseActiveGesture) |
899 | { |
900 | if (aPrevGesture == AIS_MouseGesture_SelectRectangle |
e1c9a103 |
901 | || aPrevGesture == AIS_MouseGesture_SelectLasso |
902 | || aPrevGesture == AIS_MouseGesture_ZoomWindow) |
49582f9d |
903 | { |
904 | myUI.Selection.ToApplyTool = true; |
e3d4b879 |
905 | myUI.Selection.Scheme = AIS_SelectionScheme_Replace; |
906 | myMouseSelectionSchemes.Find (aPrevButtons | aPrevModifiers, myUI.Selection.Scheme); |
49582f9d |
907 | } |
908 | |
909 | myUI.IsNewGesture = true; |
910 | toUpdateView = true; |
911 | } |
e3d4b879 |
912 | |
49582f9d |
913 | return toUpdateView; |
914 | } |
915 | |
916 | // ======================================================================= |
917 | // function : UpdateMousePosition |
918 | // purpose : |
919 | // ======================================================================= |
920 | bool AIS_ViewController::UpdateMousePosition (const Graphic3d_Vec2i& thePoint, |
921 | Aspect_VKeyMouse theButtons, |
922 | Aspect_VKeyFlags theModifiers, |
923 | bool theIsEmulated) |
924 | { |
925 | myMousePositionLast = thePoint; |
926 | if (myMouseSingleButton > 0) |
927 | { |
928 | const double aTolClick = (theIsEmulated ? myTouchToleranceScale : 1.0) * myMouseClickThreshold; |
929 | const Graphic3d_Vec2i aPressDelta = thePoint - myMousePressPoint; |
930 | if (double(aPressDelta.cwiseAbs().maxComp()) >= aTolClick) |
931 | { |
932 | myMouseClickTimer.Stop(); |
933 | myMouseClickCounter = 0; |
934 | myMouseSingleButton = -1; |
215dd331 |
935 | myMouseStopDragOnUnclick = true; |
6ef56849 |
936 | myUI.Dragging.ToConfirm = true; |
49582f9d |
937 | } |
938 | } |
939 | |
940 | bool toUpdateView = false; |
941 | Graphic3d_Vec2i aDelta = thePoint - myMouseProgressPoint; |
942 | if (!theIsEmulated |
943 | && myNavigationMode == AIS_NavigationMode_FirstPersonWalk) |
944 | { |
945 | if (!myMouseActiveIdleRotation |
946 | || myMouseActiveGesture != AIS_MouseGesture_RotateView) |
947 | { |
948 | myMouseActiveIdleRotation = true; |
949 | myMouseActiveGesture = AIS_MouseGesture_RotateView; |
950 | myMousePressPoint = thePoint; |
951 | myMouseProgressPoint = thePoint; |
952 | myUpdateStartPointRot = false; |
953 | myUI.ViewRotation.ToStart = true; |
954 | myUI.ViewRotation.PointStart.SetValues (thePoint.x(), thePoint.y()); |
955 | myUI.ViewRotation.ToRotate = false; |
956 | aDelta.SetValues (0, 0); |
957 | } |
958 | } |
959 | else |
960 | { |
961 | if (myMouseActiveIdleRotation |
962 | && myMouseActiveGesture == AIS_MouseGesture_RotateView) |
963 | { |
964 | myMouseActiveGesture = AIS_MouseGesture_NONE; |
965 | } |
966 | myMouseActiveIdleRotation = false; |
967 | } |
968 | |
969 | if (myMouseModifiers != theModifiers |
970 | && UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated)) |
971 | { |
972 | toUpdateView = true; |
973 | } |
974 | |
975 | switch (myMouseActiveGesture) |
976 | { |
977 | case AIS_MouseGesture_SelectRectangle: |
e1c9a103 |
978 | case AIS_MouseGesture_ZoomWindow: |
49582f9d |
979 | { |
980 | UpdateRubberBand (myMousePressPoint, thePoint); |
e1c9a103 |
981 | if (myMouseActiveGesture == AIS_MouseGesture_ZoomWindow) |
982 | { |
983 | myUI.Selection.Tool = AIS_ViewSelectionTool_ZoomWindow; |
984 | } |
49582f9d |
985 | toUpdateView = true; |
986 | break; |
987 | } |
988 | case AIS_MouseGesture_SelectLasso: |
989 | { |
990 | UpdatePolySelection (thePoint, true); |
991 | toUpdateView = true; |
992 | break; |
993 | } |
994 | case AIS_MouseGesture_RotateOrbit: |
995 | case AIS_MouseGesture_RotateView: |
996 | { |
997 | if (!myToAllowRotation) |
998 | { |
999 | break; |
1000 | } |
1001 | if (myUpdateStartPointRot) |
1002 | { |
1003 | if (myMouseActiveGesture == AIS_MouseGesture_RotateOrbit) |
1004 | { |
1005 | myUI.OrbitRotation.ToStart = true; |
1006 | myUI.OrbitRotation.PointStart.SetValues (myMousePressPoint.x(), myMousePressPoint.y()); |
1007 | } |
1008 | else |
1009 | { |
1010 | myUI.ViewRotation.ToStart = true; |
1011 | myUI.ViewRotation.PointStart.SetValues (myMousePressPoint.x(), myMousePressPoint.y()); |
1012 | } |
1013 | myUpdateStartPointRot = false; |
1014 | } |
1015 | |
1016 | const double aRotTol = theIsEmulated |
1017 | ? double(myTouchToleranceScale) * myTouchRotationThresholdPx |
1018 | : 0.0; |
4e1b5fcb |
1019 | const Graphic3d_Vec2d aDeltaF (aDelta); |
1020 | if (Abs (aDeltaF.x()) + Abs (aDeltaF.y()) > aRotTol) |
49582f9d |
1021 | { |
1022 | const double aRotAccel = myNavigationMode == AIS_NavigationMode_FirstPersonWalk ? myMouseAccel : myOrbitAccel; |
1023 | const Graphic3d_Vec2i aRotDelta = thePoint - myMousePressPoint; |
1024 | if (myMouseActiveGesture == AIS_MouseGesture_RotateOrbit) |
1025 | { |
1026 | myUI.OrbitRotation.ToRotate = true; |
1027 | myUI.OrbitRotation.PointTo = Graphic3d_Vec2d (myMousePressPoint.x(), myMousePressPoint.y()) |
1028 | + Graphic3d_Vec2d (aRotDelta.x(), aRotDelta.y()) * aRotAccel; |
1029 | } |
1030 | else |
1031 | { |
1032 | myUI.ViewRotation.ToRotate = true; |
1033 | myUI.ViewRotation.PointTo = Graphic3d_Vec2d (myMousePressPoint.x(), myMousePressPoint.y()) |
1034 | + Graphic3d_Vec2d (aRotDelta.x(), aRotDelta.y()) * aRotAccel; |
1035 | } |
e3fd3d83 |
1036 | |
1037 | myUI.Dragging.ToMove = true; |
49582f9d |
1038 | myUI.Dragging.PointTo = thePoint; |
1039 | |
1040 | myMouseProgressPoint = thePoint; |
1041 | toUpdateView = true; |
1042 | } |
1043 | break; |
1044 | } |
1045 | case AIS_MouseGesture_Zoom: |
1046 | { |
1047 | if (!myToAllowZooming) |
1048 | { |
1049 | break; |
1050 | } |
1051 | const double aZoomTol = theIsEmulated |
1052 | ? double(myTouchToleranceScale) * myTouchZoomThresholdPx |
1053 | : 0.0; |
1054 | if (double (Abs (aDelta.x())) > aZoomTol) |
1055 | { |
34213231 |
1056 | UpdateZoom (Aspect_ScrollDelta (aDelta.x())); |
1057 | |
1058 | myUI.Dragging.ToMove = true; |
1059 | myUI.Dragging.PointTo = thePoint; |
1060 | |
49582f9d |
1061 | myMouseProgressPoint = thePoint; |
34213231 |
1062 | toUpdateView = true; |
49582f9d |
1063 | } |
1064 | break; |
1065 | } |
1066 | case AIS_MouseGesture_Pan: |
1067 | { |
1068 | if (!myToAllowPanning) |
1069 | { |
1070 | break; |
1071 | } |
1072 | const double aPanTol = theIsEmulated |
1073 | ? double(myTouchToleranceScale) * myTouchPanThresholdPx |
1074 | : 0.0; |
4e1b5fcb |
1075 | const Graphic3d_Vec2d aDeltaF (aDelta); |
1076 | if (Abs (aDeltaF.x()) + Abs (aDeltaF.y()) > aPanTol) |
49582f9d |
1077 | { |
1078 | if (myUpdateStartPointPan) |
1079 | { |
1080 | myUI.Panning.ToStart = true; |
1081 | myUI.Panning.PointStart.SetValues (myMousePressPoint.x(), myMousePressPoint.y()); |
1082 | myUpdateStartPointPan = false; |
1083 | } |
1084 | |
1085 | aDelta.y() = -aDelta.y(); |
49582f9d |
1086 | if (myUI.Panning.ToPan) |
1087 | { |
1088 | myUI.Panning.Delta += aDelta; |
1089 | } |
1090 | else |
1091 | { |
1092 | myUI.Panning.ToPan = true; |
1093 | myUI.Panning.Delta = aDelta; |
1094 | } |
34213231 |
1095 | |
1096 | myUI.Dragging.ToMove = true; |
1097 | myUI.Dragging.PointTo = thePoint; |
1098 | |
1099 | myMouseProgressPoint = thePoint; |
1100 | |
49582f9d |
1101 | toUpdateView = true; |
1102 | } |
1103 | break; |
1104 | } |
e3fd3d83 |
1105 | case AIS_MouseGesture_Drag: |
1106 | { |
1107 | if (!myToAllowDragging) |
1108 | { |
1109 | break; |
1110 | } |
1111 | |
1112 | const double aDragTol = theIsEmulated |
1113 | ? double(myTouchToleranceScale) * myTouchDraggingThresholdPx |
1114 | : 0.0; |
1115 | if (double (Abs (aDelta.x()) + Abs (aDelta.y())) > aDragTol) |
1116 | { |
1117 | const double aRotAccel = myNavigationMode == AIS_NavigationMode_FirstPersonWalk ? myMouseAccel : myOrbitAccel; |
1118 | const Graphic3d_Vec2i aRotDelta = thePoint - myMousePressPoint; |
1119 | myUI.ViewRotation.ToRotate = true; |
1120 | myUI.ViewRotation.PointTo = Graphic3d_Vec2d (myMousePressPoint.x(), myMousePressPoint.y()) |
1121 | + Graphic3d_Vec2d (aRotDelta.x(), aRotDelta.y()) * aRotAccel; |
1122 | myUI.Dragging.ToMove = true; |
1123 | myUI.Dragging.PointTo = thePoint; |
1124 | |
1125 | myMouseProgressPoint = thePoint; |
1126 | toUpdateView = true; |
1127 | } |
1128 | break; |
1129 | } |
49582f9d |
1130 | default: |
1131 | { |
1132 | break; |
1133 | } |
1134 | } |
1135 | |
1136 | if (theButtons == Aspect_VKeyMouse_NONE |
1137 | && myNavigationMode != AIS_NavigationMode_FirstPersonWalk |
1138 | && !theIsEmulated |
1139 | && !HasTouchPoints() |
1140 | && myToAllowHighlight) |
1141 | { |
1142 | myUI.MoveTo.ToHilight = true; |
1143 | myUI.MoveTo.Point = thePoint; |
1144 | toUpdateView = true; |
1145 | } |
1146 | return toUpdateView; |
1147 | } |
1148 | |
1149 | // ======================================================================= |
1150 | // function : AddTouchPoint |
1151 | // purpose : |
1152 | // ======================================================================= |
1153 | void AIS_ViewController::AddTouchPoint (Standard_Size theId, |
1154 | const Graphic3d_Vec2d& thePnt, |
1155 | Standard_Boolean theClearBefore) |
1156 | { |
1157 | myUI.MoveTo.ToHilight = false; |
f9ab9f7f |
1158 | Aspect_WindowInputListener::AddTouchPoint (theId, thePnt, theClearBefore); |
49582f9d |
1159 | |
f9ab9f7f |
1160 | myTouchClick.From = Graphic3d_Vec2d (-1.0); |
49582f9d |
1161 | if (myTouchPoints.Extent() == 1) |
1162 | { |
f9ab9f7f |
1163 | myTouchClick.From = thePnt; |
49582f9d |
1164 | myUpdateStartPointRot = true; |
1165 | myStartRotCoord = thePnt; |
1166 | if (myToAllowDragging) |
1167 | { |
1168 | myUI.Dragging.ToStart = true; |
1169 | myUI.Dragging.PointStart.SetValues ((int )thePnt.x(), (int )thePnt.y()); |
1170 | } |
1171 | } |
1172 | else if (myTouchPoints.Extent() == 2) |
1173 | { |
1174 | myUI.Dragging.ToAbort = true; |
1175 | |
1176 | myUpdateStartPointPan = true; |
1177 | myStartPanCoord = thePnt; |
1178 | } |
1179 | myUI.IsNewGesture = true; |
1180 | } |
1181 | |
1182 | // ======================================================================= |
1183 | // function : RemoveTouchPoint |
1184 | // purpose : |
1185 | // ======================================================================= |
1186 | bool AIS_ViewController::RemoveTouchPoint (Standard_Size theId, |
1187 | Standard_Boolean theClearSelectPnts) |
1188 | { |
f9ab9f7f |
1189 | if (!Aspect_WindowInputListener::RemoveTouchPoint (theId, theClearSelectPnts)) |
49582f9d |
1190 | { |
f9ab9f7f |
1191 | return false; |
49582f9d |
1192 | } |
1193 | |
1194 | if (myTouchPoints.Extent() == 1) |
1195 | { |
1196 | // avoid incorrect transition from pinch to one finger |
1197 | Aspect_Touch& aFirstTouch = myTouchPoints.ChangeFromIndex (1); |
1198 | aFirstTouch.To = aFirstTouch.From; |
1199 | |
1200 | myStartRotCoord = aFirstTouch.To; |
1201 | myUpdateStartPointRot = true; |
1202 | } |
1203 | else if (myTouchPoints.Extent() == 2) |
1204 | { |
1205 | myStartPanCoord = myTouchPoints.FindFromIndex (1).To; |
1206 | myUpdateStartPointPan = true; |
1207 | } |
1208 | else if (myTouchPoints.IsEmpty()) |
1209 | { |
1210 | if (theClearSelectPnts) |
1211 | { |
1212 | myUI.Selection.ToApplyTool = true; |
1213 | } |
1214 | |
1215 | myUI.Dragging.ToStop = true; |
f9ab9f7f |
1216 | |
1217 | if (theId == (Standard_Size )-1) |
1218 | { |
1219 | // abort clicking |
1220 | myTouchClick.From = Graphic3d_Vec2d (-1); |
1221 | } |
1222 | else if (myTouchClick.From.minComp() >= 0.0) |
1223 | { |
1224 | bool isDoubleClick = false; |
1225 | if (myTouchDoubleTapTimer.IsStarted() |
1226 | && myTouchDoubleTapTimer.ElapsedTime() <= myMouseDoubleClickInt) |
1227 | { |
1228 | isDoubleClick = true; |
1229 | } |
1230 | else |
1231 | { |
1232 | myTouchDoubleTapTimer.Stop(); |
1233 | myTouchDoubleTapTimer.Reset(); |
1234 | myTouchDoubleTapTimer.Start(); |
1235 | } |
1236 | |
1237 | // emulate mouse click |
1238 | UpdateMouseClick (Graphic3d_Vec2i (myTouchClick.From), Aspect_VKeyMouse_LeftButton, Aspect_VKeyFlags_NONE, isDoubleClick); |
1239 | } |
49582f9d |
1240 | } |
1241 | myUI.IsNewGesture = true; |
1242 | return true; |
1243 | } |
1244 | |
1245 | // ======================================================================= |
1246 | // function : UpdateTouchPoint |
1247 | // purpose : |
1248 | // ======================================================================= |
1249 | void AIS_ViewController::UpdateTouchPoint (Standard_Size theId, |
1250 | const Graphic3d_Vec2d& thePnt) |
1251 | { |
f9ab9f7f |
1252 | Aspect_WindowInputListener::UpdateTouchPoint (theId, thePnt); |
1253 | |
1254 | const double aTouchTol = double(myTouchToleranceScale) * double(myTouchClickThresholdPx); |
1255 | if (myTouchPoints.Extent() == 1 |
1256 | && (myTouchClick.From - thePnt).cwiseAbs().maxComp() > aTouchTol) |
49582f9d |
1257 | { |
f9ab9f7f |
1258 | myTouchClick.From.SetValues (-1.0, -1.0); |
49582f9d |
1259 | } |
1260 | } |
1261 | |
d6fbb2ab |
1262 | // ======================================================================= |
1263 | // function : Update3dMouse |
1264 | // purpose : |
1265 | // ======================================================================= |
1266 | bool AIS_ViewController::Update3dMouse (const WNT_HIDSpaceMouse& theEvent) |
1267 | { |
1268 | bool toUpdate = false; |
1269 | toUpdate = update3dMouseTranslation (theEvent) || toUpdate; |
e8e157df |
1270 | toUpdate = (myToAllowRotation && update3dMouseRotation (theEvent)) || toUpdate; |
d6fbb2ab |
1271 | toUpdate = update3dMouseKeys (theEvent) || toUpdate; |
1272 | return toUpdate; |
1273 | } |
1274 | |
49582f9d |
1275 | // ======================================================================= |
1276 | // function : SetNavigationMode |
1277 | // purpose : |
1278 | // ======================================================================= |
1279 | void AIS_ViewController::SetNavigationMode (AIS_NavigationMode theMode) |
1280 | { |
1281 | myNavigationMode = theMode; |
1282 | |
1283 | // abort rotation |
1284 | myUI.OrbitRotation.ToStart = false; |
1285 | myUI.OrbitRotation.ToRotate = false; |
1286 | myUI.ViewRotation.ToStart = false; |
1287 | myUI.ViewRotation.ToRotate = false; |
1288 | } |
1289 | |
1290 | // ======================================================================= |
1291 | // function : KeyDown |
1292 | // purpose : |
1293 | // ======================================================================= |
1294 | void AIS_ViewController::KeyDown (Aspect_VKey theKey, |
1295 | double theTime, |
1296 | double thePressure) |
1297 | { |
e8e157df |
1298 | Aspect_WindowInputListener::KeyDown (theKey, theTime, thePressure); |
49582f9d |
1299 | } |
1300 | |
1301 | // ======================================================================= |
1302 | // function : KeyUp |
1303 | // purpose : |
1304 | // ======================================================================= |
1305 | void AIS_ViewController::KeyUp (Aspect_VKey theKey, |
1306 | double theTime) |
1307 | { |
e8e157df |
1308 | Aspect_WindowInputListener::KeyUp (theKey, theTime); |
49582f9d |
1309 | } |
1310 | |
1311 | // ======================================================================= |
1312 | // function : KeyFromAxis |
1313 | // purpose : |
1314 | // ======================================================================= |
1315 | void AIS_ViewController::KeyFromAxis (Aspect_VKey theNegative, |
1316 | Aspect_VKey thePositive, |
1317 | double theTime, |
1318 | double thePressure) |
1319 | { |
e8e157df |
1320 | Aspect_WindowInputListener::KeyFromAxis (theNegative, thePositive, theTime, thePressure); |
49582f9d |
1321 | } |
1322 | |
1323 | // ======================================================================= |
1324 | // function : FetchNavigationKeys |
1325 | // purpose : |
1326 | // ======================================================================= |
1327 | AIS_WalkDelta AIS_ViewController::FetchNavigationKeys (Standard_Real theCrouchRatio, |
1328 | Standard_Real theRunRatio) |
1329 | { |
1330 | AIS_WalkDelta aWalk; |
1331 | |
1332 | // navigation keys |
1333 | double aPrevEventTime = 0.0, aNewEventTime = 0.0; |
1334 | updateEventsTime (aPrevEventTime, aNewEventTime); |
1335 | |
1336 | double aDuration = 0.0, aPressure = 1.0; |
1337 | if (Abs (myThrustSpeed) > gp::Resolution()) |
1338 | { |
1339 | if (myHasThrust) |
1340 | { |
1341 | aWalk[AIS_WalkTranslation_Forward].Value = myThrustSpeed * (aNewEventTime - aPrevEventTime); |
1342 | } |
1343 | myHasThrust = true; |
1344 | myToAskNextFrame = true; |
1345 | } |
1346 | else |
1347 | { |
1348 | myHasThrust = false; |
1349 | } |
1350 | |
1351 | aWalk.SetRunning (theRunRatio > 1.0 |
1352 | && myKeys.IsKeyDown (Aspect_VKey_Shift)); |
1353 | if (myKeys.HoldDuration (Aspect_VKey_NavJump, aNewEventTime, aDuration)) |
1354 | { |
1355 | myKeys.KeyUp (Aspect_VKey_NavJump, aNewEventTime); |
f9ab9f7f |
1356 | aWalk.SetDefined (true); |
49582f9d |
1357 | aWalk.SetJumping (true); |
1358 | } |
1359 | if (!aWalk.IsJumping() |
1360 | && theCrouchRatio < 1.0 |
1361 | && myKeys.HoldDuration (Aspect_VKey_NavCrouch, aNewEventTime, aDuration)) |
1362 | { |
f9ab9f7f |
1363 | aWalk.SetDefined (true); |
49582f9d |
1364 | aWalk.SetRunning (false); |
1365 | aWalk.SetCrouching (true); |
1366 | } |
1367 | |
1368 | const double aMaxDuration = aNewEventTime - aPrevEventTime; |
1369 | const double aRunRatio = aWalk.IsRunning() |
1370 | ? theRunRatio |
1371 | : aWalk.IsCrouching() |
1372 | ? theCrouchRatio |
1373 | : 1.0; |
1374 | if (myKeys.HoldDuration (Aspect_VKey_NavForward, aNewEventTime, aDuration, aPressure)) |
1375 | { |
1376 | double aProgress = Abs (Min (aMaxDuration, aDuration)); |
1377 | aProgress *= aRunRatio; |
f9ab9f7f |
1378 | aWalk.SetDefined (true); |
49582f9d |
1379 | aWalk[AIS_WalkTranslation_Forward].Value += aProgress; |
1380 | aWalk[AIS_WalkTranslation_Forward].Pressure = aPressure; |
1381 | aWalk[AIS_WalkTranslation_Forward].Duration = aDuration; |
1382 | } |
1383 | if (myKeys.HoldDuration (Aspect_VKey_NavBackward, aNewEventTime, aDuration, aPressure)) |
1384 | { |
1385 | double aProgress = Abs (Min (aMaxDuration, aDuration)); |
1386 | aProgress *= aRunRatio; |
f9ab9f7f |
1387 | aWalk.SetDefined (true); |
49582f9d |
1388 | aWalk[AIS_WalkTranslation_Forward].Value += -aProgress; |
1389 | aWalk[AIS_WalkTranslation_Forward].Pressure = aPressure; |
1390 | aWalk[AIS_WalkTranslation_Forward].Duration = aDuration; |
1391 | } |
1392 | if (myKeys.HoldDuration (Aspect_VKey_NavSlideLeft, aNewEventTime, aDuration, aPressure)) |
1393 | { |
1394 | double aProgress = Abs (Min (aMaxDuration, aDuration)); |
1395 | aProgress *= aRunRatio; |
f9ab9f7f |
1396 | aWalk.SetDefined (true); |
49582f9d |
1397 | aWalk[AIS_WalkTranslation_Side].Value = -aProgress; |
1398 | aWalk[AIS_WalkTranslation_Side].Pressure = aPressure; |
1399 | aWalk[AIS_WalkTranslation_Side].Duration = aDuration; |
1400 | } |
1401 | if (myKeys.HoldDuration (Aspect_VKey_NavSlideRight, aNewEventTime, aDuration, aPressure)) |
1402 | { |
1403 | double aProgress = Abs (Min (aMaxDuration, aDuration)); |
1404 | aProgress *= aRunRatio; |
f9ab9f7f |
1405 | aWalk.SetDefined (true); |
49582f9d |
1406 | aWalk[AIS_WalkTranslation_Side].Value = aProgress; |
1407 | aWalk[AIS_WalkTranslation_Side].Pressure = aPressure; |
1408 | aWalk[AIS_WalkTranslation_Side].Duration = aDuration; |
1409 | } |
1410 | if (myKeys.HoldDuration (Aspect_VKey_NavLookLeft, aNewEventTime, aDuration, aPressure)) |
1411 | { |
1412 | double aProgress = Abs (Min (aMaxDuration, aDuration)) * aPressure; |
f9ab9f7f |
1413 | aWalk.SetDefined (true); |
49582f9d |
1414 | aWalk[AIS_WalkRotation_Yaw].Value = aProgress; |
1415 | aWalk[AIS_WalkRotation_Yaw].Pressure = aPressure; |
1416 | aWalk[AIS_WalkRotation_Yaw].Duration = aDuration; |
1417 | } |
1418 | if (myKeys.HoldDuration (Aspect_VKey_NavLookRight, aNewEventTime, aDuration, aPressure)) |
1419 | { |
1420 | double aProgress = Abs (Min (aMaxDuration, aDuration)) * aPressure; |
f9ab9f7f |
1421 | aWalk.SetDefined (true); |
49582f9d |
1422 | aWalk[AIS_WalkRotation_Yaw].Value = -aProgress; |
1423 | aWalk[AIS_WalkRotation_Yaw].Pressure = aPressure; |
1424 | aWalk[AIS_WalkRotation_Yaw].Duration = aDuration; |
1425 | } |
1426 | if (myKeys.HoldDuration (Aspect_VKey_NavLookUp, aNewEventTime, aDuration, aPressure)) |
1427 | { |
1428 | double aProgress = Abs (Min (aMaxDuration, aDuration)) * aPressure; |
f9ab9f7f |
1429 | aWalk.SetDefined (true); |
49582f9d |
1430 | aWalk[AIS_WalkRotation_Pitch].Value = !myToInvertPitch ? -aProgress : aProgress; |
1431 | aWalk[AIS_WalkRotation_Pitch].Pressure = aPressure; |
1432 | aWalk[AIS_WalkRotation_Pitch].Duration = aDuration; |
1433 | } |
1434 | if (myKeys.HoldDuration (Aspect_VKey_NavLookDown, aNewEventTime, aDuration, aPressure)) |
1435 | { |
1436 | double aProgress = Abs (Min (aMaxDuration, aDuration)) * aPressure; |
f9ab9f7f |
1437 | aWalk.SetDefined (true); |
49582f9d |
1438 | aWalk[AIS_WalkRotation_Pitch].Value = !myToInvertPitch ? aProgress : -aProgress; |
1439 | aWalk[AIS_WalkRotation_Pitch].Pressure = aPressure; |
1440 | aWalk[AIS_WalkRotation_Pitch].Duration = aDuration; |
1441 | } |
1442 | if (myKeys.HoldDuration (Aspect_VKey_NavRollCCW, aNewEventTime, aDuration, aPressure)) |
1443 | { |
1444 | double aProgress = Abs (Min (aMaxDuration, aDuration)) * aPressure; |
f9ab9f7f |
1445 | aWalk.SetDefined (true); |
49582f9d |
1446 | aWalk[AIS_WalkRotation_Roll].Value = -aProgress; |
1447 | aWalk[AIS_WalkRotation_Roll].Pressure = aPressure; |
1448 | aWalk[AIS_WalkRotation_Roll].Duration = aDuration; |
1449 | } |
1450 | if (myKeys.HoldDuration (Aspect_VKey_NavRollCW, aNewEventTime, aDuration, aPressure)) |
1451 | { |
1452 | double aProgress = Abs (Min (aMaxDuration, aDuration)) * aPressure; |
f9ab9f7f |
1453 | aWalk.SetDefined (true); |
49582f9d |
1454 | aWalk[AIS_WalkRotation_Roll].Value = aProgress; |
1455 | aWalk[AIS_WalkRotation_Roll].Pressure = aPressure; |
1456 | aWalk[AIS_WalkRotation_Roll].Duration = aDuration; |
1457 | } |
1458 | if (myKeys.HoldDuration (Aspect_VKey_NavSlideUp, aNewEventTime, aDuration, aPressure)) |
1459 | { |
1460 | double aProgress = Abs (Min (aMaxDuration, aDuration)); |
f9ab9f7f |
1461 | aWalk.SetDefined (true); |
49582f9d |
1462 | aWalk[AIS_WalkTranslation_Up].Value = aProgress; |
1463 | aWalk[AIS_WalkTranslation_Up].Pressure = aPressure; |
1464 | aWalk[AIS_WalkTranslation_Up].Duration = aDuration; |
1465 | } |
1466 | if (myKeys.HoldDuration (Aspect_VKey_NavSlideDown, aNewEventTime, aDuration, aPressure)) |
1467 | { |
1468 | double aProgress = Abs (Min (aMaxDuration, aDuration)); |
f9ab9f7f |
1469 | aWalk.SetDefined (true); |
49582f9d |
1470 | aWalk[AIS_WalkTranslation_Up].Value = -aProgress; |
1471 | aWalk[AIS_WalkTranslation_Up].Pressure = aPressure; |
1472 | aWalk[AIS_WalkTranslation_Up].Duration = aDuration; |
1473 | } |
1474 | return aWalk; |
1475 | } |
1476 | |
2108d9a2 |
1477 | // ======================================================================= |
1478 | // function : AbortViewAnimation |
1479 | // purpose : |
1480 | // ======================================================================= |
1481 | void AIS_ViewController::AbortViewAnimation() |
1482 | { |
1483 | if (!myViewAnimation.IsNull() |
1484 | && !myViewAnimation->IsStopped()) |
1485 | { |
1486 | myViewAnimation->Stop(); |
1487 | myViewAnimation->SetView (Handle(V3d_View)()); |
1488 | } |
1489 | } |
1490 | |
49582f9d |
1491 | // ======================================================================= |
1492 | // function : handlePanning |
1493 | // purpose : |
1494 | // ======================================================================= |
1495 | void AIS_ViewController::handlePanning (const Handle(V3d_View)& theView) |
1496 | { |
1497 | if (!myGL.Panning.ToPan |
1498 | || !myToAllowPanning) |
1499 | { |
1500 | return; |
1501 | } |
1502 | |
2108d9a2 |
1503 | AbortViewAnimation(); |
1504 | |
49582f9d |
1505 | const Handle(Graphic3d_Camera)& aCam = theView->Camera(); |
1506 | if (aCam->IsOrthographic() |
1507 | || !hasPanningAnchorPoint()) |
1508 | { |
1509 | theView->Pan (myGL.Panning.Delta.x(), myGL.Panning.Delta.y()); |
1510 | theView->Invalidate(); |
b40cdc2b |
1511 | theView->View()->SynchronizeXRPosedToBaseCamera(); |
49582f9d |
1512 | return; |
1513 | } |
1514 | |
1515 | Graphic3d_Vec2i aWinSize; |
1516 | theView->Window()->Size (aWinSize.x(), aWinSize.y()); |
1517 | |
1518 | const gp_Dir& aDir = aCam->Direction(); |
1519 | const gp_Ax3 aCameraCS (aCam->Center(), aDir.Reversed(), aDir ^ aCam->Up()); |
1520 | const gp_XYZ anEyeToPnt = myPanPnt3d.XYZ() - aCam->Eye().XYZ(); |
1521 | const gp_Pnt aViewDims = aCam->ViewDimensions (anEyeToPnt.Dot (aCam->Direction().XYZ())); // view dimensions at 3D point |
1522 | const Graphic3d_Vec2d aDxy (-aViewDims.X() * myGL.Panning.Delta.x() / double(aWinSize.x()), |
1523 | -aViewDims.X() * myGL.Panning.Delta.y() / double(aWinSize.x())); |
1524 | |
1525 | //theView->Translate (aCam, aDxy.x(), aDxy.y()); |
1526 | gp_Trsf aPanTrsf; |
1527 | const gp_Vec aCameraPan = gp_Vec (aCameraCS.XDirection()) * aDxy.x() |
1528 | + gp_Vec (aCameraCS.YDirection()) * aDxy.y(); |
1529 | aPanTrsf.SetTranslation (aCameraPan); |
1530 | aCam->Transform (aPanTrsf); |
1531 | theView->Invalidate(); |
b40cdc2b |
1532 | theView->View()->SynchronizeXRPosedToBaseCamera(); |
49582f9d |
1533 | } |
1534 | |
1535 | // ======================================================================= |
1536 | // function : handleZRotate |
1537 | // purpose : |
1538 | // ======================================================================= |
1539 | void AIS_ViewController::handleZRotate (const Handle(V3d_View)& theView) |
1540 | { |
1541 | if (!myGL.ZRotate.ToRotate |
1542 | || !myToAllowRotation) |
1543 | { |
1544 | return; |
1545 | } |
1546 | |
2108d9a2 |
1547 | AbortViewAnimation(); |
1548 | |
49582f9d |
1549 | Graphic3d_Vec2i aViewPort; |
1550 | theView->Window()->Size (aViewPort.x(), aViewPort.y()); |
1551 | Graphic3d_Vec2d aRotPnt (0.99 * aViewPort.x(), |
1552 | 0.5 * aViewPort.y()); |
1553 | theView->StartRotation (int(aRotPnt.x()), int(aRotPnt.y()), 0.4); |
1554 | aRotPnt.y() += myGL.ZRotate.Angle * aViewPort.y(); |
1555 | theView->Rotation (int(aRotPnt.x()), int(aRotPnt.y())); |
1556 | theView->Invalidate(); |
b40cdc2b |
1557 | theView->View()->SynchronizeXRPosedToBaseCamera(); |
49582f9d |
1558 | } |
1559 | |
1560 | // ======================================================================= |
1561 | // function : handleZoom |
1562 | // purpose : |
1563 | // ======================================================================= |
1564 | void AIS_ViewController::handleZoom (const Handle(V3d_View)& theView, |
1565 | const Aspect_ScrollDelta& theParams, |
1566 | const gp_Pnt* thePnt) |
1567 | { |
1568 | if (!myToAllowZooming) |
1569 | { |
1570 | return; |
1571 | } |
1572 | |
2108d9a2 |
1573 | AbortViewAnimation(); |
1574 | |
49582f9d |
1575 | const Handle(Graphic3d_Camera)& aCam = theView->Camera(); |
1576 | if (thePnt != NULL) |
1577 | { |
1578 | const double aViewDist = Max (myMinCamDistance, (thePnt->XYZ() - aCam->Eye().XYZ()).Modulus()); |
1579 | aCam->SetCenter (aCam->Eye().XYZ() + aCam->Direction().XYZ() * aViewDist); |
1580 | } |
1581 | |
1582 | if (!theParams.HasPoint()) |
1583 | { |
1584 | Standard_Real aCoeff = Abs(theParams.Delta) / 100.0 + 1.0; |
1585 | aCoeff = theParams.Delta > 0.0 ? aCoeff : 1.0 / aCoeff; |
1586 | theView->SetZoom (aCoeff, true); |
1587 | theView->Invalidate(); |
b40cdc2b |
1588 | theView->View()->SynchronizeXRPosedToBaseCamera(); |
49582f9d |
1589 | return; |
1590 | } |
1591 | |
1592 | // integer delta is too rough for small smooth increments |
1593 | //theView->StartZoomAtPoint (theParams.Point.x(), theParams.Point.y()); |
1594 | //theView->ZoomAtPoint (0, 0, (int )theParams.Delta, (int )theParams.Delta); |
1595 | |
1596 | double aDZoom = Abs (theParams.Delta) / 100.0 + 1.0; |
1597 | aDZoom = (theParams.Delta > 0.0) ? aDZoom : 1.0 / aDZoom; |
1598 | if (aDZoom <= 0.0) |
1599 | { |
1600 | return; |
1601 | } |
1602 | |
1603 | const Graphic3d_Vec2d aViewDims (aCam->ViewDimensions().X(), aCam->ViewDimensions().Y()); |
1604 | |
1605 | // ensure that zoom will not be too small or too big |
1606 | double aCoef = aDZoom; |
1607 | if (aViewDims.x() < aCoef * Precision::Confusion()) |
1608 | { |
1609 | aCoef = aViewDims.x() / Precision::Confusion(); |
1610 | } |
1611 | else if (aViewDims.x() > aCoef * 1e12) |
1612 | { |
1613 | aCoef = aViewDims.x() / 1e12; |
1614 | } |
1615 | if (aViewDims.y() < aCoef * Precision::Confusion()) |
1616 | { |
1617 | aCoef = aViewDims.y() / Precision::Confusion(); |
1618 | } |
1619 | else if (aViewDims.y() > aCoef * 1e12) |
1620 | { |
1621 | aCoef = aViewDims.y() / 1e12; |
1622 | } |
1623 | |
1624 | Graphic3d_Vec2d aZoomAtPointXYv (0.0, 0.0); |
1625 | theView->Convert (theParams.Point.x(), theParams.Point.y(), |
1626 | aZoomAtPointXYv.x(), aZoomAtPointXYv.y()); |
1627 | Graphic3d_Vec2d aDxy = aZoomAtPointXYv / aCoef; |
1628 | aCam->SetScale (aCam->Scale() / aCoef); |
1629 | |
1630 | const gp_Dir& aDir = aCam->Direction(); |
1631 | const gp_Ax3 aCameraCS (aCam->Center(), aDir.Reversed(), aDir ^ aCam->Up()); |
1632 | |
1633 | // pan back to the point |
1634 | aDxy = aZoomAtPointXYv - aDxy; |
1635 | if (thePnt != NULL) |
1636 | { |
1637 | // zoom at 3D point with perspective projection |
1638 | const gp_XYZ anEyeToPnt = thePnt->XYZ() - aCam->Eye().XYZ(); |
1639 | aDxy.SetValues (anEyeToPnt.Dot (aCameraCS.XDirection().XYZ()), |
1640 | anEyeToPnt.Dot (aCameraCS.YDirection().XYZ())); |
1641 | |
1642 | // view dimensions at 3D point |
1643 | const gp_Pnt aViewDims1 = aCam->ViewDimensions (anEyeToPnt.Dot (aCam->Direction().XYZ())); |
1644 | |
1645 | Graphic3d_Vec2i aWinSize; |
1646 | theView->Window()->Size (aWinSize.x(), aWinSize.y()); |
4e1b5fcb |
1647 | const Graphic3d_Vec2d aWinSizeF (aWinSize); |
1648 | const Graphic3d_Vec2d aPanFromCenterPx (double(theParams.Point.x()) - 0.5 * aWinSizeF.x(), |
1649 | aWinSizeF.y() - double(theParams.Point.y()) - 1.0 - 0.5 * aWinSizeF.y()); |
1650 | aDxy.x() += -aViewDims1.X() * aPanFromCenterPx.x() / aWinSizeF.x(); |
1651 | aDxy.y() += -aViewDims1.Y() * aPanFromCenterPx.y() / aWinSizeF.y(); |
49582f9d |
1652 | } |
1653 | |
1654 | //theView->Translate (aCam, aDxy.x(), aDxy.y()); |
1655 | gp_Trsf aPanTrsf; |
1656 | const gp_Vec aCameraPan = gp_Vec (aCameraCS.XDirection()) * aDxy.x() |
1657 | + gp_Vec (aCameraCS.YDirection()) * aDxy.y(); |
1658 | aPanTrsf.SetTranslation (aCameraPan); |
1659 | aCam->Transform (aPanTrsf); |
1660 | theView->Invalidate(); |
b40cdc2b |
1661 | theView->View()->SynchronizeXRPosedToBaseCamera(); |
49582f9d |
1662 | } |
1663 | |
1664 | // ======================================================================= |
1665 | // function : handleZFocusScroll |
1666 | // purpose : |
1667 | // ======================================================================= |
1668 | void AIS_ViewController::handleZFocusScroll (const Handle(V3d_View)& theView, |
1669 | const Aspect_ScrollDelta& theParams) |
1670 | { |
1671 | if (!myToAllowZFocus |
1672 | || !theView->Camera()->IsStereo()) |
1673 | { |
1674 | return; |
1675 | } |
1676 | |
1677 | Standard_Real aFocus = theView->Camera()->ZFocus() + (theParams.Delta > 0.0 ? 0.05 : -0.05); |
1678 | if (aFocus > 0.2 |
1679 | && aFocus < 2.0) |
1680 | { |
1681 | theView->Camera()->SetZFocus (theView->Camera()->ZFocusType(), aFocus); |
b40cdc2b |
1682 | theView->Invalidate(); |
49582f9d |
1683 | } |
1684 | } |
1685 | |
1686 | // ======================================================================= |
1687 | // function : handleOrbitRotation |
1688 | // purpose : |
1689 | // ======================================================================= |
1690 | void AIS_ViewController::handleOrbitRotation (const Handle(V3d_View)& theView, |
1691 | const gp_Pnt& thePnt, |
1692 | bool theToLockZUp) |
1693 | { |
1694 | if (!myToAllowRotation) |
1695 | { |
1696 | return; |
1697 | } |
1698 | |
b40cdc2b |
1699 | const Handle(Graphic3d_Camera)& aCam = theView->View()->IsActiveXR() |
1700 | ? theView->View()->BaseXRCamera() |
1701 | : theView->Camera(); |
49582f9d |
1702 | if (myGL.OrbitRotation.ToStart) |
1703 | { |
1704 | // default alternatives |
1705 | //if (myRotationMode == AIS_RotationMode_BndBoxActive) theView->StartRotation (myGL.RotateAtPoint.x(), myGL.RotateAtPoint.y()); |
1706 | //theView->Rotate (0.0, 0.0, 0.0, thePnt.X(), thePnt.Y(), thePnt.Z(), true); |
1707 | |
1708 | myRotatePnt3d = thePnt; |
1709 | myCamStartOpUp = aCam->Up(); |
607e5e62 |
1710 | myCamStartOpDir = aCam->Direction(); |
49582f9d |
1711 | myCamStartOpEye = aCam->Eye(); |
1712 | myCamStartOpCenter = aCam->Center(); |
1713 | |
1714 | gp_Trsf aTrsf; |
1715 | aTrsf.SetTransformation (gp_Ax3 (myRotatePnt3d, aCam->OrthogonalizedUp(), aCam->Direction()), |
1716 | gp_Ax3 (myRotatePnt3d, gp::DZ(), gp::DX())); |
1717 | const gp_Quaternion aRot = aTrsf.GetRotation(); |
1718 | aRot.GetEulerAngles (gp_YawPitchRoll, myRotateStartYawPitchRoll[0], myRotateStartYawPitchRoll[1], myRotateStartYawPitchRoll[2]); |
1719 | |
1720 | aTrsf.Invert(); |
1721 | myCamStartOpToEye = gp_Vec (myRotatePnt3d, aCam->Eye()).Transformed (aTrsf); |
1722 | myCamStartOpToCenter = gp_Vec (myRotatePnt3d, aCam->Center()).Transformed (aTrsf); |
1723 | |
1724 | theView->Invalidate(); |
1725 | } |
1726 | |
1727 | if (!myGL.OrbitRotation.ToRotate) |
1728 | { |
1729 | return; |
1730 | } |
1731 | |
2108d9a2 |
1732 | AbortViewAnimation(); |
49582f9d |
1733 | if (theToLockZUp) |
1734 | { |
1735 | // amend camera to exclude roll angle (put camera Up vector to plane containing global Z and view direction) |
1736 | Graphic3d_Vec2i aWinXY; |
1737 | theView->Window()->Size (aWinXY.x(), aWinXY.y()); |
1738 | double aYawAngleDelta = ((myGL.OrbitRotation.PointStart.x() - myGL.OrbitRotation.PointTo.x()) / double (aWinXY.x())) * (M_PI * 0.5); |
1739 | double aPitchAngleDelta = -((myGL.OrbitRotation.PointStart.y() - myGL.OrbitRotation.PointTo.y()) / double (aWinXY.y())) * (M_PI * 0.5); |
b40cdc2b |
1740 | double aPitchAngleNew = 0.0, aRoll = 0.0; |
1741 | const double aYawAngleNew = myRotateStartYawPitchRoll[0] + aYawAngleDelta; |
1742 | if (!theView->View()->IsActiveXR()) |
1743 | { |
1744 | aPitchAngleNew = Max (Min (myRotateStartYawPitchRoll[1] + aPitchAngleDelta, M_PI * 0.5 - M_PI / 180.0), -M_PI * 0.5 + M_PI / 180.0); |
1745 | aRoll = 0.0; |
1746 | } |
49582f9d |
1747 | |
1748 | gp_Quaternion aRot; |
1749 | aRot.SetEulerAngles (gp_YawPitchRoll, aYawAngleNew, aPitchAngleNew, aRoll); |
1750 | gp_Trsf aTrsfRot; |
1751 | aTrsfRot.SetRotation (aRot); |
1752 | |
1753 | const gp_Dir aNewUp = gp::DZ().Transformed (aTrsfRot); |
1754 | aCam->SetUp (aNewUp); |
607e5e62 |
1755 | aCam->SetEyeAndCenter (myRotatePnt3d.XYZ() + myCamStartOpToEye .Transformed (aTrsfRot).XYZ(), |
1756 | myRotatePnt3d.XYZ() + myCamStartOpToCenter.Transformed (aTrsfRot).XYZ()); |
1757 | |
49582f9d |
1758 | aCam->OrthogonalizeUp(); |
1759 | } |
1760 | else |
1761 | { |
1762 | // default alternatives |
1763 | //if (myRotationMode == AIS_RotationMode_BndBoxActive) theView->Rotation (myGL.RotateToPoint.x(), myGL.RotateToPoint.y()); |
1764 | //theView->Rotate (aDX, aDY, aDZ, myRotatePnt3d.X(), myRotatePnt3d.Y(), myRotatePnt3d.Z(), false); |
1765 | |
1766 | // restore previous camera state |
607e5e62 |
1767 | aCam->SetEyeAndCenter (myCamStartOpEye, myCamStartOpCenter); |
1768 | aCam->SetUp (myCamStartOpUp); |
1769 | aCam->SetDirectionFromEye (myCamStartOpDir); |
49582f9d |
1770 | |
1771 | Graphic3d_Vec2d aWinXY; |
1772 | theView->Size (aWinXY.x(), aWinXY.y()); |
1773 | const Standard_Real rx = (Standard_Real )theView->Convert (aWinXY.x()); |
1774 | const Standard_Real ry = (Standard_Real )theView->Convert (aWinXY.y()); |
1775 | |
1776 | const double THE_2PI = M_PI * 2.0; |
1777 | double aDX = (myGL.OrbitRotation.PointTo.x() - myGL.OrbitRotation.PointStart.x()) * M_PI / rx; |
1778 | double aDY = (myGL.OrbitRotation.PointStart.y() - myGL.OrbitRotation.PointTo.y()) * M_PI / ry; |
1779 | |
1780 | if (aDX > 0.0) { while (aDX > THE_2PI) { aDX -= THE_2PI; } } |
1781 | else if(aDX < 0.0) { while (aDX < -THE_2PI) { aDX += THE_2PI; } } |
1782 | if (aDY > 0.0) { while (aDY > THE_2PI) { aDY -= THE_2PI; } } |
1783 | else if(aDY < 0.0) { while (aDY < -THE_2PI) { aDY += THE_2PI; } } |
1784 | |
1785 | // rotate camera around 3 initial axes |
1786 | gp_Dir aCamDir (aCam->Direction().Reversed()); |
1787 | gp_Dir aCamUp (aCam->Up()); |
1788 | gp_Dir aCamSide(aCamUp.Crossed (aCamDir)); |
1789 | |
1790 | gp_Trsf aRot[2], aTrsf; |
1791 | aRot[0].SetRotation (gp_Ax1 (myRotatePnt3d, aCamUp), -aDX); |
1792 | aRot[1].SetRotation (gp_Ax1 (myRotatePnt3d, aCamSide), aDY); |
1793 | aTrsf.Multiply (aRot[0]); |
1794 | aTrsf.Multiply (aRot[1]); |
1795 | |
1796 | aCam->Transform (aTrsf); |
1797 | } |
1798 | |
1799 | theView->Invalidate(); |
b40cdc2b |
1800 | theView->View()->SynchronizeXRBaseToPosedCamera(); |
49582f9d |
1801 | } |
1802 | |
1803 | // ======================================================================= |
1804 | // function : handleViewRotation |
1805 | // purpose : |
1806 | // ======================================================================= |
1807 | void AIS_ViewController::handleViewRotation (const Handle(V3d_View)& theView, |
1808 | double theYawExtra, |
1809 | double thePitchExtra, |
1810 | double theRoll, |
1811 | bool theToRestartOnIncrement) |
1812 | { |
1813 | if (!myToAllowRotation) |
1814 | { |
1815 | return; |
1816 | } |
1817 | |
1818 | const Handle(Graphic3d_Camera)& aCam = theView->Camera(); |
1819 | const bool toRotateAnyway = Abs (theYawExtra) > gp::Resolution() |
1820 | || Abs (thePitchExtra) > gp::Resolution() |
1821 | || Abs (theRoll - myRotateStartYawPitchRoll[2]) > gp::Resolution(); |
1822 | if (toRotateAnyway |
1823 | && theToRestartOnIncrement) |
1824 | { |
1825 | myGL.ViewRotation.ToStart = true; |
1826 | myGL.ViewRotation.PointTo = myGL.ViewRotation.PointStart; |
1827 | } |
1828 | if (myGL.ViewRotation.ToStart) |
1829 | { |
1830 | gp_Trsf aTrsf; |
1831 | aTrsf.SetTransformation (gp_Ax3 (gp::Origin(), aCam->OrthogonalizedUp(), aCam->Direction()), |
1832 | gp_Ax3 (gp::Origin(), gp::DZ(), gp::DX())); |
1833 | const gp_Quaternion aRot = aTrsf.GetRotation(); |
1834 | double aRollDummy = 0.0; |
1835 | aRot.GetEulerAngles (gp_YawPitchRoll, myRotateStartYawPitchRoll[0], myRotateStartYawPitchRoll[1], aRollDummy); |
1836 | } |
1837 | if (toRotateAnyway) |
1838 | { |
1839 | myRotateStartYawPitchRoll[0] += theYawExtra; |
1840 | myRotateStartYawPitchRoll[1] += thePitchExtra; |
1841 | myRotateStartYawPitchRoll[2] = theRoll; |
1842 | myGL.ViewRotation.ToRotate = true; |
1843 | } |
1844 | |
1845 | if (!myGL.ViewRotation.ToRotate) |
1846 | { |
1847 | return; |
1848 | } |
1849 | |
2108d9a2 |
1850 | AbortViewAnimation(); |
1851 | |
49582f9d |
1852 | Graphic3d_Vec2i aWinXY; |
1853 | theView->Window()->Size (aWinXY.x(), aWinXY.y()); |
1854 | double aYawAngleDelta = ((myGL.ViewRotation.PointStart.x() - myGL.ViewRotation.PointTo.x()) / double (aWinXY.x())) * (M_PI * 0.5); |
1855 | double aPitchAngleDelta = -((myGL.ViewRotation.PointStart.y() - myGL.ViewRotation.PointTo.y()) / double (aWinXY.y())) * (M_PI * 0.5); |
1856 | const double aPitchAngleNew = Max (Min (myRotateStartYawPitchRoll[1] + aPitchAngleDelta, M_PI * 0.5 - M_PI / 180.0), -M_PI * 0.5 + M_PI / 180.0); |
1857 | const double aYawAngleNew = myRotateStartYawPitchRoll[0] + aYawAngleDelta; |
1858 | gp_Quaternion aRot; |
1859 | aRot.SetEulerAngles (gp_YawPitchRoll, aYawAngleNew, aPitchAngleNew, theRoll); |
1860 | gp_Trsf aTrsfRot; |
1861 | aTrsfRot.SetRotation (aRot); |
1862 | |
49582f9d |
1863 | const gp_Dir aNewUp = gp::DZ().Transformed (aTrsfRot); |
1864 | const gp_Dir aNewDir = gp::DX().Transformed (aTrsfRot); |
607e5e62 |
1865 | aCam->SetUp (aNewUp); |
1866 | aCam->SetDirectionFromEye (aNewDir); |
49582f9d |
1867 | aCam->OrthogonalizeUp(); |
1868 | theView->Invalidate(); |
1869 | } |
1870 | |
1871 | // ======================================================================= |
1872 | // function : PickPoint |
1873 | // purpose : |
1874 | // ======================================================================= |
1875 | bool AIS_ViewController::PickPoint (gp_Pnt& thePnt, |
1876 | const Handle(AIS_InteractiveContext)& theCtx, |
1877 | const Handle(V3d_View)& theView, |
1878 | const Graphic3d_Vec2i& theCursor, |
1879 | bool theToStickToPickRay) |
1880 | { |
1881 | ResetPreviousMoveTo(); |
1882 | |
1883 | const Handle(StdSelect_ViewerSelector3d)& aSelector = theCtx->MainSelector(); |
1884 | aSelector->Pick (theCursor.x(), theCursor.y(), theView); |
1885 | if (aSelector->NbPicked() < 1) |
1886 | { |
1887 | return false; |
1888 | } |
1889 | |
1890 | const SelectMgr_SortCriterion& aPicked = aSelector->PickedData (1); |
1891 | if (theToStickToPickRay |
1892 | && !Precision::IsInfinite (aPicked.Depth)) |
1893 | { |
1894 | thePnt = aSelector->GetManager().DetectedPoint (aPicked.Depth); |
1895 | } |
1896 | else |
1897 | { |
1898 | thePnt = aSelector->PickedPoint (1); |
1899 | } |
1900 | return !Precision::IsInfinite (thePnt.X()) |
1901 | && !Precision::IsInfinite (thePnt.Y()) |
1902 | && !Precision::IsInfinite (thePnt.Z()); |
1903 | } |
1904 | |
0461e7fd |
1905 | // ======================================================================= |
1906 | // function : PickAxis |
1907 | // purpose : |
1908 | // ======================================================================= |
1909 | bool AIS_ViewController::PickAxis (gp_Pnt& theTopPnt, |
1910 | const Handle(AIS_InteractiveContext)& theCtx, |
1911 | const Handle(V3d_View)& theView, |
1912 | const gp_Ax1& theAxis) |
1913 | { |
1914 | ResetPreviousMoveTo(); |
1915 | |
1916 | const Handle(StdSelect_ViewerSelector3d)& aSelector = theCtx->MainSelector(); |
1917 | aSelector->Pick (theAxis, theView); |
1918 | if (aSelector->NbPicked() < 1) |
1919 | { |
1920 | return false; |
1921 | } |
1922 | |
1923 | const SelectMgr_SortCriterion& aPickedData = aSelector->PickedData (1); |
1924 | theTopPnt = aPickedData.Point; |
1925 | return !Precision::IsInfinite (theTopPnt.X()) |
1926 | && !Precision::IsInfinite (theTopPnt.Y()) |
1927 | && !Precision::IsInfinite (theTopPnt.Z()); |
1928 | } |
1929 | |
49582f9d |
1930 | // ======================================================================= |
1931 | // function : GravityPoint |
1932 | // purpose : |
1933 | // ======================================================================= |
1934 | gp_Pnt AIS_ViewController::GravityPoint (const Handle(AIS_InteractiveContext)& theCtx, |
1935 | const Handle(V3d_View)& theView) |
1936 | { |
1937 | switch (myRotationMode) |
1938 | { |
1939 | case AIS_RotationMode_PickLast: |
1940 | case AIS_RotationMode_PickCenter: |
1941 | { |
1942 | Graphic3d_Vec2i aCursor ((int )myGL.OrbitRotation.PointStart.x(), (int )myGL.OrbitRotation.PointStart.y()); |
1943 | if (myRotationMode == AIS_RotationMode_PickCenter) |
1944 | { |
1945 | Graphic3d_Vec2i aViewPort; |
1946 | theView->Window()->Size (aViewPort.x(), aViewPort.y()); |
1947 | aCursor = aViewPort / 2; |
1948 | } |
1949 | |
1950 | gp_Pnt aPnt; |
9460f8c0 |
1951 | if (PickPoint (aPnt, theCtx, theView, aCursor, myToStickToRayOnRotation)) |
49582f9d |
1952 | { |
1953 | return aPnt; |
1954 | } |
1955 | break; |
1956 | } |
1957 | case AIS_RotationMode_CameraAt: |
1958 | { |
1959 | const Handle(Graphic3d_Camera)& aCam = theView->Camera(); |
1960 | return aCam->Center(); |
1961 | } |
1962 | case AIS_RotationMode_BndBoxScene: |
1963 | { |
1964 | Bnd_Box aBndBox = theView->View()->MinMaxValues (false); |
1965 | if (!aBndBox.IsVoid()) |
1966 | { |
1967 | return (aBndBox.CornerMin().XYZ() + aBndBox.CornerMax().XYZ()) * 0.5; |
1968 | } |
1969 | break; |
1970 | } |
1971 | case AIS_RotationMode_BndBoxActive: |
1972 | break; |
1973 | } |
1974 | |
1975 | return theCtx ->GravityPoint (theView); |
1976 | } |
1977 | |
d6fbb2ab |
1978 | // ======================================================================= |
1979 | // function : FitAllAuto |
1980 | // purpose : |
1981 | // ======================================================================= |
1982 | void AIS_ViewController::FitAllAuto (const Handle(AIS_InteractiveContext)& theCtx, |
1983 | const Handle(V3d_View)& theView) |
1984 | { |
b56df3a6 |
1985 | const Bnd_Box aBoxSel = theCtx->BoundingBoxOfSelection (theView); |
d6fbb2ab |
1986 | const double aFitMargin = 0.01; |
1987 | if (aBoxSel.IsVoid()) |
1988 | { |
1989 | theView->FitAll (aFitMargin, false); |
1990 | return; |
1991 | } |
1992 | |
1993 | // fit all algorithm is not 100% stable - so compute some precision to compare equal camera values |
1994 | const double aFitTol = (aBoxSel.CornerMax().XYZ() - aBoxSel.CornerMin().XYZ()).Modulus() * 0.000001; |
1995 | const Bnd_Box aBoxAll = theView->View()->MinMaxValues(); |
1996 | |
1997 | const Handle(Graphic3d_Camera)& aCam = theView->Camera(); |
1998 | Handle(Graphic3d_Camera) aCameraSel = new Graphic3d_Camera (aCam); |
1999 | Handle(Graphic3d_Camera) aCameraAll = new Graphic3d_Camera (aCam); |
2000 | theView->FitMinMax (aCameraSel, aBoxSel, aFitMargin); |
2001 | theView->FitMinMax (aCameraAll, aBoxAll, aFitMargin); |
2002 | if (aCameraSel->Center().IsEqual (aCam->Center(), aFitTol) |
2003 | && Abs (aCameraSel->Scale() - aCam->Scale()) < aFitTol |
2004 | && Abs (aCameraSel->Distance() - aCam->Distance()) < aFitTol) |
2005 | { |
2006 | // fit all entire view on second FitALL request |
2007 | aCam->Copy (aCameraAll); |
2008 | } |
2009 | else |
2010 | { |
2011 | aCam->Copy (aCameraSel); |
2012 | } |
2013 | } |
2014 | |
2015 | // ======================================================================= |
2016 | // function : handleViewOrientationKeys |
2017 | // purpose : |
2018 | // ======================================================================= |
2019 | void AIS_ViewController::handleViewOrientationKeys (const Handle(AIS_InteractiveContext)& theCtx, |
2020 | const Handle(V3d_View)& theView) |
2021 | { |
2022 | if (myNavigationMode == AIS_NavigationMode_FirstPersonWalk) |
2023 | { |
2024 | return; |
2025 | } |
2026 | |
2027 | Handle(Graphic3d_Camera) aCameraBack; |
2028 | struct ViewKeyAction |
2029 | { |
2030 | Aspect_VKey Key; |
2031 | V3d_TypeOfOrientation Orientation; |
2032 | }; |
2033 | static const ViewKeyAction THE_VIEW_KEYS[] = |
2034 | { |
2035 | { Aspect_VKey_ViewTop, V3d_TypeOfOrientation_Zup_Top }, |
2036 | { Aspect_VKey_ViewBottom, V3d_TypeOfOrientation_Zup_Bottom }, |
2037 | { Aspect_VKey_ViewLeft, V3d_TypeOfOrientation_Zup_Left }, |
2038 | { Aspect_VKey_ViewRight, V3d_TypeOfOrientation_Zup_Right }, |
2039 | { Aspect_VKey_ViewFront, V3d_TypeOfOrientation_Zup_Front }, |
2040 | { Aspect_VKey_ViewBack, V3d_TypeOfOrientation_Zup_Back }, |
2041 | { Aspect_VKey_ViewAxoLeftProj, V3d_TypeOfOrientation_Zup_AxoLeft }, |
2042 | { Aspect_VKey_ViewAxoRightProj, V3d_TypeOfOrientation_Zup_AxoRight }, |
2043 | { Aspect_VKey_ViewRoll90CW, (V3d_TypeOfOrientation )-1}, |
2044 | { Aspect_VKey_ViewRoll90CCW, (V3d_TypeOfOrientation )-1}, |
2045 | { Aspect_VKey_ViewFitAll, (V3d_TypeOfOrientation )-1} |
2046 | }; |
2047 | { |
2048 | Standard_Mutex::Sentry aLock (myKeys.Mutex()); |
2049 | const size_t aNbKeys = sizeof(THE_VIEW_KEYS) / sizeof(*THE_VIEW_KEYS); |
2050 | const double anEventTime = EventTime(); |
2051 | for (size_t aKeyIter = 0; aKeyIter < aNbKeys; ++aKeyIter) |
2052 | { |
2053 | const ViewKeyAction& aKeyAction = THE_VIEW_KEYS[aKeyIter]; |
2054 | if (!myKeys.IsKeyDown (aKeyAction.Key)) |
2055 | { |
2056 | continue; |
2057 | } |
2058 | |
2059 | myKeys.KeyUp (aKeyAction.Key, anEventTime); |
2060 | if (aCameraBack.IsNull()) |
2061 | { |
2062 | aCameraBack = theView->Camera(); |
2063 | theView->SetCamera (new Graphic3d_Camera (aCameraBack)); |
2064 | } |
2065 | if (aKeyAction.Orientation != (V3d_TypeOfOrientation )-1) |
2066 | { |
2067 | theView->SetProj (aKeyAction.Orientation); |
2068 | FitAllAuto (theCtx, theView); |
2069 | } |
2070 | else if (aKeyAction.Key == Aspect_VKey_ViewRoll90CW) |
2071 | { |
2072 | const double aTwist = theView->Twist() + M_PI / 2.0; |
2073 | theView->SetTwist (aTwist); |
2074 | } |
2075 | else if (aKeyAction.Key == Aspect_VKey_ViewRoll90CCW) |
2076 | { |
2077 | const double aTwist = theView->Twist() - M_PI / 2.0; |
2078 | theView->SetTwist (aTwist); |
2079 | } |
2080 | else if (aKeyAction.Key == Aspect_VKey_ViewFitAll) |
2081 | { |
2082 | FitAllAuto (theCtx, theView); |
2083 | } |
2084 | } |
2085 | } |
2086 | |
2087 | if (aCameraBack.IsNull()) |
2088 | { |
2089 | return; |
2090 | } |
2091 | |
2092 | Handle(Graphic3d_Camera) aCameraNew = theView->Camera(); |
2093 | theView->SetCamera (aCameraBack); |
2094 | const Graphic3d_Mat4d anOrientMat1 = aCameraBack->OrientationMatrix(); |
2095 | const Graphic3d_Mat4d anOrientMat2 = aCameraNew ->OrientationMatrix(); |
2096 | if (anOrientMat1 != anOrientMat2) |
2097 | { |
2098 | const Handle(AIS_AnimationCamera)& aCamAnim = myViewAnimation; |
2099 | aCamAnim->SetView (theView); |
2100 | aCamAnim->SetStartPts (0.0); |
2101 | aCamAnim->SetCameraStart (new Graphic3d_Camera (aCameraBack)); |
2102 | aCamAnim->SetCameraEnd (new Graphic3d_Camera (aCameraNew)); |
2103 | aCamAnim->StartTimer (0.0, 1.0, true, false); |
2104 | } |
2105 | } |
2106 | |
d22962e4 |
2107 | // ======================================================================= |
2108 | // function : handleNavigationKeys |
2109 | // purpose : |
2110 | // ======================================================================= |
2111 | AIS_WalkDelta AIS_ViewController::handleNavigationKeys (const Handle(AIS_InteractiveContext)& , |
2112 | const Handle(V3d_View)& theView) |
2113 | { |
2114 | // navigation keys |
2115 | double aCrouchRatio = 1.0, aRunRatio = 1.0; |
2116 | if (myNavigationMode == AIS_NavigationMode_FirstPersonFlight) |
2117 | { |
2118 | aRunRatio = 3.0; |
2119 | } |
2120 | |
2121 | const double aRotSpeed = 0.5; |
2122 | const double aWalkSpeedCoef = WalkSpeedRelative(); |
2123 | AIS_WalkDelta aWalk = FetchNavigationKeys (aCrouchRatio, aRunRatio); |
2124 | if (aWalk.IsJumping()) |
2125 | { |
2126 | // ask more frames |
2127 | setAskNextFrame(); |
2128 | theView->Invalidate(); |
2129 | } |
2130 | if (aWalk.IsEmpty()) |
2131 | { |
f9ab9f7f |
2132 | if (aWalk.IsDefined()) |
2133 | { |
2134 | setAskNextFrame(); |
2135 | } |
d22962e4 |
2136 | return aWalk; |
2137 | } |
2138 | else if (myGL.OrbitRotation.ToRotate |
2139 | || myGL.OrbitRotation.ToStart) |
2140 | { |
2141 | return aWalk; |
2142 | } |
2143 | |
2144 | gp_XYZ aMin, aMax; |
2145 | const Bnd_Box aBndBox = theView->View()->MinMaxValues(); |
2146 | if (!aBndBox.IsVoid()) |
2147 | { |
2148 | aMin = aBndBox.CornerMin().XYZ(); |
2149 | aMax = aBndBox.CornerMax().XYZ(); |
2150 | } |
2151 | double aBndDiam = Max (Max (aMax.X() - aMin.X(), aMax.Y() - aMin.Y()), aMax.Z() - aMin.Z()); |
2152 | if (aBndDiam <= gp::Resolution()) |
2153 | { |
2154 | aBndDiam = 0.001; |
2155 | } |
2156 | |
2157 | const double aWalkSpeed = myNavigationMode != AIS_NavigationMode_Orbit |
2158 | && myNavigationMode != AIS_NavigationMode_FirstPersonFlight |
2159 | ? theView->View()->UnitFactor() * WalkSpeedAbsolute() |
2160 | : aWalkSpeedCoef * aBndDiam; |
2161 | const Handle(Graphic3d_Camera)& aCam = theView->View()->IsActiveXR() |
2162 | ? theView->View()->BaseXRCamera() |
2163 | : theView->Camera(); |
2164 | |
2165 | // move forward in plane XY and up along Z |
2166 | const gp_Dir anUp = ToLockOrbitZUp() ? gp::DZ() : aCam->OrthogonalizedUp(); |
2167 | if (aWalk.ToMove() |
2168 | && myToAllowPanning) |
2169 | { |
2170 | const gp_Vec aSide = -aCam->SideRight(); |
2171 | gp_XYZ aFwd = aCam->Direction().XYZ(); |
2172 | aFwd -= anUp.XYZ() * (anUp.XYZ() * aFwd); |
2173 | |
2174 | gp_XYZ aMoveVec; |
2175 | if (!aWalk[AIS_WalkTranslation_Forward].IsEmpty()) |
2176 | { |
2177 | if (!aCam->IsOrthographic()) |
2178 | { |
2179 | aMoveVec += aFwd * aWalk[AIS_WalkTranslation_Forward].Value * aWalk[AIS_WalkTranslation_Forward].Pressure * aWalkSpeed; |
2180 | } |
2181 | } |
2182 | if (!aWalk[AIS_WalkTranslation_Side].IsEmpty()) |
2183 | { |
2184 | aMoveVec += aSide.XYZ() * aWalk[AIS_WalkTranslation_Side].Value * aWalk[AIS_WalkTranslation_Side].Pressure * aWalkSpeed; |
2185 | } |
2186 | if (!aWalk[AIS_WalkTranslation_Up].IsEmpty()) |
2187 | { |
2188 | aMoveVec += anUp.XYZ() * aWalk[AIS_WalkTranslation_Up].Value * aWalk[AIS_WalkTranslation_Up].Pressure * aWalkSpeed; |
2189 | } |
2190 | { |
2191 | if (aCam->IsOrthographic()) |
2192 | { |
2193 | if (!aWalk[AIS_WalkTranslation_Forward].IsEmpty()) |
2194 | { |
2195 | const double aZoomDelta = aWalk[AIS_WalkTranslation_Forward].Value * aWalk[AIS_WalkTranslation_Forward].Pressure * aWalkSpeedCoef; |
2196 | handleZoom (theView, Aspect_ScrollDelta (aZoomDelta * 100.0), NULL); |
2197 | } |
2198 | } |
2199 | |
2200 | gp_Trsf aTrsfTranslate; |
2201 | aTrsfTranslate.SetTranslation (aMoveVec); |
2202 | aCam->Transform (aTrsfTranslate); |
2203 | } |
2204 | } |
2205 | |
2206 | if (myNavigationMode == AIS_NavigationMode_Orbit |
2207 | && myToAllowRotation) |
2208 | { |
2209 | if (!aWalk[AIS_WalkRotation_Yaw].IsEmpty()) |
2210 | { |
2211 | gp_Trsf aTrsfRot; |
2212 | aTrsfRot.SetRotation (gp_Ax1 (aCam->Eye(), anUp), aWalk[AIS_WalkRotation_Yaw].Value * aRotSpeed); |
2213 | aCam->Transform (aTrsfRot); |
2214 | } |
2215 | if (!aWalk[AIS_WalkRotation_Pitch].IsEmpty()) |
2216 | { |
2217 | const gp_Vec aSide = -aCam->SideRight(); |
2218 | gp_Trsf aTrsfRot; |
2219 | aTrsfRot.SetRotation (gp_Ax1 (aCam->Eye(), aSide), -aWalk[AIS_WalkRotation_Pitch].Value * aRotSpeed); |
2220 | aCam->Transform (aTrsfRot); |
2221 | } |
2222 | if (!aWalk[AIS_WalkRotation_Roll].IsEmpty() |
2223 | && !ToLockOrbitZUp()) |
2224 | { |
2225 | gp_Trsf aTrsfRot; |
2226 | aTrsfRot.SetRotation (gp_Ax1 (aCam->Center(), aCam->Direction()), aWalk[AIS_WalkRotation_Roll].Value * aRotSpeed); |
2227 | aCam->Transform (aTrsfRot); |
2228 | } |
2229 | } |
2230 | |
2231 | // ask more frames |
2232 | setAskNextFrame(); |
2233 | theView->Invalidate(); |
2234 | theView->View()->SynchronizeXRBaseToPosedCamera(); |
2235 | return aWalk; |
2236 | } |
2237 | |
49582f9d |
2238 | // ======================================================================= |
2239 | // function : handleCameraActions |
2240 | // purpose : |
2241 | // ======================================================================= |
2242 | void AIS_ViewController::handleCameraActions (const Handle(AIS_InteractiveContext)& theCtx, |
2243 | const Handle(V3d_View)& theView, |
2244 | const AIS_WalkDelta& theWalk) |
2245 | { |
2246 | // apply view actions |
2247 | if (myGL.Orientation.ToSetViewOrient) |
2248 | { |
2249 | theView->SetProj (myGL.Orientation.ViewOrient); |
2250 | myGL.Orientation.ToFitAll = true; |
2251 | } |
2252 | |
2253 | // apply fit all |
2254 | if (myGL.Orientation.ToFitAll) |
2255 | { |
2256 | const double aFitMargin = 0.01; |
2257 | theView->FitAll (aFitMargin, false); |
2258 | theView->Invalidate(); |
2259 | myGL.Orientation.ToFitAll = false; |
2260 | } |
2261 | |
2262 | if (myGL.IsNewGesture) |
2263 | { |
2264 | if (myAnchorPointPrs1->HasInteractiveContext()) |
2265 | { |
2266 | theCtx->Remove (myAnchorPointPrs1, false); |
2267 | if (!theView->Viewer()->ZLayerSettings (myAnchorPointPrs1->ZLayer()).IsImmediate()) |
2268 | { |
2269 | theView->Invalidate(); |
2270 | } |
2271 | else |
2272 | { |
2273 | theView->InvalidateImmediate(); |
2274 | } |
2275 | } |
2276 | if (myAnchorPointPrs2->HasInteractiveContext()) |
2277 | { |
2278 | theCtx->Remove (myAnchorPointPrs2, false); |
2279 | if (!theView->Viewer()->ZLayerSettings (myAnchorPointPrs2->ZLayer()).IsImmediate()) |
2280 | { |
2281 | theView->Invalidate(); |
2282 | } |
2283 | else |
2284 | { |
2285 | theView->InvalidateImmediate(); |
2286 | } |
2287 | } |
2288 | |
2289 | if (myHasHlrOnBeforeRotation) |
2290 | { |
2291 | myHasHlrOnBeforeRotation = false; |
2292 | theView->SetComputedMode (true); |
2293 | theView->Invalidate(); |
2294 | } |
2295 | } |
2296 | |
2297 | if (myNavigationMode != AIS_NavigationMode_FirstPersonWalk) |
2298 | { |
2299 | if (myGL.Panning.ToStart |
2300 | && myToAllowPanning) |
2301 | { |
2302 | gp_Pnt aPanPnt (Precision::Infinite(), 0.0, 0.0); |
2303 | if (!theView->Camera()->IsOrthographic()) |
2304 | { |
2305 | bool toStickToRay = false; |
2306 | if (myGL.Panning.PointStart.x() >= 0 |
2307 | && myGL.Panning.PointStart.y() >= 0) |
2308 | { |
2309 | PickPoint (aPanPnt, theCtx, theView, myGL.Panning.PointStart, toStickToRay); |
2310 | } |
2311 | if (Precision::IsInfinite (aPanPnt.X())) |
2312 | { |
2313 | Graphic3d_Vec2i aWinSize; |
2314 | theView->Window()->Size (aWinSize.x(), aWinSize.y()); |
2315 | PickPoint (aPanPnt, theCtx, theView, aWinSize / 2, toStickToRay); |
2316 | } |
2317 | if (!Precision::IsInfinite (aPanPnt.X()) |
2318 | && myToShowPanAnchorPoint) |
2319 | { |
2320 | gp_Trsf aPntTrsf; |
2321 | aPntTrsf.SetTranslation (gp_Vec (aPanPnt.XYZ())); |
2322 | theCtx->SetLocation (myAnchorPointPrs2, aPntTrsf); |
2323 | } |
2324 | } |
2325 | setPanningAnchorPoint (aPanPnt); |
2326 | } |
2327 | |
2328 | if (myToShowPanAnchorPoint |
2329 | && hasPanningAnchorPoint() |
2330 | && myGL.Panning.ToPan |
2331 | && !myGL.IsNewGesture |
2332 | && !myAnchorPointPrs2->HasInteractiveContext()) |
2333 | { |
2334 | theCtx->Display (myAnchorPointPrs2, 0, -1, false, AIS_DS_Displayed); |
2335 | } |
2336 | |
2337 | handlePanning (theView); |
2338 | handleZRotate (theView); |
2339 | } |
2340 | |
2341 | if ((myNavigationMode == AIS_NavigationMode_Orbit |
2342 | || myGL.OrbitRotation.ToStart |
2343 | || myGL.OrbitRotation.ToRotate) |
2344 | && myToAllowRotation) |
2345 | { |
2346 | if (myGL.OrbitRotation.ToStart |
2347 | && !myHasHlrOnBeforeRotation) |
2348 | { |
2349 | myHasHlrOnBeforeRotation = theView->ComputedMode(); |
2350 | if (myHasHlrOnBeforeRotation) |
2351 | { |
2352 | theView->SetComputedMode (false); |
2353 | } |
2354 | } |
2355 | |
2356 | gp_Pnt aGravPnt; |
2357 | if (myGL.OrbitRotation.ToStart) |
2358 | { |
2359 | aGravPnt = GravityPoint (theCtx, theView); |
2360 | if (myToShowRotateCenter) |
2361 | { |
2362 | gp_Trsf aPntTrsf; |
2363 | aPntTrsf.SetTranslation (gp_Vec (aGravPnt.XYZ())); |
2364 | theCtx->SetLocation (myAnchorPointPrs1, aPntTrsf); |
2365 | theCtx->SetLocation (myAnchorPointPrs2, aPntTrsf); |
2366 | } |
2367 | } |
2368 | |
2369 | if (myToShowRotateCenter |
2370 | && myGL.OrbitRotation.ToRotate |
2371 | && !myGL.IsNewGesture |
2372 | && !myAnchorPointPrs1->HasInteractiveContext()) |
2373 | { |
2374 | theCtx->Display (myAnchorPointPrs1, 0, -1, false, AIS_DS_Displayed); |
2375 | theCtx->Display (myAnchorPointPrs2, 0, -1, false, AIS_DS_Displayed); |
2376 | } |
2377 | handleOrbitRotation (theView, aGravPnt, |
2378 | myToLockOrbitZUp || myNavigationMode != AIS_NavigationMode_Orbit); |
2379 | } |
2380 | |
2381 | if ((myNavigationMode != AIS_NavigationMode_Orbit |
2382 | || myGL.ViewRotation.ToStart |
2383 | || myGL.ViewRotation.ToRotate) |
2384 | && myToAllowRotation) |
2385 | { |
2386 | if (myGL.ViewRotation.ToStart |
2387 | && !myHasHlrOnBeforeRotation) |
2388 | { |
2389 | myHasHlrOnBeforeRotation = theView->ComputedMode(); |
2390 | if (myHasHlrOnBeforeRotation) |
2391 | { |
2392 | theView->SetComputedMode (false); |
2393 | } |
2394 | } |
2395 | |
2396 | double aRoll = 0.0; |
2397 | if (!theWalk[AIS_WalkRotation_Roll].IsEmpty() |
2398 | && !myToLockOrbitZUp) |
2399 | { |
2400 | aRoll = (M_PI / 12.0) * theWalk[AIS_WalkRotation_Roll].Pressure; |
2401 | aRoll *= Min (1000.0 * theWalk[AIS_WalkRotation_Roll].Duration, 100.0) / 100.0; |
2402 | if (theWalk[AIS_WalkRotation_Roll].Value < 0.0) |
2403 | { |
2404 | aRoll = -aRoll; |
2405 | } |
2406 | } |
2407 | |
2408 | handleViewRotation (theView, theWalk[AIS_WalkRotation_Yaw].Value, theWalk[AIS_WalkRotation_Pitch].Value, aRoll, |
2409 | myNavigationMode == AIS_NavigationMode_FirstPersonFlight); |
2410 | } |
2411 | |
2412 | if (!myGL.ZoomActions.IsEmpty()) |
2413 | { |
2414 | for (NCollection_Sequence<Aspect_ScrollDelta>::Iterator aZoomIter (myGL.ZoomActions); aZoomIter.More(); aZoomIter.Next()) |
2415 | { |
2416 | Aspect_ScrollDelta aZoomParams = aZoomIter.Value(); |
2417 | if (myToAllowZFocus |
2418 | && (aZoomParams.Flags & Aspect_VKeyFlags_CTRL) != 0 |
2419 | && theView->Camera()->IsStereo()) |
2420 | { |
2421 | handleZFocusScroll (theView, aZoomParams); |
2422 | continue; |
2423 | } |
2424 | |
2425 | if (!myToAllowZooming) |
2426 | { |
2427 | continue; |
2428 | } |
2429 | |
2430 | if (!theView->Camera()->IsOrthographic()) |
2431 | { |
49582f9d |
2432 | gp_Pnt aPnt; |
2433 | if (aZoomParams.HasPoint() |
9460f8c0 |
2434 | && PickPoint (aPnt, theCtx, theView, aZoomParams.Point, myToStickToRayOnZoom)) |
49582f9d |
2435 | { |
2436 | handleZoom (theView, aZoomParams, &aPnt); |
2437 | continue; |
2438 | } |
2439 | |
2440 | Graphic3d_Vec2i aWinSize; |
2441 | theView->Window()->Size (aWinSize.x(), aWinSize.y()); |
9460f8c0 |
2442 | if (PickPoint (aPnt, theCtx, theView, aWinSize / 2, myToStickToRayOnZoom)) |
49582f9d |
2443 | { |
2444 | aZoomParams.ResetPoint(); // do not pretend to zoom at 'nothing' |
2445 | handleZoom (theView, aZoomParams, &aPnt); |
2446 | continue; |
2447 | } |
2448 | } |
2449 | handleZoom (theView, aZoomParams, NULL); |
2450 | } |
2451 | myGL.ZoomActions.Clear(); |
2452 | } |
2453 | } |
2454 | |
b40cdc2b |
2455 | // ======================================================================= |
2456 | // function : handleXRInput |
2457 | // purpose : |
2458 | // ======================================================================= |
2459 | void AIS_ViewController::handleXRInput (const Handle(AIS_InteractiveContext)& theCtx, |
2460 | const Handle(V3d_View)& theView, |
2461 | const AIS_WalkDelta& ) |
2462 | { |
2463 | theView->View()->ProcessXRInput(); |
2464 | if (!theView->View()->IsActiveXR()) |
2465 | { |
2466 | return; |
2467 | } |
b40cdc2b |
2468 | handleXRTurnPad (theCtx, theView); |
2469 | handleXRTeleport(theCtx, theView); |
2470 | handleXRPicking (theCtx, theView); |
2471 | } |
2472 | |
2473 | // ======================================================================= |
2474 | // function : handleXRTurnPad |
2475 | // purpose : |
2476 | // ======================================================================= |
2477 | void AIS_ViewController::handleXRTurnPad (const Handle(AIS_InteractiveContext)& , |
2478 | const Handle(V3d_View)& theView) |
2479 | { |
2480 | if (myXRTurnAngle <= 0.0 |
2481 | || !theView->View()->IsActiveXR()) |
2482 | { |
2483 | return; |
2484 | } |
2485 | |
2486 | // turn left/right at 45 degrees on left/right trackpad clicks |
2487 | for (int aHand = 0; aHand < 2; ++aHand) |
2488 | { |
2489 | const Aspect_XRTrackedDeviceRole aRole = aHand == 0 ? Aspect_XRTrackedDeviceRole_RightHand : Aspect_XRTrackedDeviceRole_LeftHand; |
2490 | const Handle(Aspect_XRAction)& aPadClickAct = theView->View()->XRSession()->GenericAction (aRole, Aspect_XRGenericAction_InputTrackPadClick); |
2491 | const Handle(Aspect_XRAction)& aPadPosAct = theView->View()->XRSession()->GenericAction (aRole, Aspect_XRGenericAction_InputTrackPadPosition); |
2492 | if (aPadClickAct.IsNull() |
2493 | || aPadPosAct.IsNull()) |
2494 | { |
2495 | continue; |
2496 | } |
2497 | |
2498 | const Aspect_XRDigitalActionData aPadClick = theView->View()->XRSession()->GetDigitalActionData (aPadClickAct); |
2499 | const Aspect_XRAnalogActionData aPadPos = theView->View()->XRSession()->GetAnalogActionData (aPadPosAct); |
2500 | if (aPadClick.IsActive |
2501 | && aPadClick.IsPressed |
2502 | && aPadClick.IsChanged |
2503 | && aPadPos.IsActive |
2504 | && Abs (aPadPos.VecXYZ.y()) < 0.5f |
2505 | && Abs (aPadPos.VecXYZ.x()) > 0.7f) |
2506 | { |
2507 | gp_Trsf aTrsfTurn; |
2508 | aTrsfTurn.SetRotation (gp_Ax1 (gp::Origin(), theView->View()->BaseXRCamera()->Up()), aPadPos.VecXYZ.x() < 0.0f ? myXRTurnAngle : -myXRTurnAngle); |
2509 | theView->View()->TurnViewXRCamera (aTrsfTurn); |
2510 | break; |
2511 | } |
2512 | } |
2513 | } |
2514 | |
2515 | // ======================================================================= |
2516 | // function : handleXRTeleport |
2517 | // purpose : |
2518 | // ======================================================================= |
2519 | void AIS_ViewController::handleXRTeleport (const Handle(AIS_InteractiveContext)& theCtx, |
2520 | const Handle(V3d_View)& theView) |
2521 | { |
2522 | if (!theView->View()->IsActiveXR()) |
2523 | { |
2524 | return; |
2525 | } |
2526 | |
2527 | // teleport on forward trackpad unclicks |
2528 | const Aspect_XRTrackedDeviceRole aTeleOld = myXRLastTeleportHand; |
2529 | myXRLastTeleportHand = Aspect_XRTrackedDeviceRole_Other; |
2530 | for (int aHand = 0; aHand < 2; ++aHand) |
2531 | { |
2532 | const Aspect_XRTrackedDeviceRole aRole = aHand == 0 ? Aspect_XRTrackedDeviceRole_RightHand : Aspect_XRTrackedDeviceRole_LeftHand; |
2533 | const Standard_Integer aDeviceId = theView->View()->XRSession()->NamedTrackedDevice (aRole); |
2534 | if (aDeviceId == -1) |
2535 | { |
2536 | continue; |
2537 | } |
2538 | |
2539 | const Handle(Aspect_XRAction)& aPadClickAct = theView->View()->XRSession()->GenericAction (aRole, Aspect_XRGenericAction_InputTrackPadClick); |
2540 | const Handle(Aspect_XRAction)& aPadPosAct = theView->View()->XRSession()->GenericAction (aRole, Aspect_XRGenericAction_InputTrackPadPosition); |
2541 | if (aPadClickAct.IsNull() |
2542 | || aPadPosAct.IsNull()) |
2543 | { |
2544 | continue; |
2545 | } |
2546 | |
2547 | const Aspect_XRDigitalActionData aPadClick = theView->View()->XRSession()->GetDigitalActionData (aPadClickAct); |
2548 | const Aspect_XRAnalogActionData aPadPos = theView->View()->XRSession()->GetAnalogActionData (aPadPosAct); |
2549 | const bool isPressed = aPadClick.IsPressed; |
2550 | const bool isClicked = !aPadClick.IsPressed |
2551 | && aPadClick.IsChanged; |
2552 | if (aPadClick.IsActive |
2553 | && (isPressed || isClicked) |
2554 | && aPadPos.IsActive |
2555 | && aPadPos.VecXYZ.y() > 0.6f |
2556 | && Abs (aPadPos.VecXYZ.x()) < 0.5f) |
2557 | { |
2558 | const Aspect_TrackedDevicePose& aPose = theView->View()->XRSession()->TrackedPoses()[aDeviceId]; |
2559 | if (!aPose.IsValidPose) |
2560 | { |
2561 | continue; |
2562 | } |
2563 | |
2564 | myXRLastTeleportHand = aRole; |
2565 | Standard_Real& aPickDepth = aRole == Aspect_XRTrackedDeviceRole_LeftHand ? myXRLastPickDepthLeft : myXRLastPickDepthRight; |
2566 | aPickDepth = Precision::Infinite(); |
2567 | Graphic3d_Vec3 aPickNorm; |
2568 | const gp_Trsf aHandBase = theView->View()->PoseXRToWorld (aPose.Orientation); |
2569 | const Standard_Real aHeadHeight = theView->View()->XRSession()->HeadPose().TranslationPart().Y(); |
2570 | { |
2571 | const Standard_Integer aPickedId = handleXRMoveTo (theCtx, theView, aPose.Orientation, false); |
2572 | if (aPickedId >= 1) |
2573 | { |
2574 | const SelectMgr_SortCriterion& aPickedData = theCtx->MainSelector()->PickedData (aPickedId); |
2575 | aPickNorm = aPickedData.Normal; |
2576 | if (aPickNorm.SquareModulus() > ShortRealEpsilon()) |
2577 | { |
2578 | aPickDepth = aPickedData.Point.Distance (aHandBase.TranslationPart()); |
2579 | } |
2580 | } |
2581 | } |
2582 | if (isClicked) |
2583 | { |
2584 | myXRLastTeleportHand = Aspect_XRTrackedDeviceRole_Other; |
2585 | if (!Precision::IsInfinite (aPickDepth)) |
2586 | { |
2587 | const gp_Dir aTeleDir = -gp::DZ().Transformed (aHandBase); |
2588 | const gp_Dir anUpDir = theView->View()->BaseXRCamera()->Up(); |
2589 | |
2590 | bool isHorizontal = false; |
2591 | gp_Dir aPickNormDir (aPickNorm.x(), aPickNorm.y(), aPickNorm.z()); |
2592 | if (anUpDir.IsEqual ( aPickNormDir, M_PI_4) |
2593 | || anUpDir.IsEqual (-aPickNormDir, M_PI_4)) |
2594 | { |
2595 | isHorizontal = true; |
2596 | } |
2597 | |
2598 | gp_Pnt aNewEye = aHandBase.TranslationPart(); |
2599 | if (isHorizontal) |
2600 | { |
2601 | aNewEye = aHandBase.TranslationPart() |
2602 | + aTeleDir.XYZ() * aPickDepth |
2603 | + anUpDir.XYZ() * aHeadHeight; |
2604 | } |
2605 | else |
2606 | { |
2607 | if (aPickNormDir.Dot (aTeleDir) < 0.0) |
2608 | { |
2609 | aPickNormDir.Reverse(); |
2610 | } |
2611 | aNewEye = aHandBase.TranslationPart() |
2612 | + aTeleDir.XYZ() * aPickDepth |
2613 | - aPickNormDir.XYZ() * aHeadHeight / 4; |
2614 | } |
2615 | |
2616 | theView->View()->PosedXRCamera()->MoveEyeTo (aNewEye); |
2617 | theView->View()->ComputeXRBaseCameraFromPosed (theView->View()->PosedXRCamera(), theView->View()->XRSession()->HeadPose()); |
2618 | } |
2619 | } |
2620 | break; |
2621 | } |
2622 | } |
2623 | |
2624 | if (myXRLastTeleportHand != aTeleOld) |
2625 | { |
2626 | if (aTeleOld != Aspect_XRTrackedDeviceRole_Other) |
2627 | { |
2628 | if (const Handle(Aspect_XRAction)& aHaptic = theView->View()->XRSession()->GenericAction (aTeleOld, Aspect_XRGenericAction_OutputHaptic)) |
2629 | { |
2630 | theView->View()->XRSession()->AbortHapticVibrationAction (aHaptic); |
2631 | } |
2632 | } |
2633 | if (myXRLastTeleportHand != Aspect_XRTrackedDeviceRole_Other) |
2634 | { |
2635 | if (const Handle(Aspect_XRAction)& aHaptic = theView->View()->XRSession()->GenericAction (myXRLastTeleportHand, Aspect_XRGenericAction_OutputHaptic)) |
2636 | { |
2637 | theView->View()->XRSession()->TriggerHapticVibrationAction (aHaptic, myXRTeleportHaptic); |
2638 | } |
2639 | } |
2640 | } |
2641 | } |
2642 | |
2643 | // ======================================================================= |
2644 | // function : handleXRPicking |
2645 | // purpose : |
2646 | // ======================================================================= |
2647 | void AIS_ViewController::handleXRPicking (const Handle(AIS_InteractiveContext)& theCtx, |
2648 | const Handle(V3d_View)& theView) |
2649 | { |
2650 | if (!theView->View()->IsActiveXR()) |
2651 | { |
2652 | return; |
2653 | } |
2654 | |
2655 | // handle selection on trigger clicks |
2656 | Aspect_XRTrackedDeviceRole aPickDevOld = myXRLastPickingHand; |
2657 | myXRLastPickingHand = Aspect_XRTrackedDeviceRole_Other; |
2658 | for (int aHand = 0; aHand < 2; ++aHand) |
2659 | { |
2660 | const Aspect_XRTrackedDeviceRole aRole = aHand == 0 ? Aspect_XRTrackedDeviceRole_RightHand : Aspect_XRTrackedDeviceRole_LeftHand; |
2661 | const Handle(Aspect_XRAction)& aTrigClickAct = theView->View()->XRSession()->GenericAction (aRole, Aspect_XRGenericAction_InputTriggerClick); |
2662 | const Handle(Aspect_XRAction)& aTrigPullAct = theView->View()->XRSession()->GenericAction (aRole, Aspect_XRGenericAction_InputTriggerPull); |
2663 | if (aTrigClickAct.IsNull() |
2664 | || aTrigPullAct.IsNull()) |
2665 | { |
2666 | continue; |
2667 | } |
2668 | |
2669 | const Aspect_XRDigitalActionData aTrigClick = theView->View()->XRSession()->GetDigitalActionData (aTrigClickAct); |
2670 | const Aspect_XRAnalogActionData aTrigPos = theView->View()->XRSession()->GetAnalogActionData (aTrigPullAct); |
2671 | if (aTrigPos.IsActive |
2672 | && Abs (aTrigPos.VecXYZ.x()) > 0.1f) |
2673 | { |
2674 | myXRLastPickingHand = aRole; |
2675 | handleXRHighlight (theCtx, theView); |
2676 | if (aTrigClick.IsActive |
2677 | && aTrigClick.IsPressed |
2678 | && aTrigClick.IsChanged) |
2679 | { |
75cf8250 |
2680 | theCtx->SelectDetected(); |
b40cdc2b |
2681 | OnSelectionChanged (theCtx, theView); |
2682 | if (const Handle(Aspect_XRAction)& aHaptic = theView->View()->XRSession()->GenericAction (myXRLastPickingHand, Aspect_XRGenericAction_OutputHaptic)) |
2683 | { |
2684 | theView->View()->XRSession()->TriggerHapticVibrationAction (aHaptic, myXRSelectHaptic); |
2685 | } |
2686 | } |
2687 | break; |
2688 | } |
2689 | } |
2690 | if (myXRLastPickingHand != aPickDevOld) |
2691 | { |
2692 | theCtx->ClearDetected(); |
2693 | } |
2694 | } |
2695 | |
49582f9d |
2696 | // ======================================================================= |
2697 | // function : OnSelectionChanged |
2698 | // purpose : |
2699 | // ======================================================================= |
2700 | void AIS_ViewController::OnSelectionChanged (const Handle(AIS_InteractiveContext)& , |
2701 | const Handle(V3d_View)& ) |
2702 | { |
2703 | // |
2704 | } |
2705 | |
879768fb |
2706 | // ======================================================================= |
2707 | // function : OnSubviewChanged |
2708 | // purpose : |
2709 | // ======================================================================= |
2710 | void AIS_ViewController::OnSubviewChanged (const Handle(AIS_InteractiveContext)& , |
2711 | const Handle(V3d_View)& , |
2712 | const Handle(V3d_View)& ) |
2713 | { |
2714 | // |
2715 | } |
2716 | |
49582f9d |
2717 | // ======================================================================= |
2718 | // function : OnObjectDragged |
2719 | // purpose : |
2720 | // ======================================================================= |
2721 | void AIS_ViewController::OnObjectDragged (const Handle(AIS_InteractiveContext)& theCtx, |
2722 | const Handle(V3d_View)& theView, |
2723 | AIS_DragAction theAction) |
2724 | { |
2725 | switch (theAction) |
2726 | { |
2727 | case AIS_DragAction_Start: |
2728 | { |
2729 | myDragObject.Nullify(); |
630ab538 |
2730 | myDragOwner.Nullify(); |
49582f9d |
2731 | if (!theCtx->HasDetected()) |
2732 | { |
2733 | return; |
2734 | } |
2735 | |
630ab538 |
2736 | const Handle(SelectMgr_EntityOwner)& aDetectedOwner = theCtx->DetectedOwner(); |
2737 | Handle(AIS_InteractiveObject) aDetectedPrs = Handle(AIS_InteractiveObject)::DownCast (aDetectedOwner->Selectable()); |
2738 | |
2739 | if (aDetectedPrs->ProcessDragging (theCtx, theView, aDetectedOwner, myGL.Dragging.PointStart, |
2740 | myGL.Dragging.PointTo, theAction)) |
49582f9d |
2741 | { |
630ab538 |
2742 | myDragObject = aDetectedPrs; |
2743 | myDragOwner = aDetectedOwner; |
49582f9d |
2744 | } |
2745 | return; |
2746 | } |
6ef56849 |
2747 | case AIS_DragAction_Confirmed: |
2748 | { |
2749 | if (myDragObject.IsNull()) |
2750 | { |
2751 | return; |
2752 | } |
2753 | |
2754 | myDragObject->ProcessDragging (theCtx, theView, myDragOwner, myGL.Dragging.PointStart, |
2755 | myGL.Dragging.PointTo, theAction); |
2756 | return; |
2757 | } |
49582f9d |
2758 | case AIS_DragAction_Update: |
2759 | { |
2760 | if (myDragObject.IsNull()) |
2761 | { |
2762 | return; |
2763 | } |
2764 | |
2765 | if (Handle(SelectMgr_EntityOwner) aGlobOwner = myDragObject->GlobalSelOwner()) |
2766 | { |
2767 | theCtx->SetSelectedState (aGlobOwner, true); |
2768 | } |
630ab538 |
2769 | |
2770 | myDragObject->ProcessDragging (theCtx, theView, myDragOwner, myGL.Dragging.PointStart, |
2771 | myGL.Dragging.PointTo, theAction); |
49582f9d |
2772 | theView->Invalidate(); |
2773 | return; |
2774 | } |
2775 | case AIS_DragAction_Abort: |
2776 | { |
2777 | if (myDragObject.IsNull()) |
2778 | { |
2779 | return; |
2780 | } |
2781 | |
2782 | myGL.Dragging.PointTo = myGL.Dragging.PointStart; |
2783 | OnObjectDragged (theCtx, theView, AIS_DragAction_Update); |
2784 | |
630ab538 |
2785 | myDragObject->ProcessDragging (theCtx, theView, myDragOwner, myGL.Dragging.PointStart, |
2786 | myGL.Dragging.PointTo, theAction); |
49582f9d |
2787 | Standard_FALLTHROUGH |
2788 | } |
2789 | case AIS_DragAction_Stop: |
2790 | { |
2791 | if (myDragObject.IsNull()) |
2792 | { |
2793 | return; |
2794 | } |
2795 | |
2796 | if (Handle(SelectMgr_EntityOwner) aGlobOwner = myDragObject->GlobalSelOwner()) |
2797 | { |
2798 | theCtx->SetSelectedState (aGlobOwner, false); |
2799 | } |
2800 | |
630ab538 |
2801 | myDragObject->ProcessDragging (theCtx, theView, myDragOwner, myGL.Dragging.PointStart, |
2802 | myGL.Dragging.PointTo, theAction); |
49582f9d |
2803 | theView->Invalidate(); |
2804 | myDragObject.Nullify(); |
630ab538 |
2805 | myDragOwner.Nullify(); |
49582f9d |
2806 | return; |
2807 | } |
2808 | } |
2809 | } |
2810 | |
2811 | // ======================================================================= |
2812 | // function : contextLazyMoveTo |
2813 | // purpose : |
2814 | // ======================================================================= |
2815 | void AIS_ViewController::contextLazyMoveTo (const Handle(AIS_InteractiveContext)& theCtx, |
2816 | const Handle(V3d_View)& theView, |
2817 | const Graphic3d_Vec2i& thePnt) |
2818 | { |
6d1d35e4 |
2819 | if (myPrevMoveTo == thePnt |
2820 | || myHasHlrOnBeforeRotation) // ignore highlighting in-between rotation of HLR view |
49582f9d |
2821 | { |
2822 | return; |
2823 | } |
2824 | |
2825 | myPrevMoveTo = thePnt; |
2826 | |
2827 | Handle(SelectMgr_EntityOwner) aLastPicked = theCtx->DetectedOwner(); |
cdfcd39b |
2828 | |
2829 | // Picking relies on the camera frustum (including Z-range) - so make temporary AutoZFit() |
2830 | // and then restore previous frustum to avoid immediate layer rendering issues if View has not been invalidated. |
2831 | const Standard_Real aZNear = theView->Camera()->ZNear(), aZFar = theView->Camera()->ZFar(); |
b40cdc2b |
2832 | theView->AutoZFit(); |
49582f9d |
2833 | theCtx->MoveTo (thePnt.x(), thePnt.y(), theView, false); |
cdfcd39b |
2834 | theView->Camera()->SetZRange (aZNear, aZFar); |
2835 | |
49582f9d |
2836 | Handle(SelectMgr_EntityOwner) aNewPicked = theCtx->DetectedOwner(); |
2837 | |
5634c81a |
2838 | if (theView->Viewer()->IsGridActive() |
49582f9d |
2839 | && theView->Viewer()->GridEcho()) |
2840 | { |
2841 | if (aNewPicked.IsNull()) |
2842 | { |
2843 | Graphic3d_Vec3d aPnt3d; |
2844 | theView->ConvertToGrid (thePnt.x(), thePnt.y(), aPnt3d[0], aPnt3d[1], aPnt3d[2]); |
2845 | theView->Viewer()->ShowGridEcho (theView, Graphic3d_Vertex (aPnt3d[0], aPnt3d[1], aPnt3d[2])); |
2846 | theView->InvalidateImmediate(); |
2847 | } |
2848 | else |
2849 | { |
2850 | theView->Viewer()->HideGridEcho (theView); |
2851 | theView->InvalidateImmediate(); |
2852 | } |
2853 | } |
2854 | |
2855 | if (aLastPicked != aNewPicked |
2856 | || (!aNewPicked.IsNull() && aNewPicked->IsForcedHilight())) |
2857 | { |
2858 | // dynamic highlight affects all Views |
2859 | for (V3d_ListOfViewIterator aViewIter (theView->Viewer()->ActiveViewIterator()); aViewIter.More(); aViewIter.Next()) |
2860 | { |
2861 | const Handle(V3d_View)& aView = aViewIter.Value(); |
2862 | aView->InvalidateImmediate(); |
2863 | } |
2864 | } |
2865 | } |
2866 | |
2867 | // ======================================================================= |
2868 | // function : handleSelectionPick |
2869 | // purpose : |
2870 | // ======================================================================= |
2871 | void AIS_ViewController::handleSelectionPick (const Handle(AIS_InteractiveContext)& theCtx, |
2872 | const Handle(V3d_View)& theView) |
2873 | { |
2874 | if (myGL.Selection.Tool == AIS_ViewSelectionTool_Picking |
2875 | && !myGL.Selection.Points.IsEmpty()) |
2876 | { |
2877 | for (NCollection_Sequence<Graphic3d_Vec2i>::Iterator aPntIter (myGL.Selection.Points); aPntIter.More(); aPntIter.Next()) |
2878 | { |
49582f9d |
2879 | const bool hadPrevMoveTo = HasPreviousMoveTo(); |
2880 | contextLazyMoveTo (theCtx, theView, aPntIter.Value()); |
2881 | if (!hadPrevMoveTo) |
2882 | { |
2883 | ResetPreviousMoveTo(); |
2884 | } |
2885 | |
e3d4b879 |
2886 | theCtx->SelectDetected (myGL.Selection.Scheme); |
49582f9d |
2887 | |
2888 | // selection affects all Views |
2889 | theView->Viewer()->Invalidate(); |
2890 | |
2891 | OnSelectionChanged (theCtx, theView); |
2892 | } |
2893 | |
2894 | myGL.Selection.Points.Clear(); |
2895 | } |
2896 | } |
2897 | |
2898 | // ======================================================================= |
2899 | // function : handleSelectionPoly |
2900 | // purpose : |
2901 | // ======================================================================= |
2902 | void AIS_ViewController::handleSelectionPoly (const Handle(AIS_InteractiveContext)& theCtx, |
2903 | const Handle(V3d_View)& theView) |
2904 | { |
2905 | // rubber-band & window polygon selection |
2906 | if (myGL.Selection.Tool == AIS_ViewSelectionTool_RubberBand |
e1c9a103 |
2907 | || myGL.Selection.Tool == AIS_ViewSelectionTool_Polygon |
2908 | || myGL.Selection.Tool == AIS_ViewSelectionTool_ZoomWindow) |
49582f9d |
2909 | { |
2910 | if (!myGL.Selection.Points.IsEmpty()) |
2911 | { |
2912 | myRubberBand->ClearPoints(); |
2913 | myRubberBand->SetToUpdate(); |
2914 | |
e1c9a103 |
2915 | const bool anIsRubber = myGL.Selection.Tool == AIS_ViewSelectionTool_RubberBand |
2916 | || myGL.Selection.Tool == AIS_ViewSelectionTool_ZoomWindow; |
49582f9d |
2917 | if (anIsRubber) |
2918 | { |
2919 | myRubberBand->SetRectangle (myGL.Selection.Points.First().x(), -myGL.Selection.Points.First().y(), |
2920 | myGL.Selection.Points.Last().x(), -myGL.Selection.Points.Last().y()); |
2921 | } |
2922 | else |
2923 | { |
2924 | Graphic3d_Vec2i aPrev (IntegerLast(), IntegerLast()); |
2925 | for (NCollection_Sequence<Graphic3d_Vec2i>::Iterator aSelIter (myGL.Selection.Points); aSelIter.More(); aSelIter.Next()) |
2926 | { |
2927 | Graphic3d_Vec2i aPntNew = Graphic3d_Vec2i (aSelIter.Value().x(), -aSelIter.Value().y()); |
2928 | if (aPntNew != aPrev) |
2929 | { |
2930 | aPrev = aPntNew; |
2931 | myRubberBand->AddPoint (Graphic3d_Vec2i (aSelIter.Value().x(), -aSelIter.Value().y())); |
2932 | } |
2933 | } |
2934 | } |
2935 | |
2936 | myRubberBand->SetPolygonClosed (anIsRubber); |
2937 | try |
2938 | { |
2939 | theCtx->Display (myRubberBand, 0, -1, false, AIS_DS_Displayed); |
2940 | } |
2941 | catch (const Standard_Failure& theEx) |
2942 | { |
a87b1b37 |
2943 | Message::SendWarning (TCollection_AsciiString ("Internal error while displaying rubber-band: ") |
2944 | + theEx.DynamicType()->Name() + ", " + theEx.GetMessageString()); |
49582f9d |
2945 | myRubberBand->ClearPoints(); |
2946 | } |
2947 | if (!theView->Viewer()->ZLayerSettings (myRubberBand->ZLayer()).IsImmediate()) |
2948 | { |
2949 | theView->Invalidate(); |
2950 | } |
2951 | else |
2952 | { |
2953 | theView->InvalidateImmediate(); |
2954 | } |
2955 | } |
2956 | else if (!myRubberBand.IsNull() |
2957 | && myRubberBand->HasInteractiveContext()) |
2958 | { |
2959 | theCtx->Remove (myRubberBand, false); |
2960 | myRubberBand->ClearPoints(); |
2961 | } |
2962 | } |
2963 | |
2964 | if (myGL.Selection.ToApplyTool) |
2965 | { |
2966 | myGL.Selection.ToApplyTool = false; |
2967 | if (theCtx->IsDisplayed (myRubberBand)) |
2968 | { |
2969 | theCtx->Remove (myRubberBand, false); |
2970 | { |
2971 | const NCollection_Sequence<Graphic3d_Vec2i>& aPoints = myRubberBand->Points(); |
2972 | if (aPoints.Size() == 4 |
2973 | && aPoints.Value (1).x() == aPoints.Value (2).x() |
2974 | && aPoints.Value (3).x() == aPoints.Value (4).x() |
2975 | && aPoints.Value (1).y() == aPoints.Value (4).y() |
2976 | && aPoints.Value (2).y() == aPoints.Value (3).y()) |
2977 | { |
2978 | const Graphic3d_Vec2i aPnt1 (aPoints.Value (1).x(), -aPoints.Value (1).y()); |
2979 | const Graphic3d_Vec2i aPnt2 (aPoints.Value (3).x(), -aPoints.Value (3).y()); |
e1c9a103 |
2980 | if (myGL.Selection.Tool == AIS_ViewSelectionTool_ZoomWindow) |
49582f9d |
2981 | { |
e1c9a103 |
2982 | theView->WindowFitAll (aPnt1.x(), aPnt1.y(), aPnt2.x(), aPnt2.y()); |
2983 | theView->Invalidate(); |
49582f9d |
2984 | } |
2985 | else |
2986 | { |
e1c9a103 |
2987 | theCtx->MainSelector()->AllowOverlapDetection (aPnt1.y() != Min (aPnt1.y(), aPnt2.y())); |
75cf8250 |
2988 | theCtx->SelectRectangle (Graphic3d_Vec2i (Min (aPnt1.x(), aPnt2.x()), Min (aPnt1.y(), aPnt2.y())), |
2989 | Graphic3d_Vec2i (Max (aPnt1.x(), aPnt2.x()), Max (aPnt1.y(), aPnt2.y())), |
e3d4b879 |
2990 | theView, |
2991 | myGL.Selection.Scheme); |
e1c9a103 |
2992 | theCtx->MainSelector()->AllowOverlapDetection (false); |
49582f9d |
2993 | } |
49582f9d |
2994 | } |
2995 | else if (aPoints.Length() >= 3) |
2996 | { |
2997 | TColgp_Array1OfPnt2d aPolyline (1, aPoints.Length()); |
2998 | TColgp_Array1OfPnt2d::Iterator aPolyIter (aPolyline); |
2999 | for (NCollection_Sequence<Graphic3d_Vec2i>::Iterator aSelIter (aPoints); |
3000 | aSelIter.More(); aSelIter.Next(), aPolyIter.Next()) |
3001 | { |
3002 | const Graphic3d_Vec2i& aNewPnt = aSelIter.Value(); |
3003 | aPolyIter.ChangeValue() = gp_Pnt2d (aNewPnt.x(), -aNewPnt.y()); |
3004 | } |
3005 | |
e3d4b879 |
3006 | theCtx->SelectPolygon (aPolyline, theView, myGL.Selection.Scheme); |
a24a7821 |
3007 | theCtx->MainSelector()->AllowOverlapDetection (false); |
49582f9d |
3008 | } |
3009 | } |
3010 | |
49582f9d |
3011 | myRubberBand->ClearPoints(); |
e1c9a103 |
3012 | if (myGL.Selection.Tool != AIS_ViewSelectionTool_ZoomWindow) |
3013 | { |
3014 | // selection affects all Views |
3015 | theView->Viewer()->Invalidate(); |
3016 | OnSelectionChanged (theCtx, theView); |
3017 | } |
49582f9d |
3018 | } |
3019 | } |
3020 | } |
3021 | |
3022 | // ======================================================================= |
3023 | // function : handleDynamicHighlight |
3024 | // purpose : |
3025 | // ======================================================================= |
3026 | void AIS_ViewController::handleDynamicHighlight (const Handle(AIS_InteractiveContext)& theCtx, |
3027 | const Handle(V3d_View)& theView) |
3028 | { |
3029 | if ((myGL.MoveTo.ToHilight || myGL.Dragging.ToStart) |
3030 | && myNavigationMode != AIS_NavigationMode_FirstPersonWalk) |
3031 | { |
3032 | const Graphic3d_Vec2i& aMoveToPnt = myGL.MoveTo.ToHilight ? myGL.MoveTo.Point : myGL.Dragging.PointStart; |
3033 | if (myGL.Dragging.ToStart && (!myGL.MoveTo.ToHilight || !myToAllowHighlight) |
3034 | && !HasPreviousMoveTo()) |
3035 | { |
3036 | contextLazyMoveTo (theCtx, theView, aMoveToPnt); |
3037 | ResetPreviousMoveTo(); |
3038 | OnObjectDragged (theCtx, theView, AIS_DragAction_Start); |
3039 | theCtx->ClearDetected(); |
3040 | } |
3041 | else if (myToAllowHighlight) |
3042 | { |
3043 | if (myPrevMoveTo != aMoveToPnt |
b40cdc2b |
3044 | || (!theView->View()->IsActiveXR() |
3045 | && (myGL.OrbitRotation.ToRotate |
3046 | || myGL.ViewRotation.ToRotate |
3047 | || theView->IsInvalidated()))) |
49582f9d |
3048 | { |
3049 | ResetPreviousMoveTo(); |
3050 | contextLazyMoveTo (theCtx, theView, aMoveToPnt); |
3051 | } |
3052 | if (myGL.Dragging.ToStart) |
3053 | { |
3054 | OnObjectDragged (theCtx, theView, AIS_DragAction_Start); |
3055 | } |
3056 | } |
3057 | |
3058 | myGL.MoveTo.ToHilight = false; |
3059 | } |
3060 | |
3061 | if (!myDragObject.IsNull()) |
3062 | { |
3063 | if (myGL.Dragging.ToAbort) |
3064 | { |
3065 | OnObjectDragged (theCtx, theView, AIS_DragAction_Abort); |
3066 | myGL.OrbitRotation.ToRotate = false; |
3067 | myGL.ViewRotation .ToRotate = false; |
3068 | } |
3069 | else if (myGL.Dragging.ToStop) |
3070 | { |
3071 | OnObjectDragged (theCtx, theView, AIS_DragAction_Stop); |
3072 | myGL.OrbitRotation.ToRotate = false; |
3073 | myGL.ViewRotation .ToRotate = false; |
3074 | } |
e3fd3d83 |
3075 | else if (myGL.Dragging.ToMove) |
49582f9d |
3076 | { |
6ef56849 |
3077 | if (myGL.Dragging.ToConfirm) |
3078 | { |
3079 | OnObjectDragged (theCtx, theView, AIS_DragAction_Confirmed); |
3080 | } |
49582f9d |
3081 | OnObjectDragged (theCtx, theView, AIS_DragAction_Update); |
3082 | myGL.OrbitRotation.ToRotate = false; |
3083 | myGL.ViewRotation .ToRotate = false; |
34213231 |
3084 | myGL.Panning .ToPan = false; |
3085 | myGL.ZoomActions.Clear(); |
49582f9d |
3086 | } |
3087 | } |
3088 | } |
3089 | |
3090 | // ======================================================================= |
3091 | // function : handleMoveTo |
3092 | // purpose : |
3093 | // ======================================================================= |
3094 | void AIS_ViewController::handleMoveTo (const Handle(AIS_InteractiveContext)& theCtx, |
3095 | const Handle(V3d_View)& theView) |
3096 | { |
3097 | handleSelectionPick (theCtx, theView); |
3098 | handleDynamicHighlight(theCtx, theView); |
3099 | handleSelectionPoly (theCtx, theView); |
3100 | } |
3101 | |
3102 | // ======================================================================= |
3103 | // function : handleViewRedraw |
3104 | // purpose : |
3105 | // ======================================================================= |
3106 | void AIS_ViewController::handleViewRedraw (const Handle(AIS_InteractiveContext)& , |
3107 | const Handle(V3d_View)& theView) |
3108 | { |
879768fb |
3109 | Handle(V3d_View) aParentView = theView->IsSubview() ? theView->ParentView() : theView; |
3110 | |
2108d9a2 |
3111 | // manage animation state |
3112 | if (!myViewAnimation.IsNull() |
3113 | && !myViewAnimation->IsStopped()) |
3114 | { |
3115 | myViewAnimation->UpdateTimer(); |
3116 | ResetPreviousMoveTo(); |
3117 | setAskNextFrame(); |
3118 | } |
3119 | |
8f709595 |
3120 | if (!myObjAnimation.IsNull() |
3121 | && !myObjAnimation->IsStopped()) |
3122 | { |
3123 | myObjAnimation->UpdateTimer(); |
3124 | ResetPreviousMoveTo(); |
3125 | setAskNextFrame(); |
3126 | } |
3127 | |
f227f3dc |
3128 | if (myIsContinuousRedraw) |
3129 | { |
3130 | myToAskNextFrame = true; |
3131 | } |
b40cdc2b |
3132 | if (theView->View()->IsActiveXR()) |
3133 | { |
3134 | // VR requires continuous rendering |
3135 | myToAskNextFrame = true; |
3136 | } |
3137 | |
879768fb |
3138 | for (int aSubViewPass = 0; aSubViewPass < 2; ++aSubViewPass) |
49582f9d |
3139 | { |
879768fb |
3140 | const bool isSubViewPass = (aSubViewPass == 0); |
3141 | for (V3d_ListOfViewIterator aViewIter (theView->Viewer()->ActiveViewIterator()); aViewIter.More(); aViewIter.Next()) |
49582f9d |
3142 | { |
879768fb |
3143 | const Handle(V3d_View)& aView = aViewIter.Value(); |
3144 | if (isSubViewPass |
3145 | && !aView->IsSubview()) |
49582f9d |
3146 | { |
879768fb |
3147 | for (const Handle(V3d_View)& aSubviewIter : aView->Subviews()) |
3148 | { |
3149 | if (aSubviewIter->Viewer() != theView->Viewer()) |
3150 | { |
3151 | if (aSubviewIter->IsInvalidated()) |
3152 | { |
3153 | if (aSubviewIter->ComputedMode()) |
3154 | { |
3155 | aSubviewIter->Update(); |
3156 | } |
3157 | else |
3158 | { |
3159 | aSubviewIter->Redraw(); |
3160 | } |
3161 | } |
3162 | else if (aSubviewIter->IsInvalidatedImmediate()) |
3163 | { |
3164 | aSubviewIter->RedrawImmediate(); |
3165 | } |
3166 | } |
3167 | } |
3168 | continue; |
49582f9d |
3169 | } |
879768fb |
3170 | else if (!isSubViewPass |
3171 | && aView->IsSubview()) |
49582f9d |
3172 | { |
879768fb |
3173 | continue; |
3174 | } |
3175 | |
3176 | if (aView->IsInvalidated() |
3177 | || (myToAskNextFrame && aView == theView)) |
3178 | { |
3179 | if (aView->ComputedMode()) |
3180 | { |
3181 | aView->Update(); |
3182 | } |
3183 | else |
3184 | { |
3185 | aView->Redraw(); |
3186 | } |
3187 | |
3188 | if (aView->IsSubview()) |
3189 | { |
3190 | aView->ParentView()->InvalidateImmediate(); |
3191 | } |
3192 | } |
3193 | else if (aView->IsInvalidatedImmediate()) |
3194 | { |
3195 | if (aView->IsSubview()) |
3196 | { |
3197 | aView->ParentView()->InvalidateImmediate(); |
3198 | } |
3199 | |
3200 | aView->RedrawImmediate(); |
49582f9d |
3201 | } |
3202 | } |
879768fb |
3203 | } |
3204 | if (theView->IsSubview() |
3205 | && theView->Viewer() != aParentView->Viewer()) |
3206 | { |
3207 | aParentView->RedrawImmediate(); |
49582f9d |
3208 | } |
3209 | |
3210 | if (myToAskNextFrame) |
3211 | { |
3212 | // ask more frames |
879768fb |
3213 | aParentView->Window()->InvalidateContent (Handle(Aspect_DisplayConnection)()); |
49582f9d |
3214 | } |
3215 | } |
3216 | |
b40cdc2b |
3217 | // ======================================================================= |
3218 | // function : handleXRMoveTo |
3219 | // purpose : |
3220 | // ======================================================================= |
3221 | Standard_Integer AIS_ViewController::handleXRMoveTo (const Handle(AIS_InteractiveContext)& theCtx, |
3222 | const Handle(V3d_View)& theView, |
3223 | const gp_Trsf& thePose, |
3224 | const Standard_Boolean theToHighlight) |
3225 | { |
3226 | //ResetPreviousMoveTo(); |
807340d9 |
3227 | const gp_Ax1 aViewAxis = theView->View()->ViewAxisInWorld (thePose); |
b40cdc2b |
3228 | Standard_Integer aPickResult = 0; |
b40cdc2b |
3229 | if (theToHighlight) |
3230 | { |
807340d9 |
3231 | theCtx->MoveTo (aViewAxis, theView, false); |
b40cdc2b |
3232 | if (!theCtx->DetectedOwner().IsNull()) |
3233 | { |
807340d9 |
3234 | aPickResult = 1; |
b40cdc2b |
3235 | } |
3236 | } |
3237 | else |
3238 | { |
807340d9 |
3239 | theCtx->MainSelector()->Pick (aViewAxis, theView); |
3240 | if (theCtx->MainSelector()->NbPicked() >= 1) |
b40cdc2b |
3241 | { |
807340d9 |
3242 | aPickResult = 1; |
b40cdc2b |
3243 | } |
3244 | } |
807340d9 |
3245 | |
b40cdc2b |
3246 | return aPickResult; |
3247 | } |
3248 | |
3249 | // ======================================================================= |
3250 | // function : handleXRHighlight |
3251 | // purpose : |
3252 | // ======================================================================= |
3253 | void AIS_ViewController::handleXRHighlight (const Handle(AIS_InteractiveContext)& theCtx, |
3254 | const Handle(V3d_View)& theView) |
3255 | { |
3256 | if (myXRLastPickingHand != Aspect_XRTrackedDeviceRole_LeftHand |
3257 | && myXRLastPickingHand != Aspect_XRTrackedDeviceRole_RightHand) |
3258 | { |
3259 | return; |
3260 | } |
3261 | |
3262 | const Standard_Integer aDeviceId = theView->View()->XRSession()->NamedTrackedDevice (myXRLastPickingHand); |
3263 | if (aDeviceId == -1) |
3264 | { |
3265 | return; |
3266 | } |
3267 | |
3268 | const Aspect_TrackedDevicePose& aPose = theView->View()->XRSession()->TrackedPoses()[aDeviceId]; |
3269 | if (!aPose.IsValidPose) |
3270 | { |
3271 | return; |
3272 | } |
3273 | |
3274 | Handle(SelectMgr_EntityOwner) aDetOld = theCtx->DetectedOwner(); |
3275 | handleXRMoveTo (theCtx, theView, aPose.Orientation, true); |
3276 | if (!theCtx->DetectedOwner().IsNull() |
3277 | && theCtx->DetectedOwner() != aDetOld) |
3278 | { |
3279 | if (const Handle(Aspect_XRAction)& aHaptic = theView->View()->XRSession()->GenericAction (myXRLastPickingHand, Aspect_XRGenericAction_OutputHaptic)) |
3280 | { |
3281 | theView->View()->XRSession()->TriggerHapticVibrationAction (aHaptic, myXRPickingHaptic); |
3282 | } |
3283 | } |
3284 | |
3285 | Standard_Real& aPickDepth = myXRLastPickingHand == Aspect_XRTrackedDeviceRole_LeftHand ? myXRLastPickDepthLeft : myXRLastPickDepthRight; |
3286 | aPickDepth = Precision::Infinite(); |
3287 | if (theCtx->MainSelector()->NbPicked() > 0) |
3288 | { |
3289 | const gp_Trsf aHandBase = theView->View()->PoseXRToWorld (aPose.Orientation); |
3290 | const SelectMgr_SortCriterion& aPicked = theCtx->MainSelector()->PickedData (1); |
3291 | aPickDepth = aPicked.Point.Distance (aHandBase.TranslationPart()); |
3292 | } |
3293 | } |
3294 | |
3295 | // ======================================================================= |
3296 | // function : handleXRPresentations |
3297 | // purpose : |
3298 | // ======================================================================= |
3299 | void AIS_ViewController::handleXRPresentations (const Handle(AIS_InteractiveContext)& theCtx, |
3300 | const Handle(V3d_View)& theView) |
3301 | { |
3302 | if (!theView->View()->IsActiveXR() |
3303 | || (!myToDisplayXRAuxDevices |
3304 | && !myToDisplayXRHands)) |
3305 | { |
3306 | for (NCollection_Array1<Handle(AIS_XRTrackedDevice)>::Iterator aPrsIter (myXRPrsDevices); aPrsIter.More(); aPrsIter.Next()) |
3307 | { |
3308 | if (!aPrsIter.Value().IsNull() |
3309 | && aPrsIter.Value()->HasInteractiveContext()) |
3310 | { |
3311 | theCtx->Remove (aPrsIter.Value(), false); |
3312 | } |
3313 | aPrsIter.ChangeValue().Nullify(); |
3314 | } |
3315 | return; |
3316 | } |
3317 | |
3318 | if (myXRPrsDevices.Length() != theView->View()->XRSession()->TrackedPoses().Length()) |
3319 | { |
3320 | for (NCollection_Array1<Handle(AIS_XRTrackedDevice)>::Iterator aPrsIter (myXRPrsDevices); aPrsIter.More(); aPrsIter.Next()) |
3321 | { |
3322 | if (!aPrsIter.Value().IsNull()) |
3323 | { |
3324 | theCtx->Remove (aPrsIter.Value(), false); |
3325 | } |
3326 | } |
3327 | myXRPrsDevices.Resize (theView->View()->XRSession()->TrackedPoses().Lower(), theView->View()->XRSession()->TrackedPoses().Upper(), false); |
3328 | } |
3329 | |
3330 | const Standard_Integer aHeadDevice = theView->View()->XRSession()->NamedTrackedDevice (Aspect_XRTrackedDeviceRole_Head); |
3331 | const Standard_Integer aLeftDevice = theView->View()->XRSession()->NamedTrackedDevice (Aspect_XRTrackedDeviceRole_LeftHand); |
3332 | const Standard_Integer aRightDevice = theView->View()->XRSession()->NamedTrackedDevice (Aspect_XRTrackedDeviceRole_RightHand); |
3333 | for (Standard_Integer aDeviceIter = theView->View()->XRSession()->TrackedPoses().Lower(); aDeviceIter <= theView->View()->XRSession()->TrackedPoses().Upper(); ++aDeviceIter) |
3334 | { |
3335 | const Aspect_TrackedDevicePose& aPose = theView->View()->XRSession()->TrackedPoses()[aDeviceIter]; |
3336 | Handle(AIS_XRTrackedDevice)& aPosePrs = myXRPrsDevices[aDeviceIter]; |
3337 | if (!aPose.IsValidPose) |
3338 | { |
3339 | continue; |
3340 | } |
3341 | |
3342 | const bool isHand = aDeviceIter == aLeftDevice |
3343 | || aDeviceIter == aRightDevice; |
3344 | if ((!myToDisplayXRHands && isHand) |
3345 | || (!myToDisplayXRAuxDevices && !isHand)) |
3346 | { |
3347 | if (!aPosePrs.IsNull() |
3348 | && aPosePrs->HasInteractiveContext()) |
3349 | { |
3350 | theCtx->Remove (aPosePrs, false); |
3351 | } |
3352 | continue; |
3353 | } |
3354 | |
3355 | Aspect_XRTrackedDeviceRole aRole = Aspect_XRTrackedDeviceRole_Other; |
3356 | if (aDeviceIter == aLeftDevice) |
3357 | { |
3358 | aRole = Aspect_XRTrackedDeviceRole_LeftHand; |
3359 | } |
3360 | else if (aDeviceIter == aRightDevice) |
3361 | { |
3362 | aRole = Aspect_XRTrackedDeviceRole_RightHand; |
3363 | } |
3364 | |
3365 | if (!aPosePrs.IsNull() |
3366 | && aPosePrs->UnitFactor() != (float )theView->View()->UnitFactor()) |
3367 | { |
3368 | theCtx->Remove (aPosePrs, false); |
3369 | aPosePrs.Nullify(); |
3370 | } |
3371 | |
3372 | if (aPosePrs.IsNull()) |
3373 | { |
3374 | Handle(Image_Texture) aTexture; |
3375 | Handle(Graphic3d_ArrayOfTriangles) aTris; |
3376 | if (aDeviceIter != aHeadDevice) |
3377 | { |
3378 | aTris = theView->View()->XRSession()->LoadRenderModel (aDeviceIter, aTexture); |
3379 | } |
3380 | if (!aTris.IsNull()) |
3381 | { |
3382 | aPosePrs = new AIS_XRTrackedDevice (aTris, aTexture); |
3383 | } |
3384 | else |
3385 | { |
3386 | aPosePrs = new AIS_XRTrackedDevice(); |
3387 | } |
3388 | aPosePrs->SetUnitFactor ((float )theView->View()->UnitFactor()); |
3389 | aPosePrs->SetMutable (true); |
3390 | aPosePrs->SetInfiniteState (true); |
3391 | } |
3392 | aPosePrs->SetRole (aRole); |
3393 | |
3394 | if (!aPosePrs->HasInteractiveContext()) |
3395 | { |
3396 | theCtx->Display (aPosePrs, 0, -1, false); |
3397 | } |
3398 | |
3399 | gp_Trsf aPoseLocal = aPose.Orientation; |
3400 | if (aDeviceIter == aHeadDevice) |
3401 | { |
3402 | // show headset position on floor level |
3403 | aPoseLocal.SetTranslationPart (gp_Vec (aPoseLocal.TranslationPart().X(), 0.0, aPoseLocal.TranslationPart().Z())); |
3404 | } |
3405 | const gp_Trsf aPoseWorld = theView->View()->PoseXRToWorld (aPoseLocal); |
3406 | theCtx->SetLocation (aPosePrs, aPoseWorld); |
3407 | |
3408 | Standard_Real aLaserLen = 0.0; |
3409 | if (isHand |
3410 | && aPosePrs->Role() == myXRLastPickingHand) |
3411 | { |
3412 | aLaserLen = myXRLastPickingHand == Aspect_XRTrackedDeviceRole_LeftHand ? myXRLastPickDepthLeft : myXRLastPickDepthRight; |
3413 | if (Precision::IsInfinite (aLaserLen)) |
3414 | { |
3415 | const Bnd_Box aViewBox = theView->View()->MinMaxValues (true); |
3416 | if (!aViewBox.IsVoid()) |
3417 | { |
3418 | aLaserLen = Sqrt (aViewBox.SquareExtent()); |
3419 | } |
3420 | else |
3421 | { |
3422 | aLaserLen = 100.0; |
3423 | } |
3424 | } |
3425 | aPosePrs->SetLaserColor (myXRLaserPickColor); |
3426 | } |
3427 | else if (isHand |
3428 | && aPosePrs->Role() == myXRLastTeleportHand) |
3429 | { |
3430 | aLaserLen = myXRLastTeleportHand == Aspect_XRTrackedDeviceRole_LeftHand ? myXRLastPickDepthLeft : myXRLastPickDepthRight; |
3431 | if (Precision::IsInfinite (aLaserLen)) |
3432 | { |
3433 | const Bnd_Box aViewBox = theView->View()->MinMaxValues (true); |
3434 | if (!aViewBox.IsVoid()) |
3435 | { |
3436 | aLaserLen = Sqrt (aViewBox.SquareExtent()); |
3437 | } |
3438 | else |
3439 | { |
3440 | aLaserLen = 100.0; |
3441 | } |
3442 | } |
3443 | aPosePrs->SetLaserColor (myXRLaserTeleColor); |
3444 | } |
3445 | aPosePrs->SetLaserLength ((float )aLaserLen); |
3446 | } |
3447 | } |
3448 | |
49582f9d |
3449 | // ======================================================================= |
3450 | // function : HandleViewEvents |
3451 | // purpose : |
3452 | // ======================================================================= |
3453 | void AIS_ViewController::HandleViewEvents (const Handle(AIS_InteractiveContext)& theCtx, |
3454 | const Handle(V3d_View)& theView) |
3455 | { |
b40cdc2b |
3456 | const bool wasImmediateUpdate = theView->SetImmediateUpdate (false); |
49582f9d |
3457 | |
879768fb |
3458 | Handle(V3d_View) aPickedView; |
3459 | if (theView->IsSubview() |
3460 | || !theView->Subviews().IsEmpty()) |
3461 | { |
3462 | // activate another subview on mouse click |
3463 | bool toPickSubview = false; |
3464 | Graphic3d_Vec2i aClickPoint; |
3465 | if (myGL.Selection.Tool == AIS_ViewSelectionTool_Picking |
3466 | && !myGL.Selection.Points.IsEmpty()) |
3467 | { |
3468 | aClickPoint = myGL.Selection.Points.Last(); |
3469 | toPickSubview = true; |
3470 | } |
3471 | else if (!myGL.ZoomActions.IsEmpty()) |
3472 | { |
3473 | //aClickPoint = myGL.ZoomActions.Last().Point; |
3474 | //toPickSubview = true; |
3475 | } |
3476 | |
3477 | if (toPickSubview) |
3478 | { |
3479 | if (theView->IsSubview()) |
3480 | { |
3481 | aClickPoint += theView->View()->SubviewTopLeft(); |
3482 | } |
3483 | Handle(V3d_View) aParent = !theView->IsSubview() ? theView : theView->ParentView(); |
3484 | aPickedView = aParent->PickSubview (aClickPoint); |
3485 | } |
3486 | } |
3487 | |
d6fbb2ab |
3488 | handleViewOrientationKeys (theCtx, theView); |
d22962e4 |
3489 | const AIS_WalkDelta aWalk = handleNavigationKeys (theCtx, theView); |
b40cdc2b |
3490 | handleXRInput (theCtx, theView, aWalk); |
3491 | if (theView->View()->IsActiveXR()) |
3492 | { |
3493 | theView->View()->SetupXRPosedCamera(); |
3494 | } |
a7400019 |
3495 | handleMoveTo (theCtx, theView); |
49582f9d |
3496 | handleCameraActions (theCtx, theView, aWalk); |
b40cdc2b |
3497 | theView->View()->SynchronizeXRPosedToBaseCamera(); // handleCameraActions() may modify posed camera position - copy this modifications also to the base camera |
3498 | handleXRPresentations (theCtx, theView); |
3499 | |
49582f9d |
3500 | handleViewRedraw (theCtx, theView); |
b40cdc2b |
3501 | theView->View()->UnsetXRPosedCamera(); |
3502 | |
3503 | theView->SetImmediateUpdate (wasImmediateUpdate); |
49582f9d |
3504 | |
879768fb |
3505 | if (!aPickedView.IsNull() |
3506 | && aPickedView != theView) |
3507 | { |
3508 | OnSubviewChanged (theCtx, theView, aPickedView); |
3509 | } |
3510 | |
49582f9d |
3511 | // make sure to not process the same events twice |
3512 | myGL.Reset(); |
3513 | myToAskNextFrame = false; |
3514 | } |