From: mkr Date: Mon, 16 Nov 2015 16:27:20 +0000 (+0300) Subject: refs #687, #692 - #695: fix fatal errors. X-Git-Tag: v1.5~39 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b28b1d73607de9646566b9978d02834918d228fa;p=modules%2Fhydro.git refs #687, #692 - #695: fix fatal errors. --- diff --git a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx index 78ab4dec..deafdfff 100644 --- a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx @@ -168,4 +168,6 @@ void HYDROGUI_DeleteOp::startOperation() module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer ); commit(); + + module()->enableLCMActions(); } diff --git a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx index 2ee43916..777ebf39 100644 --- a/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx +++ b/src/HYDROGUI/HYDROGUI_LandCoverMapOp.cxx @@ -102,24 +102,37 @@ void HYDROGUI_LandCoverMapOp::startOperation() { if ( isApplyAndClose() ) myEditedObject = Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - if ( !myEditedObject.IsNull() ) + + // Construct a list of names of all land cover map objects defined within the data model + QStringList aLandCoverMapNames; + HYDROData_Iterator anIterator( doc(), KIND_LAND_COVER_MAP ); + for( ; anIterator.More(); anIterator.Next() ) { - anObjectName = myEditedObject->GetName(); + Handle(HYDROData_LandCoverMap) aLandCoverObj = + Handle(HYDROData_LandCoverMap)::DownCast( anIterator.Current() ); + if ( !aLandCoverObj.IsNull() ) + aLandCoverMapNames.append( aLandCoverObj->GetName() ); + } + + //aLandCoverMapNames.sort(); + aPanel->setObjectNames( aLandCoverMapNames ); - // Construct a list of names of all land cover map objects defined within the data model - QStringList aLandCoverMapNames; - HYDROData_Iterator anIterator( doc(), KIND_LAND_COVER_MAP ); - for( ; anIterator.More(); anIterator.Next() ) + if ( myEditedObject.IsNull() ) + { + if ( !aLandCoverMapNames.empty() ) { - Handle(HYDROData_LandCoverMap) aLandCoverObj = - Handle(HYDROData_LandCoverMap)::DownCast( anIterator.Current() ); - if ( !aLandCoverObj.IsNull() ) - aLandCoverMapNames.append( aLandCoverObj->GetName() ); + anObjectName = aLandCoverMapNames.first(); + if ( !anObjectName.isEmpty()) + { + Handle(HYDROData_LandCoverMap) anObject = + Handle(HYDROData_LandCoverMap)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), anObjectName ) ); + if( !anObject.IsNull() ) + myEditedObject = anObject; + } } - - //aLandCoverMapNames.sort(); - aPanel->setObjectNames( aLandCoverMapNames ); } + else + anObjectName = myEditedObject->GetName(); } aPanel->setObjectName( anObjectName ); @@ -233,6 +246,11 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, // Create / find the new / edited land cover map object Handle(HYDROData_LandCoverMap) aLandCoverMapObj = myOperationId != CreateLandCoverMapId ? myEditedObject : Handle(HYDROData_LandCoverMap)::DownCast( doc()->CreateObject( KIND_LAND_COVER_MAP ) ); + if ( aLandCoverMapObj.IsNull() ) + { + theErrorMsg = tr( "LAND_COVER_MAP_UNDEFINED" ); + return false; + } // Set land cover map name aLandCoverMapObj->SetName( anObjectName ); @@ -346,6 +364,9 @@ bool HYDROGUI_LandCoverMapOp::processApply( int& theUpdateFlags, theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; + if ( myOperationId == CreateLandCoverMapId ) + module()->enableLCMActions(); + return true; } @@ -417,7 +438,7 @@ void HYDROGUI_LandCoverMapOp::onCreatePreview() } } - if ( aViewManager && myPreviewPrs ) + if ( aViewManager && myPreviewPrs && !myEditedObject.IsNull() ) { TopoDS_Shape aLandCoverMapShape = myEditedObject->GetShape(); if( !aLandCoverMapShape.IsNull() ) diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 1b3523f1..8780c389 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -253,6 +253,8 @@ public: */ void setObjectRemoved( const Handle(HYDROData_Entity)& theObject ); + void enableLCMActions(); + protected: CAM_DataModel* createDataModel(); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index e15ed250..aa689a83 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -75,6 +75,7 @@ #include #include #include +#include #include #include @@ -355,6 +356,7 @@ void HYDROGUI_Module::createToolbars() createTool( SplitLandCoverId, aToolBar ); createTool( MergeLandCoverId, aToolBar ); createTool( ChangeLandCoverTypeId, aToolBar ); + enableLCMActions(); createTool( separator(), aToolBar ); createTool( CreateCalculationId, aToolBar ); @@ -406,6 +408,24 @@ void HYDROGUI_Module::updateUndoRedoControls() aRedoAction->setEnabled( aCanRedo ); } +void HYDROGUI_Module::enableLCMActions() +{ + HYDROData_Iterator anIt( HYDROData_Document::Document( getStudyId() ), KIND_LAND_COVER_MAP ); + bool anEnableTools = anIt.More(); + + QtxListAction* anAction; + anAction = (QtxListAction*)action( AddLandCoverId ); + if ( anAction ) anAction->setEnabled( anEnableTools ); + anAction = (QtxListAction*)action( RemoveLandCoverId ); + if ( anAction ) anAction->setEnabled( anEnableTools ); + anAction = (QtxListAction*)action( SplitLandCoverId ); + if ( anAction ) anAction->setEnabled( anEnableTools ); + anAction = (QtxListAction*)action( MergeLandCoverId ); + if ( anAction ) anAction->setEnabled( anEnableTools ); + anAction = (QtxListAction*)action( ChangeLandCoverTypeId ); + if ( anAction ) anAction->setEnabled( anEnableTools ); +} + void HYDROGUI_Module::onOperation() { const QAction* anAction = dynamic_cast( sender() ); diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 0a58c3f6..189f87a3 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2936,6 +2936,10 @@ Polyline should consist from one not closed curve. STRICKLER_TYPE_NOT_DEFINED Strickler type should be defined. + + LAND_COVER_MAP_UNDEFINED + Land cover map is undefined. + LAND_COVER_NOT_ADDED Land cover can not be added.