0024624: Lost word in license statement in source files
[occt.git] / src / TopExp / TopExp.cxx
CommitLineData
b311480e 1// Created on: 1993-01-19
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#define No_Standard_NoMoreObject
18#define No_Standard_NoSuchObject
19#define No_Standard_TypeMismatch
20
21#include <TopExp.ixx>
22#include <TopoDS.hxx>
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>
28
29//=======================================================================
30//function : MapShapes
31//purpose :
32//=======================================================================
33
34void TopExp::MapShapes(const TopoDS_Shape& S,
35 const TopAbs_ShapeEnum T,
36 TopTools_IndexedMapOfShape& M)
37{
38 TopExp_Explorer Ex(S,T);
39 while (Ex.More()) {
40 M.Add(Ex.Current());
41 Ex.Next();
42 }
43}
44
45//=======================================================================
46//function : MapShapes
47//purpose :
48//=======================================================================
49
50void TopExp::MapShapes(const TopoDS_Shape& S,
51 TopTools_IndexedMapOfShape& M)
52{
53 M.Add(S);
54 TopoDS_Iterator It(S);
55 while (It.More()) {
56 MapShapes(It.Value(),M);
57 It.Next();
58 }
59}
60
61//=======================================================================
62//function : MapShapesAndAncestors
63//purpose :
64//=======================================================================
65
66void TopExp::MapShapesAndAncestors
67 (const TopoDS_Shape& S,
68 const TopAbs_ShapeEnum TS,
69 const TopAbs_ShapeEnum TA,
70 TopTools_IndexedDataMapOfShapeListOfShape& M)
71{
72 TopTools_ListOfShape empty;
73
74 // visit ancestors
75 TopExp_Explorer exa(S,TA);
76 while (exa.More()) {
77 // visit shapes
78 const TopoDS_Shape& anc = exa.Current();
79 TopExp_Explorer exs(anc,TS);
80 while (exs.More()) {
81 Standard_Integer index = M.FindIndex(exs.Current());
82 if (index == 0) index = M.Add(exs.Current(),empty);
83 M(index).Append(anc);
84 exs.Next();
85 }
86 exa.Next();
87 }
88
89 // visit shapes not under ancestors
90 TopExp_Explorer ex(S,TS,TA);
91 while (ex.More()) {
92 Standard_Integer index = M.FindIndex(ex.Current());
93 if (index == 0) index = M.Add(ex.Current(),empty);
94 ex.Next();
95 }
96}
97
98
99
100//=======================================================================
101//function : FirstVertex
102//purpose :
103//=======================================================================
104
105TopoDS_Vertex TopExp::FirstVertex(const TopoDS_Edge& E,
106 const Standard_Boolean CumOri)
107{
108 TopoDS_Iterator ite(E,CumOri);
109 while (ite.More()) {
110 if (ite.Value().Orientation() == TopAbs_FORWARD)
111 return TopoDS::Vertex(ite.Value());
112 ite.Next();
113 }
114 return TopoDS_Vertex();
115}
116
117
118//=======================================================================
119//function : LastVertex
120//purpose :
121//=======================================================================
122
123TopoDS_Vertex TopExp::LastVertex(const TopoDS_Edge& E,
124 const Standard_Boolean CumOri)
125{
126 TopoDS_Iterator ite(E,CumOri);
127 while (ite.More()) {
128 if (ite.Value().Orientation() == TopAbs_REVERSED)
129 return TopoDS::Vertex(ite.Value());
130 ite.Next();
131 }
132 return TopoDS_Vertex();
133}
134
135
136//=======================================================================
137//function : Vertices
138//purpose :
139//=======================================================================
140
141void TopExp::Vertices(const TopoDS_Edge& E,
142 TopoDS_Vertex& Vfirst,
143 TopoDS_Vertex& Vlast,
144 const Standard_Boolean CumOri)
145{
146 Vfirst = Vlast = TopoDS_Vertex(); // nullify
147 TopoDS_Iterator ite(E,CumOri);
148 while (ite.More()) {
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());
153 ite.Next();
154 }
155}
156
157
158//=======================================================================
159//function : Vertices
160//purpose :
161//=======================================================================
162
163void TopExp::Vertices(const TopoDS_Wire& W,
164 TopoDS_Vertex& Vfirst,
165 TopoDS_Vertex& Vlast)
166{
167 Vfirst = Vlast = TopoDS_Vertex(); // nullify
168
169 TopTools_MapOfShape vmap;
170 TopoDS_Iterator it(W);
171 TopoDS_Vertex V1,V2;
172
173 while (it.More()) {
174 const TopoDS_Edge& E = TopoDS::Edge(it.Value());
175 if (E.Orientation() == TopAbs_REVERSED)
176 TopExp::Vertices(E,V2,V1);
177 else
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);
184
185 it.Next();
186 }
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));
194 }
195 else if (vmap.Extent() == 2) { //open
196 TopTools_MapIteratorOfMapOfShape ite(vmap);
197
198 while (ite.More() && ite.Key().Orientation() != TopAbs_FORWARD)
199 ite.Next();
200 if (ite.More()) Vfirst = TopoDS::Vertex(ite.Key());
201 ite.Initialize(vmap);
202 while (ite.More() && ite.Key().Orientation() != TopAbs_REVERSED)
203 ite.Next();
204 if (ite.More()) Vlast = TopoDS::Vertex(ite.Key());
205 }
206}
207
208
209//=======================================================================
210//function : CommonVertex
211//purpose :
212//=======================================================================
213Standard_Boolean TopExp::CommonVertex(const TopoDS_Edge& E1,
214 const TopoDS_Edge& E2,
215 TopoDS_Vertex& V)
216{
217 TopoDS_Vertex firstVertex1, lastVertex1, firstVertex2, lastVertex2;
218 TopExp::Vertices(E1, firstVertex1, lastVertex1);
219 TopExp::Vertices(E2, firstVertex2, lastVertex2);
220
221 if (firstVertex1.IsSame(firstVertex2) ||
222 firstVertex1.IsSame(lastVertex2)) {
223 V = firstVertex1;
224 return Standard_True;
225 }
226 if (lastVertex1.IsSame(firstVertex2) ||
227 lastVertex1.IsSame(lastVertex2)) {
228 V = lastVertex1;
229 return Standard_True;
230 }
231 return Standard_False;
232} // CommonVertex
233