b311480e |
1 | // Created on: 1999-11-29 |
2 | // Created by: Peter KURNEV |
3 | // Copyright (c) 1999-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 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public 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. |
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 | #include <TopOpeBRepBuild_Tools2d.ixx> |
18 | #include <TopoDS_Wire.hxx> |
19 | #include <TopExp_Explorer.hxx> |
20 | #include <TopOpeBRepBuild_VertexInfo.hxx> |
21 | #include <TopoDS.hxx> |
22 | #include <TopoDS_Vertex.hxx> |
23 | #include <TopExp.hxx> |
24 | #include <TopTools_IndexedMapOfShape.hxx> |
25 | #include <TopTools_ListOfShape.hxx> |
26 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
27 | #include <stdio.h> |
28 | |
29 | static |
30 | void BuildPath (const TopoDS_Vertex& myVertex0, |
31 | const TopoDS_Edge& myEdge, |
32 | const TopoDS_Vertex& myVertex, |
33 | const Standard_Integer aNbEdges, |
34 | TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M, |
35 | Standard_Integer anEdgesCount, |
36 | Standard_Integer& aBreakFlag, |
37 | TopTools_ListOfShape& myResList); |
38 | |
39 | //======================================================================= |
40 | // function :TopOpeBRepBuild_Tools2d::Path |
41 | // purpose: |
42 | //======================================================================= |
43 | void TopOpeBRepBuild_Tools2d::Path(const TopoDS_Wire& aWire, TopTools_ListOfShape& aResList) |
44 | { |
45 | Standard_Integer anEdgesCount=0, aNbEdges=0, aBreakFlag=0; |
46 | TopTools_ListOfShape myResList; |
47 | TopoDS_Vertex myVertex, myVertex0; |
48 | TopoDS_Edge myEdge, aNullEdge; |
49 | |
50 | TopExp_Explorer ex(aWire,TopAbs_EDGE); |
51 | for (; ex.More(); ex.Next()) aNbEdges++; |
52 | |
53 | myResList.Clear(); |
54 | |
55 | TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo M; |
56 | TopOpeBRepBuild_Tools2d::MakeMapOfShapeVertexInfo(aWire, M); |
57 | |
58 | |
59 | myEdge=aNullEdge; |
60 | myVertex0=TopoDS::Vertex(M.FindKey(1)); |
61 | myVertex=myVertex0; |
62 | |
63 | BuildPath (myVertex0, myEdge, myVertex, aNbEdges, M, anEdgesCount, aBreakFlag, myResList); |
64 | // |
65 | aResList.Clear(); |
66 | aResList=myResList; |
67 | } |
68 | //======================================================================= |
69 | // function :BuildPath |
70 | // purpose: |
71 | //======================================================================= |
72 | void BuildPath (const TopoDS_Vertex& myVertex0, |
73 | const TopoDS_Edge& myInputEdge, |
74 | const TopoDS_Vertex& myInputVertex, |
75 | const Standard_Integer aNbEdges, |
76 | TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M, |
77 | Standard_Integer anEdgesCount, |
78 | Standard_Integer& aBreakFlag, |
79 | TopTools_ListOfShape& myResList) |
80 | { |
81 | Standard_Integer j = 1, aFoundOut, aNbCases, stopFlag=0; |
82 | TopoDS_Edge myEdge; |
83 | TopoDS_Vertex myVertex; |
84 | |
85 | if (aBreakFlag==1) return; |
86 | |
87 | TopOpeBRepBuild_VertexInfo& aVInfo=M.ChangeFromKey(myInputVertex); |
88 | // |
89 | aVInfo.SetCurrentIn (myInputEdge); |
90 | aVInfo.Prepare(myResList); |
91 | aNbCases=aVInfo.NbCases(); |
92 | if (!aNbCases) aBreakFlag=2; |
93 | |
94 | for (j=1; j<=aNbCases; j++) { |
95 | |
96 | myEdge=aVInfo.CurrentOut(); |
97 | |
98 | aFoundOut=aVInfo.FoundOut(); |
99 | if (!aFoundOut) { //FondOut=0 TUPICK |
100 | aBreakFlag=2; |
101 | return; |
102 | } |
103 | |
104 | else { |
105 | if (stopFlag) { // if previous path was wrong |
106 | aVInfo.RemovePassed(); |
107 | myResList.RemoveFirst(); |
108 | stopFlag=0; |
109 | anEdgesCount--; |
110 | } |
111 | |
112 | aVInfo.AppendPassed (myEdge); |
113 | myResList.Prepend (myEdge); |
114 | anEdgesCount++; |
115 | myVertex=(myEdge.Orientation()==TopAbs_FORWARD)? |
116 | TopExp::LastVertex(myEdge) : TopExp::FirstVertex(myEdge); |
117 | |
118 | if (myVertex.IsSame(myVertex0) && anEdgesCount==aNbEdges) { |
119 | aBreakFlag=1; |
120 | return; |
121 | } |
122 | |
123 | BuildPath (myVertex0, myEdge, myVertex, aNbEdges, M, anEdgesCount, aBreakFlag, myResList); |
124 | //// |
125 | if (aBreakFlag==1) { |
126 | return; |
127 | } |
128 | |
129 | if (aBreakFlag==2) {// Come back |
130 | if (j==aNbCases) { |
131 | aVInfo.RemovePassed(); |
132 | myResList.RemoveFirst(); |
133 | anEdgesCount--; |
134 | //// |
135 | return; |
136 | } |
137 | else { |
138 | stopFlag=1; |
139 | aBreakFlag=0; // Next j if possible |
140 | } |
141 | } // end of if (aBreakFlag==2) |
142 | } // end of else .i.e. aFoundOut#0 |
143 | } // end of for (j=1; j<=aNbCases; j++) |
144 | } |
145 | |
146 | //======================================================================= |
147 | // function :TopOpeBRepBuild_Tools2d::MakeMapOfShapeVertexInfo |
148 | // purpose: |
149 | //======================================================================= |
150 | void TopOpeBRepBuild_Tools2d::MakeMapOfShapeVertexInfo(const TopoDS_Wire& aWire, |
151 | TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M) |
152 | { |
153 | TopOpeBRepBuild_VertexInfo empty; |
154 | TopExp_Explorer exa(aWire,TopAbs_EDGE); |
155 | for (; exa.More(); exa.Next()) { |
156 | const TopoDS_Edge& anEdge = TopoDS::Edge(exa.Current()); |
157 | TopExp_Explorer exs(anEdge, TopAbs_VERTEX); |
158 | for (; exs.More(); exs.Next()) { |
159 | const TopoDS_Vertex& aVertex= TopoDS::Vertex(exs.Current()); |
160 | Standard_Integer index = M.FindIndex(aVertex); |
161 | if (!index) |
162 | index = M.Add(aVertex, empty); |
163 | |
164 | TopOpeBRepBuild_VertexInfo& aVInfo= M(index); |
165 | aVInfo.SetVertex (aVertex); |
166 | TopAbs_Orientation anOr=aVertex.Orientation(); |
167 | if (anOr==TopAbs_FORWARD ) aVInfo.AddOut (anEdge); |
168 | else if (anOr==TopAbs_REVERSED) aVInfo.AddIn (anEdge); |
169 | } |
170 | } |
171 | |
172 | Standard_Integer i, aNb; |
173 | aNb=M.Extent(); |
174 | for (i=1; i<=aNb; i++) { |
175 | TopOpeBRepBuild_VertexInfo& aVInfo=M(i); |
176 | const TopTools_IndexedMapOfOrientedShape& EdgesIn =aVInfo.EdgesIn(); |
177 | const TopTools_IndexedMapOfOrientedShape& EdgesOut =aVInfo.EdgesOut(); |
178 | Standard_Integer aNbEdgesIn, aNbEdgesOut; |
179 | aNbEdgesIn =EdgesIn.Extent(); |
180 | aNbEdgesOut =EdgesOut.Extent(); |
181 | if (aNbEdgesIn!=1 && aNbEdgesOut!=1) { |
182 | aVInfo.SetSmart (Standard_True); |
183 | } |
184 | } |
185 | } |
186 | |
187 | //======================================================================= |
188 | // function :TopOpeBRepBuild_Tools2d::DumpMapOfShapeVertexInfo |
189 | // purpose: |
190 | //======================================================================= |
191 | void TopOpeBRepBuild_Tools2d::DumpMapOfShapeVertexInfo(const TopOpeBRepBuild_IndexedDataMapOfShapeVertexInfo& M) |
192 | { |
96a95605 |
193 | Standard_Integer i, aNb; |
7fd59977 |
194 | aNb=M.Extent(); |
195 | for (i=1; i<=aNb; i++) { |
196 | const TopOpeBRepBuild_VertexInfo& aVInfo=M(i); |
7fd59977 |
197 | |
198 | printf(" Vert.#%d, ", i); |
199 | const TopTools_ListOfShape& aList=aVInfo.ListPassed(); |
200 | |
201 | if (aList.Extent()) { |
202 | TopTools_ListIteratorOfListOfShape anIt(aList); |
203 | for (; anIt.More(); anIt.Next()) { |
204 | printf("pass,"); |
205 | } |
206 | } |
207 | |
208 | else { |
209 | printf("none"); |
210 | } |
211 | printf("\n"); |
212 | } |
213 | } |
214 | |