]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Update names of regions in calculation case if its order has been changed (Bug #47).
authoradv <adv@opencascade.com>
Tue, 12 Nov 2013 07:44:13 +0000 (07:44 +0000)
committeradv <adv@opencascade.com>
Tue, 12 Nov 2013 07:44:13 +0000 (07:44 +0000)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h
src/HYDROData/HYDROData_Region.cxx
src/HYDROData/HYDROData_Region.h

index 7bfffe60bded1f0e97b42701513eaadf6925e29a..326af7419c0f7746e9db70e867cd481ed8489769 100644 (file)
@@ -11,6 +11,9 @@
 #include "HYDROData_Tool.h"
 #include "HYDROData_Zone.h"
 
+#define CALCULATION_REGIONS_PREF GetName() + "_Reg"
+#define CALCULATION_ZONES_PREF GetName() + "_Zone"
+
 #define PYTHON_CALCULATION_ID "KIND_CALCULATION"
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
@@ -92,6 +95,9 @@ void HYDROData_CalculationCase::SplitGeometryObjects()
   if ( aSplitedZones.isEmpty() )
     return;
 
+  QString aRegsPref = CALCULATION_REGIONS_PREF;
+  QString aZonesPref = CALCULATION_ZONES_PREF;
+
   // Create result regions for case, by default one zone for one region
   HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones );
   while( anIter.hasNext() )
@@ -101,13 +107,13 @@ void HYDROData_CalculationCase::SplitGeometryObjects()
     // Create new region
     Handle(HYDROData_Region) aRegion = addNewRegion();
 
-    QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
+    QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
     aRegion->SetName( aRegionName );
 
     // Add the zone for region
     Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
 
-    QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" );
+    QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref );
     aRegionZone->SetName( aZoneName );
 
     aRegionZone->SetShape( aSplitData.Face() );
@@ -206,7 +212,9 @@ Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(H
   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
   if ( !aDocument.IsNull() )
   {
-    QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
+    QString aRegsPref = CALCULATION_REGIONS_PREF;
+
+    QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
     aNewRegion->SetName( aNewRegionName );
   }
 
@@ -248,6 +256,40 @@ HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const
   return GetReferenceObjects( DataTag_Region );
 }
 
+void HYDROData_CalculationCase::UpdateRegionsOrder()
+{
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return;
+
+  HYDROData_SequenceOfObjects aRegions = GetRegions();
+
+  HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    Handle(HYDROData_Region) aRegion =
+      Handle(HYDROData_Region)::DownCast( anIter.Value() );
+    if ( aRegion.IsNull() )
+      continue;
+
+    aRegion->SetName( "" );
+  }
+
+  QString aRegsPref = CALCULATION_REGIONS_PREF;
+
+  anIter.Init( aRegions );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    Handle(HYDROData_Region) aRegion =
+      Handle(HYDROData_Region)::DownCast( anIter.Value() );
+    if ( aRegion.IsNull() )
+      continue;
+
+    QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref );
+    aRegion->SetName( aRegionName );
+  }
+}
+
 void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
 {
   if ( theRegion.IsNull() )
index d6d6ac45d55b10bd3a41be0f04227c2d514ecff3..77edbf778faa997b627d62276f4abb03a8f1b855 100644 (file)
@@ -115,6 +115,11 @@ public:
    */
   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetRegions() const;
 
+  /**
+   * Updates names of regions to correct order.
+   */
+  HYDRODATA_EXPORT virtual void UpdateRegionsOrder();
+
   /**
    * Removes reference region from calculation case.
    */
index 6e0a0f1dee206324c3076569d210535444abbc5c..82a3b7c86a3aa207f459c78749da2653bdc969e7 100644 (file)
@@ -1,6 +1,7 @@
 
 #include "HYDROData_Region.h"
 
+#include "HYDROData_CalculationCase.h"
 #include "HYDROData_Document.h"
 #include "HYDROData_Iterator.h"
 #include "HYDROData_Zone.h"
@@ -53,6 +54,17 @@ QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjec
   return aResList;
 }
 
+void HYDROData_Region::Remove()
+{
+  Handle(HYDROData_CalculationCase) aFatherCalc = 
+    Handle(HYDROData_CalculationCase)::DownCast( GetFatherObject() );
+
+  HYDROData_Entity::Remove();
+
+  if ( !aFatherCalc.IsNull() )
+    aFatherCalc->UpdateRegionsOrder();
+}
+
 bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
 {
   if ( theZone.IsNull() )
index 5ba5bf969527ec0575ce4fc0342c605d3b56aeb7..f0d2075f107d886181494ab89e77c17430882c49 100644 (file)
@@ -41,6 +41,13 @@ public:
   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
 
 
+  /**
+   * Removes object and it child sub-objects from the data structure.
+   * Reimplemented to update names of regions in father calculation.
+   */
+  HYDRODATA_EXPORT virtual void Remove();
+
+
   /**
    * Add new one reference zone for region.
    * The label of theZone is changed in case if old parent is not this region.