1 // File: MeshVS_SensitiveMesh.cxx
2 // Created: Thu Jan 29 2007
3 // Author: Sergey KOCHETKOV
4 // Copyright: Open CASCADE 2007
6 #include <MeshVS_SensitiveMesh.ixx>
8 #include <TColgp_Array1OfPnt.hxx>
9 #include <TColStd_Array1OfReal.hxx>
10 #include <TColStd_HPackedMapOfInteger.hxx>
11 #include <Select3D_Projector.hxx>
12 #include <TopLoc_Location.hxx>
13 #include <MeshVS_DataSource.hxx>
14 #include <MeshVS_MeshOwner.hxx>
16 //=======================================================================
17 // name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh
19 //=======================================================================
20 MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwnerId,
21 const Standard_Integer theMode)
22 : Select3D_SensitiveEntity( theOwnerId )
26 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
27 if( !anOwner.IsNull() )
29 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
31 mybox = aDS->GetBoundingBox();
35 //================================================================
38 //================================================================
39 Standard_Integer MeshVS_SensitiveMesh::GetMode () const
44 //=======================================================================
47 //=======================================================================
48 Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real X,
49 const Standard_Real Y,
50 const Standard_Real aTol,
55 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
56 if( anOwner.IsNull() ) return Standard_False;
57 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
58 if( aMeshPrs.IsNull() ) return Standard_False;
59 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
60 if( aDS.IsNull() ) return Standard_False;
61 Handle(TColStd_HPackedMapOfInteger) NodesMap;
62 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
63 // Mesh data source should provide the algorithm for computation
64 // of detected entities from 2D point
65 Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, X, Y, aTol, NodesMap, ElemsMap, DMin );
66 // The detected entites will be available from mesh owner
67 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
72 //=======================================================================
75 //=======================================================================
76 Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real XMin,
77 const Standard_Real YMin,
78 const Standard_Real XMax,
79 const Standard_Real YMax,
80 const Standard_Real aTol)
82 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
83 if( anOwner.IsNull() ) return Standard_False;
84 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
85 if( aMeshPrs.IsNull() ) return Standard_False;
86 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
87 if( aDS.IsNull() ) return Standard_False;
88 Handle(TColStd_HPackedMapOfInteger) NodesMap;
89 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
90 // Mesh data source should provide the algorithm for computation
91 // of detected entities from 2D box area
92 Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, XMin, YMin, XMax, YMax, aTol, NodesMap, ElemsMap );
93 // The detected entites will be available from mesh owner
94 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
99 //=======================================================================
102 //=======================================================================
103 Standard_Boolean MeshVS_SensitiveMesh::Matches(const TColgp_Array1OfPnt2d& Polyline,
104 const Bnd_Box2d& aBox,
105 const Standard_Real aTol)
107 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
108 if( anOwner.IsNull() ) return Standard_False;
109 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
110 if( aMeshPrs.IsNull() ) return Standard_False;
111 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
112 if( aDS.IsNull() ) return Standard_False;
113 Handle(TColStd_HPackedMapOfInteger) NodesMap;
114 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
115 // Mesh data source should provide the algorithm for computation
116 // of detected entities from 2D polyline
117 Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, Polyline, aBox, aTol, NodesMap, ElemsMap );
118 // The detected entites will be available from mesh owner
119 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
124 //=======================================================================
125 // name : GetConnected
127 //=======================================================================
128 Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected( const TopLoc_Location& aLoc )
130 Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh( myOwnerId );
131 if(HasLocation()) aMeshEnt->SetLocation( Location() );
132 aMeshEnt->UpdateLocation( aLoc );
136 //=======================================================================
137 //function : ComputeDepth
139 //=======================================================================
140 Standard_Real MeshVS_SensitiveMesh::ComputeDepth( const gp_Lin& /*EyeLine*/ ) const
142 return Precision::Infinite();
145 //==================================================
146 // Function: ProjectOneCorner
148 //==================================================
149 void MeshVS_SensitiveMesh::ProjectOneCorner(const Handle(Select3D_Projector)& theProj,
150 const Standard_Real theX,
151 const Standard_Real theY,
152 const Standard_Real theZ)
154 gp_Pnt aPnt( theX, theY, theZ );
157 theProj->Project( aPnt.Transformed(Location().Transformation()), aProjPnt );
159 theProj->Project( aPnt, aProjPnt );
160 mybox2d.Add( aProjPnt );
163 //==================================================
166 //==================================================
167 void MeshVS_SensitiveMesh::Project(const Handle(Select3D_Projector)& aProj)
169 Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
174 // Compute the 2D bounding box - projection of mesh bounding box
175 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
176 if( anOwner.IsNull() ) return;
177 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
178 if( aDS.IsNull() ) return;
180 Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
181 mybox.Get( XMin, YMin, ZMin, XMax, YMax, ZMax );
183 ProjectOneCorner (aProj, XMin, YMin, ZMin);
184 ProjectOneCorner (aProj, XMin, YMin, ZMax);
185 ProjectOneCorner (aProj, XMin, YMax, ZMin);
186 ProjectOneCorner (aProj, XMin, YMax, ZMax);
187 ProjectOneCorner (aProj, XMax, YMin, ZMin);
188 ProjectOneCorner (aProj, XMax, YMin, ZMax);
189 ProjectOneCorner (aProj, XMax, YMax, ZMin);
190 ProjectOneCorner (aProj, XMax, YMax, ZMax);
193 //==================================================
196 //==================================================
197 void MeshVS_SensitiveMesh::Areas( SelectBasics_ListOfBox2d& aSeq )
199 aSeq.Append(mybox2d);