Salome HOME
0023552: Unable to use the contextual menu of Object Browser window
authorvsr <vsr@opencascade.com>
Thu, 4 Oct 2018 14:33:29 +0000 (17:33 +0300)
committervsr <vsr@opencascade.com>
Thu, 6 Dec 2018 13:02:00 +0000 (16:02 +0300)
- Another attempt to solve problem with materials sub-menu on desktops like Unity, KDE Plasma etc.

src/GEOMGUI/GEOMGUI_Selection.cxx
src/GEOMGUI/GeometryGUI.cxx
src/GEOMGUI/GeometryGUI_Operations.h

index 017e7c2400f5f2984c04dc400568951847b48232..b674220563aefe15a7b113b95a4927a56a0485ca 100644 (file)
@@ -206,6 +206,8 @@ QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const
     v = hasHiddenAnnotations(idx);
   else if ( p == "hasVisibleAnnotations" )
     v = hasVisibleAnnotations(idx);
+  else if ( p == "matMenu" )
+    v = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials", false );
   else
     v = LightApp_Selection::parameter( idx, p );
 
@@ -392,7 +394,7 @@ QString GEOMGUI_Selection::displayMode( const int index ) const
 
 bool GEOMGUI_Selection::autoBringToFront( const int /*index*/ ) const
 {
-  return SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front", "false" );
+  return SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front", false );
 }
 
 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
index 7e4acf07f1dc0c5af25eb819176f791c0769bfda..78a5caa7e665b698a777cd7816442106cd059e77 100755 (executable)
@@ -535,8 +535,9 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam )
   case GEOMOp::OpPublishObject:      // ROOT GEOM OBJECT - POPUP MENU - PUBLISH
   case GEOMOp::OpPointMarker:        // POPUP MENU - POINT MARKER
   case GEOMOp::OpMaterialProperties: // POPUP MENU - MATERIAL PROPERTIES
-  case GEOMOp::OpPredefMaterial:     // POPUP MENU - <SOME MATERIAL>
-  case GEOMOp::OpPredefMaterCustom:  // POPUP MENU - MATERIAL PROPERTIES - CUSTOM...
+  case GEOMOp::OpMaterialMenu:       // POPUP MENU - MATERIAL PROPERTIES (sub-menu)
+  case GEOMOp::OpPredefMaterial:     // POPUP MENU - MATERIAL PROPERTIES (sub-menu) - <SOME MATERIAL>
+  case GEOMOp::OpPredefMaterCustom:  // POPUP MENU - MATERIAL PROPERTIES (sub-menu) - CUSTOM...
   case GEOMOp::OpEdgeWidth:          // POPUP MENU - LINE WIDTH - EDGE WIDTH
   case GEOMOp::OpIsosWidth:          // POPUP MENU - LINE WIDTH - ISOS WIDTH
   case GEOMOp::OpBringToFront:       // POPUP MENU - BRING TO FRONT
@@ -1151,6 +1152,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
   createGeomAction( GEOMOp::OpMaterialProperties,   "POP_MATERIAL_PROPERTIES" );
   createGeomAction( GEOMOp::OpPredefMaterCustom,    "POP_PREDEF_MATER_CUSTOM" );
+  createGeomAction( GEOMOp::OpMaterialMenu, "POP_MATERIAL_PROPERTIES");
+  action(GEOMOp::OpMaterialMenu)->setMenu( new QMenu() );
   createGeomAction( GEOMOp::OpCreateFolder, "POP_CREATE_FOLDER" );
   createGeomAction( GEOMOp::OpSortChildren, "POP_SORT_CHILD_ITEMS" );
 #ifndef DISABLE_GRAPHICSVIEW
@@ -1612,7 +1615,9 @@ void GeometryGUI::initialize( CAM_Application* app )
 
   // material properties
   mgr->insert( action(  GEOMOp::OpMaterialProperties ), -1, -1 );
