b311480e |
1 | // Created on: 1996-01-05 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1996-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 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <BRep_Builder.hxx> |
19 | #include <BRep_Tool.hxx> |
7fd59977 |
20 | #include <gp_Pnt.hxx> |
21 | #include <gp_Pnt2d.hxx> |
42cf5bc1 |
22 | #include <Precision.hxx> |
23 | #include <Standard_ProgramError.hxx> |
7fd59977 |
24 | #include <TopAbs_Orientation.hxx> |
42cf5bc1 |
25 | #include <TopExp.hxx> |
7fd59977 |
26 | #include <TopoDS.hxx> |
27 | #include <TopoDS_Compound.hxx> |
7fd59977 |
28 | #include <TopoDS_Edge.hxx> |
42cf5bc1 |
29 | #include <TopoDS_Face.hxx> |
30 | #include <TopoDS_Shape.hxx> |
7fd59977 |
31 | #include <TopoDS_Vertex.hxx> |
42cf5bc1 |
32 | #include <TopOpeBRepBuild_BlockBuilder.hxx> |
33 | #include <TopOpeBRepBuild_define.hxx> |
34 | #include <TopOpeBRepBuild_FaceBuilder.hxx> |
35 | #include <TopOpeBRepBuild_Loop.hxx> |
36 | #include <TopOpeBRepBuild_LoopSet.hxx> |
37 | #include <TopOpeBRepBuild_ShapeSet.hxx> |
38 | #include <TopOpeBRepBuild_WireEdgeClassifier.hxx> |
39 | #include <TopOpeBRepBuild_WireEdgeSet.hxx> |
7fd59977 |
40 | #include <TopOpeBRepDS_BuildTool.hxx> |
7fd59977 |
41 | #include <TopTools_Array1OfShape.hxx> |
42cf5bc1 |
42 | #include <TopTools_DataMapOfShapeInteger.hxx> |
7fd59977 |
43 | #include <TopTools_DataMapOfShapeListOfShape.hxx> |
42cf5bc1 |
44 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
45 | #include <TopTools_IndexedDataMapOfShapeShape.hxx> |
46 | #include <TopTools_IndexedMapOfOrientedShape.hxx> |
7fd59977 |
47 | #include <TopTools_IndexedMapOfShape.hxx> |
42cf5bc1 |
48 | #include <TopTools_ListOfShape.hxx> |
7fd59977 |
49 | |
42cf5bc1 |
50 | //#include <BRepAdaptor_Curve2d.hxx> |
7fd59977 |
51 | #undef RM_HANGING |
52 | // MSV: RM_HANGING behaviour: when state of wire is UNCLOSEDW we do not |
53 | // remove the whole wire but remove the chains of hanging edges. This would |
54 | // produce a good result in some cases. But :-( it gives regressions on grid |
55 | // tests (1cto 021 W4,X4). Therefore I leaved this code not active. |
56 | #ifdef RM_HANGING |
57 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
58 | #endif |
59 | |
0797d9d3 |
60 | #ifdef OCCT_DEBUG |
1d0a9d4d |
61 | extern Standard_Boolean TopOpeBRepBuild_GettracePURGE(); |
62 | extern Standard_Boolean TopOpeBRepDS_GettraceSTRANGE(); |
7fd59977 |
63 | #include <TopOpeBRepDS_DSX.hxx> |
64 | void debifb() {} |
65 | #endif |
66 | |
67 | #ifdef DRAW |
68 | #include <TopOpeBRepTool_DRAW.hxx> |
69 | #endif |
70 | |
71 | //======================================================================= |
72 | //function : TopOpeBRepBuild_FaceBuilder |
73 | //purpose : |
74 | //======================================================================= |
75 | TopOpeBRepBuild_FaceBuilder::TopOpeBRepBuild_FaceBuilder() |
76 | { |
77 | } |
78 | |
79 | //======================================================================= |
80 | //function : TopOpeBRepBuild_FaceBuilder |
81 | //purpose : |
82 | //======================================================================= |
83 | TopOpeBRepBuild_FaceBuilder::TopOpeBRepBuild_FaceBuilder(TopOpeBRepBuild_WireEdgeSet& WES,const TopoDS_Shape& F,const Standard_Boolean ForceClass) |
84 | { |
85 | InitFaceBuilder(WES,F,ForceClass); |
86 | } |
87 | |
88 | //======================================================================= |
89 | //function : InitFaceBuilder |
90 | //purpose : |
91 | //======================================================================= |
92 | void TopOpeBRepBuild_FaceBuilder::InitFaceBuilder(TopOpeBRepBuild_WireEdgeSet& WES,const TopoDS_Shape& F,const Standard_Boolean ForceClass) |
93 | { |
94 | myFace = TopoDS::Face(F); |
0797d9d3 |
95 | #ifdef OCCT_DEBUG |
7fd59977 |
96 | Standard_Boolean deb = TopOpeBRepDS_GettraceSPSX(myFace); |
97 | if (deb) debifb(); |
98 | #endif |
99 | MakeLoops(WES); |
100 | TopOpeBRepBuild_BlockBuilder& BB = myBlockBuilder; |
101 | TopOpeBRepBuild_WireEdgeClassifier WEC(F,BB); |
102 | TopOpeBRepBuild_LoopSet& LS = myLoopSet; |
103 | myFaceAreaBuilder.InitFaceAreaBuilder(LS,WEC,ForceClass); |
7fd59977 |
104 | } |
105 | |
106 | //--------------------------------------------------------------- |
107 | void FUN_DetectVerticesOn1Edge(const TopoDS_Shape& W,TopTools_IndexedDataMapOfShapeShape& mapVon1E) |
108 | { |
109 | // Fills the map <mapVon1edge>,with vertices of <W> of 3d connexity 1. |
110 | TopTools_IndexedDataMapOfShapeListOfShape mapVedges; |
111 | TopExp::MapShapesAndAncestors(W,TopAbs_VERTEX,TopAbs_EDGE,mapVedges); |
112 | Standard_Integer nV = mapVedges.Extent(); |
113 | |
114 | for (Standard_Integer i = 1;i <= nV;i++) { |
115 | const TopoDS_Shape& V = mapVedges.FindKey(i); |
116 | if (V.Orientation() == TopAbs_INTERNAL) continue; |
117 | |
118 | const TopTools_ListOfShape& loE = mapVedges.FindFromIndex(i); |
119 | if (loE.Extent() < 2) { |
120 | // Keeping INTERNAL or EXTERNAL edges |
121 | const TopoDS_Shape& E = loE.First(); |
122 | TopAbs_Orientation oriE = E.Orientation(); |
123 | if ((oriE == TopAbs_INTERNAL) || (oriE == TopAbs_EXTERNAL)) continue; |
124 | mapVon1E.Add(V,E); |
125 | } |
126 | } |
127 | } |
128 | |
129 | #define ISUNKNOWN -1 |
130 | #define ISVERTEX 0 |
131 | #define GCLOSEDW 1 |
132 | #define UNCLOSEDW 2 |
133 | #define CLOSEDW 10 |
134 | Standard_Integer FUN_AnalyzemapVon1E(const TopTools_IndexedDataMapOfShapeShape& mapVon1E, |
135 | TopTools_IndexedDataMapOfShapeShape& mapVV) |
136 | { |
137 | #ifdef DRAW |
138 | Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE(); |
139 | if (trc) cout<<endl<<"* DetectUnclosedWire :"<<endl; |
140 | #endif |
141 | |
142 | Standard_Integer res = ISUNKNOWN; |
143 | |
144 | Standard_Integer nV = mapVon1E.Extent(); |
145 | if (nV == 0) { |
146 | res = CLOSEDW; |
147 | } |
148 | else if (nV == 1) { |
149 | const TopoDS_Shape& E = mapVon1E.FindFromIndex(1); |
da72a17c |
150 | Standard_Boolean Eclosed = BRep_Tool::IsClosed(E); |
7fd59977 |
151 | Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(E)); |
152 | if (dgE) res = ISVERTEX; |
153 | else if (Eclosed) res = CLOSEDW; |
154 | else res = UNCLOSEDW; |
155 | } |
156 | else { |
157 | // Finding among all vertices,couple of vertices falling on same |
158 | // geometry. |
159 | // Filling up map <mapVV>,with (vi,vj),vi and vj are on same point. |
160 | Standard_Real tol = Precision::Confusion(); |
161 | for (Standard_Integer i = 1;i <= nV;i++) { |
162 | const TopoDS_Vertex& vi = TopoDS::Vertex(mapVon1E.FindKey(i)); |
163 | gp_Pnt pi = BRep_Tool::Pnt(vi); |
164 | for (Standard_Integer j = i+1;j <= nV;j++) { |
165 | const TopoDS_Vertex& vj = TopoDS::Vertex(mapVon1E.FindKey(j)); |
166 | gp_Pnt pj = BRep_Tool::Pnt(vj); |
167 | Standard_Boolean same = pi.IsEqual(pj,tol); |
168 | if (same) { |
169 | mapVV.Add(vi,vj); |
170 | mapVV.Add(vj,vi); |
171 | break; |
172 | } |
173 | } // j |
174 | } // i |
175 | Standard_Integer nVV = mapVV.Extent(); |
176 | #ifdef RM_HANGING |
177 | // MSV Oct 4, 2001: consider GCLOSEDW even if not all vertices from mapVon1E |
178 | // hit into mapVV; reason is the left vertices may start |
179 | // useless chains of hanging edges that can be removed to |
180 | // achieve a closed wire. |
181 | if (nVV > 0) res = GCLOSEDW; |
182 | #else |
183 | if (nVV == nV) res = GCLOSEDW; |
184 | #endif |
185 | else res = UNCLOSEDW; |
186 | } |
187 | return res; |
188 | } // FUN_AnalyzemapVon1E |
189 | |
190 | #ifdef DRAW |
191 | void FUN_AnalyzemapVon1EDRAW(const Standard_Integer res, |
192 | const TopTools_IndexedDataMapOfShapeShape& mapVon1E, |
193 | const TopTools_IndexedDataMapOfShapeShape& mapVV, |
194 | const TopoDS_Shape& W,const Standard_Integer iiwi, |
195 | TopTools_IndexedDataMapOfShapeShape& mapVon1EdgeDRAW, |
196 | TopTools_IndexedDataMapOfShapeShape& mapVVsameGDRAW) |
197 | { |
198 | Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE(); |
199 | if (!trc) return; |
200 | cout<<"wire "<<iiwi; |
201 | if (res == ISVERTEX) { |
202 | cout<<" is vertex"<<endl; |
203 | } |
204 | else if (res == CLOSEDW) { |
205 | cout<<" is closed"<<endl; |
206 | } |
207 | else if (res == GCLOSEDW) { |
208 | cout<<" is Gclosed :"<<endl; |
209 | TCollection_AsciiString aa("w_");FUN_tool_draw(aa,W,iiwi); |
210 | Standard_Integer i ; |
211 | for ( i = 1;i <= mapVV.Extent();i++) { |
212 | Standard_Integer iV = mapVVsameGDRAW.Add(mapVV.FindKey(i),mapVV.FindFromIndex(i)); |
213 | cout<<" on vve_"<<iV; aa = "vve_"; |
214 | FUN_tool_draw(aa,mapVVsameGDRAW.FindKey(iV),iV); |
215 | } |
216 | for (i = 1;i <= mapVon1E.Extent();i++) { |
217 | Standard_Integer iE = mapVon1EdgeDRAW.Add(mapVon1E.FindKey(i),mapVon1E.FindFromIndex(i)); |
218 | cout<<" on eed_"<<iE; aa = "eed_"; |
219 | FUN_tool_draw(aa,mapVon1EdgeDRAW.FindFromIndex(iE),iE); |
220 | } |
221 | cout<<endl; |
222 | } |
223 | else if (res == UNCLOSEDW) { |
224 | cout<<" is unclosed "<<endl; |
225 | TCollection_AsciiString aa("w_");FUN_tool_draw(aa,W,iiwi); |
226 | } |
227 | cout<<endl; |
228 | } // FUN_AnalyzemapVon1EDRAW |
229 | #endif |
230 | |
231 | //======================================================================= |
232 | //function : DetectUnclosedWire |
233 | //purpose : |
234 | //======================================================================= |
235 | void TopOpeBRepBuild_FaceBuilder::DetectUnclosedWire(TopTools_IndexedDataMapOfShapeShape& mapVVsameG, |
236 | TopTools_IndexedDataMapOfShapeShape& mapVon1Edge) |
237 | { |
238 | // wire unclosed : has vertices of connexity == 1 |
239 | // exception : a wire of one closed edge with only one vertex describing |
240 | // a face or a degenerated edge. |
241 | |
242 | mapVVsameG.Clear(); |
243 | mapVon1Edge.Clear(); |
244 | |
245 | // During the wire processing, |
246 | // * IF THE WIRE IS G-CLOSED,we fill up the maps : |
247 | // - <mapVVsameG> with vertices falling on same geometry |
248 | // - <mapVon1Edge> with (key = vertex,item = edge), |
249 | // the vertex is connected to only one unclosed,undegenerated edge. |
250 | // * Else,if it is unclosed,we delete it (or it`s hanging edges). |
251 | |
252 | #ifdef DRAW |
253 | TopTools_IndexedDataMapOfShapeShape mapVon1EdgeDRAW,mapVVsameGDRAW; |
254 | Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE(); |
255 | if (trc) cout<<endl<<"* DetectUnclosedWire :"<<endl<<endl; |
256 | #endif |
257 | |
258 | Standard_Integer iiwi = 0; // DEB |
259 | |
260 | InitFace(); |
261 | for (;MoreFace();NextFace()) { |
262 | InitWire(); |
263 | for (;MoreWire();NextWire()) { |
264 | iiwi++; |
265 | Standard_Boolean isold = IsOldWire(); |
266 | #ifdef DRAW |
267 | if ( trc && isold ) cout<<"wire "<<iiwi<<" is old wire => closed"<<endl; |
268 | #endif |
269 | if (isold) continue; |
270 | |
271 | TopoDS_Compound cmp;BRep_Builder BB;BB.MakeCompound(cmp); |
272 | InitEdge(); |
273 | for(;MoreEdge();NextEdge()) AddEdgeWire(Edge(),cmp); |
274 | TopoDS_Shape W = cmp; |
275 | |
276 | // <mapVon1E> binds vertices of connexity 1 attached to one non-closed,non-degenerated edge. |
277 | TopTools_IndexedDataMapOfShapeShape mapVon1E; |
278 | FUN_DetectVerticesOn1Edge(W,mapVon1E); |
279 | |
280 | TopTools_IndexedDataMapOfShapeShape mapVV; |
281 | Standard_Integer res = FUN_AnalyzemapVon1E(mapVon1E,mapVV); |
282 | #ifdef DRAW |
283 | FUN_AnalyzemapVon1EDRAW(res,mapVon1E,mapVV,W,iiwi,mapVon1EdgeDRAW,mapVVsameGDRAW); |
284 | #endif |
285 | |
286 | if (res == ISVERTEX) { |
287 | continue; |
288 | } |
289 | else if (res == CLOSEDW) { |
290 | continue; |
291 | } |
292 | else if (res == GCLOSEDW) { |
293 | Standard_Integer i; |
294 | for (i = 1;i <= mapVV.Extent();i++) { |
295 | mapVVsameG.Add(mapVV.FindKey(i),mapVV.FindFromIndex(i)); |
296 | } |
297 | for (i = 1;i <= mapVon1E.Extent();i++) { |
298 | mapVon1Edge.Add(mapVon1E.FindKey(i),mapVon1E.FindFromIndex(i)); |
299 | } |
300 | } |
301 | else if (res == UNCLOSEDW) { |
302 | #ifdef RM_HANGING |
303 | // MSV Oct 4, 2001: remove hanging edges |
304 | TopTools_IndexedDataMapOfShapeListOfShape mapVE; |
305 | TopExp::MapShapesAndAncestors (W, TopAbs_VERTEX, TopAbs_EDGE, mapVE); |
306 | Standard_Integer nV = mapVon1E.Extent(); |
307 | for (Standard_Integer i = 1; i <= nV; i++) |
308 | { |
309 | TopoDS_Vertex V = TopoDS::Vertex (mapVon1E.FindKey(i)); |
310 | if (mapVV.Contains(V)) continue; // V is in same geometry pair |
311 | while (1) |
312 | { |
313 | const TopTools_ListOfShape &LE = mapVE.FindFromKey(V); |
314 | |
315 | // get not yet processed edge, count the number of such edges |
316 | Standard_Integer nEdges = 0; |
317 | TopoDS_Edge Edge; |
318 | TColStd_ListOfInteger LOI; |
319 | TopTools_ListIteratorOfListOfShape itE (LE); |
320 | for (; itE.More() && nEdges <= 1; itE.Next()) |
321 | { |
322 | const TopoDS_Edge &E = TopoDS::Edge (itE.Value()); |
323 | Standard_Integer I = myBlockBuilder.Element(E); |
da72a17c |
324 | if (!BRep_Tool::IsClosed(E) && myBlockBuilder.ElementIsValid(I)) |
7fd59977 |
325 | { |
326 | TopoDS_Vertex Vf,Vl; |
327 | TopExp::Vertices (E, Vf, Vl); |
328 | LOI.Append(I); |
329 | // consider not small edges only |
330 | if (!Vf.IsSame(Vl)) |
331 | { |
332 | Edge = E; |
333 | nEdges++; |
334 | } |
335 | } |
336 | } |
337 | if (nEdges != 1) break; // stop this chain |
338 | |
339 | // remove edges from Block Builder |
340 | TColStd_ListIteratorOfListOfInteger itLOI (LOI); |
341 | for (; itLOI.More(); itLOI.Next()) |
342 | myBlockBuilder.SetValid (itLOI.Value(), Standard_False); |
343 | |
344 | // get other vertex |
345 | TopoDS_Vertex aV1, aV2, otherV; |
346 | TopExp::Vertices (Edge, aV1, aV2); |
347 | if (aV1.IsSame (V)) |
348 | otherV = aV2; |
349 | else if (aV2.IsSame (V)) |
350 | otherV = aV1; |
351 | if (otherV.IsNull()) break; |
352 | V = otherV; |
353 | } |
354 | } |
355 | #else |
356 | TopExp_Explorer ex; |
357 | for (ex.Init(W,TopAbs_EDGE);ex.More();ex.Next()) { |
358 | // for (TopExp_Explorer ex(W,TopAbs_EDGE);ex.More();ex.Next()) { |
359 | Standard_Integer I = myBlockBuilder.Element(ex.Current()); |
360 | myBlockBuilder.SetValid(I,Standard_False); |
361 | } |
362 | #endif |
363 | } |
364 | } // MoreWire |
365 | } // MoreFace |
366 | } // DetectUnclosedWire |
367 | |
368 | //======================================================================= |
369 | //function : CorrectGclosedWire |
370 | //purpose : |
371 | //======================================================================= |
372 | void TopOpeBRepBuild_FaceBuilder::CorrectGclosedWire(const TopTools_IndexedDataMapOfShapeShape& mapVVref, |
373 | const TopTools_IndexedDataMapOfShapeShape& mapVon1Edge) |
374 | { |
375 | // prequesitory : edges described by <mapVon1Edge> are not closed,not degenerated |
0797d9d3 |
376 | #ifdef OCCT_DEBUG |
7fd59977 |
377 | Standard_Boolean trc = TopOpeBRepDS_GettraceSTRANGE(); |
378 | if (TopOpeBRepBuild_GettracePURGE()) { |
379 | cout<<endl<<"* CorrectGclosedWire :"<<endl<<endl; |
380 | trc = Standard_True; |
381 | } |
382 | #endif |
383 | |
384 | Standard_Integer nVV = mapVVref.Extent(); |
385 | for (Standard_Integer i = 1;i <= nVV;i++) { |
386 | const TopoDS_Vertex& V = TopoDS::Vertex(mapVVref.FindKey(i)); |
387 | const TopoDS_Vertex& Vref = TopoDS::Vertex(mapVVref.FindFromIndex(i)); |
388 | |
389 | if (V.IsSame(Vref)) continue; |
390 | |
391 | TopoDS_Edge E = TopoDS::Edge(mapVon1Edge.FindFromKey(V)); |
392 | Standard_Real paronE = BRep_Tool::Parameter(V,E); |
393 | |
394 | BRep_Builder BB;E.Free(Standard_True); |
395 | BB.Remove(E,V); |
396 | TopoDS_Shape aLocalShape = Vref.Oriented(V.Orientation()); |
397 | TopoDS_Vertex newVref = TopoDS::Vertex(aLocalShape); |
398 | // TopoDS_Vertex newVref = TopoDS::Vertex(Vref.Oriented(V.Orientation())); |
399 | BB.Add(E,newVref); |
0797d9d3 |
400 | #ifdef OCCT_DEBUG |
7fd59977 |
401 | Standard_Integer iV = i,iVref = mapVVref.FindIndex(Vref),iE = mapVon1Edge.FindIndex(V); |
402 | if (trc) cout << " replacing V "<<iV<<" with V "<<iVref<<" on edge "<<iE<<endl; |
403 | #endif |
404 | TopOpeBRepDS_BuildTool BT; |
405 | BT.Parameter(E,newVref,paronE); |
406 | } |
407 | } |
408 | |
409 | //======================================================================= |
410 | //function : DetectPseudoInternalEdge |
411 | //purpose : |
412 | //======================================================================= |
413 | void TopOpeBRepBuild_FaceBuilder::DetectPseudoInternalEdge(TopTools_IndexedMapOfShape& MapE) |
414 | { |
415 | TopoDS_Compound cmp;BRep_Builder BB;BB.MakeCompound(cmp); |
416 | InitFace(); |
417 | for (;MoreFace();NextFace()) { |
418 | InitWire(); |
419 | for (;MoreWire();NextWire()) { |
420 | Standard_Boolean isold = IsOldWire(); if (isold) continue; |
421 | InitEdge(); |
422 | for(;MoreEdge();NextEdge()) AddEdgeWire(Edge(),cmp); |
423 | } // MoreWire |
424 | } // MoreFace |
425 | |
426 | TopTools_IndexedDataMapOfShapeListOfShape mapVOE; |
427 | TopExp::MapShapesAndAncestors(cmp,TopAbs_VERTEX,TopAbs_EDGE,mapVOE); |
428 | Standard_Integer nv = mapVOE.Extent(); |
429 | |
430 | MapE.Clear(); |
431 | for (Standard_Integer i = 1; i <= nv; i++) { |
432 | const TopTools_ListOfShape& le = mapVOE.FindFromIndex(i); |
433 | Standard_Integer ne = le.Extent(); |
434 | if (ne == 2) { |
435 | TopTools_ListIteratorOfListOfShape ile(le); const TopoDS_Shape& e1 = ile.Value(); |
436 | ile.Next(); const TopoDS_Shape& e2 = ile.Value(); |
437 | Standard_Boolean same = e1.IsSame(e2); |
438 | TopAbs_Orientation o1 = e1.Orientation(); |
439 | TopAbs_Orientation o2 = e2.Orientation(); |
440 | Standard_Boolean o1co2 = (o1 == TopAbs::Complement(o2)); |
441 | |
442 | if ( same && o1co2 ) { |
443 | MapE.Add(e1); |
444 | |
445 | Standard_Integer ie1 = myBlockBuilder.Element(e1); |
446 | myBlockBuilder.SetValid(ie1,Standard_False); |
447 | |
448 | Standard_Integer ie2 = myBlockBuilder.Element(e2); |
449 | myBlockBuilder.SetValid(ie2,Standard_False); |
450 | } |
451 | } |
452 | } |
453 | |
454 | } |
455 | |
456 | //======================================================================= |
457 | //function : Face |
458 | //purpose : |
459 | //======================================================================= |
460 | const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::Face() const |
461 | { |
462 | return myFace; |
463 | } |
464 | |
465 | //======================================================================= |
466 | //function : InitFace |
467 | //purpose : |
468 | //======================================================================= |
469 | Standard_Integer TopOpeBRepBuild_FaceBuilder::InitFace() |
470 | { |
471 | Standard_Integer n = myFaceAreaBuilder.InitArea(); |
472 | return n; |
473 | } |
474 | |
475 | //======================================================================= |
476 | //function : MoreFace |
477 | //purpose : |
478 | //======================================================================= |
479 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreFace() const |
480 | { |
481 | Standard_Boolean b = myFaceAreaBuilder.MoreArea(); |
482 | return b; |
483 | } |
484 | |
485 | //======================================================================= |
486 | //function : NextFace |
487 | //purpose : |
488 | //======================================================================= |
489 | void TopOpeBRepBuild_FaceBuilder::NextFace() |
490 | { |
491 | myFaceAreaBuilder.NextArea(); |
492 | } |
493 | |
494 | //======================================================================= |
495 | //function : InitWire |
496 | //purpose : |
497 | //======================================================================= |
498 | Standard_Integer TopOpeBRepBuild_FaceBuilder::InitWire() |
499 | { |
500 | Standard_Integer n = myFaceAreaBuilder.InitLoop(); |
501 | return n; |
502 | } |
503 | |
504 | //======================================================================= |
505 | //function : MoreWire |
506 | //purpose : |
507 | //======================================================================= |
508 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreWire() const |
509 | { |
510 | Standard_Boolean b = myFaceAreaBuilder.MoreLoop(); |
511 | return b; |
512 | } |
513 | |
514 | //======================================================================= |
515 | //function : NextWire |
516 | //purpose : |
517 | //======================================================================= |
518 | void TopOpeBRepBuild_FaceBuilder::NextWire() |
519 | { |
520 | myFaceAreaBuilder.NextLoop(); |
521 | } |
522 | |
523 | //======================================================================= |
524 | //function : IsOldWire |
525 | //purpose : |
526 | //======================================================================= |
527 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::IsOldWire() const |
528 | { |
529 | const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop(); |
530 | Standard_Boolean b = L->IsShape(); |
531 | return b; |
532 | } |
533 | |
534 | //======================================================================= |
535 | //function : OldWire |
536 | //purpose : |
537 | //======================================================================= |
538 | const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::OldWire() const |
539 | { |
540 | const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop(); |
541 | const TopoDS_Shape& B = L->Shape(); |
542 | return B; |
543 | } |
544 | |
545 | //======================================================================= |
546 | //function : FindNextValidElement |
547 | //purpose : |
548 | //======================================================================= |
549 | void TopOpeBRepBuild_FaceBuilder::FindNextValidElement() |
550 | { |
551 | // prerequisites : myBlockIterator.Initialize |
552 | myFaceAreaBuilder.Loop(); |
553 | Standard_Boolean found = Standard_False; |
554 | |
555 | while ( myBlockIterator.More()) { |
556 | const Standard_Integer i = myBlockIterator.Value(); |
557 | found = myBlockBuilder.ElementIsValid(i); |
558 | if (found) break; |
559 | else myBlockIterator.Next(); |
560 | } |
561 | } |
562 | |
563 | //======================================================================= |
564 | //function : InitEdge |
565 | //purpose : |
566 | //======================================================================= |
567 | Standard_Integer TopOpeBRepBuild_FaceBuilder::InitEdge() |
568 | { |
569 | const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop(); |
570 | if ( L->IsShape() ) |
571 | Standard_DomainError::Raise("TopOpeBRepBuild_FaceBuilder:InitEdge"); |
572 | else { |
573 | myBlockIterator = L->BlockIterator(); |
574 | myBlockIterator.Initialize(); |
575 | FindNextValidElement(); |
576 | } |
577 | Standard_Integer n = myBlockIterator.Extent(); |
578 | return n; |
579 | } |
580 | |
581 | //======================================================================= |
582 | //function : MoreEdge |
583 | //purpose : |
584 | //======================================================================= |
585 | Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreEdge() const |
586 | { |
587 | Standard_Boolean b = myBlockIterator.More(); |
588 | return b; |
589 | } |
590 | |
591 | //======================================================================= |
592 | //function : NextEdge |
593 | //purpose : |
594 | //======================================================================= |
595 | void TopOpeBRepBuild_FaceBuilder::NextEdge() |
596 | { |
597 | myBlockIterator.Next(); |
598 | FindNextValidElement(); |
599 | } |
600 | |
601 | //======================================================================= |
602 | //function : Edge |
603 | //purpose : |
604 | //======================================================================= |
605 | const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::Edge() const |
606 | { |
607 | if (!myBlockIterator.More()) Standard_Failure::Raise("OutOfRange"); |
608 | |
609 | const Standard_Integer i = myBlockIterator.Value(); |
610 | Standard_Boolean isvalid = myBlockBuilder.ElementIsValid(i); |
611 | if (!isvalid) Standard_Failure::Raise("Edge not Valid"); |
612 | |
613 | const TopoDS_Shape& E = myBlockBuilder.Element(i); |
614 | return E; |
615 | } |
616 | |
617 | //======================================================================= |
618 | //function : EdgeConnexity |
619 | //purpose : |
620 | //======================================================================= |
621 | Standard_Integer TopOpeBRepBuild_FaceBuilder::EdgeConnexity(const TopoDS_Shape& /*E*/) const |
622 | { |
0797d9d3 |
623 | #ifdef OCCT_DEBUG |
7fd59977 |
624 | Standard_ProgramError::Raise("FaceBuilder::EdgeConnexity management disactivated"); |
625 | #endif |
626 | return 0; |
627 | // Standard_Boolean inmosi = myMOSI.IsBound(E); |
628 | // Standard_Integer nmosi = (inmosi) ? myMOSI.Find(E) : 0; |
629 | // return nmosi; |
630 | } |
631 | |
632 | //======================================================================= |
633 | //function : AddEdgeWire |
634 | //purpose : |
635 | //======================================================================= |
636 | Standard_Integer TopOpeBRepBuild_FaceBuilder::AddEdgeWire(const TopoDS_Shape& E,TopoDS_Shape& W) const |
637 | { |
638 | Standard_Integer nadd = 0; |
639 | BRep_Builder BB; |
640 | BB.Add(W,E);nadd++; |
641 | // Standard_Integer nmosi = EdgeConnexity(E); |
642 | // Standard_Boolean addEC = (nmosi == 1); |
643 | // if (addEC) { |
644 | // TopAbs_Orientation oe = E.Orientation(); |
645 | // TopAbs_Orientation oc = TopAbs::Complement(oe); |
646 | // TopoDS_Shape EC = E.Oriented(oc); |
647 | // BB.Add(W,EC);nadd++; |
648 | // } |
649 | return nadd; |
650 | } |
651 | |
652 | //======================================================================= |
653 | //function : MakeLoops |
654 | //purpose : |
655 | //======================================================================= |
656 | void TopOpeBRepBuild_FaceBuilder::MakeLoops(TopOpeBRepBuild_ShapeSet& SS) |
657 | { |
658 | TopOpeBRepBuild_BlockBuilder& BB = myBlockBuilder; |
659 | TopOpeBRepBuild_ListOfLoop& LL = myLoopSet.ChangeListOfLoop(); |
660 | |
661 | // Build blocks on elements of SS |
662 | BB.MakeBlock(SS); |
663 | |
664 | // make list of loop (LL) of the LoopSet |
665 | // - on shapes of the ShapeSet (SS) |
666 | // - on blocks of the BlockBuilder (BB) |
667 | |
668 | // Add shapes of SS as shape loops |
669 | LL.Clear(); |
670 | for(SS.InitShapes();SS.MoreShapes();SS.NextShape()) { |
671 | const TopoDS_Shape& S = SS.Shape(); |
672 | Handle(TopOpeBRepBuild_Loop) ShapeLoop = new TopOpeBRepBuild_Loop(S); |
673 | LL.Append(ShapeLoop); |
674 | } |
675 | |
676 | // Add blocks of BB as block loops |
677 | for (BB.InitBlock();BB.MoreBlock();BB.NextBlock()) { |
678 | TopOpeBRepBuild_BlockIterator BI = BB.BlockIterator(); |
679 | Handle(TopOpeBRepBuild_Loop) BlockLoop = new TopOpeBRepBuild_Loop(BI); |
680 | LL.Append(BlockLoop); |
681 | } |
682 | |
683 | } |