b311480e |
1 | // Created on: 1995-03-28 |
2 | // Created by: Yves FRICAUD |
3 | // Copyright (c) 1995-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 | |
42cf5bc1 |
17 | |
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> |
7fd59977 |
23 | #include <TopoDS.hxx> |
24 | #include <TopoDS_Iterator.hxx> |
42cf5bc1 |
25 | #include <TopoDS_Shape.hxx> |
7fd59977 |
26 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> |
27 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
b311480e |
28 | |
7fd59977 |
29 | //======================================================================= |
30 | //function : BRepTools_Substitution |
31 | //purpose : |
32 | //======================================================================= |
7fd59977 |
33 | BRepTools_Substitution::BRepTools_Substitution() |
34 | {} |
35 | |
36 | //======================================================================= |
37 | //function : Clear |
38 | //purpose : |
39 | //======================================================================= |
40 | |
41 | void BRepTools_Substitution::Clear() |
42 | { |
43 | myMap.Clear(); |
44 | } |
45 | |
46 | //======================================================================= |
47 | //function : Substitute |
48 | //purpose : |
49 | //======================================================================= |
50 | |
51 | void BRepTools_Substitution::Substitute(const TopoDS_Shape& OS, |
52 | const TopTools_ListOfShape& NS) |
53 | { |
54 | Standard_ConstructionError_Raise_if |
55 | (IsCopied(OS),"BRepTools_CutClue::Substitute"); |
56 | myMap.Bind(OS,NS); |
57 | } |
58 | |
59 | |
60 | //======================================================================= |
61 | //function : Build |
62 | //purpose : |
63 | //======================================================================= |
64 | |
65 | void BRepTools_Substitution::Build(const TopoDS_Shape& S) |
66 | { |
67 | if (IsCopied(S)) return; |
68 | |
69 | BRep_Builder B; |
70 | TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD)); |
71 | Standard_Boolean IsModified = Standard_False; |
72 | Standard_Boolean HasSubShape = Standard_False; |
73 | |
74 | //------------------------------------------ |
75 | // look S is modified and build subshapes. |
76 | //------------------------------------------ |
77 | for (; iteS.More(); iteS.Next()) { |
78 | const TopoDS_Shape& SS = iteS.Value(); |
79 | Build (SS); |
80 | if (IsCopied(SS)) { |
81 | IsModified = Standard_True; |
82 | } |
83 | } |
84 | |
85 | TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD); |
86 | if (IsModified) { |
87 | //---------------------------------------- |
88 | // Rebuild S. |
89 | //------------------------------------------ |
90 | NewS.EmptyCopy(); |
91 | |
92 | if (NewS.ShapeType() == TopAbs_EDGE) { |
93 | Standard_Real f,l; |
94 | BRep_Tool::Range(TopoDS::Edge(S),f,l); |
95 | B.Range(TopoDS::Edge(NewS),f,l); |
96 | } |
97 | |
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); |
107 | |
108 | for ( ; iteL.More(); iteL.Next()){ |
109 | const TopoDS_Shape NSS = iteL.Value(); |
110 | //------------------------------------------ |
111 | // Rebuild NSS and add its copy to NewS. |
112 | //------------------------------------------ |
113 | Build(NSS); |
114 | |
115 | const TopTools_ListOfShape& NL = myMap(NSS); |
116 | TopAbs_Orientation NewOr = TopAbs::Compose(OS,NSS.Orientation()); |
117 | TopTools_ListIteratorOfListOfShape iteNL(NL); |
118 | |
119 | for ( ; iteNL.More(); iteNL.Next()){ |
120 | B.Add (NewS,iteNL.Value().Oriented(NewOr)); |
121 | HasSubShape = Standard_True; |
122 | } |
123 | } |
124 | } |
125 | if (!HasSubShape) { |
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 | //--------------------------------------------------------------- |
131 | NewS.Nullify(); |
132 | } |
133 | } |
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)); |
140 | Substitute(S, L); |
141 | } |
142 | |
143 | |
144 | //======================================================================= |
145 | //function : IsCopied |
146 | //purpose : |
147 | //======================================================================= |
148 | |
149 | Standard_Boolean BRepTools_Substitution::IsCopied(const TopoDS_Shape& S) const |
150 | { |
151 | if (myMap.IsBound(S)) { |
152 | if (myMap (S).IsEmpty()) return Standard_True; |
153 | else |
154 | return !S.IsSame(myMap(S).First()); |
155 | } |
156 | else |
157 | return Standard_False; |
158 | } |
159 | |
160 | |
161 | //======================================================================= |
162 | //function : Copy |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | const TopTools_ListOfShape& BRepTools_Substitution::Copy (const TopoDS_Shape& S) |
167 | const |
168 | { |
169 | Standard_NoSuchObject_Raise_if(!IsCopied(S),"BRepTools_Substitution::Copy"); |
170 | return myMap(S); |
171 | } |
172 | |