1 // Created on: 1993-01-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #define No_Standard_NoMoreObject
18 #define No_Standard_NoSuchObject
19 #define No_Standard_TypeMismatch
23 #include <TopExp_Explorer.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopoDS_Shape.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <TopoDS_Wire.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_MapIteratorOfMapOfShape.hxx>
32 #include <TopTools_MapOfShape.hxx>
34 //=======================================================================
35 //function : MapShapes
37 //=======================================================================
38 void TopExp::MapShapes(const TopoDS_Shape& S,
39 const TopAbs_ShapeEnum T,
40 TopTools_IndexedMapOfShape& M)
42 TopExp_Explorer Ex(S,T);
49 //=======================================================================
50 //function : MapShapes
52 //=======================================================================
54 void TopExp::MapShapes(const TopoDS_Shape& S,
55 TopTools_IndexedMapOfShape& M)
58 TopoDS_Iterator It(S);
60 MapShapes(It.Value(),M);
65 //=======================================================================
66 //function : MapShapesAndAncestors
68 //=======================================================================
70 void TopExp::MapShapesAndAncestors
71 (const TopoDS_Shape& S,
72 const TopAbs_ShapeEnum TS,
73 const TopAbs_ShapeEnum TA,
74 TopTools_IndexedDataMapOfShapeListOfShape& M)
76 TopTools_ListOfShape empty;
79 TopExp_Explorer exa(S,TA);
82 const TopoDS_Shape& anc = exa.Current();
83 TopExp_Explorer exs(anc,TS);
85 Standard_Integer index = M.FindIndex(exs.Current());
86 if (index == 0) index = M.Add(exs.Current(),empty);
93 // visit shapes not under ancestors
94 TopExp_Explorer ex(S,TS,TA);
96 Standard_Integer index = M.FindIndex(ex.Current());
97 if (index == 0) index = M.Add(ex.Current(),empty);
102 //=======================================================================
103 //function : MapShapesAndUniqueAncestors
105 //=======================================================================
107 void TopExp::MapShapesAndUniqueAncestors
108 (const TopoDS_Shape& S,
109 const TopAbs_ShapeEnum TS,
110 const TopAbs_ShapeEnum TA,
111 TopTools_IndexedDataMapOfShapeListOfShape& M,
112 const Standard_Boolean useOrientation)
114 TopTools_ListOfShape empty;
117 TopExp_Explorer exa(S,TA);
121 const TopoDS_Shape& anc = exa.Current();
122 TopExp_Explorer exs(anc,TS);
125 Standard_Integer index = M.FindIndex(exs.Current());
127 index = M.Add(exs.Current(),empty);
128 TopTools_ListOfShape& aList = M(index);
129 // check if anc already exists in a list
130 TopTools_ListIteratorOfListOfShape it(aList);
131 for (; it.More(); it.Next())
132 if (useOrientation? anc.IsEqual(it.Value()) : anc.IsSame(it.Value()))
141 // visit shapes not under ancestors
142 TopExp_Explorer ex(S,TS,TA);
145 Standard_Integer index = M.FindIndex(ex.Current());
147 M.Add(ex.Current(),empty);
152 //=======================================================================
153 //function : FirstVertex
155 //=======================================================================
157 TopoDS_Vertex TopExp::FirstVertex(const TopoDS_Edge& E,
158 const Standard_Boolean CumOri)
160 TopoDS_Iterator ite(E,CumOri);
162 if (ite.Value().Orientation() == TopAbs_FORWARD)
163 return TopoDS::Vertex(ite.Value());
166 return TopoDS_Vertex();
170 //=======================================================================
171 //function : LastVertex
173 //=======================================================================
175 TopoDS_Vertex TopExp::LastVertex(const TopoDS_Edge& E,
176 const Standard_Boolean CumOri)
178 TopoDS_Iterator ite(E,CumOri);
180 if (ite.Value().Orientation() == TopAbs_REVERSED)
181 return TopoDS::Vertex(ite.Value());
184 return TopoDS_Vertex();
188 //=======================================================================
189 //function : Vertices
191 //=======================================================================
193 void TopExp::Vertices(const TopoDS_Edge& E,
194 TopoDS_Vertex& Vfirst,
195 TopoDS_Vertex& Vlast,
196 const Standard_Boolean CumOri)
198 // minor optimization for case when Vfirst and Vlast are non-null:
199 // at least for VC++ 10, it is faster if we use boolean flags than
200 // if we nullify vertices at that point (see #27021)
201 Standard_Boolean isFirstDefined = Standard_False;
202 Standard_Boolean isLastDefined = Standard_False;
204 TopoDS_Iterator ite(E, CumOri);
206 const TopoDS_Shape& aV = ite.Value();
207 if (aV.Orientation() == TopAbs_FORWARD)
209 Vfirst = TopoDS::Vertex (aV);
210 isFirstDefined = Standard_True;
212 else if (aV.Orientation() == TopAbs_REVERSED)
214 Vlast = TopoDS::Vertex (aV);
215 isLastDefined = Standard_True;
228 //=======================================================================
229 //function : Vertices
231 //=======================================================================
233 void TopExp::Vertices(const TopoDS_Wire& W,
234 TopoDS_Vertex& Vfirst,
235 TopoDS_Vertex& Vlast)
237 Vfirst = Vlast = TopoDS_Vertex(); // nullify
239 TopTools_MapOfShape vmap;
240 TopoDS_Iterator it(W);
244 const TopoDS_Edge& E = TopoDS::Edge(it.Value());
245 if (E.Orientation() == TopAbs_REVERSED)
246 TopExp::Vertices(E,V2,V1);
248 TopExp::Vertices(E,V1,V2);
249 // add or remove in the vertex map
250 V1.Orientation(TopAbs_FORWARD);
251 V2.Orientation(TopAbs_REVERSED);
252 if (!vmap.Add(V1)) vmap.Remove(V1);
253 if (!vmap.Add(V2)) vmap.Remove(V2);
257 if (vmap.IsEmpty()) { // closed
258 TopoDS_Shape aLocalShape = V2.Oriented(TopAbs_FORWARD);
259 Vfirst = TopoDS::Vertex(aLocalShape);
260 aLocalShape = V2.Oriented(TopAbs_REVERSED);
261 Vlast = TopoDS::Vertex(aLocalShape);
262 // Vfirst = TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD));
263 // Vlast = TopoDS::Vertex(V2.Oriented(TopAbs_REVERSED));
265 else if (vmap.Extent() == 2) { //open
266 TopTools_MapIteratorOfMapOfShape ite(vmap);
268 while (ite.More() && ite.Key().Orientation() != TopAbs_FORWARD)
270 if (ite.More()) Vfirst = TopoDS::Vertex(ite.Key());
271 ite.Initialize(vmap);
272 while (ite.More() && ite.Key().Orientation() != TopAbs_REVERSED)
274 if (ite.More()) Vlast = TopoDS::Vertex(ite.Key());
279 //=======================================================================
280 //function : CommonVertex
282 //=======================================================================
283 Standard_Boolean TopExp::CommonVertex(const TopoDS_Edge& E1,
284 const TopoDS_Edge& E2,
287 TopoDS_Vertex firstVertex1, lastVertex1, firstVertex2, lastVertex2;
288 TopExp::Vertices(E1, firstVertex1, lastVertex1);
289 TopExp::Vertices(E2, firstVertex2, lastVertex2);
291 if (firstVertex1.IsSame(firstVertex2) ||
292 firstVertex1.IsSame(lastVertex2)) {
294 return Standard_True;
296 if (lastVertex1.IsSame(firstVertex2) ||
297 lastVertex1.IsSame(lastVertex2)) {
299 return Standard_True;
301 return Standard_False;