0024070: OpenGL capped object-level clipping planes
[occt.git] / src / MeshVS / MeshVS_SensitiveMesh.cxx
CommitLineData
b311480e 1// Created on: 2007-01-29
2// Created by: Sergey KOCHETKOV
3// Copyright (c) 2007-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <MeshVS_SensitiveMesh.ixx>
22
23#include <TColgp_Array1OfPnt.hxx>
24#include <TColStd_Array1OfReal.hxx>
25#include <TColStd_HPackedMapOfInteger.hxx>
26#include <Select3D_Projector.hxx>
27#include <TopLoc_Location.hxx>
28#include <MeshVS_DataSource.hxx>
29#include <MeshVS_MeshOwner.hxx>
30
31//=======================================================================
32// name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh
33// Purpose :
34//=======================================================================
35MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwnerId,
36 const Standard_Integer theMode)
37: Select3D_SensitiveEntity( theOwnerId )
38{
39 myMode = theMode;
40 mybox.SetVoid();
41 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
42 if( !anOwner.IsNull() )
43 {
44 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
45 if( !aDS.IsNull() )
46 mybox = aDS->GetBoundingBox();
47 }
48}
49
50//================================================================
51// Function : GetMode
52// Purpose :
53//================================================================
54Standard_Integer MeshVS_SensitiveMesh::GetMode () const
55{
56 return myMode;
57}
58
59//=======================================================================
60// name : Matches
61// Purpose :
62//=======================================================================
4269bd1b 63Standard_Boolean MeshVS_SensitiveMesh::Matches (const SelectBasics_PickArgs& thePickArgs,
64 Standard_Real& theMatchDMin,
65 Standard_Real& theMatchDepth)
7fd59977 66{
4269bd1b 67 theMatchDMin = 0.0;
68 theMatchDepth = Precision::Infinite();
69
7fd59977 70 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
71 if( anOwner.IsNull() ) return Standard_False;
72 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
73 if( aMeshPrs.IsNull() ) return Standard_False;
74 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
75 if( aDS.IsNull() ) return Standard_False;
76 Handle(TColStd_HPackedMapOfInteger) NodesMap;
77 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
4269bd1b 78
7fd59977 79 // Mesh data source should provide the algorithm for computation
80 // of detected entities from 2D point
4269bd1b 81 Standard_Boolean isDetected =
82 aDS->GetDetectedEntities (aMeshPrs, thePickArgs.X(), thePickArgs.Y(),
83 thePickArgs.Tolerance(), NodesMap,
84 ElemsMap, theMatchDMin);
85
7fd59977 86 // The detected entites will be available from mesh owner
87 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
4269bd1b 88
7fd59977 89 return isDetected;
90}
91
92//=======================================================================
93// name : Matches
94// Purpose :
95//=======================================================================
96Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real XMin,
97 const Standard_Real YMin,
98 const Standard_Real XMax,
99 const Standard_Real YMax,
100 const Standard_Real aTol)
101{
102 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
103 if( anOwner.IsNull() ) return Standard_False;
104 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
105 if( aMeshPrs.IsNull() ) return Standard_False;
106 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
107 if( aDS.IsNull() ) return Standard_False;
108 Handle(TColStd_HPackedMapOfInteger) NodesMap;
109 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
110 // Mesh data source should provide the algorithm for computation
111 // of detected entities from 2D box area
112 Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, XMin, YMin, XMax, YMax, aTol, NodesMap, ElemsMap );
113 // The detected entites will be available from mesh owner
114 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
115
116 return isDetected;
117}
118
119//=======================================================================
120// name : Matches
121// Purpose :
122//=======================================================================
123Standard_Boolean MeshVS_SensitiveMesh::Matches(const TColgp_Array1OfPnt2d& Polyline,
124 const Bnd_Box2d& aBox,
125 const Standard_Real aTol)
126{
127 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
128 if( anOwner.IsNull() ) return Standard_False;
129 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
130 if( aMeshPrs.IsNull() ) return Standard_False;
131 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
132 if( aDS.IsNull() ) return Standard_False;
133 Handle(TColStd_HPackedMapOfInteger) NodesMap;
134 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
135 // Mesh data source should provide the algorithm for computation
136 // of detected entities from 2D polyline
137 Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, Polyline, aBox, aTol, NodesMap, ElemsMap );
138 // The detected entites will be available from mesh owner
139 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
140
141 return isDetected;
142}
143
144//=======================================================================
145// name : GetConnected
146// Purpose :
147//=======================================================================
148Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected( const TopLoc_Location& aLoc )
149{
150 Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh( myOwnerId );
151 if(HasLocation()) aMeshEnt->SetLocation( Location() );
152 aMeshEnt->UpdateLocation( aLoc );
153 return aMeshEnt;
154}
155
7fd59977 156//==================================================
157// Function: ProjectOneCorner
158// Purpose :
159//==================================================
4952a30a 160void MeshVS_SensitiveMesh::ProjectOneCorner(const Handle(Select3D_Projector)& theProj,
7fd59977 161 const Standard_Real theX,
162 const Standard_Real theY,
163 const Standard_Real theZ)
164{
165 gp_Pnt aPnt( theX, theY, theZ );
166 gp_Pnt2d aProjPnt;
167 if( HasLocation() )
4952a30a 168 theProj->Project( aPnt.Transformed(Location().Transformation()), aProjPnt );
7fd59977 169 else
4952a30a 170 theProj->Project( aPnt, aProjPnt );
7fd59977 171 mybox2d.Add( aProjPnt );
172}
173
174//==================================================
175// Function: Project
176// Purpose :
177//==================================================
4952a30a 178void MeshVS_SensitiveMesh::Project(const Handle(Select3D_Projector)& aProj)
7fd59977 179{
7fd59977 180 mybox2d.SetVoid();
181 if (mybox.IsVoid())
182 return;
183 // Compute the 2D bounding box - projection of mesh bounding box
184 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
185 if( anOwner.IsNull() ) return;
186 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
187 if( aDS.IsNull() ) return;
188
189 Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
190 mybox.Get( XMin, YMin, ZMin, XMax, YMax, ZMax );
191
192 ProjectOneCorner (aProj, XMin, YMin, ZMin);
193 ProjectOneCorner (aProj, XMin, YMin, ZMax);
194 ProjectOneCorner (aProj, XMin, YMax, ZMin);
195 ProjectOneCorner (aProj, XMin, YMax, ZMax);
196 ProjectOneCorner (aProj, XMax, YMin, ZMin);
197 ProjectOneCorner (aProj, XMax, YMin, ZMax);
198 ProjectOneCorner (aProj, XMax, YMax, ZMin);
199 ProjectOneCorner (aProj, XMax, YMax, ZMax);
200}
201
202//==================================================
203// Function: Areas
204// Purpose :
205//==================================================
206void MeshVS_SensitiveMesh::Areas( SelectBasics_ListOfBox2d& aSeq )
207{
208 aSeq.Append(mybox2d);
209}