#include "HYDROData_Region.h"
-#include <QString>
+#include "HYDROData_Document.h"
+#include "HYDROData_Iterator.h"
+#include "HYDROData_Zone.h"
-#define PYTHON_REGION_ID "KIND_REGION"
+#include <QStringList>
+#define PYTHON_REGION_ID "KIND_REGION"
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Domain)
-IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Domain)
+IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity)
+IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity)
HYDROData_Region::HYDROData_Region()
+ : HYDROData_Entity()
{
}
{
}
-QString HYDROData_Region::getPythonKindId() const
+QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
{
- return QString( PYTHON_REGION_ID );
+ QStringList aResList;
+
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this );
+ if ( aDocument.IsNull() )
+ return aResList;
+
+ QString aDocName = aDocument->GetDocPyName();
+ QString aRegionName = GetName();
+
+ aResList << QString( "%1 = %2.CreateObject( %3 );" )
+ .arg( aRegionName ).arg( aDocName ).arg( PYTHON_REGION_ID );
+ aResList << QString( "%1.SetName( \"%2\" );" )
+ .arg( aRegionName ).arg( aRegionName );
+ aResList << QString( "" );
+
+ HYDROData_SequenceOfObjects aZones = GetZones();
+ HYDROData_SequenceOfObjects::Iterator anIter( aZones );
+ for ( ; anIter.More(); anIter.Next() )
+ {
+ Handle(HYDROData_Zone) aRefZone =
+ Handle(HYDROData_Zone)::DownCast( anIter.Value() );
+ if ( !aRefZone.IsNull() )
+ setPythonReferenceObject( theTreatedObjects, aResList, aRefZone, "AddZone" );
+ }
+ aResList << QString( "" );
+
+ return aResList;
}
+bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
+{
+ if ( theZone.IsNull() )
+ return false;
+
+ if ( HasReference( theZone, DataTag_Zone ) )
+ return false; // Object is already in reference list
+ // Move the zone from other region
+ Handle(HYDROData_Region) aFatherRegion =
+ Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
+ if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab )
+ {
+ Handle(HYDROData_Zone) aNewZone = addNewZone();
+ theZone->CopyTo( aNewZone );
+
+ aFatherRegion->RemoveZone( theZone );
+
+ theZone->SetLabel( aNewZone->Label() );
+ }
+
+ AddReferenceObject( theZone, DataTag_Zone );
+ return true;
+}
+
+HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const
+{
+ return GetReferenceObjects( DataTag_Zone );
+}
+
+void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone )
+{
+ if ( theZone.IsNull() )
+ return;
+
+ RemoveReferenceObject( theZone->Label(), DataTag_Zone );
+
+ // Remove zone from data model
+ 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( DataTag_ChildZone ).ForgetAllAttributes( true );
+}
+
+Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
+{
+ TDF_Label aNewLab = myLab.FindChild( DataTag_ChildZone ).NewChild();
+
+ Handle(HYDROData_Zone) aNewZone =
+ Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );
+ AddZone( aNewZone );
+
+ return aNewZone;
+}