]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_SplitToZonesTool.cxx
Salome HOME
Merge branch 'BR_v14_rc' into BR_SINUSX_FORMAT
[modules/hydro.git] / src / HYDROData / HYDROData_SplitToZonesTool.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_SplitToZonesTool.h"
20
21 #include "HYDROData_PolylineXY.h"
22 #include "HYDROData_ShapesGroup.h"
23 #include <HYDROData_Transform.h>
24 #include <BRepAlgoAPI_Cut.hxx>
25 #include <BRepAlgoAPI_Common.hxx>
26 #include <BRepBuilderAPI_MakeFace.hxx>
27 #include <BRep_Builder.hxx>
28 #include <TopExp_Explorer.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <BRepCheck_Analyzer.hxx>
35 #include <TopTools_ListOfShape.hxx>
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37 #include <gp_Pln.hxx>
38 #include <BRepGProp.hxx>
39 #include <GProp_GProps.hxx>
40 #include <Geom_Plane.hxx>
41 #include <BRepBuilderAPI_FindPlane.hxx>
42
43 //#define DEB_SPLIT_TO_ZONES 1
44 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
45 #if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION))
46 #include <BRepTools.hxx>
47 static TCollection_AsciiString fileNameBefore("BeforeTranslation");
48 #endif
49
50 TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
51 {
52   TopoDS_Face aResFace;
53
54   if( !Shape.IsNull() )
55   {
56     if ( Shape.ShapeType() == TopAbs_FACE )
57     {
58       aResFace = TopoDS::Face( Shape );
59     }
60     else if ( Shape.ShapeType() == TopAbs_WIRE )
61     {
62       BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( Shape ), Standard_True );
63       aMakeFace.Build();
64       if( aMakeFace.IsDone() )
65         aResFace = aMakeFace.Face();
66     }
67   }
68
69   return aResFace;
70 }
71
72 Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace) 
73 {
74   GProp_GProps G;
75   BRepGProp::LinearProperties(theBndWire,G);
76   const gp_Pnt& aCPnt = G.CentreOfMass();
77   gp_Pln aPln;
78   BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion());  
79   if(fndPlane.Found())
80     aPln = fndPlane.Plane()->Pln();
81   else
82     aPln = gp_Pln(aCPnt, gp::OZ().Direction());
83   BRepBuilderAPI_MakeFace  aMkFace(aPln, theBndWire);
84   if(aMkFace.IsDone()) {
85     outFace = aMkFace.Face();      
86     if(!outFace.IsNull()) {
87 #ifdef DEB_SPLIT_TO_ZONES
88 //      BRepTools::Write(limFace,"FL.brep");
89 #endif
90       return Standard_True;
91     }
92   }
93   return Standard_False;
94 }
95 //======================================================================================
96
97 void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, const QString& theNameAfter)
98 {
99 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
100   if(!theNameBefore.isNull() && !theNameBefore.isEmpty())
101   {
102     TCollection_AsciiString aName (theNameBefore.toStdString().data());
103     fileNameBefore = aName;
104   }
105   if(!theNameAfter.isNull() && !theNameAfter.isEmpty())
106   {
107     TCollection_AsciiString aName (theNameAfter.toStdString().data());
108     HYDROData_Transform::SetFileName (aName);
109   }
110 #endif
111 }
112 //======================================================================================
113 Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp, 
114                                                         HYDROData_Transform& theTool)
115 {
116   theTool.Clear();
117   theTool.SetArgument(theComp);
118   theTool.Detect();
119   const Standard_Boolean bToTransform = theTool.ToTransform();  
120   theTool.SetToTransform(bToTransform);  
121   theTool.Perform();
122   Standard_Integer anErr = theTool.ErrorStatus();
123   return anErr;
124 }
125
126 //======================================================================================
127 HYDROData_SplitToZonesTool::SplitDataList
128   HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects&  theObjectList,
129                                      const HYDROData_SequenceOfObjects&  theGroupsList,
130                                      const Handle(HYDROData_PolylineXY)& thePolyline )
131 {
132   SplitDataList anOutputSplitDataList;
133   if(theObjectList.IsEmpty()) return anOutputSplitDataList;
134   // Preparation. 
135   // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape.
136   SplitDataList anInputSplitDataList;
137 #ifdef DEB_SPLIT_TO_ZONES
138   TCollection_AsciiString aNam("Faces_");
139 #endif
140   for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ )
141   {
142     Handle(HYDROData_Object) aGeomObj = 
143       Handle(HYDROData_Object)::DownCast( theObjectList.Value( anIndex ) );
144     if( aGeomObj.IsNull() )
145       continue;
146
147     TopoDS_Shape aShape = aGeomObj->GetTopShape();
148     if ( aShape.IsNull() )
149       continue;  
150 #ifdef DEB_SPLIT_TO_ZONES
151    TCollection_AsciiString aName = aNam + anIndex + ".brep";
152    BRepTools::Write(aShape, aName.ToCString());
153 #endif
154     if ( aShape.ShapeType() == TopAbs_COMPOUND ) {
155       // Create split data for each face contained in the compound
156       TopExp_Explorer anExp( aShape, TopAbs_FACE );
157       for ( ; anExp.More(); anExp.Next() ) {
158         const TopoDS_Face& aFace = TopoDS::Face( anExp.Current() );
159         if ( !aFace.IsNull() ) {
160           SplitData aSplitData( SplitData::Data_Zone, aFace, aGeomObj->GetName() );
161           anInputSplitDataList.append( aSplitData );
162         }
163       }
164     } else {
165       SplitData aSplitData( SplitData::Data_Zone, aShape, aGeomObj->GetName() );
166       anInputSplitDataList.append( aSplitData );
167     }
168   }
169   //
170   SplitDataList anInputGroupList;
171   for( int anIndex = 1, aLength = theGroupsList.Length(); anIndex <=aLength; anIndex++ )
172   {
173     Handle(HYDROData_ShapesGroup) aGeomGroup = 
174       Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) );
175     if( aGeomGroup.IsNull() )
176       continue;
177       
178     TopTools_SequenceOfShape aGroupShapes;
179     aGeomGroup->GetShapes( aGroupShapes );
180     for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) {
181       const TopoDS_Shape& aGroupShape = aGroupShapes.Value( i );
182       if ( aGroupShape.IsNull() )
183         continue;  
184
185       if ( aGroupShape.ShapeType() == TopAbs_COMPOUND ) {    
186         TopExp_Explorer anExp( aGroupShape, TopAbs_EDGE );
187         for ( ; anExp.More(); anExp.Next() ) {
188           const TopoDS_Edge& anEdge = TopoDS::Edge( anExp.Current() );
189           if ( !anEdge.IsNull() ) {
190             SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->GetName() );
191             anInputGroupList.append( aSplitData );
192           }
193         }
194       } else {
195         SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() );
196         anInputGroupList.append( aSplitData );
197 #ifdef DEB_SPLIT_TO_ZONES
198         QString aStr = aSplitData.ObjectNames.join(" "); 
199         cout << "Group# = " <<anIndex <<" Nmb in grp = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;   
200 #endif
201       }
202     }
203   }
204   // If only one shape is given we don't split it 
205   // algorithm just returns the unpacked input data
206   bool limplus1Object(false);
207   if(theObjectList.Size() == 1 )  {
208     if(thePolyline.IsNull()) {
209       anOutputSplitDataList.append(anInputSplitDataList); 
210       if(!theGroupsList.IsEmpty() ) 
211         anOutputSplitDataList.append(anInputGroupList);
212       return anOutputSplitDataList;
213     } else
214         limplus1Object = true;// size =1 && hasLimits
215   }
216   HYDROData_DataMapOfShapeListOfString aDM3;
217   if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
218     QStringList aListOfNames;
219     for (int i=0;i < anInputGroupList.size() ;i++) {
220       const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
221       aDM3.Add(aSh, anInputGroupList.at(i).ObjectNames);
222     }
223   }
224
225   // Step 1. Prepare Partition structures. 
226   TopoDS_Shape aResult;
227   BOPCol_ListOfShape aLS;  
228   QStringList aListOfNames;
229   TopoDS_Compound aCmp;
230   BRep_Builder aBB;
231   aBB.MakeCompound(aCmp);
232   for (int i=0;i < anInputSplitDataList.size() ;i++) {
233     const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
234     aDM3.Add(aSh, anInputSplitDataList.at(i).ObjectNames);
235     aLS.Append(aSh);
236     aBB.Add(aCmp,aSh);
237 #ifdef DEB_SPLIT_TO_ZONES
238     //TCollection_AsciiString aName = aNam + i + ".brep";
239     //BRepTools::Write(aSh, aName.ToCString());
240 #endif
241   }
242 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
243   TCollection_AsciiString aNameBefore = fileNameBefore + ".brep";
244   BRepTools::Write(aCmp, aNameBefore.ToCString());
245 #endif
246
247   HYDROData_DataMapOfShapeListOfShape aDM1;
248   if(anInputSplitDataList.size() > 1) {
249     HYDROData_Transform splitTool; 
250     const Standard_Integer anErr = SplitFaces(aCmp, splitTool);    
251     if(anErr)
252       return anOutputSplitDataList;
253     aResult = splitTool.Shape();
254     if (aResult.IsNull()) 
255       return anOutputSplitDataList;
256     BRepCheck_Analyzer aCheck (aResult);
257     if(!aCheck.IsValid()) {
258   #ifdef DEB_SPLIT_TO_ZONES
259       cout << "result is not valid" <<endl;
260       BRepTools::Write(aResult, "SplitFacesNV.brep");  
261   #endif
262       return anOutputSplitDataList;
263     }
264   #ifdef DEB_SPLIT_TO_ZONES
265     BRepTools::Write(aResult, "SplitFacesV.brep");
266   #endif
267     
268     // Step 3. Collect history  
269     //HYDROData_DataMapOfShapeListOfShape aDM1;
270     BOPCol_ListIteratorOfListOfShape anIt(aLS); 
271   #ifdef DEB_SPLIT_TO_ZONES
272     TCollection_AsciiString aNamM ("EdgM_");
273     TCollection_AsciiString aNamG ("EdgG_");
274   #endif
275     for (int i =1;anIt.More();anIt.Next(),i++) {
276       Standard_Boolean foundF(Standard_False);
277       const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
278       if(!aListOfNew.IsEmpty())
279         foundF = Standard_True;
280
281       TopTools_ListOfShape aList;
282
283       TopTools_ListIteratorOfListOfShape it(aListOfNew);
284       for(;it.More();it.Next())       
285         aList.Append(it.Value());
286           /* *********************************************************************
287       // Bug in History: partition should give only modified entities! => temporary solution is used
288       //const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
289       //if(!aListOfGen.IsEmpty())
290         //foundF = Standard_True;
291       //it.Initialize(aListOfGen);    
292       //for(;it.More();it.Next())     
293        // aList.Append(it.Value());  
294            ********************************************************************* */
295       if(!foundF) // face is not modified
296         aList.Append (anIt.Value());
297       aDM1.Add(anIt.Value(), aList);
298   #ifdef DEB_SPLIT_TO_ZONES
299       TCollection_AsciiString aName;
300   #endif
301       if(!anInputGroupList.isEmpty() ) { // 1
302         TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
303         for (int j =1;exp.More();exp.Next(),j++) {
304           aList.Clear();
305           Standard_Boolean foundE(Standard_False);
306           const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());    
307           //cout << "NB_EDGE_M = " << aListM.Extent() <<endl;
308           if(aListM.Extent()) foundE = Standard_True;
309           it.Initialize(aListM);    
310           for(int k=1;it.More();it.Next(),k++) {    
311             aList.Append(it.Value());
312   #ifdef DEB_SPLIT_TO_ZONES
313             //aName = aNamM + i + j +k +".brep";
314             //BRepTools::Write(it.Value(),aName.ToCString());
315   #endif
316           }
317           /* *********************************************************************
318                   //const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
319           //if(aListG.Extent()) foundE = Standard_True;
320           //it.Initialize(aListG);    
321           //for(int k=1;it.More();it.Next(),k++)
322             //aList.Append(it.Value());
323           //cout << "NB_EDGE = " << aList.Extent() <<endl;
324                   ************************************************************************** */
325           if(!foundE) {
326             aList.Append (exp.Current());
327   #ifdef DEB_SPLIT_TO_ZONES
328             aName = aNamG + i + j +".brep";
329             BRepTools::Write(exp.Current(),aName.ToCString());
330             cout << aName.ToCString()<< " = " << exp.Current().TShape() <<endl;
331   #endif
332           }
333           aDM1.Add(exp.Current(), aList);
334         }
335       }
336     }
337   } else {
338       aResult = anInputSplitDataList.at(0).Shape; // get single input shape
339   }
340
341   // aDM2: NewShape ==> ListOfOldShapes
342   HYDROData_DataMapOfShapeListOfShape aDM2;
343   // make limiting face
344   HYDROData_DataMapOfShapeListOfShape aDM4;
345   Standard_Boolean hasLimits(Standard_False);
346   QString aBndName;
347   HYDROData_MapOfShape aBndView;
348   if (! thePolyline.IsNull()) {    
349     const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape());
350     if(!aBndWire.IsNull()) {
351       TopoDS_Face limFace;       
352       if(buildLimFace(aBndWire, limFace)) {
353         TopoDS_Shape aComResult;
354         BRepAlgoAPI_Common mkCom(aResult, limFace);
355         if(mkCom.IsDone()) {
356           aComResult = mkCom.Shape();
357           BRepCheck_Analyzer aCheck (aComResult);
358           if(aCheck.IsValid()) {
359 #ifdef DEB_SPLIT_TO_ZONES
360             BRepTools::Write(aComResult,"CommonV.brep");
361             BRepTools::Write(limFace,"limFace.brep");
362 #endif    
363             aBndName = thePolyline->GetName();
364             hasLimits = Standard_True; // DM2 should be filled here
365             TopExp_Explorer exp (limFace, TopAbs_EDGE);
366             for (int i =1;exp.More();exp.Next(),i++) {
367               const TopoDS_Shape& anEdge = exp.Current();
368               if(anEdge.IsNull()) continue;
369               aBndView.Add(anEdge);
370               QStringList aListOfNames;
371               aListOfNames.append(aBndName);
372               aDM3.Add(anEdge, aListOfNames);
373               TopTools_ListOfShape aList;
374               aList.Append(anEdge);
375               aDM1.Add(anEdge,aList);
376             }
377             HYDROData_MapOfShape aView;
378             exp.Init (aResult, TopAbs_FACE);
379             for (int i =1;exp.More();exp.Next(),i++) {
380               const TopoDS_Shape& aFace = exp.Current();
381               if(!aFace.IsNull()) {
382                 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
383                 //cout << "Modified: " << aListOfNew.Extent() <<endl;                                    
384                 if(!aListOfNew.IsEmpty()) {
385                   aDM4.Add(aFace, aListOfNew);
386 #ifdef DEB_SPLIT_TO_ZONES
387                   //TCollection_AsciiString aName = aNam + i + ".brep";
388                   //BRepTools::Write(aListOfNew.Last(), aName.ToCString());                
389 #endif
390                 }
391                 else {
392                     if(!mkCom.IsDeleted(aFace)) {
393                       const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);    
394                       if(!aListOfGen.IsEmpty()) {
395                         /* aDM4.Bind(aFace, aListOfGen); ???   */
396 #ifdef DEB_SPLIT_TO_ZONES
397                         //TCollection_AsciiString aName = aNam + i + "g.brep";
398                         //BRepTools::Write(aListOfGen.Last(), aName.ToCString());
399 #endif
400                       }
401                        else {
402                         TopTools_ListOfShape aList; 
403                         aList.Append(aFace);
404                         aDM4.Add(aFace, aList); //the same face - not modified
405                        }
406                     }
407              }
408              TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
409              for (int j =1;exp2.More();exp2.Next(),j++) {
410                const TopoDS_Shape& anEdge = exp2.Current();
411                if(!anEdge.IsNull()) {
412                  if(aView.Contains(anEdge)) continue;
413                  aView.Add(anEdge);
414                  const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);                 
415                  if(!aListOfNewEd.IsEmpty())
416                    aDM4.Add(anEdge, aListOfNewEd);
417                  else {
418                    if(!mkCom.IsDeleted(anEdge)) {
419                      const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
420                      if(!aListOfGenEd.IsEmpty()) {
421                        /* aDM4.Bind(anEdge, aListOfGenEd); ???*/
422                      } else {
423                        TopTools_ListOfShape aList; 
424                        aList.Append(anEdge);
425                        aDM4.Add(anEdge, aList);//the same edge - not modified
426                      }
427                    }
428                  }
429                }
430              }
431             }
432             } //end DM4 filling (phase 1)
433             //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
434          // phase 2 (from tool)
435 #ifdef DEB_SPLIT_TO_ZONES
436          TCollection_AsciiString aNam("BndEd_");
437 #endif
438          TopExp_Explorer expt (limFace, TopAbs_EDGE);
439          for(int i =1;expt.More();expt.Next(),i++) {
440            const TopoDS_Shape& anEdge = expt.Current();
441            if(!anEdge.IsNull()) {
442              const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);    
443 #ifdef DEB_SPLIT_TO_ZONES
444              TopTools_ListIteratorOfListOfShape itl(aListOfNewEd);
445              for(int j=1;itl.More();itl.Next(),j++) {
446                TCollection_AsciiString aName = aNam + i + "_" + j + ".brep";
447                BRepTools::Write(itl.Value(), aName.ToCString());
448                cout <<aName.ToCString()<<" = "<< itl.Value().TShape() <<endl;
449              }
450 #endif
451              if(!aListOfNewEd.IsEmpty())
452                aDM4.Add(anEdge, aListOfNewEd);
453              else {
454                if(!mkCom.IsDeleted(anEdge)) {
455                  const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
456                  if(!aListOfGenEd.IsEmpty()) {
457                    /* aDM4.Bind(anEdge, aListOfGenEd); ??? */
458                  } else {
459                    TopTools_ListOfShape aList; 
460                    aList.Append(anEdge);
461                    aDM4.Add(anEdge, aList);//the same edge - not modified
462                  }
463                }
464              }
465            }
466          }
467          //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
468          if(limplus1Object) {
469            // fill DM1 (old - new) and DM2 (new - old)
470            HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape mIt(aDM4);
471            for(;mIt.More();mIt.Next()) {
472              const TopoDS_Shape& aKey = mIt.Key();//old
473              TopTools_ListOfShape aList;
474              aList.Append(aKey);
475              const TopTools_ListOfShape& aListOfNew = mIt.Value();
476              aDM1.Add(aKey, aListOfNew);
477              TopTools_ListIteratorOfListOfShape it(aListOfNew);
478              for(;it.More();it.Next()) {
479                if(!aDM2.Contains(it.Value()))
480                  aDM2.Add(it.Value(), aList);
481                else {
482                  TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
483                  aList.Prepend(aKey);
484                }
485              }
486            }
487          } else {
488            HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1); 
489            //DM4 contains Old - New after common op. DM1: old - new after Split op.
490            for(;aMIt.More();aMIt.Next()) {
491              const TopoDS_Shape& aKey = aMIt.Key();
492              TopTools_ListOfShape aList;
493              aList.Append(aKey);
494              const TopTools_ListOfShape& aListOfNew = aMIt.Value();
495              TopTools_ListIteratorOfListOfShape it(aListOfNew);
496              for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
497                if(!aDM4.Contains(it.Value())) // bi - is deleted
498                  continue; // go to the next bi
499                else {
500                  const TopTools_ListOfShape& aListOfNew4 = aDM4.FindFromKey(it.Value());
501                   TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
502                   for(;it4.More();it4.Next()) {
503                     if(!aDM2.Contains(it4.Value()))
504                       aDM2.Add(it4.Value(), aList);
505                     else {
506                       TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it4.Value());
507                       aList.Prepend(aKey);
508                     }
509                   }
510                }
511              }
512            }
513          }
514          } else {
515              hasLimits = Standard_False;
516 #ifdef DEB_SPLIT_TO_ZONES
517              BRepTools::Write(aComResult,"CommonNV.brep");
518 #endif    
519           }
520        }
521       }
522     }
523   }// end limits processing
524   if(!hasLimits) {
525     HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
526     for(;aMIt.More();aMIt.Next()) {
527       const TopoDS_Shape& aKey = aMIt.Key();
528       TopTools_ListOfShape aList;
529       aList.Append(aKey);
530       const TopTools_ListOfShape& aListOfNew = aMIt.Value();
531       TopTools_ListIteratorOfListOfShape it(aListOfNew);
532       for(;it.More();it.Next()) {
533         if(!aDM2.Contains(it.Value()))
534           aDM2.Add(it.Value(), aList);
535         else {
536           TopTools_ListOfShape& aList = aDM2.ChangeFromKey(it.Value());
537           aList.Prepend(aKey);
538         }
539       }
540     }
541   }
542   // Step 4. Fill output structure.
543 #ifdef DEB_SPLIT_TO_ZONES
544   TCollection_AsciiString aNam4 ("SC_");
545 #endif  
546   HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
547   for(int i =1;aMIt.More();aMIt.Next(),i++) {
548     SplitData aDestSplitData;
549     const TopoDS_Shape& aKey = aMIt.Key(); //new
550     aDestSplitData.Shape = aKey;
551     if(aKey.ShapeType() == TopAbs_FACE)
552       aDestSplitData.Type = SplitData::Data_Zone;
553     else {
554       aDestSplitData.Type = SplitData::Data_Edge;
555 #ifdef DEB_SPLIT_TO_ZONES
556       TCollection_AsciiString aName = aNam4 + i + ".brep";
557       BRepTools::Write(aKey,aName.ToCString());
558 #endif    
559     }
560
561     QStringList aListOfNames; // names processing
562     const TopTools_ListOfShape& aListOfOld = aMIt.Value();
563     TopTools_ListIteratorOfListOfShape it(aListOfOld);
564     for(int j =1;it.More();it.Next(),j++) {    
565       const TopoDS_Shape& aSh = it.Value(); //old
566       if(aDM3.Contains(aSh)) {
567         const QStringList& ObjectNames = aDM3.FindFromKey(aSh);    
568         aListOfNames.append(ObjectNames);
569 #ifdef DEB_SPLIT_TO_ZONES
570         TCollection_AsciiString aName = aNam4 + i +"_" + j + ".brep";
571         BRepTools::Write(aSh ,aName.ToCString());        
572 #endif    
573       }    else {
574 #ifdef DEB_SPLIT_TO_ZONES
575         TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + ".brep";
576         BRepTools::Write(aSh ,aName.ToCString());        
577         cout <<aName.ToCString()<<" = "<< aSh.TShape() <<endl;
578 #endif
579           if(aBndView.Contains(aSh) && hasLimits) {            
580             aListOfNames.append(aBndName);
581 #ifdef DEB_SPLIT_TO_ZONES
582             cout << " BndName = "<<aBndName.toStdString() <<endl; 
583 #endif
584           }
585       }
586     }
587
588     aDestSplitData.ObjectNames = aListOfNames;  
589     anOutputSplitDataList.append(aDestSplitData);    
590 #ifdef DEB_SPLIT_TO_ZONES
591     QString aStr = aDestSplitData.ObjectNames.join(" "); 
592     cout << "New# = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aDestSplitData.ObjectNames.size() <<endl; 
593 #endif
594   }
595
596   return anOutputSplitDataList;
597 }
598