Salome HOME
NCollection sequences improved.
[modules/hydro.git] / src / HYDROData / HYDROData_SplitToZonesTool.cxx
index 1ae7a1b2e641b3f0b031343c84eabed0e326e02b..3661c514a1f63cb30bdeba18d061910d1170b2ed 100644 (file)
@@ -3,35 +3,33 @@
 
 #include "HYDROData_PolylineXY.h"
 #include "HYDROData_ShapesGroup.h"
-
-#include <BRepAlgoAPI_Common.hxx>
+#include <HYDROData_Transform.h>
 #include <BRepAlgoAPI_Cut.hxx>
+#include <BRepAlgoAPI_Common.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
-
+#include <BRep_Builder.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Iterator.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Compound.hxx>
 #include <TopoDS_Wire.hxx>
-#include <TopoDS_Iterator.hxx>
+#include <TopoDS_Edge.hxx>
 #include <BRepCheck_Analyzer.hxx>
-#include <NCollection_IncAllocator.hxx>
-#include <BOPAlgo_Builder.hxx>
-#include <BOPAlgo_PaveFiller.hxx>
-#include <NCollection_DataMap.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
-#include <TopTools_ShapeMapHasher.hxx>
-typedef NCollection_DataMap<TopoDS_Shape, TopTools_ListOfShape, TopTools_ShapeMapHasher> HYDROData_DataMapOfShapeListOfShape;
-typedef HYDROData_DataMapOfShapeListOfShape::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape;
-typedef NCollection_DataMap<TopoDS_Shape,  QStringList, TopTools_ShapeMapHasher> HYDROData_DataMapOfShapeListOfString;
-typedef HYDROData_DataMapOfShapeListOfString::Iterator HYDROData_DataMapIteratorOfDataMapOfShapeListOfString;
-#undef _NCollection_MapHasher
-
-#define DEB_SPLIT_TO_ZONES 1
-#ifdef DEB_SPLIT_TO_ZONES       
+#include <gp_Pln.hxx>
+#include <BRepGProp.hxx>
+#include <GProp_GProps.hxx>
+#include <Geom_Plane.hxx>
+#include <BRepBuilderAPI_FindPlane.hxx>
+
+//#define DEB_SPLIT_TO_ZONES 1
+//#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
+#if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION))
 #include <BRepTools.hxx>
+static TCollection_AsciiString fileNameBefore("BeforeTranslation");
 #endif
+
 TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
 {
   TopoDS_Face aResFace;
@@ -54,16 +52,72 @@ TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
   return aResFace;
 }
 
+Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace) 
+{
+  GProp_GProps G;
+  BRepGProp::LinearProperties(theBndWire,G);
+  const gp_Pnt& aCPnt = G.CentreOfMass();
+  gp_Pln aPln;
+  BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion());  
+  if(fndPlane.Found())
+    aPln = fndPlane.Plane()->Pln();
+  else
+    aPln = gp_Pln(aCPnt, gp::OZ().Direction());
+  BRepBuilderAPI_MakeFace  aMkFace(aPln, theBndWire);
+  if(aMkFace.IsDone()) {
+    outFace = aMkFace.Face();    
+    if(!outFace.IsNull()) {
+#ifdef DEB_SPLIT_TO_ZONES
+//       BRepTools::Write(limFace,"FL.brep");
+#endif
+      return Standard_True;
+       }
+  }
+  return Standard_False;
+}
+//======================================================================================
+
+void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, const QString& theNameAfter)
+{
+#ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
+  if(!theNameBefore.isNull() && !theNameBefore.isEmpty())
+  {
+    TCollection_AsciiString aName (theNameBefore.toStdString().data());
+       fileNameBefore = aName;
+  }
+  if(!theNameAfter.isNull() && !theNameAfter.isEmpty())
+  {
+    TCollection_AsciiString aName (theNameAfter.toStdString().data());
+    HYDROData_Transform::SetFileName (aName);
+  }
+#endif
+}
+//======================================================================================
+Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp, 
+                                                                                                               HYDROData_Transform& theTool)
+{
+  theTool.Clear();
+  theTool.SetArgument(theComp);
+  theTool.Detect();
+  const Standard_Boolean bToTransform = theTool.ToTransform();  
+  theTool.SetToTransform(bToTransform);  
+  theTool.Perform();
+  Standard_Integer anErr = theTool.ErrorStatus();
+  return anErr;
+}
+
+//======================================================================================
 HYDROData_SplitToZonesTool::SplitDataList
   HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects&  theObjectList,
                                      const HYDROData_SequenceOfObjects&  theGroupsList,
                                      const Handle(HYDROData_PolylineXY)& thePolyline )
 {
   SplitDataList anOutputSplitDataList;
-
+  if(theObjectList.IsEmpty()) return anOutputSplitDataList;
   // Preparation. 
   // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape.
   SplitDataList anInputSplitDataList;
+  TCollection_AsciiString aNam("Faces_");
   for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ )
   {
     Handle(HYDROData_Object) aGeomObj = 
@@ -74,6 +128,8 @@ HYDROData_SplitToZonesTool::SplitDataList
     TopoDS_Shape aShape = aGeomObj->GetTopShape();
     if ( aShape.IsNull() )
       continue;  
+   //TCollection_AsciiString aName = aNam + anIndex + ".brep";
+   //BRepTools::Write(aShape, aName.ToCString());
 
     if ( aShape.ShapeType() == TopAbs_COMPOUND ) {
       // Create split data for each face contained in the compound
@@ -98,7 +154,7 @@ HYDROData_SplitToZonesTool::SplitDataList
       Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) );
     if( aGeomGroup.IsNull() )
       continue;
-         
+      
     TopTools_SequenceOfShape aGroupShapes;
     aGeomGroup->GetShapes( aGroupShapes );
     for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) {
@@ -114,107 +170,125 @@ HYDROData_SplitToZonesTool::SplitDataList
             SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->GetName() );
             anInputGroupList.append( aSplitData );
           }
-             }
+          }
       } else {
         SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() );
         anInputGroupList.append( aSplitData );
       }
     }
   }
-
+  // If only one shape is given we don't split it 
+  // algorithm just returns the unpacked input data
+  if(theObjectList.Size() == 1)  {
+       anOutputSplitDataList.append(anInputSplitDataList); 
+       if(!theGroupsList.IsEmpty() ) 
+         anOutputSplitDataList.append(anInputGroupList);       
+    return anOutputSplitDataList;
+  }
   HYDROData_DataMapOfShapeListOfString aDM3;
-  if(!anInputGroupList.isEmpty()) {    // Old edge ==> List_Of_Names
+  if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
     QStringList aListOfNames;
     for (int i=0;i < anInputGroupList.size() ;i++) {
-      const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;  
-      aDM3.Bind(aSh, anInputGroupList.at(i).ObjectNames);        
-       }
+      const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
+      aDM3.Bind(aSh, anInputGroupList.at(i).ObjectNames);
+    }
   }
-  // Step 1. Prepare Partition structures.
-  Handle(NCollection_BaseAllocator) pA1 = new NCollection_IncAllocator, pA2 = new NCollection_IncAllocator;
-  BOPAlgo_PaveFiller* aPaveFiller      = new BOPAlgo_PaveFiller(pA1);
-  BOPAlgo_Builder* aBuilder            = new BOPAlgo_Builder(pA2);
+  // Step 1. Prepare Partition structures. 
   BOPCol_ListOfShape aLS;  
   QStringList aListOfNames;
