1 // File: BRepTools_Substitution.cxx
2 // Created: Tue Mar 28 09:54:41 1995
3 // Author: Yves FRICAUD
7 #include <BRepTools_Substitution.ixx>
9 #include <TopoDS_Iterator.hxx>
10 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
11 #include <TopTools_ListIteratorOfListOfShape.hxx>
12 #include <BRep_Builder.hxx>
13 #include <Standard_ConstructionError.hxx>
14 #include <BRep_Tool.hxx>
16 //=======================================================================
17 //function : BRepTools_Substitution
19 //=======================================================================
21 BRepTools_Substitution::BRepTools_Substitution()
24 //=======================================================================
27 //=======================================================================
29 void BRepTools_Substitution::Clear()
34 //=======================================================================
35 //function : Substitute
37 //=======================================================================
39 void BRepTools_Substitution::Substitute(const TopoDS_Shape& OS,
40 const TopTools_ListOfShape& NS)
42 Standard_ConstructionError_Raise_if
43 (IsCopied(OS),"BRepTools_CutClue::Substitute");
48 //=======================================================================
51 //=======================================================================
53 void BRepTools_Substitution::Build(const TopoDS_Shape& S)
55 if (IsCopied(S)) return;
58 TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD));
59 Standard_Boolean IsModified = Standard_False;
60 Standard_Boolean HasSubShape = Standard_False;
62 //------------------------------------------
63 // look S is modified and build subshapes.
64 //------------------------------------------
65 for (; iteS.More(); iteS.Next()) {
66 const TopoDS_Shape& SS = iteS.Value();
69 IsModified = Standard_True;
73 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
75 //----------------------------------------
77 //------------------------------------------
80 if (NewS.ShapeType() == TopAbs_EDGE) {
82 BRep_Tool::Range(TopoDS::Edge(S),f,l);
83 B.Range(TopoDS::Edge(NewS),f,l);
86 iteS.Initialize(S.Oriented(TopAbs_FORWARD));
87 //------------------------------------------
88 // Add the copy of subshapes of S to NewS.
89 //------------------------------------------
90 for ( ;iteS.More(); iteS.Next()) {
91 TopAbs_Orientation OS = iteS.Value().Orientation();
92 TopTools_ListOfShape L;
93 L = myMap(iteS.Value());
94 TopTools_ListIteratorOfListOfShape iteL(L);
96 for ( ; iteL.More(); iteL.Next()){
97 const TopoDS_Shape NSS = iteL.Value();
98 //------------------------------------------
99 // Rebuild NSS and add its copy to NewS.
100 //------------------------------------------
103 const TopTools_ListOfShape& NL = myMap(NSS);
104 TopAbs_Orientation NewOr = TopAbs::Compose(OS,NSS.Orientation());
105 TopTools_ListIteratorOfListOfShape iteNL(NL);
107 for ( ; iteNL.More(); iteNL.Next()){
108 B.Add (NewS,iteNL.Value().Oriented(NewOr));
109 HasSubShape = Standard_True;
114 if (NewS.ShapeType() == TopAbs_WIRE || NewS.ShapeType() == TopAbs_SHELL ||
115 NewS.ShapeType() == TopAbs_SOLID || NewS.ShapeType() == TopAbs_COMPOUND)
116 //----------------------------------------------------------------
117 // Wire,Solid,Shell,Compound mut have subshape else they disapear
118 //---------------------------------------------------------------
122 TopTools_ListOfShape L;
123 //-------------------------------------------------------
124 // NewS has the same orientation than S in its ancestors
125 // so NewS is bound with orientation FORWARD.
126 //-------------------------------------------------------
127 if (!NewS.IsNull()) L.Append(NewS.Oriented(TopAbs_FORWARD));
132 //=======================================================================
133 //function : IsCopied
135 //=======================================================================
137 Standard_Boolean BRepTools_Substitution::IsCopied(const TopoDS_Shape& S) const
139 if (myMap.IsBound(S)) {
140 if (myMap (S).IsEmpty()) return Standard_True;
142 return !S.IsSame(myMap(S).First());
145 return Standard_False;
149 //=======================================================================
152 //=======================================================================
154 const TopTools_ListOfShape& BRepTools_Substitution::Copy (const TopoDS_Shape& S)
157 Standard_NoSuchObject_Raise_if(!IsCopied(S),"BRepTools_Substitution::Copy");