const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next();
// Create new region
- Handle(HYDROData_Region) aRegion = AddNewRegion();
+ Handle(HYDROData_Region) aRegion = addNewRegion();
QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
aRegion->SetName( aRegionName );
// Add the zone for region
- Handle(HYDROData_Zone) aRegionZone = aRegion->AddNewZone();
+ Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone();
QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" );
aRegionZone->SetName( aZoneName );
ClearReferenceObjects( DataTag_GeometryObject );
}
-Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion()
+Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion( const Handle(HYDROData_Zone)& theZone )
{
- TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild();
+ Handle(HYDROData_Region) aNewRegion = addNewRegion();
+ if ( aNewRegion.IsNull() )
+ return aNewRegion;
- Handle(HYDROData_Region) aNewRegion =
- Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
- AddRegion( aNewRegion );
+ // Generate new name for new region
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+ if ( !aDocument.IsNull() )
+ {
+ QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" );
+ aNewRegion->SetName( aNewRegionName );
+ }
+
+ aNewRegion->AddZone( theZone );
return aNewRegion;
}
-bool HYDROData_Calculation::AddRegion( Handle(HYDROData_Region)& theRegion )
+bool HYDROData_Calculation::AddRegion( const Handle(HYDROData_Region)& theRegion )
{
if ( theRegion.IsNull() )
return false;
Handle(HYDROData_Calculation)::DownCast( theRegion->GetFatherObject() );
if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab )
{
- Handle(HYDROData_Region) aNewRegion = AddNewRegion();
+ Handle(HYDROData_Region) aNewRegion = addNewRegion();
theRegion->CopyTo( aNewRegion );
aFatherCalc->RemoveRegion( theRegion );
- theRegion = aNewRegion;
+ theRegion->SetLabel( aNewRegion->Label() );
}
AddReferenceObject( theRegion, DataTag_Region );
void HYDROData_Calculation::RemoveRegion( const Handle(HYDROData_Region)& theRegion )
{
- if ( theRegion.IsNull() || !HasReference( theRegion, DataTag_Region ) )
+ if ( theRegion.IsNull() )
return;
RemoveReferenceObject( theRegion->Label(), DataTag_Region );
// Remove region from data model
- theRegion->Remove();
+ Handle(HYDROData_Calculation) aFatherCalc =
+ Handle(HYDROData_Calculation)::DownCast( theRegion->GetFatherObject() );
+ if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab )
+ theRegion->Remove();
}
void HYDROData_Calculation::RemoveRegions()
ClearReferenceObjects( DataTag_Region );
myLab.FindChild( ChildTag_Region ).ForgetAllAttributes( true );
}
+
+Handle(HYDROData_Region) HYDROData_Calculation::addNewRegion()
+{
+ TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild();
+
+ Handle(HYDROData_Region) aNewRegion =
+ Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) );
+ AddRegion( aNewRegion );
+
+ return aNewRegion;
+}
+
class Handle(HYDROData_Object);
class Handle(HYDROData_Region);
+class Handle(HYDROData_Zone);
DEFINE_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Entity)
/**
- * Add new one region for calculation case.
+ * Add new one child region for calculation case.
* The new region is added into the list of reference regions.
+ * The label of theZone is changed during this operation
+ * because of new region becomes the new parent for this zone.
*/
- HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion();
+ HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion( const Handle(HYDROData_Zone)& theZone );
/**
* Add new one reference region for calculation case.
+ * The label of theRegion is changed in case if old parent is not this calculation.
*/
- HYDRODATA_EXPORT virtual bool AddRegion( Handle(HYDROData_Region)& theRegion );
+ HYDRODATA_EXPORT virtual bool AddRegion( const Handle(HYDROData_Region)& theRegion );
/**
* Returns all reference regions of calculation case.
*/
HYDRODATA_EXPORT virtual void RemoveRegions();
+private:
+
+ /**
+ * Add new one region for calculation case.
+ * The new region is added into the list of reference regions.
+ */
+ HYDRODATA_EXPORT virtual Handle(HYDROData_Region) addNewRegion();
+
+
protected:
friend class HYDROData_Iterator;
return aResList;
}
-bool HYDROData_Region::AddZone( Handle(HYDROData_Zone)& theZone )
+bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
{
if ( theZone.IsNull() )
return false;
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() );
}
AddReferenceObject( theZone, DataTag_Zone );
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()
myLab.FindChild( ChildTag_Zone ).ForgetAllAttributes( true );
}
-Handle(HYDROData_Zone) HYDROData_Region::AddNewZone()
+Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
{
TDF_Label aNewLab = myLab.FindChild( ChildTag_Zone ).NewChild();