Salome HOME
lots 3,8
[modules/hydro.git] / src / HYDROData / HYDROData_SplitToZonesTool.cxx
index ddcc40706f0870ebfe84d50ab6e51a9bab8f7903..94d57ea7b5647713be2d65eae0fb0b370f2707fe 100644 (file)
@@ -44,6 +44,7 @@
 #include <BOPAlgo_BOP.hxx>
 #include <BOPAlgo_Builder.hxx>
 #include <TopExp.hxx>
+#include <assert.h>
 
 //#define DEB_SPLIT_TO_ZONES 1
 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
@@ -52,7 +53,7 @@
 static TCollection_AsciiString fileNameBefore("BeforeTranslation");
 #endif
 
-#define _DEVDEBUG_
+//#define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
 
 TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
@@ -118,7 +119,7 @@ void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, cons
 #endif
 }
 //======================================================================================
-Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp, 
+bool HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp, 
                                                         HYDROData_Transform& theTool)
 {
   theTool.Clear();
@@ -127,8 +128,7 @@ Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& t
   const Standard_Boolean bToTransform = theTool.ToTransform();  
   theTool.SetToTransform(bToTransform);  
   theTool.Perform();
-  Standard_Integer anErr = theTool.ErrorStatus();
-  return anErr;
+  return theTool.HasErrors();
 }
 
 //======================================================================================
@@ -138,7 +138,9 @@ HYDROData_SplitToZonesTool::SplitDataList
                                      const Handle(HYDROData_PolylineXY)& thePolyline,
                                      const HYDROData_SequenceOfObjects& InterPolys)
 {
+#ifndef NDEBUG
   DEBTRACE("Split");
+#endif
   SplitDataList anOutputSplitDataList;
   NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher> OutNE;
   if(theObjectList.IsEmpty())
@@ -225,7 +227,8 @@ HYDROData_SplitToZonesTool::SplitDataList
       //anOutputSplitDataList.append(anInputSplitDataList); 
       SplitData SD = anInputSplitDataList.at(0);
       TopTools_ListOfShape newshs;
-      CutFaceByEdges(SD.Face(), newshs, InterPolys, &OutNE);
+      TopTools_IndexedDataMapOfShapeListOfShape OutOrSh2M;
+      CutFaceByEdges(SD.Face(), newshs, InterPolys, &OutNE, &OutOrSh2M);
       for (TopTools_ListIteratorOfListOfShape it(newshs); it.More(); it.Next())
       {
         SplitData NSD = SD;
@@ -243,8 +246,66 @@ HYDROData_SplitToZonesTool::SplitDataList
         anOutputSplitDataList.append(SDI);
       }
 
+#ifndef NDEBUG
+      //check CutFaceByEdges method: ensure that SD.Face() edges fully covered by
+      //history map (OutOrSh2M)
+      if (!OutOrSh2M.IsEmpty())
+      {
+        TopTools_IndexedMapOfShape EE;
+        TopExp::MapShapes(SD.Face(), TopAbs_EDGE, EE);
+        int noncontNb = 0;      
+        for (int i = 1; i <= EE.Extent(); i++)
+        {
+          const TopoDS_Shape& E = EE(i);
+          noncontNb += !OutOrSh2M.Contains(E);
+        }
+        //noncontNb > 0 => some problem with edge history
+        assert(noncontNb == 0);
+      }
+#endif
+
       if(!theGroupsList.IsEmpty() ) 
-        anOutputSplitDataList.append(anInputGroupList);
+      {
+        SplitDataList ModifInpGroupList;
+        SplitDataListIterator it(anInputGroupList);
+        while( it.hasNext() )
+        {
+          const SplitData& SData = it.next();
+          if (SData.Type != SplitData::Data_Edge)
+            ModifInpGroupList.append(SData); //add as is
+          const TopoDS_Shape& SData_sh = SData.Shape;
+          TopTools_ListOfShape modif_ls;
+          if (!InterPolys.IsEmpty())
+            if (OutOrSh2M.Contains(SData_sh))
+              modif_ls = OutOrSh2M.FindFromKey(SData_sh);
+            //else TODO -  show message that one of the object should be updated
+
+#ifndef NDEBUG
+          if (!InterPolys.IsEmpty() && OutOrSh2M.IsEmpty())
+            assert (true);
+#endif
+          if (modif_ls.IsEmpty())
+            ModifInpGroupList.append(SData); //non modified
+          else
+          {
+            TopTools_ListIteratorOfListOfShape itl_modif(modif_ls);
+            for (;itl_modif.More();itl_modif.Next())
+            {
+              const TopoDS_Shape& CSH = itl_modif.Value();
+              if (CSH.ShapeType() == TopAbs_EDGE)
+              {
+                SplitData NewSData;
+                NewSData.ObjectNames = SData.ObjectNames;
+                NewSData.Type = SData.Type;
+                NewSData.Shape = CSH;
+                ModifInpGroupList.append(NewSData);
+              }
+            }
+          }
+
+        }
+        anOutputSplitDataList.append(ModifInpGroupList);
+      }
       return anOutputSplitDataList;
     }
     else
@@ -261,7 +322,7 @@ HYDROData_SplitToZonesTool::SplitDataList
 
   // Step 1. Prepare Partition structures. 
   TopoDS_Shape aResult;
-  BOPCol_ListOfShape aLS;  
+  TopTools_ListOfShape aLS;  
   QStringList aListOfNames;
   TopoDS_Compound aCmp;
   BRep_Builder aBB;
