Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI.cxx
old mode 100755 (executable)
new mode 100644 (file)
index cff4a46..d7319a4
@@ -1,4 +1,4 @@
-// Copyright (C) 2009-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 using namespace std;
 using namespace HEXABLOCK::GUI;
 
-int  HEXABLOCKGUI::_oldStudyId = -1;
-
 // HEXABLOCK_ORB::HEXABLOCK_Gen_var HEXABLOCKGUI::_hexaEngine  = HEXABLOCK_ORB::HEXABLOCK_Gen::_nil();
 //
 VtkDocumentGraphicView* HEXABLOCKGUI::currentDocGView = NULL;
@@ -144,7 +142,7 @@ HEXABLOCKGUI::HEXABLOCKGUI() :
           _dwAssociation(0),
           _dwGroups(0),
           _dwMesh(0),
-          _dwObjectBrowser(0),
+//          _dwObjectBrowser(0),
           _dwInputPanel(0),
           _patternDataTreeView(0),
 //          _patternBuilderTreeView(0),
@@ -252,7 +250,6 @@ void HEXABLOCKGUI::initialize( CAM_Application* app )
     createActions();
     createMenus();
     createTools();
-    studyActivated();
 }
 
 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
@@ -285,8 +282,10 @@ bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
 
     connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
             this, SLOT(onWindowActivated( SUIT_ViewWindow* )), Qt::UniqueConnection );
-    connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
-            this, SLOT( onObjectBrowserClick(const QModelIndex&) ), Qt::UniqueConnection );
+    if ( getApp()->objectBrowser() ) {
+      connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
+              this, SLOT( onObjectBrowserClick(const QModelIndex&) ), Qt::UniqueConnection );
+    }
 
     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
 
@@ -340,15 +339,6 @@ bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
                 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
     }
 
-    /* ************************************   TODO Hexa6
-    _hexaEngine->SetCurrentStudy(SALOMEDS::Study::_nil());
-    if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( theStudy ))
-        if ( _PTR(Study) aStudy = s->studyDS()) {
-            _hexaEngine->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
-            updateObjBrowser(); // objects can be removed
-        }
-     ************************************ */
-
     if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
             currentOccGView->getViewWindow()->installEventFilter(this);
 
@@ -418,16 +408,24 @@ bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
 
     hideActor();
 
+    if(currentOccGView) {
+      delete currentOccGView;
+      currentOccGView = NULL;
+    }
+
+    if(currentDocGView) {
+      delete currentDocGView;
+      currentDocGView = NULL;
+    }
+
     return bOk;
 }
 
-SALOMEDS::Study_var HEXABLOCKGUI::ClientStudyToStudy (_PTR(Study) theStudy)
+SALOMEDS::Study_var HEXABLOCKGUI::getStudyServant()
 {
-  SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
-  CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
-  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
-  int aStudyID = theStudy->StudyId();
-  SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
+  SALOME_NamingService_Abstract *aNamingService = SalomeApp_Application::namingService();
+  CORBA::Object_var aSMObject = aNamingService->Resolve("/Study");
+  SALOMEDS::Study_var aDSStudy = SALOMEDS::Study::_narrow(aSMObject);
   return aDSStudy._retn();
 }
 
@@ -440,8 +438,7 @@ void HEXABLOCKGUI::addInStudy(QMap<QString, TopoDS_Shape>& topo_shapes,
 
     SalomeApp_Study* appStudy = HEXABLOCKGUI::activeStudy();
     if(!appStudy) return;
-    _PTR(Study) aStudy = appStudy->studyDS();
-    SALOMEDS::Study_var aDSStudy = ClientStudyToStudy( aStudy );
+    SALOMEDS::Study_var aDSStudy = getStudyServant();
     SALOMEDS::StudyBuilder_var     aBuilder (aDSStudy->NewBuilder());
     QString entry = currentDocGView->getDocumentModel()->documentEntry();
     SALOMEDS::SObject_var aFatherSO = aDSStudy->FindObjectID( qPrintable(entry) );
@@ -505,29 +502,18 @@ bool HEXABLOCKGUI::renameObject( const QString& entry, const QString& name)
     if (dgview == NULL || dgview->getDocumentModel() == NULL)
         return result;
 
-    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication());
-    SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
-
-    if(!appStudy)
-        return result;
-
-    _PTR(Study) aStudy = appStudy->studyDS();
-
-    if(!aStudy)
-        return result;;
-
-    _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
+    _PTR(SObject) obj ( SalomeApp_Application::getStudy()->FindObjectID(qPrintable(entry)) );
     _PTR(GenericAttribute) anAttr;
     if ( obj ){
-        if ( obj->FindAttribute(anAttr, "AttributeName") ){
-            _PTR(AttributeName) aName (anAttr);
-            DocumentModel* docModel = dgview->getDocumentModel();
-            docModel->setName( name );
-            aName->SetValue( name.toLatin1().data() );
-            getApp()->updateObjectBrowser();
-//            _dwPattern->setWindowTitle( name );
-            result = true;
-        }
+      if ( obj->FindAttribute(anAttr, "AttributeName") ) {
+        _PTR(AttributeName) aName (anAttr);
+        DocumentModel* docModel = dgview->getDocumentModel();
+        docModel->setName( name );
+        aName->SetValue( name.toLatin1().data() );
+        getApp()->updateObjectBrowser();
+//        _dwPattern->setWindowTitle( name );
+        result = true;
+      }
     }
     return result;
 }
