From: adv Date: Thu, 21 Nov 2013 12:21:08 +0000 (+0000) Subject: Update the names of Regions and Zones if case name changed (Bug #110). X-Git-Tag: BR_hydro_v_0_3_1~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ad8562bab9992101430a6327aa7ca06c71f6d084;p=modules%2Fhydro.git Update the names of Regions and Zones if case name changed (Bug #110). --- diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 301d043b..52599029 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -34,6 +34,50 @@ HYDROData_CalculationCase::~HYDROData_CalculationCase() { } +void HYDROData_CalculationCase::SetName( const QString& theName ) +{ + QString anOldCaseName = GetName(); + if ( anOldCaseName != theName ) + { + 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; + + QString aRegionName = aRegion->GetName(); + if ( aRegionName.startsWith( anOldCaseName ) ) + { + aRegionName.replace( anOldCaseName, theName ); + aRegion->SetName( aRegionName ); + } + + HYDROData_SequenceOfObjects aZones = aRegion->GetZones(); + HYDROData_SequenceOfObjects::Iterator anIter( aZones ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Zone) aRegZone = + Handle(HYDROData_Zone)::DownCast( anIter.Value() ); + if ( aRegZone.IsNull() ) + continue; + + QString aRegionZoneName = aRegZone->GetName(); + if ( aRegionZoneName.startsWith( anOldCaseName ) ) + { + aRegionZoneName.replace( anOldCaseName, theName ); + aRegZone->SetName( aRegionZoneName ); + } + } + } + } + + HYDROData_Entity::SetName( theName ); +} + QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList; diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 2b471335..1b6d4bfb 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -45,6 +45,11 @@ public: */ HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_CALCULATION; } + /** + * Updates the name of this object. + * Reimplemented to update the names of regions and zones. + */ + HYDRODATA_EXPORT virtual void SetName( const QString& theName ); /** * Dump Calculation object to Python script representation. diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index 3fb5d239..0df866a8 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -80,12 +80,12 @@ public: /** * Returns the name of this object. */ - HYDRODATA_EXPORT QString GetName() const; + HYDRODATA_EXPORT virtual QString GetName() const; /** * Updates the name of this object. */ - HYDRODATA_EXPORT void SetName(const QString& theName); + HYDRODATA_EXPORT virtual void SetName( const QString& theName ); /** * Dump object to Python script representation. @@ -110,7 +110,7 @@ public: * Sets the "MustBeUpdated" flag: if object is depended on updated features. * \param theFlag is true for objects that must be updated, false for up-to-date */ - HYDRODATA_EXPORT void SetToUpdate(bool theFlag); + HYDRODATA_EXPORT void SetToUpdate( bool theFlag ); /** * Returns the "MustBeUpdated" flag: is object data must be updated or not @@ -132,19 +132,19 @@ public: /** * Returns unique integer identifier of the object (may be used for ordering of objects) */ - HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();} + HYDRODATA_EXPORT inline int ID() const { return myLab.Tag(); } /** * Copies all properties of this to the destinated object. * Objects must be the same type. * \param theDestination initialized object (from any document) - target of copying */ - HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Entity theDestination) const; + HYDRODATA_EXPORT void CopyTo( Handle_HYDROData_Entity theDestination ) const; /** * Returns the label of this object. */ - HYDRODATA_EXPORT TDF_Label& Label() {return myLab;} + HYDRODATA_EXPORT TDF_Label& Label() { return myLab; } /** * Returns father object. For object created under root document label diff --git a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx index 50575d88..8e3e404f 100644 --- a/src/HYDROGUI/HYDROGUI_CalculationOp.cxx +++ b/src/HYDROGUI/HYDROGUI_CalculationOp.cxx @@ -555,19 +555,28 @@ void HYDROGUI_CalculationOp::onApply() void HYDROGUI_CalculationOp::onSplitZones() { + HYDROGUI_CalculationDlg* aPanel = + ::qobject_cast( inputPanel() ); + if ( !aPanel ) + return; + QApplication::setOverrideCursor( Qt::WaitCursor ); + QString aNewCaseName = aPanel->getObjectName(); + QString anOldCaseName = myEditedObject->GetName(); + + bool anIsToUpdateOb = myIsEdit && anOldCaseName != aNewCaseName; + + // At first we must to update the case name because of + // automatic names generation for regions and zones + myEditedObject->SetName( aNewCaseName ); + if ( myEditedObject->IsMustBeUpdated() ) { myShowZones = true; myEditedObject->SplitGeometryObjects(); - HYDROGUI_CalculationDlg* aPanel = - ::qobject_cast( inputPanel() ); - if ( aPanel ) - { - aPanel->setEditedObject( myEditedObject ); - } + aPanel->setEditedObject( myEditedObject ); createPreview(); } @@ -576,6 +585,9 @@ void HYDROGUI_CalculationOp::onSplitZones() setZonesVisible( true ); } + if ( anIsToUpdateOb ) + module()->getApp()->updateObjectBrowser( false ); + QApplication::restoreOverrideCursor(); }