@@ -284,7 +345,7 @@ HYDROData_SplitToZonesTool::SplitDataList
   HYDROData_DataMapOfShapeListOfShape aDM1;
   if(anInputSplitDataList.size() > 1) {
     HYDROData_Transform splitTool; 
-    const Standard_Integer anErr = SplitFaces(aCmp, splitTool);    
+    bool anErr = SplitFaces(aCmp, splitTool);    
     if(anErr)
       return anOutputSplitDataList;
     aResult = splitTool.Shape();
@@ -304,7 +365,7 @@ HYDROData_SplitToZonesTool::SplitDataList
     
     // Step 3. Collect history  
     //HYDROData_DataMapOfShapeListOfShape aDM1;
-    BOPCol_ListIteratorOfListOfShape anIt(aLS); 
+    TopTools_ListIteratorOfListOfShape anIt(aLS); 
   #ifdef DEB_SPLIT_TO_ZONES
     TCollection_AsciiString aNamM ("EdgM_");
     TCollection_AsciiString aNamG ("EdgG_");
@@ -340,8 +401,10 @@ HYDROData_SplitToZonesTool::SplitDataList
         for (int j =1;exp.More();exp.Next(),j++) {
           aList.Clear();
           Standard_Boolean foundE(Standard_False);
-          const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());    
+          const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current()); 
+#ifndef NDEBUG
           DEBTRACE("NB_EDGE_M = " << aListM.Extent());
+#endif
           if(aListM.Extent()) foundE = Standard_True;
           it.Initialize(aListM);    
           for(int k=1;it.More();it.Next(),k++) {    
@@ -419,7 +482,9 @@ HYDROData_SplitToZonesTool::SplitDataList
               const TopoDS_Shape& aFace = exp.Current();
               if(!aFace.IsNull()) {
                 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
+#ifndef NDEBUG
                 DEBTRACE("Modified: " << aListOfNew.Extent());
+#endif
                 if(!aListOfNew.IsEmpty()) {
                   aDM4.Add(aFace, aListOfNew);
 #ifdef DEB_SPLIT_TO_ZONES
@@ -682,7 +747,7 @@ void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOf
     TopTools_ListOfShape out;
     if (K.ShapeType() == TopAbs_FACE)
     {
-      CutByEdges(K, Wires, out, &OutNE1);
+      CutByEdges(K, Wires, out, &OutNE1, NULL);
       TopTools_ListIteratorOfListOfShape it(out);
       for (;it.More(); it.Next())
       {
@@ -704,7 +769,8 @@ void HYDROData_SplitToZonesTool::AddInternalEdges(HYDROData_DataMapOfShapeListOf
 void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in, 
                                                 TopTools_ListOfShape& out, 
                                                 const HYDROData_SequenceOfObjects& thePolylines,
-                                                NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE)
+                                                NCollection_DataMap<TopoDS_Shape, Handle(HYDROData_PolylineXY), TopTools_ShapeMapHasher>* OutNE,                                                
+                                                TopTools_IndexedDataMapOfShapeListOfShape* OutOrSh2M)
 {
 
   HYDROData_SequenceOfObjects::Iterator it(thePolylines);
@@ -719,7 +785,7 @@ void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in,
   }
 
   TopTools_IndexedDataMapOfShapeShape OutNE1;
-  CutByEdges(in, Wires, out, &OutNE1);
+  CutByEdges(in, Wires, out, &OutNE1, OutOrSh2M);
 
   for (int i = 1; i <= OutNE1.Extent(); i++)
     OutNE->Bind(OutNE1.FindKey(i), W2P(OutNE1.FindFromIndex(i)));
@@ -727,7 +793,9 @@ void HYDROData_SplitToZonesTool::CutFaceByEdges(const TopoDS_Face& in,
 }
 
 int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTools_ListOfShape& InW,
-  TopTools_ListOfShape& outShs, TopTools_IndexedDataMapOfShapeShape* OutNE)
+                                           TopTools_ListOfShape& outShs, 
+                                           TopTools_IndexedDataMapOfShapeShape* OutNE, 
+                                           TopTools_IndexedDataMapOfShapeListOfShape* OInSH2MSH)
 {
   int anError;
   if (InSh.IsNull())
@@ -747,9 +815,8 @@ int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTo
     anAlgo.AddArgument( anIt.Value() );
 
   anAlgo.Perform(); 
-  anError = anAlgo.ErrorStatus();
-  if (anError)
-    return anError;
+  if (anAlgo.HasErrors())
+    return -1;
 
   outShs = anAlgo.Modified( InSh );
   if (outShs.IsEmpty())
@@ -785,7 +852,19 @@ int HYDROData_SplitToZonesTool::CutByEdges(const TopoDS_Shape& InSh, const TopTo
       if (AllEdges.Contains(CE))
         OutNE->Add(CE, V);
     }
+  }
 
+  //map all sub-shapes from the original InSh to modified shapes  
+  if (OInSH2MSH)
+  {
+    TopTools_IndexedMapOfShape allSh;
+    TopExp::MapShapes(InSh, allSh);
+    for(int i = 1; i <= allSh.Extent(); i++ )
+    {
+      const TopoDS_Shape& or_sh = allSh(i); 
+      const TopTools_ListOfShape& ls = anAlgo.Modified(or_sh);
+      OInSH2MSH->Add(or_sh, ls);
+    }
   }
 
   return 0;