From 05915f7cd6bda6323b22fd68210bcee00531bfde Mon Sep 17 00:00:00 2001 From: stv Date: Tue, 25 Mar 2008 09:32:51 +0000 Subject: [PATCH] *** empty log message *** --- src/LightApp/LightApp_Application.cxx | 97 +++++++-- src/LightApp/LightApp_Application.h | 31 +-- src/Qtx/QtxMRUAction.cxx | 90 ++++++-- src/Qtx/QtxMRUAction.h | 9 + src/STD/STD_Application.cxx | 85 +++++--- src/STD/STD_Application.h | 24 ++- src/SUIT/SUIT_FileDlg.cxx | 2 +- src/SalomeApp/SalomeApp_Application.cxx | 270 ++++++++++-------------- src/SalomeApp/SalomeApp_Application.h | 36 ++-- 9 files changed, 373 insertions(+), 271 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 9311771bf..e8f752b69 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -508,8 +508,8 @@ void LightApp_Application::createActions() } //! MRU - QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk ); - connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) ); + static QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), 0 ); + connect( mru, SIGNAL( activated( const QString& ) ), this, SLOT( onOpenDoc( const QString& ) ) ); registerAction( MRUId, mru ); // default icon for neutral point ('SALOME' module) @@ -726,6 +726,7 @@ void LightApp_Application::onOpenDoc() */ bool LightApp_Application::onOpenDoc( const QString& aName ) { +#ifdef SWITCH_OFF bool isAlreadyOpen = false; // Look among opened studies @@ -777,13 +778,13 @@ bool LightApp_Application::onOpenDoc( const QString& aName ) } } } +#endif bool res = CAM_Application::onOpenDoc( aName ); - QAction* a = action( MRUId ); - if ( a && a->inherits( "QtxMRUAction" ) ) + QtxMRUAction* mru = ::qobject_cast( action( MRUId ) ); + if ( mru ) { - QtxMRUAction* mru = (QtxMRUAction*)a; if ( res ) mru->insert( aName ); else @@ -1557,12 +1558,6 @@ void LightApp_Application::onPreferenceChanged( QString& modName, QString& secti emit preferenceChanged( modName, section, param ); } -/*!Private SLOT. On open document with name \a aName.*/ -void LightApp_Application::onMRUActivated( QString aName ) -{ - onOpenDoc( aName ); -} - /*!Remove all windows from study.*/ void LightApp_Application::beforeCloseDoc( SUIT_Study* s ) { @@ -2112,6 +2107,15 @@ void LightApp_Application::loadPreferences() if ( !aResMgr ) return; + static bool mru_load = true; + if ( mru_load ) + { + QtxMRUAction* mru = ::qobject_cast( action( MRUId ) ); + if ( mru ) + mru->loadLinks( aResMgr, "MRU" ); + mru_load = false; + } + myWinGeom.clear(); QStringList mods = aResMgr->parameters( "windows_geometry" ); for ( QStringList::const_iterator it = mods.begin(); it != mods.end(); ++it ) @@ -2143,25 +2147,32 @@ void LightApp_Application::savePreferences() saveDockWindowsState(); - if ( !resourceMgr() ) + SUIT_ResourceMgr* aResMgr = resourceMgr(); + + if ( !aResMgr ) return; + QtxMRUAction* mru = ::qobject_cast( action( MRUId ) ); + if ( mru ) + mru->saveLinks( aResMgr, "MRU" ); + for ( WinGeom::const_iterator it = myWinGeom.begin(); it != myWinGeom.end(); ++it ) - resourceMgr()->setValue( "windows_geometry", it.key(), it.value() ); + aResMgr->setValue( "windows_geometry", it.key(), it.value() ); for ( WinVis::const_iterator itr = myWinVis.begin(); itr != myWinVis.end(); ++itr ) - resourceMgr()->setValue( "windows_visibility", itr.key(), itr.value() ); + aResMgr->setValue( "windows_visibility", itr.key(), itr.value() ); if ( desktop() ) - resourceMgr()->setValue( "desktop", "geometry", desktop()->storeGeometry() ); + aResMgr->setValue( "desktop", "geometry", desktop()->storeGeometry() ); - resourceMgr()->save(); + aResMgr->save(); } /*! Updates desktop title */ -void LightApp_Application::updateDesktopTitle() { +void LightApp_Application::updateDesktopTitle() +{ QString aTitle = applicationName(); QString aVer = applicationVersion(); if ( !aVer.isEmpty() ) @@ -2752,3 +2763,55 @@ bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj) return false; } + +int LightApp_Application::openChoice( const QString& aName ) +{ + int choice = CAM_Application::openChoice( aName ); + + if ( choice == OpenExist ) // The document is already open. + { + // Do you want to reload it? + if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYOPEN" ).arg( aName ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No ) == SUIT_MessageBox::Yes ) + choice = OpenReload; + } + + return choice; +} + +bool LightApp_Application::openAction( const int choice, const QString& aName ) +{ + bool res = false; + switch ( choice ) + { + case OpenReload: + { + STD_Application* app = 0; + SUIT_Session* session = SUIT_Session::session(); + QList appList = session->applications(); + for ( QList::iterator it = appList.begin(); it != appList.end() && !app; ++it ) + { + if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName ) + app = ::qobject_cast( *it ); + } + + if ( app ) + { + app->onCloseDoc( false ); + appList = session->applications(); + STD_Application* other = 0; + for ( QList::iterator it = appList.begin(); it != appList.end() && !other; ++it ) + other = ::qobject_cast( *it ); + + if ( other ) + res = other->onOpenDoc( aName ); + } + } + break; + default: + res = CAM_Application::openAction( choice, aName ); + break; + } + + return res; +} diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 6a6081060..cc9f4f693 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -74,29 +74,8 @@ public: enum { MenuWindowId = 6 }; - enum { RenameId = CAM_Application::UserID, - -#ifndef DISABLE_GLVIEWER - NewGLViewId , -#endif - -#ifndef DISABLE_PLOT2DVIEWER - NewPlot2dId, -#endif - -#ifndef DISABLE_OCCVIEWER - NewOCCViewId, -#endif - -#ifndef DISABLE_VTKVIEWER - NewVTKViewId, -#endif - -#ifndef DISABLE_QXGRAPHVIEWER - NewQxGraphViewId, -#endif - - PreferencesId, MRUId, ModulesListId, UserID }; + enum { RenameId = CAM_Application::UserID, PreferencesId, MRUId, ModulesListId, + NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, UserID }; protected: enum { NewStudyId = 1, OpenStudyId }; @@ -224,7 +203,6 @@ private slots: void onSelection(); void onRefresh(); void onPreferences(); - void onMRUActivated( QString ); void onPreferenceChanged( QString&, QString&, QString& ); void onRenameWindow(); @@ -252,12 +230,17 @@ protected: QByteArray dockWindowsState( const QMap&, const QMap& ) const; void dockWindowsState( const QByteArray&, QMap&, QMap& ) const; + virtual int openChoice( const QString& ); + virtual bool openAction( const int, const QString& ); + protected: typedef QPointer WinPtr; typedef QMap WinMap; typedef QMap WinVis; typedef QMap WinGeom; + enum { OpenReload = CAM_Application::OpenExist + 1 }; + protected: LightApp_Preferences* myPrefs; LightApp_SelectionMgr* mySelMgr; diff --git a/src/Qtx/QtxMRUAction.cxx b/src/Qtx/QtxMRUAction.cxx index c78b0c6de..0cc2e5c98 100755 --- a/src/Qtx/QtxMRUAction.cxx +++ b/src/Qtx/QtxMRUAction.cxx @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -38,6 +38,7 @@ QtxMRUAction::QtxMRUAction( QObject* parent ) : QtxAction( "Most Recently Used", "Most Recently Used", 0, parent ), myVisCount( 5 ), + myLinkType( LinkAuto ), myInsertMode( MoveFirst ) { setMenu( new QMenu( 0 ) ); @@ -53,6 +54,7 @@ QtxMRUAction::QtxMRUAction( QObject* parent ) QtxMRUAction::QtxMRUAction( const QString& text, const QString& menuText, QObject* parent ) : QtxAction( text, menuText, 0, parent ), myVisCount( 5 ), + myLinkType( LinkAuto ), myInsertMode( MoveFirst ) { setMenu( new QMenu( 0 ) ); @@ -69,8 +71,9 @@ QtxMRUAction::QtxMRUAction( const QString& text, const QString& menuText, QObjec QtxMRUAction::QtxMRUAction( const QString& text, const QIcon& icon, const QString& menuText, QObject* parent ) : QtxAction( text, icon, menuText, 0, parent ), -myVisCount( 5 ), -myInsertMode( MoveFirst ) + myVisCount( 5 ), + myLinkType( LinkAuto ), + myInsertMode( MoveFirst ) { setMenu( new QMenu( 0 ) ); connect( menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); @@ -102,6 +105,24 @@ void QtxMRUAction::setInsertMode( const int mode ) myInsertMode = mode; } +/*! + \brief Get the type of link menu name. + \return link type (QtxMRUAction::LinkType) +*/ +int QtxMRUAction::linkType() const +{ + return myLinkType; +} + +/*! + \brief Set the type of link menu name. + \param link type (QtxMRUAction::LinkType) +*/ +void QtxMRUAction::setLinkType( const int type ) +{ + myLinkType = type; +} + /*! \brief Get number of MRU items. \return number of MRU items @@ -132,7 +153,7 @@ int QtxMRUAction::visibleCount() const /*! \brief Set number of visible MRU items. - + This method sets the maximum number of MRU items to be displayed in the popup menu (5 by default). @@ -316,7 +337,7 @@ void QtxMRUAction::saveLinks( QtxResourceMgr* resMgr, const QString& section, co /*! \brief Prepare MRU items popup menu. - + This method is called when the parent menu is shown. Enables or disables sub menu item according to the number of MRU items. */ @@ -336,7 +357,7 @@ void QtxMRUAction::onActivated() if ( !a ) return; - QString link = a->text(); + QString link = a->data().toString(); if ( !link.isEmpty() && myLinks.contains( link ) ) emit activated( link ); } @@ -352,9 +373,50 @@ void QtxMRUAction::updateMenu() pm->clear(); + QStringList links; + QMap map; int count = visibleCount() < 0 ? myLinks.count() : visibleCount(); for ( QStringList::const_iterator it = myLinks.begin(); it != myLinks.end() && count > 0; ++it, count-- ) - pm->addAction( *it, this, SLOT( onActivated() ) ); + { + links.append( *it ); + if ( linkType() == LinkAuto ) + { + QString shortName = Qtx::file( *it ); + if ( map.contains( shortName ) ) + map[shortName]++; + else + map.insert( shortName, 0 ); + } + } + + int i = 0; + for ( QStringList::const_iterator it = links.begin(); it != links.end(); ++it, i++ ) + { + QString linkName; + switch( linkType() ) + { + case LinkAuto: + linkName = Qtx::file( *it ); + if ( map.contains( linkName ) && map[linkName] ) + linkName = *it; + break; + case LinkShort: + linkName = Qtx::file( *it ); + break; + case LinkFull: + default: + linkName = *it; + break; + } + + if ( links.count() < 10 ) + linkName = QString( "&%1 %2" ).arg( i ).arg( linkName ); + + pm->addAction( linkName, this, SLOT( onActivated() ) )->setData( *it ); + } + + if ( pm->isEmpty() ) + pm->addAction( tr( "" ) )->setEnabled( false ); } /*! diff --git a/src/Qtx/QtxMRUAction.h b/src/Qtx/QtxMRUAction.h index f8a5dd9b0..708383f43 100755 --- a/src/Qtx/QtxMRUAction.h +++ b/src/Qtx/QtxMRUAction.h @@ -44,6 +44,11 @@ public: AddLast //!< if specified item doesn't exist, add it to the end } InsertionMode; + typedef enum { LinkAuto, //!< put the full path of link into the menu if link file names of severals link are same + LinkShort, //!< put the only file name of link into the menu + LinkFull //!< put the full path of link into the menu + } LinkType; + public: QtxMRUAction( QObject* = 0 ); QtxMRUAction( const QString&, const QString&, QObject* = 0 ); @@ -53,6 +58,9 @@ public: int insertMode() const; void setInsertMode( const int ); + int linkType() const; + void setLinkType( const int ); + int count() const; bool isEmpty() const; @@ -83,6 +91,7 @@ private: private: QStringList myLinks; //!< most recent used items int myVisCount; //!< number of visible MRU items + int myLinkType; //!< type of link names in menu int myInsertMode; //!< items insertion policy }; diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 4708a666e..211966bcd 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -314,37 +314,8 @@ bool STD_Application::onOpenDoc( const QString& aName ) { QApplication::setOverrideCursor( Qt::WaitCursor ); - bool res = true; - if ( !activeStudy() ) - { - // if no study - open in current desktop - res = useFile( aName ); - } - else - { - // if study exists - open in new desktop. Check: is the same file is opened? - SUIT_Session* aSession = SUIT_Session::session(); - QList aAppList = aSession->applications(); - bool isAlreadyOpen = false; - SUIT_Application* aApp = 0; - for ( QList::iterator it = aAppList.begin(); it != aAppList.end() && !isAlreadyOpen; ++it ) - { - aApp = *it; - if ( aApp->activeStudy()->studyName() == aName ) - isAlreadyOpen = true; - } - if ( !isAlreadyOpen ) - { - aApp = startApplication( 0, 0 ); - if ( aApp ) - res = aApp->useFile( aName ); - if ( !res ) - aApp->closeApplication(); - } - else - aApp->desktop()->activateWindow(); - } - + bool res = openAction( openChoice( aName ), aName ); + QApplication::restoreOverrideCursor(); return res; @@ -455,6 +426,58 @@ bool STD_Application::closeAction( const int choice, bool& closePermanently ) return res; } +int STD_Application::openChoice( const QString& aName ) +{ + SUIT_Session* aSession = SUIT_Session::session(); + + bool isAlreadyOpen = false; + QList aAppList = aSession->applications(); + for ( QList::iterator it = aAppList.begin(); it != aAppList.end() && !isAlreadyOpen; ++it ) + isAlreadyOpen = (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName; + return isAlreadyOpen ? OpenExist : OpenNew; +} + +bool STD_Application::openAction( const int choice, const QString& aName ) +{ + bool res = true; + switch ( choice ) + { + case OpenExist: + { + SUIT_Application* aApp = 0; + SUIT_Session* aSession = SUIT_Session::session(); + QList aAppList = aSession->applications(); + for ( QList::iterator it = aAppList.begin(); it != aAppList.end() && !aApp; ++it ) + { + if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName ) + aApp = *it; + } + if ( aApp ) + aApp->desktop()->activateWindow(); + else + res = false; + } + break; + case OpenNew: + if ( !activeStudy() ) + res = useFile( aName ); + else + { + SUIT_Application* aApp = startApplication( 0, 0 ); + if ( aApp ) + res = aApp->useFile( aName ); + if ( !res ) + aApp->closeApplication(); + } + break; + case OpenCancel: + default: + res = false; + } + + return res; +} + /*!Save document if all ok, else error message.*/ void STD_Application::onSaveDoc() { diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index 50a1efbda..77f2ed646 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -81,7 +81,7 @@ public: void viewManagers( const QString&, ViewManagerList& ) const; virtual QString getFileFilter() const { return QString(); } - virtual QString getFileName( bool open, const QString& initial, const QString& filters, + virtual QString getFileName( bool open, const QString& initial, const QString& filters, const QString& caption, QWidget* parent ); QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ); @@ -135,6 +135,7 @@ protected: MenuHelpId = 7 }; + enum { OpenCancel, OpenNew, OpenExist }; enum { CloseCancel, CloseSave, CloseDiscard }; protected: @@ -156,8 +157,11 @@ protected: virtual void setActiveViewManager( SUIT_ViewManager* ); - virtual bool closeAction( const int, bool& ); + virtual int openChoice( const QString& ); + virtual bool openAction( const int, const QString& ); + virtual int closeChoice( const QString& ); + virtual bool closeAction( const int, bool& ); private: ViewManagerList myViewMgrs; diff --git a/src/SUIT/SUIT_FileDlg.cxx b/src/SUIT/SUIT_FileDlg.cxx index 3ab4dc318..f984a9740 100755 --- a/src/SUIT/SUIT_FileDlg.cxx +++ b/src/SUIT/SUIT_FileDlg.cxx @@ -729,7 +729,7 @@ QString SUIT_FileDlg::getFileName( QWidget* parent, const QString& initial, { SUIT_FileDlg fd( parent, open, showQuickDir, true ); - fd.setFileMode( ExistingFile ); + fd.setFileMode( open ? ExistingFile : AnyFile ); if ( filters.isEmpty() ) fd.setFilter( tr( "ALL_FILES_FILTER" ) ); // All files (*) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 383ba5135..75330dd1b 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -96,7 +96,7 @@ void SalomeApp_Updater::update( SUIT_DataObject* theObj, OB_ListItem* theItem ) SalomeApp_DataObject* SAObj = dynamic_cast( theObj ); if( !SAObj ) return; - + _PTR(SObject) SObj = SAObj->object(); if( !SObj ) return; @@ -109,14 +109,14 @@ void SalomeApp_Updater::update( SUIT_DataObject* theObj, OB_ListItem* theItem ) theItem->setSelectable( aAttrSel->IsSelectable() ); } // Expandable - if ( SObj->FindAttribute(anAttr, "AttributeExpandable") ) + if ( SObj->FindAttribute(anAttr, "AttributeExpandable") ) { _PTR(AttributeExpandable) aAttrExpand = anAttr; theItem->setExpandable( aAttrExpand->IsExpandable() ); } // Opened //this attribute is not supported in the version of SALOME 3.x - //if ( SObj->FindAttribute(anAttr, "AttributeOpened") ) + //if ( SObj->FindAttribute(anAttr, "AttributeOpened") ) //{ // _PTR(AttributeOpened) aAttrOpen = anAttr; // theItem->setOpen( aAttrOpen->IsOpened() ); @@ -133,7 +133,7 @@ extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication() SalomeApp_Application::SalomeApp_Application() : LightApp_Application() { - connect( desktop(), SIGNAL( message( const QString& ) ), + connect( desktop(), SIGNAL( message( const QString& ) ), this, SLOT( onDesktopMessage( const QString& ) ) ); } @@ -220,18 +220,18 @@ void SalomeApp_Application::createActions() LightApp_Application::createActions(); SUIT_Desktop* desk = desktop(); - + //! Save GUI state // "Save GUI State" command is moved to VISU module // createAction( SaveGUIStateId, tr( "TOT_DESK_FILE_SAVE_GUI_STATE" ), QIcon(), // tr( "MEN_DESK_FILE_SAVE_GUI_STATE" ), tr( "PRP_DESK_FILE_SAVE_GUI_STATE" ), // 0, desk, false, this, SLOT( onSaveGUIState() ) ); - + //! Dump study createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIcon(), tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ), Qt::CTRL+Qt::Key_D, desk, false, this, SLOT( onDumpStudy() ) ); - + //! Load script createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIcon(), tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ), @@ -262,9 +262,9 @@ void SalomeApp_Application::createActions() int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); - // "Save GUI State" command is renamed to "Save VISU State" and + // "Save GUI State" command is renamed to "Save VISU State" and // creation of menu item is moved to VISU - // createMenu( SaveGUIStateId, fileMenu, 10, -1 ); + // createMenu( SaveGUIStateId, fileMenu, 10, -1 ); createMenu( FileLoadId, fileMenu, 0 ); //SRN: BugID IPAL9021, add a menu item "Load" @@ -281,105 +281,6 @@ void SalomeApp_Application::createActions() createMenu( separator(), toolsMenu, -1, 15, -1 ); } -/*! Purpose : SLOT. Open new document with \a aName.*/ -bool SalomeApp_Application::onOpenDoc( const QString& aName ) -{ - bool res = false, toOpen = true, isAlreadyOpen = false; - - // Look among opened studies - if (activeStudy()) { // at least one study is opened - SUIT_Session* aSession = SUIT_Session::session(); - QList aAppList = aSession->applications(); - QListIterator it (aAppList); - SUIT_Application* aApp = 0; - // iterate on all applications - while ( it.hasNext() && !isAlreadyOpen ) { - aApp = it.next(); - - if (aApp && aApp->activeStudy()->studyName() == aName) { - isAlreadyOpen = true; // Already opened, ask user what to do - - // The document ... is already open. - // Do you want to reload it? - int aAnswer = SUIT_MessageBox::question(desktop(), tr("WRN_WARNING"), - tr("QUE_DOC_ALREADYOPEN").arg(aName), - SUIT_MessageBox::Yes | SUIT_MessageBox::No, - SUIT_MessageBox::No); - if (aAnswer == SUIT_MessageBox::Yes) { // reload - if (activeStudy()->studyName() == aName && aAppList.count() > 1) { - // Opened in THIS (active) application. - STD_Application* app1 = (STD_Application*)aAppList.at(0); - STD_Application* app2 = (STD_Application*)aAppList.at(1); - if (!app1 || !app2) { - // Error - return false; - } - if (app1->activeStudy()->studyName() == aName) { - // app1 is this application, we need another one - app1 = app2; - } - // Close document of this application. This application will be destroyed. - onCloseDoc(/*ask = */false); - // Open the file with another application, as this one will be destroyed. - return app1->onOpenDoc(aName); - } else { - // Opened in another application. - STD_Application* app = (STD_Application*)aApp; - if (app) - app->onCloseDoc(/*ask = */false); - } - } else { // do not reload - // OK, the study will not be reloaded, but we call - // CAM_Application::onOpenDoc( aName ) all the same. - // It will activate a desktop of the study . - } - } - } - } - - // Look among unloaded studies - if (!isAlreadyOpen) { - std::vector List = studyMgr()->GetOpenStudies(); - - QString studyName; - for (unsigned int ind = 0; ind < List.size() && !isAlreadyOpen; ind++) { - studyName = List[ind].c_str(); - if (aName == studyName) { - // Already exists unloaded, ask user what to do - isAlreadyOpen = true; - - // The document ... already exists in the study manager. - // Do you want to reload it? - int aAnswer = SUIT_MessageBox::question(desktop(), tr("WRN_WARNING"), - tr("QUE_DOC_ALREADYEXIST").arg(aName), - SUIT_MessageBox::Yes | SUIT_MessageBox::No, - SUIT_MessageBox::No); - if (aAnswer == SUIT_MessageBox::Yes) { - _PTR(Study) aStudy = studyMgr()->GetStudyByName(aName.toStdString()); - if (aStudy) - studyMgr()->Close(aStudy); - } else { - toOpen = false; - } - } - } - } - - if (toOpen) - res = CAM_Application::onOpenDoc( aName ); - - QAction* a = action( MRUId ); - if ( a && a->inherits( "QtxMRUAction" ) ) - { - QtxMRUAction* mru = (QtxMRUAction*)a; - if ( res ) - mru->insert( aName ); - else - mru->remove( aName ); - } - return res; -} - /*! \brief Close application. */ @@ -393,7 +294,7 @@ void SalomeApp_Application::onExit() result = dlg.exec() == QDialog::Accepted; killServers = dlg.isServersShutdown(); } - + if ( result ) SUIT_Session::session()->closeSession( SUIT_Session::ASK, killServers ); } @@ -417,13 +318,13 @@ void SalomeApp_Application::onLoadDoc() QListIterator it( aAppList ); while ( it.hasNext() && !isAlreadyOpen ) { SUIT_Application* aApp = it.next(); - if( !aApp || !aApp->activeStudy() ) + if( !aApp || !aApp->activeStudy() ) continue; - if ( aApp->activeStudy()->studyName() == studyName ) + if ( aApp->activeStudy()->studyName() == studyName ) isAlreadyOpen = true; } - if ( !isAlreadyOpen ) + if ( !isAlreadyOpen ) unloadedStudies << studyName; } @@ -432,7 +333,7 @@ void SalomeApp_Application::onLoadDoc() return; #ifndef WIN32 - // this code replaces marker of windows drive and path become invalid therefore + // this code replaces marker of windows drive and path become invalid therefore // defines placed there studyName.replace( QRegExp(":"), "/" ); #endif @@ -458,7 +359,7 @@ bool SalomeApp_Application::onLoadDoc( const QString& aName ) QList aAppList = aSession->applications(); bool isAlreadyOpen = false; SalomeApp_Application* aApp = 0; - for ( QList::iterator it = aAppList.begin(); + for ( QList::iterator it = aAppList.begin(); it != aAppList.end() && !isAlreadyOpen; ++it ) { aApp = dynamic_cast( *it ); if ( aApp && aApp->activeStudy()->studyName() == aName ) @@ -483,10 +384,10 @@ void SalomeApp_Application::onCopy() SALOME_ListIO list; LightApp_SelectionMgr* mgr = selectionMgr(); mgr->selectedObjects(list); - + SalomeApp_Study* study = dynamic_cast(activeStudy()); if(study == NULL) return; - + _PTR(Study) stdDS = study->studyDS(); if(!stdDS) return; @@ -551,14 +452,14 @@ void SalomeApp_Application::onCloseDoc( bool ask ) SalomeApp_Study* study = dynamic_cast(activeStudy()); if (study != NULL) { - _PTR(Study) stdDS = study->studyDS(); + _PTR(Study) stdDS = study->studyDS(); if(stdDS && stdDS->IsStudyLocked()) { if ( SUIT_MessageBox::question( desktop(), QObject::tr( "WRN_WARNING" ), QObject::tr( "CLOSE_LOCKED_STUDY" ), SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No) == SUIT_MessageBox::No ) return; - + } } @@ -693,13 +594,13 @@ void SalomeApp_Application::updateCommandsStatus() /*! \class DumpStudyFileDlg - Private class used in Dump Study operation. Consists 2 check boxes: + Private class used in Dump Study operation. Consists 2 check boxes: "Publish in study" and "Save GUI parameters" */ class DumpStudyFileDlg : public SUIT_FileDlg { public: - DumpStudyFileDlg( QWidget* parent ) : SUIT_FileDlg( parent, false, true, true ) + DumpStudyFileDlg( QWidget* parent ) : SUIT_FileDlg( parent, false, true, true ) { QGridLayout* grid = ::qobject_cast( layout() ); if ( grid ) @@ -707,20 +608,20 @@ public: QWidget *hB = new QWidget( this ); myPublishChk = new QCheckBox( tr("PUBLISH_IN_STUDY") ); mySaveGUIChk = new QCheckBox( tr("SAVE_GUI_STATE") ); - + QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(myPublishChk); layout->addWidget(mySaveGUIChk); hB->setLayout(layout); - - QPushButton* pb = new QPushButton(this); + + QPushButton* pb = new QPushButton(this); int row = grid->rowCount(); grid->addWidget( new QLabel("", this), row, 0 ); grid->addWidget( hB, row, 1, 1, 3 ); grid->addWidget( pb, row, 5 ); - - pb->hide(); + + pb->hide(); } } QCheckBox* myPublishChk; @@ -767,11 +668,11 @@ void SalomeApp_Application::onDumpStudy( ) if(ip->isDumpPython(appStudy->studyDS())) ip->setDumpPython(appStudy->studyDS()); //Unset DumpPython flag. if ( toSaveGUI ) { //SRN: Store a visual state of the study at the save point for DumpStudy method ip->setDumpPython(appStudy->studyDS()); - savePoint = SalomeApp_VisualState( this ).storeState(); //SRN: create a temporary save point + savePoint = SalomeApp_VisualState( this ).storeState(); //SRN: create a temporary save point } - bool res = aStudy->DumpStudy( aFileInfo.absolutePath().toStdString(), + bool res = aStudy->DumpStudy( aFileInfo.absolutePath().toStdString(), aFileInfo.baseName().toStdString(), toPublish); - if ( toSaveGUI ) + if ( toSaveGUI ) appStudy->removeSavePoint(savePoint); //SRN: remove the created temporary save point. if ( !res ) SUIT_MessageBox::warning( desktop(), @@ -843,7 +744,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) if ( flag == WT_ObjectBrowser ) { SUIT_DataBrowser* ob = qobject_cast( wid ); - if ( ob ) { + if ( ob ) { // temporary commented //ob->setUpdater( new SalomeApp_Updater() ); @@ -974,13 +875,66 @@ bool SalomeApp_Application::closeAction( const int choice, bool& closePermanentl return res; } +int SalomeApp_Application::openChoice( const QString& aName ) +{ + int choice = LightApp_Application::openChoice( aName ); + + 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. + // Do you want to reload it? + if ( exist ) + { + int answer = SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYEXIST" ).arg( aName ), + SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No ); + if ( answer == SUIT_MessageBox::Yes ) + choice = OpenRefresh; + else + choice = OpenCancel; + } + } + + return choice; +} + +bool SalomeApp_Application::openAction( const int aChoice, const QString& aName ) +{ + bool res = false; + int choice = aChoice; + switch ( choice ) + { + case OpenRefresh: + { + _PTR(Study) aStudy = studyMgr()->GetStudyByName( aName.toStdString() ); + if ( aStudy ) + { + studyMgr()->Close( aStudy ); + choice = OpenNew; + } + } + default: + res = LightApp_Application::openAction( choice, aName ); + break; + } + + return res; +} + /*! - \brief Get map of the operations which can be performed + \brief Get map of the operations which can be performed on the module activation. - + The method should return the map of the kind \c {:} where \c is an integer identifier of the operation and - \c is a title for the button to be added to the + \c is a title for the button to be added to the dialog box. After user selects the required operation by the clicking the corresponding button in the dialog box, its identifier is passed to the moduleActionSelected() method to process @@ -1001,7 +955,7 @@ QMap SalomeApp_Application::activateModuleActions() const from "Activate module" dialog box. Performs the required operation according to the user choice. - + \param id operation identifier \sa activateModuleActions() */ @@ -1095,7 +1049,7 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePop mgr->selectedObjects( aList, QString(), false ); // add GUI state commands: restore, rename - if ( aList.Extent() == 1 && aList.First()->hasEntry() && + if ( aList.Extent() == 1 && aList.First()->hasEntry() && QString( aList.First()->getEntry() ).startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) ) { thePopup->addSeparator(); thePopup->addAction( tr( "MEN_RESTORE_VS" ), this, SLOT( onRestoreGUIState() ) ); @@ -1163,7 +1117,7 @@ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) _PTR(Study) stdDS = study->studyDS(); if( stdDS ) { - for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() ) + for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() ) { _PTR(SComponent) aComponent ( it->Value() ); @@ -1279,8 +1233,8 @@ int getSelectedSavePoint( const LightApp_SelectionMgr* selMgr ) void SalomeApp_Application::onRestoreGUIState() { int savePoint = ::getSelectedSavePoint( selectionMgr() ); - if ( savePoint == -1 ) - return; + if ( savePoint == -1 ) + return; SalomeApp_VisualState( this ).restoreState( savePoint ); } @@ -1288,10 +1242,10 @@ void SalomeApp_Application::onRestoreGUIState() void SalomeApp_Application::onRenameGUIState() { int savePoint = ::getSelectedSavePoint( selectionMgr() ); - if ( savePoint == -1 ) - return; + if ( savePoint == -1 ) + return; SalomeApp_Study* study = dynamic_cast( activeStudy() ); - if ( !study ) + if ( !study ) return; QString newName = LightApp_NameDlg::getName( desktop(), study->getNameOfSavePoint( savePoint ) ); @@ -1308,12 +1262,12 @@ void SalomeApp_Application::onRenameGUIState() void SalomeApp_Application::onDeleteGUIState() { int savePoint = ::getSelectedSavePoint( selectionMgr() ); - if ( savePoint == -1 ) - return; + if ( savePoint == -1 ) + return; SalomeApp_Study* study = dynamic_cast( activeStudy() ); - if ( !study ) + if ( !study ) return; - + study->removeSavePoint( savePoint ); updateSavePointDataObjects( study ); } @@ -1353,8 +1307,8 @@ void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study ) // find GUI states root object SUIT_DataObject* guiRootObj = 0; - DataObjectList ch; - study->root()->children( ch ); + DataObjectList ch; + study->root()->children( ch ); DataObjectList::const_iterator it = ch.begin(), last = ch.end(); for ( ; it != last ; ++it ) { if ( dynamic_cast( *it ) ) { @@ -1385,8 +1339,8 @@ void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study ) // store data objects in a map id-to-DataObject QMap mapDO; - ch.clear(); - guiRootObj->children( ch ); + ch.clear(); + guiRootObj->children( ch ); for( it = ch.begin(), last = ch.end(); it != last ; ++it ) { SalomeApp_SavePointObject* dobj = dynamic_cast( *it ); if ( dobj ) @@ -1394,7 +1348,7 @@ void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study ) } // iterate new save points. if DataObject with such ID not found in map - create DataObject - // if in the map - remove it from map. + // if in the map - remove it from map. for ( int i = 0; i < savePoints.size(); i++ ) if ( !mapDO.contains( savePoints[i] ) ) new SalomeApp_SavePointObject( guiRootObj, savePoints[i], study ); @@ -1419,7 +1373,7 @@ bool SalomeApp_Application::checkDataObject(LightApp_DataObject* theObj) void SalomeApp_Application::onDesktopMessage( const QString& message ) { // update object browser - if ( message.toLower() == "updateobjectbrowser" || + if ( message.toLower() == "updateobjectbrowser" || message.toLower() == "updateobjbrowser" ) updateObjectBrowser(); } diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index a965a652c..d23bef56a 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -1,17 +1,17 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com @@ -65,8 +65,9 @@ public: CatalogGenId, RegDisplayId, SaveGUIStateId, FileLoadId, UserID }; protected: - enum { CloseUnload = CloseDiscard + 1 }; - enum { LoadStudyId = OpenStudyId + 1 }; + enum { OpenRefresh = LightApp_Application::OpenReload + 1 }; + enum { CloseUnload = LightApp_Application::CloseDiscard + 1 }; + enum { LoadStudyId = LightApp_Application::OpenStudyId + 1 }; public: SalomeApp_Application(); @@ -90,20 +91,20 @@ public: SUIT_ViewManager* newViewManager(const QString&); void updateSavePointDataObjects( SalomeApp_Study* ); - + virtual bool isPossibleToClose( bool& ); virtual bool useStudy( const QString& ); public slots: - virtual bool onOpenDoc( const QString& ); virtual void onLoadDoc(); virtual bool onLoadDoc( const QString& ); + virtual void onCloseDoc( bool ask = true); + virtual void onExit(); virtual void onCopy(); virtual void onPaste(); void onSaveGUIState();// called from VISU - virtual void onCloseDoc( bool ask = true); protected slots: void onStudySaved( SUIT_Study* ); @@ -123,7 +124,10 @@ protected: virtual bool closeAction( const int, bool& ); virtual int closeChoice( const QString& ); - + + virtual int openChoice( const QString& ); + virtual bool openAction( const int, const QString& ); + virtual QMap activateModuleActions() const; virtual void moduleActionSelected( const int ); @@ -132,9 +136,9 @@ private slots: void onDblClick( QListViewItem* ); void onProperties(); void onDumpStudy(); - void onLoadScript(); + void onLoadScript(); - void onDeleteGUIState(); + void onDeleteGUIState(); void onRestoreGUIState(); void onRenameGUIState(); -- 2.39.2