b311480e |
1 | // Created on: 2002-02-07 |
2 | // Created by: Igor FEOKTISTOV |
973c2be1 |
3 | // Copyright (c) 2002-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
7fd59977 |
17 | #include <BRep_Builder.hxx> |
42cf5bc1 |
18 | #include <BRepBuilderAPI_Copy.hxx> |
19 | #include <QANewModTopOpe_ReShaper.hxx> |
20 | #include <Standard_Type.hxx> |
7fd59977 |
21 | #include <TopoDS.hxx> |
42cf5bc1 |
22 | #include <TopoDS_Compound.hxx> |
23 | #include <TopoDS_Iterator.hxx> |
24 | #include <TopoDS_Shape.hxx> |
25 | #include <TopTools_HSequenceOfShape.hxx> |
7fd59977 |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(QANewModTopOpe_ReShaper,MMgt_TShared) |
28 | |
7fd59977 |
29 | QANewModTopOpe_ReShaper::QANewModTopOpe_ReShaper(const TopoDS_Shape& TheInitialShape): |
30 | myInitShape(TheInitialShape) |
31 | { |
32 | |
33 | } |
34 | QANewModTopOpe_ReShaper::QANewModTopOpe_ReShaper(const TopoDS_Shape& TheInitialShape, |
35 | const TopTools_MapOfShape& TheMap): |
36 | myInitShape(TheInitialShape) |
37 | { |
38 | myMap.Assign(TheMap); |
39 | } |
40 | |
41 | QANewModTopOpe_ReShaper::QANewModTopOpe_ReShaper(const TopoDS_Shape& TheInitialShape, |
42 | const Handle(TopTools_HSequenceOfShape)& TheShapeToBeRemoved): |
43 | myInitShape(TheInitialShape) |
44 | { |
45 | |
46 | Standard_Integer i, n = TheShapeToBeRemoved->Length(); |
47 | for(i = 1; i <= n; i++) { |
48 | myMap.Add(TheShapeToBeRemoved->Value(i)); |
49 | } |
50 | |
51 | } |
52 | |
53 | void QANewModTopOpe_ReShaper::Remove(const TopoDS_Shape& TheS) |
54 | { |
55 | myMap.Add(TheS); |
56 | } |
57 | |
58 | void QANewModTopOpe_ReShaper::Perform() |
59 | { |
60 | |
61 | BRepBuilderAPI_Copy aCopier; |
62 | |
63 | if(myMap.IsEmpty()) { |
64 | |
65 | aCopier.Perform(myInitShape); |
66 | myResult = aCopier.Shape(); |
67 | return; |
68 | |
69 | } |
70 | |
71 | BRep_Builder aBB; |
72 | myResult.Nullify(); |
73 | aBB.MakeCompound(TopoDS::Compound(myResult)); |
74 | TopoDS_Iterator anIter(myInitShape); |
75 | |
76 | for(; anIter.More(); anIter.Next()) { |
77 | |
78 | const TopoDS_Shape& aS = anIter.Value(); |
79 | |
80 | if(myMap.Contains(aS)) continue; |
81 | |
82 | if(aS.ShapeType() != TopAbs_COMPOUND) { |
83 | aCopier.Perform(aS); |
84 | aBB.Add(myResult, aCopier.Shape()); |
85 | } |
86 | else { |
87 | Handle(QANewModTopOpe_ReShaper) aR = new QANewModTopOpe_ReShaper(aS, myMap); |
88 | aR->Perform(); |
89 | const TopoDS_Shape& aSp = aR->GetResult(); |
90 | if(aSp.ShapeType() == TopAbs_COMPOUND) { |
91 | TopoDS_Iterator anIt(aSp); |
92 | if(anIt.More()) { |
93 | aBB.Add(myResult, aSp); |
94 | } |
95 | } |
96 | else { |
97 | aBB.Add(myResult, aSp); |
98 | } |
99 | } |
100 | |
101 | } |
102 | |
103 | if(myResult.ShapeType() == TopAbs_COMPOUND) { |
104 | anIter.Initialize(myResult); |
105 | if(anIter.More()) { |
106 | const TopoDS_Shape& aSp = anIter.Value(); |
107 | anIter.Next(); |
108 | if(!anIter.More()) myResult = aSp; |
109 | } |
110 | } |
111 | |
112 | } |
113 | |
114 | const TopoDS_Shape& QANewModTopOpe_ReShaper::GetResult() const |
115 | { |
116 | return myResult; |
117 | } |
118 | |
119 | void QANewModTopOpe_ReShaper::Clear() |
120 | { |
121 | myMap.Clear(); |
122 | myResult.Nullify(); |
123 | } |