7fd59977 |
1 | // File: MeshVS_SensitiveMesh.cxx |
2 | // Created: Thu Jan 29 2007 |
3 | // Author: Sergey KOCHETKOV |
4 | // Copyright: Open CASCADE 2007 |
5 | |
6 | #include <MeshVS_SensitiveMesh.ixx> |
7 | |
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> |
15 | |
16 | //======================================================================= |
17 | // name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh |
18 | // Purpose : |
19 | //======================================================================= |
20 | MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwnerId, |
21 | const Standard_Integer theMode) |
22 | : Select3D_SensitiveEntity( theOwnerId ) |
23 | { |
24 | myMode = theMode; |
25 | mybox.SetVoid(); |
26 | Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() ); |
27 | if( !anOwner.IsNull() ) |
28 | { |
29 | Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource(); |
30 | if( !aDS.IsNull() ) |
31 | mybox = aDS->GetBoundingBox(); |
32 | } |
33 | } |
34 | |
35 | //================================================================ |
36 | // Function : GetMode |
37 | // Purpose : |
38 | //================================================================ |
39 | Standard_Integer MeshVS_SensitiveMesh::GetMode () const |
40 | { |
41 | return myMode; |
42 | } |
43 | |
44 | //======================================================================= |
45 | // name : Matches |
46 | // Purpose : |
47 | //======================================================================= |
48 | Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real X, |
49 | const Standard_Real Y, |
50 | const Standard_Real aTol, |
51 | Standard_Real& DMin) |
52 | { |
53 | DMin = 0.; |
54 | |
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 ); |
68 | |
69 | return isDetected; |
70 | } |
71 | |
72 | //======================================================================= |
73 | // name : Matches |
74 | // Purpose : |
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) |
81 | { |
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 ); |
95 | |
96 | return isDetected; |
97 | } |
98 | |
99 | //======================================================================= |
100 | // name : Matches |
101 | // Purpose : |
102 | //======================================================================= |
103 | Standard_Boolean MeshVS_SensitiveMesh::Matches(const TColgp_Array1OfPnt2d& Polyline, |
104 | const Bnd_Box2d& aBox, |
105 | const Standard_Real aTol) |
106 | { |
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 ); |
120 | |
121 | return isDetected; |
122 | } |
123 | |
124 | //======================================================================= |
125 | // name : GetConnected |
126 | // Purpose : |
127 | //======================================================================= |
128 | Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected( const TopLoc_Location& aLoc ) |
129 | { |
130 | Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh( myOwnerId ); |
131 | if(HasLocation()) aMeshEnt->SetLocation( Location() ); |
132 | aMeshEnt->UpdateLocation( aLoc ); |
133 | return aMeshEnt; |
134 | } |
135 | |
136 | //======================================================================= |
137 | //function : ComputeDepth |
138 | //purpose : |
139 | //======================================================================= |
140 | Standard_Real MeshVS_SensitiveMesh::ComputeDepth( const gp_Lin& /*EyeLine*/ ) const |
141 | { |
4952a30a |
142 | return Precision::Infinite(); |
7fd59977 |
143 | } |
144 | |
145 | //================================================== |
146 | // Function: ProjectOneCorner |
147 | // Purpose : |
148 | //================================================== |
4952a30a |
149 | void MeshVS_SensitiveMesh::ProjectOneCorner(const Handle(Select3D_Projector)& theProj, |
7fd59977 |
150 | const Standard_Real theX, |
151 | const Standard_Real theY, |
152 | const Standard_Real theZ) |
153 | { |
154 | gp_Pnt aPnt( theX, theY, theZ ); |
155 | gp_Pnt2d aProjPnt; |
156 | if( HasLocation() ) |
4952a30a |
157 | theProj->Project( aPnt.Transformed(Location().Transformation()), aProjPnt ); |
7fd59977 |
158 | else |
4952a30a |
159 | theProj->Project( aPnt, aProjPnt ); |
7fd59977 |
160 | mybox2d.Add( aProjPnt ); |
161 | } |
162 | |
163 | //================================================== |
164 | // Function: Project |
165 | // Purpose : |
166 | //================================================== |
4952a30a |
167 | void MeshVS_SensitiveMesh::Project(const Handle(Select3D_Projector)& aProj) |
7fd59977 |
168 | { |
169 | Select3D_SensitiveEntity::Project(aProj); // to set the field last proj... |
170 | |
171 | mybox2d.SetVoid(); |
172 | if (mybox.IsVoid()) |
173 | return; |
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; |
179 | |
180 | Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax; |
181 | mybox.Get( XMin, YMin, ZMin, XMax, YMax, ZMax ); |
182 | |
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); |
191 | } |
192 | |
193 | //================================================== |
194 | // Function: Areas |
195 | // Purpose : |
196 | //================================================== |
197 | void MeshVS_SensitiveMesh::Areas( SelectBasics_ListOfBox2d& aSeq ) |
198 | { |
199 | aSeq.Append(mybox2d); |
200 | } |