Salome HOME
lot 15:: protection against corrupted polylines/objects
[modules/hydro.git] / src / HYDROData / HYDROData_CompleteCalcCase.cxx
index 2aa627b003070201f591a9808755292ab7a46898..4814cf27e2781210da27c6892dcb4121e016d20a 100644 (file)
@@ -42,7 +42,12 @@ static void GetModifToOrigHistory(BOPAlgo_Builder& theAlgo, TopTools_IndexedData
   TopTools_IndexedMapOfShape argsAllSh;
   TopTools_ListOfShape::Iterator it(args);
   for (;it.More();it.Next())
+  {
+    const TopoDS_Shape& aSh = it.Value();
+    if (aSh.IsNull())
+      continue;
     TopExp::MapShapes(it.Value(), argsAllSh);
+  }
   for (int i=1;i<=argsAllSh.Extent();i++)
   {
     const TopoDS_Shape& arg_sh = argsAllSh(i);
@@ -90,7 +95,9 @@ static bool CheckIntersection(BOPAlgo_Builder& theAlgo, const std::vector<TopoDS
 bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& doc,
                                              Handle(HYDROData_CalculationCase)& theCalcCase, 
                                              NCollection_Sequence<Handle(HYDROData_Entity)> theNewObjects,
-                                             bool& IsIntersectionOfNewObj)
+                                             bool IsUseOrigNamingOfNewRegions,
+                                             bool& IsIntersectionOfNewObj,
+                                             NCollection_Sequence<Handle(HYDROData_Region)>& theNewRegions)
 {
   Handle(HYDROData_PolylineXY) aBndPolyline = theCalcCase->GetBoundaryPolyline();        
   TopoDS_Wire aBndWire;
@@ -125,10 +132,13 @@ bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& d
     if (!aPolyXY.IsNull())
     {
       TopoDS_Shape aSh = aPolyXY->GetShape();
-      newShapes.push_back(aSh);
-      anAlgo.AddArgument(aSh);
-      QStringList aLS(aPolyXY->GetName());
-      aShToRefObjects.Bind(aSh, aLS);
+      if (!aSh.IsNull())
+      {
+        newShapes.push_back(aSh);
+        anAlgo.AddArgument(aSh);
+        QStringList aLS(aPolyXY->GetName());
+        aShToRefObjects.Bind(aSh, aLS);
+      }
     }
     else 
     {
@@ -146,10 +156,13 @@ bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& d
           newshapesGroups.push_back(aGroup);
         }
         //
-        newShapes.push_back(aSh);
-        anAlgo.AddArgument(aSh);
-        QStringList aLS(anObj->GetName());
-        aShToRefObjects.Bind(aSh, aLS);
+        if (!aSh.IsNull())
+        {
+          newShapes.push_back(aSh);
+          anAlgo.AddArgument(aSh);
+          QStringList aLS(anObj->GetName());
+          aShToRefObjects.Bind(aSh, aLS);
+        }
       }
     }
   }
@@ -245,7 +258,7 @@ bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& d
       NREGV.push_back(vect);
     }
   }
-  
+
   //iter through already existing zone
   //substract new zones (NREGV) from old zones
   for ( int i = 1; i <= aRegions.Size(); i++ )
@@ -307,10 +320,12 @@ bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& d
   {
     const std::vector<TopoDS_Shape>& sh_vec = NREGV[k];
     Handle(HYDROData_Region) aRegion = theCalcCase->addNewRegion( doc, aRegsPref );
+    theNewRegions.Append(aRegion);
+    QString OrigNameOfRegion = "";
     for (int i=0;i<sh_vec.size();i++)
     {
       TopoDS_Face nF = TopoDS::Face(sh_vec[i]);
-      QString zoneName = aZonesPref;
+      //QString zoneName = aZonesPref;
       QStringList refObjList;
       //
       const TopTools_ListOfShape* origLS = theModifToOrigMap.Seek(nF);
@@ -326,7 +341,13 @@ bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& d
       }
       //
       Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone( doc, aZonesPref, nF, refObjList);
+
+      //try to get an origial name region (obtained from origin object)
+      if (IsUseOrigNamingOfNewRegions && !refObjList.empty() && OrigNameOfRegion == "") 
+        OrigNameOfRegion = refObjList.first();
     }
+    if (OrigNameOfRegion != "")
+      aRegion->SetName(OrigNameOfRegion + "_reg");
   }
 
   //GROUPS
@@ -418,6 +439,7 @@ bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& d
     TopTools_SequenceOfShape aSeqSh, ModifedGDefSeq;
     aGroup->GetShapes(aSeqSh);
     Handle(HYDROData_SplitShapesGroup) aSplitGroup = theCalcCase->addNewSplitGroup( aName );
+    theCalcCase->AddGeometryGroup( aSplitGroup );
 
     for (int i=1;i<=aSeqSh.Length();i++)
     {
@@ -431,5 +453,6 @@ bool HYDROData_CompleteCalcCase::AddObjects( const Handle(HYDROData_Document)& d
     }
     aSplitGroup->SetShapes(ModifedGDefSeq);
   }
+
   return true;
 }