0027067: Avoid use of virtual methods for implementation of destructors in legacy...
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_Builder1_1.cxx
CommitLineData
b311480e 1// Created on: 1999-10-07
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//
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
7fd59977 18#include <BRep_Builder.hxx>
42cf5bc1 19#include <BRep_Tool.hxx>
20#include <BRepAdaptor_Curve.hxx>
21#include <BRepTools.hxx>
22#include <Geom_Curve.hxx>
23#include <gp_Pnt.hxx>
24#include <Precision.hxx>
25#include <Standard_NoSuchObject.hxx>
26#include <TCollection_AsciiString.hxx>
27#include <TColStd_ListIteratorOfListOfInteger.hxx>
7fd59977 28#include <TopExp.hxx>
7fd59977 29#include <TopoDS.hxx>
42cf5bc1 30#include <TopoDS_Edge.hxx>
31#include <TopoDS_Face.hxx>
32#include <TopoDS_Shape.hxx>
7fd59977 33#include <TopoDS_Vertex.hxx>
34#include <TopoDS_Wire.hxx>
42cf5bc1 35#include <TopOpeBRepBuild_Builder.hxx>
7fd59977 36#include <TopOpeBRepBuild_EdgeBuilder.hxx>
42cf5bc1 37#include <TopOpeBRepBuild_FaceBuilder.hxx>
38#include <TopOpeBRepBuild_GTool.hxx>
39#include <TopOpeBRepBuild_GTopo.hxx>
40#include <TopOpeBRepBuild_HBuilder.hxx>
7fd59977 41#include <TopOpeBRepBuild_ListOfListOfLoop.hxx>
42cf5bc1 42#include <TopOpeBRepBuild_Loop.hxx>
43#include <TopOpeBRepBuild_Pave.hxx>
44#include <TopOpeBRepBuild_PaveSet.hxx>
45#include <TopOpeBRepBuild_ShapeSet.hxx>
46#include <TopOpeBRepBuild_ShellFaceSet.hxx>
47#include <TopOpeBRepBuild_SolidBuilder.hxx>
7fd59977 48#include <TopOpeBRepBuild_Tools.hxx>
42cf5bc1 49#include <TopOpeBRepBuild_WireEdgeSet.hxx>
50#include <TopOpeBRepDS_BuildTool.hxx>
51#include <TopOpeBRepDS_CurveIterator.hxx>
7fd59977 52#include <TopOpeBRepDS_DataMapIteratorOfDataMapOfShapeState.hxx>
42cf5bc1 53#include <TopOpeBRepDS_DataMapOfShapeState.hxx>
54#include <TopOpeBRepDS_DataStructure.hxx>
55#include <TopOpeBRepDS_HDataStructure.hxx>
56#include <TopOpeBRepDS_IndexedDataMapOfShapeWithState.hxx>
7fd59977 57#include <TopOpeBRepDS_Interference.hxx>
7fd59977 58#include <TopOpeBRepDS_ListIteratorOfListOfInterference.hxx>
42cf5bc1 59#include <TopOpeBRepDS_ListOfInterference.hxx>
7fd59977 60#include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
42cf5bc1 61#include <TopOpeBRepDS_PointIterator.hxx>
62#include <TopOpeBRepDS_ShapeWithState.hxx>
63#include <TopOpeBRepDS_SurfaceIterator.hxx>
64#include <TopOpeBRepTool_ShapeExplorer.hxx>
7fd59977 65#include <TopTools_DataMapOfShapeListOfInteger.hxx>
42cf5bc1 66#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
67#include <TopTools_IndexedMapOfShape.hxx>
68#include <TopTools_MapIteratorOfMapOfShape.hxx>
69#include <TopTools_MapOfShape.hxx>
7fd59977 70
71//define parameter division number as 10*e^(-PI) = 0.43213918
72const Standard_Real PAR_T = 0.43213918;
73
74static TopAbs_State ClassifyEdgeToSolidByOnePoint(const TopoDS_Edge& E,
75 TopOpeBRepTool_ShapeClassifier& SC);
76
77//=======================================================================
78// : Definition the States of Shape's Entities for an Object
79// : and a Tool. Thu Oct 7 09:38:29 1999
80//=======================================================================
81
82static TopTools_IndexedMapOfShape processedEdges;
83static TopTools_IndexedMapOfShape theUsedVertexMap;
84static TopTools_MapOfShape theUnkStateVer;
85
1d0a9d4d 86extern Standard_Boolean GLOBAL_faces2d;
7fd59977 87
88//modified by NIZNHY-PKV Mon Dec 16 11:38:55 2002 f
89//=======================================================================
e6f550da 90//function : ~TopOpeBRepBuild_Builder1
7fd59977 91//purpose :
92//=======================================================================
e6f550da 93TopOpeBRepBuild_Builder1::~TopOpeBRepBuild_Builder1()
7fd59977 94{
95 processedEdges.Clear();
96 theUsedVertexMap.Clear();
97 theUnkStateVer.Clear();
98}
99//modified by NIZNHY-PKV Mon Dec 16 11:38:59 2002 t
100
101//=======================================================================
102//function : PerformShapeWithStates
103//purpose :
104//=======================================================================
105 void TopOpeBRepBuild_Builder1::PerformShapeWithStates()
106{
107 theUsedVertexMap.Clear();
108 theUnkStateVer.Clear();
109 myDataStructure -> ChangeDS().ChangeMapOfShapeWithStateObj().Clear();
110 myDataStructure -> ChangeDS().ChangeMapOfShapeWithStateTool().Clear();
111 //modified by NIZHNY-MZV Mon Feb 21 13:30:05 2000
112 //process section curves
113 Standard_Integer i, nbC = myDataStructure -> DS().NbCurves();
114 for(i = 1; i <= nbC; i++) {
115 TopTools_ListOfShape& LSE = ChangeNewEdges(i);
116 TopTools_ListIteratorOfListOfShape it(LSE);
117 for(; it.More(); it.Next()) {
118 const TopoDS_Shape& E = it.Value();
119 TopoDS_Vertex Vf, Vl;
120 TopExp::Vertices(TopoDS::Edge(E), Vf, Vl);
121 theUsedVertexMap.Add(Vf);
122 theUsedVertexMap.Add(Vl);
123 }
124 }
125
126 //process section edges
127 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
128 Standard_Integer n = BDS.NbSectionEdges();
129 for (i = 1; i <= n; i++) {
130 TopTools_ListIteratorOfListOfShape anIt;
131 const TopoDS_Edge& E = TopoDS::Edge(BDS.SectionEdge(i));
132 if(E.IsNull()) continue;
133
134 const TopTools_ListOfShape& SplitsON = Splits(E, TopAbs_ON);
135 anIt.Initialize (SplitsON);
136 for (; anIt.More(); anIt.Next()) {
137 TopoDS_Shape aNewEdge=anIt.Value();
138 TopoDS_Vertex Vf, Vl;
139 TopExp::Vertices(TopoDS::Edge(aNewEdge), Vf, Vl);
140 theUsedVertexMap.Add(Vf);
141 theUsedVertexMap.Add(Vl);
142 }
143
144 // IN
145 const TopTools_ListOfShape& SplitsIN = Splits(E, TopAbs_IN);
146 anIt.Initialize (SplitsIN);
147 for (; anIt.More(); anIt.Next()) {
148 TopoDS_Shape aNewEdge=anIt.Value();
149 TopoDS_Vertex Vf, Vl;
150 TopExp::Vertices(TopoDS::Edge(aNewEdge), Vf, Vl);
151 theUsedVertexMap.Add(Vf);
152 theUsedVertexMap.Add(Vl);
153 }
154
155 // OUT
156 const TopTools_ListOfShape& SplitsOUT = Splits(E, TopAbs_OUT);
157 anIt.Initialize (SplitsOUT);
158 for (; anIt.More(); anIt.Next()) {
159 TopoDS_Shape aNewEdge=anIt.Value();
160 TopoDS_Vertex Vf, Vl;
161 TopExp::Vertices(TopoDS::Edge(aNewEdge), Vf, Vl);
162 theUsedVertexMap.Add(Vf);
163 theUsedVertexMap.Add(Vl);
164 }
165 }
166
167 //modified by NIZHNY-MZV Tue Apr 11 17:32:05 2000
168 //1) Add both arguments to facilitate the search
169 TopOpeBRepDS_ShapeWithState aShapeWithState;
170 TopOpeBRepDS_DataStructure& aDataStructure=myDataStructure->ChangeDS();
171
172 TopOpeBRepDS_IndexedDataMapOfShapeWithState& aMapOfShapeWithStateObj=
173 aDataStructure.ChangeMapOfShapeWithStateObj();
174 TopOpeBRepDS_IndexedDataMapOfShapeWithState& aMapOfShapeWithStateTool=
175 aDataStructure.ChangeMapOfShapeWithStateTool();
176
177 aMapOfShapeWithStateObj.Add(myShape1, aShapeWithState);
178 aMapOfShapeWithStateTool.Add(myShape2, aShapeWithState);
179
180 //2) Add all rejected shapes as OUT
181
182 TopTools_IndexedMapOfShape& aMapOfRejectedShapesObj=
183 aDataStructure.ChangeMapOfRejectedShapesObj();
184 TopTools_IndexedMapOfShape& aMapOfRejectedShapesTool=
185 aDataStructure.ChangeMapOfRejectedShapesTool();
186
187 aShapeWithState.SetIsSplitted (Standard_False);
188 aShapeWithState.SetState (TopAbs_OUT);
189
190 Standard_Integer iW, j, nW, nE,
191 nRSObj = aMapOfRejectedShapesObj.Extent(),
192 nRSTool = aMapOfRejectedShapesTool.Extent();
193
194 for(i = 1; i <= nRSObj; i++) {
195 const TopoDS_Shape& aFace = aMapOfRejectedShapesObj(i);
196 if(aFace.ShapeType() != TopAbs_FACE)
197 continue;
198 TopTools_IndexedMapOfShape aWiresMap;
199
200 TopExp::MapShapes (aFace, TopAbs_WIRE, aWiresMap);
201 nW=aWiresMap.Extent ();
202 for (iW=1; iW<=nW; iW++) {
203 const TopoDS_Shape& aWire=aWiresMap(iW);
204 //
205 TopTools_IndexedMapOfShape anEdgesMap;
206 TopExp::MapShapes (aWire, TopAbs_EDGE, anEdgesMap);
207 nE=anEdgesMap.Extent ();
208 for (j=1; j<=nE; j++)
209 aMapOfShapeWithStateObj.Add(anEdgesMap(j), aShapeWithState); // add edge
210
211 aMapOfShapeWithStateObj.Add(aWire, aShapeWithState); // add wire
212 }
213 aMapOfShapeWithStateObj.Add(aFace, aShapeWithState); // add face
214 }
215
216 for(i = 1; i <= nRSTool; i++) {
217 const TopoDS_Shape& aFace = aMapOfRejectedShapesTool(i);
218 //modified by NIZHNY-MZV Wed Apr 5 10:27:18 2000
219 if(aFace.ShapeType() != TopAbs_FACE)
220 continue;
221 TopTools_IndexedMapOfShape aWiresMap;
222 TopExp::MapShapes (aFace, TopAbs_WIRE, aWiresMap);
223 nW=aWiresMap.Extent ();
224 for (iW=1; iW<=nW; iW++) {
225 const TopoDS_Shape& aWire=aWiresMap(iW);
226 //
227 TopTools_IndexedMapOfShape anEdgesMap;
228 TopExp::MapShapes (aWire, TopAbs_EDGE, anEdgesMap);
229 nE=anEdgesMap.Extent ();
230 for (j=1; j<=nE; j++)
231 aMapOfShapeWithStateTool.Add(anEdgesMap(j), aShapeWithState); // add edge
232
233 aMapOfShapeWithStateTool.Add(aWire, aShapeWithState); // add wire
234 }
235 aMapOfShapeWithStateTool.Add(aFace, aShapeWithState); // add face
236 }
237
238 PerformShapeWithStates (myShape1, myShape2);
239 processedEdges.Clear();
240 PerformShapeWithStates (myShape2, myShape1);
241 processedEdges.Clear();
242 // Print Block
243// printf(" ..::PerformShapeWithStates() [Dump is off]\n");
244
245/* printf(" ..::PerformShapeWithStates() [Dump is on]\n");
246
247 TopOpeBRepDS_DataStructure& aDS= myDataStructure-> ChangeDS();
248
249 TopOpeBRepDS_IndexedDataMapOfShapeWithState& aMapOfShapeWithStateObj=
250 aDS.ChangeMapOfShapeWithStateObj();
251
252 TopOpeBRepDS_IndexedDataMapOfShapeWithState& aMapOfShapeWithStateTool=
253 aDS.ChangeMapOfShapeWithStateTool();
254
255 TopOpeBRepBuild_Tools::DumpMapOfShapeWithState(0, aMapOfShapeWithStateObj);
256 TopOpeBRepBuild_Tools::DumpMapOfShapeWithState(1, aMapOfShapeWithStateTool);
257*/
258
259 // Phase#2 Phase ON
260// PerformOn2D ();
261}
262
263//=======================================================================
264//function :PerformShapeWithStates
265//purpose :
266//=======================================================================
267 void TopOpeBRepBuild_Builder1::PerformShapeWithStates (const TopoDS_Shape& anObj,
268 const TopoDS_Shape& aReference)
269{
270 myShapeClassifier.SetReference(aReference);
271 TopOpeBRepDS_DataStructure& aDS= myDataStructure-> ChangeDS();
272 // Get aMapOfShapeWithState for Obj
273 Standard_Boolean aFlag;
274 TopOpeBRepDS_IndexedDataMapOfShapeWithState& aMapOfShapeWithState=
275 aDS.ChangeMapOfShapeWithState(anObj, aFlag);
276 if (!aFlag) return;
277 //
278 Standard_Integer i, j, k, nS, nF, nE;
279
280 TopTools_IndexedMapOfShape aFacesMap, aFacesWithInterferencesMap, aFacesToRestMap;
281 TopOpeBRepDS_DataMapOfShapeState aSplFacesState;
282
283 TopTools_IndexedMapOfShape aShellsMap;
284 TopExp::MapShapes(anObj, TopAbs_SHELL, aShellsMap);
285
286 nS=aShellsMap.Extent();
287 for (i=1; i<=nS; i++) {
288 const TopoDS_Shape& aShell = aShellsMap(i);
289
290 if (aMapOfShapeWithState.Contains (aShell)) continue;
291
292 else if (!myDataStructure -> HasShape(aShell)) {
293 // Shell has no interference.
294 // So, define its state and push into the Map as is.// A.1
295 TopOpeBRepBuild_Tools::FindStateThroughVertex (aShell, myShapeClassifier,
296 aMapOfShapeWithState, theUnkStateVer);
297 continue;
298 }
299
300 else {// A.2
301 // Shell has interference. Try to separate it into FacesToRest and InterferredFace
302 aFacesMap.Clear();
303 aFacesWithInterferencesMap.Clear();
304 aFacesToRestMap.Clear();
305 aSplFacesState.Clear();
306
307 TopExp::MapShapes (aShell, TopAbs_FACE, aFacesMap);
308 nF=aFacesMap.Extent();
309 for (j=1; j<=nF; j++) {
310 const TopoDS_Shape& aFace = aFacesMap(j);
311
312 if (aMapOfShapeWithState.Contains (aFace)) {
313
314 // if the face is known, its edges are also known.
315 // We just insert this info. into aSplFacesState in order to
316 // propagate the state for faces with unknown states.
317 TopTools_IndexedMapOfShape anEdgesMap;
318 TopExp::MapShapes (aFace, TopAbs_EDGE, anEdgesMap);
319 nE=anEdgesMap.Extent();
320 for (k=1; k<=nE; k++) {
321 const TopoDS_Shape& anEdge=anEdgesMap(k);
322 const TopOpeBRepDS_ShapeWithState& aSWS=
323 aMapOfShapeWithState.FindFromKey(anEdge);
324 TopAbs_State aState=aSWS.State();
325 aSplFacesState.Bind (anEdge, aState);
326 }
327 continue;
328 }
329 else if (myDataStructure -> HasShape(aFace))
330 aFacesWithInterferencesMap.Add (aFace);
331 else {
332 aFacesToRestMap.Add (aFace);
333 }
334 } // ... next Face
335 // work with aFacesWithInterferencesMap
336 PerformFacesWithStates (anObj, aFacesWithInterferencesMap, aSplFacesState);
337
338 // Propagate the States for all unknown faces from aFacesToRestMap
339 TopTools_MapOfShape anUnkStateEdge;
340 TopOpeBRepBuild_Tools::PropagateState (aSplFacesState,aFacesToRestMap,
341 TopAbs_EDGE, TopAbs_FACE, myShapeClassifier,
342 aMapOfShapeWithState, anUnkStateEdge);
343 ///// Propagate on WIres from aFacesToRestMap
344 TopOpeBRepBuild_Tools::PropagateStateForWires (aFacesToRestMap, aMapOfShapeWithState);
345 } // end of else A.2
346 } // next Shell
347}
348
349//=======================================================================
350//function :PerformFacesWithStates
351//purpose :
352//=======================================================================
353 void TopOpeBRepBuild_Builder1::PerformFacesWithStates (const TopoDS_Shape& anObj,
354 const TopTools_IndexedMapOfShape& aFacesWithInterferencesMap,
355 TopOpeBRepDS_DataMapOfShapeState& aSplFacesState)
356{
357 TopOpeBRepDS_DataStructure& aDS= myDataStructure-> ChangeDS();
358 // Get aMapOfShapeWithState for Obj
359 Standard_Boolean aFlag;
360 TopOpeBRepDS_IndexedDataMapOfShapeWithState& aMapOfShapeWithState=aDS.ChangeMapOfShapeWithState(anObj, aFlag);
361 if (!aFlag) return;
362 //
363
364 Standard_Integer i, j, k, nF, nW, nE;
365
366 nF=aFacesWithInterferencesMap.Extent();
367
368 for (i=1; i<=nF; i++) {
369 TopTools_IndexedMapOfShape anEdgesToSplitMap, anEdgesToRestMap;
370
371 const TopoDS_Shape& aFace = aFacesWithInterferencesMap(i);
372
373 TopTools_IndexedMapOfShape aWireMap;
374 TopExp::MapShapes (aFace, TopAbs_WIRE, aWireMap);
375 nW=aWireMap.Extent();
376 for (j=1; j<=nW; j++) {
377 const TopoDS_Shape& aWire=aWireMap(j);
378
379 if (!myDataStructure -> HasShape(aWire)) {
380 // Wire has no interference.
381 // So, define its state and push into the Map as is.
382 TopOpeBRepBuild_Tools::FindStateThroughVertex (aWire, myShapeClassifier,
383 aMapOfShapeWithState, theUnkStateVer);
384 continue;
385 }
386
387 else {
388 // Wire has an interferences
389 TopTools_IndexedMapOfShape anEdgeMap;
390 TopExp::MapShapes (aWire, TopAbs_EDGE, anEdgeMap);
391 nE=anEdgeMap.Extent ();
392 for (k=1; k<=nE; k++) {
393 const TopoDS_Shape& anEdge=anEdgeMap(k);
394
395 if (myDataStructure -> HasShape(anEdge)) {
396 anEdgesToSplitMap.Add(anEdge);
397 }
398 else {
399 anEdgesToRestMap.Add(anEdge);
400 }
401 }
402
403 // split edges and define the states for all edges and parts of edges
404 StatusEdgesToSplit (anObj, anEdgesToSplitMap, anEdgesToRestMap);
405
406 ////// After StatusEdgesToSplit we can find the status of each Rest Edge
407 ////// in aMapOfShapeWithState. So we can insert this info. into
408 ////// aSplFacesState in order to propagate the state for faces.
409 nE=anEdgesToRestMap.Extent();
410 for (k=1; k<=nE; k++) {
411 const TopoDS_Shape anEdge=anEdgesToRestMap(k);
412 if (aMapOfShapeWithState.Contains (anEdge)) {
413 const TopOpeBRepDS_ShapeWithState& aSWS=aMapOfShapeWithState.FindFromKey(anEdge);
414 TopAbs_State aState=aSWS.State();
415 aSplFacesState.Bind (anEdge, aState);
416 }
417 }
418 } //end of else {// Wire has an interferences
419 } // next Wire
420 } // next interferred Face ... for (i=1; i<=nF; i++) ...
421}
422
423//=======================================================================
424//function :StatusEdgesToSplit
425//purpose :
426//=======================================================================
427 void TopOpeBRepBuild_Builder1::StatusEdgesToSplit (const TopoDS_Shape& anObj,
428 const TopTools_IndexedMapOfShape& anEdgesToSplitMap,
429 const TopTools_IndexedMapOfShape& anEdgesToRestMap)
430{
431
432
433 TopOpeBRepDS_DataStructure& aDS= myDataStructure-> ChangeDS();
434 // Get aMapOfShapeWithState for Obj
435 Standard_Boolean aFlag;
436 TopOpeBRepDS_IndexedDataMapOfShapeWithState& aMapOfShapeWithState=aDS.ChangeMapOfShapeWithState(anObj, aFlag);
437 if (!aFlag) return;
438 //
439
440 Standard_Integer i, nE=anEdgesToSplitMap.Extent();
441 if (!nE) return;
442
443 TopOpeBRepDS_DataMapOfShapeState aSplEdgesState;
444 TopTools_ListIteratorOfListOfShape anIt;
445 TopAbs_State aState;
446
447 for (i=1; i<=nE; i++) {
448 const TopoDS_Shape& anEdge=anEdgesToSplitMap(i);
449
450 if(processedEdges.Contains(anEdge)) {
451 if (aMapOfShapeWithState.Contains(anEdge)) {
452 const TopOpeBRepDS_ShapeWithState& aSWS=
453 aMapOfShapeWithState.FindFromKey(anEdge);
454 if (aSWS.IsSplitted()) {
455
456 const TopTools_ListOfShape& SplitsON=aSWS.Part(TopAbs_ON);
457 anIt.Initialize (SplitsON);
458 for (; anIt.More(); anIt.Next())
459 aSplEdgesState.Bind(anIt.Value(), TopAbs_ON);
460
461 const TopTools_ListOfShape& SplitsOUT=aSWS.Part(TopAbs_OUT);
462 anIt.Initialize (SplitsOUT);
463 for (; anIt.More(); anIt.Next())
464 aSplEdgesState.Bind(anIt.Value(), TopAbs_OUT);
465
466 const TopTools_ListOfShape& SplitsIN=aSWS.Part(TopAbs_IN);
467 anIt.Initialize (SplitsIN);
468 for (; anIt.More(); anIt.Next())
469 aSplEdgesState.Bind(anIt.Value(), TopAbs_IN);
470
471 }
472 }
473 continue;
474 }
475
476 processedEdges.Add(anEdge);
477
478 TopOpeBRepDS_ShapeWithState aShapeWithState;
479
480 // if IsSplit - it is the case of edges from SameDomain faces
481 Standard_Boolean IsSplitON = IsSplit(anEdge, TopAbs_ON);
482 if(IsSplitON) {
483 // ON
484 const TopTools_ListOfShape& SplitsON = Splits(anEdge, TopAbs_ON);
485 anIt.Initialize (SplitsON);
486 for (; anIt.More(); anIt.Next()) {
487 TopoDS_Shape aNewEdge=anIt.Value();
488 aNewEdge.Orientation (anEdge.Orientation());
489 aShapeWithState.AddPart (aNewEdge, TopAbs_ON);
490 aSplEdgesState.Bind(anIt.Value(), TopAbs_ON);
491 }
492
493 // IN
494 const TopTools_ListOfShape& SplitsIN = Splits(anEdge, TopAbs_IN);
495 anIt.Initialize (SplitsIN);
496 for (; anIt.More(); anIt.Next()) {
497 TopoDS_Shape aNewEdge=anIt.Value();
498 aNewEdge.Orientation (anEdge.Orientation());
499 aShapeWithState.AddPart (aNewEdge, TopAbs_IN);
500 aSplEdgesState.Bind(anIt.Value(), TopAbs_IN);
501 }
502
503 // OUT
504 const TopTools_ListOfShape& SplitsOUT = Splits(anEdge, TopAbs_OUT);
505 anIt.Initialize (SplitsOUT);
506 for (; anIt.More(); anIt.Next()) {
507 TopoDS_Shape aNewEdge=anIt.Value();
508 aNewEdge.Orientation (anEdge.Orientation());
509 aShapeWithState.AddPart (aNewEdge, TopAbs_OUT);
510 aSplEdgesState.Bind(anIt.Value(), TopAbs_OUT);
511 }
512
513 aShapeWithState.SetIsSplitted(Standard_True);
514 aMapOfShapeWithState.Add(anEdge, aShapeWithState);
515 continue;
516 }
517
518 // Attempt to split the Edge (for all other edges (from non SameDomain Faces))
519 TopOpeBRepDS_DataMapOfShapeState aDataMapOfShapeState;
520 TopTools_ListOfShape aLNew;
521
522 Standard_Boolean oldState = GLOBAL_faces2d;
523
524 GLOBAL_faces2d = Standard_True;
525 SplitEdge (anEdge, aLNew, aDataMapOfShapeState);
526 GLOBAL_faces2d = oldState;
527
528 //
529 if (!aLNew.Extent()) {
530 // * It means that whole Edge is IN (see SplitEdge(...) at line
531 // G1=TopOpeBRepBuild_GTool::GFusSame(tf,tf); Operation Fuse
532 // loses all parts of the Edge with IN state, but we need
533 // to have all parts. So, we have to rest the Edge as is ...
534 // ** But the edge itself will have UNKNOWN state and one split Part with state =IN.
535 TopoDS_Vertex Vf, Vl;
536 TopExp::Vertices(TopoDS::Edge(anEdge), Vf, Vl);
537
538 Standard_Boolean HasSDV1 = myDataStructure->HasSameDomain(Vf);
539 Standard_Boolean HasSDV2 = myDataStructure->HasSameDomain(Vl);
540
541 TopoDS_Edge aNewEdge = TopoDS::Edge(anEdge);
542
543 //if edge has SD edges , it is error because it must be processed in SplitSectionEdges
544 //but if we here we don't do anything with it
545 if(myDataStructure -> HasSameDomain(aNewEdge)) {
546 HasSDV1 = Standard_False;
547 HasSDV2 = Standard_False;
548 }
549 //if vertices has SD we must update edge, so we copy it
550 if(HasSDV1 || HasSDV2) {
551 TopoDS_Shape EOR = anEdge;
552 EOR.Orientation(TopAbs_FORWARD);
553
554 Standard_Real ParF = BRep_Tool::Parameter(Vf, TopoDS::Edge(EOR));
555 Standard_Real ParL = BRep_Tool::Parameter(Vl, TopoDS::Edge(EOR));
556 myBuildTool.CopyEdge (EOR, aNewEdge);
557
558 if (HasSDV1) { // on prend le vertex reference de V
559 Standard_Integer iref = myDataStructure->SameDomainReference(Vf);
560 Vf = TopoDS::Vertex(myDataStructure->Shape(iref));
561 Vf.Orientation(TopAbs_FORWARD);
562 }
563
564 if (HasSDV2) { // on prend le vertex reference de V
565 Standard_Integer iref = myDataStructure->SameDomainReference(Vl);
566 Vl = TopoDS::Vertex(myDataStructure->Shape(iref));
567 Vl.Orientation(TopAbs_REVERSED);
568 }
7fd59977 569
570 myBuildTool.AddEdgeVertex (aNewEdge, Vf);
571 myBuildTool.Parameter (aNewEdge, Vf, ParF);
572
573 myBuildTool.AddEdgeVertex (aNewEdge, Vl);
574 myBuildTool.Parameter (aNewEdge, Vl, ParL);
575
576 aNewEdge.Orientation (anEdge.Orientation());
577 }
578
579 aState= ClassifyEdgeToSolidByOnePoint(aNewEdge, myShapeClassifier);
580 aShapeWithState.SetIsSplitted (Standard_True);
581
582 aShapeWithState.AddPart (aNewEdge, aState);
583 aSplEdgesState.Bind(aNewEdge, aState);
584
585 TopExp::Vertices(aNewEdge, Vf, Vl);
586 theUsedVertexMap.Add(Vf);
587 theUsedVertexMap.Add(Vl);
588 if (!BRep_Tool::Degenerated(TopoDS::Edge(aNewEdge))) {
589 // MSV: it may be the case when an edge has one state but its vertex
590 // has another state. We should clarify this to avoid incorrect
591 // propagation of state.
592 myShapeClassifier.StateP3DReference(BRep_Tool::Pnt(Vf));
593 if (myShapeClassifier.State() != aState && myShapeClassifier.State() != TopAbs_ON)
594 theUnkStateVer.Add(Vf);
595 if (!Vf.IsSame(Vl)) {
596 myShapeClassifier.StateP3DReference(BRep_Tool::Pnt(Vl));
597 if (myShapeClassifier.State() != aState && myShapeClassifier.State() != TopAbs_ON)
598 theUnkStateVer.Add(Vl);
599 }
600 }
601 }
602 else {
603 // Usual case. The Edge was splitted onto several parts:
604 TopTools_ListIteratorOfListOfShape aLIt(aLNew);
605 for (; aLIt.More(); aLIt.Next()) {
606 const TopoDS_Shape& aS = aLIt.Value();
607 aState = aDataMapOfShapeState(aS);
608 ////////////////////////////////////////////////////////////////////////////
609 // ** When aState==TopAbs_IN it is not evidence that it is realy so.
610 // There are some cases when JYL does not define ON parts completely.
611 // So, as we want to have right states, we have to do it ourselves.
612 // PKV Mon 25 Oct 1999
613 Standard_Boolean isdegen = BRep_Tool::Degenerated(TopoDS::Edge(aS));
614 //if edge is degenerated we trust that it have IN state without classify
615
616 if (aState==TopAbs_IN && !isdegen)
617 aState= ClassifyEdgeToSolidByOnePoint(TopoDS::Edge(aS), myShapeClassifier);
618
619 ////////////////////////////////////////////////////////////////////////////
620 aShapeWithState.AddPart (aS, aState);
621 aShapeWithState.SetIsSplitted (Standard_True);
622
623 aSplEdgesState.Bind(aS, aState);
624 TopoDS_Vertex Vf, Vl;
625 TopExp::Vertices(TopoDS::Edge(aS), Vf, Vl);
626 theUsedVertexMap.Add(Vf);
627 theUsedVertexMap.Add(Vl);
628 if (!isdegen) {
629 // MSV: clarify state of vertices (see my above comment)
630 myShapeClassifier.StateP3DReference(BRep_Tool::Pnt(Vf));
631 if (myShapeClassifier.State() != aState && myShapeClassifier.State() != TopAbs_ON)
632 theUnkStateVer.Add(Vf);
633 if (!Vf.IsSame(Vl)) {
634 myShapeClassifier.StateP3DReference(BRep_Tool::Pnt(Vl));
635 if (myShapeClassifier.State() != aState && myShapeClassifier.State() != TopAbs_ON)
636 theUnkStateVer.Add(Vl);
637 }
638 }
639 }
640 }
641
642 const TopTools_ListOfShape& EspON = aShapeWithState.Part(TopAbs_ON);
643
644 Standard_Integer nON = EspON.Extent();
645 if(!IsSplitON && nON) {
646 TopOpeBRepDS_ListOfShapeOn1State ONspl;
647 TopTools_ListOfShape& lON = ONspl.ChangeListOnState();
648 lON.Assign(EspON);
649 ONspl.Split(Standard_True);
650 mySplitON.Bind(anEdge, ONspl);
651 myDataStructure -> ChangeDS().AddSectionEdge(TopoDS::Edge(anEdge));
652 }
653
654 aMapOfShapeWithState.Add(anEdge, aShapeWithState);
655 } // end for (i=1; i<=nE; i++)
656
657 nE=anEdgesToRestMap.Extent();
658 for (i=1; i<=nE; i++) {
659 const TopoDS_Shape& anEdge=anEdgesToRestMap.FindKey(i);
660 if (aMapOfShapeWithState.Contains (anEdge)) {
661 const TopOpeBRepDS_ShapeWithState& aSWS=
662 aMapOfShapeWithState.FindFromKey(anEdge);
663 if (!aSWS.IsSplitted()) {
664 // just in case
665 aState=aSWS.State();
666 aSplEdgesState.Bind (anEdge, aState);
667 continue;
668 }
669 }
670 }
671
672 if (nE)
673 // Propagate the status for anEdgesToRestMap edges
674 TopOpeBRepBuild_Tools::PropagateState (aSplEdgesState, anEdgesToRestMap,
675 TopAbs_VERTEX, TopAbs_EDGE, myShapeClassifier,
676 aMapOfShapeWithState, theUnkStateVer);
677
678}
679
680
681
682//=======================================================================
683//function : SplitEdge
684//purpose :
685//=======================================================================
686 void TopOpeBRepBuild_Builder1::SplitEdge (const TopoDS_Shape& anEdge,
687 TopTools_ListOfShape& aLNew,
688 TopOpeBRepDS_DataMapOfShapeState& aDataMapOfShapeState)
689{
690 Standard_Real aPar1, aPar2;
691 TopAbs_Orientation anOr1, anOr2;
692
693 // Attention! If you didn't do the orientation of the Edge =FORWARD,
694 // the GFillPointTopologyPVS() method will give you a garbage!
695 TopoDS_Shape EdgeF=anEdge;
696 EdgeF.Orientation(TopAbs_FORWARD);
697
698 // Make a PaveSet PVS on edge EF
699 TopOpeBRepBuild_PaveSet PVS (EdgeF);
700 TopOpeBRepBuild_GTopo G1;
701 TopAbs_ShapeEnum tf = TopAbs_FACE;
702 G1=TopOpeBRepBuild_GTool::GFusSame(tf,tf);
703 myEdgeReference = TopoDS::Edge(EdgeF);
704
705 GFillPointTopologyPVS(EdgeF, G1, PVS);
706
707 PVS.InitLoop();
708
709 //firstly we detect paves with equal params
710
711 // MSV Oct 23, 2001:
712 // Add Paves to a standard list rather than to a PaveSet to avoid
713 // possible sequence disturbance in InitLoop.
714 // Check points for equality in both 3d and 1d spaces using maximum
715 // of tolerances of the edge and compared vertices, in 1d using resolution
716 // on edge from that value
717
718 TopOpeBRepBuild_ListOfPave aPVSlist;
719 TopTools_DataMapOfShapeListOfInteger aVerOriMap;
720
721 BRepAdaptor_Curve aCurveAdaptor(TopoDS::Edge(anEdge));
722 Standard_Real tolEdge = BRep_Tool::Tolerance(TopoDS::Edge(anEdge));
723
724 while (PVS.MoreLoop()) {
725 Handle(TopOpeBRepBuild_Pave) aPave1=Handle(TopOpeBRepBuild_Pave)::DownCast(PVS.Loop());
726 const TopoDS_Vertex& aV1= TopoDS::Vertex(aPave1->Vertex());
727 aPar1 = aPave1->Parameter();
728
729 PVS.NextLoop();
730 if (!PVS.MoreLoop()) {
731 aPVSlist.Append(aPave1);
732 break;
733 }
734
735 Handle(TopOpeBRepBuild_Pave) aPave2=Handle(TopOpeBRepBuild_Pave)::DownCast(PVS.Loop());
736 const TopoDS_Vertex& aV2= TopoDS::Vertex(aPave2->Vertex());
737 aPar2 = aPave2->Parameter();
738
739 Standard_Real tolV1 = BRep_Tool::Tolerance(aV1);
740 Standard_Real tolV2 = BRep_Tool::Tolerance(aV2);
741 Standard_Real tolMax = Max(tolEdge,Max(tolV1,tolV2));
742 Standard_Real resol = aCurveAdaptor.Resolution(tolMax);
743 Standard_Real delta = Abs(aPar1 - aPar2);
744
745 if(delta < resol) {
746 Standard_Real dist = BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
747 if (dist < tolMax || delta < Precision::PConfusion()) {
748
749 TopOpeBRepDS_Kind IntType1 = aPave1 -> InterferenceType();
750 Standard_Boolean Int3d1 = (IntType1 == TopOpeBRepDS_FACE);
751 Standard_Boolean HasSDV1 = myDataStructure->HasSameDomain(aV1);
752 Standard_Boolean HasSDV2 = myDataStructure->HasSameDomain(aV2);
753 Standard_Boolean UsedV1 = theUsedVertexMap.Contains(aV1);
754 Standard_Boolean UsedV2 = theUsedVertexMap.Contains(aV2);
755
756 Standard_Boolean takeFirst = Standard_True;
757 if(HasSDV1) ;
758 else if(HasSDV2) takeFirst = Standard_False;
759 else if(UsedV1) ;
760 else if(UsedV2) takeFirst = Standard_False;
761 else if(Int3d1) ;
762 else takeFirst = Standard_False;
763 TopoDS_Shape aVer;
764 Standard_Boolean HasSDV;
765 TopAbs_Orientation anOriOpp;
766 if (takeFirst) {
767 aPVSlist.Append(aPave1);
768 aVer = aV1; HasSDV = HasSDV1; anOriOpp = aV2.Orientation();
769 }
770 else {
771 aPVSlist.Append(aPave2);
772 aVer = aV2; HasSDV = HasSDV2; anOriOpp = aV1.Orientation();
773 }
774
775 if (aV1.Orientation() != aV2.Orientation()) {
776 // MSV: save orientation of removed vertex
777 TColStd_ListOfInteger thelist;
778 if (!aVerOriMap.IsBound(aVer)) aVerOriMap.Bind(aVer, thelist);
779 TColStd_ListOfInteger& anOriList = aVerOriMap(aVer);
780 anOriList.Append(takeFirst);
781 anOriList.Append(anOriOpp);
782 // mark this vertex as having unknown state
783 if (HasSDV) {
784 Standard_Integer iref = myDataStructure->SameDomainReference(aVer);
785 aVer = myDataStructure->Shape(iref);
786 }
787 theUnkStateVer.Add(aVer);
788 }
789
790 PVS.NextLoop();
791 continue;
792 }
793 }
794 aPVSlist.Append(aPave1);
795 }
796
797 TopOpeBRepBuild_ListIteratorOfListOfPave aPVSit(aPVSlist);
798 while (aPVSit.More()) {
799 Handle(TopOpeBRepBuild_Pave) aPave1 = aPVSit.Value();
800 TopoDS_Shape aV1= aPave1->Vertex();
801 aV1.Orientation(TopAbs_FORWARD);
802 aPar1 = aPave1->Parameter();
803 anOr1=(aPave1->Vertex()).Orientation();
804 if (aVerOriMap.IsBound(aV1)) {
805 // MSV: restore orientation of removed vertex
806 TColStd_ListOfInteger& anOriList = aVerOriMap(aV1);
807 if (!anOriList.IsEmpty()) {
808 if (anOriList.First()) {
809 TColStd_ListIteratorOfListOfInteger it(anOriList); it.Next();
810 anOr1 = (TopAbs_Orientation) it.Value();
811 }
812 anOriList.RemoveFirst(); anOriList.RemoveFirst();
813 }
814 }
815
816 aPVSit.Next();
817
818 if (!aPVSit.More()) break;
819
820 Handle(TopOpeBRepBuild_Pave) aPave2 = aPVSit.Value();
821 TopoDS_Shape aV2= aPave2->Vertex();
822 aV2.Orientation(TopAbs_REVERSED);
823 aPar2 = aPave2->Parameter();
824 anOr2=(aPave2->Vertex()).Orientation();
825 if (aVerOriMap.IsBound(aV2)) {
826 TColStd_ListOfInteger& anOriList = aVerOriMap(aV2);
827 if (!anOriList.IsEmpty()) {
828 if (!anOriList.First()) {
829 TColStd_ListIteratorOfListOfInteger it(anOriList); it.Next();
830 anOr2 = (TopAbs_Orientation) it.Value();
831 }
832 }
833 }
834
835 // MSV: avoid creation of an edge with invalid range
836 if (aPar1 > aPar2) continue;
837
838 Standard_Boolean HasSDV1 = myDataStructure->HasSameDomain(aV1);
839 Standard_Boolean HasSDV2 = myDataStructure->HasSameDomain(aV2);
840 if (HasSDV1) { // on prend le vertex reference de V
841 Standard_Integer iref = myDataStructure->SameDomainReference(aV1);
842 aV1 = myDataStructure->Shape(iref);
843 aV1.Orientation(TopAbs_FORWARD);
844 }
845
846 if (HasSDV2) { // on prend le vertex reference de V
847 Standard_Integer iref = myDataStructure->SameDomainReference(aV2);
848 aV2 = myDataStructure->Shape(iref);
849 aV2.Orientation(TopAbs_REVERSED);
850 }
851
852 // Make new edge from EdgeF
853 TopoDS_Edge aNewEdge;
854 myBuildTool.CopyEdge (EdgeF, aNewEdge);
7fd59977 855
856 myBuildTool.AddEdgeVertex (aNewEdge, aV1);
857 myBuildTool.Parameter (aNewEdge, aV1, aPar1);
858
859 myBuildTool.AddEdgeVertex (aNewEdge, aV2);
860 myBuildTool.Parameter (aNewEdge, aV2, aPar2);
861 // State of piece
862
863
864 TopAbs_State aState=TopAbs_IN;
865
866 if (anOr1==TopAbs_FORWARD && anOr2==TopAbs_REVERSED) aState=TopAbs_OUT;
867 if (anOr1==TopAbs_FORWARD && anOr2==TopAbs_INTERNAL) aState=TopAbs_OUT;
868 if (anOr1==TopAbs_INTERNAL && anOr2==TopAbs_REVERSED) aState=TopAbs_OUT;
869 ///* Added
870 if (anOr1==TopAbs_INTERNAL && anOr2==TopAbs_INTERNAL) aState=TopAbs_OUT;
871 //printf(" anOr1=%d, anOr2=%d\n", anOr1, anOr2);
872
873 // set old orientation to new edge;
874 aNewEdge.Orientation (anEdge.Orientation());
875 aLNew.Append(aNewEdge);
876 aDataMapOfShapeState.Bind(aNewEdge, aState);
877 }
878 //GEDBUMakeEdges(EdgeF,EDBU,aListOfShape);
879}
880
881static TopAbs_State ClassifyEdgeToSolidByOnePoint(const TopoDS_Edge& E,
882 TopOpeBRepTool_ShapeClassifier& SC)
883{
884 Standard_Real f2 = 0., l2 = 0., par = 0.;
885
886 Handle(Geom_Curve) C3D = BRep_Tool::Curve(E, f2, l2);
887 gp_Pnt aP3d;
888
889 if(C3D.IsNull()) {
890 //it means that we are in degenerated edge
891 const TopoDS_Vertex& fv = TopExp::FirstVertex(E);
892 if(fv.IsNull())
893 return TopAbs_UNKNOWN;
894 aP3d = BRep_Tool::Pnt(fv);
895 }
896 else {//usual case
897 par = f2*PAR_T + (1 - PAR_T)*l2;
898 C3D -> D0(par, aP3d);
899 }
900
901 SC.StateP3DReference(aP3d);
902
903 return SC.State();
904}