+  TopoDS_Compound aCmp;
+  BRep_Builder aBB;
+  aBB.MakeCompound(aCmp);
   for (int i=0;i < anInputSplitDataList.size() ;i++) {
-       const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;     
-       aDM3.Bind(aSh, anInputSplitDataList.at(i).ObjectNames);
-    aLS.Append(aSh);    
+    const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
+    aDM3.Bind(aSh, anInputSplitDataList.at(i).ObjectNames);
+    aLS.Append(aSh);
+       aBB.Add(aCmp,aSh);
+    //TCollection_AsciiString aName = aNam + i + ".brep";
+    //BRepTools::Write(aSh, aName.ToCString());
   }
-  aPaveFiller->SetArguments(aLS);
-  aPaveFiller->Perform();
-  Standard_Integer anErr = aPaveFiller->ErrorStatus();
-  if(anErr) 
-    return anOutputSplitDataList;
-  BOPDS_PDS pDS = aPaveFiller->PDS();
-  if (!pDS) 
-    return anOutputSplitDataList;
-  aBuilder->Clear();
+#ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
+  TCollection_AsciiString aNameBefore = fileNameBefore + ".brep";
+  BRepTools::Write(aCmp, aNameBefore.ToCString());
+#endif
 
-  // Step 2. Split faces 
-  BOPCol_ListIteratorOfListOfShape anIt(aPaveFiller->Arguments());
-  for (; anIt.More(); anIt.Next()) {
-    const TopoDS_Shape& aS = anIt.Value();
-    aBuilder->AddArgument(aS);
-  }
-  aBuilder->PerformWithFiller(*aPaveFiller);
-  anErr = aBuilder->ErrorStatus();
-  if(anErr) 
+  HYDROData_Transform splitTool; 
+  const Standard_Integer anErr = SplitFaces(aCmp, splitTool);    
+  if(anErr)
     return anOutputSplitDataList;
-  const TopoDS_Shape& aResult = aBuilder->Shape();
+  const TopoDS_Shape& aResult = splitTool.Shape();
   if (aResult.IsNull()) 
     return anOutputSplitDataList;
   BRepCheck_Analyzer aCheck (aResult);
   if(!aCheck.IsValid()) {
-#ifdef DEB_SPLIT_TO_ZONES      
-    cout << "result is not valid" <<endl;       
+#ifdef DEB_SPLIT_TO_ZONES
+    cout << "result is not valid" <<endl;
     BRepTools::Write(aResult, "SplitFacesNV.brep");  
 #endif
     return anOutputSplitDataList;
   }
-#ifdef DEB_SPLIT_TO_ZONES      
-  //BRepTools::Write(aResult, "SplitFacesV.brep");
+#ifdef DEB_SPLIT_TO_ZONES
+  BRepTools::Write(aResult, "SplitFacesV.brep");
 #endif
   
   // Step 3. Collect history  
   HYDROData_DataMapOfShapeListOfShape aDM1;
