913a4c4a |
1 | // Created on: 2011-10-20 |
2 | // Created by: Roman KOZLOV |
3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <IVtkOCC_ViewerSelector.hxx> |
17 | #include <Select3D_SensitiveBox.hxx> |
18 | #include <TColgp_Array1OfPnt2d.hxx> |
913a4c4a |
19 | #include <Graphic3d_Camera.hxx> |
20 | |
913a4c4a |
21 | |
92efcf78 |
22 | IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector) |
23 | |
913a4c4a |
24 | //============================================================================ |
25 | // Method: Constructor |
26 | // Purpose: |
27 | //============================================================================ |
28 | IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector() |
29 | : SelectMgr_ViewerSelector(), |
30 | myPixTol(2), |
f751596e |
31 | myToUpdateTol(Standard_True) {} |
913a4c4a |
32 | |
33 | //============================================================================ |
34 | // Method: Pick |
35 | // Purpose: Implements point picking |
36 | //============================================================================ |
37 | void IVtkOCC_ViewerSelector::Pick (const Standard_Integer theXPix, |
38 | const Standard_Integer theYPix, |
39 | const IVtk_IView::Handle& theView) |
40 | { |
f751596e |
41 | if (myToUpdateTol) |
42 | { |
43 | // Compute and set a sensitivity tolerance according to the renderer (viewport). |
44 | // TODO: Think if this works well in perspective view...'cause result depends |
45 | // on position on the screen, but we always use the point close to the |
46 | // screen's origin... |
47 | mySelectingVolumeMgr.SetPixelTolerance (myPixTol); |
48 | |
49 | myToUpdateTol = Standard_False; |
50 | } |
51 | |
52 | Standard_Integer aWidth = 0, aHeight = 0; |
53 | Graphic3d_Mat4d aProj, anOrient; |
54 | Standard_Boolean isOrthographic = Standard_False; |
55 | Standard_Real aX = RealLast(), aY = RealLast(); |
56 | Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast(); |
57 | |
58 | mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Point); |
59 | theView->GetCamera (aProj, anOrient, isOrthographic); |
60 | mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic); |
61 | |
62 | theView->GetWindowSize (aWidth, aHeight); |
63 | mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight); |
64 | |
65 | theView->GetViewport (aX, aY, aVpWidth, aVpHeight); |
66 | mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight); |
67 | |
68 | gp_Pnt2d aMousePos (static_cast<Standard_Real> (theXPix), |
69 | static_cast<Standard_Real> (theYPix)); |
70 | mySelectingVolumeMgr.BuildSelectingVolume (aMousePos); |
71 | |
72 | TraverseSensitives(); |
913a4c4a |
73 | } |
74 | |
75 | //============================================================================ |
76 | // Method: Pick |
77 | // Purpose: Picking by rectangle |
78 | //============================================================================ |
79 | void IVtkOCC_ViewerSelector::Pick (const Standard_Integer theXMin, |
80 | const Standard_Integer theYMin, |
81 | const Standard_Integer theXMax, |
82 | const Standard_Integer theYMax, |
83 | const IVtk_IView::Handle& theView) |
84 | { |
85 | if (myToUpdateTol) |
86 | { |
87 | // Compute and set a sensitivity tolerance according to the renderer (viewport). |
88 | // TODO: Think if this works well in perspective view...'cause result depends |
89 | // on position on the screen, but we always use the point close to the |
90 | // screen's origin... |
f751596e |
91 | mySelectingVolumeMgr.SetPixelTolerance (myPixTol); |
92 | |
913a4c4a |
93 | myToUpdateTol = Standard_False; |
94 | } |
913a4c4a |
95 | |
f751596e |
96 | Standard_Integer aWidth = 0, aHeight = 0; |
97 | Graphic3d_Mat4d aProj, anOrient; |
98 | Standard_Boolean isOrthographic = Standard_False; |
99 | Standard_Real aX = RealLast(), aY = RealLast(); |
100 | Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast(); |
101 | |
102 | mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Box); |
103 | theView->GetCamera (aProj, anOrient, isOrthographic); |
104 | mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic); |
913a4c4a |
105 | |
f751596e |
106 | theView->GetWindowSize (aWidth, aHeight); |
107 | mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight); |
913a4c4a |
108 | |
f751596e |
109 | theView->GetViewport (aX, aY, aVpWidth, aVpHeight); |
110 | mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight); |
913a4c4a |
111 | |
f751596e |
112 | gp_Pnt2d aMinMousePos (static_cast<Standard_Real> (theXMin), |
113 | static_cast<Standard_Real> (theYMin)); |
114 | gp_Pnt2d aMaxMousePos (static_cast<Standard_Real> (theXMax), |
115 | static_cast<Standard_Real> (theYMax)); |
116 | |
117 | mySelectingVolumeMgr.BuildSelectingVolume (aMinMousePos, |
118 | aMaxMousePos); |
119 | |
120 | TraverseSensitives(); |
913a4c4a |
121 | } |
122 | |
123 | //============================================================================ |
124 | // Method: Pick |
125 | // Purpose: |
126 | //============================================================================ |
127 | void IVtkOCC_ViewerSelector::Pick (double** thePoly, |
128 | const int theNbPoints, |
129 | const IVtk_IView::Handle& theView) |
130 | { |
131 | TColgp_Array1OfPnt2d aPolyline (1, theNbPoints); |
132 | |
133 | if (myToUpdateTol) |
134 | { |
135 | // Compute and set a sensitivity tolerance according to the renderer (viewport). |
136 | // TODO: Think if this works well in perspective view...'cause result depends |
137 | // on position on the screen, but we always use the point close to the |
138 | // screen's origin... |
f751596e |
139 | mySelectingVolumeMgr.SetPixelTolerance (myPixTol); |
140 | |
913a4c4a |
141 | myToUpdateTol = Standard_False; |
142 | } |
143 | |
913a4c4a |
144 | // Build TColgp_Array1OfPnt2d from input array of doubles |
145 | gp_XYZ aWorldPnt; |
146 | |
147 | for (Standard_Integer anIt = 0; anIt < theNbPoints; anIt++) |
148 | { |
149 | gp_XY aDispPnt = thePoly[anIt][2] != 0 ? gp_XY (thePoly[anIt][0] / thePoly[anIt][2], thePoly[anIt][1] / thePoly[anIt][2]) |
150 | : gp_XY (thePoly[anIt][0], thePoly[anIt][1]); |
f751596e |
151 | aPolyline.SetValue (anIt + 1, aDispPnt); |
913a4c4a |
152 | } |
153 | |
f751596e |
154 | Standard_Integer aWidth = 0, aHeight = 0; |
155 | Graphic3d_Mat4d aProj, anOrient; |
156 | Standard_Boolean isOrthographic = Standard_False; |
157 | Standard_Real aX = RealLast(), aY = RealLast(); |
158 | Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast(); |
913a4c4a |
159 | |
f751596e |
160 | mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Polyline); |
161 | theView->GetCamera (aProj, anOrient, isOrthographic); |
162 | mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic); |
913a4c4a |
163 | |
f751596e |
164 | theView->GetWindowSize (aWidth, aHeight); |
165 | mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight); |
913a4c4a |
166 | |
f751596e |
167 | theView->GetViewport (aX, aY, aVpWidth, aVpHeight); |
168 | mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight); |
913a4c4a |
169 | |
f751596e |
170 | mySelectingVolumeMgr.BuildSelectingVolume (aPolyline); |
913a4c4a |
171 | |
f751596e |
172 | TraverseSensitives(); |
913a4c4a |
173 | } |
174 | |
175 | //============================================================================ |
176 | // Method: Activate |
177 | // Purpose: Activates the given selection |
178 | //============================================================================ |
f751596e |
179 | void IVtkOCC_ViewerSelector::Activate (const Handle(SelectMgr_Selection)& theSelection) |
913a4c4a |
180 | { |
f751596e |
181 | for (theSelection->Init(); theSelection->More(); theSelection->Next()) |
913a4c4a |
182 | { |
f751596e |
183 | theSelection->Sensitive()->SetActiveForSelection(); |
913a4c4a |
184 | } |
f751596e |
185 | |
186 | theSelection->SetSelectionState (SelectMgr_SOS_Activated); |
187 | |
188 | myTolerances.Add (theSelection->Sensitivity()); |
f751596e |
189 | myToUpdateTolerance = Standard_True; |
913a4c4a |
190 | } |
191 | |
192 | //============================================================================ |
193 | // Method: Deactivate |
194 | // Purpose: Deactivate the given selection |
195 | //============================================================================ |
196 | void IVtkOCC_ViewerSelector::Deactivate (const Handle(SelectMgr_Selection)& theSelection) |
197 | { |
f751596e |
198 | for (theSelection->Init(); theSelection->More(); theSelection->Next()) |
913a4c4a |
199 | { |
f751596e |
200 | theSelection->Sensitive()->ResetSelectionActiveStatus(); |
913a4c4a |
201 | } |
913a4c4a |
202 | |
f751596e |
203 | theSelection->SetSelectionState (SelectMgr_SOS_Deactivated); |
204 | |
205 | myTolerances.Decrement (theSelection->Sensitivity()); |
f751596e |
206 | myToUpdateTolerance = Standard_True; |
913a4c4a |
207 | } |