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>
24 #include <TopoDS_Iterator.hxx>
25 #include <TopTools_ListOfShape.hxx>
26 #include <TopTools_MapOfShape.hxx>
27 #include <TopTools_MapIteratorOfMapOfShape.hxx>
29 //=======================================================================
30 //function : MapShapes
32 //=======================================================================
34 void TopExp::MapShapes(const TopoDS_Shape& S,
35 const TopAbs_ShapeEnum T,
36 TopTools_IndexedMapOfShape& M)
38 TopExp_Explorer Ex(S,T);
45 //=======================================================================
46 //function : MapShapes
48 //=======================================================================
50 void TopExp::MapShapes(const TopoDS_Shape& S,
51 TopTools_IndexedMapOfShape& M)
54 TopoDS_Iterator It(S);
56 MapShapes(It.Value(),M);
61 //=======================================================================
62 //function : MapShapesAndAncestors
64 //=======================================================================
66 void TopExp::MapShapesAndAncestors
67 (const TopoDS_Shape& S,
68 const TopAbs_ShapeEnum TS,
69 const TopAbs_ShapeEnum TA,
70 TopTools_IndexedDataMapOfShapeListOfShape& M)
72 TopTools_ListOfShape empty;
75 TopExp_Explorer exa(S,TA);
78 const TopoDS_Shape& anc = exa.Current();
79 TopExp_Explorer exs(anc,TS);
81 Standard_Integer index = M.FindIndex(exs.Current());
82 if (index == 0) index = M.Add(exs.Current(),empty);
89 // visit shapes not under ancestors
90 TopExp_Explorer ex(S,TS,TA);
92 Standard_Integer index = M.FindIndex(ex.Current());
93 if (index == 0) index = M.Add(ex.Current(),empty);
100 //=======================================================================
101 //function : FirstVertex
103 //=======================================================================
105 TopoDS_Vertex TopExp::FirstVertex(const TopoDS_Edge& E,
106 const Standard_Boolean CumOri)
108 TopoDS_Iterator ite(E,CumOri);
110 if (ite.Value().Orientation() == TopAbs_FORWARD)
111 return TopoDS::Vertex(ite.Value());
114 return TopoDS_Vertex();
118 //=======================================================================
119 //function : LastVertex
121 //=======================================================================
123 TopoDS_Vertex TopExp::LastVertex(const TopoDS_Edge& E,
124 const Standard_Boolean CumOri)
126 TopoDS_Iterator ite(E,CumOri);
128 if (ite.Value().Orientation() == TopAbs_REVERSED)
129 return TopoDS::Vertex(ite.Value());
132 return TopoDS_Vertex();
136 //=======================================================================
137 //function : Vertices
139 //=======================================================================
141 void TopExp::Vertices(const TopoDS_Edge& E,
142 TopoDS_Vertex& Vfirst,
143 TopoDS_Vertex& Vlast,
144 const Standard_Boolean CumOri)
146 Vfirst = Vlast = TopoDS_Vertex(); // nullify
147 TopoDS_Iterator ite(E,CumOri);
149 if (ite.Value().Orientation() == TopAbs_FORWARD)
150 Vfirst = TopoDS::Vertex(ite.Value());
151 else if (ite.Value().Orientation() == TopAbs_REVERSED)
152 Vlast = TopoDS::Vertex(ite.Value());
158 //=======================================================================
159 //function : Vertices
161 //=======================================================================
163 void TopExp::Vertices(const TopoDS_Wire& W,
164 TopoDS_Vertex& Vfirst,
165 TopoDS_Vertex& Vlast)
167 Vfirst = Vlast = TopoDS_Vertex(); // nullify
169 TopTools_MapOfShape vmap;
170 TopoDS_Iterator it(W);
174 const TopoDS_Edge& E = TopoDS::Edge(it.Value());
175 if (E.Orientation() == TopAbs_REVERSED)
176 TopExp::Vertices(E,V2,V1);
178 TopExp::Vertices(E,V1,V2);
179 // add or remove in the vertex map
180 V1.Orientation(TopAbs_FORWARD);
181 V2.Orientation(TopAbs_REVERSED);
182 if (!vmap.Add(V1)) vmap.Remove(V1);
183 if (!vmap.Add(V2)) vmap.Remove(V2);
187 if (vmap.IsEmpty()) { // closed
188 TopoDS_Shape aLocalShape = V2.Oriented(TopAbs_FORWARD);
189 Vfirst = TopoDS::Vertex(aLocalShape);
190 aLocalShape = V2.Oriented(TopAbs_REVERSED);
191 Vlast = TopoDS::Vertex(aLocalShape);
192 // Vfirst = TopoDS::Vertex(V2.Oriented(TopAbs_FORWARD));
193 // Vlast = TopoDS::Vertex(V2.Oriented(TopAbs_REVERSED));
195 else if (vmap.Extent() == 2) { //open
196 TopTools_MapIteratorOfMapOfShape ite(vmap);
198 while (ite.More() && ite.Key().Orientation() != TopAbs_FORWARD)
200 if (ite.More()) Vfirst = TopoDS::Vertex(ite.Key());
201 ite.Initialize(vmap);
202 while (ite.More() && ite.Key().Orientation() != TopAbs_REVERSED)
204 if (ite.More()) Vlast = TopoDS::Vertex(ite.Key());
209 //=======================================================================
210 //function : CommonVertex
212 //=======================================================================
213 Standard_Boolean TopExp::CommonVertex(const TopoDS_Edge& E1,
214 const TopoDS_Edge& E2,
217 TopoDS_Vertex firstVertex1, lastVertex1, firstVertex2, lastVertex2;
218 TopExp::Vertices(E1, firstVertex1, lastVertex1);
219 TopExp::Vertices(E2, firstVertex2, lastVertex2);
221 if (firstVertex1.IsSame(firstVertex2) ||
222 firstVertex1.IsSame(lastVertex2)) {
224 return Standard_True;
226 if (lastVertex1.IsSame(firstVertex2) ||
227 lastVertex1.IsSame(lastVertex2)) {
229 return Standard_True;
231 return Standard_False;