From 9e98bec12318798b0ccaa2a4c2bb973ddd0a6e85 Mon Sep 17 00:00:00 2001 From: rnv Date: Wed, 7 May 2014 10:53:48 +0400 Subject: [PATCH] Implementation a mono-study approach in the GUI. --- src/LightApp/LightApp_Application.cxx | 34 ++++--- src/LightApp/LightApp_Application.h | 3 + src/SalomeApp/SalomeApp_Application.cxx | 105 ++++++++++++++++---- src/SalomeApp/SalomeApp_Application.h | 2 + src/SalomeApp/resources/SalomeApp_msg_en.ts | 18 +++- 5 files changed, 127 insertions(+), 35 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 976f9c803..2640effb9 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -876,11 +876,12 @@ void LightApp_Application::onNewDoc() //asl: fix for 0020515 if ( activeStudy() ) { saveDockWindowsState(); + } + #ifdef SINGLE_DESKTOP - if ( !closeDoc() ) - return; + if ( !checkExistingDoc() ) + return; #endif - } CAM_Application::onNewDoc(); } @@ -892,15 +893,14 @@ void LightApp_Application::onOpenDoc() { SUIT_Study* study = activeStudy(); saveDockWindowsState(); - if (study) { + #ifdef SINGLE_DESKTOP - if ( !closeDoc() ) - return; + if ( !checkExistingDoc() ) + return; #endif - } - + CAM_Application::onOpenDoc(); - + if ( !study ) // new study will be create in THIS application { updateWindows(); @@ -914,15 +914,13 @@ void LightApp_Application::onOpenDoc() */ bool LightApp_Application::onOpenDoc( const QString& aName ) { - if ( activeStudy() ) { #ifdef SINGLE_DESKTOP - if ( !closeDoc() ) - return false; + if ( !checkExistingDoc() ) + return false; #endif - } // We should take mru action first because this application instance can be deleted later. QtxMRUAction* mru = ::qobject_cast( action( MRUId ) ); - + bool res = CAM_Application::onOpenDoc( aName ); if ( mru ) @@ -4425,3 +4423,11 @@ void LightApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) aStudy->setVisibilityStateForAll( Qtx::UnpresentableState ); } } + +/*! + Check existing document. +*/ +bool LightApp_Application::checkExistingDoc() { + return true; +} + diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 1fcef083d..93b325c8a 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -179,6 +179,8 @@ public: void updateVisibilityState( DataObjectList& theList, SUIT_ViewModel* theViewModel ); + virtual bool checkExistingDoc(); + signals: void studyOpened(); void studySaved(); @@ -191,6 +193,7 @@ public slots: virtual void onHelpContextModule( const QString&, const QString&, const QString& = QString() ); virtual void onNewDoc(); virtual void onOpenDoc(); + virtual void onHelpAbout(); virtual bool onOpenDoc( const QString& ); virtual void onCopy(); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 6bab8edef..4182bfcb1 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -320,12 +320,13 @@ void SalomeApp_Application::createActions() tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ), /*Qt::SHIFT+Qt::Key_D*/0, desk, false, this, SLOT( onRegDisplay() ) ); - //SRN: BugID IPAL9021, add an action "Load" - createAction( FileLoadId, tr( "TOT_DESK_FILE_LOAD" ), - resourceMgr()->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ), - tr( "MEN_DESK_FILE_LOAD" ), tr( "PRP_DESK_FILE_LOAD" ), - Qt::CTRL+Qt::Key_L, desk, false, this, SLOT( onLoadDoc() ) ); - //SRN: BugID IPAL9021: End + //rnv commented : implementation of the mono-study in GUI + // + //createAction( FileLoadId, tr( "TOT_DESK_FILE_LOAD" ), + // resourceMgr()->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ), + // tr( "MEN_DESK_FILE_LOAD" ), tr( "PRP_DESK_FILE_LOAD" ), + // Qt::CTRL+Qt::Key_L, desk, false, this, SLOT( onLoadDoc() ) ); + #ifdef WITH_SIMANIO if (myIsSiman) { @@ -345,7 +346,7 @@ void SalomeApp_Application::createActions() // creation of menu item is moved to VISU // createMenu( SaveGUIStateId, fileMenu, 10, -1 ); - createMenu( FileLoadId, fileMenu, 0 ); //SRN: BugID IPAL9021, add a menu item "Load" + // createMenu( FileLoadId, fileMenu, 0 ); #ifdef WITH_SIMANIO if (myIsSiman) { @@ -423,6 +424,11 @@ void SalomeApp_Application::onLoadDoc() 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" + + /* SUIT_Session* aSession = SUIT_Session::session(); QList aAppList = aSession->applications(); @@ -444,10 +450,19 @@ void SalomeApp_Application::onLoadDoc() if ( !isAlreadyOpen ) unloadedStudies << studyName; } - studyName = SalomeApp_LoadStudiesDlg::selectStudy( desktop(), unloadedStudies ); if ( studyName.isEmpty() ) return; + */ + + if(List.size() <= 0) { + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_NO_STUDY_ON SERV") ); + return; + } + + studyName = List[0].c_str(); #ifndef WIN32 // this code replaces marker of windows drive and path become invalid therefore @@ -1138,15 +1153,16 @@ int SalomeApp_Application::closeChoice( const QString& docName ) { int answer = SUIT_MessageBox::question( desktop(), tr( "APPCLOSE_CAPTION" ), tr( "APPCLOSE_DESCRIPTION" ).arg( docName ), tr ("APPCLOSE_SAVE"), tr ("APPCLOSE_CLOSE"), - tr ("APPCLOSE_UNLOAD"), tr ("APPCLOSE_CANCEL"), 0 ); + //tr ("APPCLOSE_UNLOAD"), + tr ("APPCLOSE_CANCEL"), 0 ); int res = CloseCancel; if ( answer == 0 ) res = CloseSave; else if ( answer == 1 ) res = CloseDiscard; - else if ( answer == 2 ) - res = CloseUnload; + // else if ( answer == 2 ) + // res = CloseUnload; return res; } @@ -1249,7 +1265,10 @@ bool SalomeApp_Application::openAction( const int aChoice, const QString& aName QMap SalomeApp_Application::activateModuleActions() const { QMap opmap = LightApp_Application::activateModuleActions(); - opmap.insert( LoadStudyId, tr( "ACTIVATE_MODULE_OP_LOAD" ) ); + + // rnv commented : implementation of the mono-study in GUI + // opmap.insert( LoadStudyId, tr( "ACTIVATE_MODULE_OP_LOAD" ) ); + opmap.insert( NewAndScriptId, tr( "ACTIVATE_MODULE_OP_SCRIPT" ) ); return opmap; } @@ -1564,10 +1583,10 @@ void SalomeApp_Application::onStudyCreated( SUIT_Study* study ) { LightApp_Application::onStudyCreated( study ); -#ifndef DISABLE_PYCONSOLE - desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), - windowDock( getWindow( WT_ObjectBrowser ) ) ); -#endif +//#ifndef DISABLE_PYCONSOLE +// desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), +// windowDock( getWindow( WT_ObjectBrowser ) ) ); +//#endif loadDockWindowsState(); @@ -1579,10 +1598,10 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* study ) { LightApp_Application::onStudyOpened( study ); -#ifndef DISABLE_PYCONSOLE - desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), - windowDock( getWindow( WT_ObjectBrowser ) ) ); -#endif +//#ifndef DISABLE_PYCONSOLE +// desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), +// windowDock( getWindow( WT_ObjectBrowser ) ) ); +//#endif loadDockWindowsState(); @@ -2025,3 +2044,49 @@ void SalomeApp_Application::afterCloseDoc() #endif LightApp_Application::afterCloseDoc(); } + +/* + Asks to close existing document. +*/ +bool SalomeApp_Application::checkExistingDoc() { + bool result = true; + if( activeStudy() ) { + int answer = SUIT_MessageBox::question( desktop(), + tr( "APPCLOSE_CAPTION" ), + tr( "STUDYCLOSE_DESCRIPTION" ), + tr( "APPCLOSE_SAVE" ), + tr( "APPCLOSE_CLOSE" ), + tr( "APPCLOSE_CANCEL" ), 0 ); + if(answer == 0) { + if ( activeStudy()->isSaved() ) { + onSaveDoc(); + closeDoc( false ); + } else if ( onSaveAsDoc() ) { + if( !closeDoc( false ) ) { + result = false; + } + } else { + result = false; + } + } + else if( answer == 1 ) { + closeDoc( false ); + } else if( answer == 2 ) { + result = false; + } + } else { + SALOMEDSClient_StudyManager* aMgr = studyMgr(); + if( aMgr ) { + std::vector List = studyMgr()->GetOpenStudies(); + if( List.size() > 0 ) { + int answer = SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_ACTIVEDOC_LOAD" ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No ); + if ( answer == SUIT_MessageBox::Yes ) { + onLoadDoc(); + } + result = false; + } + } + } + return result; +} diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index c715722bb..5d999d1a9 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -96,6 +96,8 @@ public: virtual bool checkDataObject(LightApp_DataObject* theObj); virtual void setDesktop( SUIT_Desktop* ); + + virtual bool checkExistingDoc(); static CORBA::ORB_var orb(); static SALOMEDSClient_StudyManager* studyMgr(); diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index d663c6ecb..16e1ae5b5 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -12,10 +12,26 @@ Python file must include only letters, digits and underscores and start from let WRN_FILE_NOT_EXIST The file %1 does not exist. + + QUE_ACTIVEDOC_LOAD + There is an active study in the session. +Do you want to load it? + + + + STUDYCLOSE_DESCRIPTION + You should close an existing study before. +Do you want to close it? + + WRN_STUDY_LOCKED Study is locked. + + WRN_NO_STUDY_ON SERV + No active study in this session. + CLOSE_LOCKED_STUDY Close locked study? @@ -216,7 +232,7 @@ Do you want to reload it ? APPCLOSE_DESCRIPTION - Do you want to close or unload study before closing? + Do you want to save study before closing? PRP_DESK_PROPERTIES -- 2.39.2