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.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepTools_Substitution.hxx>
21 #include <Standard_ConstructionError.hxx>
22 #include <Standard_NoSuchObject.hxx>
24 #include <TopoDS_Iterator.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
27 #include <TopTools_ListIteratorOfListOfShape.hxx>
29 //=======================================================================
30 //function : BRepTools_Substitution
32 //=======================================================================
33 BRepTools_Substitution::BRepTools_Substitution()
36 //=======================================================================
39 //=======================================================================
41 void BRepTools_Substitution::Clear()
46 //=======================================================================
47 //function : Substitute
49 //=======================================================================
51 void BRepTools_Substitution::Substitute(const TopoDS_Shape& OS,
52 const TopTools_ListOfShape& NS)
54 Standard_ConstructionError_Raise_if
55 (IsCopied(OS),"BRepTools_CutClue::Substitute");
60 //=======================================================================
63 //=======================================================================
65 void BRepTools_Substitution::Build(const TopoDS_Shape& S)
67 if (IsCopied(S)) return;
70 TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD));
71 Standard_Boolean IsModified = Standard_False;
72 Standard_Boolean HasSubShape = Standard_False;
74 //------------------------------------------
75 // look S is modified and build subshapes.
76 //------------------------------------------
77 for (; iteS.More(); iteS.Next()) {
78 const TopoDS_Shape& SS = iteS.Value();
81 IsModified = Standard_True;
85 TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD);
87 //----------------------------------------
89 //------------------------------------------
92 if (NewS.ShapeType() == TopAbs_EDGE) {
94 BRep_Tool::Range(TopoDS::Edge(S),f,l);
95 B.Range(TopoDS::Edge(NewS),f,l);
98 iteS.Initialize(S.Oriented(TopAbs_FORWARD));
99 //------------------------------------------
100 // Add the copy of subshapes of S to NewS.
101 //------------------------------------------
102 for ( ;iteS.More(); iteS.Next()) {
103 TopAbs_Orientation OS = iteS.Value().Orientation();
104 TopTools_ListOfShape L;
105 L = myMap(iteS.Value());
106 TopTools_ListIteratorOfListOfShape iteL(L);
108 for ( ; iteL.More(); iteL.Next()){
109 const TopoDS_Shape NSS = iteL.Value();
110 //------------------------------------------
111 // Rebuild NSS and add its copy to NewS.
112 //------------------------------------------
115 const TopTools_ListOfShape& NL = myMap(NSS);
116 TopAbs_Orientation NewOr = TopAbs::Compose(OS,NSS.Orientation());
117 TopTools_ListIteratorOfListOfShape iteNL(NL);
119 for ( ; iteNL.More(); iteNL.Next()){
120 B.Add (NewS,iteNL.Value().Oriented(NewOr));
121 HasSubShape = Standard_True;
126 if (NewS.ShapeType() == TopAbs_WIRE || NewS.ShapeType() == TopAbs_SHELL ||
127 NewS.ShapeType() == TopAbs_SOLID || NewS.ShapeType() == TopAbs_COMPOUND)
128 //----------------------------------------------------------------
129 // Wire,Solid,Shell,Compound mut have subshape else they disapear
130 //---------------------------------------------------------------
134 TopTools_ListOfShape L;
135 //-------------------------------------------------------
136 // NewS has the same orientation than S in its ancestors
137 // so NewS is bound with orientation FORWARD.
138 //-------------------------------------------------------
139 if (!NewS.IsNull()) L.Append(NewS.Oriented(TopAbs_FORWARD));
144 //=======================================================================
145 //function : IsCopied
147 //=======================================================================
149 Standard_Boolean BRepTools_Substitution::IsCopied(const TopoDS_Shape& S) const
151 if (myMap.IsBound(S)) {
152 if (myMap (S).IsEmpty()) return Standard_True;
154 return !S.IsSame(myMap(S).First());
157 return Standard_False;
161 //=======================================================================
164 //=======================================================================
166 const TopTools_ListOfShape& BRepTools_Substitution::Copy (const TopoDS_Shape& S)
169 Standard_NoSuchObject_Raise_if(!IsCopied(S),"BRepTools_Substitution::Copy");