From: mpa Date: Fri, 30 Sep 2016 06:30:31 +0000 (+0300) Subject: 0023299: [CEA] Finalize multi-study removal X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=442688722e293ce0dc5173f6b9bd0fda78e5d850;p=modules%2Fgui.git 0023299: [CEA] Finalize multi-study removal - delete study id parameter - initialize one studyDS per application --- diff --git a/src/GuiHelpers/SALOME_AppStudyEditor.cxx b/src/GuiHelpers/SALOME_AppStudyEditor.cxx index 1252bc431..4f9b88242 100644 --- a/src/GuiHelpers/SALOME_AppStudyEditor.cxx +++ b/src/GuiHelpers/SALOME_AppStudyEditor.cxx @@ -29,28 +29,6 @@ SALOME_AppStudyEditor::SALOME_AppStudyEditor(SalomeApp_Application * salomeApp) : SALOME_StudyEditor() { _salomeApp = salomeApp; - updateActiveStudy(); -} - -/** - * This updates the editor with the current active study. If the - * active study id is identical to the study id currently associated - * to this object, then no update is performed. - */ -int SALOME_AppStudyEditor::updateActiveStudy() { - int activeStudyId = SALOME_AppStudyEditor::getActiveStudyId(_salomeApp); - if ( activeStudyId != this->getStudyId() ) { - this->setStudyById(activeStudyId); - } - return activeStudyId; -} - -// GUI context only -int SALOME_AppStudyEditor::getActiveStudyId(SalomeApp_Application * salomeApp) { - SalomeApp_Study* appStudy = dynamic_cast (salomeApp->activeStudy()); - _PTR(Study) aCStudy = appStudy->studyDS(); - int studyId = aCStudy->StudyId(); - return studyId; } SALOMEDS::SObject_ptr SALOME_AppStudyEditor::IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject) { diff --git a/src/GuiHelpers/SALOME_AppStudyEditor.hxx b/src/GuiHelpers/SALOME_AppStudyEditor.hxx index 19ceb182c..804ad6df1 100644 --- a/src/GuiHelpers/SALOME_AppStudyEditor.hxx +++ b/src/GuiHelpers/SALOME_AppStudyEditor.hxx @@ -37,13 +37,10 @@ class SALOMEGUIHELPERS_EXPORT SALOME_AppStudyEditor: public SALOME_StudyEditor { public: SALOME_AppStudyEditor(SalomeApp_Application * salomeApp); - int updateActiveStudy(); SALOMEDS::SObject_ptr IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject); SALOME_StudyEditor::SObjectList * getSelectedObjects(); - static int getActiveStudyId(SalomeApp_Application * salomeApp); - private: SalomeApp_Application * _salomeApp; diff --git a/src/GuiHelpers/SALOME_GuiServices.cxx b/src/GuiHelpers/SALOME_GuiServices.cxx index 76d1dc081..c5ce1b135 100644 --- a/src/GuiHelpers/SALOME_GuiServices.cxx +++ b/src/GuiHelpers/SALOME_GuiServices.cxx @@ -75,13 +75,13 @@ namespace GUI { * process, i.e. the SALOME_SessionServer embedding the * SalomeApp_Application. */ - int getActiveStudyId() { + bool isActiveStudy() { SALOME::Session_var aSession = KERNEL::getSalomeSession(); if ( CORBA::is_nil(aSession) ) { INFOS("ERR: can't request for active study because the session is NULL"); - return -1; + return false; } - return aSession->GetActiveStudyId(); + return true; } /** @@ -89,7 +89,8 @@ namespace GUI { * defined in the SALOME session, returns null otherwise. */ SALOMEDS::Study_ptr getActiveStudy() { - return KERNEL::getStudyById(getActiveStudyId()); + if ( isActiveStudy() ) + return KERNEL::getStudy(); } @@ -120,8 +121,7 @@ namespace GUI { // retrieve the SALOMEDS::Study servant first and the to // request this servant to get the SObject given its entry. // - _PTR(Study) studyClient = appStudy->studyDS(); - SALOMEDS::Study_var study = KERNEL::getStudyManager()->GetStudyByID(studyClient->StudyId()); + SALOMEDS::Study_var study = KERNEL::getStudy(); SALOMEDS::SObject_ptr sobject = study->FindObjectID(iobject->getEntry()); return sobject; } diff --git a/src/GuiHelpers/SALOME_GuiServices.hxx b/src/GuiHelpers/SALOME_GuiServices.hxx index 73661bb98..92fdd6005 100644 --- a/src/GuiHelpers/SALOME_GuiServices.hxx +++ b/src/GuiHelpers/SALOME_GuiServices.hxx @@ -59,7 +59,7 @@ namespace GUI { // of the attribute of a SObject is a CORBA servant that handles the // data to work with SALOMEGUIHELPERS_EXPORT SALOMEDS::Study_ptr getActiveStudy(); - SALOMEGUIHELPERS_EXPORT int getActiveStudyId(); + SALOMEGUIHELPERS_EXPORT bool isActiveStudy(); // Another way to get the active study (to be converted in // SALOMEDS::Study): diff --git a/src/GuiHelpers/StandardApp_Module.cxx b/src/GuiHelpers/StandardApp_Module.cxx index e969ed113..f1636d52c 100644 --- a/src/GuiHelpers/StandardApp_Module.cxx +++ b/src/GuiHelpers/StandardApp_Module.cxx @@ -304,9 +304,8 @@ bool StandardApp_Module::createStudyComponentAtActivation() { void StandardApp_Module::createStudyComponent(SUIT_Study* theStudy) { SALOME_NamingService *aNamingService = SalomeApp_Application::namingService(); - CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject); - SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(theStudy->id()); + CORBA::Object_var aStudyObject = aNamingService->Resolve("/Study"); + SALOMEDS::Study_var aDSStudy = SALOMEDS::Study::_narrow(aStudyObject); SALOMEDS::SComponent_var aFather = aDSStudy->FindComponent(QCHARSTAR(moduleName())); if (aFather->_is_nil()) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 37ca6fd0f..0015d75ce 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -230,8 +230,6 @@ static const char* imageEmptyIcon[] = { "....................", "...................."}; -int LightApp_Application::lastStudyId = 0; - // Markers used to parse array with dockable windows and toolbars state. // For more details please see the qdockarealayout.cpp && qtoolbararealayout.cpp // in the Qt source code. @@ -295,14 +293,6 @@ namespace } } -/*! - \return last global id of study -*/ -int LightApp_Application::studyId() -{ - return LightApp_Application::lastStudyId; -} - /*!Create new instance of LightApp_Application.*/ extern "C" LIGHTAPP_EXPORT SUIT_Application* createApplication() { @@ -1356,10 +1346,9 @@ void LightApp_Application::placeDockWindow( const int id, Qt::DockWidgetArea pla /*! Gets window. \param flag - key for window - \param studyId - study id Flag used how identificator of window in windows list. */ -QWidget* LightApp_Application::getWindow( const int flag, const int ) +QWidget* LightApp_Application::getWindow( const int flag) { QWidget* wid = dockWindow( flag ); if ( !wid ) @@ -1987,8 +1976,6 @@ void LightApp_Application::updateActions() */ SUIT_Study* LightApp_Application::createNewStudy() { - LightApp_Application::lastStudyId++; - LightApp_Study* aStudy = new LightApp_Study( this ); // Set up processing of major study-related events diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 926546228..399de7814 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -135,7 +135,7 @@ public: virtual SUIT_ViewManager* createViewManager( const QString& vmType, QWidget* w ); virtual SUIT_ViewManager* createViewManager( SUIT_ViewModel* ); - QWidget* getWindow( const int, const int = -1 ); + QWidget* getWindow( const int ); QWidget* dockWindow( const int ) const; void removeDockWindow( const int ); void insertDockWindow( const int, QWidget* ); @@ -154,8 +154,6 @@ public: void setDefaultStudyName( const QString& theName ); - static int studyId(); - virtual bool event( QEvent* ); virtual bool checkDataObject( LightApp_DataObject* theObj ); @@ -341,7 +339,6 @@ protected: static LightApp_Preferences* _prefs_; - static int lastStudyId; QStringList myUserWmTypes; }; diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index 9a3d5dfb7..debdb25b4 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -60,8 +60,6 @@ LightApp_Study::~LightApp_Study() */ bool LightApp_Study::createDocument( const QString& theStr ) { - setStudyName( QString( "Study%1" ).arg( LightApp_Application::studyId() ) ); - // create myRoot setRoot( new LightApp_RootObject( this ) ); diff --git a/src/LightApp/resources/LightApp_msg_en.ts b/src/LightApp/resources/LightApp_msg_en.ts index 53f076da3..b22285011 100644 --- a/src/LightApp/resources/LightApp_msg_en.ts +++ b/src/LightApp/resources/LightApp_msg_en.ts @@ -56,15 +56,15 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS STUDYCLOSE_DESCRIPTION - You already have an active study in your session. It has to be closed before working with another study. + The current study has unsaved changes. Would you like to save before closing it? APPCLOSE_SAVE - &Save && Close + &Yes APPCLOSE_CLOSE - Close &w/o saving + &No APPCLOSE_CANCEL diff --git a/src/LightApp/resources/LightApp_msg_fr.ts b/src/LightApp/resources/LightApp_msg_fr.ts index 1646f5b82..fa83e5822 100755 --- a/src/LightApp/resources/LightApp_msg_fr.ts +++ b/src/LightApp/resources/LightApp_msg_fr.ts @@ -56,15 +56,15 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS STUDYCLOSE_DESCRIPTION - Une étude est déjà ouverte. Elle doit être fermée avant d'en ouvrir une autre. + Une étude a des modifications non enregistrées. Voulez-vous les sauvegarder avant de fermer? APPCLOSE_SAVE - &Sauvegarder && Fermer + &Oui APPCLOSE_CLOSE - &Fermer sans sauvegarder + &Non APPCLOSE_CANCEL diff --git a/src/LightApp/resources/LightApp_msg_ja.ts b/src/LightApp/resources/LightApp_msg_ja.ts index b294bed04..24be3884f 100644 --- a/src/LightApp/resources/LightApp_msg_ja.ts +++ b/src/LightApp/resources/LightApp_msg_ja.ts @@ -56,16 +56,15 @@ CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS STUDYCLOSE_DESCRIPTION - 既存のスタディを閉じる必要があります。閉じますか? - + The current study has unsaved changes. Would you like to save before closing it? APPCLOSE_SAVE - 保存して閉じる(&S) + はい(&Y) APPCLOSE_CLOSE - 保存せずに閉じる(&C) + いいえ(&N) APPCLOSE_CANCEL diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx index 3bf337a96..0b8446dfc 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx @@ -603,7 +603,6 @@ void PyModuleHelper::XmlHandler::insertPopupItems( QDomNode& parentNode, QMenu* SALOME GUI modules. */ -PyModuleHelper::InterpMap PyModuleHelper::myInterpMap; LightApp_Module* PyModuleHelper::myInitModule = 0; /*! @@ -1678,31 +1677,15 @@ QString PyModuleHelper::engineIOR() const /*! \brief Initialize python subinterpreter (one per study). \internal - \param studyId study ID */ -void PyModuleHelper::initInterp( int studyId ) +void PyModuleHelper::initInterp() { FuncMsg fmsg( "--- PyModuleHelper::initInterp()" ); - // check study Id - if ( !studyId ) { - // Error! Study Id must not be 0! - myInterp = 0; - return; - } - QMutexLocker ml( &myInitMutex ); - // try to find the subinterpreter - if ( myInterpMap.contains( studyId ) ) { - // found! - myInterp = myInterpMap[ studyId ]; - return; - } - myInterp = new SALOME_PYQT_PyInterp(); myInterp->initialize(); - myInterpMap[ studyId ] = myInterp; #ifndef GUI_DISABLE_CORBA if ( !SUIT_PYTHON::initialized ) { @@ -1719,7 +1702,7 @@ void PyModuleHelper::initInterp( int studyId ) } // ... then call a method int embedded = 1; - PyObjWrapper aRes( PyObject_CallMethod( aMod, (char*)"salome_init", (char*)"ii", studyId, embedded ) ); + PyObjWrapper aRes( PyObject_CallMethod( aMod, (char*)"salome_init", (char*)"ii", embedded ) ); if ( !aRes ) { // Error! PyErr_Print(); @@ -1852,10 +1835,9 @@ void PyModuleHelper::internalInitialize( CAM_Application* app ) LightApp_Study* aStudy = dynamic_cast( app->activeStudy() ); if ( !aStudy ) return; - int aStudyId = aStudy ? aStudy->id() : 0; // initialize Python subinterpreter (on per study) and put it in variable - initInterp( aStudyId ); + initInterp(); if ( !myInterp ) return; // Error @@ -1953,10 +1935,11 @@ void PyModuleHelper::internalActivate( SUIT_Study* study ) // get study Id LightApp_Study* aStudy = dynamic_cast( study ); - int aStudyId = aStudy ? aStudy->id() : 0; + if ( !aStudy ) + return; // initialize Python subinterpreter (on per study) and put it in variable - initInterp( aStudyId ); + initInterp(); if ( !myInterp ) { myLastActivateStatus = false; return; // Error @@ -2005,10 +1988,11 @@ void PyModuleHelper::internalCustomize( SUIT_Study* study ) // get study Id LightApp_Study* aStudy = dynamic_cast( study ); - int aStudyId = aStudy ? aStudy->id() : 0; + if ( !aStudy ) + return; // initialize Python subinterpreter (on per study) and put it in variable - initInterp( aStudyId ); + initInterp(); if ( !myInterp ) { myLastActivateStatus = false; return; // Error @@ -2081,7 +2065,8 @@ void PyModuleHelper::internalClosedStudy( SUIT_Study* theStudy ) // Get study Id // get study Id LightApp_Study* aStudy = dynamic_cast( theStudy ); - int aStudyId = aStudy ? aStudy->id() : 0; + if ( !aStudy ) + return; // check that Python subinterpreter is initialized and Python module is imported if ( !myInterp || !myPyModule ) { @@ -2090,7 +2075,7 @@ void PyModuleHelper::internalClosedStudy( SUIT_Study* theStudy ) } // then call Python module's deactivate() method if ( PyObject_HasAttrString( myPyModule , (char*)"closeStudy" ) ) { - PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"closeStudy", (char*)"i", aStudyId ) ); + PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"closeStudy", (char*)"i" ) ); if( !res ) { PyErr_Print(); } @@ -2149,12 +2134,11 @@ void PyModuleHelper::internalStudyChanged( SUIT_Study* study ) // get study Id LightApp_Study* aStudy = dynamic_cast( study ); - int id = aStudy ? aStudy->id() : 0; - - fmsg.message( QString( "study id = %1" ).arg( id ) ); + if ( !aStudy ) + return; // initialize Python subinterpreter (on per study) and put it in variable - initInterp( id ); + initInterp(); if ( !myInterp ) return; // Error @@ -2171,7 +2155,7 @@ void PyModuleHelper::internalStudyChanged( SUIT_Study* study ) // call Python module's activeStudyChanged() method if ( PyObject_HasAttrString( myPyModule, (char*)"activeStudyChanged" ) ) { - PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"activeStudyChanged", (char*)"i", id ) ); + PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"activeStudyChanged", (char*)"i" ) ); if( !res ) { PyErr_Print(); } @@ -2198,7 +2182,7 @@ void PyModuleHelper::internalActionActivated( int id ) return; // Error if ( PyObject_HasAttrString( myPyModule, (char*)"OnGUIEvent" ) ) { - PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"OnGUIEvent", (char*)"i", id ) ); + PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"OnGUIEvent", (char*)"i" ) ); if( !res ) { PyErr_Print(); } diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h index d49485080..757867254 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h @@ -54,9 +54,6 @@ private: class XmlHandler; class InitLocker; - typedef QMap InterpMap; - - static InterpMap myInterpMap; //!< study to Python subinterpreter map static LightApp_Module* myInitModule; //!< Python GUI being initialized (not zero only during the initialization) LightApp_Module* myModule; //!< GUI module @@ -109,7 +106,7 @@ public slots: void onObjectBrowserClicked(SUIT_DataObject*, int); private: - void initInterp( int ); + void initInterp(); void importModule(); void setWorkSpace(); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 0d91d941d..69544f95a 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -678,26 +678,23 @@ bool SalomePyQt::activateModule( const QString& modName ) \brief updateSelection update selection flag (not used) \sa getActiveStudy() */ -void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection ) +void SalomePyQt::updateObjBrowser( bool updateSelection ) { class TEvent: public SALOME_Event { - int myStudyId; bool myUpdateSelection; public: - TEvent( const int studyId, bool updateSelection ) - : myStudyId( studyId ), myUpdateSelection( updateSelection ) {} + TEvent( bool updateSelection ) + : myUpdateSelection( updateSelection ) {} virtual void Execute() { if ( SUIT_Session::session() ) { - if ( getActiveStudy() && myStudyId <= 0 ) - myStudyId = getActiveStudy()->id(); - if ( myStudyId > 0 ) { + if ( getActiveStudy() ) { QList apps = SUIT_Session::session()->applications(); QList::Iterator it; for( it = apps.begin(); it != apps.end(); ++it ) { LightApp_Application* anApp = dynamic_cast( *it ); - if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) { + if ( anApp && anApp->activeStudy() ) { anApp->updateObjectBrowser(); return; } @@ -706,7 +703,7 @@ void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection ) } } }; - ProcessVoidEvent( new TEvent( studyId, updateSelection ) ); + ProcessVoidEvent( new TEvent( updateSelection ) ); } diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index f508b046f..72f45703d 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -174,7 +174,7 @@ public: static const QString getActiveComponent(); static PyObject* getActivePythonModule(); static bool activateModule( const QString& ); - static void updateObjBrowser( const int = 0, bool = true ); + static void updateObjBrowser( bool = true ); static bool isModified(); static void setModified( bool ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 662aa4858..c6d3bd3dc 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -276,7 +276,7 @@ public: static const QString getActiveComponent() /ReleaseGIL/ ; static SIP_PYOBJECT getActivePythonModule() /ReleaseGIL/ ; static bool activateModule( const QString& ) /ReleaseGIL/ ; - static void updateObjBrowser( const int = 0, bool = true ) /ReleaseGIL/ ; + static void updateObjBrowser( bool = true ) /ReleaseGIL/ ; static bool isModified() /ReleaseGIL/ ; static void setModified( bool ) /ReleaseGIL/ ; diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index fa6c6ab7b..de451cc60 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -406,8 +406,6 @@ void SalomeApp_Application::onLoadDoc() { QString studyName; - std::vector List = studyMgr()->GetOpenStudies(); - // rnv: According to the single-study approach on the server side // can be only one study. So if it is exists connect to them, // overwise show warning message: "No active study on the server" @@ -439,14 +437,14 @@ void SalomeApp_Application::onLoadDoc() return; */ - if(List.size() <= 0) { + if(!activeStudy()) { SUIT_MessageBox::warning( desktop(), QObject::tr("WRN_WARNING"), QObject::tr("WRN_NO_STUDY_ON SERV") ); return; } - studyName = List[0].c_str(); + studyName = activeStudy()->studyName(); #ifndef WIN32 // this code replaces marker of windows drive and path become invalid therefore @@ -555,15 +553,10 @@ bool SalomeApp_Application::onLoadDoc( const QString& aName ) /*!SLOT. Parse message for desktop.*/ void SalomeApp_Application::onDesktopMessage( const QString& message ) { - if (message.indexOf("studyCreated:") == 0) { - // Enable 'Connect' action + if (message.indexOf("studyCreated") == 0) { updateCommandsStatus(); } - else if (message.indexOf("studyClosed:") == 0) { - /* message also contains ID of the closed study, - but as soon as SALOME is mono-study application for the moment, - this ID is not needed now.*/ - //long aStudyId = message.section(':', 1).toLong(); + if (message.indexOf("studyCleared") == 0) { // Disconnect GUI from active study, because it was closed on DS side. closeActiveDoc( false ); // Disable 'Connect' action @@ -595,7 +588,7 @@ void SalomeApp_Application::onCopy() { _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); try { - studyMgr()->Copy(so); + stdDS->Copy(so); onSelectionChanged(); } catch(...) { @@ -628,7 +621,7 @@ void SalomeApp_Application::onPaste() { _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); try { - studyMgr()->Paste(so); + stdDS->Paste(so); updateObjectBrowser( true ); updateActions(); //SRN: BugID IPAL9377, case 3 } @@ -692,8 +685,8 @@ void SalomeApp_Application::onSelectionChanged() _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); if ( so ) { - canCopy = canCopy || studyMgr()->CanCopy(so); - canPaste = canPaste || studyMgr()->CanPaste(so); + canCopy = canCopy || stdDS->CanCopy(so); + canPaste = canPaste || stdDS->CanPaste(so); } } } @@ -804,7 +797,7 @@ void SalomeApp_Application::updateCommandsStatus() // Connect study menu a = action( ConnectId ); if( a ) - a->setEnabled( !activeStudy() && studyMgr()->GetOpenStudies().size() > 0 ); + a->setEnabled( !activeStudy() ); // Disconnect study menu a = action( DisconnectId ); @@ -1200,12 +1193,10 @@ int SalomeApp_Application::openChoice( const QString& aName ) if ( QFileInfo( aName ).exists() ) { if ( choice == OpenNew ) { // The document isn't already open. bool exist = false; - std::vector lst = studyMgr()->GetOpenStudies(); - for ( uint i = 0; i < lst.size() && !exist; i++ ) { - if ( aName == QString( lst[i].c_str() ) ) - exist = true; - } - // The document already exists in the study manager. + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + if ( aName == study->studyDS()->Name().c_str() ) + exist = true; + // The document already exists in the study. // Do you want to reload it? if ( exist ) { int answer = SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYEXIST" ).arg( aName ), @@ -1234,10 +1225,11 @@ bool SalomeApp_Application::openAction( const int aChoice, const QString& aName { case OpenRefresh: { - _PTR(Study) aStudy = studyMgr()->GetStudyByName( aName.toStdString() ); + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + _PTR(Study) aStudy = study->studyDS(); if ( aStudy ) { - studyMgr()->Close( aStudy ); + aStudy->Clear(); choice = OpenNew; } } @@ -1313,11 +1305,15 @@ CORBA::ORB_var SalomeApp_Application::orb() } /*!Create and return SALOMEDS_StudyManager.*/ -SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr() +SALOMEDSClient_Study* SalomeApp_Application::getStudy() { - static _PTR(StudyManager) _sm; - if(!_sm) _sm = ClientFactory::StudyManager(); - return _sm.get(); + static _PTR(Study) _study; + if(!_study) { + CORBA::Object_var aSObject = namingService()->Resolve("/Study"); + SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(aSObject); + _study = ClientFactory::Study(aStudy); + } + return _study.get(); } /*!Create and return SALOME_NamingService.*/ @@ -2064,7 +2060,7 @@ void SalomeApp_Application::afterCloseDoc() bool SalomeApp_Application::checkExistingDoc() { bool result = LightApp_Application::checkExistingDoc(); - if ( result && !activeStudy() ) { + /*if ( result && !activeStudy() ) { SALOMEDSClient_StudyManager* aMgr = studyMgr(); if ( aMgr ) { std::vector List = studyMgr()->GetOpenStudies(); @@ -2073,7 +2069,7 @@ bool SalomeApp_Application::checkExistingDoc() result = false; } } - } + }*/ // NB!!! return result; } diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index c2b62929d..5633d46d1 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -98,7 +98,7 @@ public: virtual bool checkExistingDoc(); static CORBA::ORB_var orb(); - static SALOMEDSClient_StudyManager* studyMgr(); + static SALOMEDSClient_Study* getStudy(); static SALOME_NamingService* namingService(); static SALOME_LifeCycleCORBA* lcc(); diff --git a/src/SalomeApp/SalomeApp_DataObject.cxx b/src/SalomeApp/SalomeApp_DataObject.cxx index a6fd9c005..2cabd00fd 100644 --- a/src/SalomeApp/SalomeApp_DataObject.cxx +++ b/src/SalomeApp/SalomeApp_DataObject.cxx @@ -291,7 +291,7 @@ QString SalomeApp_DataObject::toolTip( const int /*id*/ ) const if ( !CORBA::is_nil(aComponent) && aComponent->hasObjectInfo() ) { LightApp_RootObject* aRoot = dynamic_cast( root() ); if ( aRoot && aRoot->study() ) { - CORBA::String_var data = aComponent->getObjectInfo( aRoot->study()->id(), entry().toLatin1().constData()); + CORBA::String_var data = aComponent->getObjectInfo( entry().toLatin1().constData()); QString objInfo = data.in(); QStringList l; l << name(); diff --git a/src/SalomeApp/SalomeApp_Engine_i.cxx b/src/SalomeApp/SalomeApp_Engine_i.cxx index 16c1fcc29..3d5776a99 100644 --- a/src/SalomeApp/SalomeApp_Engine_i.cxx +++ b/src/SalomeApp/SalomeApp_Engine_i.cxx @@ -68,40 +68,34 @@ SALOMEDS::TMPFile* SalomeApp_Engine_i::Save (SALOMEDS::SComponent_ptr theCompone if (CORBA::is_nil(theComponent) || CORBA::is_nil(theComponent->GetStudy())) return aStreamFile._retn(); - const int studyId = theComponent->GetStudy()->StudyId(); - // Get a temporary directory to store a file //std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir(); - if (myMap.count(studyId)) { - std::string componentName (theComponent->ComponentDataType()); - - // Error somewhere outside - Save() called with - // wrong SComponent instance - if ( myComponentName != componentName ) - return aStreamFile._retn(); + std::string componentName (theComponent->ComponentDataType()); - const ListOfFiles& listOfFiles = myMap[studyId]; + // Error somewhere outside - Save() called with + // wrong SComponent instance + if ( myComponentName != componentName ) + return aStreamFile._retn(); - // listOfFiles must contain temporary directory name in its first item - // and names of files (relatively the temporary directory) in the others - const int n = listOfFiles.size() - 1; + // listOfFiles must contain temporary directory name in its first item + // and names of files (relatively the temporary directory) in the others + const int n = myListOfFiles.size() - 1; - if (n > 0) { // there are some files, containing persistent data of the component - std::string aTmpDir = listOfFiles[0]; + if (n > 0) { // there are some files, containing persistent data of the component + std::string aTmpDir = myListOfFiles[0]; - // Create a list to store names of created files - SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; - aSeq->length(n); - for (int i = 0; i < n; i++) - aSeq[i] = CORBA::string_dup(listOfFiles[i + 1].c_str()); + // Create a list to store names of created files + SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; + aSeq->length(n); + for (int i = 0; i < n; i++) + aSeq[i] = CORBA::string_dup(myListOfFiles[i + 1].c_str()); - // Convert a file to the byte stream - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile); + // Convert a file to the byte stream + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile); - // Remove the files and tmp directory, created by the component storage procedure - if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); - } + // Remove the files and tmp directory, created by the component storage procedure + if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true); } return aStreamFile._retn(); @@ -122,8 +116,6 @@ CORBA::Boolean SalomeApp_Engine_i::Load (SALOMEDS::SComponent_ptr theComponent, if ( myComponentName != componentName ) return false; - const int studyId = theComponent->GetStudy()->StudyId(); - // Create a temporary directory for the component's data files std::string aTmpDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir(); @@ -139,36 +131,27 @@ CORBA::Boolean SalomeApp_Engine_i::Load (SALOMEDS::SComponent_ptr theComponent, for (int i = 1; i < n; i++) listOfFiles[i] = std::string(aSeq[i - 1]); - SetListOfFiles(listOfFiles, studyId); + SetListOfFiles(listOfFiles); return true; } -SalomeApp_Engine_i::ListOfFiles SalomeApp_Engine_i::GetListOfFiles (const int theStudyId) +SalomeApp_Engine_i::ListOfFiles SalomeApp_Engine_i::GetListOfFiles() { - ListOfFiles aListOfFiles; - - if (myMap.find(theStudyId) != myMap.end()) - { - aListOfFiles = myMap[theStudyId]; - } - - return aListOfFiles; + return myListOfFiles; } -void SalomeApp_Engine_i::SetListOfFiles (const ListOfFiles& theListOfFiles, - const int theStudyId) +void SalomeApp_Engine_i::SetListOfFiles (const ListOfFiles& theListOfFiles) { - myMap[theStudyId] = theListOfFiles; + myListOfFiles = theListOfFiles; } /*! * DumpPython implementation for light modules */ -Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, - CORBA::Boolean isMultiFile, - CORBA::Boolean& isValidScript) +Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, + CORBA::Boolean& isValidScript) { MESSAGE("SalomeApp_Engine_i::DumpPython(): myComponentName = "<< myComponentName << ", this = " << this); @@ -182,24 +165,13 @@ Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Object_ptr theStudy, aStreamFile[0] = '\0'; isValidScript = true; - if (CORBA::is_nil(theStudy)) - return aStreamFile._retn(); - - SALOMEDS::Study_var studyDS = SALOMEDS::Study::_narrow( theStudy ); - const int studyId = studyDS->StudyId(); - - if (!myMap.count(studyId)) - return aStreamFile._retn(); - - ListOfFiles listOfFiles = myMap[studyId]; - // listOfFiles must contain temporary directory name in its first item // and names of files (relatively the temporary directory) in the others - if ( listOfFiles.size() < 2 ) + if ( myListOfFiles.size() < 2 ) return aStreamFile._retn(); // there are some files, containing persistent data of the component - QString aTmpPath( listOfFiles.front().c_str() ); + QString aTmpPath( myListOfFiles.front().c_str() ); QDir aTmpDir( aTmpPath ); if ( !aTmpDir.exists() ) return aStreamFile._retn(); @@ -208,8 +180,8 @@ Engines::TMPFile* SalomeApp_Engine_i::DumpPython(CORBA::Object_ptr theStudy, QStringList aFilePaths; QList aFileSizes; qint64 aBuffSize = 0; - ListOfFiles::const_iterator aFIt = listOfFiles.begin(); - ListOfFiles::const_iterator aFEnd = listOfFiles.end(); + ListOfFiles::const_iterator aFIt = myListOfFiles.begin(); + ListOfFiles::const_iterator aFEnd = myListOfFiles.end(); aFIt++; for (; aFIt != aFEnd; aFIt++){ QString aFileName( (*aFIt).c_str() ); diff --git a/src/SalomeApp/SalomeApp_Engine_i.h b/src/SalomeApp/SalomeApp_Engine_i.h index ec2641913..2669c5134 100644 --- a/src/SalomeApp/SalomeApp_Engine_i.h +++ b/src/SalomeApp/SalomeApp_Engine_i.h @@ -55,17 +55,15 @@ public: const char* theURL, bool isMultiFile ); - virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, - CORBA::Boolean isPublished, + virtual Engines::TMPFile* DumpPython(CORBA::Boolean isPublished, CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript); public: typedef std::vector ListOfFiles; - ListOfFiles GetListOfFiles (const int theStudyId); - void SetListOfFiles (const ListOfFiles& theListOfFiles, - const int theStudyId); + ListOfFiles GetListOfFiles (); + void SetListOfFiles (const ListOfFiles& theListOfFiles); static std::string EngineIORForComponent( const char* theComponentName, bool toCreate ); @@ -98,8 +96,7 @@ private: static PortableServer::POA_var poa(); static SALOME_NamingService* namingService(); private: - typedef std::map MapOfListOfFiles; - MapOfListOfFiles myMap; + ListOfFiles myListOfFiles; std::string myComponentName; }; diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 0bd5244e3..d7e793b70 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -418,17 +418,6 @@ void SalomeApp_Study::onNoteBookVarUpdate( QString theVarName) } #endif -/*! - Gets study id. -*/ -int SalomeApp_Study::id() const -{ - int id = -1; - if ( studyDS() ) - id = studyDS()->StudyId(); - return id; -} - /*! Get study name. */ @@ -464,13 +453,13 @@ bool SalomeApp_Study::createDocument( const QString& theStr ) MESSAGE( "createDocument" ); // initialize myStudyDS, read HDF file - QString aName = newStudyName(); + QString aName = studyName(); _PTR(Study) study; bool showError = !application()->property("open_study_from_command_line").isValid() || !application()->property("open_study_from_command_line").toBool(); try { - study = _PTR(Study)( SalomeApp_Application::studyMgr()->NewStudy( aName.toUtf8().data() ) ); + study = _PTR(Study)( SalomeApp_Application::getStudy() ); } catch(const SALOME_Exception& ex) { application()->putInfo(tr(ex.what())); @@ -521,12 +510,12 @@ bool SalomeApp_Study::openDocument( const QString& theFileName ) { MESSAGE( "openDocument" ); - // initialize myStudyDS, read HDF file - _PTR(Study) study; - bool showError = !application()->property("open_study_from_command_line").isValid() || + // read HDF file + bool res = false; + bool showError = !application()->property("open_study_from_command_line").isValid() || !application()->property("open_study_from_command_line").toBool(); try { - study = _PTR(Study) ( SalomeApp_Application::studyMgr()->Open( theFileName.toUtf8().data() ) ); + res = studyDS()->Open( theFileName.toUtf8().data() ); } catch(const SALOME_Exception& ex) { application()->putInfo(tr(ex.what())); @@ -534,7 +523,7 @@ bool SalomeApp_Study::openDocument( const QString& theFileName ) SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), tr("ERR_ERROR"), tr(ex.what())); return false; - } + } catch(...) { application()->putInfo(tr("OPEN_DOCUMENT_PROBLEM")); if ( showError ) @@ -543,11 +532,9 @@ bool SalomeApp_Study::openDocument( const QString& theFileName ) return false; } - if ( !study ) + if ( !res) return false; - setStudyDS( study ); - setRoot( new SalomeApp_RootObject( this ) ); // create myRoot // update loaded data models: call open() and update() on them. @@ -569,10 +556,10 @@ bool SalomeApp_Study::openDocument( const QString& theFileName ) myStudyDS->attach(myObserver->_this(),true); #endif - bool res = CAM_Study::openDocument( theFileName ); + res = CAM_Study::openDocument( theFileName ); emit opened( this ); - study->IsSaved(true); + studyDS()->IsSaved(true); bool restore = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", true ); if ( restore ) { @@ -594,7 +581,7 @@ bool SalomeApp_Study::loadDocument( const QString& theStudyName ) MESSAGE( "loadDocument" ); // obtain myStudyDS from StudyManager - _PTR(Study) study ( SalomeApp_Application::studyMgr()->GetStudyByName( theStudyName.toUtf8().data() ) ); + _PTR(Study) study = studyDS(); if ( !study ) return false; @@ -676,8 +663,8 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); bool isAscii = resMgr->booleanValue( "Study", "ascii_file", false ); bool res = (isAscii ? - SalomeApp_Application::studyMgr()->SaveAsASCII( theFileName.toUtf8().data(), studyDS(), isMultiFile ) : - SalomeApp_Application::studyMgr()->SaveAs ( theFileName.toUtf8().data(), studyDS(), isMultiFile )) + studyDS()->SaveAsASCII( theFileName.toUtf8().data(), isMultiFile ) : + studyDS()->SaveAs ( theFileName.toUtf8().data(), isMultiFile )) && CAM_Study::saveDocumentAs( theFileName ); res = res && saveStudyData(theFileName); @@ -721,8 +708,8 @@ bool SalomeApp_Study::saveDocument() bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false ); bool isAscii = resMgr->booleanValue( "Study", "ascii_file", false ); bool res = (isAscii ? - SalomeApp_Application::studyMgr()->SaveASCII( studyDS(), isMultiFile ) : - SalomeApp_Application::studyMgr()->Save ( studyDS(), isMultiFile )) && CAM_Study::saveDocument(); + studyDS()->SaveASCII( isMultiFile ) : + studyDS()->Save ( isMultiFile )) && CAM_Study::saveDocument(); res = res && saveStudyData(studyName()); if ( res ) @@ -748,7 +735,7 @@ void SalomeApp_Study::closeDocument(bool permanently) SUIT_Desktop* desk = SUIT_Session::session()->activeApplication()->desktop(); bool isBlocked = desk->signalsBlocked(); desk->blockSignals( true ); - SalomeApp_Application::studyMgr()->Close( studyPtr ); + studyDS()->Clear(); desk->blockSignals( isBlocked ); #ifndef DISABLE_PYCONSOLE SalomeApp_Application* app = dynamic_cast( application() ); @@ -1123,28 +1110,6 @@ bool SalomeApp_Study::openDataModel( const QString& studyName, CAM_DataModel* dm return false; } -/*! - Create new study name. -*/ -QString SalomeApp_Study::newStudyName() const -{ - std::vector studies = SalomeApp_Application::studyMgr()->GetOpenStudies(); - QString prefix( "Study%1" ), newName, curName; - int i = 1, j, n = studies.size(); - while ( newName.isEmpty() ){ - curName = prefix.arg( i ); - for ( j = 0 ; j < n; j++ ){ - if ( !strcmp( studies[j].c_str(), curName.toLatin1() ) ) - break; - } - if ( j == n ) - newName = curName; - else - i++; - } - return newName; -} - /*! Note that this method does not create or activate SalomeApp_Engine_i instance, therefore it can be called safely for any kind of module, but for full @@ -1157,7 +1122,7 @@ std::vector SalomeApp_Study::GetListOfFiles( const char* theModuleN // Issue 21377 - using separate engine for each type of light module SalomeApp_Engine_i* aDefaultEngine = SalomeApp_Engine_i::GetInstance( theModuleName, false ); if (aDefaultEngine) - return aDefaultEngine->GetListOfFiles(id()); + return aDefaultEngine->GetListOfFiles(); std::vector aListOfFiles; return aListOfFiles; @@ -1177,7 +1142,7 @@ void SalomeApp_Study::SetListOfFiles ( const char* theModuleName, // Issue 21377 - using separate engine for each type of light module SalomeApp_Engine_i* aDefaultEngine = SalomeApp_Engine_i::GetInstance( theModuleName, false ); if (aDefaultEngine) - aDefaultEngine->SetListOfFiles(theListOfFiles, id()); + aDefaultEngine->SetListOfFiles(theListOfFiles); } /*! @@ -1219,8 +1184,8 @@ void SalomeApp_Study::RemoveTemporaryFiles ( const char* theModuleName, const bo */ void SalomeApp_Study::updateFromNotebook( const QString& theFileName, bool isSaved ) { - setStudyName(theFileName); - studyDS()->Name(theFileName.toStdString()); +// setStudyName(theFileName); +// studyDS()->Name(theFileName.toStdString()); NB!!! setIsSaved( isSaved ); } #endif diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index cf93e4056..2f9f48ef2 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -43,7 +43,6 @@ public: SalomeApp_Study( SUIT_Application* ); virtual ~SalomeApp_Study(); - virtual int id() const; virtual QString studyName() const; virtual bool createDocument( const QString& ); @@ -112,9 +111,6 @@ protected slots: void onNoteBookVarUpdate( QString theVarName ); #endif -private: - QString newStudyName() const; - private: _PTR(Study) myStudyDS; Observer_i* myObserver; diff --git a/src/Session/Session_ServerCheck.cxx b/src/Session/Session_ServerCheck.cxx index 1575acb72..582374cd7 100644 --- a/src/Session/Session_ServerCheck.cxx +++ b/src/Session/Session_ServerCheck.cxx @@ -354,12 +354,12 @@ void Session_ServerCheck::run() SALOME_NamingService &NS = *SINGLETON_::Instance(); ASSERT( SINGLETON_::IsAlreadyExisting() ); NS.init_orb( orb ); - CORBA::Object_var obj = NS.Resolve( "/myStudyManager" ); - SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow( obj ); - if ( !CORBA::is_nil( studyManager ) ) { - MESSAGE( "/myStudyManager is found" ); - studyManager->ping(); - MESSAGE( "StudyManager was activated" ); + CORBA::Object_var obj = NS.Resolve( "/myStudy" ); + SALOMEDS::Study_var study = SALOMEDS::Study::_narrow( obj ); + if ( !CORBA::is_nil( study ) ) { + MESSAGE( "/myStudy is found" ); + study->ping(); + MESSAGE( "Study was activated" ); setStep( ++current * myAttempts ); break; } diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx index ee1c1f681..0ca79c9bb 100755 --- a/src/Session/Session_ServerThread.cxx +++ b/src/Session/Session_ServerThread.cxx @@ -142,7 +142,7 @@ void Session_ServerThread::Init() } case 4: // Session { - NamingService_WaitForServerReadiness(_NS,"/myStudyManager"); + NamingService_WaitForServerReadiness(_NS,"/Study"); std::string containerName = "/Containers/"; containerName = containerName + Kernel_Utils::GetHostname(); containerName = containerName + "/FactoryServer"; @@ -215,7 +215,7 @@ void Session_ServerThread::ActivateSALOMEDS(int argc, // counted objects, they will be deleted by the POA when they are no // longer needed. - ClientFactory::createStudyManager(_orb,_root_poa); +// ClientFactory::createStudyManager(_orb,_root_poa); } catch(CORBA::SystemException&) { INFOS( "Caught CORBA::SystemException." );