X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSalomeApp%2FSalomeApp_Application.cxx;h=7e3a64966f8863d51b3c4203ff638c0d2821d12f;hb=034a705024b224972c148e1e3834c5ee38df184b;hp=c33026683fbb56b8ec2c4e5652ba07526082bef4;hpb=a947e05a9b21d1c671fb63c69db4a643f6c17532;p=modules%2Fgui.git diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index c33026683..7e3a64966 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -1,961 +1,2110 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + // File: SalomeApp_Application.cxx // Created: 10/22/2004 3:23:45 PM // Author: Sergey LITONIN -// Copyright (C) CEA 2004 -#include "SalomeApp_PyInterp.h" // WARNING! This include must be the first! +#ifdef WIN32 +// E.A. : On windows with python 2.6, there is a conflict +// E.A. : between pymath.h and Standard_math.h which define +// E.A. : some same symbols : acosh, asinh, ... +#include +#include +#endif +#include "SalomeApp_PyInterp.h" // WARNING! This include must be the first! #include "SalomeApp_Application.h" - #include "SalomeApp_Study.h" -#include "SalomeApp_Module.h" -#include "SalomeApp_GLSelector.h" -#include "SalomeApp_OBSelector.h" -#include "SalomeApp_OCCSelector.h" -#include "SalomeApp_VTKSelector.h" -#include "SalomeApp_EventFilter.h" -#include "SalomeApp_SelectionMgr.h" -#include "SalomeApp_EventFilter.h" -#include "SalomeApp_WidgetContainer.h" -#include "SalomeApp_ModuleDlg.h" - -#include - -#include -#include - -#include +#include "SalomeApp_DataModel.h" +#include "SalomeApp_DataObject.h" +#include "SalomeApp_VisualState.h" +#include "SalomeApp_StudyPropertiesDlg.h" +#include "SalomeApp_LoadStudiesDlg.h" +#include "SalomeApp_NoteBook.h" -#include -#include +#include "SalomeApp_ExitDlg.h" -#include -#include +#include +#include +#include +#include +#include +#include +#include -#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include -#include +#include -#include +#include -#include +// temporary commented +//#include -#include -#include -#include +#include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "SALOMEDS_StudyManager.hxx" - -#define OBJECT_BROWSER_WIDTH 300 - -static const char* imageEmptyIcon[] = { -"20 20 1 1", -". c None", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"....................", -"...................."}; +#include -extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication() -{ - return new SalomeApp_Application(); -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -/* - Class : SalomeApp_Application - Description : Application containing SalomeApp module -*/ +#include +#include -SalomeApp_Application::SalomeApp_Application() -: CAM_Application( false ) -{ - STD_TabDesktop* desk = new STD_TabDesktop(); +#include +#include +#include - setDesktop( desk ); - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) ); +#include +#include - desktop()->setIcon( aLogo ); - desktop()->setDockableMenuBar( true ); - desktop()->setDockableStatusBar( false ); +#include - clearViewManagers(); +#include - mySelMgr = new SalomeApp_SelectionMgr( this ); +/*!Internal class that updates object browser item properties */ +// temporary commented +/*class SalomeApp_Updater : public OB_Updater +{ +public: + SalomeApp_Updater() : OB_Updater(){}; + virtual ~SalomeApp_Updater(){}; + virtual void update( SUIT_DataObject* theObj, OB_ListItem* theItem ); +}; - connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ), - this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) ); +void SalomeApp_Updater::update( SUIT_DataObject* theObj, OB_ListItem* theItem ) +{ + if( !theObj || !theItem ) + return; - connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) ); -} + SalomeApp_DataObject* SAObj = dynamic_cast( theObj ); + if( !SAObj ) + return; -SalomeApp_Application::~SalomeApp_Application() -{ - saveWindowsGeometry(); + _PTR(SObject) SObj = SAObj->object(); + if( !SObj ) + return; + _PTR( GenericAttribute ) anAttr; - if ( resourceMgr() ) + // Selectable + if ( SObj->FindAttribute( anAttr, "AttributeSelectable" ) ) { - if ( desktop() ) - desktop()->saveGeometry( resourceMgr(), "desktop" ); - resourceMgr()->save(); + _PTR(AttributeSelectable) aAttrSel = anAttr; + theItem->setSelectable( aAttrSel->IsSelectable() ); } + // Expandable + 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") ) + //{ + // _PTR(AttributeOpened) aAttrOpen = anAttr; + // theItem->setOpen( aAttrOpen->IsOpened() ); + //} +}*/ + +/*!Create new instance of SalomeApp_Application.*/ +extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication() +{ + return new SalomeApp_Application(); +} - delete mySelMgr; +/*!Constructor.*/ +SalomeApp_Application::SalomeApp_Application() + : LightApp_Application() +{ + connect( desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); + connect( desktop(), SIGNAL( message( const QString& ) ), + this, SLOT( onLoadDocMessage( const QString& ) ), Qt::UniqueConnection ); + myIsSiman = false; // default +} - SalomeApp_EventFilter::Destroy(); +/*!Destructor. + *\li Destroy event filter. + */ +SalomeApp_Application::~SalomeApp_Application() +{ + // Do not destroy. It's a singleton ! + //SALOME_EventFilter::Destroy(); } +/*!Start application.*/ void SalomeApp_Application::start() { - if ( desktop() ) - desktop()->loadGeometry( resourceMgr(), "desktop" ); - - CAM_Application::start(); - - QAction* a = action( ViewWindowsId ); - if ( a && a->inherits( "QtxDockAction" ) ) - ((QtxDockAction*)a)->setAutoPlace( true ); - - SalomeApp_EventFilter::Init(); - - updateWindows(); - updateViewManagers(); + // process the command line options before start: to createActions in accordance to the options + static bool isFirst = true; + if ( isFirst ) { + isFirst = false; + + QString hdffile; + QStringList pyfiles; + QString loadStudy; + + for (int i = 1; i < qApp->argc(); i++) { + QRegExp rxs ("--study-hdf=(.+)"); + if ( rxs.indexIn( QString(qApp->argv()[i]) ) >= 0 && rxs.capturedTexts().count() > 1 ) { + QString file = rxs.capturedTexts()[1]; + QFileInfo fi ( file ); + QString extension = fi.suffix().toLower(); + if ( extension == "hdf" && fi.exists() ) + hdffile = fi.absoluteFilePath(); + } + else { + QRegExp rxp ("--pyscript=\\[(.+)\\]"); + QRegExp rxl ("--siman-study=(.+)"); + if ( rxp.indexIn( QString(qApp->argv()[i]) ) >= 0 && rxp.capturedTexts().count() > 1 ) { + // pyscript + QStringList dictList = rxp.capturedTexts()[1].split("},", QString::SkipEmptyParts); + for (int k = 0; k < dictList.count(); ++k) { + QRegExp rxd ("[\\s]*\\{?([^\\{\\}]+)\\}?[\\s]*"); + if ( rxd.indexIn( dictList[k] ) >= 0 && rxd.capturedTexts().count() > 1 ) { + for (int m = 1; m < rxd.capturedTexts().count(); ++m) { + pyfiles += rxd.capturedTexts()[m]; + } + } + } + } +#ifdef WITH_SIMANIO + if ( rxl.indexIn( QString(qApp->argv()[i]) ) >= 0 && rxl.capturedTexts().count() > 1 ) { + // siman + loadStudy = rxl.capturedTexts()[1]; + myIsSiman = true; + } +#endif + } + } + // Here pyfiles elements are: "script_name": [list_of_"arg"s] + // For example: "/absolute/path/to/my_script.py": ["1", "2"] - putInfo( "" ); -} + LightApp_Application::start(); + SALOME_EventFilter::Init(); -QString SalomeApp_Application::applicationName() const -{ - return "SalomeApp"; -} + if ( !hdffile.isEmpty() ) // open hdf file given as parameter + onOpenDoc( hdffile ); + else if ( pyfiles.count() > 0 ) // create new study + onNewDoc(); + else if (!loadStudy.isEmpty()) {// load study by name + if (onLoadDoc(loadStudy)) + updateObjectBrowser(true); + } -CAM_Module* SalomeApp_Application::loadModule( const QString& name ) -{ - CAM_Module* mod = CAM_Application::loadModule( name ); - if ( mod ) - { - connect( this, SIGNAL( studyOpened() ), mod, SLOT( onModelOpened() ) ); - connect( this, SIGNAL( studySaved() ), mod, SLOT( onModelSaved() ) ); - connect( this, SIGNAL( studyClosed() ), mod, SLOT( onModelClosed() ) ); + // import/execute python scripts + if ( pyfiles.count() > 0 && activeStudy() ) { + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + PyConsole_Console* pyConsole = pythonConsole(); + if ( appStudy && pyConsole ) { + _PTR(Study) aStudy = appStudy->studyDS(); + if ( !aStudy->GetProperties()->IsLocked() ) { + // pyfiles[j] is a dictionary: {"/absolute/path/to/script.py": [script_args]} + // Path is absolute, script has .py extension + for (uint j = 0; j < pyfiles.count(); j++ ) { + // Extract scripts and their arguments, if any + QRegExp rxp ("\"(.+)\":[\\s]*\\[(.*)\\]"); + if ( rxp.indexIn( pyfiles[j] ) >= 0 && rxp.capturedTexts().count() == 3 ) { + QString script = rxp.capturedTexts()[1]; + QString args = ""; + QStringList argList = rxp.capturedTexts()[2].split(",", QString::SkipEmptyParts); + for (uint k = 0; k < argList.count(); k++ ) { + QString arg = argList[k].trimmed(); + arg.remove( QRegExp("^[\"]") ); + arg.remove( QRegExp("[\"]$") ); + args += arg+","; + } + args.remove( QRegExp("[,]$") ); + if (!args.isEmpty()) { + args = "args:"+args; + } + + script.remove( QRegExp("^python.*[\\s]+") ); + QString cmd = script+" "+args; + QString command = QString( "execfile(r\"%1\")" ).arg(cmd.trimmed()); + pyConsole->exec(command); + } + } // end for loop on pyfiles QStringList + } + } + } + } else { + LightApp_Application::start(); + SALOME_EventFilter::Init(); } - return mod; } -bool SalomeApp_Application::activateModule( const QString& modName ) +/*!Create actions:*/ +void SalomeApp_Application::createActions() { - QString actName; - CAM_Module* prevMod = activeModule(); + LightApp_Application::createActions(); - if ( prevMod ) - actName = prevMod->moduleName(); - - if ( actName == modName ) - return true; + SUIT_Desktop* desk = desktop(); - saveWindowsGeometry(); + //! 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" ), + Qt::CTRL+Qt::Key_T, desk, false, this, SLOT( onLoadScript() ) ); + + //! Properties + createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIcon(), + tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ), + Qt::CTRL+Qt::Key_P, desk, false, this, SLOT( onProperties() ) ); + + //! Catalog Generator + createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIcon(), + tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ), + Qt::ALT+Qt::SHIFT+Qt::Key_G, desk, false, this, SLOT( onCatalogGen() ) ); + + //! Registry Display + createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIcon(), + 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 + +#ifdef WITH_SIMANIO + if (myIsSiman) { + // check-in operations for SIMAN study + createAction( SimanCheckInId, tr( "TOT_SIMAN_CHECK_IN" ), QIcon(), + tr( "MEN_SIMAN_CHECK_IN" ), tr( "PRP_SIMAN_CHECK_IN" ), + 0, desk, false, this, SLOT( onCheckIn() ) ); + createAction( SimanLocalCheckInId, tr( "TOT_SIMAN_LOCAL_CHECK_IN" ), QIcon(), + tr( "MEN_SIMAN_LOCAL_CHECK_IN" ), tr( "PRP_SIMAN_LOCAL_CHECK_IN" ), + 0, desk, false, this, SLOT( onLocalCheckIn() ) ); + } +#endif - bool status = CAM_Application::activateModule( modName ); + int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); - updateModuleActions(); + // "Save GUI State" command is renamed to "Save VISU State" and + // creation of menu item is moved to VISU + // createMenu( SaveGUIStateId, fileMenu, 10, -1 ); - if ( !status ) - return false; + createMenu( FileLoadId, fileMenu, 0 ); //SRN: BugID IPAL9021, add a menu item "Load" - updateWindows(); - updateViewManagers(); +#ifdef WITH_SIMANIO + if (myIsSiman) { + // check-in operation for SIMAN study + // last argument "5" locates this just after "Save As" but certain constant is bad => insert after the separator + createMenu( SimanCheckInId, fileMenu, 5); + createMenu( SimanLocalCheckInId, fileMenu, 5); + createMenu( separator(), fileMenu, 5 ); + } +#endif + createMenu( DumpStudyId, fileMenu, 10, -1 ); + createMenu( separator(), fileMenu, -1, 10, -1 ); + createMenu( LoadScriptId, fileMenu, 10, -1 ); + createMenu( separator(), fileMenu, -1, 10, -1 ); + createMenu( PropertiesId, fileMenu, 10, -1 ); + createMenu( separator(), fileMenu, -1, 10, -1 ); + + int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, MenuToolsId, 50 ); + createMenu( CatalogGenId, toolsMenu, 10, -1 ); + createMenu( RegDisplayId, toolsMenu, 10, -1 ); + createMenu( separator(), toolsMenu, -1, 15, -1 ); + + createExtraActions(); + + // import Python module that manages SALOME plugins + PyGILState_STATE gstate = PyGILState_Ensure(); + PyObjWrapper pluginsmanager = PyImport_ImportModule((char*)"salome_pluginsmanager"); + PyObjWrapper res = PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",0,"salome",tr("MEN_DESK_PLUGINS_TOOLS").toStdString().c_str(),tr("MEN_DESK_PLUGINS").toStdString().c_str()); + if ( !res ) + PyErr_Print(); + PyGILState_Release(gstate); + // end of SALOME plugins loading - return true; } -SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const + +/*!Set desktop:*/ +void SalomeApp_Application::setDesktop( SUIT_Desktop* desk ) { - return mySelMgr; + LightApp_Application::setDesktop( desk ); + + if ( desk ) { + connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); + connect( desk, SIGNAL( message( const QString& ) ), + this, SLOT( onLoadDocMessage( const QString& ) ), Qt::UniqueConnection ); + } } -void SalomeApp_Application::createActions() +/*! + \brief Close application. +*/ +void SalomeApp_Application::onExit() { - STD_Application::createActions(); - - SUIT_Desktop* desk = desktop(); - SUIT_ResourceMgr* resMgr = resourceMgr(); + bool killServers = false; + bool result = true; - // default icon for neutral point ('SALOME' module) - QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) ); - if ( defIcon.isNull() ) - defIcon = QPixmap( imageEmptyIcon ); + if ( exitConfirmation() ) { + SalomeApp_ExitDlg dlg( desktop() ); + result = dlg.exec() == QDialog::Accepted; + killServers = dlg.isServersShutdown(); + } - // default icon for any module - QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) ); - if ( modIcon.isNull() ) - modIcon = QPixmap( imageEmptyIcon ); + if ( result ) + SUIT_Session::session()->closeSession( SUIT_Session::ASK, killServers ); +} - QToolBar* modTBar = new QtxToolBar( true, desk ); - modTBar->setLabel( tr( "INF_TOOLBAR_MODULES" ) ); +/*!SLOT. Load document.*/ +void SalomeApp_Application::onLoadDoc() +{ + QString studyName; + + std::vector List = studyMgr()->GetOpenStudies(); + + SUIT_Session* aSession = SUIT_Session::session(); + QList aAppList = aSession->applications(); + + QStringList unloadedStudies; + + for ( unsigned int ind = 0; ind < List.size(); ind++ ) { + studyName = List[ind].c_str(); + // Add to list only unloaded studies + bool isAlreadyOpen = false; + QListIterator it( aAppList ); + while ( it.hasNext() && !isAlreadyOpen ) { + SUIT_Application* aApp = it.next(); + if( !aApp || !aApp->activeStudy() ) + continue; + if ( aApp->activeStudy()->studyName() == studyName ) + isAlreadyOpen = true; + } + + if ( !isAlreadyOpen ) + unloadedStudies << studyName; + } - QActionGroup* modGroup = new QActionGroup( this ); - modGroup->setExclusive( true ); - modGroup->setUsesDropDown( true ); + studyName = SalomeApp_LoadStudiesDlg::selectStudy( desktop(), unloadedStudies ); + if ( studyName.isEmpty() ) + return; - QAction* a = createAction( -1, tr( "APP_NAME" ), defIcon, tr( "APP_NAME" ), - tr( "PRP_APP_MODULE" ), 0, desk, true ); - modGroup->add( a ); - myActions.insert( QString(), a ); +#ifndef WIN32 + // this code replaces marker of windows drive and path become invalid therefore + // defines placed there + studyName.replace( QRegExp(":"), "/" ); +#endif - QMap iconMap; - moduleIconNames( iconMap ); + if ( onLoadDoc( studyName ) ) { + updateWindows(); + updateViewManagers(); + updateObjectBrowser( true ); + } +} - const int iconSize = 20; +/*!SLOT. Create new study and load script*/ +void SalomeApp_Application::onNewWithScript() +{ + QStringList filtersList; + filtersList.append(tr("PYTHON_FILES_FILTER")); + filtersList.append(tr("ALL_FILES_FILTER")); - modGroup->addTo( modTBar ); - modTBar->addSeparator(); + QString anInitialPath = ""; + if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) + anInitialPath = QDir::currentPath(); - QStringList modList; - modules( modList, false ); + QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true ); - for ( QStringList::Iterator it = modList.begin(); it != modList.end(); ++it ) + if ( !aFile.isEmpty() ) { - if ( (*it).isEmpty() ) - continue; - - QString iconName; - if ( iconMap.contains( *it ) ) - iconName = iconMap[*it]; - - QString modName = moduleName( *it ); + onNewDoc(); - QPixmap icon = resMgr->loadPixmap( modName, iconName ); - if ( icon.isNull() ) - icon = modIcon; + QString command = QString("execfile(r\"%1\")").arg(aFile); - icon.convertFromImage( icon.convertToImage().smoothScale( iconSize, iconSize, QImage::ScaleMin ) ); + PyConsole_Console* pyConsole = pythonConsole(); - QAction* a = createAction( -1, *it, icon, *it, tr( "PRP_MODULE" ).arg( *it ), 0, desk, true ); - a->addTo( modTBar ); - modGroup->add( a ); - - myActions.insert( *it, a ); + if ( pyConsole ) + pyConsole->exec( command ); } +} - SUIT_Tools::simplifySeparators( modTBar ); - // New window +/*!SLOT. Load document with \a aName.*/ +bool SalomeApp_Application::onLoadDoc( const QString& aName ) +{ + bool res = true; + if ( !activeStudy() ) { + // if no study - load in current desktop + res = useStudy( aName ); + } + else { + // if study exists - load in new desktop. Check: is the same file is loaded? + SUIT_Session* aSession = SUIT_Session::session(); + QList aAppList = aSession->applications(); + bool isAlreadyOpen = false; + SalomeApp_Application* aApp = 0; + for ( QList::iterator it = aAppList.begin(); + it != aAppList.end() && !isAlreadyOpen; ++it ) { + aApp = dynamic_cast( *it ); + if ( aApp && aApp->activeStudy()->studyName() == aName ) + isAlreadyOpen = true; + } + if ( !isAlreadyOpen ) { + aApp = dynamic_cast( startApplication( 0, 0 ) ); + if ( aApp ) + res = aApp->useStudy( aName ); + } + else { + aApp->desktop()->activateWindow(); + } + } - int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 ); - int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); - createMenu( separator(), windowMenu, -1, 1 ); + return res; +} - for ( int id = NewGLViewId; id <= NewVTKViewId; id++ ) - { - QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(), - tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), - tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), - 0, desk, false, this, SLOT( onNewWindow() ) ); - createMenu( a, newWinMenu, -1 ); +/*!SLOT. Load document with a name, specified in \a aMessage.*/ +void SalomeApp_Application::onLoadDocMessage(const QString& aMessage) +{ + if (aMessage.indexOf("simanCheckoutDone ") == 0) { +#ifdef WITH_SIMANIO + onLoadDoc(aMessage.section(' ', 1)); +#else + printf( "****************************************************************\n" ); + printf( "* Warning: SALOME is built without SIMAN support.\n" ); + printf( "****************************************************************\n" ); +#endif } - - connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) ); } -void SalomeApp_Application::onModuleActivation( QAction* a ) +/*!SLOT. Copy objects to study maneger from selection maneger..*/ +void SalomeApp_Application::onCopy() { - if ( !a ) - return; + 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; + + SALOME_ListIteratorOfListIO it( list ); + if(it.More()) + { + _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); + try { + studyMgr()->Copy(so); + onSelectionChanged(); + } + catch(...) { + } + } +} - QString modName = a->menuText(); - if ( modName == tr( "APP_NAME" ) ) - modName = QString::null; +/*!SLOT. Paste objects to study maneger from selection manager.*/ +void SalomeApp_Application::onPaste() +{ + SALOME_ListIO list; + LightApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(list); - // Force user to create/open a study before module activation - QMap iconMap; - moduleIconNames( iconMap ); - QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] ); + SalomeApp_Study* study = dynamic_cast(activeStudy()); + if(study == NULL) return; - bool cancelled = false; - while ( !modName.isEmpty() && !activeStudy() && !cancelled ){ - SalomeApp_ModuleDlg aDlg( desktop(), modName, icon ); - int res = aDlg.exec(); + _PTR(Study) stdDS = study->studyDS(); + if(!stdDS) return; - switch ( res ){ - case 1: - onNewDoc(); - break; - case 2: - onOpenDoc(); - break; - case 3: - //onLoadStudy(); - //break; - case 0: - default: - putInfo( tr("INF_CANCELLED") ); - myActions[QString()]->setOn( true ); - cancelled = true; - } + if ( stdDS->GetProperties()->IsLocked() ) { + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED") ); + return; } - if ( !cancelled ) - activateModule( modName ); + SALOME_ListIteratorOfListIO it( list ); + if(it.More()) + { + _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); + try { + studyMgr()->Paste(so); + updateObjectBrowser( true ); + updateActions(); //SRN: BugID IPAL9377, case 3 + } + catch(...) { + } + } } -QString SalomeApp_Application::defaultModule() const +/*!Check the application on closing. + * \retval true if possible, else false + */ +bool SalomeApp_Application::isPossibleToClose( bool& closePermanently ) { - QStringList aModuleNames; - modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration - // If there's the one and only module --> activate it automatically - // TODO: Possible improvement - default module can be taken from preferences - return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" ); + return LightApp_Application::isPossibleToClose( closePermanently ); } -void SalomeApp_Application::onNewWindow() +/*! Check if the study is locked */ +void SalomeApp_Application::onCloseDoc( bool ask ) { - const QObject* obj = sender(); - if ( !obj || !obj->inherits( "QAction" ) ) - return; + SalomeApp_Study* study = dynamic_cast(activeStudy()); - QString type; - int id = actionId( (QAction*)obj ); - switch ( id ) - { - case NewGLViewId: - type = GLViewer_Viewer::Type(); - break; - case NewPlot2dId: - type = Plot2d_Viewer::Type(); - break; - case NewOCCViewId: - type = OCCViewer_Viewer::Type(); - break; - case NewVTKViewId: - type = VTKViewer_Viewer::Type(); - break; + if (study != NULL) { + _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; + + } } - if ( !type.isEmpty() ) - createViewManager( type ); + LightApp_Application::onCloseDoc( ask ); } -//======================================================================= -// name : onNewDoc -// Purpose : SLOT. Create new document -//======================================================================= -void SalomeApp_Application::onNewDoc() +/*!Sets enable or disable some actions on selection changed.*/ +void SalomeApp_Application::onSelectionChanged() { - SUIT_Study* study = activeStudy(); + SALOME_ListIO list; + LightApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(list); - saveWindowsGeometry(); + bool canCopy = false; + bool canPaste = false; - CAM_Application::onNewDoc(); - - if ( !study ) // new study will be create in THIS application - { - updateWindows(); - updateViewManagers(); - } -} + SalomeApp_Study* study = dynamic_cast(activeStudy()); + if (study != NULL) { + _PTR(Study) stdDS = study->studyDS(); -//======================================================================= -// name : onOpenDoc -// Purpose : SLOT. Open new document -//======================================================================= -void SalomeApp_Application::onOpenDoc() -{ - SUIT_Study* study = activeStudy(); - saveWindowsGeometry(); + if (stdDS) { + SALOME_ListIteratorOfListIO it ( list ); - CAM_Application::onOpenDoc(); - - if ( !study ) // new study will be create in THIS application - { - updateWindows(); - updateViewManagers(); - } + if (it.More() && list.Extent() == 1) { + _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); + + if ( so ) { + canCopy = studyMgr()->CanCopy(so); + canPaste = studyMgr()->CanPaste(so); + } + } + } + } + + action(EditCopyId)->setEnabled(canCopy); + action(EditPasteId)->setEnabled(canPaste); } -void SalomeApp_Application::onSelection() +/*!Delete references.*/ +void SalomeApp_Application::onDeleteInvalidReferences() { - onSelectionChanged(); + SALOME_ListIO aList; + LightApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects( aList, QString(), false ); + + if( aList.IsEmpty() ) + return; + + SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); + _PTR(Study) aStudyDS = aStudy->studyDS(); + _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder(); + _PTR(SObject) anObj; - if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) ) - ((SalomeApp_Module*)activeModule())->selectionChanged(); + for( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) + if ( it.Value()->hasEntry() ) + { + _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ), aRefObj = aSObject; + while( aRefObj && aRefObj->ReferencedObject( anObj ) ) + aRefObj = anObj; + + if( aRefObj && aRefObj!=aSObject && QString( aRefObj->GetName().c_str() ).isEmpty() ) + aStudyBuilder->RemoveReference( aSObject ); + } + updateObjectBrowser(); } -void SalomeApp_Application::onSelectionChanged() +/*!Private SLOT. */ +void SalomeApp_Application::onOpenWith() { + QApplication::setOverrideCursor( Qt::WaitCursor ); + SALOME_ListIO aList; + LightApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(aList); + if (aList.Extent() != 1) + { + QApplication::restoreOverrideCursor(); + return; + } + Handle(SALOME_InteractiveObject) aIObj = aList.First(); + QString aModuleName(aIObj->getComponentDataType()); + QString aModuleTitle = moduleTitle(aModuleName); + activateModule(aModuleTitle); + QApplication::restoreOverrideCursor(); } -void SalomeApp_Application::setActiveStudy( SUIT_Study* study ) +/*! + Creates new study +*/ +SUIT_Study* SalomeApp_Application::createNewStudy() { - CAM_Application::setActiveStudy( study ); - - activateWindows(); -} + SalomeApp_Study* aStudy = new SalomeApp_Study( this ); -//======================================================================= -// name : createNewStudy -// Purpose : Create new study -//======================================================================= -SUIT_Study* SalomeApp_Application::createNewStudy() -{ - SalomeApp_Study* aStudy = new SalomeApp_Study( this ); - // Set up processing of major study-related events connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) ); connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) ); connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) ); connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) ); - return aStudy; + //to receive signal in application that NoteBook's variable was modified + connect( aStudy, SIGNAL(notebookVarUpdated(QString)), + this, SIGNAL(notebookVarUpdated(QString)) ); + + return aStudy; } -//======================================================================= -// name : createNewStudy -// Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu -//======================================================================= +/*! + Enable/Disable menu items and toolbar buttons. Rebuild menu +*/ void SalomeApp_Application::updateCommandsStatus() { - CAM_Application::updateCommandsStatus(); + LightApp_Application::updateCommandsStatus(); + + // Dump study menu + QAction* a = action( DumpStudyId ); + if ( a ) + a->setEnabled( activeStudy() ); + + // Load script menu + a = action( LoadScriptId ); + if ( a ) + a->setEnabled( activeStudy() ); + + // Properties menu + a = action( PropertiesId ); + if( a ) + a->setEnabled( activeStudy() ); - for ( int id = NewGLViewId; id <= NewVTKViewId; id++ ) + // Save GUI state menu + a = action( SaveGUIStateId ); + if( a ) + a->setEnabled( activeStudy() ); + + // update state of Copy/Paste menu items + onSelectionChanged(); +} + +/*! + \class DumpStudyFileDlg + 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 ) { - QAction* a = action( id ); - if ( a ) - a->setEnabled( activeStudy() ); + QGridLayout* grid = ::qobject_cast( layout() ); + if ( grid ) + { + QWidget *hB = new QWidget( this ); + myPublishChk = new QCheckBox( tr("PUBLISH_IN_STUDY") ); + myMultiFileChk = new QCheckBox( tr("MULTI_FILE_DUMP") ); + mySaveGUIChk = new QCheckBox( tr("SAVE_GUI_STATE") ); + + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(myPublishChk); + layout->addWidget(myMultiFileChk); + layout->addWidget(mySaveGUIChk); + hB->setLayout(layout); + + 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(); + } + } + QCheckBox* myPublishChk; + QCheckBox* myMultiFileChk; + QCheckBox* mySaveGUIChk; +}; + +class DumpStudyFileValidator : public SUIT_FileValidator +{ + public: + DumpStudyFileValidator( QWidget* parent) : SUIT_FileValidator ( parent ) {}; + virtual ~DumpStudyFileValidator() {}; + virtual bool canSave( const QString& file, bool permissions ); +}; + +bool DumpStudyFileValidator::canSave(const QString& file, bool permissions) +{ + QFileInfo fi( file ); + if ( !QRegExp( "[A-Za-z_][A-Za-z0-9_]*" ).exactMatch( fi.completeBaseName() ) ) { + SUIT_MessageBox::critical( parent(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_FILE_NAME_BAD") ); + return false; } + return SUIT_FileValidator::canSave( file, permissions); } -//======================================================================= -// name : onHelpAbout -// Purpose : SLOT. Display "About" message box -//======================================================================= -void SalomeApp_Application::onHelpAbout() +/*!Private SLOT. On dump study.*/ +void SalomeApp_Application::onDumpStudy( ) { - QMessageBox aDlg( desktop(), "AboutDlg" ); + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( !appStudy ) return; + _PTR(Study) aStudy = appStudy->studyDS(); - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aPixmap = aResMgr->loadPixmap( "SalomeApp", tr( "ABOUT_ICO" ) ); + QStringList aFilters; + aFilters.append( tr( "PYTHON_FILES_FILTER" ) ); - QFontMetrics m( aDlg.font() ); - QImage anImage = aPixmap.convertToImage(); - int w = m.height() * 5; - anImage = anImage.scale( w, w ); - aPixmap.convertFromImage( anImage ); + bool anIsPublish = true; + bool anIsMultiFile = false; + bool anIsSaveGUI = true; - aDlg.setCaption( tr( "ABOUT" ) ); - aDlg.setText( tr( "APP_NAME_LONG" ).arg( APP_VERSION ) ); - aDlg.setIconPixmap( aPixmap ); - aDlg.exec(); + if ( SUIT_ResourceMgr* aResourceMgr = resourceMgr() ) { + anIsPublish = aResourceMgr->booleanValue( "Study", "pydump_publish", anIsPublish ); + anIsMultiFile = aResourceMgr->booleanValue( "Study", "multi_file_dump", anIsMultiFile ); + anIsSaveGUI = aResourceMgr->booleanValue( "Study", "pydump_save_gui", anIsSaveGUI ); + } + + DumpStudyFileDlg fd( desktop() ); + fd.setValidator( new DumpStudyFileValidator( &fd ) ); + fd.setWindowTitle( tr( "TOT_DESK_FILE_DUMP_STUDY" ) ); + fd.setFilters( aFilters ); + fd.myPublishChk->setChecked( anIsPublish ); + fd.myMultiFileChk->setChecked( anIsMultiFile ); + fd.mySaveGUIChk->setChecked( anIsSaveGUI ); + if ( fd.exec() == QDialog::Accepted ) + { + QString aFileName = fd.selectedFile(); + + bool toPublish = fd.myPublishChk->isChecked(); + bool isMultiFile = fd.myMultiFileChk->isChecked(); + bool toSaveGUI = fd.mySaveGUIChk->isChecked(); + + if ( !aFileName.isEmpty() ) { + QFileInfo aFileInfo(aFileName); + if( aFileInfo.isDir() ) // IPAL19257 + return; + + // Issue 21377 - dump study implementation moved to SalomeApp_Study class + bool res; + { + SUIT_OverrideCursor wc; + res = appStudy->dump( aFileName, toPublish, isMultiFile, toSaveGUI ); + } + if ( !res ) + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + tr("WRN_DUMP_STUDY_FAILED") ); + } + } } -QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const +/*!Private SLOT. On load script.*/ +void SalomeApp_Application::onLoadScript( ) { - QWidget* wid = 0; + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( !appStudy ) return; + _PTR(Study) aStudy = appStudy->studyDS(); + + if ( aStudy->GetProperties()->IsLocked() ) { + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED") ); + return; + } + + QStringList filtersList; + filtersList.append(tr("PYTHON_FILES_FILTER")); + filtersList.append(tr("ALL_FILES_FILTER")); + + QString anInitialPath = ""; + if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) + anInitialPath = QDir::currentPath(); + +#ifdef WITH_SIMANIO + // MPV: if it is SIMAN study, make the initial path as the path to the Siman scripts storage + if (myIsSiman) { + SALOMEDSClient_StudyManager* aMgr = studyMgr(); + aMgr->GetSimanStudy()->StudyId(); + anInitialPath = QString(QDir::separator()) + "tmp" + QDir::separator() + "SimanSalome" + QDir::separator() + + aMgr->GetSimanStudy()->StudyId().c_str() + QDir::separator() + + aMgr->GetSimanStudy()->ScenarioId().c_str() + QDir::separator() + aMgr->GetSimanStudy()->UserId().c_str(); + } +#endif - int sId = studyId; - if ( sId < 0 ) + QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true ); + + if ( !aFile.isEmpty() ) { - if ( !activeStudy() ) - return 0; - else - sId = activeStudy()->id(); + QString command = QString("execfile(r\"%1\")").arg(aFile); + + PyConsole_Console* pyConsole = pythonConsole(); + + if ( pyConsole ) + pyConsole->exec( command ); } +} - if ( myWindows.contains( flag ) ) - wid = myWindows[flag]->widget( sId ); +/*!Private SLOT. On save GUI state.*/ +void SalomeApp_Application::onSaveGUIState() +{ + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + if ( study ) { + SalomeApp_VisualState( this ).storeState(); + updateSavePointDataObjects( study ); + updateObjectBrowser(); + } + updateActions(); +} - return wid; +/*!Public SLOT. On SIMAN check in operation.*/ +void SalomeApp_Application::onCheckIn() +{ +#ifdef WITH_SIMANIO + setMenuShown(SimanCheckInId, false); // check in may be performed only once + setMenuShown(SimanLocalCheckInId, false); + SALOMEDSClient_StudyManager* aMgr = studyMgr(); + aMgr->GetSimanStudy()->CheckIn(""); +#else + printf( "****************************************************************\n" ); + printf( "* Warning: SALOME is built without SIMAN support.\n" ); + printf( "****************************************************************\n" ); +#endif } -void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId ) +/*!Public SLOT. On SIMAN local check in operation.*/ +void SalomeApp_Application::onLocalCheckIn() { - if ( !wid ) - return; +#ifdef WITH_SIMANIO + // get the active module + CAM_Module* aModule = activeModule(); + if (!aModule) return; // there is no active module + + setMenuShown(SimanCheckInId, false); // check in may be performed only once + setMenuShown(SimanLocalCheckInId, false); + SALOMEDSClient_StudyManager* aMgr = studyMgr(); + aMgr->GetSimanStudy()->CheckIn(aModule->name().toLatin1().data()); +#else + printf( "****************************************************************\n" ); + printf( "* Warning: SALOME is built without SIMAN support.\n" ); + printf( "****************************************************************\n" ); +#endif +} - int sId = studyId; - if ( sId < 0 ) +/*!Gets file filter. + *\retval QString "(*.hdf)" + */ +QString SalomeApp_Application::getFileFilter() const +{ + return "(*.hdf)"; +} + +/*!Create window.*/ +QWidget* SalomeApp_Application::createWindow( const int flag ) +{ + QWidget* wid = 0; + if ( flag != WT_PyConsole ) wid = LightApp_Application::createWindow(flag); + + SUIT_ResourceMgr* resMgr = resourceMgr(); + + if ( flag == WT_ObjectBrowser ) { - if ( !activeStudy() ) - return; - else - sId = activeStudy()->id(); + SUIT_DataBrowser* ob = qobject_cast( wid ); + if ( ob ) { + // temporary commented + //ob->setUpdater( new SalomeApp_Updater() ); + +#ifdef WITH_SALOMEDS_OBSERVER + //do not activate the automatic update of Qt tree through signal/slot + ob->setAutoUpdate(false); + //activate update of modified objects only + ob->setUpdateModified(true); +#endif + + connect( ob, SIGNAL( doubleClicked( SUIT_DataObject* ) ), this, SLOT( onDblClick( SUIT_DataObject* ) ) ); + + QString + ValueCol = QObject::tr( "VALUE_COLUMN" ), + IORCol = QObject::tr( "IOR_COLUMN" ), + RefCol = QObject::tr( "REFENTRY_COLUMN" ), + EntryCol = QObject::tr( "ENTRY_COLUMN" ); + + SUIT_AbstractModel* treeModel = dynamic_cast( ob->model() ); + treeModel->registerColumn( 0, EntryCol, SalomeApp_DataObject::EntryId ); + treeModel->registerColumn( 0, ValueCol, SalomeApp_DataObject::ValueId ); + treeModel->registerColumn( 0, IORCol, SalomeApp_DataObject::IORId ); + treeModel->registerColumn( 0, RefCol, SalomeApp_DataObject::RefEntryId ); + treeModel->setAppropriate( EntryCol, Qtx::Toggled ); + treeModel->setAppropriate( ValueCol, Qtx::Toggled ); + treeModel->setAppropriate( IORCol, Qtx::Toggled ); + treeModel->setAppropriate( RefCol, Qtx::Toggled ); + + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); + bool autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true ); + bool resizeOnExpandItem = resMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", true ); + + ob->setAutoSizeFirstColumn(autoSizeFirst); + ob->setAutoSizeColumns(autoSize); + ob->setResizeOnExpandItem(resizeOnExpandItem); + ob->setProperty( "shortcut", QKeySequence( "Alt+Shift+O" ) ); + + // temporary commented + /* + for ( int i = SalomeApp_DataObject::ValueIdx; i <= SalomeApp_DataObject::RefEntryIdx; i++ ) + { + ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i ); + ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser", + QString().sprintf( "visibility_column_%d", i ), true ) ); + } + */ + + // temporary commented + /* + ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); + ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual ); + ob->resize( desktop()->width()/3, ob->height() ); + */ + } } - - if ( !myWindows.contains( flag ) ) + else if ( flag == WT_PyConsole ) + { + PyConsole_Console* pyCons = new PyConsole_EnhConsole( desktop(), new SalomeApp_PyInterp() ); + pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) ); + pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" )); + pyCons->setIsShowBanner(resourceMgr()->booleanValue( "PyConsole", "show_banner", true )); + pyCons->setProperty( "shortcut", QKeySequence( "Alt+Shift+P" ) ); + wid = pyCons; + //pyCons->resize( pyCons->width(), desktop()->height()/4 ); + pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + } + else if ( flag == WT_NoteBook ) { - QMap winMap; - currentWindows( winMap ); + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( appStudy ) { + _PTR(Study) aStudy = appStudy->studyDS(); + setNoteBook( new SalomeApp_NoteBook( desktop(), aStudy ) ); + //to receive signal in NoteBook that it's variable was modified + connect( this, SIGNAL( notebookVarUpdated( QString ) ), + getNoteBook(), SLOT( onVarUpdate( QString ) ) ); + } + wid = getNoteBook(); + } + return wid; +} - myWindows.insert( flag, new SalomeApp_WidgetContainer( flag, desktop() ) ); - if ( winMap.contains( flag ) ) - desktop()->moveDockWindow( myWindows[flag], (Dock)winMap[flag] ); +/*!Create preferences.*/ +void SalomeApp_Application::createPreferences( LightApp_Preferences* pref ) +{ + LightApp_Application::createPreferences(pref); + + if ( !pref ) + return; - myWindows[flag]->setResizeEnabled( true ); - myWindows[flag]->setCloseMode( QDockWindow::Always ); - myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) ); + int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) ); + int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat ); + int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab ); + for ( int i = SalomeApp_DataObject::EntryId; i < SalomeApp_DataObject::LastId; i++ ) + { + pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i-SalomeApp_DataObject::EntryId ).toLatin1() ), defCols, + LightApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_id_%d", i-1 ) ); } + pref->setItemProperty( "orientation", Qt::Vertical, defCols ); + + // adding preference to LightApp_Application handled preferences.. a bit of hacking with resources.. + int genTab = pref->addPreference( LightApp_Application::tr( "PREF_TAB_GENERAL" ), salomeCat ); + int studyGroup = pref->addPreference( LightApp_Application::tr( "PREF_GROUP_STUDY" ), genTab ); + pref->addPreference( tr( "PREF_STORE_VISUAL_STATE" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_visual_state" ); + pref->addPreference( "", studyGroup, LightApp_Preferences::Space ); + pref->addPreference( tr( "PREF_PYDUMP_PUBLISH" ), studyGroup, LightApp_Preferences::Bool, "Study", "pydump_publish" ); + pref->addPreference( tr( "PREF_PYDUMP_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file_dump" ); + pref->addPreference( tr( "PREF_PYDUMP_SAVE_GUI" ), studyGroup, LightApp_Preferences::Bool, "Study", "pydump_save_gui" ); + pref->addPreference( "", studyGroup, LightApp_Preferences::Space ); + pref->addPreference( "", studyGroup, LightApp_Preferences::Space ); +} - myWindows[flag]->insert( sId, wid ); +/*!Update desktop title.*/ +void SalomeApp_Application::updateDesktopTitle() { + QString aTitle = applicationName(); + QString aVer = applicationVersion(); + if ( !aVer.isEmpty() ) + aTitle += QString( " " ) + aVer; - setWindowShown( flag, !myWindows[flag]->isEmpty() ); + if ( activeStudy() ) + { + QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false ); + if ( !sName.isEmpty() ) { + SalomeApp_Study* study = dynamic_cast(activeStudy()); + if ( study ) { + _PTR(Study) stdDS = study->studyDS(); + if(stdDS) { + if ( stdDS->GetProperties()->IsLocked() ) { + aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) ); + } else { + aTitle += QString( " - [%1]" ).arg( sName ); + } + } + } + } + } + + desktop()->setWindowTitle( aTitle ); } -void SalomeApp_Application::removeWindow( const int flag, const int studyId ) +int SalomeApp_Application::closeChoice( const QString& docName ) { - if ( !myWindows.contains( flag ) ) - return; + 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 ); + + int res = CloseCancel; + if ( answer == 0 ) + res = CloseSave; + else if ( answer == 1 ) + res = CloseDiscard; + else if ( answer == 2 ) + res = CloseUnload; - int sId = studyId; - if ( sId < 0 ) + return res; +} + +bool SalomeApp_Application::closeAction( const int choice, bool& closePermanently ) +{ + bool res = true; + switch( choice ) { - if ( !activeStudy() ) - return; - else - sId = activeStudy()->id(); + case CloseSave: + if ( activeStudy()->isSaved() ) + onSaveDoc(); + else if ( !onSaveAsDoc() ) + res = false; + break; + case CloseDiscard: + break; + case CloseUnload: + closePermanently = false; + break; + case CloseCancel: + default: + res = false; } - myWindows[flag]->remove( sId ); - - setWindowShown( flag, !myWindows[flag]->isEmpty() ); + return res; } -QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId ) +int SalomeApp_Application::openChoice( const QString& aName ) { - QWidget* wid = window( flag, studyId ); - if ( !wid ) - addWindow( wid = createWindow( flag ), flag, studyId ); + int choice = LightApp_Application::openChoice( 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. + // 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; + } + } + } else { // file is not exist on disk + SUIT_MessageBox::warning( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_FILE_NOT_EXIST").arg(aName.toLatin1().data())); + return false; + } - return wid; + return choice; } -bool SalomeApp_Application::isWindowVisible( const int type ) const +bool SalomeApp_Application::openAction( const int aChoice, const QString& aName ) { bool res = false; - if ( myWindows.contains( type ) ) + int choice = aChoice; + switch ( choice ) { - SUIT_Desktop* desk = ((SalomeApp_Application*)this)->desktop(); - res = desk && desk->appropriate( myWindows[type] ); + 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; } -void SalomeApp_Application::setWindowShown( const int type, const bool on ) -{ - if ( !desktop() || !myWindows.contains( type ) ) - return; +/*! + \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 + 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 + the made choice. - QDockWindow* dw = myWindows[type]; - desktop()->setAppropriate( dw, on ); - on ? dw->show() : dw->hide(); + \return map of the operations + \sa moduleActionSelected() +*/ +QMap SalomeApp_Application::activateModuleActions() const +{ + QMap opmap = LightApp_Application::activateModuleActions(); + opmap.insert( LoadStudyId, tr( "ACTIVATE_MODULE_OP_LOAD" ) ); + opmap.insert( NewAndScriptId, tr( "ACTIVATE_MODULE_OP_SCRIPT" ) ); + return opmap; } -OB_Browser* SalomeApp_Application::objectBrowser() +/*! + \brief Called when the used selectes required operation chosen + from "Activate module" dialog box. + + Performs the required operation according to the user choice. + + \param id operation identifier + \sa activateModuleActions() +*/ +void SalomeApp_Application::moduleActionSelected( const int id ) { - OB_Browser* ob = 0; - QWidget* wid = getWindow( WT_ObjectBrowser ); - if ( wid->inherits( "OB_Browser" ) ) - ob = (OB_Browser*)wid; - return ob; + switch ( id ) { + case LoadStudyId: + onLoadDoc(); + break; + case NewAndScriptId: + onNewWithScript(); + break; + default: + LightApp_Application::moduleActionSelected( id ); + break; + } } -LogWindow* SalomeApp_Application::logWindow() +/*!Gets CORBA::ORB_var*/ +CORBA::ORB_var SalomeApp_Application::orb() { - LogWindow* lw = 0; - QWidget* wid = getWindow( WT_LogWindow ); - if ( wid->inherits( "LogWindow" ) ) - lw = (LogWindow*)wid; - return lw; + ORB_INIT& init = *SINGLETON_::Instance(); + static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() ); + return _orb; } -SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create ) +/*!Create and return SALOMEDS_StudyManager.*/ +SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr() { - SUIT_ViewManager* aVM = viewManager( vmType ); - SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager(); - if ( anActiveVM && anActiveVM->getType() == vmType ) - aVM = anActiveVM; - else if ( aVM ) - { - if ( !aVM->getActiveView() ) - aVM->createView(); - } - else if ( create ) - aVM = createViewManager( vmType ); - return aVM; + static _PTR(StudyManager) _sm; + if(!_sm) _sm = ClientFactory::StudyManager(); + return _sm.get(); } -SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType ) +/*!Create and return SALOME_NamingService.*/ +SALOME_NamingService* SalomeApp_Application::namingService() { - SUIT_ViewManager* viewMgr = 0; - if ( vmType == GLViewer_Viewer::Type() ) - { - viewMgr = new GLViewer_ViewManager( activeStudy(), desktop() ); - new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr ); - } - else if ( vmType == Plot2d_Viewer::Type() ) - viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() ); - else if ( vmType == OCCViewer_Viewer::Type() ) - { - viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() ); - viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface - new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr ); - } - else if ( vmType == SVTK_Viewer::Type() ) - { - viewMgr = new SVTK_ViewManager( activeStudy(), desktop() ); - new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr); - } + static SALOME_NamingService _ns(orb()); + return &_ns; +} - if ( !viewMgr ) - return 0; +/*!Create and return SALOME_LifeCycleCORBA.*/ +SALOME_LifeCycleCORBA* SalomeApp_Application::lcc() +{ + static SALOME_LifeCycleCORBA _lcc( namingService() ); + return &_lcc; +} - addViewManager( viewMgr ); - SUIT_ViewWindow* viewWin = viewMgr->createViewWindow(); +/*!Private SLOT. On preferences.*/ +void SalomeApp_Application::onProperties() +{ + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + if( !study ) + return; - if ( viewWin && desktop() ) - viewWin->resize( (int)( desktop()->width() * 0.6 ), (int)( desktop()->height() * 0.6 ) ); + _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder(); + SB->NewCommand(); - connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), - this, SLOT( onCloseView( SUIT_ViewManager* ) ) ); + SalomeApp_StudyPropertiesDlg aDlg( desktop() ); + int res = aDlg.exec(); + if( res==QDialog::Accepted && aDlg.isChanged() ) + SB->CommitCommand(); + else + SB->AbortCommand(); - return viewMgr; + //study->updateCaptions(); + updateDesktopTitle(); + updateActions(); } -void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM ) +/*!Insert items in popup, which necessary for current application*/ +void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title ) { - removeViewManager( theVM ); -} + LightApp_SelectionMgr* mgr = selectionMgr(); + bool cacheIsOn = mgr->isSelectionCacheEnabled(); + mgr->setSelectionCacheEnabled( true ); + + LightApp_Application::contextMenuPopup( type, thePopup, title ); + + // temporary commented + /*OB_Browser* ob = objectBrowser(); + if ( !ob || type != ob->popupClientType() ) + return;*/ + + // Get selected objects + SALOME_ListIO aList; + mgr->selectedObjects( aList, QString(), false ); + + // add GUI state commands: restore, rename + 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() ) ); + thePopup->addAction( tr( "MEN_RENAME_VS" ), objectBrowser(), + SLOT( onStartEditing() ), objectBrowser()->shortcutKey(SUIT_DataBrowser::RenameShortcut) ); + thePopup->addAction( tr( "MEN_DELETE_VS" ), this, SLOT( onDeleteGUIState() ) ); + } -void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy ) -{ - SUIT_DataObject* aRoot = 0; - if ( theStudy && theStudy->root() ) + // "Delete reference" item should appear only for invalid references + + // isInvalidRefs will be true, if at least one of selected objects is invalid reference + bool isInvalidRefs = false; + SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); + _PTR(Study) aStudyDS = aStudy->studyDS(); + _PTR(SObject) anObj; + + for( SALOME_ListIteratorOfListIO it( aList ); it.More() && !isInvalidRefs; it.Next() ) + if( it.Value()->hasEntry() ) + { + _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ), aRefObj = aSObject; + while( aRefObj && aRefObj->ReferencedObject( anObj ) ) + aRefObj = anObj; + + if( aRefObj && aRefObj!=aSObject && QString( aRefObj->GetName().c_str() ).isEmpty() ) + isInvalidRefs = true; + } + + // Add "Delete reference" item to popup + if ( isInvalidRefs ) { - aRoot = theStudy->root(); - //aRoot->setName( tr( "DATA_MODELS" ) ); + thePopup->addSeparator(); + thePopup->addAction( tr( "MEN_DELETE_INVALID_REFERENCE" ), this, SLOT( onDeleteInvalidReferences() ) ); + return; + } + + // "Activate module" item should appear only if it's necessary + if ( aList.Extent() == 1 ) { + aList.Clear(); + mgr->selectedObjects( aList ); + + Handle(SALOME_InteractiveObject) aIObj = aList.First(); + + // add extra popup menu (defined in XML) + if ( myExtActions.size() > 0 ) { + // Use only first selected object + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + if ( study ) { + _PTR(Study) stdDS = study->studyDS(); + if ( stdDS ) { + _PTR(SObject) aSO = stdDS->FindObjectID( aIObj->getEntry() ); + if ( aSO ) { + _PTR( GenericAttribute ) anAttr; + std::string auid = "AttributeUserID"; + auid += Kernel_Utils::GetGUID(Kernel_Utils::ObjectdID); + if ( aSO->FindAttribute( anAttr, auid ) ) { + _PTR(AttributeUserID) aAttrID = anAttr; + QString aId = aAttrID->Value().c_str(); + if ( myExtActions.contains( aId ) ) { + thePopup->addAction(myExtActions[aId]); + } + } + } + } + } + } + + // check if item is a "GUI state" item (also a first level object) + QString entry( aIObj->getEntry() ); + if ( !entry.startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) ) { + QString aModuleName( aIObj->getComponentDataType() ); + QString aModuleTitle = moduleTitle( aModuleName ); + CAM_Module* currentModule = activeModule(); + if ( ( !currentModule || currentModule->moduleName() != aModuleTitle ) && !aModuleTitle.isEmpty() ) + thePopup->addAction( tr( "MEN_OPENWITH" ).arg( aModuleTitle ), this, SLOT( onOpenWith() ) ); + } } - if ( objectBrowser() != 0 ) - objectBrowser()->setRootObject( aRoot ); - activateModule( defaultModule() ); + mgr->setSelectionCacheEnabled( cacheIsOn ); } -void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy ) +/*!Update obect browser: + 1.if 'updateModels' true, update existing data models; + 2. update "non-existing" (not loaded yet) data models; + 3. update object browser if it exists */ +void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) { - SUIT_DataObject* aRoot = 0; - if ( theStudy && theStudy->root() ) + // update "non-existing" (not loaded yet) data models + SalomeApp_Study* study = dynamic_cast(activeStudy()); + if ( study ) { - aRoot = theStudy->root(); - //aRoot->dump(); - } - if ( objectBrowser() != 0 ) { - objectBrowser()->setRootObject( aRoot ); + _PTR(Study) stdDS = study->studyDS(); + if( stdDS ) + { + for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() ) + { + _PTR(SComponent) aComponent ( it->Value() ); + +#ifndef WITH_SALOMEDS_OBSERVER + // with GUI observers this check is not needed anymore + if ( aComponent->ComponentDataType() == study->getVisualComponentName().toLatin1().constData() ) + continue; // skip the magic "Interface Applicative" component +#endif + if ( !objectBrowser() ) + getWindow( WT_ObjectBrowser ); + const bool isAutoUpdate = objectBrowser()->autoUpdate(); + objectBrowser()->setAutoUpdate( false ); + SalomeApp_DataModel::synchronize( aComponent, study ); + objectBrowser()->setAutoUpdate( isAutoUpdate ); + } + } } - activateWindows(); + // create data objects that correspond to GUI state save points + if ( study ) updateSavePointDataObjects( study ); - activateModule( defaultModule() ); + // update existing data models (already loaded SComponents) + LightApp_Application::updateObjectBrowser( updateModels ); +} - emit studyOpened(); +/*!Display Catalog Genenerator dialog */ +void SalomeApp_Application::onCatalogGen() +{ + ToolsGUI_CatalogGeneratorDlg aDlg( desktop() ); + aDlg.exec(); } -void SalomeApp_Application::onStudySaved( SUIT_Study* ) +/*!Display Registry Display dialog */ +void SalomeApp_Application::onRegDisplay() { - emit studySaved(); + CORBA::ORB_var anOrb = orb(); + ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop() ); + regWnd->show(); + regWnd->raise(); + regWnd->activateWindow(); } -void SalomeApp_Application::onStudyClosed( SUIT_Study* ) +/*!find original object by double click on item */ +void SalomeApp_Application::onDblClick( SUIT_DataObject* theObj ) { - emit studyClosed(); + // Issue 21379: References are supported at LightApp_DataObject level + LightApp_DataObject* obj = dynamic_cast( theObj ); + + if( obj && obj->isReference() ) + { + QString entry = obj->refEntry(); - activateModule( "" ); - if ( objectBrowser() != 0 ) - objectBrowser()->setRootObject( 0 ); + SUIT_DataOwnerPtrList aList; + aList.append( new LightApp_DataOwner( entry ) ); + selectionMgr()->setSelected( aList, false ); - saveWindowsGeometry(); + SUIT_DataBrowser* ob = objectBrowser(); + + QModelIndexList aSelectedIndexes = ob->selectedIndexes(); + if ( !aSelectedIndexes.isEmpty() ) + ob->treeView()->scrollTo( aSelectedIndexes.first() ); + } } -QString SalomeApp_Application::getFileFilter() const +/*! + Creates new view manager + \param type - type of view manager +*/ +SUIT_ViewManager* SalomeApp_Application::newViewManager(const QString& type) { - return "(*.hdf)"; + return createViewManager(type); } -void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s ) + +/*!Global utility funciton, returns selected GUI Save point object's ID */ +int getSelectedSavePoint( const LightApp_SelectionMgr* selMgr ) { - CAM_Application::beforeCloseDoc( s ); + SALOME_ListIO aList; + selMgr->selectedObjects( aList ); + if( aList.Extent() > 0 ) { + Handle(SALOME_InteractiveObject) aIObj = aList.First(); + QString entry( aIObj->getEntry() ); + QString startStr = QObject::tr( "SAVE_POINT_DEF_NAME" ); + if ( !entry.startsWith( startStr ) ) // it's a "GUI state" object + return -1; + bool ok; // conversion to integer is ok? + int savePoint = entry.right( entry.length() - startStr.length() ).toInt( &ok ); + return ok ? savePoint : -1; + } + return -1; +} - for ( WindowMap::ConstIterator itr = myWindows.begin(); s && itr != myWindows.end(); ++itr ) - removeWindow( itr.key(), s->id() ); +/*!Called on Restore GUI State popup command*/ +void SalomeApp_Application::onRestoreGUIState() +{ + int savePoint = ::getSelectedSavePoint( selectionMgr() ); + if ( savePoint == -1 ) + return; + SalomeApp_VisualState( this ).restoreState( savePoint ); } -void SalomeApp_Application::afterCloseDoc() +/*!Called on Delete GUI State popup command*/ +void SalomeApp_Application::onDeleteGUIState() { - updateWindows(); + int savePoint = ::getSelectedSavePoint( selectionMgr() ); + if ( savePoint == -1 ) + return; + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + if ( !study ) + return; - CAM_Application::afterCloseDoc(); + study->removeSavePoint( savePoint ); + updateSavePointDataObjects( study ); } -void SalomeApp_Application::updateActions() +/*!Called on New study operation*/ +void SalomeApp_Application::onStudyCreated( SUIT_Study* study ) { - updateCommandsStatus(); + LightApp_Application::onStudyCreated( study ); + + desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), + windowDock( getWindow( WT_ObjectBrowser ) ) ); + + loadDockWindowsState(); + + connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); + + + objectBrowserColumnsVisibility(); } -QWidget* SalomeApp_Application::createWindow( const int flag ) +/*!Called on Save study operation*/ +void SalomeApp_Application::onStudySaved( SUIT_Study* study ) { - QWidget* wid = 0; + LightApp_Application::onStudySaved( study ); - if ( flag == WT_ObjectBrowser ) - { - OB_Browser* ob = new OB_Browser( desktop() ); + // temporary commented + /*if ( objectBrowser() ) { + updateSavePointDataObjects( dynamic_cast( study ) ); + objectBrowser()->updateTree( study->root() ); + }*/ +} + +/*!Called on Open study operation*/ +void SalomeApp_Application::onStudyOpened( SUIT_Study* study ) +{ + LightApp_Application::onStudyOpened( study ); - ob->setCaption( tr( "OBJECT_BROWSER" ) ); - ob->resize( OBJECT_BROWSER_WIDTH, ob->height() ); - ob->setAutoUpdate( true ); + desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), + windowDock( getWindow( WT_ObjectBrowser ) ) ); - // Create OBSelector - new SalomeApp_OBSelector( ob, mySelMgr ); + loadDockWindowsState(); - wid = ob; + connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); + + objectBrowserColumnsVisibility(); + + // temporary commented + /*if ( objectBrowser() ) { + updateSavePointDataObjects( dynamic_cast( study ) ); + objectBrowser()->updateTree( study->root() ); + }*/ +} - ob->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); +/*! updateSavePointDataObjects: syncronize data objects that correspond to save points (gui states)*/ +void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study ) +{ + + SUIT_DataBrowser* ob = objectBrowser(); + LightApp_SelectionMgr* selMgr = selectionMgr(); + + if ( !study || !ob || !selMgr ) + return; + + // find GUI states root object + SUIT_DataObject* guiRootObj = 0; + DataObjectList ch; + study->root()->children( ch ); + DataObjectList::const_iterator it = ch.begin(), last = ch.end(); + for ( ; it != last ; ++it ) { + if ( dynamic_cast( *it ) ) { + guiRootObj = *it; + break; + } + } + std::vector savePoints = study->getSavePoints(); + // case 1: no more save points but they existed in study's tree + if ( savePoints.empty() && guiRootObj ) { + //rnv : to fix bug "IPAL22450 TC6.3.0: sigsegv loop deleting the GUI state" + // : set auto update to true for removing SalomeApp_SavePointRootObject from the SUIT_TreeModel + const bool isAutoUpdate = ob->autoUpdate(); + selMgr->clearSelected(); + ob->setAutoUpdate(true); + DataObjectList ch = guiRootObj->children(); + for( int i = 0; i < ch.size(); i++ ) + delete ch[i]; + delete guiRootObj; + ob->setAutoUpdate(isAutoUpdate); + return; + } + // case 2: no more save points but root does not exist either + if ( savePoints.empty() && !guiRootObj ) + return; + // case 3: save points but no root for them - create it + if ( !savePoints.empty() && !guiRootObj ) + guiRootObj = new SalomeApp_SavePointRootObject( study->root() ); + // case 4: everything already exists.. here may be a problem: we want "GUI states" root object + // to be always the last one in the tree. Here we check - if it is not the last one - remove and + // re-create it. + if ( guiRootObj->nextBrother() ) { + study->root()->removeChild(guiRootObj); + study->root()->appendChild(guiRootObj); + //study->root()->dump(); } - else if ( flag == WT_PyConsole ) - { - PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() ); - pyCons->setCaption( tr( "PYTHON_CONSOLE" ) ); - wid = pyCons; - // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + // store data objects in a map id-to-DataObject + QMap mapDO; + ch.clear(); + guiRootObj->children( ch ); + for( it = ch.begin(), last = ch.end(); it != last ; ++it ) { + SalomeApp_SavePointObject* dobj = dynamic_cast( *it ); + if ( dobj ) + mapDO[dobj->getId()] = dobj; } - else if ( flag == WT_LogWindow ) - { - LogWindow* logWin = new LogWindow( desktop() ); - logWin->setCaption( tr( "LOG_WINDOW" ) ); - wid = logWin; - logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); + // iterate new save points. if DataObject with such ID not found in map - create DataObject + // 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 ); + else + mapDO.remove( savePoints[i] ); + + // delete DataObjects that are still in the map -- their IDs were not found in data model + if( mapDO.size() > 0) { + //rnv : to fix bug "IPAL22450 TC6.3.0: sigsegv loop deleting the GUI state" + // : set auto update to true for removing SalomeApp_SavePointObject from the SUIT_TreeModel + selMgr->clearSelected(); + const bool isAutoUpdate = ob->autoUpdate(); + ob->setAutoUpdate(true); + for ( QMap::Iterator it = mapDO.begin(); it != mapDO.end(); ++it ) + delete it.value(); + ob->setAutoUpdate(isAutoUpdate); } - - return wid; } -void SalomeApp_Application::defaultWindows( QMap& aMap ) const +/*! Check data object */ +bool SalomeApp_Application::checkDataObject(LightApp_DataObject* theObj) { - aMap.insert( WT_ObjectBrowser, Qt::DockLeft ); - aMap.insert( WT_PyConsole, Qt::DockBottom ); + if (theObj) + return true; + + return false; } -void SalomeApp_Application::defaultViewManagers( QStringList& ) const +/*! + Opens other study into active Study. If Study is empty - creates it. + \param theName - name of study +*/ +bool SalomeApp_Application::useStudy( const QString& theName ) { + createEmptyStudy(); + SalomeApp_Study* aStudy = dynamic_cast( activeStudy() ); + bool res = false; + if (aStudy) + res = aStudy->loadDocument( theName ); + updateDesktopTitle(); + updateCommandsStatus(); + return res; } -void SalomeApp_Application::afterCloseDoc() +/*! Show/hide object browser colums according to preferences */ +void SalomeApp_Application::objectBrowserColumnsVisibility() { - updateWindows(); - - CAM_Application::afterCloseDoc(); + if ( objectBrowser() ) + for ( int i = SalomeApp_DataObject::EntryId; i < SalomeApp_DataObject::LastId; i++ ) + { + bool shown = resourceMgr()->booleanValue( "ObjectBrowser", QString( "visibility_column_id_%1" ).arg( i-1 ), true ); + objectBrowser()->treeView()->setColumnHidden( i, !shown ); + } } -CORBA::ORB_var SalomeApp_Application::orb() +/*! Set SalomeApp_NoteBook pointer */ +void SalomeApp_Application::setNoteBook( SalomeApp_NoteBook* theNoteBook ) { - ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var& orb = init( qApp->argc(), qApp->argv() ); + myNoteBook = theNoteBook; +} - return orb; +/*! Return SalomeApp_NoteBook pointer */ +SalomeApp_NoteBook* SalomeApp_Application::getNoteBook() const +{ + return myNoteBook; } -SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr() +/*! + * Define extra actions defined in module definition XML file. + * Additional popup items sections can be defined by parameter "popupitems". + * Supported attributes: + * title - title of menu item, + * attributelocalid - AttributeLocalId defined for selected data item where menu command has to be applied, + * method - method which has to be called when menu item is selected + * Example: + *
+ * + *
+ *
+ * + * + * + *
+ */ +void SalomeApp_Application::createExtraActions() { - static SALOMEDSClient_StudyManager* aStudyManager = NULL; - - if(!aStudyManager) { - aStudyManager = new SALOMEDS_StudyManager(); + myExtActions.clear(); + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + + QStringList aModules; + modules(aModules, false); + foreach(QString aModile, aModules) { + QString aModName = moduleName(aModile); + QString aSectionStr = resMgr->stringValue(aModName, "popupitems", QString()); + if (!aSectionStr.isNull()) { + QStringList aSections = aSectionStr.split(':'); + foreach(QString aSection, aSections) { + QString aTitle = resMgr->stringValue(aSection, "title", QString()); + QString aId = resMgr->stringValue(aSection, "objectid", QString()); + QString aSlot = resMgr->stringValue(aSection, "method", QString()); + if (aTitle.isEmpty() || aSlot.isEmpty() || aId.isEmpty()) + continue; + + QString aModuleName = resMgr->stringValue(aSection, "module", QString()); + if (aModuleName.isNull()) + aModuleName = aModName; + + QAction* aAction = new QAction(aTitle, this); + QStringList aData; + aData<setData(aData); + connect(aAction, SIGNAL(triggered()), this, SLOT(onExtAction())); + myExtActions[aId] = aAction; + } + } } - return aStudyManager; } -SALOME_NamingService* SalomeApp_Application::namingService() +/*! + * Called when extra action is selected + */ +void SalomeApp_Application::onExtAction() { - return new SALOME_NamingService( orb() ); + QAction* aAction = ::qobject_cast(sender()); + if (!aAction) + return; + + QVariant aData = aAction->data(); + QStringList aDataList = aData.value(); + if (aDataList.size() != 2) + return; + + LightApp_SelectionMgr* aSelectionMgr = selectionMgr(); + SALOME_ListIO aListIO; + aSelectionMgr->selectedObjects(aListIO); + const Handle(SALOME_InteractiveObject)& anIO = aListIO.First(); + if (aListIO.Extent() < 1) + return; + if (!anIO->hasEntry()) + return; + + QString aEntry(anIO->getEntry()); + + QApplication::setOverrideCursor( Qt::WaitCursor ); + QString aModuleTitle = moduleTitle(aDataList[0]); + activateModule(aModuleTitle); + QApplication::restoreOverrideCursor(); + + QCoreApplication::processEvents(); + + CAM_Module* aModule = activeModule(); + if (!aModule) + return; + + if (!QMetaObject::invokeMethod(aModule, qPrintable(aDataList[1]), Q_ARG(QString, aEntry))) + printf("Error: Can't Invoke method %s\n", qPrintable(aDataList[1])); } -QString SalomeApp_Application::defaultEngineIOR() +/*! + * Called when window activated + */ +void SalomeApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow ) { - // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence) - QString anIOR( "" ); - CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" ); - if ( !CORBA::is_nil( anEngine ) ) - anIOR = orb()->object_to_string( anEngine ); - return anIOR; + SUIT_DataBrowser* anOB = objectBrowser(); + if( !anOB ) + return; + SUIT_DataObject* rootObj = anOB->root(); + if( !rootObj ) + return; + + DataObjectList listObj = rootObj->children( true ); + + SUIT_ViewModel* vmod = 0; + if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() ) + vmod = vman->getViewModel(); + updateVisibilityState( listObj, vmod ); } -void SalomeApp_Application::moduleIconNames( QMap& iconMap ) const +/*! + Update visibility state of given objects + */ +void SalomeApp_Application::updateVisibilityState( DataObjectList& theList, + SUIT_ViewModel* theViewModel ) { - iconMap.clear(); + LightApp_Study* aStudy = dynamic_cast(activeStudy()); - SUIT_ResourceMgr* resMgr = resourceMgr(); - if ( !resMgr ) + if(!theViewModel) return; - QStringList modList; - modules( modList, false ); + SALOME_View* aView = dynamic_cast( theViewModel ); - for ( QStringList::const_iterator it = modList.begin(); it != modList.end(); ++it ) - { - QString modName = *it; - QString modIntr = moduleName( modName ); - QString modIcon = resMgr->stringValue( modIntr, "icon", QString::null ); + if (theList.isEmpty() || !aStudy) + return; - if ( modIcon.isEmpty() ) - continue; + for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) { + LightApp_DataObject* obj = dynamic_cast(*itr); - if ( SUIT_Tools::extension( modIcon ).isEmpty() ) - modIcon += QString( ".png" ); + if (!obj || aStudy->isComponent(obj->entry())) + continue; - iconMap.insert( modName, modIcon ); + LightApp_Module* anObjModule = dynamic_cast(obj->module()); + Qtx::VisibilityState anObjState = Qtx::UnpresentableState; + + if(anObjModule) { + LightApp_Displayer* aDisplayer = anObjModule->displayer(); + if(aDisplayer) { + if( aDisplayer->canBeDisplayed(obj->entry(), theViewModel->getType()) ) { + if(aView && aDisplayer->IsDisplayed(obj->entry(),aView)) + anObjState = Qtx::ShownState; + else + anObjState = Qtx::HiddenState; + } + aStudy->setVisibilityState( obj->entry(), anObjState ); + } + } } } -void SalomeApp_Application::updateModuleActions() +/*! + Called then view manager removed +*/ +void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) { - QString modName; - if ( activeModule() ) - modName = activeModule()->moduleName(); + ViewManagerList lst; + viewManagers(lst); + if( lst.count() == 1) { // in case if closed last view window + LightApp_Study* aStudy = dynamic_cast(activeStudy()); + if(aStudy) + aStudy->setVisibilityStateForAll(Qtx::UnpresentableState); + } +} - if ( myActions.contains( modName ) ) - myActions[modName]->setOn( true ); +/*! + Checks that an object can be renamed. + \param entry entry of the object + \brief Return \c true if object can be renamed +*/ +bool SalomeApp_Application::renameAllowed( const QString& entry) const +{ + return entry.startsWith( tr( "SAVE_POINT_DEF_NAME") ); } -void SalomeApp_Application::currentWindows( QMap& winMap ) const +/*! + Rename object by entry. + \param entry entry of the object + \param name new name of the object + \brief Return \c true if rename operation finished successfully, \c false otherwise. +*/ +bool SalomeApp_Application::renameObject( const QString& entry, const QString& name ) { - winMap.clear(); - if ( !activeStudy() ) - return; + SalomeApp_Study* aStudy = dynamic_cast( activeStudy() ); - if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) ) - ((SalomeApp_Module*)activeModule())->windows( winMap ); - else - defaultWindows( winMap ); + int savePoint = ::getSelectedSavePoint( selectionMgr() ); + + if(!aStudy || savePoint == -1) + return false; + + if ( !name.isNull() && !name.isEmpty() ) { + aStudy->setNameOfSavePoint( savePoint, name ); + updateSavePointDataObjects( aStudy ); + + //Mark study as modified + aStudy->Modified(); + return true; + } + return false; } -void SalomeApp_Application::currentViewManagers( QStringList& lst ) const +/*! + \return default windows( Object Browser, Python Console ) + Adds to map \a aMap. +*/ +void SalomeApp_Application::defaultWindows( QMap& aMap ) const { - lst.clear(); - if ( !activeStudy() ) - return; - - if ( activeModule() && activeModule()->inherits( "SalomeApp_Module" ) ) - ((SalomeApp_Module*)activeModule())->viewManagers( lst ); - else - defaultViewManagers( lst ); + LightApp_Application::defaultWindows(aMap); + if ( !aMap.contains( WT_NoteBook ) ) { + if ( !myNoteBook ) { + aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea ); + } + } } -void SalomeApp_Application::updateWindows() +/*! + Gets current windows. + \param winMap - output current windows map. +*/ +void SalomeApp_Application::currentWindows(QMap& aMap) const { - QMap winMap; - currentWindows( winMap ); + LightApp_Application::currentWindows( aMap ); + if ( !aMap.contains( WT_NoteBook) && myNoteBook ) + aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea ); +} - for ( QMap::ConstIterator it = winMap.begin(); it != winMap.end(); ++it ) - getWindow( it.key() ); +//============================================================================ +/*! Function : onUpdateStudy + * Purpose : Slot to update the study. + */ +//============================================================================ +void SalomeApp_Application::onUpdateStudy() +{ + QApplication::setOverrideCursor( Qt::WaitCursor ); - loadWindowsGeometry(); + if( !updateStudy() ) + SUIT_MessageBox::warning( desktop(), tr( "ERROR" ), tr( "ERR_UPDATE_STUDY_FAILED" ) ); - for ( WindowMap::ConstIterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) - setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) ); + QApplication::restoreOverrideCursor(); } -void SalomeApp_Application::updateViewManagers() +//============================================================================ +/*! Function : updateStudy + * Purpose : Update study by dumping the study to Python script and loading it. + * It is used to apply variable modifications done in NoteBook to created objects. + */ +//============================================================================ +bool SalomeApp_Application::updateStudy() { - QStringList lst; - currentViewManagers( lst ); + SalomeApp_Study* study = dynamic_cast( activeStudy() ); + if ( !study || !myNoteBook ) + return false; - for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it ) - getViewManager( *it, true ); -} + myNoteBook->setIsDumpedStudySaved( study->isSaved() ); + myNoteBook->setDumpedStudyName( study->studyName() ); -void SalomeApp_Application::loadWindowsGeometry() -{ - QtxDockAction* dockMgr = 0; + _PTR(Study) studyDS = study->studyDS(); - QAction* a = action( ViewWindowsId ); - if ( a && a->inherits( "QtxDockAction" ) ) - dockMgr = (QtxDockAction*)a; + // get unique temporary directory name + QString aTmpDir = QString::fromStdString( SALOMEDS_Tool::GetTmpDir() ); + if( aTmpDir.isEmpty() ) + return false; - if ( !dockMgr ) - return; + if( aTmpDir.right( 1 ).compare( QDir::separator() ) == 0 ) + aTmpDir.remove( aTmpDir.length() - 1, 1 ); + + // dump study to the temporary directory + QString aScriptName( "notebook" ); + bool toPublish = true; + bool isMultiFile = false; + bool toSaveGUI = true; + + int savePoint; + _PTR(AttributeParameter) ap; + _PTR(IParameters) ip = ClientFactory::getIParameters(ap); + if(ip->isDumpPython(studyDS)) ip->setDumpPython(studyDS); //Unset DumpPython flag. + if ( toSaveGUI ) { //SRN: Store a visual state of the study at the save point for DumpStudy method + ip->setDumpPython(studyDS); + savePoint = SalomeApp_VisualState( this ).storeState(); //SRN: create a temporary save point + } + bool ok = studyDS->DumpStudy( aTmpDir.toStdString(), aScriptName.toStdString(), toPublish, isMultiFile ); + if ( toSaveGUI ) + study->removeSavePoint(savePoint); //SRN: remove the created temporary save point. - QString modName; - if ( activeModule() ) - modName = moduleLibrary( activeModule()->moduleName(), false ); - - QString section = QString( "windows_geometry" ); - if ( !modName.isEmpty() ) - section += QString( "." ) + modName; + if( ok ) + myNoteBook->setDumpedStudyScript( aTmpDir + QDir::separator() + aScriptName + ".py" ); + else + return false; + + QList aList = SUIT_Session::session()->applications(); + int anIndex = aList.indexOf( this ); + + // Disconnect dialog from application desktop in case if: + // 1) Application is not the first application in the session + // 2) Application is the first application in session but not the only. + bool changeDesktop = ((anIndex > 0) || (anIndex == 0 && aList.count() > 1)); + if( changeDesktop ) { + + SalomeApp_Application* app = this; + if( anIndex > 0 && anIndex < aList.count() ) + app = dynamic_cast( aList[ anIndex - 1 ] ); + else if(anIndex == 0 && aList.count() > 1) + app = dynamic_cast( aList[ 1 ] ); + + if( !app ) + return false; + + // creation a new study and restoring will be done in another application + connect( this, SIGNAL( dumpedStudyClosed( const QString&, const QString&, bool ) ), + app, SLOT( onRestoreStudy( const QString&, const QString&, bool ) ), Qt::UniqueConnection ); + } + + QString aDumpScript = myNoteBook->getDumpedStudyScript(); + QString aStudyName = myNoteBook->getDumpedStudyName(); + bool isStudySaved = myNoteBook->isDumpedStudySaved(); + // clear a study (delete all objects) + onCloseDoc( false ); + if( !changeDesktop ) { + ok = onRestoreStudy( aDumpScript, + aStudyName, + isStudySaved ); + } - dockMgr->loadGeometry( resourceMgr(), section, false ); - dockMgr->restoreGeometry(); + return ok; } -void SalomeApp_Application::saveWindowsGeometry() +//============================================================================ +/*! Function : onRestoreStudy + * Purpose : Load the dumped study from Python script + */ +//============================================================================ +bool SalomeApp_Application::onRestoreStudy( const QString& theDumpScript, + const QString& theStudyName, + bool theIsStudySaved ) { - QtxDockAction* dockMgr = 0; + bool ok = true; - QAction* a = action( ViewWindowsId ); - if ( a && a->inherits( "QtxDockAction" ) ) - dockMgr = (QtxDockAction*)a; + // create a new study + onNewDoc(); - if ( !dockMgr ) - return; + // get active application + SalomeApp_Application* app = dynamic_cast( SUIT_Session::session()->activeApplication() ); - QString modName; - if ( activeModule() ) - modName = moduleLibrary( activeModule()->moduleName(), false ); - - QString section = QString( "windows_geometry" ); - if ( !modName.isEmpty() ) - section += QString( "." ) + modName; + // load study from the temporary directory + QString command = QString( "execfile(r\"%1\")" ).arg( theDumpScript ); + + PyConsole_Console* pyConsole = app->pythonConsole(); + if ( pyConsole ) + pyConsole->execAndWait( command ); - dockMgr->storeGeometry(); - dockMgr->saveGeometry( resourceMgr(), section, false ); + // remove temporary directory + QFileInfo aScriptInfo = QFileInfo( theDumpScript ); + QString aStudyName = aScriptInfo.baseName(); + QDir aDir = aScriptInfo.absoluteDir(); + QStringList aFiles = aDir.entryList( QStringList( "*.py*" ) ); + for( QStringList::iterator it = aFiles.begin(), itEnd = aFiles.end(); it != itEnd; ++it ) + ok = aDir.remove( *it ) && ok; + if( ok ) + ok = aDir.rmdir( aDir.absolutePath() ); + + if( SalomeApp_Study* newStudy = dynamic_cast( app->activeStudy() ) ) + { + _PTR(Study) aStudyDS = newStudy->studyDS(); + app->getNoteBook()->Init( aStudyDS ); + newStudy->updateFromNotebook(theStudyName, theIsStudySaved); + newStudy->Modified(); + updateDesktopTitle(); + updateActions(); + } + else + ok = false; + + return ok; } -void SalomeApp_Application::activateWindows() +/*! + Close the Application +*/ +void SalomeApp_Application::afterCloseDoc() { - if ( activeStudy() ) - { - for ( WindowMap::Iterator itr = myWindows.begin(); itr != myWindows.end(); ++itr ) - itr.data()->activate( activeStudy()->id() ); + // emit signal to restore study from Python script + if ( myNoteBook ) { + emit dumpedStudyClosed( myNoteBook->getDumpedStudyScript(), + myNoteBook->getDumpedStudyName(), + myNoteBook->isDumpedStudySaved() ); } + LightApp_Application::afterCloseDoc(); }