From 8538df60dfaeb61e0e44362e20d359747cdae923 Mon Sep 17 00:00:00 2001 From: adv Date: Tue, 29 Oct 2013 06:24:53 +0000 Subject: [PATCH] Calculation case and it child objects methods has been revised. --- src/HYDROData/HYDROData_Calculation.cxx | 110 +++++++++------------- src/HYDROData/HYDROData_Calculation.h | 71 ++------------ src/HYDROData/HYDROData_Entity.cxx | 39 ++++++++ src/HYDROData/HYDROData_Entity.h | 14 +++ src/HYDROData/HYDROData_Iterator.cxx | 11 ++- src/HYDROData/HYDROData_Iterator.h | 2 +- src/HYDROData/HYDROData_Region.cxx | 96 ++++++------------- src/HYDROData/HYDROData_Region.h | 77 ++------------- src/HYDROData/HYDROData_Zone.cxx | 56 ++++++++--- src/HYDROData/HYDROData_Zone.h | 47 +++++++--- src/HYDROGUI/HYDROGUI_CalculationOp.cxx | 2 - src/HYDROPy/HYDROData_Calculation.sip | 120 +----------------------- src/HYDROPy/HYDROData_Region.sip | 115 ----------------------- src/HYDROPy/HYDROData_Zone.sip | 88 ++++++++++------- 14 files changed, 289 insertions(+), 559 deletions(-) diff --git a/src/HYDROData/HYDROData_Calculation.cxx b/src/HYDROData/HYDROData_Calculation.cxx index 33e91daf..c70d300a 100644 --- a/src/HYDROData/HYDROData_Calculation.cxx +++ b/src/HYDROData/HYDROData_Calculation.cxx @@ -1,16 +1,15 @@ #include "HYDROData_Calculation.h" +#include "HYDROData_ArtificialObject.h" #include "HYDROData_Document.h" #include "HYDROData_Iterator.h" -#include "HYDROData_Object.h" +#include "HYDROData_NaturalObject.h" #include "HYDROData_SplitToZonesTool.h" #include "HYDROData_Region.h" #include "HYDROData_Tool.h" #include "HYDROData_Zone.h" -#include - #define PYTHON_CALCULATION_ID "KIND_CALCULATION" IMPLEMENT_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Entity) @@ -77,7 +76,6 @@ void HYDROData_Calculation::SplitGeometryObjects() { // At first we remove previously created regions RemoveRegions(); - RemoveChildRegions(); Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); if ( aDocument.IsNull() ) @@ -100,14 +98,12 @@ void HYDROData_Calculation::SplitGeometryObjects() // Create new region Handle(HYDROData_Region) aRegion = AddNewRegion(); - AddRegion( aRegion ); QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" ); aRegion->SetName( aRegionName ); // Add the zone for region Handle(HYDROData_Zone) aRegionZone = aRegion->AddNewZone(); - aRegion->AddZone( aRegionZone ); QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" ); aRegionZone->SetName( aZoneName ); @@ -129,36 +125,33 @@ void HYDROData_Calculation::SplitGeometryObjects() } } -int HYDROData_Calculation::NbGeometryObjects() const +bool HYDROData_Calculation::AddGeometryObject( const Handle(HYDROData_Object)& theObject ) { - return NbReferenceObjects( DataTag_GeometryObject ); -} + if ( theObject.IsNull() ) + return false; + + if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) && + !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) ) + return false; // Wrong type of object -void HYDROData_Calculation::AddGeometryObject( const Handle(HYDROData_Object)& theObject ) -{ - AddReferenceObject( theObject, DataTag_GeometryObject ); -} + if ( HasReference( theObject, DataTag_GeometryObject ) ) + return false; // Object is already in reference list -void HYDROData_Calculation::SetGeometryObject( const int theIndex, - const Handle(HYDROData_Object)& theObject ) -{ - SetReferenceObject( theObject, DataTag_GeometryObject, theIndex ); + AddReferenceObject( theObject, DataTag_GeometryObject ); + return true; } -void HYDROData_Calculation::SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ) +HYDROData_SequenceOfObjects HYDROData_Calculation::GetGeometryObjects() const { - SetReferenceObjects( theObjects, DataTag_GeometryObject ); + return GetReferenceObjects( DataTag_GeometryObject ); } -Handle(HYDROData_Object) HYDROData_Calculation::GetGeometryObject( const int theIndex ) const +void HYDROData_Calculation::RemoveGeometryObject( const Handle(HYDROData_Object)& theObject ) { - return Handle(HYDROData_Object)::DownCast( - GetReferenceObject( DataTag_GeometryObject, theIndex ) ); -} + if ( theObject.IsNull() ) + return; -HYDROData_SequenceOfObjects HYDROData_Calculation::GetGeometryObjects() const -{ - return GetReferenceObjects( DataTag_GeometryObject ); + RemoveReferenceObject( theObject->Label(), DataTag_GeometryObject ); } void HYDROData_Calculation::RemoveGeometryObjects() @@ -170,46 +163,36 @@ Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion() { TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild(); - return Handle(HYDROData_Region)::DownCast( - HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) ); -} - -void HYDROData_Calculation::RemoveChildRegions() -{ - myLab.FindChild( ChildTag_Region ).ForgetAllAttributes( true ); -} - -int HYDROData_Calculation::NbRegions() const -{ - return NbReferenceObjects( DataTag_Region ); -} + Handle(HYDROData_Region) aNewRegion = + Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) ); + AddRegion( aNewRegion ); -void HYDROData_Calculation::AddRegion( const Handle(HYDROData_Region)& theRegion ) -{ - AddReferenceObject( theRegion, DataTag_Region ); + return aNewRegion; } -void HYDROData_Calculation::SetRegion( const int theIndex, - const Handle(HYDROData_Region)& theRegion ) +bool HYDROData_Calculation::AddRegion( Handle(HYDROData_Region)& theRegion ) { - SetReferenceObject( theRegion, DataTag_Region, theIndex ); -} + if ( theRegion.IsNull() ) + return false; + + if ( HasReference( theRegion, DataTag_Region ) ) + return false; // Object is already in reference list + + // Move the region from other calculation + Handle(HYDROData_Calculation) aFatherCalc = + Handle(HYDROData_Calculation)::DownCast( theRegion->GetFatherObject() ); + if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab ) + { + Handle(HYDROData_Region) aNewRegion = AddNewRegion(); + theRegion->CopyTo( aNewRegion ); -void HYDROData_Calculation::InsertRegion( const int theBeforeIndex, - const Handle(HYDROData_Region)& theRegion ) -{ - InsertReferenceObject( theRegion, DataTag_Region, theBeforeIndex ); -} + aFatherCalc->RemoveRegion( theRegion ); -void HYDROData_Calculation::SetRegions( const HYDROData_SequenceOfObjects& theRegions ) -{ - SetReferenceObjects( theRegions, DataTag_Region ); -} + theRegion = aNewRegion; + } -Handle(HYDROData_Region) HYDROData_Calculation::GetRegion( const int theIndex ) const -{ - return Handle(HYDROData_Region)::DownCast( - GetReferenceObject( DataTag_Region, theIndex ) ); + AddReferenceObject( theRegion, DataTag_Region ); + return true; } HYDROData_SequenceOfObjects HYDROData_Calculation::GetRegions() const @@ -219,18 +202,17 @@ HYDROData_SequenceOfObjects HYDROData_Calculation::GetRegions() const void HYDROData_Calculation::RemoveRegion( const Handle(HYDROData_Region)& theRegion ) { - if ( theRegion.IsNull() ) + if ( theRegion.IsNull() || !HasReference( theRegion, DataTag_Region ) ) return; RemoveReferenceObject( theRegion->Label(), DataTag_Region ); -} -void HYDROData_Calculation::RemoveRegion( const int theIndex ) -{ - RemoveReferenceObject( DataTag_Region, theIndex ); + // Remove region from data model + theRegion->Remove(); } void HYDROData_Calculation::RemoveRegions() { ClearReferenceObjects( DataTag_Region ); + myLab.FindChild( ChildTag_Region ).ForgetAllAttributes( true ); } diff --git a/src/HYDROData/HYDROData_Calculation.h b/src/HYDROData/HYDROData_Calculation.h index 60acfb8d..4e7856ab 100644 --- a/src/HYDROData/HYDROData_Calculation.h +++ b/src/HYDROData/HYDROData_Calculation.h @@ -64,85 +64,37 @@ public: /** - * Returns number of geometry objects for calculation case. + * Add new one reference geometry object for calculation case. */ - HYDRODATA_EXPORT virtual int NbGeometryObjects() const; + HYDRODATA_EXPORT virtual bool AddGeometryObject( const Handle(HYDROData_Object)& theObject ); /** - * Add new one geometry object for calculation case. + * Returns all reference geometry objects of calculation case. */ - HYDRODATA_EXPORT virtual void AddGeometryObject( const Handle(HYDROData_Object)& theObject ); - - /** - * Replace the geometry object for calculation case. - */ - HYDRODATA_EXPORT virtual void SetGeometryObject( const int theIndex, - const Handle(HYDROData_Object)& theObject ); - - /** - * Sets the geometry object for calculation case. - */ - HYDRODATA_EXPORT virtual void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); - - /** - * Returns geometry object of calculation case by index. - */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Object) GetGeometryObject( const int theIndex ) const; + HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryObjects() const; /** - * Returns all geometry objects of calculation case. + * Removes reference geometry object from calculation case. */ - HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryObjects() const; + HYDRODATA_EXPORT virtual void RemoveGeometryObject( const Handle(HYDROData_Object)& theObject ); /** - * Removes all geometry objects from calculation case. + * Removes all reference geometry objects from calculation case. */ HYDRODATA_EXPORT virtual void RemoveGeometryObjects(); /** * Add new one region for calculation case. - * The new region is not added into the list of reference regions. + * The new region is added into the list of reference regions. */ HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion(); - /** - * Removes all child regions from calculation case. - */ - HYDRODATA_EXPORT virtual void RemoveChildRegions(); - - - /** - * Returns number of reference regions of calculation case. - */ - int NbRegions() const; /** * Add new one reference region for calculation case. */ - HYDRODATA_EXPORT virtual void AddRegion( const Handle(HYDROData_Region)& theRegion ); - - /** - * Replace the reference region for calculation case. - */ - HYDRODATA_EXPORT virtual void SetRegion( const int theIndex, - const Handle(HYDROData_Region)& theRegion ); - - /** - * Inserts the reference region for calculation case before given index. - */ - HYDRODATA_EXPORT virtual void InsertRegion( const int theBeforeIndex, - const Handle(HYDROData_Region)& theRegion ); - - /** - * Sets reference regions for calculation case. - */ - HYDRODATA_EXPORT virtual void SetRegions( const HYDROData_SequenceOfObjects& theRegions ); - - /** - * Returns reference region of calculation case by index. - */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Region) GetRegion( const int theIndex ) const; + HYDRODATA_EXPORT virtual bool AddRegion( Handle(HYDROData_Region)& theRegion ); /** * Returns all reference regions of calculation case. @@ -154,11 +106,6 @@ public: */ HYDRODATA_EXPORT virtual void RemoveRegion( const Handle(HYDROData_Region)& theRegion ); - /** - * Removes reference region from calculation case by it index. - */ - HYDRODATA_EXPORT virtual void RemoveRegion( const int theIndex ); - /** * Removes all reference regions from calculation case. */ diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index be8a51ed..27efc616 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -84,6 +84,24 @@ void HYDROData_Entity::CopyTo(Handle_HYDROData_Entity theDestination) const aCopy.Perform(); } +Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const +{ + Handle(HYDROData_Entity) aFather; + + if ( !myLab.IsNull() ) + { + TDF_Label aFatherLabel = myLab.Father(); + + while ( aFather.IsNull() && !aFatherLabel.IsNull() && !aFatherLabel.IsRoot() ) + { + aFather = HYDROData_Iterator::Object( aFatherLabel ); + aFatherLabel = aFatherLabel.Father(); + } + } + + return aFather; +} + void HYDROData_Entity::SetLabel(TDF_Label theLabel) { myLab = theLabel; @@ -133,6 +151,27 @@ int HYDROData_Entity::NbReferenceObjects( const int theTag ) const return aRefs.IsNull() ? 0 : aRefs->Extent(); } +bool HYDROData_Entity::HasReference( const Handle_HYDROData_Entity& theObj, + const int theTag ) const +{ + if ( theObj.IsNull() ) + return false; + + Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false ); + if ( aRefs.IsNull() || aRefs->IsEmpty() ) + return false; + + TDF_ListIteratorOfLabelList aListIt( aRefs->List() ); + for ( ; aListIt.More(); aListIt.Next() ) + { + const TDF_Label& aRefLabel = aListIt.Value(); + if ( theObj->Label() == aRefLabel ) + return true; + } + + return false; +} + void HYDROData_Entity::AddReferenceObject( const Handle_HYDROData_Entity& theObj, const int theTag ) { diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index ca4ac508..79f4f5c0 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -137,6 +137,12 @@ public: */ HYDRODATA_EXPORT TDF_Label& Label() {return myLab;} + /** + * Returns father object. For object created under root document label + * this method always return NULL object. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const; + protected: friend class HYDROData_Iterator; @@ -182,6 +188,14 @@ protected: */ int NbReferenceObjects( const int theTag = 0 ) const; + /** + * Internal method that used to check object for entry into the reference list + * \param theObj pointer to reference object + * \param theTag tag of a label to store attribute (for 0 this is myLab) + */ + bool HasReference( const Handle_HYDROData_Entity& theObj, + const int theTag = 0 ) const; + /** * Internal method that used to store the reference object label attribute * \param theObj pointer to reference object diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index 04ad41dd..a9486d07 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -71,8 +71,16 @@ Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& the return Object( theNewLabel ); } -Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label theLabel ) +Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel ) { + Handle(HYDROData_Entity) aResult; + + // If label has no name attribute it mean that this is not object or + // this object has been removed from document + Handle(TDataStd_Name) aNameAtt; + if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) ) + return aResult; + ObjectKind aKind = KIND_UNKNOWN; // Retrieve the type of object from label @@ -83,7 +91,6 @@ Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label theLabel ) if ( aKind == KIND_UNKNOWN ) aKind = theLabel.Father().Tag(); // Try to get type from father label - Handle(HYDROData_Entity) aResult; switch( aKind ) { case KIND_IMAGE: diff --git a/src/HYDROData/HYDROData_Iterator.h b/src/HYDROData/HYDROData_Iterator.h index 64728dd2..409787fc 100644 --- a/src/HYDROData/HYDROData_Iterator.h +++ b/src/HYDROData/HYDROData_Iterator.h @@ -67,7 +67,7 @@ protected: /** * Returns object associated to the given label. */ - static Handle(HYDROData_Entity) Object(const TDF_Label theLabel); + static Handle(HYDROData_Entity) Object( const TDF_Label& theLabel ); TDF_ChildIDIterator myIter; ///< iterator by the objects in the document }; diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 7f4fae7a..10275833 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -7,8 +7,6 @@ #include -#include - #define PYTHON_REGION_ID "KIND_REGION" IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity) @@ -18,7 +16,6 @@ IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity) HYDROData_Region::HYDROData_Region() : HYDROData_Entity() { - SetMergeType( Merge_ZMIN ); } HYDROData_Region::~HYDROData_Region() @@ -56,69 +53,29 @@ QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjec return aResList; } -Handle(HYDROData_Zone) HYDROData_Region::AddNewZone() -{ - TDF_Label aNewLab = myLab.FindChild( ChildTag_Zone ).NewChild(); - - return Handle(HYDROData_Zone)::DownCast( - HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) ); -} - -void HYDROData_Region::RemoveChildZones() -{ - myLab.FindChild( ChildTag_Zone ).ForgetAllAttributes( true ); -} - -void HYDROData_Region::SetMergeType( const MergeBathymetriesType& theType ) +bool HYDROData_Region::AddZone( Handle(HYDROData_Zone)& theZone ) { - Handle(TDataStd_Integer) anInt; - if ( !myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) ) - anInt = TDataStd_Integer::Set( myLab, 0 ); - anInt->Set( (int)theType ); -} - -HYDROData_Region::MergeBathymetriesType HYDROData_Region::GetMergeType() const -{ - MergeBathymetriesType aMergeType = Merge_ZMIN; + if ( theZone.IsNull() ) + return false; - Handle(TDataStd_Integer) anInt; - if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) ) - aMergeType = (MergeBathymetriesType)anInt->Get(); - - return aMergeType; -} - -int HYDROData_Region::NbZones() const -{ - return NbReferenceObjects( DataTag_Zone ); -} - -void HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone ) -{ - AddReferenceObject( theZone, DataTag_Zone ); -} + if ( HasReference( theZone, DataTag_Zone ) ) + return false; // Object is already in reference list -void HYDROData_Region::SetZone( const int theIndex, - const Handle(HYDROData_Zone)& theZone ) -{ - SetReferenceObject( theZone, DataTag_Zone, theIndex ); -} + // 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 ); -void HYDROData_Region::InsertZone( const int theBeforeIndex, - const Handle(HYDROData_Zone)& theZone ) -{ - InsertReferenceObject( theZone, DataTag_Zone, theBeforeIndex ); -} + aFatherRegion->RemoveZone( theZone ); -void HYDROData_Region::SetZones( const HYDROData_SequenceOfObjects& theZones ) -{ - SetReferenceObjects( theZones, DataTag_Zone ); -} + theZone = aNewZone; + } -Handle(HYDROData_Zone) HYDROData_Region::GetZone( const int theIndex ) const -{ - return Handle(HYDROData_Zone)::DownCast( - GetReferenceObject( DataTag_Zone, theIndex ) ); + AddReferenceObject( theZone, DataTag_Zone ); + return true; } HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const @@ -128,20 +85,29 @@ HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone ) { - if ( theZone.IsNull() ) + if ( theZone.IsNull() || !HasReference( theZone, DataTag_Zone ) ) return; RemoveReferenceObject( theZone->Label(), DataTag_Zone ); -} -void HYDROData_Region::RemoveZone( const int theIndex ) -{ - RemoveReferenceObject( DataTag_Zone, theIndex ); + // Remove zone from data model + theZone->Remove(); } void HYDROData_Region::RemoveZones() { ClearReferenceObjects( DataTag_Zone ); + myLab.FindChild( ChildTag_Zone ).ForgetAllAttributes( true ); } +Handle(HYDROData_Zone) HYDROData_Region::AddNewZone() +{ + TDF_Label aNewLab = myLab.FindChild( ChildTag_Zone ).NewChild(); + + Handle(HYDROData_Zone) aNewZone = + Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) ); + AddZone( aNewZone ); + + return aNewZone; +} diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index e79f9394..6a4fd316 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -15,15 +15,6 @@ class Handle(HYDROData_Zone); class HYDROData_Region : public HYDROData_Entity { -public: - - // Enumeration of mergin types for conflict bathymetries - enum MergeBathymetriesType - { - Merge_ZMIN, - Merge_ZMAX - }; - protected: /** @@ -33,7 +24,6 @@ protected: { DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve DataTag_Zone, ///< reference zones - DataTag_MergeType, ///< mergin type of conflict bathymetries }; /** @@ -59,62 +49,10 @@ public: HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; - /** - * Create new one reference zone for region on child label. - * The new zone is not added into the list of reference zones. - */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) AddNewZone(); - - /** - * Removes all child zones from region. - */ - HYDRODATA_EXPORT virtual void RemoveChildZones(); - - - /** - * Sets the merging type for conflict bathymetries. - * By default it is set to Merge_ZMIN. - */ - HYDRODATA_EXPORT virtual void SetMergeType( const MergeBathymetriesType& theType ); - - /** - * Returns the merging type for conflict bathymetries. - */ - HYDRODATA_EXPORT virtual MergeBathymetriesType GetMergeType() const; - - - - /** - * Returns number of reference zones of region. - */ - int NbZones() const; - /** * Add new one reference zone for region. */ - HYDRODATA_EXPORT virtual void AddZone( const Handle(HYDROData_Zone)& theZone ); - - /** - * Replace the reference zone for region. - */ - HYDRODATA_EXPORT virtual void SetZone( const int theIndex, - const Handle(HYDROData_Zone)& theZone ); - - /** - * Inserts the reference zone for region before given index. - */ - HYDRODATA_EXPORT virtual void InsertZone( const int theBeforeIndex, - const Handle(HYDROData_Zone)& theZone ); - - /** - * Sets reference zones for calculation region. - */ - HYDRODATA_EXPORT virtual void SetZones( const HYDROData_SequenceOfObjects& theZones ); - - /** - * Returns reference zone of region by index. - */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZone( const int theIndex ) const; + HYDRODATA_EXPORT virtual bool AddZone( Handle(HYDROData_Zone)& theZone ); /** * Returns all reference zone of region. @@ -126,17 +64,20 @@ public: */ HYDRODATA_EXPORT virtual void RemoveZone( const Handle(HYDROData_Zone)& theZone ); - /** - * Removes reference zone from region by it index. - */ - HYDRODATA_EXPORT virtual void RemoveZone( const int theIndex ); - /** * Removes all reference zones from region. */ HYDRODATA_EXPORT virtual void RemoveZones(); +protected: + + /** + * Create new one reference zone for region on child label. + * The new zone is added into the list of reference zones. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) AddNewZone(); + protected: friend class HYDROData_Calculation; diff --git a/src/HYDROData/HYDROData_Zone.cxx b/src/HYDROData/HYDROData_Zone.cxx index 36b13d65..9a1ffbaf 100644 --- a/src/HYDROData/HYDROData_Zone.cxx +++ b/src/HYDROData/HYDROData_Zone.cxx @@ -1,8 +1,10 @@ #include "HYDROData_Zone.h" +#include "HYDROData_ArtificialObject.h" +#include "HYDROData_Bathymetry.h" #include "HYDROData_Document.h" -#include "HYDROData_Object.h" +#include "HYDROData_NaturalObject.h" #include #include @@ -11,6 +13,8 @@ #include +#include + #define PYTHON_ZONE_ID "KIND_ZONE" IMPLEMENT_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity) @@ -20,6 +24,7 @@ IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity) HYDROData_Zone::HYDROData_Zone() : HYDROData_Entity() { + SetMergeType( Merge_ZMIN ); } HYDROData_Zone::~HYDROData_Zone() @@ -73,31 +78,55 @@ TopoDS_Shape HYDROData_Zone::GetShape() const return TopoDS_Shape(); } -int HYDROData_Zone::NbGeometryObjects() const +void HYDROData_Zone::SetMergeType( const MergeBathymetriesType& theType ) { - return NbReferenceObjects( DataTag_GeometryObject ); + Handle(TDataStd_Integer) anInt; + if ( !myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) ) + anInt = TDataStd_Integer::Set( myLab, 0 ); + anInt->Set( (int)theType ); } -void HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject ) +HYDROData_Zone::MergeBathymetriesType HYDROData_Zone::GetMergeType() const { - AddReferenceObject( theObject, DataTag_GeometryObject ); + MergeBathymetriesType aMergeType = Merge_ZMIN; + + Handle(TDataStd_Integer) anInt; + if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) ) + aMergeType = (MergeBathymetriesType)anInt->Get(); + + return aMergeType; +} + +void HYDROData_Zone::SetMergeBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ) +{ + SetReferenceObject( theBathymetry, DataTag_Bathymetry ); } -void HYDROData_Zone::SetGeometryObject( const int theIndex, - const Handle(HYDROData_Object)& theObject ) +Handle(HYDROData_Bathymetry) HYDROData_Zone::GetMergeBathymetry() const { - SetReferenceObject( theObject, DataTag_GeometryObject, theIndex ); + return Handle(HYDROData_Bathymetry)::DownCast( + GetReferenceObject( DataTag_Bathymetry ) ); } -void HYDROData_Zone::SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ) +void HYDROData_Zone::RemoveMergeBathymetry() { - SetReferenceObjects( theObjects, DataTag_GeometryObject ); + ClearReferenceObjects( DataTag_Bathymetry ); } -Handle(HYDROData_Object) HYDROData_Zone::GetGeometryObject( const int theIndex ) const +bool HYDROData_Zone::AddGeometryObject( const Handle(HYDROData_Object)& theObject ) { - return Handle(HYDROData_Object)::DownCast( - GetReferenceObject( DataTag_GeometryObject, theIndex ) ); + if ( theObject.IsNull() ) + return false; + + if ( !theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) && + !theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ) ) + return false; // Wrong type of object + + if ( HasReference( theObject, DataTag_GeometryObject ) ) + return false; // Object is already in reference list + + AddReferenceObject( theObject, DataTag_GeometryObject ); + return true; } HYDROData_SequenceOfObjects HYDROData_Zone::GetGeometryObjects() const @@ -112,4 +141,3 @@ void HYDROData_Zone::RemoveGeometryObjects() - diff --git a/src/HYDROData/HYDROData_Zone.h b/src/HYDROData/HYDROData_Zone.h index 4ef2dd9c..eddee171 100644 --- a/src/HYDROData/HYDROData_Zone.h +++ b/src/HYDROData/HYDROData_Zone.h @@ -5,6 +5,7 @@ #include class Handle(HYDROData_Object); +class Handle(HYDROData_Bathymetry); class TopoDS_Shape; DEFINE_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity) @@ -16,6 +17,16 @@ DEFINE_STANDARD_HANDLE(HYDROData_Zone, HYDROData_Entity) class HYDROData_Zone : public HYDROData_Entity { +public: + + // Enumeration of mergin types for conflict bathymetries + enum MergeBathymetriesType + { + Merge_ZMIN, // The minimum values + Merge_ZMAX, // The maximum values + Merge_Object // Only one bathymetry will be taken into account + }; + protected: /** * Enumeration of tags corresponding to the persistent object parameters. @@ -23,8 +34,10 @@ protected: enum DataTag { DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve - DataTag_Shape, ///< reference shape - DataTag_GeometryObject, ///< reference geometry objects + DataTag_Shape, ///< reference shape + DataTag_GeometryObject, ///< reference geometry objects + DataTag_MergeType, ///< mergin type of conflict bathymetries + DataTag_Bathymetry, ///< reference bathymetry }; public: @@ -53,30 +66,38 @@ public: /** - * Returns number of geometry objects for zone. + * Sets the merging type for conflict bathymetries. + * By default it is set to Merge_ZMIN. */ - HYDRODATA_EXPORT virtual int NbGeometryObjects() const; + HYDRODATA_EXPORT virtual void SetMergeType( const MergeBathymetriesType& theType ); /** - * Add new one geometry object for zone. + * Returns the merging type for conflict bathymetries. */ - HYDRODATA_EXPORT virtual void AddGeometryObject( const Handle(HYDROData_Object)& theObject ); + HYDRODATA_EXPORT virtual MergeBathymetriesType GetMergeType() const; + /** - * Replace the geometry object for zone. + * Sets the reference bathymetry to resolve the conflict. + * This object is used only in case of "Merge_Object" merge type. */ - HYDRODATA_EXPORT virtual void SetGeometryObject( const int theIndex, - const Handle(HYDROData_Object)& theObject ); + HYDRODATA_EXPORT virtual void SetMergeBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry ); /** - * Sets the geometry object for zone. + * Returns the reference bathymetry to resolve the conflict. */ - HYDRODATA_EXPORT virtual void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); + HYDRODATA_EXPORT virtual Handle(HYDROData_Bathymetry) GetMergeBathymetry() const; /** - * Returns geometry object of zone by index. + * Removes the reference bathymetry for resolving the conflict. + */ + HYDRODATA_EXPORT virtual void RemoveMergeBathymetry(); + + + /** + * Add new one geometry object for zone. */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Object) GetGeometryObject( const int theIndex ) const; + HYDRODATA_EXPORT virtual bool AddGeometryObject( const Handle(HYDROData_Object)& theObject ); /** * Returns all geometry objects of zone. diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index ff036a4f..4ab01f72 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -165,8 +165,6 @@ bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags, HYDROData_SequenceOfObjects aGeomObjects = HYDROGUI_Tool::FindObjectsByNames( module(), aRefObjectNames ); - aCalculObj->SetGeometryObjects( aGeomObjects ); - theUpdateFlags = UF_Model; return true; diff --git a/src/HYDROPy/HYDROData_Calculation.sip b/src/HYDROPy/HYDROData_Calculation.sip index f03984b4..18264de0 100644 --- a/src/HYDROPy/HYDROData_Calculation.sip +++ b/src/HYDROPy/HYDROData_Calculation.sip @@ -24,7 +24,7 @@ #include %End -class HYDROData_Calculation : HYDROData_Object +class HYDROData_Calculation : HYDROData_Entity { %TypeHeaderCode @@ -74,47 +74,6 @@ public: %End - /** - * Replace the geometry object for calculation case. - */ - void SetGeometryObject( const int theIndex, - HYDROData_Object theObject ) [void (const int, const Handle_HYDROData_Object&)]; - %MethodCode - - Handle(HYDROData_Object) aGeomObj = - Handle(HYDROData_Object)::DownCast( createHandle( a1 ) ); - if ( !aGeomObj.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Calculation::SetGeometryObject( a0, aGeomObj ) : - sipCpp->SetGeometryObject( a0, aGeomObj ); - Py_END_ALLOW_THREADS - } - - %End - - /** - * Sets the geometry object for calculation case. - */ - //void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); - - /** - * Returns geometry object of calculation case by index. - */ - HYDROData_Object GetGeometryObject( const int theIndex ) const [Handle_HYDROData_Object (const int)]; - %MethodCode - - Handle(HYDROData_Object) aGeomObj; - - Py_BEGIN_ALLOW_THREADS - aGeomObj = sipSelfWasArg ? sipCpp->HYDROData_Calculation::GetGeometryObject( a0 ) : - sipCpp->GetGeometryObject( a0 ); - Py_END_ALLOW_THREADS - - sipRes = (HYDROData_Object*)createPointer( aGeomObj ); - - %End - /** * Returns all geometry objects of calculation case. */ @@ -128,7 +87,7 @@ public: /** * Add new one region for calculation case. - * The new region is not added into the list of reference regions. + * The new region is added into the list of reference regions. */ HYDROData_Region AddNewRegion() [Handle_HYDROData_Region ()]; %MethodCode @@ -144,16 +103,6 @@ public: %End - /** - * Removes all child regions from calculation case. - */ - void RemoveChildRegions(); - - - /** - * Returns number of reference regions for calculation case. - */ - int NbRegions() const; /** * Add new one reference region for calculation case. @@ -173,66 +122,6 @@ public: %End - /** - * Replace the reference region for calculation case. - */ - void SetRegion( const int theIndex, - HYDROData_Region theRegion ) [void (const int, const Handle_HYDROData_Region&)]; - %MethodCode - - Handle(HYDROData_Region) aRegion = - Handle(HYDROData_Region)::DownCast( createHandle( a1 ) ); - if ( !aRegion.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Calculation::SetRegion( a0, aRegion ) : - sipCpp->SetRegion( a0, aRegion ); - Py_END_ALLOW_THREADS - } - - %End - - /** - * Inserts the reference region for calculation case before given index. - */ - void InsertRegion( const int theBeforeIndex, - HYDROData_Region theRegion ) [void (const int, const Handle_HYDROData_Region&)]; - %MethodCode - - Handle(HYDROData_Region) aRegion = - Handle(HYDROData_Region)::DownCast( createHandle( a1 ) ); - if ( !aRegion.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Calculation::InsertRegion( a0, aRegion ) : - sipCpp->InsertRegion( a0, aRegion ); - Py_END_ALLOW_THREADS - } - - %End - - /** - * Sets reference regions for calculation case. - */ - //void SetRegions( const HYDROData_SequenceOfObjects& theRegions ); - - /** - * Returns reference region of calculation case by index. - */ - HYDROData_Region GetRegion( const int theIndex ) const [Handle_HYDROData_Region (const int)]; - %MethodCode - - Handle(HYDROData_Region) aRefRegion; - - Py_BEGIN_ALLOW_THREADS - aRefRegion = sipSelfWasArg ? sipCpp->HYDROData_Calculation::GetRegion( a0 ) : - sipCpp->GetRegion( a0 ); - Py_END_ALLOW_THREADS - - sipRes = (HYDROData_Region*)createPointer( aRefRegion ); - - %End - /** * Returns all reference regions of calculation case. */ @@ -256,11 +145,6 @@ public: %End - /** - * Removes region from calculation case by it index. - */ - void RemoveRegion( const int theIndex ); - /** * Removes all reference regions from calculation case. */ diff --git a/src/HYDROPy/HYDROData_Region.sip b/src/HYDROPy/HYDROData_Region.sip index 5566811b..0f228ff4 100644 --- a/src/HYDROPy/HYDROData_Region.sip +++ b/src/HYDROPy/HYDROData_Region.sip @@ -44,58 +44,8 @@ class HYDROData_Region : HYDROData_Entity } %End -public: - - // Enumeration of mergin types for conflict bathymetries - enum MergeBathymetriesType - { - Merge_ZMIN, - Merge_ZMAX - }; - public: - /** - * Create new one reference zone for region on child label. - * The new zone is not added into the list of reference zones. - */ - HYDROData_Zone AddNewZone() [Handle_HYDROData_Zone ()]; - %MethodCode - - Handle(HYDROData_Zone) aNewZone; - - Py_BEGIN_ALLOW_THREADS - aNewZone = sipSelfWasArg ? sipCpp->HYDROData_Region::AddNewZone() : - sipCpp->AddNewZone(); - Py_END_ALLOW_THREADS - - sipRes = (HYDROData_Zone*)createPointer( aNewZone ); - - %End - - /** - * Removes all child zones from region. - */ - void RemoveChildZones(); - - - /** - * Sets the merging type for conflict bathymetries. - * By default it is set to Merge_ZMIN. - */ - void SetMergeType( const MergeBathymetriesType& theType ); - - /** - * Returns the merging type for conflict bathymetries. - */ - MergeBathymetriesType GetMergeType() const; - - - /** - * Returns number of reference zones of region. - */ - int NbZones() const; - /** * Add new one reference zone for region. */ @@ -114,66 +64,6 @@ public: %End - /** - * Replace the reference zone for region. - */ - void SetZone( const int theIndex, - HYDROData_Zone theZone ) [void (const int, const Handle_HYDROData_Zone&)]; - %MethodCode - - Handle(HYDROData_Zone) aZone = - Handle(HYDROData_Zone)::DownCast( createHandle( a1 ) ); - if ( !aZone.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Region::SetZone( a0, aZone ) : - sipCpp->SetZone( a0, aZone ); - Py_END_ALLOW_THREADS - } - - %End - - /** - * Inserts the reference zone for region before given index. - */ - void InsertZone( const int theBeforeIndex, - HYDROData_Zone theZone ) [void (const int, const Handle_HYDROData_Zone&)]; - %MethodCode - - Handle(HYDROData_Zone) aZone = - Handle(HYDROData_Zone)::DownCast( createHandle( a1 ) ); - if ( !aZone.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Region::InsertZone( a0, aZone ) : - sipCpp->InsertZone( a0, aZone ); - Py_END_ALLOW_THREADS - } - - %End - - /** - * Sets reference zones for calculation region. - */ - //void SetZones( const HYDROData_SequenceOfObjects& theZones ); - - /** - * Returns reference zone of region by index. - */ - HYDROData_Zone GetZone( const int theIndex ) const [Handle_HYDROData_Zone (const int)]; - %MethodCode - - Handle(HYDROData_Zone) aRefZone; - - Py_BEGIN_ALLOW_THREADS - aRefZone = sipSelfWasArg ? sipCpp->HYDROData_Region::GetZone( a0 ) : - sipCpp->GetZone( a0 ); - Py_END_ALLOW_THREADS - - sipRes = (HYDROData_Zone*)createPointer( aRefZone ); - - %End - /** * Returns all reference zone of region. */ @@ -197,11 +87,6 @@ public: %End - /** - * Removes reference zone from region by it index. - */ - void RemoveZone( const int theIndex ); - /** * Removes all reference zones from region. */ diff --git a/src/HYDROPy/HYDROData_Zone.sip b/src/HYDROPy/HYDROData_Zone.sip index e70baae0..4b28e6d8 100644 --- a/src/HYDROPy/HYDROData_Zone.sip +++ b/src/HYDROPy/HYDROData_Zone.sip @@ -44,72 +44,90 @@ class HYDROData_Zone : HYDROData_Entity } %End +public: + + // Enumeration of mergin types for conflict bathymetries + enum MergeBathymetriesType + { + Merge_ZMIN, // The minimum values + Merge_ZMAX, // The maximum values + Merge_Object // Only one bathymetry will be taken into account + }; + public: /** - * Returns number of geometry objects for zone. + * Sets the merging type for conflict bathymetries. + * By default it is set to Merge_ZMIN. */ - int NbGeometryObjects() const; + void SetMergeType( const MergeBathymetriesType& theType ); /** - * dd new one geometry object for zone. + * Returns the merging type for conflict bathymetries. */ - void AddGeometryObject( HYDROData_Object theRegion ) [void (const Handle_HYDROData_Object&)]; - %MethodCode - - Handle(HYDROData_Object) aGeomObj = - Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); - if ( !aGeomObj.IsNull() ) - { - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Zone::AddGeometryObject( aGeomObj ) : - sipCpp->AddGeometryObject( aGeomObj ); - Py_END_ALLOW_THREADS - } + MergeBathymetriesType GetMergeType() const; - %End /** - * Replace the geometry object for zone. + * Sets the reference bathymetry to resolve the conflict. + * This object is used only in case of "Merge_Object" merge type. */ - void SetGeometryObject( const int theIndex, - HYDROData_Object theObject ) [void (const int, const Handle_HYDROData_Object&)]; + void SetMergeBathymetry( HYDROData_Bathymetry theBathymetry ) [void (const Handle_HYDROData_Bathymetry&)]; %MethodCode - Handle(HYDROData_Object) aGeomObj = - Handle(HYDROData_Object)::DownCast( createHandle( a1 ) ); - if ( !aGeomObj.IsNull() ) + Handle(HYDROData_Bathymetry) aRefBath = + Handle(HYDROData_Bathymetry)::DownCast( createHandle( a0 ) ); + if ( !aRefBath.IsNull() ) { Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Zone::SetGeometryObject( a0, aGeomObj ) : - sipCpp->SetGeometryObject( a0, aGeomObj ); + sipSelfWasArg ? sipCpp->HYDROData_Zone::SetMergeBathymetry( aRefBath ) : + sipCpp->SetMergeBathymetry( aRefBath ); Py_END_ALLOW_THREADS } %End /** - * Sets the geometry object for zone. + * Returns the reference bathymetry to resolve the conflict. */ - //void SetGeometryObjects( const HYDROData_SequenceOfObjects& theObjects ); - - /** - * Returns geometry object of zone by index. - */ - HYDROData_Object GetGeometryObject( const int theIndex ) const [Handle_HYDROData_Object (const int)]; + HYDROData_Bathymetry GetMergeBathymetry() const [Handle_HYDROData_Bathymetry ()]; %MethodCode - Handle(HYDROData_Object) aGeomObj; + Handle(HYDROData_Bathymetry) aRefBath; Py_BEGIN_ALLOW_THREADS - aGeomObj = sipSelfWasArg ? sipCpp->HYDROData_Zone::GetGeometryObject( a0 ) : - sipCpp->GetGeometryObject( a0 ); + aRefBath = sipSelfWasArg ? sipCpp->HYDROData_Zone::GetMergeBathymetry() : + sipCpp->GetMergeBathymetry(); Py_END_ALLOW_THREADS - sipRes = (HYDROData_Object*)createPointer( aGeomObj ); + sipRes = (HYDROData_Bathymetry*)createPointer( aRefBath ); %End + /** + * Removes the reference bathymetry for resolving the conflict. + */ + void RemoveMergeBathymetry(); + + + /** + * dd new one geometry object for zone. + */ + void AddGeometryObject( HYDROData_Object theRegion ) [void (const Handle_HYDROData_Object&)]; + %MethodCode + + Handle(HYDROData_Object) aGeomObj = + Handle(HYDROData_Object)::DownCast( createHandle( a0 ) ); + if ( !aGeomObj.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_Zone::AddGeometryObject( aGeomObj ) : + sipCpp->AddGeometryObject( aGeomObj ); + Py_END_ALLOW_THREADS + } + + %End + /** * Returns all geometry objects of zone. */ -- 2.39.2