From: rnv Date: Fri, 1 Jun 2018 09:22:01 +0000 (+0300) Subject: Alternative solution for '23552: Unable to use the contextual menu of Object Browser... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Frnv%2F23552_2;p=modules%2Fgeom.git Alternative solution for '23552: Unable to use the contextual menu of Object Browser window' issue. --- diff --git a/src/GEOMGUI/CMakeLists.txt b/src/GEOMGUI/CMakeLists.txt index db8aacf2c..d6cce5e33 100755 --- a/src/GEOMGUI/CMakeLists.txt +++ b/src/GEOMGUI/CMakeLists.txt @@ -79,11 +79,13 @@ SET(GEOMGUI_HEADERS GEOMGUI_TextTreeSelector.h GEOMGUI_DimensionProperty.h GEOMGUI_AnnotationAttrs.h + GEOMGUI_MaterialAction.h ) # header files / to be processed by moc SET(_moc_HEADERS GEOMGUI_AnnotationMgr.h + GEOMGUI_MaterialAction.h GEOMGUI_CreationInfoWdg.h GEOMGUI_TextTreeWdg.h GEOMGUI_TextTreeSelector.h @@ -124,6 +126,7 @@ SET(GEOMGUI_SOURCES GEOMGUI_TextTreeSelector.cxx GEOMGUI_DimensionProperty.cxx GEOMGUI_AnnotationAttrs.cxx + GEOMGUI_MaterialAction.cxx ${_moc_SOURCES} ${_rcc_SOURCES} ) diff --git a/src/GEOMGUI/GEOMGUI_MaterialAction.cxx b/src/GEOMGUI/GEOMGUI_MaterialAction.cxx new file mode 100644 index 000000000..20645d088 --- /dev/null +++ b/src/GEOMGUI/GEOMGUI_MaterialAction.cxx @@ -0,0 +1,141 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : GEOMGUI_MaterialAction.cxx +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) + +#include "GEOMGUI.h" +#include "GEOMGUI_MaterialAction.h" +#include "GeometryGUI.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +/*! + * GEOMGUI_MaterialAction::GEOMGUI_MaterialAction + * Constructor + */ +GEOMGUI_MaterialAction::GEOMGUI_MaterialAction(const QString& text, const QIcon& icon, const QString& menuText, + int accel, QObject* parent, bool toggle, const QString& shortcutAction) : + QtxAction( text, icon, menuText, accel, parent, toggle , shortcutAction){ + + LightApp_Application* anApp = dynamic_cast ( SUIT_Session::session()->activeApplication() ); + myMaterialMenu = new QMenu(); + + //connections + connect(anApp, SIGNAL( preferenceChanged( const QString&, const QString&, const QString& ) ), + this, SLOT( trackActionState(const QString&, const QString& , const QString& ) ) ); + connect(myMaterialMenu, SIGNAL( aboutToShow() ), this, SLOT( buildMaterialMenu() ) ); + + trackActionState( QString( "Geometry" ), QString( "Geometry" ), QString( "predef_materials" ) ); +} + +/*! + * GEOMGUI_MaterialAction::GEOMGUI_MaterialAction + * Destructor + */ +GEOMGUI_MaterialAction::~GEOMGUI_MaterialAction() { +} + + +/*! + * GEOMGUI_MaterialAction::buildMaterialMenu + * Build material menu immediately before rendering + */ +void GEOMGUI_MaterialAction::buildMaterialMenu(){ + myMaterialMenu->clear(); + + LightApp_Application* anApp = dynamic_cast ( SUIT_Session::session()->activeApplication() ); + if ( !anApp ) + return; + + GeometryGUI* aModule = dynamic_cast( anApp->activeModule() ); + if( !aModule ) + return; + + SALOME_ListIO lst; + aModule->getApp()->selectionMgr()->selectedObjects( lst ); + QSignalMapper* signalMapper = new QSignalMapper( myMaterialMenu ); + + //Get current material model for the object + QVariant v; + if ( anApp->activeViewManager() ) { + LightApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); + if( aStudy ) { + v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() ); + } + } + QString curModel = ""; + if ( v.canConvert() ) curModel = v.toString(); + // get list of all predefined materials + QStringList materials = Material_ResourceMgr::resourceMgr()->materials(); + bool found = false; + foreach ( QString material, materials ) + { + QAction* menAct = myMaterialMenu->addAction( material ); + connect(menAct, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) ); + signalMapper->setMapping( menAct, material ); + menAct->setCheckable( true ); + // Set checked if this material is current + Material_Model aModel; + aModel.fromResources( material ); + if ( !found && aModel.toProperties() == curModel ) { + menAct->setChecked( true ); + found = true; + } + } + myMaterialMenu->insertAction( myMaterialMenu->addSeparator(), aModule->action( GEOMOp::OpPredefMaterCustom ) ); + myMaterialMenu->insertSeparator( aModule->action( GEOMOp::OpPredefMaterCustom ) ); + connect( signalMapper, SIGNAL( mapped( const QString & ) ), + aModule, SLOT( OnSetMaterial( const QString & ) ) ); +} + +/*! + * GEOMGUI_MaterialAction::trackActionState + * Track state of this action after preferences change: simple action or action with submenu + */ +void GEOMGUI_MaterialAction::trackActionState(const QString& module, const QString& section, const QString& parameter ) { + if (module == "Geometry" && section == "Geometry" && parameter == "predef_materials" ) { + + bool isPredefMat = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials" ); + if (isPredefMat) { + setMenu( myMaterialMenu ); + } else { + setMenu( NULL ); + } + } +} diff --git a/src/GEOMGUI/GEOMGUI_MaterialAction.h b/src/GEOMGUI/GEOMGUI_MaterialAction.h new file mode 100644 index 000000000..3aaa9ffc4 --- /dev/null +++ b/src/GEOMGUI/GEOMGUI_MaterialAction.h @@ -0,0 +1,41 @@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : GEOMGUI_MaterialAction.h +// Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com) +// +#include + +class QMenu; + +class GEOMGUI_MaterialAction : public QtxAction { + Q_OBJECT + public: + GEOMGUI_MaterialAction(const QString&, const QIcon&, const QString&, int, QObject*, bool = false, const QString& = QString()); + virtual ~GEOMGUI_MaterialAction(); + + public slots: + void trackActionState( const QString& module, const QString& section, const QString& parameter ); + void buildMaterialMenu(); + private: + QMenu* myMaterialMenu; +}; diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 4a21919d8..70a71eff4 100755 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -41,6 +41,7 @@ #include "GEOMUtils_XmlHandler.hxx" #include "GEOMGUI_AnnotationMgr.h" #include "GEOMGUI_TextTreeSelector.h" +#include "GEOMGUI_MaterialAction.h" #include "GEOM_Actor.h" @@ -1155,7 +1156,23 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpUnpublishObject, "POP_UNPUBLISH_OBJ" ); createGeomAction( GEOMOp::OpPublishObject, "POP_PUBLISH_OBJ" ); createGeomAction( GEOMOp::OpPointMarker, "POP_POINT_MARKER" ); - createGeomAction( GEOMOp::OpMaterialProperties, "POP_MATERIAL_PROPERTIES" ); + + // Custom action for Material properties + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + LightApp_Application* anApp = dynamic_cast ( SUIT_Session::session()->activeApplication() ); + QPixmap icon = resMgr ? resMgr->loadPixmap( "GEOM", tr("ICO_POP_MATERIAL_PROPERTIES"), false ) : QPixmap(); + GEOMGUI_MaterialAction* matAction = new GEOMGUI_MaterialAction( tr("TOP_POP_MATERIAL_PROPERTIES"), + QIcon(icon), + tr("MEN_POP_MATERIAL_PROPERTIES"), + 0, + anApp->desktop(), + false, + QString("") ); + matAction->setStatusTip( tr("STB_POP_MATERIAL_PROPERTIES") ); + registerAction( GEOMOp::OpMaterialProperties, matAction ); + connect( matAction, SIGNAL( triggered( bool ) ), this , SLOT( OnGUIEvent() ) ); + + createGeomAction( GEOMOp::OpPredefMaterCustom, "POP_PREDEF_MATER_CUSTOM" ); createGeomAction( GEOMOp::OpCreateFolder, "POP_CREATE_FOLDER" ); createGeomAction( GEOMOp::OpSortChildren, "POP_SORT_CHILD_ITEMS" ); @@ -1733,7 +1750,6 @@ void GeometryGUI::initialize( CAM_Application* app ) mgr->hide( mgr->actionId( action( myEraseAll ) ) ); - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); if (resMgr) { GEOM_AISShape::setTopLevelDisplayMode((GEOM_AISShape::TopLevelDispMode)resMgr->integerValue("Geometry", "toplevel_dm", 0)); QColor c = resMgr->colorValue( "Geometry", "toplevel_color", QColor( 170, 85, 0 ) ); @@ -2264,57 +2280,6 @@ void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& SalomeApp_Module::contextMenuPopup( client, menu, title ); SALOME_ListIO lst; getApp()->selectionMgr()->selectedObjects( lst ); - - //Add submenu for predefined materials - bool isPredefMat = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials" ); - if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() > 0 ) { - QtxPopupMgr* mgr = popupMgr(); - //get parrent for submenu - QAction* act = mgr->action( mgr->actionId( action( GEOMOp::OpMaterialProperties ) ) ); - //Clear old menu - QMenu* oldMenu = act->menu() ; - if( oldMenu ) { - delete oldMenu; - } - if( isPredefMat ){ - QMenu* matMenu = new QMenu(); - QSignalMapper* signalMapper = new QSignalMapper( matMenu ); - - //Get current material model for the object - QVariant v; - LightApp_Application* anApp = dynamic_cast( getApp() ); - if ( anApp && anApp->activeViewManager() ) { - LightApp_Study* aStudy = dynamic_cast( anApp->activeStudy() ); - if( aStudy ) { - v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() ); - } - } - QString curModel = ""; - if ( v.canConvert() ) curModel = v.toString(); - // get list of all predefined materials - QStringList materials = Material_ResourceMgr::resourceMgr()->materials(); - bool found = false; - foreach ( QString material, materials ) - { - QAction* menAct = matMenu->addAction( material ); - connect(menAct, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) ); - signalMapper->setMapping( menAct, material ); - menAct->setCheckable( true ); - // Set checked if this material is current - Material_Model aModel; - aModel.fromResources( material ); - if ( !found && aModel.toProperties() == curModel ) { - menAct->setChecked( true ); - found = true; - } - } - matMenu->insertAction( matMenu->addSeparator(), action( GEOMOp::OpPredefMaterCustom ) ); - matMenu->insertSeparator( action( GEOMOp::OpPredefMaterCustom ) ); - connect( signalMapper, SIGNAL( mapped( const QString & ) ), - this, SLOT( OnSetMaterial( const QString & ) ) ); - act->setMenu( matMenu ); - } - } //Set name if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) { Handle(SALOME_InteractiveObject) io = lst.First(); @@ -2387,8 +2352,8 @@ void GeometryGUI::createPreferences() LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" ); addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup, - LightApp_Preferences::Bool, "Geometry", "predef_materials" ); - + LightApp_Preferences::Bool, "Geometry", "predef_materials" ); + int material = addPreference( tr( "PREF_MATERIAL" ), genGroup, LightApp_Preferences::Selector, "Geometry", "material" );