From a735d3579cae0b95c56436cae00b09473a2b85db Mon Sep 17 00:00:00 2001 From: ouv Date: Tue, 17 Sep 2013 13:44:29 +0000 Subject: [PATCH] Bug 23: popup menu. --- src/HYDROData/HYDROData_Object.h | 1 + src/HYDROGUI/HYDROGUI_DataModel.cxx | 24 +++++++-- src/HYDROGUI/HYDROGUI_DataModel.h | 11 +++- src/HYDROGUI/HYDROGUI_Module.cxx | 62 ++++++++++++++++++----- src/HYDROGUI/HYDROGUI_ObjSelector.cxx | 5 ++ src/HYDROGUI/HYDROGUI_ObjSelector.h | 1 + src/HYDROGUI/HYDROGUI_Operations.cxx | 3 +- src/HYDROGUI/HYDROGUI_Tool.cxx | 27 ++++++++++ src/HYDROGUI/HYDROGUI_Tool.h | 7 +++ src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx | 9 ++++ src/HYDROGUI/HYDROGUI_TwoImagesDlg.h | 2 + src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx | 10 ++++ src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 30 +++++------ 13 files changed, 156 insertions(+), 36 deletions(-) diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index 04e83ed9..5d43cdde 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -26,6 +26,7 @@ const ObjectKind KIND_PROFILE = 6; const ObjectKind KIND_PROFILES_GROUP = 7; const ObjectKind KIND_GUIDE_LINE = 8; const ObjectKind KIND_ZONE = 9; +const ObjectKind KIND_LAST = KIND_ZONE; DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared) diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index e9462628..392dfef5 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -219,7 +219,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) if( aDocument.IsNull() ) return; - LightApp_DataObject* anImageRootObj = createObject( aRootObj, "IMAGES" ); + LightApp_DataObject* anImageRootObj = createObject( aRootObj, partitionName( KIND_IMAGE ) ); HYDROData_Iterator anIterator( aDocument, KIND_IMAGE ); for( ; anIterator.More(); anIterator.Next() ) @@ -240,7 +240,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) } } - LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, "BATHYMETRIES" ); + LightApp_DataObject* aBathymetryRootObj = createObject( aRootObj, partitionName( KIND_BATHYMETRY ) ); anIterator = HYDROData_Iterator( aDocument, KIND_BATHYMETRY ); for( ; anIterator.More(); anIterator.Next() ) @@ -251,7 +251,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) createObject( aBathymetryRootObj, aBathymetryObj ); } - LightApp_DataObject* aCalculRootObj = createObject( aRootObj, "CALCULATION CASES" ); + LightApp_DataObject* aCalculRootObj = createObject( aRootObj, partitionName( KIND_CALCULATION ) ); anIterator = HYDROData_Iterator( aDocument, KIND_CALCULATION ); for( ; anIterator.More(); anIterator.Next() ) @@ -262,7 +262,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) createObject( aCalculRootObj, aCalculObj ); } - LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, "POLYLINES" ); + LightApp_DataObject* aPolylineRootObj = createObject( aRootObj, partitionName( KIND_POLYLINE ) ); anIterator = HYDROData_Iterator( aDocument, KIND_POLYLINE ); for( ; anIterator.More(); anIterator.Next() ) @@ -273,7 +273,7 @@ void HYDROGUI_DataModel::update( const int theStudyId ) createObject( aPolylineRootObj, aPolylineObj ); } - LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, "VISUAL_STATES" ); + LightApp_DataObject* aVisualStateRootObj = createObject( aRootObj, partitionName( KIND_VISUAL_STATE ) ); anIterator = HYDROData_Iterator( aDocument, KIND_VISUAL_STATE ); for( ; anIterator.More(); anIterator.Next() ) @@ -497,6 +497,20 @@ void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects myCopyingObjects.Assign( theSeq ); } +QString HYDROGUI_DataModel::partitionName( const ObjectKind theObjectKind ) +{ + switch( theObjectKind ) + { + case KIND_IMAGE: return "IMAGES"; + case KIND_POLYLINE: return "POLYLINES"; + case KIND_VISUAL_STATE: return "VISUAL_STATES"; + case KIND_BATHYMETRY: return "BATHYMETRIES"; + case KIND_CALCULATION: return "CALCULATION_CASES"; + default: break; + } + return QString(); +} + Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const { int aStudyId = module()->application()->activeStudy()->id(); diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 9c1ff225..3576a1a0 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -109,14 +109,14 @@ public: /** * Returns data object corresponding to the model object. * \param the data model object - * \returns the only one object referenced to the given data model object, or null if not found + * \return the only one object referenced to the given data model object, or null if not found */ virtual HYDROGUI_DataObject* getDataObject( const Handle(HYDROData_Object)& theModelObject ); /** * Returns a data object referenced to the given data object. * \param the data object - * \returns the object referenced to the given object, or null if not found + * \return the object referenced to the given object, or null if not found */ virtual HYDROGUI_DataObject* getReferencedDataObject( HYDROGUI_DataObject* theObject ); @@ -215,6 +215,13 @@ public: */ static void changeCopyingObjects( const HYDROData_SequenceOfObjects& ); + /** + * Returns name of the partition containing the objects of the specified kind + * \param theObjectKind kind of objects + * \return partition name + */ + static QString partitionName( const ObjectKind theObjectKind ); + protected: /** * Returns the document for the current study diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 28f98579..6ce7fa53 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -173,9 +173,14 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { HYDROGUI_DataModel* aModel = getDataModel(); + bool anIsObjectBrowser = theClient == "ObjectBrowser"; + bool anIsGraphicsView = theClient == "GraphicsView"; + if( !anIsObjectBrowser && !anIsGraphicsView ) + return; + size_t aViewId = HYDROGUI_Tool::GetActiveGraphicsViewId( this ); - bool anIsSelection = false; + bool anIsSelectedDataObjects = false; bool anIsVisibleInSelection = false; bool anIsHiddenInSelection = false; @@ -190,13 +195,14 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, bool anIsCalculation = false; bool anIsVisualState = false; + // check the selected data model objects HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this ); for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { Handle(HYDROData_Object) anObject = aSeq.Value( anIndex ); if( !anObject.IsNull() ) { - anIsSelection = true; + anIsSelectedDataObjects = true; bool aVisibility = isObjectVisible( aViewId, anObject ); anIsVisibleInSelection |= aVisibility; @@ -235,19 +241,41 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, } } - if( aSeq.IsEmpty() ) + // check the selected partitions + if( !anIsSelectedDataObjects && anIsObjectBrowser ) { - theMenu->addAction( action( SaveVisualStateId ) ); - theMenu->addSeparator(); + ObjectKind aSelectedPartition = HYDROGUI_Tool::GetSelectedPartition( this ); + if( aSelectedPartition != KIND_UNKNOWN ) + { + switch( aSelectedPartition ) + { + case KIND_IMAGE: + theMenu->addAction( action( ImportImageId ) ); + break; + case KIND_POLYLINE: + theMenu->addAction( action( CreatePolylineId ) ); + break; + case KIND_VISUAL_STATE: + theMenu->addAction( action( SaveVisualStateId ) ); + break; + case KIND_BATHYMETRY: + theMenu->addAction( action( ImportBathymetryId ) ); + break; + case KIND_CALCULATION: + theMenu->addAction( action( CreateCalculationId ) ); + break; + } + theMenu->addSeparator(); + } } - if( anIsSelection && anIsMustBeUpdatedImage ) + if( anIsSelectedDataObjects && anIsMustBeUpdatedImage ) { theMenu->addAction( action( UpdateImageId ) ); theMenu->addSeparator(); } - if( anIsSelection && aSeq.Length() == 1 ) + if( anIsSelectedDataObjects && aSeq.Length() == 1 ) { if( anIsImage ) { @@ -266,6 +294,11 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( ObserveImageId ) ); theMenu->addAction( action( ExportImageId ) ); theMenu->addSeparator(); + + theMenu->addAction( action( FuseImagesId ) ); + theMenu->addAction( action( CutImagesId ) ); + theMenu->addAction( action( SplitImageId ) ); + theMenu->addSeparator(); } else if( anIsPolyline ) { @@ -277,7 +310,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addAction( action( EditCalculationId ) ); theMenu->addSeparator(); } - else if( anIsVisualState ) + else if( anIsVisualState && anIsObjectBrowser ) { theMenu->addAction( action( SaveVisualStateId ) ); theMenu->addAction( action( LoadVisualStateId ) ); @@ -285,13 +318,13 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, } } - if( anIsSelection ) + if( anIsSelectedDataObjects ) { theMenu->addAction( action( DeleteId ) ); theMenu->addSeparator(); } - if( anIsSelection && ( anIsImage || anIsPolyline ) ) + if( anIsSelectedDataObjects && ( anIsImage || anIsPolyline ) ) { if( anIsHiddenInSelection ) theMenu->addAction( action( ShowId ) ); @@ -301,9 +334,12 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, theMenu->addSeparator(); } - theMenu->addAction( action( ShowAllId ) ); - theMenu->addAction( action( HideAllId ) ); - theMenu->addSeparator(); + if( anIsObjectBrowser || anIsGraphicsView ) + { + theMenu->addAction( action( ShowAllId ) ); + theMenu->addAction( action( HideAllId ) ); + theMenu->addSeparator(); + } } void HYDROGUI_Module::update( const int flags ) diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx index f97212a0..a79c1f6b 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx @@ -122,3 +122,8 @@ void HYDROGUI_ObjSelector::Clear() myObjName->clear(); myBtn->setChecked( false ); } + +void HYDROGUI_ObjSelector::SetChecked( const bool theState ) +{ + myBtn->setChecked( theState ); +} diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.h b/src/HYDROGUI/HYDROGUI_ObjSelector.h index ba1ff514..717d7001 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.h +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.h @@ -42,6 +42,7 @@ public: virtual ~HYDROGUI_ObjSelector(); void Clear(); + void SetChecked( const bool ); void SetName( const QString& ); QString GetName() const; diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 08dc8a38..544d124d 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -84,7 +84,7 @@ void HYDROGUI_Module::createActions() createAction( CreatePolylineId, "CREATE_POLYLINE" ); createAction( EditPolylineId, "EDIT_POLYLINE" ); - createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::SHIFT + Qt::Key_I ); + createAction( ImportBathymetryId, "IMPORT_BATHYMETRY", "", Qt::CTRL + Qt::Key_B ); createAction( CreateCalculationId, "CREATE_CALCULATION" ); createAction( EditCalculationId, "EDIT_CALCULATION" ); @@ -127,6 +127,7 @@ void HYDROGUI_Module::createMenus() createMenu( ImportBathymetryId, aHydroId, -1, -1 ); createMenu( CreatePolylineId, aHydroId, -1, -1 ); createMenu( CreateCalculationId, aHydroId, -1, -1 ); + createMenu( separator(), aHydroId ); createMenu( FuseImagesId, aHydroId, -1, -1 ); createMenu( CutImagesId, aHydroId, -1, -1 ); createMenu( SplitImageId, aHydroId, -1, -1 ); diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 29d053f0..e030e1db 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -23,6 +23,7 @@ #include "HYDROGUI_Tool.h" #include "HYDROGUI_DataModel.h" +#include "HYDROGUI_DataObject.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Prs.h" @@ -265,6 +266,32 @@ Handle(HYDROData_Object) HYDROGUI_Tool::GetSelectedObject( HYDROGUI_Module* theM return NULL; } +ObjectKind HYDROGUI_Tool::GetSelectedPartition( HYDROGUI_Module* theModule ) +{ + HYDROGUI_DataModel* aModel = theModule->getDataModel(); + + SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr(); + SUIT_DataOwnerPtrList anOwners; + aSelectionMgr->selected( anOwners ); + + if( anOwners.size() != 1 ) + return KIND_UNKNOWN; + + if( LightApp_DataOwner* anOwner = dynamic_cast( anOwners.first().operator->() ) ) + { + QString anEntry = anOwner->entry(); + QString aPrefix = HYDROGUI_DataObject::entryPrefix(); + if( anEntry.left( aPrefix.length() ) == aPrefix ) + { + anEntry.remove( aPrefix ); + for( ObjectKind anObjectKind = KIND_UNKNOWN + 1; anObjectKind <= KIND_LAST; anObjectKind++ ) + if( HYDROGUI_DataModel::partitionName( anObjectKind ) == anEntry ) + return anObjectKind; + } + } + return KIND_UNKNOWN; +} + Handle(HYDROData_Object) HYDROGUI_Tool::FindObjectByName( HYDROGUI_Module* theModule, const QString& theName, const ObjectKind theObjectKind ) diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 7c959d85..c2552ddc 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -158,6 +158,13 @@ public: */ static Handle(HYDROData_Object) GetSelectedObject( HYDROGUI_Module* theModule ); + /** + * \brief Get kind of objects the selected partition contains. + * \param theModule module + * \return object kind + */ + static ObjectKind GetSelectedPartition( HYDROGUI_Module* theModule ); + /** * \brief Find the data object with the specified name. * \param theModule module diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx index 5a80d9e2..4ed15020 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.cxx @@ -169,6 +169,15 @@ bool HYDROGUI_TwoImagesDlg::getSelectedObjects( QString& theName1, return !theName1.isEmpty() && !theName2.isEmpty(); } +void HYDROGUI_TwoImagesDlg::setPreselectedObject( const QString& theName ) +{ + myImage1->SetName( theName ); + + HYDROGUI_ObjSelector* aSelector = myMode == TwoImages ? myImage2 : myPolyline; + aSelector->SetChecked( true ); + aSelector->SetName( QString() ); +} + void HYDROGUI_TwoImagesDlg::setColor( const QColor& theColor ) { if( theColor.alpha() == 0 ) // transparent diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h index 8ac3bce7..5f952266 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h +++ b/src/HYDROGUI/HYDROGUI_TwoImagesDlg.h @@ -58,6 +58,8 @@ public: bool getSelectedObjects( QString& theName1, QString& theName2 ) const; + void setPreselectedObject( const QString& theName ); + void setColor( const QColor& theColor ); QColor getColor() const; diff --git a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx index 2e634382..3def5370 100644 --- a/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_TwoImagesOp.cxx @@ -123,6 +123,16 @@ void HYDROGUI_TwoImagesOp::startOperation() aPanel->setColor( aColor ); } } + else if( !myIsEdit ) + { + Handle(HYDROData_Image) aSelectedImage = + Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); + if( !aSelectedImage.IsNull() ) + { + QString aSelectedName = aSelectedImage->GetName(); + aPanel->setPreselectedObject( aSelectedName ); + } + } } bool HYDROGUI_TwoImagesOp::processApply( int& theUpdateFlags, diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 70729b30..18d81f7f 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -54,11 +54,11 @@ does not exist or you have not enough permissions to open it. CALCULATION_BOUNDARY - Domain of calculation Case + Domain of calculation case CALCULATION_NAME - Calculation Case name + Calculation case name NAME @@ -70,11 +70,11 @@ does not exist or you have not enough permissions to open it. HYDROGUI_CalculationOp CREATE_CALCULATION - Create calculation Case + Create calculation case EDIT_CALCULATION - Edit calculation Case + Edit calculation case @@ -144,7 +144,7 @@ Do you want to continue? IMPORT_BATHYMETRY_FROM_FILE - Import Bathymetry from file + Import bathymetry from file NAME @@ -156,7 +156,7 @@ Do you want to continue? HYDROGUI_ImportBathymetryOp IMPORT_BATHYMETRY - Import Bathymetry + Import bathymetry BAD_IMPORTED_BATHYMETRY_FILE @@ -253,7 +253,7 @@ file cannot be correctly imported for a Bathymetry definition. HYDROGUI_Module DSK_CREATE_CALCULATION - Create calculation Case + Create calculation case DSK_CREATE_POLYLINE @@ -273,7 +273,7 @@ file cannot be correctly imported for a Bathymetry definition. DSK_EDIT_CALCULATION - Edit calculation Case + Edit calculation case DSK_EDIT_CUT_IMAGE @@ -313,7 +313,7 @@ file cannot be correctly imported for a Bathymetry definition. DSK_IMPORT_BATHYMETRY - Import Bathymetry + Import bathymetry DSK_IMPORT_IMAGE @@ -365,7 +365,7 @@ file cannot be correctly imported for a Bathymetry definition. MEN_CREATE_CALCULATION - Create new calculation Case + Create new calculation case MEN_CREATE_POLYLINE @@ -389,7 +389,7 @@ file cannot be correctly imported for a Bathymetry definition. MEN_EDIT_CALCULATION - Edit calculation Case + Edit calculation case MEN_EDIT_CUT_IMAGE @@ -429,7 +429,7 @@ file cannot be correctly imported for a Bathymetry definition. MEN_IMPORT_BATHYMETRY - Import Bathymetry + Import bathymetry MEN_IMPORT_IMAGE @@ -481,7 +481,7 @@ file cannot be correctly imported for a Bathymetry definition. STB_CREATE_CALCULATION - Create new calculation Case + Create new calculation case STB_CREATE_POLYLINE @@ -501,7 +501,7 @@ file cannot be correctly imported for a Bathymetry definition. STB_EDIT_CALCULATION - Edit calculation Case + Edit calculation case STB_EDIT_CUT_IMAGE @@ -541,7 +541,7 @@ file cannot be correctly imported for a Bathymetry definition. STB_IMPORT_BATHYMETRY - Import Bathymetry + Import bathymetry STB_IMPORT_IMAGE -- 2.39.2