Salome HOME
Fix for IPAL9275
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index e3d8df78712a71c96f9a8da371ae57cde8fec782..21602a0fa0dca12b97adb6b5b5c04d34cb918b03 100644 (file)
@@ -240,6 +240,8 @@ namespace{
                                QObject::tr("SMESH_BUT_OK"));
          wc.resume();
        }
+
+       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
       }
       catch (const SALOME::SALOME_Exception& S_ex){
        wc.suspend();
@@ -802,46 +804,10 @@ namespace{
   }
 }
 
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-class CustomItem : public QCustomMenuItem
-{
-public:
-  CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
-  ~CustomItem() {}
-
-  void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
-  {
-    p->save();
-    p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
-    p->setPen( act ? cg.highlightedText() : cg.buttonText() );
-    p->setFont( myFont );
-    p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
-    p->restore();
-  }
-
-  QSize sizeHint()
-  {
-    return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
-  }
-
-  bool fullSpan() const
-  {
-    return true;
-  }
-
-private:
-  QString myString;
-  QFont   myFont;
-};
-
 extern "C" {
   Standard_EXPORT CAM_Module* createModule()
   {
-    return SMESHGUI::GetSMESHGUI();
+    return new SMESHGUI();
   }
 }
 
@@ -853,7 +819,7 @@ SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
  */
 //=============================================================================
 SMESHGUI::SMESHGUI() :
-  SalomeApp_Module( "SMESH" )
+SalomeApp_Module( "SMESH" )
 {
   if ( CORBA::is_nil( myComponentSMESH ) )
   {
@@ -862,6 +828,7 @@ SMESHGUI::SMESHGUI() :
     myComponentSMESH = SMESH::SMESH_Gen::_narrow( comp );
   }
 
+  myAutomaticUpdate = false;
   myActiveDialogBox = 0 ;
   myState = -1 ;
 
@@ -913,24 +880,32 @@ SUIT_ResourceMgr* SMESHGUI::resourceMgr()
 //=============================================================================
 SMESHGUI* SMESHGUI::GetSMESHGUI()
 {
-  static SMESHGUI* aSMESHGUI = NULL;
-  if( !aSMESHGUI )
-    aSMESHGUI = new SMESHGUI();
-
-  if(_PTR(Study) aStudy = SMESH::GetActiveStudyDocument())
-    GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
+  SMESHGUI* smeshMod = 0;
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
+  if ( app )
+  {
+    CAM_Module* module = app->module( "Mesh" );
+    smeshMod = dynamic_cast<SMESHGUI*>( module );
+  }
 
-  SUIT_ResourceMgr* mgr = resourceMgr();
-  if( mgr )
-  /* Automatic Update flag */
-    aSMESHGUI->myAutomaticUpdate = ( mgr->stringValue( "SMESH", "AutomaticUpdate" ).compare( "true" ) == 0 );
+  if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
+  {
+    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
+    if ( study )
+    {
+      _PTR(Study) aStudy = study->studyDS();
+      if ( aStudy )
+       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
+    }
+  }
 
-  return aSMESHGUI;
+  return smeshMod;
 }
 
 extern "C"
 {
-  Standard_EXPORT SMESHGUI* GetComponentGUI() {
+  Standard_EXPORT SMESHGUI* GetComponentGUI()
+  {
     return SMESHGUI::GetSMESHGUI();
   }
 }
@@ -1352,6 +1327,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
                              tr("SMESH_WRN_VIEWER_VTK"),
                              tr("SMESH_BUT_OK"));
       }
+      updateObjBrowser();
       break;
     }
 
@@ -1894,6 +1870,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           }
         }
       }
+      updateObjBrowser( true );
       break;
     }
 
@@ -2279,7 +2256,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
   }
 
-  updateObjBrowser();
+  //updateObjBrowser();
   return true;
 }
 
@@ -2466,6 +2443,11 @@ void SMESHGUI::initialize( CAM_Application* app )
 {
   SalomeApp_Module::initialize( app );
 
+  SUIT_ResourceMgr* mgr = app->resourceMgr();
+  if ( mgr )
+  /* Automatic Update flag */
+    myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
+
   // ----- create actions --------------
 
   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
@@ -2856,7 +2838,7 @@ void SMESHGUI::initialize( CAM_Application* app )
 
   QString aSelCount = QString( "%1 = 1" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
   QString lc = QtxPopupMgr::Selection::defEquality();
-  QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer' 'ObjectBrowser'" );
+  QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() ).arg( mesh_group );
   QString aMeshInVTK = aClient + "&&" + aType;// + "&&" + aSelCount;
   
@@ -3073,6 +3055,11 @@ void SMESHGUI::OnGUIEvent()
 
 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
 {
+  if ( CORBA::is_nil( myComponentSMESH ) )
+    {
+      SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
+      return aGUI.myComponentSMESH;
+    }  
   return myComponentSMESH;
 }