1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: NMTAlgo_Splitter1.cxx
23 // Created: Wed Feb 11 14:26:27 2004
24 // Author: Peter KURNEV
27 #include <NMTAlgo_Splitter1.ixx>
28 #include <NMTAlgo_Splitter.hxx>
29 #include <TopAbs_ShapeEnum.hxx>
30 #include <TopoDS_Iterator.hxx>
31 #include <TopTools_IndexedMapOfShape.hxx>
32 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
34 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopTools_ListOfShape.hxx>
38 #include <TopExp_Explorer.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TopTools_DataMapOfIntegerListOfShape.hxx>
43 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
44 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_MapOfShape.hxx>
47 #include <NMTAlgo_Loop3d.hxx>
48 #include <TopTools_MapOfOrientedShape.hxx>
49 #include <BRep_Builder.hxx>
50 #include <TopoDS_Solid.hxx>
51 #include <NMTAlgo_Tools.hxx>
53 //=======================================================================
54 //function : NMTAlgo_Spliter1::NMTAlgo_Splitter1
56 //=======================================================================
57 NMTAlgo_Splitter1::NMTAlgo_Splitter1()
61 myRemoveWebs=Standard_False;
63 //=======================================================================
64 // function: ~NMTAlgo_Splitter1
66 //=======================================================================
67 NMTAlgo_Splitter1::~NMTAlgo_Splitter1()
71 //=======================================================================
74 //=======================================================================
75 void NMTAlgo_Splitter1::Clear()
77 NMTAlgo_Splitter::Clear();
79 myRemoveWebs=Standard_False;
83 //=======================================================================
84 //function : SetRemoveWebs
86 //=======================================================================
87 void NMTAlgo_Splitter1::SetRemoveWebs(const Standard_Boolean bFlag)
91 //=======================================================================
92 //function : RemoveWebs
94 //=======================================================================
95 Standard_Boolean NMTAlgo_Splitter1::RemoveWebs()const
99 //=======================================================================
100 //function : GetMaterialTable
102 //=======================================================================
103 const TopTools_DataMapOfShapeInteger& NMTAlgo_Splitter1::GetMaterialTable()const
107 //=======================================================================
108 //function : SetMaterial
110 //=======================================================================
111 void NMTAlgo_Splitter1::SetMaterial(const TopoDS_Shape& aS,
112 const Standard_Integer iMt)
114 TopExp_Explorer aExp;
116 aExp.Init(aS, TopAbs_SOLID);
117 for(; aExp.More(); aExp.Next()) {
118 const TopoDS_Shape& aSd=aExp.Current();
119 myMapSWM.Bind(aSd, iMt);
122 //=======================================================================
123 //function : AddShape
125 //=======================================================================
126 void NMTAlgo_Splitter1::AddShape(const TopoDS_Shape& aS)
129 NMTAlgo_Splitter::AddShape(aS);
131 //=======================================================================
132 //function : AddToolWithMaterial
134 //=======================================================================
135 void NMTAlgo_Splitter1::AddTool(const TopoDS_Shape& aS)
139 NMTAlgo_Splitter::AddTool(aS);
141 //=======================================================================
144 //=======================================================================
145 void NMTAlgo_Splitter1::Build(const TopAbs_ShapeEnum aLimit)
147 NMTAlgo_Splitter::Build(aLimit);
153 if (myRemoveWebs && myMapSWMOut.Extent()) {
158 //=======================================================================
159 //function : TreatWebs
161 //=======================================================================
162 void NMTAlgo_Splitter1::TreatWebs()
164 Standard_Integer nMt;
165 TopTools_DataMapOfIntegerListOfShape aMMLS;
167 TopTools_DataMapIteratorOfDataMapOfShapeInteger aIt2;
168 TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aIt1;
169 TopTools_ListIteratorOfListOfShape aItS;
173 aIt2.Initialize(myMapSWMOut);
174 for (; aIt2.More(); aIt2.Next()) {
175 const TopoDS_Shape& aS=aIt2.Key();
178 if (aMMLS.IsBound(nMt)){
179 TopTools_ListOfShape& aLS=aMMLS.ChangeFind(nMt);
183 TopTools_ListOfShape aLS;
185 aMMLS.Bind(nMt, aLS);
190 myBuilder.MakeCompound(aCx);
192 aIt1.Initialize(aMMLS);
193 for (; aIt1.More(); aIt1.Next()) {
197 myBuilder.MakeCompound(aCS);
198 const TopTools_ListOfShape& aLS=aIt1.Value();
199 aItS.Initialize(aLS);
200 for (; aItS.More(); aItS.Next()) {
201 const TopoDS_Shape& aS=aItS.Value();
202 myBuilder.Add(aCS, aS);
205 NMTAlgo_Tools::BreakWebs(aCS, aCSR);
207 aIt.Initialize(aCSR);
208 for(; aIt.More(); aIt.Next()) {
209 const TopoDS_Shape& aS=aIt.Value();
210 myBuilder.Add(aCx, aS);
212 myMapSWMOut.Bind(aS, nMt);
216 aIt.Initialize(myRestParts);
217 for(; aIt.More(); aIt.Next()) {
218 const TopoDS_Shape& aS=aIt.Value();
219 myBuilder.Add(aCx, aS);
225 //=======================================================================
226 //function : RestParts
228 //=======================================================================
229 void NMTAlgo_Splitter1::RestParts()
234 myBuilder.MakeCompound(aR);
236 aIt.Initialize(myShape);
237 for(; aIt.More(); aIt.Next()) {
238 const TopoDS_Shape& aS=aIt.Value();
239 if (aS.ShapeType()==TopAbs_SOLID){
240 if (myMapSWMOut.IsBound(aS)) {
244 myBuilder.Add(aR, aS);
248 //=======================================================================
249 //function : TreatSolids
251 //=======================================================================
252 void NMTAlgo_Splitter1::TreatSolids()
254 Standard_Integer i, j, aNbSd, aNbSdx, nMtMax, nMt;
255 TopAbs_ShapeEnum aType;
257 TopTools_IndexedMapOfShape aMSo, aMSd;
258 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
259 TopTools_ListIteratorOfListOfShape aItS, aItLS;
260 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMCS;
262 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
263 TopExp::MapShapes(myShape, TopAbs_SOLID, aMSo);
270 aItS.Initialize(myListShapes);
271 for ( ;aItS.More(); aItS.Next()) {
272 const TopoDS_Shape& aS=aItS.Value();
274 aType=aS.ShapeType();
275 if (aType != TopAbs_SOLID) {
279 if (myToolShapes.Contains(aS)) {
283 if (!myMapSIFC.IsBound(aS)){
289 const TopoDS_Shape& aIFC=myMapSIFC.Find(aS);
291 aIt.Initialize(aIFC);
292 for (; aIt.More(); aIt.Next()) {
293 const TopoDS_Shape& aIF=aIt.Value();
294 if (aMFS.Contains(aIF)) {
295 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aIF);
296 aItLS.Initialize(aLS);
297 for ( ;aItLS.More(); aItLS.Next()) {
298 const TopoDS_Shape& aSd=aItLS.Value();
299 if (!aMSd.Contains(aSd)) {
308 //modified by NIZNHY-PKV Thu Dec 23 15:07:46 2004 f
309 Standard_Boolean bFound;
310 //modified by NIZNHY-PKV Thu Dec 23 15:07:49 2004 t
313 const TopoDS_Shape& aFC=myImageShape.Image(aS).First();
314 //modified by NIZNHY-PKV Thu Dec 23 15:08:17 2004 f
315 //NMTAlgo_Tools::FindImageSolid(aFC, aMSo, aSd);
317 bFound=NMTAlgo_Tools::FindImageSolid(aFC, aMSo, aSd);
321 //modified by NIZNHY-PKV Thu Dec 23 15:09:02 2004 t
324 } //for ( ;aItS.More(); aItS.Next())
329 for (i=1; i<=aNbSd; ++i) {
330 const TopoDS_Shape& aSd=aMCS.FindKey(i);
331 const TopTools_IndexedMapOfShape& aMSdx=aMCS(i);
332 aNbSdx=aMSdx.Extent();
333 for (j=1; j<=aNbSdx; ++j) {
334 const TopoDS_Shape& aSdx=aMSdx(j);
336 if (aMFS.Contains(aSdx)) {
337 TopTools_ListOfShape& aLS=aMFS.ChangeFromKey(aSdx);
341 TopTools_ListOfShape aLS;
348 // Assign materials values to subsolids
352 aNbSdx=aMFS.Extent();
353 for (i=1; i<=aNbSdx; ++i) {
354 const TopoDS_Shape& aSdx=aMFS.FindKey(i);
355 const TopTools_ListOfShape& aLS=aMFS(i);
356 aItLS.Initialize(aLS);
357 for (j=0; aItLS.More(); aItLS.Next(), ++j) {
358 const TopoDS_Shape& aSd=aItLS.Value();
360 if (!myMapSWM.IsBound(aSd)){
364 nMt=myMapSWM.Find(aSd);
373 myMapSWMOut.Bind(aSdx, nMtMax);