1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: NMTAlgo_Splitter1.cxx
21 // Created: Wed Feb 11 14:26:27 2004
22 // Author: Peter KURNEV
26 #include <NMTAlgo_Splitter1.ixx>
27 #include <NMTAlgo_Splitter.hxx>
28 #include <TopAbs_ShapeEnum.hxx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopTools_IndexedMapOfShape.hxx>
31 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
40 #include <TopoDS_Compound.hxx>
41 #include <TopTools_DataMapOfIntegerListOfShape.hxx>
42 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
43 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
45 #include <TopTools_MapOfShape.hxx>
46 #include <NMTAlgo_Loop3d.hxx>
47 #include <TopTools_MapOfOrientedShape.hxx>
48 #include <BRep_Builder.hxx>
49 #include <TopoDS_Solid.hxx>
50 #include <NMTAlgo_Tools.hxx>
52 //=======================================================================
53 //function : NMTAlgo_Spliter1::NMTAlgo_Splitter1
55 //=======================================================================
56 NMTAlgo_Splitter1::NMTAlgo_Splitter1()
60 myRemoveWebs=Standard_False;
62 //=======================================================================
63 // function: ~NMTAlgo_Splitter1
65 //=======================================================================
66 NMTAlgo_Splitter1::~NMTAlgo_Splitter1()
70 //=======================================================================
73 //=======================================================================
74 void NMTAlgo_Splitter1::Clear()
76 NMTAlgo_Splitter::Clear();
78 myRemoveWebs=Standard_False;
82 //=======================================================================
83 //function : SetRemoveWebs
85 //=======================================================================
86 void NMTAlgo_Splitter1::SetRemoveWebs(const Standard_Boolean bFlag)
90 //=======================================================================
91 //function : RemoveWebs
93 //=======================================================================
94 Standard_Boolean NMTAlgo_Splitter1::RemoveWebs()const
98 //=======================================================================
99 //function : GetMaterialTable
101 //=======================================================================
102 const TopTools_DataMapOfShapeInteger& NMTAlgo_Splitter1::GetMaterialTable()const
106 //=======================================================================
107 //function : SetMaterial
109 //=======================================================================
110 void NMTAlgo_Splitter1::SetMaterial(const TopoDS_Shape& aS,
111 const Standard_Integer iMt)
113 TopExp_Explorer aExp;
115 aExp.Init(aS, TopAbs_SOLID);
116 for(; aExp.More(); aExp.Next()) {
117 const TopoDS_Shape& aSd=aExp.Current();
118 myMapSWM.Bind(aSd, iMt);
121 //=======================================================================
122 //function : AddShape
124 //=======================================================================
125 void NMTAlgo_Splitter1::AddShape(const TopoDS_Shape& aS)
128 NMTAlgo_Splitter::AddShape(aS);
130 //=======================================================================
131 //function : AddToolWithMaterial
133 //=======================================================================
134 void NMTAlgo_Splitter1::AddTool(const TopoDS_Shape& aS)
138 NMTAlgo_Splitter::AddTool(aS);
140 //=======================================================================
143 //=======================================================================
144 void NMTAlgo_Splitter1::Build(const TopAbs_ShapeEnum aLimit)
146 NMTAlgo_Splitter::Build(aLimit);
152 if (myRemoveWebs && myMapSWMOut.Extent()) {
157 //=======================================================================
158 //function : TreatWebs
160 //=======================================================================
161 void NMTAlgo_Splitter1::TreatWebs()
163 Standard_Integer nMt;
164 TopTools_DataMapOfIntegerListOfShape aMMLS;
166 TopTools_DataMapIteratorOfDataMapOfShapeInteger aIt2;
167 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aIt1;
168 TopTools_ListIteratorOfListOfShape aItS;
172 aIt2.Initialize(myMapSWMOut);
173 for (; aIt2.More(); aIt2.Next()) {
174 const TopoDS_Shape& aS=aIt2.Key();
177 if (aMMLS.IsBound(nMt)){
178 TopTools_ListOfShape& aLS=aMMLS.ChangeFind(nMt);
182 TopTools_ListOfShape aLS;
184 aMMLS.Bind(nMt, aLS);
189 myBuilder.MakeCompound(aCx);
191 aIt1.Initialize(aMMLS);
192 for (; aIt1.More(); aIt1.Next()) {
196 myBuilder.MakeCompound(aCS);
197 const TopTools_ListOfShape& aLS=aIt1.Value();
198 aItS.Initialize(aLS);
199 for (; aItS.More(); aItS.Next()) {
200 const TopoDS_Shape& aS=aItS.Value();
201 myBuilder.Add(aCS, aS);
204 NMTAlgo_Tools::BreakWebs(aCS, aCSR);
206 aIt.Initialize(aCSR);
207 for(; aIt.More(); aIt.Next()) {
208 const TopoDS_Shape& aS=aIt.Value();
209 myBuilder.Add(aCx, aS);
211 myMapSWMOut.Bind(aS, nMt);
215 aIt.Initialize(myRestParts);
216 for(; aIt.More(); aIt.Next()) {
217 const TopoDS_Shape& aS=aIt.Value();
218 myBuilder.Add(aCx, aS);
224 //=======================================================================
225 //function : RestParts
227 //=======================================================================
228 void NMTAlgo_Splitter1::RestParts()
233 myBuilder.MakeCompound(aR);
235 aIt.Initialize(myShape);
236 for(; aIt.More(); aIt.Next()) {
237 const TopoDS_Shape& aS=aIt.Value();
238 if (aS.ShapeType()==TopAbs_SOLID){
239 if (myMapSWMOut.IsBound(aS)) {
243 myBuilder.Add(aR, aS);
247 //=======================================================================
248 //function : TreatSolids
250 //=======================================================================
251 void NMTAlgo_Splitter1::TreatSolids()
253 Standard_Integer i, j, aNbSd, aNbSdx, nMtMax, nMt;
254 TopAbs_ShapeEnum aType;
256 TopTools_IndexedMapOfShape aMSo, aMSd;
257 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
258 TopTools_ListIteratorOfListOfShape aItS, aItLS;
259 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMCS;
261 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
262 TopExp::MapShapes(myShape, TopAbs_SOLID, aMSo);
269 aItS.Initialize(myListShapes);
270 for ( ;aItS.More(); aItS.Next()) {
271 const TopoDS_Shape& aS=aItS.Value();
273 aType=aS.ShapeType();
274 if (aType != TopAbs_SOLID) {
278 if (myToolShapes.Contains(aS)) {
282 if (!myMapSIFC.IsBound(aS)){
288 const TopoDS_Shape& aIFC=myMapSIFC.Find(aS);
290 aIt.Initialize(aIFC);
291 for (; aIt.More(); aIt.Next()) {
292 const TopoDS_Shape& aIF=aIt.Value();
293 if (aMFS.Contains(aIF)) {
294 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aIF);
295 aItLS.Initialize(aLS);
296 for ( ;aItLS.More(); aItLS.Next()) {
297 const TopoDS_Shape& aSd=aItLS.Value();
298 if (!aMSd.Contains(aSd)) {
307 //modified by NIZNHY-PKV Thu Dec 23 15:07:46 2004 f
308 Standard_Boolean bFound;
309 //modified by NIZNHY-PKV Thu Dec 23 15:07:49 2004 t
312 const TopoDS_Shape& aFC=myImageShape.Image(aS).First();
313 //modified by NIZNHY-PKV Thu Dec 23 15:08:17 2004 f
314 //NMTAlgo_Tools::FindImageSolid(aFC, aMSo, aSd);
316 bFound=NMTAlgo_Tools::FindImageSolid(aFC, aMSo, aSd);
320 //modified by NIZNHY-PKV Thu Dec 23 15:09:02 2004 t
323 } //for ( ;aItS.More(); aItS.Next())
328 for (i=1; i<=aNbSd; ++i) {
329 const TopoDS_Shape& aSd=aMCS.FindKey(i);
330 const TopTools_IndexedMapOfShape& aMSdx=aMCS(i);
331 aNbSdx=aMSdx.Extent();
332 for (j=1; j<=aNbSdx; ++j) {
333 const TopoDS_Shape& aSdx=aMSdx(j);
335 if (aMFS.Contains(aSdx)) {
336 TopTools_ListOfShape& aLS=aMFS.ChangeFromKey(aSdx);
340 TopTools_ListOfShape aLS;
347 // Assign materials values to subsolids
351 aNbSdx=aMFS.Extent();
352 for (i=1; i<=aNbSdx; ++i) {
353 const TopoDS_Shape& aSdx=aMFS.FindKey(i);
354 const TopTools_ListOfShape& aLS=aMFS(i);
355 aItLS.Initialize(aLS);
356 for (j=0; aItLS.More(); aItLS.Next(), ++j) {
357 const TopoDS_Shape& aSd=aItLS.Value();
359 if (!myMapSWM.IsBound(aSd)){
363 nMt=myMapSWM.Find(aSd);
372 myMapSWMOut.Bind(aSdx, nMtMax);