-  anIt.Init(aLS); 
-  //TCollection_AsciiString aNamM ("EdgM_");
-  //TCollection_AsciiString aNamG ("EdgG_");
+  BOPCol_ListIteratorOfListOfShape anIt(aLS); 
+  TCollection_AsciiString aNamM ("EdgM_");
+  TCollection_AsciiString aNamG ("EdgG_");
   for (int i =1;anIt.More();anIt.Next(),i++) {
-       const TopTools_ListOfShape& aListOfNew = aBuilder->Modified(anIt.Value());      
+       Standard_Boolean foundF(Standard_False);
+    const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
+       if(!aListOfNew.IsEmpty())
+         foundF = Standard_True;
     TopTools_ListOfShape aList;
-       TopTools_ListIteratorOfListOfShape it(aListOfNew);
-       for(;it.More();it.Next())       
-         aList.Append(it.Value());
-       // Bug in History: partition should give only modified entities! => temporary solution is used
-    const TopTools_ListOfShape& aListOfGen = aBuilder->Generated(anIt.Value());
+    TopTools_ListIteratorOfListOfShape it(aListOfNew);
+    for(;it.More();it.Next())       
+      aList.Append(it.Value());
+    // Bug in History: partition should give only modified entities! => temporary solution is used
+    const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
+       if(!aListOfGen.IsEmpty())
+         foundF = Standard_True;
        it.Initialize(aListOfGen);    
        for(;it.More();it.Next())     
          aList.Append(it.Value());
-
+    if(!foundF) // face is not modified
+         aList.Append (anIt.Value());
        aDM1.Bind(anIt.Value(), aList);
-       //TCollection_AsciiString aName;
-       if(!anInputGroupList.isEmpty()) { /* 1 */
+#ifdef DEB_SPLIT_TO_ZONES
+       TCollection_AsciiString aName;
+#endif
+       if(!anInputGroupList.isEmpty() ) { // 1
       aList.Clear();
          TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
          for (int j =1;exp.More();exp.Next(),j++) {
-           const TopTools_ListOfShape& aListM = aBuilder->Modified(exp.Current());     
+           Standard_Boolean foundE(Standard_False);
+           const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());     
                //cout << "NB_EDGE_M = " << aListM.Extent() <<endl;
+               if(aListM.Extent()) foundE = Standard_True;
                it.Initialize(aListM);    
                for(int k=1;it.More();it.Next(),k++) {    
              aList.Append(it.Value());
                  //aName = aNamM + i + j +k +".brep";
                  //BRepTools::Write(it.Value(),aName.ToCString());
                }
-               const TopTools_ListOfShape& aListG = aBuilder->Generated(exp.Current());
+               const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
+               if(aListG.Extent()) foundE = Standard_True;
                it.Initialize(aListG);    
                for(int k=1;it.More();it.Next(),k++)   {  
              aList.Append(it.Value());
                  //aName = aNamG + i + j +k +".brep";
-                //BRepTools::Write(it.Value(),aName.ToCString());
+                 //BRepTools::Write(it.Value(),aName.ToCString());
                }
                //cout << "NB_EDGE = " << aList.Extent() <<endl;
+               if(!foundE) {
+                 aList.Append (exp.Current());
+#ifdef DEB_SPLIT_TO_ZONES
+                 aName = aNamG + i + j +".brep";
+                 //BRepTools::Write(exp.Current(),aName.ToCString());
+                 cout << aName.ToCString()<< " = " << exp.Current().TShape() <<endl;
+#endif
+               }
                aDM1.Bind(exp.Current(), aList);
          }      
        }
@@ -222,35 +296,175 @@ HYDROData_SplitToZonesTool::SplitDataList
 
   // aDM2: NewShape ==> ListOfOldShapes
   HYDROData_DataMapOfShapeListOfShape aDM2;
-  HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
-  for(;aMIt.More();aMIt.Next()) {
-       const TopoDS_Shape& aKey = aMIt.Key();
-       TopTools_ListOfShape aList;
-       aList.Append(aKey);
-       const TopTools_ListOfShape& aListOfNew = aMIt.Value();
-       TopTools_ListIteratorOfListOfShape it(aListOfNew);
-       for(;it.More();it.Next()) {
-         if(!aDM2.IsBound(it.Value()))
-           aDM2.Bind(it.Value(), aList);
-         else {
-               TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
-               aList.Prepend(aKey);
+  // make limiting face
+  HYDROData_DataMapOfShapeListOfShape aDM4;
+  Standard_Boolean hasLimits(Standard_False);
+  if (! thePolyline.IsNull()) {         
+    //const TopoDS_Shape aShape = thePolyline->GetShape();     
+    const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape());
+    if(!aBndWire.IsNull()) {
+      TopoDS_Face limFace;       
+         if(buildLimFace(aBndWire, limFace)) {
+               TopoDS_Shape aComResult;
+           BRepAlgoAPI_Common mkCom(aResult, limFace);
+               if(mkCom.IsDone()) {
+             aComResult = mkCom.Shape();
+                 BRepCheck_Analyzer aCheck (aComResult);
+          if(aCheck.IsValid()) {
+#ifdef DEB_SPLIT_TO_ZONES
+                   BRepTools::Write(aComResult,"CommonV.brep");
+#endif 
+
+                   hasLimits = Standard_True; // DM2 should filled here
+                   HYDROData_MapOfShape aView;
+                   TopExp_Explorer exp (aResult, TopAbs_FACE);
+                   for (int i =1;exp.More();exp.Next(),i++) {
+              const TopoDS_Shape& aFace = exp.Current();
+                     if(!aFace.IsNull()) {
+                       const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
+                         //cout << "Modified: " << aListOfNew.Extent() <<endl;                 
+                const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);                       
+                           if(!aListOfNew.IsEmpty()) {
+                     aDM4.Bind(aFace, aListOfNew);
+                             //TCollection_AsciiString aName = aNam + i + ".brep";
+                                 //BRepTools::Write(aListOfNew.Last(), aName.ToCString());                             
+                               }
+                               else {
+                             if(!mkCom.IsDeleted(aFace)) {
+                                   if(!aListOfGen.IsEmpty()) {
+                         aDM4.Bind(aFace, aListOfGen);                        
+                                     //TCollection_AsciiString aName = aNam + i + "g.brep";
+                                     //BRepTools::Write(aListOfGen.Last(), aName.ToCString());
+                                       }
+                                        else {
+                                   TopTools_ListOfShape aList; 
+                                       aList.Append(aFace);
+                                       aDM4.Bind(aFace, aList); //the same face - not modified
+                                        }
+                                 }
+                        }
+                        TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
+                        for (int j =1;exp2.More();exp2.Next(),j++) {
+                          const TopoDS_Shape& anEdge = exp2.Current();
+                          if(!anEdge.IsNull()) {
+                                if(aView.Contains(anEdge)) continue;
+                                aView.Add(anEdge);
+                                const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
+                                const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
+                 if(!aListOfNewEd.IsEmpty())
+                      aDM4.Bind(anEdge, aListOfNewEd);
+                                else {
+                                  if(!mkCom.IsDeleted(anEdge)) {
+                                        if(!aListOfGenEd.IsEmpty()) {
+                                          aDM4.Bind(anEdge, aListOfGenEd);
+                                        } else {
+                                          TopTools_ListOfShape aList; 
+                                      aList.Append(anEdge);
+                                      aDM4.Bind(anEdge, aList);//the same edge - not modified
+                                        }
+                                  }
+                                }
+                          }
+                        }
+                       }
+                 } //end DM4 filling (phase 1)
+                   //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
+                // phase 2 (from tool)
+         TopExp_Explorer expt (limFace, TopAbs_EDGE);
+                for(;expt.More();expt.Next()) {
+                  const TopoDS_Shape& anEdge = expt.Current();
+                  if(!anEdge.IsNull()) {
+             const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
+                        const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
+             if(!aListOfNewEd.IsEmpty())
+                  aDM4.Bind(anEdge, aListOfNewEd);
+                        else {
+                          if(!mkCom.IsDeleted(anEdge)) {
+                                if(!aListOfGenEd.IsEmpty()) {
+                                  aDM4.Bind(anEdge, aListOfGenEd);
+                                } else {
+                                  TopTools_ListOfShape aList; 
+                              aList.Append(anEdge);
+                              aDM4.Bind(anEdge, aList);//the same edge - not modified
+                                }
+                          }
+                        }
+                  }
+                }
+                //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
+         HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1); 
+                //DM4 contains Old - New after common op. DM1: old - new after Split op.
+         for(;aMIt.More();aMIt.Next()) {
+           const TopoDS_Shape& aKey = aMIt.Key();
+           TopTools_ListOfShape aList;
+           aList.Append(aKey);
+           const TopTools_ListOfShape& aListOfNew = aMIt.Value();
+           TopTools_ListIteratorOfListOfShape it(aListOfNew);
+           for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
+                        if(!aDM4.IsBound(it.Value())) // bi - is deleted
+               continue; // go to the next bi
+                        else {
+                               const TopTools_ListOfShape& aListOfNew4 = aDM4.Find(it.Value());
+                           TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
+                for(;it4.More();it4.Next()) {
+                                 if(!aDM2.IsBound(it4.Value()))
+                    aDM2.Bind(it4.Value(), aList);
+                             else {
+                    TopTools_ListOfShape& aList = aDM2.ChangeFind(it4.Value());
+                    aList.Prepend(aKey);
+                                 }
+                               }
+                        }
+                  }//
+                 }
+                } else {
+                        hasLimits = Standard_False;
+#ifdef DEB_SPLIT_TO_ZONES
+                    BRepTools::Write(aComResult,"CommonNV.brep");
+#endif 
+                 }
+          }
+         }
+       }
+  }
+  if(!hasLimits) {
+    HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
+    for(;aMIt.More();aMIt.Next()) {
+      const TopoDS_Shape& aKey = aMIt.Key();
+      TopTools_ListOfShape aList;
+      aList.Append(aKey);
+      const TopTools_ListOfShape& aListOfNew = aMIt.Value();
+      TopTools_ListIteratorOfListOfShape it(aListOfNew);
+      for(;it.More();it.Next()) {
+        if(!aDM2.IsBound(it.Value()))
+          aDM2.Bind(it.Value(), aList);
+        else {
+          TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
+          aList.Prepend(aKey);
+               }
          }
        }
   }
