Salome HOME
Porting on OCCT 7.0 and Qt 5. Make compilable version.
[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 #define _DEVDEBUG_
51 #include "HYDRO_trace.hxx"
52
53 TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
54 {
55   TopoDS_Face aResFace;
56
57   if( !Shape.IsNull() )
58   {
59     if ( Shape.ShapeType() == TopAbs_FACE )
60     {
61       aResFace = TopoDS::Face( Shape );
62     }
63     else if ( Shape.ShapeType() == TopAbs_WIRE )
64     {
65       BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( Shape ), Standard_True );
66       aMakeFace.Build();
67       if( aMakeFace.IsDone() )
68         aResFace = aMakeFace.Face();
69     }
70   }
71
72   return aResFace;
73 }
74
75 Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace) 
76 {
77   GProp_GProps G;
78   BRepGProp::LinearProperties(theBndWire,G);
79   const gp_Pnt& aCPnt = G.CentreOfMass();
80   gp_Pln aPln;
81   BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion());  
82   if(fndPlane.Found())
83     aPln = fndPlane.Plane()->Pln();
84   else
85     aPln = gp_Pln(aCPnt, gp::OZ().Direction());
86   BRepBuilderAPI_MakeFace  aMkFace(aPln, theBndWire);
87   if(aMkFace.IsDone()) {
88     outFace = aMkFace.Face();      
89     if(!outFace.IsNull()) {
90 #ifdef DEB_SPLIT_TO_ZONES
91 //      BRepTools::Write(limFace,"FL.brep");
92 #endif
93       return Standard_True;
94     }
95   }
96   return Standard_False;
97 }
98 //======================================================================================
99
100 void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, const QString& theNameAfter)
101 {
102 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
103   if(!theNameBefore.isNull() && !theNameBefore.isEmpty())
104   {
105     TCollection_AsciiString aName (theNameBefore.toStdString().data());
106     fileNameBefore = aName;
107   }
108   if(!theNameAfter.isNull() && !theNameAfter.isEmpty())
109   {
110     TCollection_AsciiString aName (theNameAfter.toStdString().data());
111     HYDROData_Transform::SetFileName (aName);
112   }
113 #endif
114 }
115 //======================================================================================
116 Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp, 
117                                                         HYDROData_Transform& theTool)
118 {
119   theTool.Clear();
120   theTool.SetArgument(theComp);
121   theTool.Detect();
122   const Standard_Boolean bToTransform = theTool.ToTransform();  
123   theTool.SetToTransform(bToTransform);  
124   theTool.Perform();
125   Standard_Integer anErr = theTool.ErrorStatus();
126   return anErr;
127 }
128
129 //======================================================================================
130 HYDROData_SplitToZonesTool::SplitDataList
131   HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects&  theObjectList,
132                                      const HYDROData_SequenceOfObjects&  theGroupsList,
133                                      const Handle(HYDROData_PolylineXY)& thePolyline )
134 {
135   DEBTRACE("Split");
136   SplitDataList anOutputSplitDataList;
137   if(theObjectList.IsEmpty()) return anOutputSplitDataList;
138   // Preparation. 
139   // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape.
140   SplitDataList anInputSplitDataList;
141 #ifdef DEB_SPLIT_TO_ZONES
142   TCollection_AsciiString aNam("Faces_");
143 #endif
144   for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ )
145   {
146     Handle(HYDROData_Entity) anObj = theObjectList.Value( anIndex );
147     TopoDS_Shape aShape;
148
149     Handle(HYDROData_Object) aGeomObj = Handle(HYDROData_Object)::DownCast( anObj );
150     if( !aGeomObj.IsNull() ) {
151       aShape = aGeomObj->GetTopShape();
152     }
153
154     if ( aShape.IsNull() )
155       continue;  
156 #ifdef DEB_SPLIT_TO_ZONES
157    TCollection_AsciiString aName = aNam + anIndex + "_a.brep";
158    BRepTools::Write(aShape, aName.ToCString());
159 #endif
160     if ( aShape.ShapeType() == TopAbs_COMPOUND ) {
161       // Create split data for each face contained in the compound
162       TopExp_Explorer anExp( aShape, TopAbs_FACE );
163       for ( ; anExp.More(); anExp.Next() ) {
164         const TopoDS_Face& aFace = TopoDS::Face( anExp.Current() );
165         if ( !aFace.IsNull() ) {
166           SplitData aSplitData( SplitData::Data_Zone, aFace, anObj->GetName() );
167           anInputSplitDataList.append( aSplitData );
168         }
169       }
170     } else {
171       SplitData aSplitData( SplitData::Data_Zone, aShape, anObj->GetName() );
172       anInputSplitDataList.append( aSplitData );
173     }
174   }
175   //
176   SplitDataList anInputGroupList;
177   for( int anIndex = 1, aLength = theGroupsList.Length(); anIndex <=aLength; anIndex++ )
178   {
179     Handle(HYDROData_ShapesGroup) aGeomGroup = 
180       Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) );
181     if( aGeomGroup.IsNull() )
182       continue;
183       
184     TopTools_SequenceOfShape aGroupShapes;
185     aGeomGroup->GetShapes( aGroupShapes );
186     for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) {
187       const TopoDS_Shape& aGroupShape = aGroupShapes.Value( i );
188       if ( aGroupShape.IsNull() )
189         continue;  
190
191       if ( aGroupShape.ShapeType() == TopAbs_COMPOUND ) {    
192         TopExp_Explorer anExp( aGroupShape, TopAbs_EDGE );
193         for ( ; anExp.More(); anExp.Next() ) {
194           const TopoDS_Edge& anEdge = TopoDS::Edge( anExp.Current() );
195           if ( !anEdge.IsNull() ) {
196             SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->GetName() );
197             anInputGroupList.append( aSplitData );
198           }
199         }
200       } else {
201         SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() );
202         anInputGroupList.append( aSplitData );
203 #ifdef DEB_SPLIT_TO_ZONES
204         QString aStr = aSplitData.ObjectNames.join(" "); 
205         DEBTRACE("Group# = " <<anIndex <<" Nmb in grp = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size());
206 #endif
207       }
208     }
209   }
210   // If only one shape is given we don't split it 
211   // algorithm just returns the unpacked input data
212   bool limplus1Object(false);
213   if(theObjectList.Size() == 1 )  {
214     if(thePolyline.IsNull()) {
215       anOutputSplitDataList.append(anInputSplitDataList); 
216       if(!theGroupsList.IsEmpty() ) 
217         anOutputSplitDataList.append(anInputGroupList);
218       return anOutputSplitDataList;
219     } else
220         limplus1Object = true;// size =1 && hasLimits
221   }
222   HYDROData_DataMapOfShapeListOfString aDM3;
223   if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
224     QStringList aListOfNames;
225     for (int i=0;i < anInputGroupList.size() ;i++) {
226       const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
227       aDM3.Add(aSh, anInputGroupList.at(i).ObjectNames);
228     }
229   }
230
231   // Step 1. Prepare Partition structures. 
232   TopoDS_Shape aResult;
233   BOPCol_ListOfShape aLS;  
234   QStringList aListOfNames;
235   TopoDS_Compound aCmp;
236   BRep_Builder aBB;
237   aBB.MakeCompound(aCmp);
238   for (int i=0;i < anInputSplitDataList.size() ;i++) {
239     const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
240     aDM3.Add(aSh, anInputSplitDataList.at(i).ObjectNames);
241     aLS.Append(aSh);
242     aBB.Add(aCmp,aSh);
243 #ifdef DEB_SPLIT_TO_ZONES
244     TCollection_AsciiString aName = aNam + i + "_b.brep";
245     BRepTools::Write(aSh, aName.ToCString());
246 #endif
247   }
248 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
249   TCollection_AsciiString aNameBefore = fileNameBefore + "_c.brep";
250   BRepTools::Write(aCmp, aNameBefore.ToCString());
251 #endif
252
253   HYDROData_DataMapOfShapeListOfShape aDM1;
254   if(anInputSplitDataList.size() > 1) {
255     HYDROData_Transform splitTool; 
256     const Standard_Integer anErr = SplitFaces(aCmp, splitTool);    
257     if(anErr)
258       return anOutputSplitDataList;
259     aResult = splitTool.Shape();
260     if (aResult.IsNull()) 
261       return anOutputSplitDataList;
262     BRepCheck_Analyzer aCheck (aResult);
263     if(!aCheck.IsValid()) {
264   #ifdef DEB_SPLIT_TO_ZONES
265       DEBTRACE("result is not valid");
266       BRepTools::Write(aResult, "SplitFacesNV.brep");  
267   #endif
268       return anOutputSplitDataList;
269     }
270   #ifdef DEB_SPLIT_TO_ZONES
271     BRepTools::Write(aResult, "SplitFacesV.brep");
272   #endif
273     
274     // Step 3. Collect history  
275     //HYDROData_DataMapOfShapeListOfShape aDM1;
276     BOPCol_ListIteratorOfListOfShape anIt(aLS); 
277   #ifdef DEB_SPLIT_TO_ZONES
278     TCollection_AsciiString aNamM ("EdgM_");
279     TCollection_AsciiString aNamG ("EdgG_");
280   #endif
281     for (int i =1;anIt.More();anIt.Next(),i++) {
282       Standard_Boolean foundF(Standard_False);
283       const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
284       if(!aListOfNew.IsEmpty())
285         foundF = Standard_True;
286
287       TopTools_ListOfShape aList;
288
289       TopTools_ListIteratorOfListOfShape it(aListOfNew);
290       for(;it.More();it.Next())       
291         aList.Append(it.Value());
292           /* *********************************************************************
293       // Bug in History: partition should give only modified entities! => temporary solution is used
294       //const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
295       //if(!aListOfGen.IsEmpty())
296         //foundF = Standard_True;
297       //it.Initialize(aListOfGen);    
298       //for(;it.More();it.Next())     
299        // aList.Append(it.Value());  
300            ********************************************************************* */
301       if(!foundF) // face is not modified
302         aList.Append (anIt.Value());
303       aDM1.Add(anIt.Value(), aList);
304   #ifdef DEB_SPLIT_TO_ZONES
305       TCollection_AsciiString aName;
306   #endif
307       if(!anInputGroupList.isEmpty() ) { // 1
308         TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
309         for (int j =1;exp.More();exp.Next(),j++) {
310           aList.Clear();
311           Standard_Boolean foundE(Standard_False);
312           const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());    
313           DEBTRACE("NB_EDGE_M = " << aListM.Extent());
314           if(aListM.Extent()) foundE = Standard_True;
315           it.Initialize(aListM);    
316           for(int k=1;it.More();it.Next(),k++) {    
317             aList.Append(it.Value());
318   #ifdef DEB_SPLIT_TO_ZONES
319             aName = aNamM + i + j +k +"_d.brep";
320             BRepTools::Write(it.Value(),aName.ToCString());
321   #endif
322           }
323           /* *********************************************************************
324                   //const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
325           //if(aListG.Extent()) foundE = Standard_True;
326           //it.Initialize(aListG);    
327           //for(int k=1;it.More();it.Next(),k++)
328             //aList.Append(it.Value());
329           //cout << "NB_EDGE = " << aList.Extent() <<endl;
330                   ************************************************************************** */
331           if(!foundE) {
332             aList.Append (exp.Current());
333   #ifdef DEB_SPLIT_TO_ZONES
334             aName = aNamG + i + j +"_e.brep";
335             BRepTools::Write(exp.Current(),aName.ToCString());
336             DEBTRACE(aName.ToCString()<< " = " << exp.Current().TShape());
337   #endif
338           }
339           aDM1.Add(exp.Current(), aList);
340         }
341       }
342     }
343   } else {
344       aResult = anInputSplitDataList.at(0).Shape; // get single input shape
345   }
346
347   // aDM2: NewShape ==> ListOfOldShapes
348   HYDROData_DataMapOfShapeListOfShape aDM2;
349   // make limiting face
350   HYDROData_DataMapOfShapeListOfShape aDM4;
351   Standard_Boolean hasLimits(Standard_False);
352   QString aBndName;
353   HYDROData_MapOfShape aBndView;
354   if (! thePolyline.IsNull()) {
355     Handle(TopTools_HSequenceOfShape) aConnectedWires = new TopTools_HSequenceOfShape;
356     int nbWires = thePolyline->GetNbConnectedWires(aConnectedWires);
357     const TopoDS_Wire aBndWire = TopoDS::Wire(aConnectedWires->Value(1));
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                 DEBTRACE("Modified: " << aListOfNew.Extent());
392                 if(!aListOfNew.IsEmpty()) {
393                   aDM4.Add(aFace, aListOfNew);
394 #ifdef DEB_SPLIT_TO_ZONES
395                   TCollection_AsciiString aName = aNam + i + "_f.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 + "_j.brep";
455                BRepTools::Write(itl.Value(), aName.ToCString());
456                DEBTRACE(aName.ToCString()<<" = "<< itl.Value().TShape());
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 + "_k.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 + "_l.brep";
579         BRepTools::Write(aSh ,aName.ToCString());        
580 #endif    
581       }    else {
582 #ifdef DEB_SPLIT_TO_ZONES
583         TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + "_m.brep";
584         BRepTools::Write(aSh ,aName.ToCString());        
585         DEBTRACE(aName.ToCString()<<" = "<< aSh.TShape());
586 #endif
587           if(aBndView.Contains(aSh) && hasLimits) {            
588             aListOfNames.append(aBndName);
589 #ifdef DEB_SPLIT_TO_ZONES
590             DEBTRACE(" BndName = "<<aBndName.toStdString());
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     DEBTRACE("New# = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aDestSplitData.ObjectNames.size());
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 }