1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
// File: MeshVS_SensitiveMesh.cxx
// Created: Thu Jan 29 2007
// Author: Sergey KOCHETKOV
// Copyright: Open CASCADE 2007
#include <MeshVS_SensitiveMesh.ixx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HPackedMapOfInteger.hxx>
#include <Select3D_Projector.hxx>
#include <TopLoc_Location.hxx>
#include <MeshVS_DataSource.hxx>
#include <MeshVS_MeshOwner.hxx>
//=======================================================================
// name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh
// Purpose :
//=======================================================================
MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Standard_Integer theMode)
: Select3D_SensitiveEntity( theOwnerId )
{
myMode = theMode;
mybox.SetVoid();
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( !anOwner.IsNull() )
{
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( !aDS.IsNull() )
mybox = aDS->GetBoundingBox();
}
}
//================================================================
// Function : GetMode
// Purpose :
//================================================================
Standard_Integer MeshVS_SensitiveMesh::GetMode () const
{
return myMode;
}
//=======================================================================
// name : Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
DMin = 0.;
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return Standard_False;
Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
if( aMeshPrs.IsNull() ) return Standard_False;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return Standard_False;
Handle(TColStd_HPackedMapOfInteger) NodesMap;
Handle(TColStd_HPackedMapOfInteger) ElemsMap;
// Mesh data source should provide the algorithm for computation
// of detected entities from 2D point
Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, X, Y, aTol, NodesMap, ElemsMap, DMin );
// The detected entites will be available from mesh owner
anOwner->SetDetectedEntities( NodesMap, ElemsMap );
return isDetected;
}
//=======================================================================
// name : Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return Standard_False;
Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
if( aMeshPrs.IsNull() ) return Standard_False;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return Standard_False;
Handle(TColStd_HPackedMapOfInteger) NodesMap;
Handle(TColStd_HPackedMapOfInteger) ElemsMap;
// Mesh data source should provide the algorithm for computation
// of detected entities from 2D box area
Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, XMin, YMin, XMax, YMax, aTol, NodesMap, ElemsMap );
// The detected entites will be available from mesh owner
anOwner->SetDetectedEntities( NodesMap, ElemsMap );
return isDetected;
}
//=======================================================================
// name : Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveMesh::Matches(const TColgp_Array1OfPnt2d& Polyline,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return Standard_False;
Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
if( aMeshPrs.IsNull() ) return Standard_False;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return Standard_False;
Handle(TColStd_HPackedMapOfInteger) NodesMap;
Handle(TColStd_HPackedMapOfInteger) ElemsMap;
// Mesh data source should provide the algorithm for computation
// of detected entities from 2D polyline
Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, Polyline, aBox, aTol, NodesMap, ElemsMap );
// The detected entites will be available from mesh owner
anOwner->SetDetectedEntities( NodesMap, ElemsMap );
return isDetected;
}
//=======================================================================
// name : GetConnected
// Purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected( const TopLoc_Location& aLoc )
{
Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh( myOwnerId );
if(HasLocation()) aMeshEnt->SetLocation( Location() );
aMeshEnt->UpdateLocation( aLoc );
return aMeshEnt;
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real MeshVS_SensitiveMesh::ComputeDepth( const gp_Lin& /*EyeLine*/ ) const
{
return Precision::Infinite();
}
//==================================================
// Function: ProjectOneCorner
// Purpose :
//==================================================
void MeshVS_SensitiveMesh::ProjectOneCorner(const Handle(Select3D_Projector)& theProj,
const Standard_Real theX,
const Standard_Real theY,
const Standard_Real theZ)
{
gp_Pnt aPnt( theX, theY, theZ );
gp_Pnt2d aProjPnt;
if( HasLocation() )
theProj->Project( aPnt.Transformed(Location().Transformation()), aProjPnt );
else
theProj->Project( aPnt, aProjPnt );
mybox2d.Add( aProjPnt );
}
//==================================================
// Function: Project
// Purpose :
//==================================================
void MeshVS_SensitiveMesh::Project(const Handle(Select3D_Projector)& aProj)
{
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
mybox2d.SetVoid();
if (mybox.IsVoid())
return;
// Compute the 2D bounding box - projection of mesh bounding box
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return;
Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
mybox.Get( XMin, YMin, ZMin, XMax, YMax, ZMax );
ProjectOneCorner (aProj, XMin, YMin, ZMin);
ProjectOneCorner (aProj, XMin, YMin, ZMax);
ProjectOneCorner (aProj, XMin, YMax, ZMin);
ProjectOneCorner (aProj, XMin, YMax, ZMax);
ProjectOneCorner (aProj, XMax, YMin, ZMin);
ProjectOneCorner (aProj, XMax, YMin, ZMax);
ProjectOneCorner (aProj, XMax, YMax, ZMin);
ProjectOneCorner (aProj, XMax, YMax, ZMax);
}
//==================================================
// Function: Areas
// Purpose :
//==================================================
void MeshVS_SensitiveMesh::Areas( SelectBasics_ListOfBox2d& aSeq )
{
aSeq.Append(mybox2d);
}
|