-  //cout << "DM2 Ext = " <<aDM2.Extent() <<endl;
   // Step 4. Fill output structure.
-  aMIt.Initialize(aDM2);
+#ifdef DEB_SPLIT_TO_ZONES
+  TCollection_AsciiString aNam4 ("SC_");
+#endif  
+  HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
   for(int i =1;aMIt.More();aMIt.Next(),i++) {
     SplitData aDestSplitData;
-       const TopoDS_Shape& aKey = aMIt.Key(); //new
-       aDestSplitData.Shape = aKey;
-       if(aKey.ShapeType() == TopAbs_FACE)
-         aDestSplitData.Type = SplitData::Data_Zone;
-       else
+    const TopoDS_Shape& aKey = aMIt.Key(); //new
+    aDestSplitData.Shape = aKey;
+    if(aKey.ShapeType() == TopAbs_FACE)
+      aDestSplitData.Type = SplitData::Data_Zone;
+       else {
       aDestSplitData.Type = SplitData::Data_Edge;
+#ifdef DEB_SPLIT_TO_ZONES
+         TCollection_AsciiString aName = aNam4 + i + ".brep";
+         BRepTools::Write(aKey,aName.ToCString());
+#endif 
+       }
 
-       QStringList aListOfNames; // names processing
+    QStringList aListOfNames; // names processing
     const TopTools_ListOfShape& aListOfOld = aMIt.Value();
     TopTools_ListIteratorOfListOfShape it(aListOfOld);
        for(;it.More();it.Next()) {     
@@ -258,97 +472,21 @@ HYDROData_SplitToZonesTool::SplitDataList
          if(aDM3.IsBound(aSh)) {
            const QStringList& ObjectNames = aDM3.Find(aSh);
                aListOfNames.append(ObjectNames);
+#ifdef DEB_SPLIT_TO_ZONES
+
+               for ( int k = 1;k <= ObjectNames.length(); ++k ) {
+                       QString aStr = ObjectNames.last(); 
+                       cout << "Indx = " << i<< " k = " << k << " size = " <<ObjectNames.size() << " Name = "<<aStr.toStdString() <<endl;   
+               }       
+#endif 
          }      
        }
-/*     
-       if(aKey.ShapeType() == TopAbs_EDGE) {
-         QString aStr("EDGE_Of_Face_");
-         aStr = aStr.append(TCollection_AsciiString(i).ToCString());
-         const QStringList& ObjectNames = QStringList( aStr);
-         cout << "EDGE ==> " << ObjectNames.size() <<" " << aStr.toStdString()<<endl;
-         aListOfNames.append(ObjectNames);
-       }*/
+
        aDestSplitData.ObjectNames = aListOfNames;  
        anOutputSplitDataList.append(aDestSplitData);
   }