-  mgr->setRule( action( GEOMOp::OpMaterialProperties ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
+  mgr->setRule( action( GEOMOp::OpMaterialProperties ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'}) and matMenu=false", QtxPopupMgr::VisibleRule );
+  mgr->insert( action(  GEOMOp::OpMaterialMenu ), -1, -1 );
+  mgr->setRule( action( GEOMOp::OpMaterialMenu ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'}) and matMenu=true", QtxPopupMgr::VisibleRule );
 
  // texture
   mgr->insert( action(  GEOMOp::OpSetTexture ), -1, -1 );
@@ -2248,59 +2253,44 @@ void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString&
   SALOME_ListIO lst;
   getApp()->selectionMgr()->selectedObjects( lst );
 
-  //Add submenu for predefined materials
-  // RNV: '#23552: Unable to use the contextual menu of Object Browser window' issue: 
-  //      Temporary solution: do not show 'Materials' submenu forcibly
-  //bool isPredefMat = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials" );
-  bool isPredefMat = false;
-  
+  // Update submenu for predefined materials
   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() > 0 ) {
-    QtxPopupMgr* mgr = popupMgr();
-    //get parent 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<LightApp_Application*>( getApp() );
-      if ( anApp && anApp->activeViewManager() ) {
-        LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() );
-        if( aStudy ) {
-          v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() );
-        }
+    QMenu* matMenu = action( GEOMOp::OpMaterialMenu )->menu();
+    matMenu->clear();
+    QSignalMapper* signalMapper = new QSignalMapper( menu );
+
+    QVariant v;
+    LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( getApp() );
+    if ( anApp && anApp->activeViewManager() ) {
+      LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( anApp->activeStudy() );
+      if( aStudy ) {
+        v = aStudy->getObjectProperty( anApp->activeViewManager()->getGlobalId(), lst.Last()->getEntry(), GEOM::propertyName( GEOM::Material ), QVariant() );
       }
-      QString curModel = "";
-      if ( v.canConvert<QString>() ) 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;
-        }
+    }
+    QString curModel = "";
+    if ( v.canConvert<QString>() ) curModel = v.toString();
+
+    // get list of all predefined materials
+    QStringList materials = Material_ResourceMgr::resourceMgr()->materials();
+    bool found = false;
+    foreach ( QString material, materials )
+    {
+      QAction* a = matMenu->addAction( material );
+      connect( a, SIGNAL( toggled( bool ) ), signalMapper, SLOT( map() ) );
+      signalMapper->setMapping( a, material );
+      a->setCheckable( true );
+
+      Material_Model aModel;
+      aModel.fromResources( material );
+      if ( !found && aModel.toProperties() == curModel ) {
+       a->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 );
     }
+    matMenu->addSeparator();
+    matMenu->addAction( action( GEOMOp::OpPredefMaterCustom ) );
+    connect( signalMapper, SIGNAL( mapped( const QString & ) ),
+                 this, SLOT( OnSetMaterial( const QString & ) ) );
   }
   //Set name
   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
@@ -2373,9 +2363,8 @@ void GeometryGUI::createPreferences()
   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
 
-  // RNV: Temporary hide this preference, because of the '#23552: Unable to use the contextual menu of Object Browser window' issue
-  //addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
-  //               LightApp_Preferences::Bool, "Geometry", "predef_materials" );
+  addPreference( tr( "PREF_PREDEF_MATERIALS" ), genGroup,
+                 LightApp_Preferences::Bool, "Geometry", "predef_materials" );
 
   int material = addPreference( tr( "PREF_MATERIAL" ), genGroup,
                                 LightApp_Preferences::Selector,
index da8ae797e208cbb20f9f981aaf594309a0927154..d4068e7aabf59f96599d11d18185ae4db6b8f20d 100755 (executable)
@@ -51,8 +51,9 @@ namespace GEOMOp {
     OpPointMarker         = 1210,   // POPUP MENU - POINT MARKER
     OpSetTexture          = 1211,   // POPUP MENU - SETTEXTURE
     OpMaterialProperties  = 1212,   // POPUP MENU - MATERIAL PROPERTIES
-    OpPredefMaterial      = 1213,   // POPUP MENU - MATERIAL PROPERTIES - <SOME MATERIAL>
-    OpPredefMaterCustom   = 1214,   // POPUP MENU - MATERIAL PROPERTIES - CUSTOM...
+    OpMaterialMenu        = 1213,   // POPUP MENU - MATERIAL PROPERTIES (sub-menu)
+    OpPredefMaterial      = 1214,   // POPUP MENU - MATERIAL PROPERTIES (sub-menu) - <SOME MATERIAL>
+    OpPredefMaterCustom   = 1215,   // POPUP MENU - MATERIAL PROPERTIES (sub-menu) - CUSTOM...
     OpDiscloseChildren    = 1250,   // POPUP MENU - DISCLOSE CHILD ITEMS
     OpConcealChildren     = 1251,   // POPUP MENU - CONCEAL CHILD ITEMS
     OpUnpublishObject     = 1253,   // POPUP MENU - UNPUBLISH