1 // Created on: 1993-06-23
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-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.
18 #include <Geom_Surface.hxx>
19 #include <Standard_ProgramError.hxx>
21 #include <TopoDS_Edge.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopOpeBRepDS_Curve.hxx>
24 #include <TopOpeBRepDS_CurveData.hxx>
25 #include <TopOpeBRepDS_CurveExplorer.hxx>
26 #include <TopOpeBRepDS_DataStructure.hxx>
27 #include <TopOpeBRepDS_define.hxx>
28 #include <TopOpeBRepDS_Interference.hxx>
29 #include <TopOpeBRepDS_Point.hxx>
30 #include <TopOpeBRepDS_PointData.hxx>
31 #include <TopOpeBRepDS_PointExplorer.hxx>
32 #include <TopOpeBRepDS_ShapeData.hxx>
33 #include <TopOpeBRepDS_ShapeWithState.hxx>
34 #include <TopOpeBRepDS_Surface.hxx>
35 #include <TopOpeBRepDS_SurfaceData.hxx>
36 #include <TopOpeBRepDS_SurfaceExplorer.hxx>
37 #include <TopOpeBRepTool_ShapeTool.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 //=======================================================================
41 //function : TopOpeBRepDS_DataStructure
43 //=======================================================================
44 TopOpeBRepDS_DataStructure::TopOpeBRepDS_DataStructure() :
48 myIsfafa(Standard_False),
53 //=======================================================================
56 //=======================================================================
57 void TopOpeBRepDS_DataStructure::Init()
66 //Begin modified by NIZHNY-MZV Tue Apr 18 16:33:26 2000
67 myMapOfShapeWithStateObj.Clear();
68 myMapOfShapeWithStateTool.Clear();
69 myMapOfRejectedShapesObj.Clear();
70 myMapOfRejectedShapesTool.Clear();
71 //End modified by NIZHNY-MZV Tue Apr 18 16:33:32 2000
76 //=======================================================================
77 //function : AddSurface
79 //=======================================================================
80 Standard_Integer TopOpeBRepDS_DataStructure::AddSurface(const TopOpeBRepDS_Surface& S)
83 //modified by NIZNHY-PKV Tue Oct 30 09:22:04 2001 f
84 TopOpeBRepDS_SurfaceData aSD(S);
85 mySurfaces.Bind(myNbSurfaces, aSD);
86 //mySurfaces.Bind(myNbSurfaces,S);
87 //modified by NIZNHY-PKV Tue Oct 30 09:22:20 2001 t
92 //=======================================================================
93 //function : RemoveSurface
95 //=======================================================================
96 void TopOpeBRepDS_DataStructure::RemoveSurface(const Standard_Integer I)
101 //=======================================================================
102 //function : KeepSurface
104 //=======================================================================
105 Standard_Boolean TopOpeBRepDS_DataStructure::KeepSurface(const Standard_Integer I) const
107 const TopOpeBRepDS_Surface& S = Surface(I);
108 Standard_Boolean b = S.Keep();
112 //=======================================================================
113 //function : KeepSurface
115 //=======================================================================
116 Standard_Boolean TopOpeBRepDS_DataStructure::KeepSurface(TopOpeBRepDS_Surface& S) const
118 Standard_Boolean b = S.Keep();
122 //=======================================================================
123 //function : ChangeKeepSurface
125 //=======================================================================
126 void TopOpeBRepDS_DataStructure::ChangeKeepSurface(const Standard_Integer I,const Standard_Boolean FindKeep)
128 TopOpeBRepDS_Surface& S = ChangeSurface(I);
129 S.ChangeKeep(FindKeep);
132 //=======================================================================
133 //function : ChangeKeepSurface
135 //=======================================================================
136 void TopOpeBRepDS_DataStructure::ChangeKeepSurface(TopOpeBRepDS_Surface& S,const Standard_Boolean FindKeep)
138 S.ChangeKeep(FindKeep);
141 //=======================================================================
142 //function : AddCurve
144 //=======================================================================
145 Standard_Integer TopOpeBRepDS_DataStructure::AddCurve(const TopOpeBRepDS_Curve& C)
149 // NYI : modifier const & sur Curve dans le CDL NYI
150 TopOpeBRepDS_Curve* PC = (TopOpeBRepDS_Curve*)(void*)&C;
151 PC->ChangeDSIndex(myNbCurves);
153 TopOpeBRepDS_CurveData CD(C);
154 myCurves.Bind(myNbCurves,CD);
159 //=======================================================================
160 //function : RemoveCurve
162 //=======================================================================
163 void TopOpeBRepDS_DataStructure::RemoveCurve(const Standard_Integer I)
165 TopOpeBRepDS_Curve& C = ChangeCurve(I);
169 Handle(TopOpeBRepDS_Interference) I1,I2;
171 if ( ! I1.IsNull() ) RemoveShapeInterference(S1,I1);
172 if ( ! I2.IsNull() ) RemoveShapeInterference(S2,I2);
173 C.ChangeKeep(Standard_False);
175 // NYI : nullify interferences I1,I2
178 //=======================================================================
179 //function : KeepCurve
181 //=======================================================================
182 Standard_Boolean TopOpeBRepDS_DataStructure::KeepCurve(const Standard_Integer I) const
184 const TopOpeBRepDS_Curve& C = Curve(I);
185 Standard_Boolean b = C.Keep();
189 //=======================================================================
190 //function : KeepCurve
192 //=======================================================================
193 Standard_Boolean TopOpeBRepDS_DataStructure::KeepCurve(const TopOpeBRepDS_Curve& C) const
195 Standard_Boolean b = C.Keep();
199 //=======================================================================
200 //function : ChangeKeepCurve
202 //=======================================================================
203 void TopOpeBRepDS_DataStructure::ChangeKeepCurve(const Standard_Integer I,const Standard_Boolean FindKeep)
205 TopOpeBRepDS_Curve& C = ChangeCurve(I);
206 C.ChangeKeep(FindKeep);
209 //=======================================================================
210 //function : ChangeKeepCurve
212 //=======================================================================
213 void TopOpeBRepDS_DataStructure::ChangeKeepCurve(TopOpeBRepDS_Curve& C,const Standard_Boolean FindKeep)
215 C.ChangeKeep(FindKeep);
219 //=======================================================================
220 //function : AddPoint
222 //=======================================================================
223 Standard_Integer TopOpeBRepDS_DataStructure::AddPoint(const TopOpeBRepDS_Point& PDS)
226 myPoints.Bind(myNbPoints,PDS);
230 //=======================================================================
231 //function : AddPointSS
233 //=======================================================================
234 Standard_Integer TopOpeBRepDS_DataStructure::AddPointSS(const TopOpeBRepDS_Point& PDS,
235 const TopoDS_Shape& /*S1*/,
236 const TopoDS_Shape& /*S2*/)
238 Standard_Integer i = AddPoint(PDS);
243 //=======================================================================
244 //function : RemovePoint
246 //=======================================================================
247 void TopOpeBRepDS_DataStructure::RemovePoint(const Standard_Integer I)
249 TopOpeBRepDS_Point& P = ChangePoint(I);
250 P.ChangeKeep(Standard_False);
253 //=======================================================================
254 //function : KeepPoint
256 //=======================================================================
257 Standard_Boolean TopOpeBRepDS_DataStructure::KeepPoint(const Standard_Integer I) const
259 const TopOpeBRepDS_Point& P = Point(I);
260 Standard_Boolean b = P.Keep();
264 //=======================================================================
265 //function : KeepPoint
267 //=======================================================================
268 Standard_Boolean TopOpeBRepDS_DataStructure::KeepPoint(const TopOpeBRepDS_Point& P) const
270 Standard_Boolean b = P.Keep();
274 //=======================================================================
275 //function : ChangeKeepPoint
277 //=======================================================================
278 void TopOpeBRepDS_DataStructure::ChangeKeepPoint(const Standard_Integer I,const Standard_Boolean FindKeep)
280 TopOpeBRepDS_Point& P = ChangePoint(I);
281 P.ChangeKeep(FindKeep);
284 //=======================================================================
285 //function : ChangeKeepPoint
287 //=======================================================================
288 void TopOpeBRepDS_DataStructure::ChangeKeepPoint(TopOpeBRepDS_Point& P,const Standard_Boolean FindKeep)
290 P.ChangeKeep(FindKeep);
294 //=======================================================================
295 //function : AddShape
297 //=======================================================================
298 Standard_Integer TopOpeBRepDS_DataStructure::AddShape(const TopoDS_Shape& S)
300 Standard_Integer iS = myShapes.FindIndex(S);
302 TopOpeBRepDS_ShapeData SD;
303 iS = myShapes.Add(S,SD);
304 // a shape is its own reference, oriented as itself
305 SameDomainRef(iS,iS);
306 SameDomainOri(iS,TopOpeBRepDS_SAMEORIENTED);
311 //=======================================================================
312 //function : AddShape
314 //=======================================================================
315 Standard_Integer TopOpeBRepDS_DataStructure::AddShape(const TopoDS_Shape& S,const Standard_Integer Ianc)
317 Standard_Integer iS = myShapes.FindIndex(S);
319 TopOpeBRepDS_ShapeData SD;
320 iS = myShapes.Add(S,SD);
321 // a shape is its own reference, oriented as itself
322 SameDomainRef(iS,iS);
323 SameDomainOri(iS,TopOpeBRepDS_SAMEORIENTED);
324 AncestorRank(iS,Ianc);
329 //=======================================================================
330 //function : KeepShape
332 //=======================================================================
333 Standard_Boolean TopOpeBRepDS_DataStructure::KeepShape(const Standard_Integer I,const Standard_Boolean FindKeep) const
335 Standard_Boolean b = Standard_False;
336 if (I >= 1 && I <= myShapes.Extent()) {
337 const TopoDS_Shape& S = myShapes.FindKey(I);
346 //=======================================================================
347 //function : KeepShape
349 //=======================================================================
350 Standard_Boolean TopOpeBRepDS_DataStructure::KeepShape(const TopoDS_Shape& S,const Standard_Boolean FindKeep) const
352 Standard_Boolean b = Standard_False;
353 if ( (!myShapes.IsEmpty()) && (!S.IsNull()) && myShapes.Contains(S)) {
354 const TopOpeBRepDS_ShapeData& SD = myShapes.FindFromKey(S);
363 //=======================================================================
364 //function : ChangeKeepShape
366 //=======================================================================
367 void TopOpeBRepDS_DataStructure::ChangeKeepShape(const Standard_Integer I, const Standard_Boolean FindKeep)
369 if (I >= 1 && I <= myShapes.Extent()) {
370 const TopoDS_Shape& S = myShapes.FindKey(I);
371 ChangeKeepShape(S, FindKeep);
375 //=======================================================================
376 //function : ChangeKeepShape
378 //=======================================================================
379 void TopOpeBRepDS_DataStructure::ChangeKeepShape(const TopoDS_Shape& S,const Standard_Boolean FindKeep)
381 if(!S.IsNull() && myShapes.Contains(S)) {
382 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromKey(S);
383 SD.ChangeKeep(FindKeep);
387 //=======================================================================
388 //function : InitSectionEdges
390 //=======================================================================
391 void TopOpeBRepDS_DataStructure::InitSectionEdges()
393 mySectionEdges.Clear();
396 //=======================================================================
397 //function : AddSectionEdge
399 //=======================================================================
400 Standard_Integer TopOpeBRepDS_DataStructure::AddSectionEdge(const TopoDS_Edge& E)
402 Standard_Integer iE = mySectionEdges.FindIndex(E);
403 if (iE == 0) iE = mySectionEdges.Add(E);
407 //=======================================================================
408 //function : ChangeShapes
410 //=======================================================================
411 TopOpeBRepDS_MapOfShapeData& TopOpeBRepDS_DataStructure::ChangeShapes ()
417 //=======================================================================
418 //function : SurfaceInterferences
420 //=======================================================================
421 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::SurfaceInterferences(const Standard_Integer I)const
424 if ( !mySurfaces.IsBound(I) ) {
425 return myEmptyListOfInterference;
427 const TopOpeBRepDS_SurfaceData& SD = mySurfaces.Find(I);
428 const TopOpeBRepDS_ListOfInterference& LI = SD.Interferences();
433 //=======================================================================
434 //function : ChangeSurfaceInterferences
436 //=======================================================================
437 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::ChangeSurfaceInterferences(const Standard_Integer I)
440 if ( !mySurfaces.IsBound(I) ) {
441 return myEmptyListOfInterference;
443 TopOpeBRepDS_SurfaceData& SD = mySurfaces.ChangeFind(I);
444 TopOpeBRepDS_ListOfInterference& LI = SD.ChangeInterferences();
448 //=======================================================================
449 //function : CurveInterferences
451 //=======================================================================
452 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::CurveInterferences(const Standard_Integer I)const
455 if ( !myCurves.IsBound(I) ) {
456 return myEmptyListOfInterference;
458 const TopOpeBRepDS_CurveData& CD = myCurves.Find(I);
459 const TopOpeBRepDS_ListOfInterference& LI = CD.Interferences();
464 //=======================================================================
465 //function : ChangeCurveInterferences
467 //=======================================================================
468 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::ChangeCurveInterferences(const Standard_Integer I)
471 if ( !myCurves.IsBound(I) ) {
472 return myEmptyListOfInterference;
474 TopOpeBRepDS_CurveData& CD = myCurves.ChangeFind(I);
475 TopOpeBRepDS_ListOfInterference& LI = CD.ChangeInterferences();
480 //=======================================================================
481 //function : PointInterferences
483 //=======================================================================
484 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::PointInterferences(const Standard_Integer I)const
487 if ( !myPoints.IsBound(I) ) {
488 return myEmptyListOfInterference;
490 const TopOpeBRepDS_PointData& PD = myPoints.Find(I);
491 const TopOpeBRepDS_ListOfInterference& LI = PD.Interferences();
496 //=======================================================================
497 //function : ChangePointInterferences
499 //=======================================================================
500 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::ChangePointInterferences(const Standard_Integer I)
503 if ( !myPoints.IsBound(I) ) {
504 return myEmptyListOfInterference;
506 TopOpeBRepDS_PointData& PD = myPoints.ChangeFind(I);
507 TopOpeBRepDS_ListOfInterference& LI = PD.ChangeInterferences();
512 //=======================================================================
513 //function : ShapeInterferences
515 //=======================================================================
516 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::ShapeInterferences(const TopoDS_Shape& S,const Standard_Boolean FindKeep)const
518 if(HasShape(S, FindKeep))
519 return myShapes.FindFromKey(S).myInterferences;
520 return myEmptyListOfInterference;
524 //=======================================================================
525 //function : ChangeShapeInterferences
527 //=======================================================================
528 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::ChangeShapeInterferences(const TopoDS_Shape& S)
531 return myEmptyListOfInterference;
532 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromKey(S);
533 return SD.myInterferences;
536 //=======================================================================
537 //function : ShapeInterferences
539 //=======================================================================
540 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::ShapeInterferences(const Standard_Integer I,const Standard_Boolean FindKeep) const
542 if(FindKeep && !KeepShape(I))
543 return myEmptyListOfInterference;
544 return myShapes.FindFromIndex(I).myInterferences;
548 //=======================================================================
549 //function : ChangeShapeInterferences
551 //=======================================================================
552 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_DataStructure::ChangeShapeInterferences(const Standard_Integer I)
554 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromIndex(I);
555 return SD.myInterferences;
559 //=======================================================================
560 //function : ShapeSameDomain
562 //=======================================================================
563 const TopTools_ListOfShape& TopOpeBRepDS_DataStructure::ShapeSameDomain(const TopoDS_Shape& S)const
566 if (myShapes.Contains(S)) {
567 const TopOpeBRepDS_ShapeData& SD = myShapes.FindFromKey(S);
568 const TopTools_ListOfShape& l = SD.mySameDomain;
571 return myEmptyListOfShape;
575 //=======================================================================
576 //function : ChangeShapeSameDomain
578 //=======================================================================
579 TopTools_ListOfShape& TopOpeBRepDS_DataStructure::ChangeShapeSameDomain(const TopoDS_Shape& S)
581 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromKey(S);
582 return SD.mySameDomain;
586 //=======================================================================
587 //function : ShapeSameDomain
589 //=======================================================================
590 const TopTools_ListOfShape& TopOpeBRepDS_DataStructure::ShapeSameDomain(const Standard_Integer I)const
592 if (I >= 1 && I <= myShapes.Extent()) {
593 const TopOpeBRepDS_ShapeData& SD = myShapes.FindFromIndex(I);
594 const TopTools_ListOfShape& l = SD.mySameDomain;
598 return myEmptyListOfShape;
603 //=======================================================================
604 //function : ChangeShapeSameDomain
606 //=======================================================================
607 TopTools_ListOfShape& TopOpeBRepDS_DataStructure::ChangeShapeSameDomain(const Standard_Integer I)
609 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromIndex(I);
610 return SD.mySameDomain;
614 //=======================================================================
615 //function : AddShapeSameDomain
617 //=======================================================================
618 void TopOpeBRepDS_DataStructure::AddShapeSameDomain(const TopoDS_Shape& S, const TopoDS_Shape& SSD)
620 Standard_Boolean append = Standard_True;
622 TopTools_ListIteratorOfListOfShape it(ShapeSameDomain(S));
623 for (; it.More(); it.Next() ) {
624 const TopoDS_Shape& itS = it.Value();
625 if ( itS.IsSame(SSD) ) {
626 append = Standard_False;
632 ChangeShapeSameDomain(S).Append(SSD);
636 //=======================================================================
637 //function : RemoveShapeSameDomain
639 //=======================================================================
640 void TopOpeBRepDS_DataStructure::RemoveShapeSameDomain(const TopoDS_Shape& S, const TopoDS_Shape& SSD)
642 TopTools_ListOfShape& L = ChangeShapeSameDomain(S);
643 TopTools_ListIteratorOfListOfShape it(L);
645 const TopoDS_Shape& itS = it.Value();
646 Standard_Boolean remove = itS.IsSame(SSD);
654 //=======================================================================
655 //function : SameDomainRef
657 //=======================================================================
658 Standard_Integer TopOpeBRepDS_DataStructure::SameDomainRef(const Standard_Integer I)const
660 if (I >= 1 && I <= myShapes.Extent()) {
661 return myShapes.FindFromIndex(I).mySameDomainRef;
666 //=======================================================================
667 //function : SameDomainRef
669 //=======================================================================
670 Standard_Integer TopOpeBRepDS_DataStructure::SameDomainRef(const TopoDS_Shape& S) const
672 if(S.IsNull()) return 0;
673 if (myShapes.Contains(S)) {
674 return myShapes.FindFromKey(S).mySameDomainRef;
679 //=======================================================================
680 //function : SameDomainRef
682 //=======================================================================
683 void TopOpeBRepDS_DataStructure::SameDomainRef(const Standard_Integer I, const Standard_Integer Ref)
685 if (I >= 1 && I <= myShapes.Extent()) {
686 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromIndex(I);
687 SD.mySameDomainRef = Ref;
691 //=======================================================================
692 //function : SameDomainRef
694 //=======================================================================
695 void TopOpeBRepDS_DataStructure::SameDomainRef(const TopoDS_Shape& S, const Standard_Integer Ref)
697 if(S.IsNull()) return;
698 if (myShapes.Contains(S)) {
699 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromKey(S);
700 SD.mySameDomainRef = Ref;
704 //=======================================================================
705 //function : SameDomainOri
707 //=======================================================================
708 TopOpeBRepDS_Config TopOpeBRepDS_DataStructure::SameDomainOri(const Standard_Integer I)const
710 if (I >= 1 && I <= myShapes.Extent()) {
711 return myShapes.FindFromIndex(I).mySameDomainOri;
713 return TopOpeBRepDS_UNSHGEOMETRY;
716 //=======================================================================
717 //function : SameDomainOri
719 //=======================================================================
720 TopOpeBRepDS_Config TopOpeBRepDS_DataStructure::SameDomainOri(const TopoDS_Shape& S) const
723 if (myShapes.Contains(S)) {
724 return myShapes.FindFromKey(S).mySameDomainOri;
726 return TopOpeBRepDS_UNSHGEOMETRY;
729 //=======================================================================
730 //function : SameDomainOri
732 //=======================================================================
733 void TopOpeBRepDS_DataStructure::SameDomainOri(const Standard_Integer I, const TopOpeBRepDS_Config Ori)
735 if (I >= 1 && I <= myShapes.Extent()) {
736 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromIndex(I);
737 SD.mySameDomainOri = Ori;
741 //=======================================================================
742 //function : SameDomainOri
744 //=======================================================================
745 void TopOpeBRepDS_DataStructure::SameDomainOri(const TopoDS_Shape& S, const TopOpeBRepDS_Config Ori)
748 if (myShapes.Contains(S)) {
749 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromKey(S);
750 SD.mySameDomainOri = Ori;
754 //=======================================================================
755 //function : SameDomainInd
757 //=======================================================================
758 Standard_Integer TopOpeBRepDS_DataStructure::SameDomainInd(const Standard_Integer I)const
760 if (I >= 1 && I <= myShapes.Extent()) {
761 return myShapes.FindFromIndex(I).mySameDomainInd;
766 //=======================================================================
767 //function : SameDomainInd
769 //=======================================================================
770 Standard_Integer TopOpeBRepDS_DataStructure::SameDomainInd(const TopoDS_Shape& S) const
773 if (myShapes.Contains(S)) {
774 return myShapes.FindFromKey(S).mySameDomainInd;
779 //=======================================================================
780 //function : SameDomainInd
782 //=======================================================================
783 void TopOpeBRepDS_DataStructure::SameDomainInd(const Standard_Integer I, const Standard_Integer Ind)
785 if (I >= 1 && I <= myShapes.Extent()) {
786 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromIndex(I);
787 SD.mySameDomainInd = Ind;
791 //=======================================================================
792 //function : SameDomainInd
794 //=======================================================================
795 void TopOpeBRepDS_DataStructure::SameDomainInd(const TopoDS_Shape& S, const Standard_Integer Ind)
797 if(S.IsNull()) return;
798 if (myShapes.Contains(S)) {
799 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromKey(S);
800 SD.mySameDomainInd = Ind;
804 //=======================================================================
805 //function : AncestorRank
807 //=======================================================================
808 Standard_Integer TopOpeBRepDS_DataStructure::AncestorRank(const Standard_Integer I)const
810 if (I >= 1 && I <= myShapes.Extent()) {
811 return myShapes.FindFromIndex(I).myAncestorRank;
816 //=======================================================================
817 //function : AncestorRank
819 //=======================================================================
820 Standard_Integer TopOpeBRepDS_DataStructure::AncestorRank(const TopoDS_Shape& S) const
822 if(S.IsNull()) return 0;
823 if (myShapes.Contains(S)) {
824 return myShapes.FindFromKey(S).myAncestorRank;
829 //=======================================================================
830 //function : AncestorRank
832 //=======================================================================
833 void TopOpeBRepDS_DataStructure::AncestorRank(const Standard_Integer I, const Standard_Integer Ianc)
835 if (I >= 1 && I <= myShapes.Extent()) {
836 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromIndex(I);
837 SD.myAncestorRank = Ianc;
841 //=======================================================================
842 //function : AncestorRank
844 //=======================================================================
845 void TopOpeBRepDS_DataStructure::AncestorRank(const TopoDS_Shape& S, const Standard_Integer Ianc)
847 if(S.IsNull()) return;
848 if (myShapes.Contains(S)) {
849 TopOpeBRepDS_ShapeData& SD = myShapes.ChangeFromKey(S);
850 SD.myAncestorRank = Ianc;
854 //=======================================================================
855 //function : AddShapeInterference
857 //=======================================================================
858 void TopOpeBRepDS_DataStructure::AddShapeInterference(const TopoDS_Shape& S, const Handle(TopOpeBRepDS_Interference)& I)
860 ChangeShapeInterferences(S).Append(I);
864 //=======================================================================
865 //function : RemoveShapeInterference
867 //=======================================================================
868 void TopOpeBRepDS_DataStructure::RemoveShapeInterference(const TopoDS_Shape& S, const Handle(TopOpeBRepDS_Interference)& I)
870 TopOpeBRepDS_ListOfInterference& L = ChangeShapeInterferences(S);
871 TopOpeBRepDS_ListIteratorOfListOfInterference it(L);
872 Standard_Boolean b = FindInterference(it,I);
878 //=======================================================================
879 //function : FillShapesSameDomain
881 //=======================================================================
882 void TopOpeBRepDS_DataStructure::FillShapesSameDomain(const TopoDS_Shape& S1,
883 const TopoDS_Shape& S2,
884 const Standard_Boolean refFirst)
886 TopAbs_Orientation o1 = S1.Orientation();
887 TopAbs_Orientation o2 = S2.Orientation();
889 Standard_Integer iS1 = AddShape(S1,1);
890 TopOpeBRepDS_ShapeData& SD1 = myShapes.ChangeFromIndex(iS1);
891 Standard_Boolean isdef1 = SD1.myOrientationDef;
892 Standard_Boolean todef1 = ( !isdef1 );
893 if ( isdef1 && SD1.mySameDomainOri == TopOpeBRepDS_UNSHGEOMETRY ) todef1 = Standard_True;
895 SD1.myOrientation = o1;
896 SD1.myOrientationDef = Standard_True;
899 Standard_Integer iS2 = AddShape(S2,2);
900 TopOpeBRepDS_ShapeData& SD2 = myShapes.ChangeFromIndex(iS2);
901 Standard_Boolean isdef2 = SD2.myOrientationDef;
902 Standard_Boolean todef2 = ( !isdef2 );
903 if ( isdef2 && SD2.mySameDomainOri == TopOpeBRepDS_UNSHGEOMETRY ) todef2 = Standard_True;
905 SD2.myOrientation = o2;
906 SD2.myOrientationDef = Standard_True;
909 Standard_Integer n1 = ShapeSameDomain(S1).Extent();
910 Standard_Integer n2 = ShapeSameDomain(S2).Extent();
912 AddShapeSameDomain(S1,S2);
913 AddShapeSameDomain(S2,S1);
915 Standard_Integer n11 = ShapeSameDomain(S1).Extent();
916 Standard_Integer n22 = ShapeSameDomain(S2).Extent();
918 Standard_Boolean cond = ( n11 == n1 ) && (n22 == n2);
919 cond = cond && (!todef1) && (!todef2);
921 // nothing changed in SameDomain data of S1 and S2 : return
925 Standard_Integer r1 = SameDomainRef(S1);
926 Standard_Integer r2 = SameDomainRef(S2);
927 Standard_Integer r = 0;
928 // r1 == i1 r2 == i2 : shapes have no SameDomain ref : take S1 as reference
929 // r1 == i1 r2 != i2 : S2 has a SameDomain reference : give it to S1
930 // r1 != i1 r2 == i2 : S1 has a SameDomain reference : give it to S2
931 // r1 != i1 r2 != i2 : S1,S2 have SameDomain reference : check equality
932 if ( r1 == iS1 && r2 == iS2 ) r = (refFirst? iS1 : iS2);
933 else if ( r1 == iS1 && r2 != iS2 ) r = r2;
934 else if ( r1 != iS1 && r2 == iS2 ) r = r1;
935 else if ( r1 != iS1 && r2 != iS2 ) {
937 // throw Standard_ProgramError("FacesFiller::Insert SD 1");
939 r = (refFirst? r1 : r2);
943 throw Standard_ProgramError("FacesFiller::Insert SD 2");
946 TopoDS_Shape Sr = Shape(r);
947 const TopOpeBRepDS_ShapeData& SD = myShapes.FindFromKey(Sr);
948 TopAbs_Orientation oSr = SD.myOrientation;
951 if ( r != r1 || todef1) { // S1 gets a new reference r
952 TopOpeBRepDS_Config o = TopOpeBRepDS_SAMEORIENTED;
953 if ( r != iS1 || todef1) {
954 Standard_Boolean sso = TopOpeBRepTool_ShapeTool::ShapesSameOriented(S1,Sr);
955 if (!sso) o = TopOpeBRepDS_DIFFORIENTED;
957 SameDomainRef(iS1,r);
958 SameDomainOri(iS1,o);
961 if ( r != r2 || todef2) { // S2 gets a new reference r
962 TopOpeBRepDS_Config o = TopOpeBRepDS_SAMEORIENTED;
963 if ( r != iS2 || todef2) {
964 Standard_Boolean sso = TopOpeBRepTool_ShapeTool::ShapesSameOriented(S2,Sr);
965 if (!sso) o = TopOpeBRepDS_DIFFORIENTED;
967 SameDomainRef(iS2,r);
968 SameDomainOri(iS2,o);
976 //=======================================================================
977 //function : FillShapesSameDomain
979 //=======================================================================
980 void TopOpeBRepDS_DataStructure::FillShapesSameDomain(const TopoDS_Shape& S1,
981 const TopoDS_Shape& S2,
982 const TopOpeBRepDS_Config c1,
983 const TopOpeBRepDS_Config c2,
984 const Standard_Boolean refFirst)
986 Standard_Integer iS1 = AddShape(S1,1);
987 TopOpeBRepDS_ShapeData& SD1 = myShapes.ChangeFromIndex(iS1);
988 Standard_Boolean isdef1 = SD1.myOrientationDef;
989 Standard_Boolean todef1 = Standard_True;
990 if (c1 == TopOpeBRepDS_UNSHGEOMETRY && isdef1) todef1 = Standard_False;
992 Standard_Integer iS2 = AddShape(S2,2);
993 TopOpeBRepDS_ShapeData& SD2 = myShapes.ChangeFromIndex(iS2);
994 Standard_Boolean isdef2 = SD2.myOrientationDef;
995 Standard_Boolean todef2 = Standard_True;
996 if (c2 == TopOpeBRepDS_UNSHGEOMETRY && isdef2) todef2 = Standard_False;
998 if (todef1 || todef2 ) {
999 FillShapesSameDomain(S1,S2,refFirst);
1002 if (todef1 && c1 == TopOpeBRepDS_UNSHGEOMETRY)
1003 SameDomainOri(S1,TopOpeBRepDS_UNSHGEOMETRY);
1004 if (todef2 && c2 == TopOpeBRepDS_UNSHGEOMETRY)
1005 SameDomainOri(S2,TopOpeBRepDS_UNSHGEOMETRY);
1008 //=======================================================================
1009 //function : UnfillShapesSameDomain
1011 //=======================================================================
1012 void TopOpeBRepDS_DataStructure::UnfillShapesSameDomain(const TopoDS_Shape& S1,const TopoDS_Shape& S2)
1014 RemoveShapeSameDomain(S1,S2);
1015 RemoveShapeSameDomain(S2,S1);
1018 //=======================================================================
1019 //function : NbSurfaces
1021 //=======================================================================
1022 Standard_Integer TopOpeBRepDS_DataStructure::NbSurfaces()const
1024 Standard_Integer n = myNbSurfaces;
1029 //=======================================================================
1030 //function : NbCurves
1032 //=======================================================================
1033 Standard_Integer TopOpeBRepDS_DataStructure::NbCurves()const
1035 Standard_Integer n = myNbCurves;
1040 //=======================================================================
1041 //function : ChangeNbCurves
1043 //=======================================================================
1044 void TopOpeBRepDS_DataStructure::ChangeNbCurves(const Standard_Integer n)
1050 //=======================================================================
1051 //function : NbPoints
1053 //=======================================================================
1054 Standard_Integer TopOpeBRepDS_DataStructure::NbPoints()const
1056 Standard_Integer n = myNbPoints;
1061 //=======================================================================
1062 //function : NbShapes
1064 //=======================================================================
1065 Standard_Integer TopOpeBRepDS_DataStructure::NbShapes()const
1067 Standard_Integer n = myShapes.Extent();
1072 //=======================================================================
1073 //function : NbSectionEdges
1075 //=======================================================================
1076 Standard_Integer TopOpeBRepDS_DataStructure::NbSectionEdges()const
1078 Standard_Integer n = mySectionEdges.Extent();
1083 //=======================================================================
1084 //function : Surface
1086 //=======================================================================
1087 const TopOpeBRepDS_Surface& TopOpeBRepDS_DataStructure::Surface(const Standard_Integer I) const
1089 if ( mySurfaces.IsBound(I) )
1090 return mySurfaces(I).mySurface;
1092 return myEmptySurface;
1096 //=======================================================================
1097 //function : ChangeSurface
1099 //=======================================================================
1100 TopOpeBRepDS_Surface& TopOpeBRepDS_DataStructure::ChangeSurface(const Standard_Integer I)
1102 if ( mySurfaces.IsBound(I) )
1103 return mySurfaces(I).mySurface;
1105 return myEmptySurface;
1109 //=======================================================================
1112 //=======================================================================
1113 const TopOpeBRepDS_Curve& TopOpeBRepDS_DataStructure::Curve(const Standard_Integer I)const
1115 if ( myCurves.IsBound(I) ) {
1116 const TopOpeBRepDS_CurveData& CD = myCurves(I);
1117 const TopOpeBRepDS_Curve& C = CD.myCurve;
1121 return myEmptyCurve;
1124 //=======================================================================
1125 //function : ChangeCurve
1127 //=======================================================================
1128 TopOpeBRepDS_Curve& TopOpeBRepDS_DataStructure::ChangeCurve(const Standard_Integer I)
1130 if ( myCurves.IsBound(I) ) {
1131 TopOpeBRepDS_CurveData& CD = myCurves.ChangeFind(I);
1132 TopOpeBRepDS_Curve& C = CD.myCurve;
1135 return myEmptyCurve;
1138 //=======================================================================
1141 //=======================================================================
1142 const TopOpeBRepDS_Point& TopOpeBRepDS_DataStructure::Point(const Standard_Integer I)const
1144 if ( I < 1 || I > myNbPoints ) {
1145 throw Standard_ProgramError("TopOpeBRepDS_DataStructure::Point");
1148 if ( myPoints.IsBound(I) )
1149 return myPoints(I).myPoint;
1151 return myEmptyPoint;
1154 //=======================================================================
1155 //function : ChangePoint
1157 //=======================================================================
1158 TopOpeBRepDS_Point& TopOpeBRepDS_DataStructure::ChangePoint(const Standard_Integer I)
1160 if ( I < 1 || I > myNbPoints ) {
1161 throw Standard_ProgramError("TopOpeBRepDS_DataStructure::Point");
1164 if ( myPoints.IsBound(I) )
1165 return myPoints(I).myPoint;
1167 return myEmptyPoint;
1171 //=======================================================================
1174 //=======================================================================
1175 const TopoDS_Shape& TopOpeBRepDS_DataStructure::Shape(const Standard_Integer I,const Standard_Boolean FindKeep) const
1177 if(KeepShape(I, FindKeep)) {
1178 const TopoDS_Shape& S = myShapes.FindKey(I);
1181 return myEmptyShape;
1184 //=======================================================================
1187 //=======================================================================
1188 Standard_Integer TopOpeBRepDS_DataStructure::Shape(const TopoDS_Shape& S,const Standard_Boolean FindKeep)const
1190 Standard_Integer i = 0;
1191 Standard_Boolean hs = HasShape(S, FindKeep);
1193 i = myShapes.FindIndex(S);
1199 //=======================================================================
1200 //function : SectionEdge
1202 //=======================================================================
1203 const TopoDS_Edge& TopOpeBRepDS_DataStructure::SectionEdge(const Standard_Integer I,const Standard_Boolean FindKeep) const
1205 const TopoDS_Shape& S = mySectionEdges.FindKey(I);
1206 if(HasShape(S, FindKeep))
1207 return TopoDS::Edge(S);
1208 return TopoDS::Edge(myEmptyShape);
1211 //=======================================================================
1212 //function : SectionEdge
1214 //=======================================================================
1215 Standard_Integer TopOpeBRepDS_DataStructure::SectionEdge(const TopoDS_Edge& S,const Standard_Boolean FindKeep) const
1217 Standard_Integer i = 0;
1218 if(KeepShape(S, FindKeep))
1219 i = mySectionEdges.FindIndex(S);
1224 //=======================================================================
1225 //function : IsSectionEdge
1227 //=======================================================================
1228 Standard_Boolean TopOpeBRepDS_DataStructure::IsSectionEdge(const TopoDS_Edge& S,const Standard_Boolean FindKeep) const
1230 Standard_Boolean b = KeepShape(S, FindKeep);
1232 b = mySectionEdges.Contains(S);
1238 //=======================================================================
1239 //function : HasGeometry
1241 //=======================================================================
1242 Standard_Boolean TopOpeBRepDS_DataStructure::HasGeometry(const TopoDS_Shape& S)const
1244 Standard_Boolean has = HasShape(S);
1246 has = ! ShapeInterferences(S).IsEmpty();
1252 //=======================================================================
1253 //function : HasShape
1255 //=======================================================================
1256 Standard_Boolean TopOpeBRepDS_DataStructure::HasShape(const TopoDS_Shape& S,const Standard_Boolean FindKeep)const
1258 Standard_Boolean res = KeepShape(S, FindKeep);
1262 //=======================================================================
1263 //function : SetNewSurface
1265 //=======================================================================
1266 void TopOpeBRepDS_DataStructure::SetNewSurface(const TopoDS_Shape& F, const Handle(Geom_Surface)& S)
1268 myNewSurface.Bind(F,S);
1271 //=======================================================================
1272 //function : HasNewSurface
1274 //=======================================================================
1275 Standard_Boolean TopOpeBRepDS_DataStructure::HasNewSurface(const TopoDS_Shape& F) const
1277 Standard_Boolean b = myNewSurface.IsBound(F);
1281 //=======================================================================
1282 //function : NewSurface
1284 //=======================================================================
1285 const Handle(Geom_Surface)& TopOpeBRepDS_DataStructure::NewSurface(const TopoDS_Shape& F) const
1287 if (HasNewSurface(F)) return myNewSurface.Find(F);
1288 return myEmptyGSurface;
1291 //=======================================================================
1292 //function : FindInterference
1294 //=======================================================================
1295 Standard_Boolean TopOpeBRepDS_DataStructure::FindInterference(TopOpeBRepDS_ListIteratorOfListOfInterference& IT,const Handle(TopOpeBRepDS_Interference)& I) const
1297 for( ; IT.More(); IT.Next()) if (IT.Value() == I ) return Standard_True;
1298 return Standard_False;
1302 //=======================================================================
1305 //=======================================================================
1306 void TopOpeBRepDS_DataStructure::Isfafa(const Standard_Boolean isfafa)
1311 //=======================================================================
1314 //=======================================================================
1315 Standard_Boolean TopOpeBRepDS_DataStructure::Isfafa() const
1321 //=======================================================================
1322 //function :ChangeMapOfShapeWithStateObj
1324 //=======================================================================
1325 TopOpeBRepDS_IndexedDataMapOfShapeWithState& TopOpeBRepDS_DataStructure::ChangeMapOfShapeWithStateObj()
1327 return myMapOfShapeWithStateObj;
1330 //=======================================================================
1331 //function :ChangeMapOfShapeWithStateTool
1333 //=======================================================================
1334 TopOpeBRepDS_IndexedDataMapOfShapeWithState& TopOpeBRepDS_DataStructure::ChangeMapOfShapeWithStateTool()
1336 return myMapOfShapeWithStateTool;
1339 //=======================================================================
1340 //function :ChangeMapOfShapeWithState
1342 //=======================================================================
1343 TopOpeBRepDS_IndexedDataMapOfShapeWithState& TopOpeBRepDS_DataStructure::ChangeMapOfShapeWithState
1344 (const TopoDS_Shape& aShape, Standard_Boolean& aFlag)
1346 static TopOpeBRepDS_IndexedDataMapOfShapeWithState dummy;
1347 aFlag=Standard_True;
1349 if (myMapOfShapeWithStateObj.Contains(aShape))
1350 return myMapOfShapeWithStateObj;
1352 if (myMapOfShapeWithStateTool.Contains(aShape))
1353 return myMapOfShapeWithStateTool;
1355 aFlag=Standard_False;
1360 //=======================================================================
1361 //function :GetShapeWithState
1363 //=======================================================================
1364 const TopOpeBRepDS_ShapeWithState& TopOpeBRepDS_DataStructure::GetShapeWithState(const TopoDS_Shape& aShape) const
1366 static TopOpeBRepDS_ShapeWithState dummy;
1367 if(myMapOfShapeWithStateObj.Contains(aShape))
1368 return myMapOfShapeWithStateObj.FindFromKey(aShape);
1369 else if(myMapOfShapeWithStateTool.Contains(aShape))
1370 return myMapOfShapeWithStateTool.FindFromKey(aShape);
1375 //=======================================================================
1376 //function :ChangeMapOfRejectedShapesObj
1378 //=======================================================================
1379 TopTools_IndexedMapOfShape& TopOpeBRepDS_DataStructure::ChangeMapOfRejectedShapesObj()
1381 return myMapOfRejectedShapesObj;
1384 //=======================================================================
1385 //function :ChangeMapOfRejectedShapesTool
1387 //=======================================================================
1388 TopTools_IndexedMapOfShape& TopOpeBRepDS_DataStructure::ChangeMapOfRejectedShapesTool()
1390 return myMapOfRejectedShapesTool;