@@ -830,7 +816,7 @@ bool HEXABLOCKGUI::createSComponent() //addComponent
     DEBTRACE("HEXABLOCKGUI::createSComponent");
     // --- Find or create (if not done yet) "HEXABLOCK" SComponent in the study
 
-    _PTR(Study)            aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
+    _PTR(Study)            aStudy = SalomeApp_Application::getStudy();
     _PTR(StudyBuilder)     aBuilder (aStudy->NewBuilder());
     _PTR(GenericAttribute) anAttr;
     _PTR(AttributeName)    aName;
@@ -875,29 +861,14 @@ void HEXABLOCKGUI::preferencesChanged( const QString& sect, const QString& name
 //        _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
 }
 
-void HEXABLOCKGUI::studyActivated() //CS_TODO
-{
-    int newStudyId = getApp()->activeStudy()->id();
-    DEBTRACE("HEXABLOCKGUI::studyActivated " << _oldStudyId << " " << newStudyId);
-//    if (_oldStudyId != -1)
-//    {
-//        _studyContextMap[_oldStudyId] = QtGuiContext::getQtCurrent();
-//        if (_studyContextMap.count(newStudyId))
-//        {
-//            DEBTRACE("switch to valid context " << QtGuiContext::getQtCurrent() << " " << _studyContextMap[newStudyId]);
-//            QtGuiContext::setQtCurrent(_studyContextMap[newStudyId]);
-//        }
-//        else
-//        {
-//            DEBTRACE("no switch to null context");
-//        }
-//    }
-    _oldStudyId = newStudyId;
-}
-
 void HEXABLOCKGUI::treeContextMenu(const QPoint& aPosition)
 {
     QModelIndex currentIndex = _patternDataTreeView->currentIndex();
+
+    // if nothing is selected, return
+    if (! currentIndex.isValid())
+      return;
+
     QVariant currentAssocVariant;
     QString currentAssocEntry;
 
@@ -1019,30 +990,35 @@ void HEXABLOCKGUI::createAndFillDockWidget()
     _meshTreeView->show();
 
 //    QDockWidget *_dwObjectBrowser = 0;
-    QWidget* wid = getApp()->objectBrowser()->treeView();
-    QWidget *w   = wid->parentWidget();
-    while ( w && !_dwObjectBrowser ) {
-        _dwObjectBrowser = ::qobject_cast<QDockWidget*>( w );
-        w = w->parentWidget();
+    QWidget* wid = 0;
+    if ( getApp()->objectBrowser() )
+      wid = getApp()->objectBrowser()->treeView();
+    while ( wid && !_dwObjectBrowser ) {
+        _dwObjectBrowser = ::qobject_cast<QDockWidget*>( wid );
+        wid = wid->parentWidget();
+    }
+    
+    if ( _dwObjectBrowser ) {
+      _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
+      _dwObjectBrowser->setWindowTitle("Study");
     }
-    _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
-    _dwObjectBrowser->setWindowTitle("Study");
 
     // dock widget position
-    aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
+    if ( _dwObjectBrowser ) {
+      aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
+    }
     aParent->addDockWidget( Qt::RightDockWidgetArea, _dwInputPanel );
 
 //    aParent->tabifyDockWidget( _dwPattern, _dwObjectBrowser );
 //    aParent->tabifyDockWidget( _dwGroups, _dwPattern );
 //    aParent->tabifyDockWidget( _dwMesh, _dwGroups );
 
-    aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
+    if ( _dwObjectBrowser ) {
+      aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
+    }
     aParent->tabifyDockWidget( _dwPattern, _dwGroups );
     aParent->tabifyDockWidget( _dwGroups, _dwMesh );
-
-#if QT_VERSION >= 0x040500
     aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
-#endif
 
     // popup menu on data tree view
     _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -3239,8 +3215,7 @@ QString HEXABLOCKGUI::addDocInStudy (HEXA_NS::Document* document)
     if (app_study == NULL)
         return docEntry;
 
-    _PTR(Study)         study    = app_study->studyDS();
-    SALOMEDS::Study_var ds_study = ClientStudyToStudy (study);
+    SALOMEDS::Study_var ds_study = getStudyServant();
     SALOMEDS::StudyBuilder_var aBuilder (ds_study->NewBuilder());
     QString entry = app_study->centry("HEXABLOCK");
     SALOMEDS::SObject_var aFatherSO = ds_study->FindObjectID( qPrintable(entry) );