1 // Created on: 1999-11-29
2 // Created by: Peter KURNEV
3 // Copyright (c) 1999-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.
19 #include <TopExp_Explorer.hxx>
21 #include <TopoDS_Vertex.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <TopOpeBRepBuild_Tools2d.hxx>
24 #include <TopOpeBRepBuild_VertexInfo.hxx>
25 #include <TopTools_IndexedMapOfShape.hxx>
26 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <TopTools_ListOfShape.hxx>
31 void BuildPath (const TopoDS_Vertex& myVertex0,
32 const TopoDS_Edge& myEdge,
33 const TopoDS_Vertex& myVertex,
34 const Standard_Integer aNbEdges,
35 TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M,
36 Standard_Integer anEdgesCount,
37 Standard_Integer& aBreakFlag,
38 TopTools_ListOfShape& myResList);
40 //=======================================================================
41 // function :TopOpeBRepBuild_Tools2d::Path
43 //=======================================================================
44 void TopOpeBRepBuild_Tools2d::Path(const TopoDS_Wire& aWire, TopTools_ListOfShape& aResList)
46 Standard_Integer anEdgesCount=0, aNbEdges=0, aBreakFlag=0;
47 TopTools_ListOfShape myResList;
48 TopoDS_Vertex myVertex, myVertex0;
49 TopoDS_Edge myEdge, aNullEdge;
51 TopExp_Explorer ex(aWire,TopAbs_EDGE);
52 for (; ex.More(); ex.Next()) aNbEdges++;
56 TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo M;
57 TopOpeBRepBuild_Tools2d::MakeMapOfShapeVertexInfo(aWire, M);
61 myVertex0=TopoDS::Vertex(M.FindKey(1));
64 BuildPath (myVertex0, myEdge, myVertex, aNbEdges, M, anEdgesCount, aBreakFlag, myResList);
69 //=======================================================================
70 // function :BuildPath
72 //=======================================================================
73 void BuildPath (const TopoDS_Vertex& myVertex0,
74 const TopoDS_Edge& myInputEdge,
75 const TopoDS_Vertex& myInputVertex,
76 const Standard_Integer aNbEdges,
77 TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M,
78 Standard_Integer anEdgesCount,
79 Standard_Integer& aBreakFlag,
80 TopTools_ListOfShape& myResList)
82 Standard_Integer j = 1, aFoundOut, aNbCases, stopFlag=0;
84 TopoDS_Vertex myVertex;
86 if (aBreakFlag==1) return;
88 TopOpeBRepBuild_VertexInfo& aVInfo=M.ChangeFromKey(myInputVertex);
90 aVInfo.SetCurrentIn (myInputEdge);
91 aVInfo.Prepare(myResList);
92 aNbCases=aVInfo.NbCases();
93 if (!aNbCases) aBreakFlag=2;
95 for (j=1; j<=aNbCases; j++) {
97 myEdge=aVInfo.CurrentOut();
99 aFoundOut=aVInfo.FoundOut();
100 if (!aFoundOut) { //FondOut=0 TUPICK
106 if (stopFlag) { // if previous path was wrong
107 aVInfo.RemovePassed();
108 myResList.RemoveFirst();
113 aVInfo.AppendPassed (myEdge);
114 myResList.Prepend (myEdge);
116 myVertex=(myEdge.Orientation()==TopAbs_FORWARD)?
117 TopExp::LastVertex(myEdge) : TopExp::FirstVertex(myEdge);
119 if (myVertex.IsSame(myVertex0) && anEdgesCount==aNbEdges) {
124 BuildPath (myVertex0, myEdge, myVertex, aNbEdges, M, anEdgesCount, aBreakFlag, myResList);
130 if (aBreakFlag==2) {// Come back
132 aVInfo.RemovePassed();
133 myResList.RemoveFirst();
140 aBreakFlag=0; // Next j if possible
142 } // end of if (aBreakFlag==2)
143 } // end of else .i.e. aFoundOut#0
144 } // end of for (j=1; j<=aNbCases; j++)
147 //=======================================================================
148 // function :TopOpeBRepBuild_Tools2d::MakeMapOfShapeVertexInfo
150 //=======================================================================
151 void TopOpeBRepBuild_Tools2d::MakeMapOfShapeVertexInfo(const TopoDS_Wire& aWire,
152 TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M)
154 TopOpeBRepBuild_VertexInfo empty;
155 TopExp_Explorer exa(aWire,TopAbs_EDGE);
156 for (; exa.More(); exa.Next()) {
157 const TopoDS_Edge& anEdge = TopoDS::Edge(exa.Current());
158 TopExp_Explorer exs(anEdge, TopAbs_VERTEX);
159 for (; exs.More(); exs.Next()) {
160 const TopoDS_Vertex& aVertex= TopoDS::Vertex(exs.Current());
161 Standard_Integer index = M.FindIndex(aVertex);
163 index = M.Add(aVertex, empty);
165 TopOpeBRepBuild_VertexInfo& aVInfo= M(index);
166 aVInfo.SetVertex (aVertex);
167 TopAbs_Orientation anOr=aVertex.Orientation();
168 if (anOr==TopAbs_FORWARD ) aVInfo.AddOut (anEdge);
169 else if (anOr==TopAbs_REVERSED) aVInfo.AddIn (anEdge);
173 Standard_Integer i, aNb;
175 for (i=1; i<=aNb; i++) {
176 TopOpeBRepBuild_VertexInfo& aVInfo=M(i);
177 const TopTools_IndexedMapOfOrientedShape& EdgesIn =aVInfo.EdgesIn();
178 const TopTools_IndexedMapOfOrientedShape& EdgesOut =aVInfo.EdgesOut();
179 Standard_Integer aNbEdgesIn, aNbEdgesOut;
180 aNbEdgesIn =EdgesIn.Extent();
181 aNbEdgesOut =EdgesOut.Extent();
182 if (aNbEdgesIn!=1 && aNbEdgesOut!=1) {
183 aVInfo.SetSmart (Standard_True);
188 //=======================================================================
189 // function :TopOpeBRepBuild_Tools2d::DumpMapOfShapeVertexInfo
191 //=======================================================================
192 void TopOpeBRepBuild_Tools2d::DumpMapOfShapeVertexInfo(const TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M)
194 Standard_Integer i, aNb;
196 for (i=1; i<=aNb; i++) {
197 const TopOpeBRepBuild_VertexInfo& aVInfo=M(i);
199 printf(" Vert.#%d, ", i);
200 const TopTools_ListOfShape& aList=aVInfo.ListPassed();
202 if (aList.Extent()) {
203 TopTools_ListIteratorOfListOfShape anIt(aList);
204 for (; anIt.More(); anIt.Next()) {