-  //cout << "anOutputSplitDataList = " <<anOutputSplitDataList.size() <<endl;
   return anOutputSplitDataList;
-
-  /*
-  SplitDataListIterator anInputIter( anInputSplitDataList );
-  while( anInputIter.hasNext() )
-  {
-    const SplitData& anInputSplitData = anInputIter.next();
-    if( anOutputSplitDataList.isEmpty() )
-      anOutputSplitDataList.append( anInputSplitData );
-    else
-    {
-      SplitDataList aSplitDataList;
-
-      SplitDataList aSrcSplitDataList;
-      aSrcSplitDataList.append( anInputSplitData );
-
-      SplitDataList aDestSplitDataList = anOutputSplitDataList;
-      anOutputSplitDataList.clear();
-
-      while( !aDestSplitDataList.isEmpty() )
-      {
-        SplitData aSrcSplitData = aSrcSplitDataList.last();
-
-        SplitData aDestSplitData = aDestSplitDataList.first();
-        aDestSplitDataList.pop_front();
-
-        SplitData aData1Subtracted, aData2Subtracted, aDataIntersected;
-        if( SplitTwoData( aSrcSplitData, aDestSplitData,
-                          aData1Subtracted, aData2Subtracted, aDataIntersected ) )
-          anOutputSplitDataList.append( aDataIntersected );
-        anOutputSplitDataList.append( aData2Subtracted );
-        aSrcSplitDataList.append( aData1Subtracted );
-      }
-
-      if( !aSrcSplitDataList.isEmpty() )
-        anOutputSplitDataList.append( aSrcSplitDataList.last() );
-    }
-  }
-
-  // Step 2. Take into account the boundary polyline.
-  if( !thePolyline.IsNull() )
-  {
-    TopoDS_Wire aWire = TopoDS::Wire( thePolyline->GetShape() );
-    if( !aWire.IsNull() )
-    {
-      BRepBuilderAPI_MakeFace aMakeFace( aWire, Standard_True );
-      aMakeFace.Build();
-      if( aMakeFace.IsDone() )
-      {
-        SplitData aBoundarySplitData( SplitData::Data_Zone, aMakeFace.Face(), "" );
-
-        SplitDataList aCutSplitDataList;
-        SplitDataListIterator anOutputIter( anOutputSplitDataList );
-        while( anOutputIter.hasNext() )
-        {
-          const SplitData& anOutputSplitData = anOutputIter.next();
-
-          SplitData aData1Subtracted, aData2Subtracted, aDataIntersected;
-          if( SplitTwoData( anOutputSplitData, aBoundarySplitData,
-                            aData1Subtracted, aData2Subtracted, aDataIntersected ) )
-            aCutSplitDataList.append( aDataIntersected );
-        }
-        anOutputSplitDataList = aCutSplitDataList;
-      }
-    }
-  }
-
-  // Step 3. Extract the separate regions.
-  SplitDataList anExtractedSplitDataList;
-  SplitDataListIterator anOutputIter( anOutputSplitDataList );
-  while( anOutputIter.hasNext() )
-  {
-    const SplitData& anOutputSplitData = anOutputIter.next();
-    anExtractedSplitDataList.append( ExtractSeparateData( anOutputSplitData ) );
-  }
-*/
- // return anExtractedSplitDataList;
 }
 
 bool HYDROData_SplitToZonesTool::SplitTwoData( const SplitData& theData1,