Salome HOME
Methods to work with imagw references:
[modules/hydro.git] / src / HYDROData / HYDROData_Region.cxx
index 10275833185f1117fdfa734c460b8f0e369a6235..6e0a0f1dee206324c3076569d210535444abbc5c 100644 (file)
@@ -26,7 +26,7 @@ QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjec
 {
   QStringList aResList;
 
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
   if ( aDocument.IsNull() )
     return aResList;
 
@@ -53,7 +53,7 @@ QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjec
   return aResList;
 }
 
-bool HYDROData_Region::AddZone( Handle(HYDROData_Zone)& theZone )
+bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
 {
   if ( theZone.IsNull() )
     return false;
@@ -66,15 +66,18 @@ bool HYDROData_Region::AddZone( Handle(HYDROData_Zone)& theZone )
     Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
   if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab )
   {
-    Handle(HYDROData_Zone) aNewZone = AddNewZone();
+    Handle(HYDROData_Zone) aNewZone = addNewZone();
     theZone->CopyTo( aNewZone );
 
     aFatherRegion->RemoveZone( theZone );
 
-    theZone = aNewZone;
+    theZone->SetLabel( aNewZone->Label() );
+  }
+  else
+  {
+    AddReferenceObject( theZone, DataTag_Zone );
   }
 
-  AddReferenceObject( theZone, DataTag_Zone );
   return true;
 }
 
@@ -85,24 +88,32 @@ HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const
 
 void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone )
 {
-  if ( theZone.IsNull() || !HasReference( theZone, DataTag_Zone ) )
+  if ( theZone.IsNull() )
     return;
 
   RemoveReferenceObject( theZone->Label(), DataTag_Zone );
 
   // Remove zone from data model
-  theZone->Remove();
+  Handle(HYDROData_Region) aFatherRegion = 
+    Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
+  if ( !aFatherRegion.IsNull() && aFatherRegion->Label() == myLab )
+    theZone->Remove();
+
+  // If the last zone has been removed from region we remove this region
+  HYDROData_SequenceOfObjects aRefZones = GetZones();
+  if ( aRefZones.IsEmpty() )
+    Remove();
 }
 
 void HYDROData_Region::RemoveZones()
 {
   ClearReferenceObjects( DataTag_Zone );
-  myLab.FindChild( ChildTag_Zone ).ForgetAllAttributes( true );
+  myLab.FindChild( DataTag_ChildZone ).ForgetAllAttributes( true );
 }
 
-Handle(HYDROData_Zone) HYDROData_Region::AddNewZone()
+Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
 {
-  TDF_Label aNewLab = myLab.FindChild( ChildTag_Zone ).NewChild();
+  TDF_Label aNewLab = myLab.FindChild( DataTag_ChildZone ).NewChild();
 
   Handle(HYDROData_Zone) aNewZone =
     Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );