| 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 |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 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. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | #include <BRepTools_Substitution.ixx> |
| 18 | #include <TopoDS.hxx> |
| 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> |
| 25 | |
| 26 | //======================================================================= |
| 27 | //function : BRepTools_Substitution |
| 28 | //purpose : |
| 29 | //======================================================================= |
| 30 | |
| 31 | BRepTools_Substitution::BRepTools_Substitution() |
| 32 | {} |
| 33 | |
| 34 | //======================================================================= |
| 35 | //function : Clear |
| 36 | //purpose : |
| 37 | //======================================================================= |
| 38 | |
| 39 | void BRepTools_Substitution::Clear() |
| 40 | { |
| 41 | myMap.Clear(); |
| 42 | } |
| 43 | |
| 44 | //======================================================================= |
| 45 | //function : Substitute |
| 46 | //purpose : |
| 47 | //======================================================================= |
| 48 | |
| 49 | void BRepTools_Substitution::Substitute(const TopoDS_Shape& OS, |
| 50 | const TopTools_ListOfShape& NS) |
| 51 | { |
| 52 | Standard_ConstructionError_Raise_if |
| 53 | (IsCopied(OS),"BRepTools_CutClue::Substitute"); |
| 54 | myMap.Bind(OS,NS); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | //======================================================================= |
| 59 | //function : Build |
| 60 | //purpose : |
| 61 | //======================================================================= |
| 62 | |
| 63 | void BRepTools_Substitution::Build(const TopoDS_Shape& S) |
| 64 | { |
| 65 | if (IsCopied(S)) return; |
| 66 | |
| 67 | BRep_Builder B; |
| 68 | TopoDS_Iterator iteS (S.Oriented(TopAbs_FORWARD)); |
| 69 | Standard_Boolean IsModified = Standard_False; |
| 70 | Standard_Boolean HasSubShape = Standard_False; |
| 71 | |
| 72 | //------------------------------------------ |
| 73 | // look S is modified and build subshapes. |
| 74 | //------------------------------------------ |
| 75 | for (; iteS.More(); iteS.Next()) { |
| 76 | const TopoDS_Shape& SS = iteS.Value(); |
| 77 | Build (SS); |
| 78 | if (IsCopied(SS)) { |
| 79 | IsModified = Standard_True; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | TopoDS_Shape NewS = S.Oriented(TopAbs_FORWARD); |
| 84 | if (IsModified) { |
| 85 | //---------------------------------------- |
| 86 | // Rebuild S. |
| 87 | //------------------------------------------ |
| 88 | NewS.EmptyCopy(); |
| 89 | |
| 90 | if (NewS.ShapeType() == TopAbs_EDGE) { |
| 91 | Standard_Real f,l; |
| 92 | BRep_Tool::Range(TopoDS::Edge(S),f,l); |
| 93 | B.Range(TopoDS::Edge(NewS),f,l); |
| 94 | } |
| 95 | |
| 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); |
| 105 | |
| 106 | for ( ; iteL.More(); iteL.Next()){ |
| 107 | const TopoDS_Shape NSS = iteL.Value(); |
| 108 | //------------------------------------------ |
| 109 | // Rebuild NSS and add its copy to NewS. |
| 110 | //------------------------------------------ |
| 111 | Build(NSS); |
| 112 | |
| 113 | const TopTools_ListOfShape& NL = myMap(NSS); |
| 114 | TopAbs_Orientation NewOr = TopAbs::Compose(OS,NSS.Orientation()); |
| 115 | TopTools_ListIteratorOfListOfShape iteNL(NL); |
| 116 | |
| 117 | for ( ; iteNL.More(); iteNL.Next()){ |
| 118 | B.Add (NewS,iteNL.Value().Oriented(NewOr)); |
| 119 | HasSubShape = Standard_True; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | if (!HasSubShape) { |
| 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 | //--------------------------------------------------------------- |
| 129 | NewS.Nullify(); |
| 130 | } |
| 131 | } |
| 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)); |
| 138 | Substitute(S, L); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | //======================================================================= |
| 143 | //function : IsCopied |
| 144 | //purpose : |
| 145 | //======================================================================= |
| 146 | |
| 147 | Standard_Boolean BRepTools_Substitution::IsCopied(const TopoDS_Shape& S) const |
| 148 | { |
| 149 | if (myMap.IsBound(S)) { |
| 150 | if (myMap (S).IsEmpty()) return Standard_True; |
| 151 | else |
| 152 | return !S.IsSame(myMap(S).First()); |
| 153 | } |
| 154 | else |
| 155 | return Standard_False; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | //======================================================================= |
| 160 | //function : Copy |
| 161 | //purpose : |
| 162 | //======================================================================= |
| 163 | |
| 164 | const TopTools_ListOfShape& BRepTools_Substitution::Copy (const TopoDS_Shape& S) |
| 165 | const |
| 166 | { |
| 167 | Standard_NoSuchObject_Raise_if(!IsCopied(S),"BRepTools_Substitution::Copy"); |
| 168 | return myMap(S); |
| 169 | } |
| 170 | |