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