1 // Created on: 2007-01-29
2 // Created by: Sergey KOCHETKOV
3 // Copyright (c) 2007-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
8 // under the terms of the GNU Lesser General Public 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 <MeshVS_SensitiveMesh.ixx>
18 #include <TColgp_Array1OfPnt.hxx>
19 #include <TColStd_Array1OfReal.hxx>
20 #include <TColStd_HPackedMapOfInteger.hxx>
21 #include <Select3D_Projector.hxx>
22 #include <TopLoc_Location.hxx>
23 #include <MeshVS_DataSource.hxx>
24 #include <MeshVS_MeshOwner.hxx>
26 //=======================================================================
27 // name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh
29 //=======================================================================
30 MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwnerId,
31 const Standard_Integer theMode)
32 : Select3D_SensitiveEntity( theOwnerId )
36 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
37 if( !anOwner.IsNull() )
39 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
41 mybox = aDS->GetBoundingBox();
45 //================================================================
48 //================================================================
49 Standard_Integer MeshVS_SensitiveMesh::GetMode () const
54 //=======================================================================
57 //=======================================================================
58 Standard_Boolean MeshVS_SensitiveMesh::Matches (const SelectBasics_PickArgs& thePickArgs,
59 Standard_Real& theMatchDMin,
60 Standard_Real& theMatchDepth)
63 theMatchDepth = Precision::Infinite();
65 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
66 if( anOwner.IsNull() ) return Standard_False;
67 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
68 if( aMeshPrs.IsNull() ) return Standard_False;
69 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
70 if( aDS.IsNull() ) return Standard_False;
71 Handle(TColStd_HPackedMapOfInteger) NodesMap;
72 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
74 // Mesh data source should provide the algorithm for computation
75 // of detected entities from 2D point
76 Standard_Boolean isDetected =
77 aDS->GetDetectedEntities (aMeshPrs, thePickArgs.X(), thePickArgs.Y(),
78 thePickArgs.Tolerance(), NodesMap,
79 ElemsMap, theMatchDMin);
81 // The detected entites will be available from mesh owner
82 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
87 //=======================================================================
90 //=======================================================================
91 Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real XMin,
92 const Standard_Real YMin,
93 const Standard_Real XMax,
94 const Standard_Real YMax,
95 const Standard_Real aTol)
97 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
98 if( anOwner.IsNull() ) return Standard_False;
99 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
100 if( aMeshPrs.IsNull() ) return Standard_False;
101 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
102 if( aDS.IsNull() ) return Standard_False;
103 Handle(TColStd_HPackedMapOfInteger) NodesMap;
104 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
105 // Mesh data source should provide the algorithm for computation
106 // of detected entities from 2D box area
107 Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, XMin, YMin, XMax, YMax, aTol, NodesMap, ElemsMap );
108 // The detected entites will be available from mesh owner
109 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
114 //=======================================================================
117 //=======================================================================
118 Standard_Boolean MeshVS_SensitiveMesh::Matches(const TColgp_Array1OfPnt2d& Polyline,
119 const Bnd_Box2d& aBox,
120 const Standard_Real aTol)
122 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
123 if( anOwner.IsNull() ) return Standard_False;
124 Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
125 if( aMeshPrs.IsNull() ) return Standard_False;
126 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
127 if( aDS.IsNull() ) return Standard_False;
128 Handle(TColStd_HPackedMapOfInteger) NodesMap;
129 Handle(TColStd_HPackedMapOfInteger) ElemsMap;
130 // Mesh data source should provide the algorithm for computation
131 // of detected entities from 2D polyline
132 Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, Polyline, aBox, aTol, NodesMap, ElemsMap );
133 // The detected entites will be available from mesh owner
134 anOwner->SetDetectedEntities( NodesMap, ElemsMap );
139 //=======================================================================
140 // name : GetConnected
142 //=======================================================================
143 Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected( const TopLoc_Location& aLoc )
145 Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh( myOwnerId );
146 if(HasLocation()) aMeshEnt->SetLocation( Location() );
147 aMeshEnt->UpdateLocation( aLoc );
151 //==================================================
152 // Function: ProjectOneCorner
154 //==================================================
155 void MeshVS_SensitiveMesh::ProjectOneCorner(const Handle(Select3D_Projector)& theProj,
156 const Standard_Real theX,
157 const Standard_Real theY,
158 const Standard_Real theZ)
160 gp_Pnt aPnt( theX, theY, theZ );
163 theProj->Project( aPnt.Transformed(Location().Transformation()), aProjPnt );
165 theProj->Project( aPnt, aProjPnt );
166 mybox2d.Add( aProjPnt );
169 //==================================================
172 //==================================================
173 void MeshVS_SensitiveMesh::Project(const Handle(Select3D_Projector)& aProj)
178 // Compute the 2D bounding box - projection of mesh bounding box
179 Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
180 if( anOwner.IsNull() ) return;
181 Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
182 if( aDS.IsNull() ) return;
184 Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
185 mybox.Get( XMin, YMin, ZMin, XMax, YMax, ZMax );
187 ProjectOneCorner (aProj, XMin, YMin, ZMin);
188 ProjectOneCorner (aProj, XMin, YMin, ZMax);
189 ProjectOneCorner (aProj, XMin, YMax, ZMin);
190 ProjectOneCorner (aProj, XMin, YMax, ZMax);
191 ProjectOneCorner (aProj, XMax, YMin, ZMin);
192 ProjectOneCorner (aProj, XMax, YMin, ZMax);
193 ProjectOneCorner (aProj, XMax, YMax, ZMin);
194 ProjectOneCorner (aProj, XMax, YMax, ZMax);
197 //==================================================
200 //==================================================
201 void MeshVS_SensitiveMesh::Areas( SelectBasics_ListOfBox2d& aSeq )
203 aSeq.Append(mybox2d);