1 // Created on: 2011-10-20
2 // Created by: Roman KOZLOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IVtkOCC_ViewerSelector.hxx>
17 #include <Select3D_SensitiveBox.hxx>
18 #include <TColgp_Array1OfPnt2d.hxx>
19 #include <Graphic3d_Camera.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(IVtkOCC_ViewerSelector,SelectMgr_ViewerSelector)
24 //============================================================================
25 // Method: Constructor
27 //============================================================================
28 IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector()
29 : SelectMgr_ViewerSelector(),
31 myToUpdateTol(Standard_True) {}
33 //============================================================================
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)
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
47 mySelectingVolumeMgr.SetPixelTolerance (myPixTol);
49 myToUpdateTol = Standard_False;
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();
58 mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Point);
59 theView->GetCamera (aProj, anOrient, isOrthographic);
60 mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
62 theView->GetWindowSize (aWidth, aHeight);
63 mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
65 theView->GetViewport (aX, aY, aVpWidth, aVpHeight);
66 mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight);
68 gp_Pnt2d aMousePos (static_cast<Standard_Real> (theXPix),
69 static_cast<Standard_Real> (theYPix));
70 mySelectingVolumeMgr.BuildSelectingVolume (aMousePos);
75 //============================================================================
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)
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
91 mySelectingVolumeMgr.SetPixelTolerance (myPixTol);
93 myToUpdateTol = Standard_False;
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();
102 mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Box);
103 theView->GetCamera (aProj, anOrient, isOrthographic);
104 mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
106 theView->GetWindowSize (aWidth, aHeight);
107 mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
109 theView->GetViewport (aX, aY, aVpWidth, aVpHeight);
110 mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight);
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));
117 mySelectingVolumeMgr.BuildSelectingVolume (aMinMousePos,
120 TraverseSensitives();
123 //============================================================================
126 //============================================================================
127 void IVtkOCC_ViewerSelector::Pick (double** thePoly,
128 const int theNbPoints,
129 const IVtk_IView::Handle& theView)
131 TColgp_Array1OfPnt2d aPolyline (1, theNbPoints);
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...
139 mySelectingVolumeMgr.SetPixelTolerance (myPixTol);
141 myToUpdateTol = Standard_False;
144 // Build TColgp_Array1OfPnt2d from input array of doubles
147 for (Standard_Integer anIt = 0; anIt < theNbPoints; anIt++)
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]);
151 aPolyline.SetValue (anIt + 1, aDispPnt);
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();
160 mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Polyline);
161 theView->GetCamera (aProj, anOrient, isOrthographic);
162 mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
164 theView->GetWindowSize (aWidth, aHeight);
165 mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
167 theView->GetViewport (aX, aY, aVpWidth, aVpHeight);
168 mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight);
170 mySelectingVolumeMgr.BuildSelectingVolume (aPolyline);
172 TraverseSensitives();
175 //============================================================================
177 // Purpose: Activates the given selection
178 //============================================================================
179 void IVtkOCC_ViewerSelector::Activate (const Handle(SelectMgr_Selection)& theSelection)
181 for (theSelection->Init(); theSelection->More(); theSelection->Next())
183 theSelection->Sensitive()->SetActiveForSelection();
186 theSelection->SetSelectionState (SelectMgr_SOS_Activated);
188 myTolerances.Add (theSelection->Sensitivity());
189 myToUpdateTolerance = Standard_True;
192 //============================================================================
193 // Method: Deactivate
194 // Purpose: Deactivate the given selection
195 //============================================================================
196 void IVtkOCC_ViewerSelector::Deactivate (const Handle(SelectMgr_Selection)& theSelection)
198 for (theSelection->Init(); theSelection->More(); theSelection->Next())
200 theSelection->Sensitive()->ResetSelectionActiveStatus();
203 theSelection->SetSelectionState (SelectMgr_SOS_Deactivated);
205 myTolerances.Decrement (theSelection->Sensitivity());
206 myToUpdateTolerance = Standard_True;