1 // Created on: 1995-03-28
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1995-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.
17 #include <BRepTools_Substitution.ixx>
19 #include <TopoDS_Iterator.hxx>
20 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
21 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <BRep_Builder.hxx>
23 #include <Standard_ConstructionError.hxx>
24 #include <BRep_Tool.hxx>
26 //=======================================================================
27 //function : BRepTools_Substitution
29 //=======================================================================
31 BRepTools_Substitution::BRepTools_Substitution()
34 //=======================================================================
37 //=======================================================================
39 void BRepTools_Substitution::Clear()
44 //=======================================================================
45 //function : Substitute
47 //=======================================================================
49 void BRepTools_Substitution::Substitute(const TopoDS_Shape& OS,
50 const TopTools_ListOfShape& NS)
52 Standard_ConstructionError_Raise_if
53 (IsCopied(OS),"BRepTools_CutClue::Substitute");
58 //=======================================================================
61 //=======================================================================
63 void BRepTools_Substitution::Build(const TopoDS_Shape& S)
65 if (IsCopied(S)) return;
68 TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD));
69 Standard_Boolean IsModified = Standard_False;
70 Standard_Boolean HasSubShape = Standard_False;
72 //------------------------------------------
73 // look S is modified and build subshapes.
74 //------------------------------------------
75 for (; iteS.More(); iteS.Next()) {
76 const TopoDS_Shape& SS = iteS.Value();
79 IsModified = Standard_True;
83 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
85 //----------------------------------------
87 //------------------------------------------
90 if (NewS.ShapeType() == TopAbs_EDGE) {
92 BRep_Tool::Range(TopoDS::Edge(S),f,l);
93 B.Range(TopoDS::Edge(NewS),f,l);
96 iteS.Initialize(S.Oriented(TopAbs_FORWARD));
97 //------------------------------------------
98 // Add the copy of subshapes of S to NewS.
99 //------------------------------------------
100 for ( ;iteS.More(); iteS.Next()) {
101 TopAbs_Orientation OS = iteS.Value().Orientation();
102 TopTools_ListOfShape L;
103 L = myMap(iteS.Value());
104 TopTools_ListIteratorOfListOfShape iteL(L);
106 for ( ; iteL.More(); iteL.Next()){
107 const TopoDS_Shape NSS = iteL.Value();
108 //------------------------------------------
109 // Rebuild NSS and add its copy to NewS.
110 //------------------------------------------
113 const TopTools_ListOfShape& NL = myMap(NSS);
114 TopAbs_Orientation NewOr = TopAbs::Compose(OS,NSS.Orientation());
115 TopTools_ListIteratorOfListOfShape iteNL(NL);
117 for ( ; iteNL.More(); iteNL.Next()){
118 B.Add (NewS,iteNL.Value().Oriented(NewOr));
119 HasSubShape = Standard_True;
124 if (NewS.ShapeType() == TopAbs_WIRE || NewS.ShapeType() == TopAbs_SHELL ||
125 NewS.ShapeType() == TopAbs_SOLID || NewS.ShapeType() == TopAbs_COMPOUND)
126 //----------------------------------------------------------------
127 // Wire,Solid,Shell,Compound mut have subshape else they disapear
128 //---------------------------------------------------------------
132 TopTools_ListOfShape L;
133 //-------------------------------------------------------
134 // NewS has the same orientation than S in its ancestors
135 // so NewS is bound with orientation FORWARD.
136 //-------------------------------------------------------
137 if (!NewS.IsNull()) L.Append(NewS.Oriented(TopAbs_FORWARD));
142 //=======================================================================
143 //function : IsCopied
145 //=======================================================================
147 Standard_Boolean BRepTools_Substitution::IsCopied(const TopoDS_Shape& S) const
149 if (myMap.IsBound(S)) {
150 if (myMap (S).IsEmpty()) return Standard_True;
152 return !S.IsSame(myMap(S).First());
155 return Standard_False;
159 //=======================================================================
162 //=======================================================================
164 const TopTools_ListOfShape& BRepTools_Substitution::Copy (const TopoDS_Shape& S)
167 Standard_NoSuchObject_Raise_if(!IsCopied(S),"BRepTools_Substitution::Copy");