b311480e |
1 | // Created on: 2000-12-26 |
2 | // Created by: Vladislav ROMASHKO <vro@nnov.matra-dtv.fr> |
973c2be1 |
3 | // Copyright (c) 2000-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_Tool.hxx> |
42cf5bc1 |
18 | #include <QANewBRepNaming_Limitation.hxx> |
19 | #include <QANewBRepNaming_Loader.hxx> |
20 | #include <QANewModTopOpe_Limitation.hxx> |
21 | #include <QANewModTopOpe_ModeOfLimitation.hxx> |
22 | #include <TDataStd_Name.hxx> |
23 | #include <TDF_Label.hxx> |
24 | #include <TNaming_Builder.hxx> |
25 | #include <TNaming_NamedShape.hxx> |
7fd59977 |
26 | #include <TopExp.hxx> |
27 | #include <TopExp_Explorer.hxx> |
42cf5bc1 |
28 | #include <TopoDS.hxx> |
29 | #include <TopoDS_Iterator.hxx> |
30 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
31 | #include <TopTools_IndexedMapOfShape.hxx> |
32 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
7fd59977 |
33 | |
34 | // OCAF |
7fd59977 |
35 | // Specific |
7fd59977 |
36 | //======================================================================= |
37 | //function : QANewBRepNaming_Limitation |
38 | //purpose : |
39 | //======================================================================= |
7fd59977 |
40 | QANewBRepNaming_Limitation::QANewBRepNaming_Limitation() {} |
41 | |
42 | //======================================================================= |
43 | //function : QANewBRepNaming_Limitation |
44 | //purpose : |
45 | //======================================================================= |
46 | |
47 | QANewBRepNaming_Limitation::QANewBRepNaming_Limitation(const TDF_Label& ResultLabel) |
e45b5ff7 |
48 | :QANewBRepNaming_BooleanOperation(ResultLabel) {} |
7fd59977 |
49 | |
50 | //======================================================================= |
51 | //function : Load |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | void QANewBRepNaming_Limitation::Load(QANewModTopOpe_Limitation& MS) const { |
56 | TopoDS_Shape ResSh = MS.Shape(); |
57 | |
58 | const TopoDS_Shape& ObjSh = MS.Shape1(); |
7fd59977 |
59 | const TopAbs_ShapeEnum& ObjType = ShapeType(ObjSh); |
60 | |
61 | if (ResSh.IsNull()) { |
0797d9d3 |
62 | #ifdef OCCT_DEBUG |
7fd59977 |
63 | cout<<"QANewBRepNaming_Limitation::Load(): The result of the boolean operation is null"<<endl; |
64 | #endif |
65 | return; |
66 | } |
67 | |
68 | if (MS.Shape().ShapeType() == TopAbs_COMPOUND) { |
69 | Standard_Integer nbSubResults = 0; |
70 | TopoDS_Iterator itr(MS.Shape()); |
71 | for (; itr.More(); itr.Next()) nbSubResults++; |
72 | if (nbSubResults == 1) { |
73 | itr.Initialize(MS.Shape()); |
74 | if (itr.More()) ResSh = itr.Value(); |
75 | } |
76 | } |
77 | if(MS.Shape1().IsSame(ResSh)) { |
78 | // If the shapes are the same - select the result and exit: |
0797d9d3 |
79 | #ifdef OCCT_DEBUG |
7fd59977 |
80 | cout<<"QANewBRepNaming_Limitation::Load(): The object and the result of LIMITATION operation are the same"<<endl; |
81 | #endif |
82 | TNaming_Builder aBuilder(ResultLabel()); |
83 | aBuilder.Select(ResSh, ObjSh); |
84 | return; |
85 | } |
86 | // Naming of the result: |
87 | LoadResult(MS); |
88 | |
89 | // Naming of the content: |
90 | // if (ResSh.ShapeType() == TopAbs_COMPOUND) { |
91 | |
92 | // LoadContent(MS); |
93 | |
94 | // } |
95 | |
96 | // Naming of modified, deleted and new sub shapes: |
97 | if (ObjType == TopAbs_WIRE || ObjType == TopAbs_EDGE) { |
98 | // LoadWire(MS); |
99 | TNaming_Builder ModBuilder(ModifiedEdges()); |
100 | QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False); |
101 | if(MS.HasGenerated()) { |
102 | TNaming_Builder nBuilder (NewShapes()); |
103 | // generated Vertexes |
104 | QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_EDGE, nBuilder); |
105 | QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder); |
106 | QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder); |
107 | } |
108 | if(MS.HasDeleted()){ |
109 | TNaming_Builder DelEBuilder(DeletedEdges()); |
110 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder); |
111 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder); |
112 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_VERTEX, DelEBuilder); |
113 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_VERTEX, DelEBuilder); |
114 | } |
115 | } |
116 | else if (ObjType == TopAbs_SHELL || ObjType == TopAbs_FACE) { |
117 | //LoadShell(MS); |
118 | TNaming_Builder ModBuilder(ModifiedFaces()); |
119 | QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False); |
120 | QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_EDGE, ModBuilder, Standard_False); |
121 | |
122 | if(MS.HasGenerated()) { |
123 | TNaming_Builder nBuilder (NewShapes()); |
124 | // generated free Edges |
125 | QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape1(), TopAbs_FACE, nBuilder); |
126 | QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_FACE, nBuilder); |
127 | QANewBRepNaming_Loader::LoadGeneratedShapes (MS, MS.Shape2(), TopAbs_EDGE, nBuilder); |
128 | } |
129 | if(MS.HasDeleted()){ |
130 | TNaming_Builder DelEBuilder(DeletedFaces()); |
131 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder); |
132 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder); |
133 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_EDGE, DelEBuilder); //free bound. |
134 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_EDGE, DelEBuilder); |
135 | } |
136 | } |
137 | else if(ObjType == TopAbs_SOLID) { |
138 | TNaming_Builder ModBuilder(ModifiedFaces()); |
139 | QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape1(), TopAbs_FACE, ModBuilder, Standard_False); |
140 | QANewBRepNaming_Loader::LoadModifiedShapes (MS, MS.Shape2(), TopAbs_FACE, ModBuilder, Standard_False); |
141 | |
142 | if(MS.HasDeleted()){ |
143 | TNaming_Builder DelEBuilder(DeletedFaces()); |
144 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape1(), TopAbs_FACE, DelEBuilder); |
145 | QANewBRepNaming_Loader::LoadDeletedShapes(MS, MS.Shape2(), TopAbs_FACE, DelEBuilder); |
146 | } |
147 | } |
148 | |
149 | LoadDegenerated(MS); |
150 | |
151 | } |
152 | |
153 | //======================================================================= |
154 | //function : LoadResult |
155 | //purpose : |
156 | //======================================================================= |
157 | |
158 | void QANewBRepNaming_Limitation::LoadResult(QANewModTopOpe_Limitation& MS) const { |
159 | Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel()); |
160 | if (Tagger.IsNull()) return; |
161 | Tagger->Set(0); |
162 | TNaming_Builder Builder (ResultLabel()); |
163 | TopoDS_Shape aResult = MS.Shape(); |
164 | if (aResult.ShapeType() == TopAbs_COMPOUND) { |
165 | Standard_Integer nbSubResults = 0; |
166 | TopoDS_Iterator itr(aResult); |
167 | for (; itr.More(); itr.Next()) nbSubResults++; |
168 | if (nbSubResults == 1) { |
169 | itr.Initialize(aResult); |
170 | if (itr.More()) aResult = itr.Value(); |
171 | } |
172 | } |
173 | if (MS.Shape1().IsNull()) Builder.Generated(aResult); |
174 | else Builder.Modify(MS.Shape1(), aResult); |
175 | } |
176 | |
177 | //======================================================================= |
178 | //function : LoadDegenerated |
179 | //purpose : |
180 | //======================================================================= |
181 | |
182 | void QANewBRepNaming_Limitation::LoadDegenerated(QANewModTopOpe_Limitation& MS) const { |
183 | TopTools_IndexedMapOfShape allEdges; |
184 | TopExp::MapShapes(MS.Shape1(), TopAbs_EDGE, allEdges); |
185 | Standard_Integer i = 1; |
186 | for (; i <= allEdges.Extent(); i++) { |
187 | if (BRep_Tool::Degenerated(TopoDS::Edge(allEdges.FindKey(i)))) { |
188 | if (MS.IsDeleted(allEdges.FindKey(i))) { |
189 | TNaming_Builder DegeneratedBuilder(DeletedDegeneratedEdges()); |
190 | DegeneratedBuilder.Generated(allEdges.FindKey(i)); |
0797d9d3 |
191 | #ifdef OCCT_DEBUG |
7fd59977 |
192 | TDataStd_Name::Set(DegeneratedBuilder.NamedShape()->Label(), "DeletedDegenerated"); |
193 | #endif |
194 | } |
195 | } |
196 | } |
197 | } |
198 | //======================================================================= |
199 | //function : LoadContent |
200 | //purpose : |
201 | //======================================================================= |
202 | |
203 | void QANewBRepNaming_Limitation::LoadContent(QANewModTopOpe_Limitation& MS) const { |
204 | if (MS.Shape().ShapeType() == TopAbs_COMPSOLID || MS.Shape().ShapeType() == TopAbs_COMPOUND) { |
205 | TopoDS_Iterator itr(MS.Shape()); |
206 | Standard_Integer nbShapes = 0; |
207 | while (itr.More()) { |
208 | nbShapes++; |
209 | itr.Next(); |
210 | } |
211 | if (nbShapes > 1) { |
212 | for (itr.Initialize(MS.Shape()); itr.More(); itr.Next()) { |
213 | TNaming_Builder bContent(Content()); |
214 | bContent.Generated(MS.Shape1(),itr.Value()); |
215 | bContent.Generated(MS.Shape2(),itr.Value()); |
216 | } |
217 | } |
218 | } |
219 | } |