Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopExp / TopExp.cxx
CommitLineData
7fd59977 1// File: TopExp.cxx
2// Created: Tue Jan 19 20:20:00 1993
3// Author: Remi LEQUETTE
4// <rle@phylox>
5
6#define No_Standard_NoMoreObject
7#define No_Standard_NoSuchObject
8#define No_Standard_TypeMismatch
9
10#include <TopExp.ixx>
11#include <TopoDS.hxx>
12#include <TopExp_Explorer.hxx>
13#include <TopoDS_Iterator.hxx>
14#include <TopTools_ListOfShape.hxx>
15#include <TopTools_MapOfShape.hxx>
16#include <TopTools_MapIteratorOfMapOfShape.hxx>
17
18//=======================================================================
19//function : MapShapes
20//purpose :
21//=======================================================================
22
23void TopExp::MapShapes(const TopoDS_Shape& S,
24 const TopAbs_ShapeEnum T,
25 TopTools_IndexedMapOfShape& M)
26{
27 TopExp_Explorer Ex(S,T);
28 while (Ex.More()) {
29 M.Add(Ex.Current());
30 Ex.Next();
31 }
32}
33
34//=======================================================================
35//function : MapShapes
36//purpose :
37//=======================================================================
38
39void TopExp::MapShapes(const TopoDS_Shape& S,
40 TopTools_IndexedMapOfShape& M)
41{
42 M.Add(S);
43 TopoDS_Iterator It(S);
44 while (It.More()) {
45 MapShapes(It.Value(),M);
46 It.Next();
47 }
48}
49
50//=======================================================================
51//function : MapShapesAndAncestors
52//purpose :
53//=======================================================================
54
55void TopExp::MapShapesAndAncestors
56 (const TopoDS_Shape& S,
57 const TopAbs_ShapeEnum TS,
58 const TopAbs_ShapeEnum TA,
59 TopTools_IndexedDataMapOfShapeListOfShape& M)
60{
61 TopTools_ListOfShape empty;
62
63 // visit ancestors
64 TopExp_Explorer exa(S,TA);
65 while (exa.More()) {
66 // visit shapes
67 const TopoDS_Shape& anc = exa.Current();
68 TopExp_Explorer exs(anc,TS);
69 while (exs.More()) {
70 Standard_Integer index = M.FindIndex(exs.Current());
71 if (index == 0) index = M.Add(exs.Current(),empty);
72 M(index).Append(anc);
73 exs.Next();
74 }
75 exa.Next();
76 }
77
78 // visit shapes not under ancestors
79 TopExp_Explorer ex(S,TS,TA);
80 while (ex.More()) {
81 Standard_Integer index = M.FindIndex(ex.Current());
82 if (index == 0) index = M.Add(ex.Current(),empty);
83 ex.Next();
84 }
85}
86
87
88
89//=======================================================================
90//function : FirstVertex
91//purpose :
92//=======================================================================
93
94TopoDS_Vertex TopExp::FirstVertex(const TopoDS_Edge& E,
95 const Standard_Boolean CumOri)
96{
97 TopoDS_Iterator ite(E,CumOri);
98 while (ite.More()) {
99 if (ite.Value().Orientation() == TopAbs_FORWARD)
100 return TopoDS::Vertex(ite.Value());
101 ite.Next();
102 }
103 return TopoDS_Vertex();
104}
105
106
107//=======================================================================
108//function : LastVertex
109//purpose :
110//=======================================================================
111
112TopoDS_Vertex TopExp::LastVertex(const TopoDS_Edge& E,
113 const Standard_Boolean CumOri)
114{
115 TopoDS_Iterator ite(E,CumOri);
116 while (ite.More()) {
117 if (ite.Value().Orientation() == TopAbs_REVERSED)
118 return TopoDS::Vertex(ite.Value());
119 ite.Next();
120 }
121 return TopoDS_Vertex();
122}
123
124
125//=======================================================================
126//function : Vertices
127//purpose :
128//=======================================================================
129
130void TopExp::Vertices(const TopoDS_Edge& E,
131 TopoDS_Vertex& Vfirst,
132 TopoDS_Vertex& Vlast,
133 const Standard_Boolean CumOri)
134{
135 Vfirst = Vlast = TopoDS_Vertex(); // nullify
136 TopoDS_Iterator ite(E,CumOri);
137 while (ite.More()) {
138 if (ite.Value().Orientation() == TopAbs_FORWARD)
139 Vfirst = TopoDS::Vertex(ite.Value());
140 else if (ite.Value().Orientation() == TopAbs_REVERSED)
141 Vlast = TopoDS::Vertex(ite.Value());
142 ite.Next();
143 }
144}
145
146
147//=======================================================================
148//function : Vertices
149//purpose :
150//=======================================================================
151
152void TopExp::Vertices(const TopoDS_Wire& W,
153 TopoDS_Vertex& Vfirst,
154 TopoDS_Vertex& Vlast)
155{
156 Vfirst = Vlast = TopoDS_Vertex(); // nullify
157
158 TopTools_MapOfShape vmap;
159 TopoDS_Iterator it(W);
160 TopoDS_Vertex V1,V2;
161
162 while (it.More()) {
163 const TopoDS_Edge& E = TopoDS::Edge(it.Value());
164 if (E.Orientation() == TopAbs_REVERSED)
165 TopExp::Vertices(E,V2,V1);
166 else
167 TopExp::Vertices(E,V1,V2);
168 // add or remove in the vertex map
169 V1.Orientation(TopAbs_FORWARD);
170 V2.Orientation(TopAbs_REVERSED);
171 if (!vmap.Add(V1)) vmap.Remove(V1);
172 if (!vmap.Add(V2)) vmap.Remove(V2);
173
174 it.Next();
175 }
176 if (vmap.IsEmpty()) { // closed
177 TopoDS_Shape aLocalShape = V2.Oriented(TopAbs_FORWARD);
178 Vfirst = TopoDS::Vertex(aLocalShape);
179 aLocalShape = V2.Oriented(TopAbs_REVERSED);
180 Vlast = TopoDS::Vertex(aLocalShape);
181// Vfirst = TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD));
182// Vlast = TopoDS::Vertex(V2.Oriented(TopAbs_REVERSED));
183 }
184 else if (vmap.Extent() == 2) { //open
185 TopTools_MapIteratorOfMapOfShape ite(vmap);
186
187 while (ite.More() && ite.Key().Orientation() != TopAbs_FORWARD)
188 ite.Next();
189 if (ite.More()) Vfirst = TopoDS::Vertex(ite.Key());
190 ite.Initialize(vmap);
191 while (ite.More() && ite.Key().Orientation() != TopAbs_REVERSED)
192 ite.Next();
193 if (ite.More()) Vlast = TopoDS::Vertex(ite.Key());
194 }
195}
196
197
198//=======================================================================
199//function : CommonVertex
200//purpose :
201//=======================================================================
202Standard_Boolean TopExp::CommonVertex(const TopoDS_Edge& E1,
203 const TopoDS_Edge& E2,
204 TopoDS_Vertex& V)
205{
206 TopoDS_Vertex firstVertex1, lastVertex1, firstVertex2, lastVertex2;
207 TopExp::Vertices(E1, firstVertex1, lastVertex1);
208 TopExp::Vertices(E2, firstVertex2, lastVertex2);
209
210 if (firstVertex1.IsSame(firstVertex2) ||
211 firstVertex1.IsSame(lastVertex2)) {
212 V = firstVertex1;
213 return Standard_True;
214 }
215 if (lastVertex1.IsSame(firstVertex2) ||
216 lastVertex1.IsSame(lastVertex2)) {
217 V = lastVertex1;
218 return Standard_True;
219 }
220 return Standard_False;
221} // CommonVertex
222