-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE\r
-//\r
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS\r
-//\r
-// This library is free software; you can redistribute it and/or\r
-// modify it under the terms of the GNU Lesser General Public\r
-// License as published by the Free Software Foundation; either\r
-// version 2.1 of the License.\r
-//\r
-// This library is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
-// Lesser General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU Lesser General Public\r
-// License along with this library; if not, write to the Free Software\r
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-//\r
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com\r
-//\r
-\r
-// File: SalomeApp_Application.cxx\r
-// Created: 10/22/2004 3:23:45 PM\r
-// Author: Sergey LITONIN\r
-\r
-#ifdef WNT\r
-// E.A. : On windows with python 2.6, there is a conflict\r
-// E.A. : between pymath.h and Standard_math.h which define\r
-// E.A. : some same symbols : acosh, asinh, ...\r
-#include <Standard_math.hxx>\r
-#include <pymath.h>\r
-#endif\r
-\r
-#include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!\r
-#include "SalomeApp_Application.h"\r
-#include "SalomeApp_Study.h"\r
-#include "SalomeApp_DataModel.h"\r
-#include "SalomeApp_DataObject.h"\r
-#include "SalomeApp_VisualState.h"\r
-#include "SalomeApp_StudyPropertiesDlg.h"\r
-#include "SalomeApp_LoadStudiesDlg.h"\r
-#include "SalomeApp_NoteBook.h"\r
-\r
-#include "SalomeApp_ExitDlg.h"\r
-\r
-#include <LightApp_Application.h>\r
-#include <LightApp_Module.h>\r
-#include <LightApp_Preferences.h>\r
-#include <LightApp_SelectionMgr.h>\r
-#include <LightApp_NameDlg.h>\r
-#include <LightApp_DataOwner.h>\r
-#include <LightApp_Displayer.h>\r
-\r
-#include <CAM_Module.h>\r
-\r
-#include <SUIT_Tools.h>\r
-#include <SUIT_Session.h>\r
-#include <SUIT_Desktop.h>\r
-#include <SUIT_DataBrowser.h>\r
-#include <SUIT_FileDlg.h>\r
-#include <SUIT_FileValidator.h>\r
-#include <SUIT_MessageBox.h>\r
-#include <SUIT_ResourceMgr.h>\r
-#include <SUIT_TreeModel.h>\r
-#include <SUIT_ViewWindow.h>\r
-#include <SUIT_ViewManager.h>\r
-#include <SUIT_ViewModel.h>\r
-\r
-#include <QtxTreeView.h>\r
-\r
-#include <SALOME_EventFilter.h>\r
-\r
-// temporary commented\r
-//#include <OB_ListItem.h>\r
-\r
-#include <PyConsole_Console.h>\r
-\r
-#include <Utils_ORB_INIT.hxx>\r
-#include <Utils_SINGLETON.hxx>\r
-#include <SALOME_LifeCycleCORBA.hxx>\r
-\r
-#include <QApplication>\r
-#include <QAction>\r
-#include <QRegExp>\r
-#include <QCheckBox>\r
-#include <QPushButton>\r
-#include <QLabel>\r
-#include <QListWidget>\r
-#include <QGridLayout>\r
-#include <QMenu>\r
-#include <QtDebug>\r
-\r
-#include <SALOMEDSClient_ClientFactory.hxx>\r
-#include <Basics_Utils.hxx>\r
-\r
-#include <SALOME_ListIO.hxx>\r
-#include <SALOME_ListIteratorOfListIO.hxx>\r
-#include <SALOME_Prs.h>\r
-\r
-\r
-#include <ToolsGUI_CatalogGeneratorDlg.h>\r
-#include <ToolsGUI_RegWidget.h>\r
-\r
-#include <vector>\r
-\r
-#include <SALOMEDS_Tool.hxx>\r
-\r
-/*!Internal class that updates object browser item properties */\r
-// temporary commented\r
-/*class SalomeApp_Updater : public OB_Updater\r
-{\r
-public:\r
- SalomeApp_Updater() : OB_Updater(){};\r
- virtual ~SalomeApp_Updater(){};\r
- virtual void update( SUIT_DataObject* theObj, OB_ListItem* theItem );\r
-};\r
-\r
-void SalomeApp_Updater::update( SUIT_DataObject* theObj, OB_ListItem* theItem )\r
-{\r
- if( !theObj || !theItem )\r
- return;\r
-\r
- SalomeApp_DataObject* SAObj = dynamic_cast<SalomeApp_DataObject*>( theObj );\r
- if( !SAObj )\r
- return;\r
-\r
- _PTR(SObject) SObj = SAObj->object();\r
- if( !SObj )\r
- return;\r
- _PTR( GenericAttribute ) anAttr;\r
-\r
- // Selectable\r
- if ( SObj->FindAttribute( anAttr, "AttributeSelectable" ) )\r
- {\r
- _PTR(AttributeSelectable) aAttrSel = anAttr;\r
- theItem->setSelectable( aAttrSel->IsSelectable() );\r
- }\r
- // Expandable\r
- if ( SObj->FindAttribute(anAttr, "AttributeExpandable") )\r
- {\r
- _PTR(AttributeExpandable) aAttrExpand = anAttr;\r
- theItem->setExpandable( aAttrExpand->IsExpandable() );\r
- }\r
- // Opened\r
- //this attribute is not supported in the version of SALOME 3.x\r
- //if ( SObj->FindAttribute(anAttr, "AttributeOpened") )\r
- //{\r
- // _PTR(AttributeOpened) aAttrOpen = anAttr;\r
- // theItem->setOpen( aAttrOpen->IsOpened() );\r
- //}\r
-}*/\r
-\r
-/*!Create new instance of SalomeApp_Application.*/\r
-extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()\r
-{\r
- return new SalomeApp_Application();\r
-}\r
-\r
-/*!Constructor.*/\r
-SalomeApp_Application::SalomeApp_Application()\r
- : LightApp_Application()\r
-{\r
- connect( desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),\r
- this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );\r
-\r
- setNoteBook(0);\r
-}\r
-\r
-/*!Destructor.\r
- *\li Destroy event filter.\r
- */\r
-SalomeApp_Application::~SalomeApp_Application()\r
-{\r
- // Do not destroy. It's a singleton !\r
- //SALOME_EventFilter::Destroy();\r
-}\r
-\r
-/*!Start application.*/\r
-void SalomeApp_Application::start()\r
-{\r
- LightApp_Application::start();\r
-\r
- SALOME_EventFilter::Init();\r
-\r
- static bool isFirst = true;\r
- if ( isFirst ) {\r
- isFirst = false;\r
-\r
- QString hdffile;\r
- QStringList pyfiles;\r
-\r
- for (int i = 1; i < qApp->argc(); i++) {\r
- QRegExp rxs ("--study-hdf=(.+)");\r
- if ( rxs.indexIn( QString(qApp->argv()[i]) ) >= 0 && rxs.capturedTexts().count() > 1 ) {\r
- QString file = rxs.capturedTexts()[1];\r
- QFileInfo fi ( file );\r
- QString extension = fi.suffix().toLower();\r
- if ( extension == "hdf" && fi.exists() )\r
- hdffile = fi.absoluteFilePath();\r
- }\r
- else {\r
- QRegExp rxp ("--pyscript=(.+)");\r
- if ( rxp.indexIn( QString(qApp->argv()[i]) ) >= 0 && rxp.capturedTexts().count() > 1 ) {\r
- QStringList files = rxp.capturedTexts()[1].split(",",QString::SkipEmptyParts);\r
- pyfiles += files;\r
- }\r
- }\r
- }\r
-\r
- if ( !hdffile.isEmpty() ) // open hdf file given as parameter\r
- onOpenDoc( hdffile );\r
- else if ( pyfiles.count() > 0 ) // create new study\r
- onNewDoc();\r
-\r
- // import/execute python scripts\r
- if ( pyfiles.count() > 0 && activeStudy() ) {\r
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- PyConsole_Console* pyConsole = pythonConsole();\r
- if ( appStudy && pyConsole ) {\r
- _PTR(Study) aStudy = appStudy->studyDS();\r
- if ( !aStudy->GetProperties()->IsLocked() ) {\r
- for (uint j = 0; j < pyfiles.count(); j++ ) {\r
- QFileInfo fi ( pyfiles[j] );\r
- QFileInfo fipy ( pyfiles[j] + ".py" );\r
- QString command = QString( "execfile(r\"%1\")" );\r
- if ( fi.isAbsolute() ) {\r
- if ( fi.exists() )\r
- pyConsole->exec( command.arg( fi.absoluteFilePath() ) );\r
- else if ( fipy.exists() )\r
- pyConsole->exec( command.arg( fipy.absoluteFilePath() ) );\r
- else\r
- qDebug() << "Can't execute file" << pyfiles[j];\r
- }\r
- else {\r
- bool found = false;\r
- QStringList dirs;\r
- dirs << QDir::currentPath();\r
- if ( ::getenv( "PYTHONPATH" ) )\r
- dirs += QString( ::getenv( "PYTHONPATH" ) ).split( QRegExp( "[:|;]" ) );\r
- foreach( QString dir, dirs ) {\r
- qDebug() << "try" << QFileInfo( dir, pyfiles[j] ).absoluteFilePath();\r
- qDebug() << "try" << QFileInfo( dir, pyfiles[j] + ".py" ).absoluteFilePath();\r
- if ( QFileInfo( dir, pyfiles[j] ).exists() ) {\r
- pyConsole->exec( command.arg( QFileInfo( dir, pyfiles[j] ).absoluteFilePath() ) );\r
- found = true;\r
- break;\r
- }\r
- else if ( QFileInfo( dir, pyfiles[j] + ".py" ).exists() ) {\r
- pyConsole->exec( command.arg( QFileInfo( dir, pyfiles[j] + ".py" ).absoluteFilePath() ) );\r
- found = true;\r
- break;\r
- }\r
- }\r
- if ( !found ) {\r
- qDebug() << "Can't execute file" << pyfiles[j];\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
-}\r
-\r
-/*!Create actions:*/\r
-void SalomeApp_Application::createActions()\r
-{\r
- LightApp_Application::createActions();\r
-\r
- SUIT_Desktop* desk = desktop();\r
-\r
- //! Save GUI state\r
- // "Save GUI State" command is moved to VISU module\r
- // createAction( SaveGUIStateId, tr( "TOT_DESK_FILE_SAVE_GUI_STATE" ), QIcon(),\r
- // tr( "MEN_DESK_FILE_SAVE_GUI_STATE" ), tr( "PRP_DESK_FILE_SAVE_GUI_STATE" ),\r
- // 0, desk, false, this, SLOT( onSaveGUIState() ) );\r
-\r
- //! Dump study\r
- createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIcon(),\r
- tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),\r
- Qt::CTRL+Qt::Key_D, desk, false, this, SLOT( onDumpStudy() ) );\r
- \r
- //! Load script\r
- createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIcon(),\r
- tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),\r
- Qt::CTRL+Qt::Key_T, desk, false, this, SLOT( onLoadScript() ) );\r
-\r
- //! Properties\r
- createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIcon(),\r
- tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),\r
- Qt::CTRL+Qt::Key_P, desk, false, this, SLOT( onProperties() ) );\r
-\r
- //! Catalog Generator\r
- createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIcon(),\r
- tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),\r
- Qt::ALT+Qt::SHIFT+Qt::Key_G, desk, false, this, SLOT( onCatalogGen() ) );\r
-\r
- //! Registry Display\r
- createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIcon(),\r
- tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),\r
- /*Qt::SHIFT+Qt::Key_D*/0, desk, false, this, SLOT( onRegDisplay() ) );\r
-\r
- //SRN: BugID IPAL9021, add an action "Load"\r
- createAction( FileLoadId, tr( "TOT_DESK_FILE_LOAD" ),\r
- resourceMgr()->loadPixmap( "STD", tr( "ICON_FILE_OPEN" ) ),\r
- tr( "MEN_DESK_FILE_LOAD" ), tr( "PRP_DESK_FILE_LOAD" ),\r
- Qt::CTRL+Qt::Key_L, desk, false, this, SLOT( onLoadDoc() ) );\r
- //SRN: BugID IPAL9021: End\r
-\r
-\r
- int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );\r
-\r
- // "Save GUI State" command is renamed to "Save VISU State" and\r
- // creation of menu item is moved to VISU\r
- // createMenu( SaveGUIStateId, fileMenu, 10, -1 );\r
-\r
- createMenu( FileLoadId, fileMenu, 0 ); //SRN: BugID IPAL9021, add a menu item "Load"\r
-\r
- createMenu( DumpStudyId, fileMenu, 10, -1 );\r
- createMenu( separator(), fileMenu, -1, 10, -1 );\r
- createMenu( LoadScriptId, fileMenu, 10, -1 );\r
- createMenu( separator(), fileMenu, -1, 10, -1 );\r
- createMenu( PropertiesId, fileMenu, 10, -1 );\r
- createMenu( separator(), fileMenu, -1, 10, -1 );\r
-\r
- int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, MenuToolsId, 50 );\r
- createMenu( CatalogGenId, toolsMenu, 10, -1 );\r
- createMenu( RegDisplayId, toolsMenu, 10, -1 );\r
- createMenu( separator(), toolsMenu, -1, 15, -1 );\r
-\r
- createExtraActions();\r
-\r
- // import Python module that manages SALOME plugins\r
- PyGILState_STATE gstate = PyGILState_Ensure();\r
- PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");\r
- PyObject* 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());\r
- if(res==NULL)\r
- PyErr_Print();\r
- Py_XDECREF(res);\r
- PyGILState_Release(gstate);\r
- // end of SALOME plugins loading\r
-\r
-}\r
-\r
-\r
-/*!Set desktop:*/\r
-void SalomeApp_Application::setDesktop( SUIT_Desktop* desk )\r
-{\r
- LightApp_Application::setDesktop( desk );\r
-\r
- if ( desk ) {\r
- connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ),\r
- this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );\r
- }\r
-}\r
-\r
-/*!\r
- \brief Close application.\r
-*/\r
-void SalomeApp_Application::onExit()\r
-{\r
- bool killServers = false;\r
- bool result = true;\r
-\r
- if ( exitConfirmation() ) {\r
- SalomeApp_ExitDlg dlg( desktop() );\r
- result = dlg.exec() == QDialog::Accepted;\r
- killServers = dlg.isServersShutdown();\r
- }\r
-\r
- if ( result )\r
- SUIT_Session::session()->closeSession( SUIT_Session::ASK, killServers );\r
-}\r
-\r
-/*!SLOT. Load document.*/\r
-void SalomeApp_Application::onLoadDoc()\r
-{\r
- QString studyName;\r
-\r
- std::vector<std::string> List = studyMgr()->GetOpenStudies();\r
-\r
- SUIT_Session* aSession = SUIT_Session::session();\r
- QList<SUIT_Application*> aAppList = aSession->applications();\r
-\r
- QStringList unloadedStudies;\r
-\r
- for ( unsigned int ind = 0; ind < List.size(); ind++ ) {\r
- studyName = List[ind].c_str();\r
- // Add to list only unloaded studies\r
- bool isAlreadyOpen = false;\r
- QListIterator<SUIT_Application*> it( aAppList );\r
- while ( it.hasNext() && !isAlreadyOpen ) {\r
- SUIT_Application* aApp = it.next();\r
- if( !aApp || !aApp->activeStudy() )\r
- continue;\r
- if ( aApp->activeStudy()->studyName() == studyName )\r
- isAlreadyOpen = true;\r
- }\r
-\r
- if ( !isAlreadyOpen )\r
- unloadedStudies << studyName;\r
- }\r
-\r
- studyName = SalomeApp_LoadStudiesDlg::selectStudy( desktop(), unloadedStudies );\r
- if ( studyName.isEmpty() )\r
- return;\r
-\r
-#ifndef WIN32\r
- // this code replaces marker of windows drive and path become invalid therefore\r
- // defines placed there\r
- studyName.replace( QRegExp(":"), "/" );\r
-#endif\r
-\r
- if ( onLoadDoc( studyName ) ) {\r
- updateWindows();\r
- updateViewManagers();\r
- updateObjectBrowser( true );\r
- }\r
-}\r
-\r
-/*!SLOT. Create new study and load script*/\r
-void SalomeApp_Application::onNewWithScript()\r
-{\r
- QStringList filtersList;\r
- filtersList.append(tr("PYTHON_FILES_FILTER"));\r
- filtersList.append(tr("ALL_FILES_FILTER"));\r
-\r
- QString anInitialPath = "";\r
- if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )\r
- anInitialPath = QDir::currentPath();\r
-\r
- QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );\r
-\r
- if ( !aFile.isEmpty() )\r
- {\r
- onNewDoc();\r
-\r
- QString command = QString("execfile(r\"%1\")").arg(aFile);\r
-\r
- PyConsole_Console* pyConsole = pythonConsole();\r
-\r
- if ( pyConsole )\r
- pyConsole->exec( command );\r
- }\r
-}\r
-\r
-\r
-/*!SLOT. Load document with \a aName.*/\r
-bool SalomeApp_Application::onLoadDoc( const QString& aName )\r
-{\r
- bool res = true;\r
- if ( !activeStudy() ) {\r
- // if no study - load in current desktop\r
- res = useStudy( aName );\r
- }\r
- else {\r
- // if study exists - load in new desktop. Check: is the same file is loaded?\r
- SUIT_Session* aSession = SUIT_Session::session();\r
- QList<SUIT_Application*> aAppList = aSession->applications();\r
- bool isAlreadyOpen = false;\r
- SalomeApp_Application* aApp = 0;\r
- for ( QList<SUIT_Application*>::iterator it = aAppList.begin();\r
- it != aAppList.end() && !isAlreadyOpen; ++it ) {\r
- aApp = dynamic_cast<SalomeApp_Application*>( *it );\r
- if ( aApp && aApp->activeStudy()->studyName() == aName )\r
- isAlreadyOpen = true;\r
- }\r
- if ( !isAlreadyOpen ) {\r
- aApp = dynamic_cast<SalomeApp_Application*>( startApplication( 0, 0 ) );\r
- if ( aApp )\r
- res = aApp->useStudy( aName );\r
- }\r
- else {\r
- aApp->desktop()->activateWindow();\r
- }\r
- }\r
-\r
- return res;\r
-}\r
-\r
-/*!SLOT. Copy objects to study maneger from selection maneger..*/\r
-void SalomeApp_Application::onCopy()\r
-{\r
- SALOME_ListIO list;\r
- LightApp_SelectionMgr* mgr = selectionMgr();\r
- mgr->selectedObjects(list);\r
-\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
- if(study == NULL) return;\r
-\r
- _PTR(Study) stdDS = study->studyDS();\r
- if(!stdDS) return;\r
-\r
- SALOME_ListIteratorOfListIO it( list );\r
- if(it.More())\r
- {\r
- _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());\r
- try {\r
- studyMgr()->Copy(so);\r
- onSelectionChanged();\r
- }\r
- catch(...) {\r
- }\r
- }\r
-}\r
-\r
-/*!SLOT. Paste objects to study maneger from selection manager.*/\r
-void SalomeApp_Application::onPaste()\r
-{\r
- SALOME_ListIO list;\r
- LightApp_SelectionMgr* mgr = selectionMgr();\r
- mgr->selectedObjects(list);\r
-\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
- if(study == NULL) return;\r
-\r
- _PTR(Study) stdDS = study->studyDS();\r
- if(!stdDS) return;\r
-\r
- if ( stdDS->GetProperties()->IsLocked() ) {\r
- SUIT_MessageBox::warning( desktop(),\r
- QObject::tr("WRN_WARNING"),\r
- QObject::tr("WRN_STUDY_LOCKED") );\r
- return;\r
- }\r
-\r
- SALOME_ListIteratorOfListIO it( list );\r
- if(it.More())\r
- {\r
- _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());\r
- try {\r
- studyMgr()->Paste(so);\r
- updateObjectBrowser( true );\r
- updateActions(); //SRN: BugID IPAL9377, case 3\r
- }\r
- catch(...) {\r
- }\r
- }\r
-}\r
-\r
-/*!Check the application on closing.\r
- * \retval true if possible, else false\r
- */\r
-bool SalomeApp_Application::isPossibleToClose( bool& closePermanently )\r
-{\r
- return LightApp_Application::isPossibleToClose( closePermanently );\r
-}\r
-\r
-/*! Check if the study is locked */\r
-void SalomeApp_Application::onCloseDoc( bool ask )\r
-{\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
-\r
- if (study != NULL) {\r
- _PTR(Study) stdDS = study->studyDS();\r
- if(stdDS && stdDS->IsStudyLocked()) {\r
- if ( SUIT_MessageBox::question( desktop(),\r
- QObject::tr( "WRN_WARNING" ),\r
- QObject::tr( "CLOSE_LOCKED_STUDY" ),\r
- SUIT_MessageBox::Yes | SUIT_MessageBox::No,\r
- SUIT_MessageBox::No) == SUIT_MessageBox::No ) return;\r
-\r
- }\r
- }\r
-\r
- LightApp_Application::onCloseDoc( ask );\r
-}\r
-\r
-/*!Sets enable or disable some actions on selection changed.*/\r
-void SalomeApp_Application::onSelectionChanged()\r
-{\r
- SALOME_ListIO list;\r
- LightApp_SelectionMgr* mgr = selectionMgr();\r
- mgr->selectedObjects(list);\r
-\r
- bool canCopy = false;\r
- bool canPaste = false;\r
-\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
- if (study != NULL) {\r
- _PTR(Study) stdDS = study->studyDS();\r
-\r
- if (stdDS) {\r
- SALOME_ListIteratorOfListIO it ( list );\r
-\r
- if (it.More() && list.Extent() == 1) {\r
- _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());\r
-\r
- if ( so ) {\r
- canCopy = studyMgr()->CanCopy(so);\r
- canPaste = studyMgr()->CanPaste(so);\r
- }\r
- }\r
- }\r
- }\r
-\r
- action(EditCopyId)->setEnabled(canCopy);\r
- action(EditPasteId)->setEnabled(canPaste);\r
-}\r
-\r
-/*!Delete references.*/\r
-void SalomeApp_Application::onDeleteInvalidReferences()\r
-{\r
- SALOME_ListIO aList;\r
- LightApp_SelectionMgr* mgr = selectionMgr();\r
- mgr->selectedObjects( aList, QString(), false );\r
-\r
- if( aList.IsEmpty() )\r
- return;\r
-\r
- SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
- _PTR(Study) aStudyDS = aStudy->studyDS();\r
- _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();\r
- _PTR(SObject) anObj;\r
-\r
- for( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )\r
- if ( it.Value()->hasEntry() )\r
- {\r
- _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ), aRefObj = aSObject;\r
- while( aRefObj && aRefObj->ReferencedObject( anObj ) )\r
- aRefObj = anObj;\r
-\r
- if( aRefObj && aRefObj!=aSObject && QString( aRefObj->GetName().c_str() ).isEmpty() )\r
- aStudyBuilder->RemoveReference( aSObject );\r
- }\r
- updateObjectBrowser();\r
-}\r
-\r
-/*!Private SLOT. */\r
-void SalomeApp_Application::onOpenWith()\r
-{\r
- QApplication::setOverrideCursor( Qt::WaitCursor );\r
- SALOME_ListIO aList;\r
- LightApp_SelectionMgr* mgr = selectionMgr();\r
- mgr->selectedObjects(aList);\r
- if (aList.Extent() != 1)\r
- {\r
- QApplication::restoreOverrideCursor();\r
- return;\r
- }\r
- Handle(SALOME_InteractiveObject) aIObj = aList.First();\r
- QString aModuleName(aIObj->getComponentDataType());\r
- QString aModuleTitle = moduleTitle(aModuleName);\r
- activateModule(aModuleTitle);\r
- QApplication::restoreOverrideCursor();\r
-}\r
-\r
-/*!\r
- Creates new study\r
-*/\r
-SUIT_Study* SalomeApp_Application::createNewStudy()\r
-{\r
- SalomeApp_Study* aStudy = new SalomeApp_Study( this );\r
-\r
- // Set up processing of major study-related events\r
- connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );\r
- connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );\r
- connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) );\r
- connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );\r
-\r
- //to receive signal in application that NoteBook's variable was modified\r
- connect( aStudy, SIGNAL(notebookVarUpdated(QString)), \r
- this, SIGNAL(notebookVarUpdated(QString)) );\r
-\r
- return aStudy;\r
-}\r
-\r
-/*!\r
- Enable/Disable menu items and toolbar buttons. Rebuild menu\r
-*/\r
-void SalomeApp_Application::updateCommandsStatus()\r
-{\r
- LightApp_Application::updateCommandsStatus();\r
-\r
- // Dump study menu\r
- QAction* a = action( DumpStudyId );\r
- if ( a )\r
- a->setEnabled( activeStudy() );\r
-\r
- // Load script menu\r
- a = action( LoadScriptId );\r
- if ( a )\r
- a->setEnabled( activeStudy() );\r
-\r
- // Properties menu\r
- a = action( PropertiesId );\r
- if( a )\r
- a->setEnabled( activeStudy() );\r
-\r
- // Save GUI state menu\r
- a = action( SaveGUIStateId );\r
- if( a )\r
- a->setEnabled( activeStudy() );\r
-\r
- // update state of Copy/Paste menu items\r
- onSelectionChanged();\r
-}\r
-\r
-/*!\r
- \class DumpStudyFileDlg\r
- Private class used in Dump Study operation. Consists 2 check boxes:\r
- "Publish in study" and "Save GUI parameters"\r
-*/\r
-class DumpStudyFileDlg : public SUIT_FileDlg\r
-{\r
-public:\r
- DumpStudyFileDlg( QWidget* parent ) : SUIT_FileDlg( parent, false, true, true )\r
- {\r
- QGridLayout* grid = ::qobject_cast<QGridLayout*>( layout() );\r
- if ( grid )\r
- {\r
- QWidget *hB = new QWidget( this );\r
- myPublishChk = new QCheckBox( tr("PUBLISH_IN_STUDY") );\r
- myMultiFileChk = new QCheckBox( tr("MULTI_FILE_DUMP") );\r
- mySaveGUIChk = new QCheckBox( tr("SAVE_GUI_STATE") );\r
-\r
- QHBoxLayout *layout = new QHBoxLayout;\r
- layout->addWidget(myPublishChk);\r
- layout->addWidget(myMultiFileChk);\r
- layout->addWidget(mySaveGUIChk);\r
- hB->setLayout(layout);\r
-\r
- QPushButton* pb = new QPushButton(this);\r
-\r
- int row = grid->rowCount();\r
- grid->addWidget( new QLabel("", this), row, 0 );\r
- grid->addWidget( hB, row, 1, 1, 3 );\r
- grid->addWidget( pb, row, 5 );\r
-\r
- pb->hide();\r
- }\r
- }\r
- QCheckBox* myPublishChk;\r
- QCheckBox* myMultiFileChk;\r
- QCheckBox* mySaveGUIChk;\r
-};\r
-\r
-class DumpStudyFileValidator : public SUIT_FileValidator\r
-{\r
- public:\r
- DumpStudyFileValidator( QWidget* parent) : SUIT_FileValidator ( parent ) {};\r
- virtual ~DumpStudyFileValidator() {};\r
- virtual bool canSave( const QString& file, bool permissions );\r
-};\r
-\r
-bool DumpStudyFileValidator::canSave(const QString& file, bool permissions)\r
-{\r
- QFileInfo fi( file );\r
- if ( !QRegExp( "[A-Za-z_][A-Za-z0-9_]*" ).exactMatch( fi.completeBaseName() ) ) {\r
- SUIT_MessageBox::critical( parent(),\r
- QObject::tr("WRN_WARNING"),\r
- QObject::tr("WRN_FILE_NAME_BAD") );\r
- return false;\r
- }\r
- return SUIT_FileValidator::canSave( file, permissions);\r
-}\r
-\r
-/*!Private SLOT. On dump study.*/\r
-void SalomeApp_Application::onDumpStudy( )\r
-{\r
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if ( !appStudy ) return;\r
- _PTR(Study) aStudy = appStudy->studyDS();\r
-\r
- QStringList aFilters;\r
- aFilters.append( tr( "PYTHON_FILES_FILTER" ) );\r
-\r
- bool anIsPublish = true;\r
- bool anIsMultiFile = false;\r
- bool anIsSaveGUI = true;\r
-\r
- if ( SUIT_ResourceMgr* aResourceMgr = resourceMgr() ) {\r
- anIsPublish = aResourceMgr->booleanValue( "Study", "pydump_publish", anIsPublish );\r
- anIsMultiFile = aResourceMgr->booleanValue( "Study", "multi_file_dump", anIsMultiFile );\r
- anIsSaveGUI = aResourceMgr->booleanValue( "Study", "pydump_save_gui", anIsSaveGUI );\r
- }\r
-\r
- DumpStudyFileDlg fd( desktop() );\r
- fd.setValidator( new DumpStudyFileValidator( &fd ) );\r
- fd.setWindowTitle( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );\r
- fd.setFilters( aFilters );\r
- fd.myPublishChk->setChecked( anIsPublish );\r
- fd.myMultiFileChk->setChecked( anIsMultiFile );\r
- fd.mySaveGUIChk->setChecked( anIsSaveGUI );\r
- if ( fd.exec() == QDialog::Accepted )\r
- {\r
- QString aFileName = fd.selectedFile();\r
-\r
- bool toPublish = fd.myPublishChk->isChecked();\r
- bool isMultiFile = fd.myMultiFileChk->isChecked();\r
- bool toSaveGUI = fd.mySaveGUIChk->isChecked();\r
-\r
- if ( !aFileName.isEmpty() ) {\r
- QFileInfo aFileInfo(aFileName);\r
- if( aFileInfo.isDir() ) // IPAL19257\r
- return;\r
- \r
- // Issue 21377 - dump study implementation moved to SalomeApp_Study class\r
- bool res = appStudy->dump( aFileName, toPublish, isMultiFile, toSaveGUI );\r
-\r
- if ( !res )\r
- SUIT_MessageBox::warning( desktop(),\r
- QObject::tr("WRN_WARNING"),\r
- tr("WRN_DUMP_STUDY_FAILED") );\r
- }\r
- }\r
-}\r
-\r
-/*!Private SLOT. On load script.*/\r
-void SalomeApp_Application::onLoadScript( )\r
-{\r
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if ( !appStudy ) return;\r
- _PTR(Study) aStudy = appStudy->studyDS();\r
-\r
- if ( aStudy->GetProperties()->IsLocked() ) {\r
- SUIT_MessageBox::warning( desktop(),\r
- QObject::tr("WRN_WARNING"),\r
- QObject::tr("WRN_STUDY_LOCKED") );\r
- return;\r
- }\r
-\r
- QStringList filtersList;\r
- filtersList.append(tr("PYTHON_FILES_FILTER"));\r
- filtersList.append(tr("ALL_FILES_FILTER"));\r
-\r
- QString anInitialPath = "";\r
- if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )\r
- anInitialPath = QDir::currentPath();\r
-\r
- QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );\r
-\r
- if ( !aFile.isEmpty() )\r
- {\r
- QString command = QString("execfile(r\"%1\")").arg(aFile);\r
-\r
- PyConsole_Console* pyConsole = pythonConsole();\r
-\r
- if ( pyConsole )\r
- pyConsole->exec( command );\r
- }\r
-}\r
-\r
-/*!Private SLOT. On save GUI state.*/\r
-void SalomeApp_Application::onSaveGUIState()\r
-{\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if ( study ) {\r
- SalomeApp_VisualState( this ).storeState();\r
- updateSavePointDataObjects( study );\r
- updateObjectBrowser();\r
- }\r
- updateActions();\r
-}\r
-\r
-/*!Gets file filter.\r
- *\retval QString "(*.hdf)"\r
- */\r
-QString SalomeApp_Application::getFileFilter() const\r
-{\r
- return "(*.hdf)";\r
-}\r
-\r
-/*!Create window.*/\r
-QWidget* SalomeApp_Application::createWindow( const int flag )\r
-{\r
- QWidget* wid = 0;\r
- if ( flag != WT_PyConsole ) wid = LightApp_Application::createWindow(flag);\r
-\r
- SUIT_ResourceMgr* resMgr = resourceMgr();\r
-\r
- if ( flag == WT_ObjectBrowser )\r
- {\r
- SUIT_DataBrowser* ob = qobject_cast<SUIT_DataBrowser*>( wid );\r
- if ( ob ) {\r
- // temporary commented\r
- //ob->setUpdater( new SalomeApp_Updater() );\r
-\r
-#ifdef WITH_SALOMEDS_OBSERVER\r
- //do not activate the automatic update of Qt tree through signal/slot\r
- ob->setAutoUpdate(false);\r
- //activate update of modified objects only\r
- ob->setUpdateModified(true);\r
-#endif\r
-\r
- connect( ob, SIGNAL( doubleClicked( SUIT_DataObject* ) ), this, SLOT( onDblClick( SUIT_DataObject* ) ) );\r
-\r
- QString\r
- ValueCol = QObject::tr( "VALUE_COLUMN" ),\r
- IORCol = QObject::tr( "IOR_COLUMN" ),\r
- RefCol = QObject::tr( "REFENTRY_COLUMN" ),\r
- EntryCol = QObject::tr( "ENTRY_COLUMN" );\r
-\r
- SUIT_AbstractModel* treeModel = dynamic_cast<SUIT_AbstractModel*>( ob->model() );\r
- treeModel->registerColumn( 0, EntryCol, SalomeApp_DataObject::EntryId );\r
- treeModel->registerColumn( 0, ValueCol, SalomeApp_DataObject::ValueId );\r
- treeModel->registerColumn( 0, IORCol, SalomeApp_DataObject::IORId );\r
- treeModel->registerColumn( 0, RefCol, SalomeApp_DataObject::RefEntryId );\r
- treeModel->setAppropriate( EntryCol, Qtx::Toggled );\r
- treeModel->setAppropriate( ValueCol, Qtx::Toggled );\r
- treeModel->setAppropriate( IORCol, Qtx::Toggled );\r
- treeModel->setAppropriate( RefCol, Qtx::Toggled );\r
-\r
- bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );\r
- bool autoSizeFirst = resMgr->booleanValue( "ObjectBrowser", "auto_size_first", true );\r
- bool resizeOnExpandItem = resMgr->booleanValue( "ObjectBrowser", "resize_on_expand_item", true );\r
-\r
- ob->setAutoSizeFirstColumn(autoSizeFirst);\r
- ob->setAutoSizeColumns(autoSize);\r
- ob->setResizeOnExpandItem(resizeOnExpandItem);\r
- ob->setProperty( "shortcut", QKeySequence( "Alt+Shift+O" ) );\r
-\r
- // temporary commented\r
- /*\r
- for ( int i = SalomeApp_DataObject::ValueIdx; i <= SalomeApp_DataObject::RefEntryIdx; i++ )\r
- {\r
- ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );\r
- ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",\r
- QString().sprintf( "visibility_column_%d", i ), true ) );\r
- }\r
- */\r
-\r
- // temporary commented\r
- /*\r
- ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );\r
- ob->listView()->setColumnWidthMode( 0, autoSizeFirst ? QListView::Maximum : QListView::Manual );\r
- ob->resize( desktop()->width()/3, ob->height() );\r
- */\r
- }\r
- }\r
- else if ( flag == WT_PyConsole )\r
- {\r
- PyConsole_Console* pyCons = new PyConsole_Console( desktop(), new SalomeApp_PyInterp() );\r
- pyCons->setWindowTitle( tr( "PYTHON_CONSOLE" ) );\r
- pyCons->setFont(resourceMgr()->fontValue( "PyConsole", "font" ));\r
- pyCons->setIsShowBanner(resourceMgr()->booleanValue( "PyConsole", "show_banner", true ));\r
- pyCons->setProperty( "shortcut", QKeySequence( "Alt+Shift+P" ) );\r
- wid = pyCons;\r
- //pyCons->resize( pyCons->width(), desktop()->height()/4 );\r
- pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );\r
- }\r
- else if ( flag == WT_NoteBook )\r
- {\r
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if ( appStudy ) {\r
- _PTR(Study) aStudy = appStudy->studyDS();\r
- myNoteBook = new SalomeApp_NoteBook( desktop(), aStudy );\r
- //to receive signal in NoteBook that it's variable was modified\r
- connect( this, SIGNAL(notebookVarUpdated(QString)), \r
- myNoteBook, SLOT(onVarUpdate(QString)) );\r
- }\r
- wid = myNoteBook;\r
- }\r
- return wid;\r
-}\r
-\r
-/*!Create preferences.*/\r
-void SalomeApp_Application::createPreferences( LightApp_Preferences* pref )\r
-{\r
- LightApp_Application::createPreferences(pref);\r
-\r
- if ( !pref )\r
- return;\r
-\r
- int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );\r
- int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );\r
- int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );\r
- for ( int i = SalomeApp_DataObject::EntryId; i < SalomeApp_DataObject::LastId; i++ )\r
- {\r
- pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i-SalomeApp_DataObject::EntryId ).toLatin1() ), defCols,\r
- LightApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_id_%d", i-1 ) );\r
- }\r
- pref->setItemProperty( "orientation", Qt::Vertical, defCols );\r
-\r
- // adding preference to LightApp_Application handled preferences.. a bit of hacking with resources..\r
- int genTab = pref->addPreference( LightApp_Application::tr( "PREF_TAB_GENERAL" ), salomeCat );\r
- int studyGroup = pref->addPreference( LightApp_Application::tr( "PREF_GROUP_STUDY" ), genTab );\r
- pref->addPreference( tr( "PREF_STORE_VISUAL_STATE" ), studyGroup, LightApp_Preferences::Bool, "Study", "store_visual_state" );\r
- pref->addPreference( "", studyGroup, LightApp_Preferences::Space );\r
- pref->addPreference( tr( "PREF_PYDUMP_PUBLISH" ), studyGroup, LightApp_Preferences::Bool, "Study", "pydump_publish" );\r
- pref->addPreference( tr( "PREF_PYDUMP_MULTI_FILE" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file_dump" );\r
- pref->addPreference( tr( "PREF_PYDUMP_SAVE_GUI" ), studyGroup, LightApp_Preferences::Bool, "Study", "pydump_save_gui" );\r
- pref->addPreference( "", studyGroup, LightApp_Preferences::Space );\r
- pref->addPreference( "", studyGroup, LightApp_Preferences::Space );\r
-}\r
-\r
-/*!Update desktop title.*/\r
-void SalomeApp_Application::updateDesktopTitle() {\r
- QString aTitle = applicationName();\r
- QString aVer = applicationVersion();\r
- if ( !aVer.isEmpty() )\r
- aTitle += QString( " " ) + aVer;\r
-\r
- if ( activeStudy() )\r
- {\r
- QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );\r
- if ( !sName.isEmpty() ) {\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
- if ( study ) {\r
- _PTR(Study) stdDS = study->studyDS();\r
- if(stdDS) {\r
- if ( stdDS->GetProperties()->IsLocked() ) {\r
- aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );\r
- } else {\r
- aTitle += QString( " - [%1]" ).arg( sName );\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- desktop()->setWindowTitle( aTitle );\r
-}\r
-\r
-int SalomeApp_Application::closeChoice( const QString& docName )\r
-{\r
- int answer = SUIT_MessageBox::question( desktop(), tr( "APPCLOSE_CAPTION" ), tr( "APPCLOSE_DESCRIPTION" ).arg( docName ),\r
- tr ("APPCLOSE_SAVE"), tr ("APPCLOSE_CLOSE"),\r
- tr ("APPCLOSE_UNLOAD"), tr ("APPCLOSE_CANCEL"), 0 );\r
-\r
- int res = CloseCancel;\r
- if ( answer == 0 )\r
- res = CloseSave;\r
- else if ( answer == 1 )\r
- res = CloseDiscard;\r
- else if ( answer == 2 )\r
- res = CloseUnload;\r
-\r
- return res;\r
-}\r
-\r
-bool SalomeApp_Application::closeAction( const int choice, bool& closePermanently )\r
-{\r
- bool res = true;\r
- switch( choice )\r
- {\r
- case CloseSave:\r
- if ( activeStudy()->isSaved() )\r
- onSaveDoc();\r
- else if ( !onSaveAsDoc() )\r
- res = false;\r
- break;\r
- case CloseDiscard:\r
- break;\r
- case CloseUnload:\r
- closePermanently = false;\r
- break;\r
- case CloseCancel:\r
- default:\r
- res = false;\r
- }\r
-\r
- return res;\r
-}\r
-\r
-int SalomeApp_Application::openChoice( const QString& aName )\r
-{\r
- int choice = LightApp_Application::openChoice( aName );\r
-\r
- if ( QFileInfo( aName ).exists() ) {\r
- if ( choice == OpenNew ) { // The document isn't already open.\r
- bool exist = false;\r
- std::vector<std::string> lst = studyMgr()->GetOpenStudies();\r
- for ( uint i = 0; i < lst.size() && !exist; i++ ) {\r
- if ( aName == QString( lst[i].c_str() ) )\r
- exist = true;\r
- }\r
- // The document already exists in the study manager.\r
- // Do you want to reload it?\r
- if ( exist ) {\r
- int answer = SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYEXIST" ).arg( aName ),\r
- SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No );\r
- if ( answer == SUIT_MessageBox::Yes )\r
- choice = OpenRefresh;\r
- else\r
- choice = OpenCancel;\r
- }\r
- }\r
- } else { // file is not exist on disk\r
- SUIT_MessageBox::warning( desktop(),\r
- QObject::tr("WRN_WARNING"),\r
- QObject::tr("WRN_FILE_NOT_EXIST").arg(aName.toLatin1().data()));\r
- return false;\r
- }\r
-\r
- return choice;\r
-}\r
-\r
-bool SalomeApp_Application::openAction( const int aChoice, const QString& aName )\r
-{\r
- bool res = false;\r
- int choice = aChoice;\r
- switch ( choice )\r
- {\r
- case OpenRefresh:\r
- {\r
- _PTR(Study) aStudy = studyMgr()->GetStudyByName( aName.toStdString() );\r
- if ( aStudy )\r
- {\r
- studyMgr()->Close( aStudy );\r
- choice = OpenNew;\r
- }\r
- }\r
- default:\r
- res = LightApp_Application::openAction( choice, aName );\r
- break;\r
- }\r
-\r
- return res;\r
-}\r
-\r
-/*!\r
- \brief Get map of the operations which can be performed\r
- on the module activation.\r
-\r
- The method should return the map of the kind \c {<id>:<name>}\r
- where \c <id> is an integer identifier of the operation and\r
- \c <name> is a title for the button to be added to the\r
- dialog box. After user selects the required operation by the\r
- clicking the corresponding button in the dialog box, its identifier\r
- is passed to the moduleActionSelected() method to process\r
- the made choice.\r
-\r
- \return map of the operations\r
- \sa moduleActionSelected()\r
-*/\r
-QMap<int, QString> SalomeApp_Application::activateModuleActions() const\r
-{\r
- QMap<int, QString> opmap = LightApp_Application::activateModuleActions();\r
- opmap.insert( LoadStudyId, tr( "ACTIVATE_MODULE_OP_LOAD" ) );\r
- opmap.insert( NewAndScriptId, tr( "ACTIVATE_MODULE_OP_SCRIPT" ) );\r
- return opmap;\r
-}\r
-\r
-/*!\r
- \brief Called when the used selectes required operation chosen\r
- from "Activate module" dialog box.\r
-\r
- Performs the required operation according to the user choice.\r
-\r
- \param id operation identifier\r
- \sa activateModuleActions()\r
-*/\r
-void SalomeApp_Application::moduleActionSelected( const int id )\r
-{\r
- switch ( id ) {\r
- case LoadStudyId:\r
- onLoadDoc();\r
- break;\r
- case NewAndScriptId:\r
- onNewWithScript();\r
- break;\r
- default:\r
- LightApp_Application::moduleActionSelected( id );\r
- break;\r
- }\r
-}\r
-\r
-/*!Gets CORBA::ORB_var*/\r
-CORBA::ORB_var SalomeApp_Application::orb()\r
-{\r
- ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();\r
- static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );\r
- return _orb;\r
-}\r
-\r
-/*!Create and return SALOMEDS_StudyManager.*/\r
-SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()\r
-{\r
- static _PTR(StudyManager) _sm;\r
- if(!_sm) _sm = ClientFactory::StudyManager();\r
- return _sm.get();\r
-}\r
-\r
-/*!Create and return SALOME_NamingService.*/\r
-SALOME_NamingService* SalomeApp_Application::namingService()\r
-{\r
- static SALOME_NamingService _ns(orb());\r
- return &_ns;\r
-}\r
-\r
-/*!Create and return SALOME_LifeCycleCORBA.*/\r
-SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()\r
-{\r
- static SALOME_LifeCycleCORBA _lcc( namingService() );\r
- return &_lcc;\r
-}\r
-\r
-/*!Private SLOT. On preferences.*/\r
-void SalomeApp_Application::onProperties()\r
-{\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if( !study )\r
- return;\r
-\r
- _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();\r
- SB->NewCommand();\r
-\r
- SalomeApp_StudyPropertiesDlg aDlg( desktop() );\r
- int res = aDlg.exec();\r
- if( res==QDialog::Accepted && aDlg.isChanged() )\r
- SB->CommitCommand();\r
- else\r
- SB->AbortCommand();\r
-\r
- //study->updateCaptions();\r
- updateDesktopTitle();\r
- updateActions();\r
-}\r
-\r
-/*!Insert items in popup, which necessary for current application*/\r
-void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title )\r
-{\r
- LightApp_SelectionMgr* mgr = selectionMgr();\r
- bool cacheIsOn = mgr->isSelectionCacheEnabled();\r
- mgr->setSelectionCacheEnabled( true );\r
-\r
- LightApp_Application::contextMenuPopup( type, thePopup, title );\r
-\r
- // temporary commented\r
- /*OB_Browser* ob = objectBrowser();\r
- if ( !ob || type != ob->popupClientType() )\r
- return;*/\r
-\r
- // Get selected objects\r
- SALOME_ListIO aList;\r
- mgr->selectedObjects( aList, QString(), false );\r
-\r
- // add GUI state commands: restore, rename\r
- if ( aList.Extent() == 1 && aList.First()->hasEntry() &&\r
- QString( aList.First()->getEntry() ).startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) ) {\r
- thePopup->addSeparator();\r
- thePopup->addAction( tr( "MEN_RESTORE_VS" ), this, SLOT( onRestoreGUIState() ) );\r
- thePopup->addAction( tr( "MEN_RENAME_VS" ), objectBrowser(),\r
- SLOT( onStartEditing() ), objectBrowser()->shortcutKey(SUIT_DataBrowser::RenameShortcut) );\r
- thePopup->addAction( tr( "MEN_DELETE_VS" ), this, SLOT( onDeleteGUIState() ) );\r
- }\r
-\r
- // "Delete reference" item should appear only for invalid references\r
-\r
- // isInvalidRefs will be true, if at least one of selected objects is invalid reference\r
- bool isInvalidRefs = false;\r
- SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
- _PTR(Study) aStudyDS = aStudy->studyDS();\r
- _PTR(SObject) anObj;\r
-\r
- for( SALOME_ListIteratorOfListIO it( aList ); it.More() && !isInvalidRefs; it.Next() )\r
- if( it.Value()->hasEntry() )\r
- {\r
- _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ), aRefObj = aSObject;\r
- while( aRefObj && aRefObj->ReferencedObject( anObj ) )\r
- aRefObj = anObj;\r
-\r
- if( aRefObj && aRefObj!=aSObject && QString( aRefObj->GetName().c_str() ).isEmpty() )\r
- isInvalidRefs = true;\r
- }\r
-\r
- // Add "Delete reference" item to popup\r
- if ( isInvalidRefs )\r
- {\r
- thePopup->addSeparator();\r
- thePopup->addAction( tr( "MEN_DELETE_INVALID_REFERENCE" ), this, SLOT( onDeleteInvalidReferences() ) );\r
- return;\r
- }\r
-\r
- // "Activate module" item should appear only if it's necessary\r
- if ( aList.Extent() == 1 ) {\r
- aList.Clear();\r
- mgr->selectedObjects( aList );\r
-\r
- Handle(SALOME_InteractiveObject) aIObj = aList.First();\r
-\r
- // add extra popup menu (defined in XML)\r
- if ( myExtActions.size() > 0 ) {\r
- // Use only first selected object\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if ( study ) {\r
- _PTR(Study) stdDS = study->studyDS();\r
- if ( stdDS ) {\r
- _PTR(SObject) aSO = stdDS->FindObjectID( aIObj->getEntry() );\r
- if ( aSO ) {\r
- _PTR( GenericAttribute ) anAttr;\r
- std::string auid = "AttributeUserID";\r
- auid += Kernel_Utils::GetGUID(Kernel_Utils::ObjectdID);\r
- if ( aSO->FindAttribute( anAttr, auid ) ) {\r
- _PTR(AttributeUserID) aAttrID = anAttr;\r
- QString aId = aAttrID->Value().c_str();\r
- if ( myExtActions.contains( aId ) ) {\r
- thePopup->addAction(myExtActions[aId]);\r
- }\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- // check if item is a "GUI state" item (also a first level object)\r
- QString entry( aIObj->getEntry() );\r
- if ( !entry.startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) ) {\r
- QString aModuleName( aIObj->getComponentDataType() );\r
- QString aModuleTitle = moduleTitle( aModuleName );\r
- CAM_Module* currentModule = activeModule();\r
- if ( ( !currentModule || currentModule->moduleName() != aModuleTitle ) && !aModuleTitle.isEmpty() )\r
- thePopup->addAction( tr( "MEN_OPENWITH" ).arg( aModuleTitle ), this, SLOT( onOpenWith() ) );\r
- }\r
- }\r
-\r
- mgr->setSelectionCacheEnabled( cacheIsOn );\r
-}\r
-\r
-/*!Update obect browser:\r
- 1.if 'updateModels' true, update existing data models;\r
- 2. update "non-existing" (not loaded yet) data models;\r
- 3. update object browser if it exists */\r
-void SalomeApp_Application::updateObjectBrowser( const bool updateModels )\r
-{\r
- // update "non-existing" (not loaded yet) data models\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());\r
- if ( study )\r
- {\r
- _PTR(Study) stdDS = study->studyDS();\r
- if( stdDS )\r
- {\r
- for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() )\r
- {\r
- _PTR(SComponent) aComponent ( it->Value() );\r
-\r
-#ifndef WITH_SALOMEDS_OBSERVER\r
- // with GUI observers this check is not needed anymore\r
- if ( aComponent->ComponentDataType() == study->getVisualComponentName().toLatin1().constData() )\r
- continue; // skip the magic "Interface Applicative" component\r
-#endif\r
- if ( !objectBrowser() )\r
- getWindow( WT_ObjectBrowser );\r
- const bool isAutoUpdate = objectBrowser()->autoUpdate();\r
- objectBrowser()->setAutoUpdate( false );\r
- SalomeApp_DataModel::synchronize( aComponent, study );\r
- objectBrowser()->setAutoUpdate( isAutoUpdate );\r
- }\r
- }\r
- }\r
-\r
- // create data objects that correspond to GUI state save points\r
- if ( study ) updateSavePointDataObjects( study );\r
-\r
- // update existing data models (already loaded SComponents)\r
- LightApp_Application::updateObjectBrowser( updateModels );\r
-}\r
-\r
-/*!Display Catalog Genenerator dialog */\r
-void SalomeApp_Application::onCatalogGen()\r
-{\r
- ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );\r
- aDlg.exec();\r
-}\r
-\r
-/*!Display Registry Display dialog */\r
-void SalomeApp_Application::onRegDisplay()\r
-{\r
- CORBA::ORB_var anOrb = orb();\r
- ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop() );\r
- regWnd->show();\r
- regWnd->raise();\r
- regWnd->activateWindow();\r
-}\r
-\r
-/*!find original object by double click on item */\r
-void SalomeApp_Application::onDblClick( SUIT_DataObject* theObj )\r
-{\r
- // Issue 21379: References are supported at LightApp_DataObject level\r
- LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( theObj );\r
-\r
- if( obj && obj->isReference() )\r
- {\r
- QString entry = obj->refEntry();\r
-\r
- SUIT_DataOwnerPtrList aList;\r
- aList.append( new LightApp_DataOwner( entry ) );\r
- selectionMgr()->setSelected( aList, false );\r
- \r
- SUIT_DataBrowser* ob = objectBrowser();\r
-\r
- QModelIndexList aSelectedIndexes = ob->selectedIndexes();\r
- if ( !aSelectedIndexes.isEmpty() )\r
- ob->treeView()->scrollTo( aSelectedIndexes.first() );\r
- }\r
-}\r
-\r
-/*!\r
- Creates new view manager\r
- \param type - type of view manager\r
-*/\r
-SUIT_ViewManager* SalomeApp_Application::newViewManager(const QString& type)\r
-{\r
- return createViewManager(type);\r
-}\r
-\r
-\r
-/*!Global utility funciton, returns selected GUI Save point object's ID */\r
-int getSelectedSavePoint( const LightApp_SelectionMgr* selMgr )\r
-{\r
- SALOME_ListIO aList;\r
- selMgr->selectedObjects( aList );\r
- if( aList.Extent() > 0 ) {\r
- Handle(SALOME_InteractiveObject) aIObj = aList.First();\r
- QString entry( aIObj->getEntry() );\r
- QString startStr = QObject::tr( "SAVE_POINT_DEF_NAME" );\r
- if ( !entry.startsWith( startStr ) ) // it's a "GUI state" object\r
- return -1;\r
- bool ok; // conversion to integer is ok?\r
- int savePoint = entry.right( entry.length() - startStr.length() ).toInt( &ok );\r
- return ok ? savePoint : -1;\r
- }\r
- return -1;\r
-}\r
-\r
-/*!Called on Restore GUI State popup command*/\r
-void SalomeApp_Application::onRestoreGUIState()\r
-{\r
- int savePoint = ::getSelectedSavePoint( selectionMgr() );\r
- if ( savePoint == -1 )\r
- return;\r
- SalomeApp_VisualState( this ).restoreState( savePoint );\r
-}\r
-\r
-/*!Called on Delete GUI State popup command*/\r
-void SalomeApp_Application::onDeleteGUIState()\r
-{\r
- int savePoint = ::getSelectedSavePoint( selectionMgr() );\r
- if ( savePoint == -1 )\r
- return;\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if ( !study )\r
- return;\r
-\r
- study->removeSavePoint( savePoint );\r
- updateSavePointDataObjects( study );\r
-}\r
-\r
-/*!Called on New study operation*/\r
-void SalomeApp_Application::onStudyCreated( SUIT_Study* study )\r
-{\r
- LightApp_Application::onStudyCreated( study );\r
-\r
- desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), \r
- windowDock( getWindow( WT_ObjectBrowser ) ) );\r
-\r
- loadDockWindowsState();\r
-\r
- connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),\r
- this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection );\r
-\r
-\r
- objectBrowserColumnsVisibility();\r
-}\r
-\r
-/*!Called on Save study operation*/\r
-void SalomeApp_Application::onStudySaved( SUIT_Study* study )\r
-{\r
- LightApp_Application::onStudySaved( study );\r
-\r
- // temporary commented\r
- /*if ( objectBrowser() ) {\r
- updateSavePointDataObjects( dynamic_cast<SalomeApp_Study*>( study ) );\r
- objectBrowser()->updateTree( study->root() );\r
- }*/\r
-}\r
-\r
-/*!Called on Open study operation*/\r
-void SalomeApp_Application::onStudyOpened( SUIT_Study* study )\r
-{\r
- LightApp_Application::onStudyOpened( study );\r
-\r
- desktop()->tabifyDockWidget( windowDock( getWindow( WT_NoteBook ) ), \r
- windowDock( getWindow( WT_ObjectBrowser ) ) );\r
-\r
- loadDockWindowsState();\r
-\r
- connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ),\r
- this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection );\r
-\r
- objectBrowserColumnsVisibility();\r
-\r
- // temporary commented\r
- /*if ( objectBrowser() ) {\r
- updateSavePointDataObjects( dynamic_cast<SalomeApp_Study*>( study ) );\r
- objectBrowser()->updateTree( study->root() );\r
- }*/\r
-}\r
-\r
-/*! updateSavePointDataObjects: syncronize data objects that correspond to save points (gui states)*/\r
-void SalomeApp_Application::updateSavePointDataObjects( SalomeApp_Study* study )\r
-{\r
-\r
- SUIT_DataBrowser* ob = objectBrowser();\r
- LightApp_SelectionMgr* selMgr = selectionMgr();\r
-\r
- if ( !study || !ob || !selMgr ) \r
- return;\r
-\r
- // find GUI states root object\r
- SUIT_DataObject* guiRootObj = 0;\r
- DataObjectList ch;\r
- study->root()->children( ch );\r
- DataObjectList::const_iterator it = ch.begin(), last = ch.end();\r
- for ( ; it != last ; ++it ) {\r
- if ( dynamic_cast<SalomeApp_SavePointRootObject*>( *it ) ) {\r
- guiRootObj = *it;\r
- break;\r
- }\r
- }\r
- std::vector<int> savePoints = study->getSavePoints();\r
- // case 1: no more save points but they existed in study's tree\r
- if ( savePoints.empty() && guiRootObj ) {\r
- //rnv : to fix bug "IPAL22450 TC6.3.0: sigsegv loop deleting the GUI state"\r
- // : set auto update to true for removing SalomeApp_SavePointRootObject from the SUIT_TreeModel\r
- const bool isAutoUpdate = ob->autoUpdate();\r
- selMgr->clearSelected();\r
- ob->setAutoUpdate(true);\r
- DataObjectList ch = guiRootObj->children();\r
- for( int i = 0; i < ch.size(); i++ ) \r
- delete ch[i];\r
- delete guiRootObj;\r
- ob->setAutoUpdate(isAutoUpdate);\r
- return;\r
- }\r
- // case 2: no more save points but root does not exist either\r
- if ( savePoints.empty() && !guiRootObj )\r
- return;\r
- // case 3: save points but no root for them - create it\r
- if ( !savePoints.empty() && !guiRootObj )\r
- guiRootObj = new SalomeApp_SavePointRootObject( study->root() );\r
- // case 4: everything already exists.. here may be a problem: we want "GUI states" root object\r
- // to be always the last one in the tree. Here we check - if it is not the last one - remove and\r
- // re-create it.\r
- if ( guiRootObj->nextBrother() ) {\r
- study->root()->removeChild(guiRootObj);\r
- study->root()->appendChild(guiRootObj);\r
- //study->root()->dump();\r
- }\r
-\r
- // store data objects in a map id-to-DataObject\r
- QMap<int,SalomeApp_SavePointObject*> mapDO;\r
- ch.clear();\r
- guiRootObj->children( ch );\r
- for( it = ch.begin(), last = ch.end(); it != last ; ++it ) {\r
- SalomeApp_SavePointObject* dobj = dynamic_cast<SalomeApp_SavePointObject*>( *it );\r
- if ( dobj )\r
- mapDO[dobj->getId()] = dobj;\r
- }\r
-\r
- // iterate new save points. if DataObject with such ID not found in map - create DataObject\r
- // if in the map - remove it from map.\r
- for ( int i = 0; i < savePoints.size(); i++ )\r
- if ( !mapDO.contains( savePoints[i] ) )\r
- new SalomeApp_SavePointObject( guiRootObj, savePoints[i], study );\r
- else\r
- mapDO.remove( savePoints[i] );\r
-\r
- // delete DataObjects that are still in the map -- their IDs were not found in data model\r
- if( mapDO.size() > 0) {\r
- //rnv : to fix bug "IPAL22450 TC6.3.0: sigsegv loop deleting the GUI state"\r
- // : set auto update to true for removing SalomeApp_SavePointObject from the SUIT_TreeModel\r
- selMgr->clearSelected();\r
- const bool isAutoUpdate = ob->autoUpdate();\r
- ob->setAutoUpdate(true);\r
- for ( QMap<int,SalomeApp_SavePointObject*>::Iterator it = mapDO.begin(); it != mapDO.end(); ++it )\r
- delete it.value();\r
- ob->setAutoUpdate(isAutoUpdate);\r
- }\r
-}\r
-\r
-/*! Check data object */\r
-bool SalomeApp_Application::checkDataObject(LightApp_DataObject* theObj)\r
-{\r
- if (theObj)\r
- return true;\r
-\r
- return false;\r
-}\r
-\r
-/*!\r
- Opens other study into active Study. If Study is empty - creates it.\r
- \param theName - name of study\r
-*/\r
-bool SalomeApp_Application::useStudy( const QString& theName )\r
-{\r
- createEmptyStudy();\r
- SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- bool res = false;\r
- if (aStudy)\r
- res = aStudy->loadDocument( theName );\r
- updateDesktopTitle();\r
- updateCommandsStatus();\r
- return res;\r
-}\r
-\r
-/*! Show/hide object browser colums according to preferences */\r
-void SalomeApp_Application::objectBrowserColumnsVisibility()\r
-{\r
- if ( objectBrowser() )\r
- for ( int i = SalomeApp_DataObject::EntryId; i < SalomeApp_DataObject::LastId; i++ )\r
- {\r
- bool shown = resourceMgr()->booleanValue( "ObjectBrowser", QString( "visibility_column_id_%1" ).arg( i-1 ), true );\r
- objectBrowser()->treeView()->setColumnHidden( i, !shown );\r
- }\r
-}\r
-\r
-/*! Set SalomeApp_NoteBook pointer */\r
-void SalomeApp_Application::setNoteBook(SalomeApp_NoteBook* theNoteBook){\r
- myNoteBook = theNoteBook;\r
-}\r
-\r
-/*! Return SalomeApp_NoteBook pointer */\r
-SalomeApp_NoteBook* SalomeApp_Application::getNoteBook() const\r
-{\r
- return myNoteBook;\r
-}\r
-\r
-/*!\r
- * Define extra actions defined in module definition XML file.\r
- * Additional popup items sections can be defined by parameter "popupitems".\r
- * Supported attributes:\r
- * title - title of menu item,\r
- * attributelocalid - AttributeLocalId defined for selected data item where menu command has to be applied,\r
- * method - method which has to be called when menu item is selected\r
- * Example:\r
- * <section name="MODULENAME">\r
- * <parameter name="popupitems" value="menuitem1:menuitem2:..."/>\r
- * </section>\r
- * <section name="importmed">\r
- * <parameter name="title" value="My menu"/>\r
- * <parameter name="objectid" value="VISU.Result"/>\r
- * <parameter name="method" value="nameOfModuleMethod"/>\r
- * </section>\r
- */\r
-void SalomeApp_Application::createExtraActions()\r
-{\r
- myExtActions.clear();\r
- SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();\r
-\r
- QStringList aModules;\r
- modules(aModules, false);\r
- foreach(QString aModile, aModules) {\r
- QString aModName = moduleName(aModile);\r
- QString aSectionStr = resMgr->stringValue(aModName, "popupitems", QString());\r
- if (!aSectionStr.isNull()) {\r
- QStringList aSections = aSectionStr.split(':');\r
- foreach(QString aSection, aSections) {\r
- QString aTitle = resMgr->stringValue(aSection, "title", QString());\r
- QString aId = resMgr->stringValue(aSection, "objectid", QString());\r
- QString aSlot = resMgr->stringValue(aSection, "method", QString());\r
- if (aTitle.isEmpty() || aSlot.isEmpty() || aId.isEmpty())\r
- continue;\r
-\r
- QString aModuleName = resMgr->stringValue(aSection, "module", QString());\r
- if (aModuleName.isNull())\r
- aModuleName = aModName;\r
-\r
- QAction* aAction = new QAction(aTitle, this);\r
- QStringList aData;\r
- aData<<aModuleName<<aSlot;\r
- aAction->setData(aData);\r
- connect(aAction, SIGNAL(triggered()), this, SLOT(onExtAction()));\r
- myExtActions[aId] = aAction;\r
- }\r
- }\r
- }\r
-}\r
-\r
-/*!\r
- * Called when extra action is selected\r
- */\r
-void SalomeApp_Application::onExtAction()\r
-{\r
- QAction* aAction = ::qobject_cast<QAction*>(sender());\r
- if (!aAction)\r
- return;\r
-\r
- QVariant aData = aAction->data();\r
- QStringList aDataList = aData.value<QStringList>();\r
- if (aDataList.size() != 2)\r
- return;\r
-\r
- LightApp_SelectionMgr* aSelectionMgr = selectionMgr();\r
- SALOME_ListIO aListIO;\r
- aSelectionMgr->selectedObjects(aListIO);\r
- const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();\r
- if (aListIO.Extent() < 1)\r
- return;\r
- if (!anIO->hasEntry())\r
- return;\r
-\r
- QString aEntry(anIO->getEntry());\r
-\r
- QApplication::setOverrideCursor( Qt::WaitCursor );\r
- QString aModuleTitle = moduleTitle(aDataList[0]);\r
- activateModule(aModuleTitle);\r
- QApplication::restoreOverrideCursor();\r
-\r
- QCoreApplication::processEvents();\r
-\r
- CAM_Module* aModule = activeModule();\r
- if (!aModule)\r
- return;\r
-\r
- if (!QMetaObject::invokeMethod(aModule, qPrintable(aDataList[1]), Q_ARG(QString, aEntry)))\r
- printf("Error: Can't Invoke method %s\n", qPrintable(aDataList[1]));\r
-}\r
-\r
-/*!\r
- * Called when window activated\r
- */\r
-void SalomeApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow )\r
-{\r
- SUIT_DataBrowser* anOB = objectBrowser();\r
- if( !anOB )\r
- return;\r
- SUIT_DataObject* rootObj = anOB->root();\r
- if( !rootObj )\r
- return;\r
-\r
- DataObjectList listObj = rootObj->children( true );\r
-\r
- SUIT_ViewModel* vmod = 0;\r
- if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() )\r
- vmod = vman->getViewModel();\r
- updateVisibilityState( listObj, vmod );\r
-}\r
-\r
-/*!\r
- Update visibility state of given objects\r
- */\r
-void SalomeApp_Application::updateVisibilityState( DataObjectList& theList,\r
- SUIT_ViewModel* theViewModel )\r
-{\r
- LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());\r
-\r
- if(!theViewModel)\r
- return;\r
-\r
- SALOME_View* aView = dynamic_cast<SALOME_View*>( theViewModel );\r
-\r
- if (theList.isEmpty() || !aView || !aStudy)\r
- return;\r
-\r
- for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) {\r
- LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(*itr);\r
-\r
- if (!obj || aStudy->isComponent(obj->entry()))\r
- continue;\r
-\r
- LightApp_Module* anObjModule = dynamic_cast<LightApp_Module*>(obj->module());\r
- Qtx::VisibilityState anObjState = Qtx::UnpresentableState;\r
-\r
- if(anObjModule) {\r
- LightApp_Displayer* aDisplayer = anObjModule->displayer();\r
- if(aDisplayer) {\r
- if( aDisplayer->canBeDisplayed(obj->entry(), theViewModel->getType()) ) {\r
- if(aDisplayer->IsDisplayed(obj->entry(),aView))\r
- anObjState = Qtx::ShownState;\r
- else\r
- anObjState = Qtx::HiddenState;\r
- }\r
- }\r
- aStudy->setVisibilityState( obj->entry(), anObjState );\r
- }\r
- }\r
-}\r
-\r
-/*!\r
- Called then view manager removed\r
-*/\r
-void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* )\r
-{\r
- ViewManagerList lst;\r
- viewManagers(lst);\r
- if( lst.count() == 1) { // in case if closed last view window\r
- LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());\r
- if(aStudy)\r
- aStudy->setVisibilityStateForAll(Qtx::UnpresentableState);\r
- }\r
-}\r
-\r
-/*!\r
- Checks that an object can be renamed.\r
- \param entry entry of the object\r
- \brief Return \c true if object can be renamed\r
-*/\r
-bool SalomeApp_Application::renameAllowed( const QString& entry) const\r
-{\r
- return entry.startsWith( tr( "SAVE_POINT_DEF_NAME") );\r
-}\r
-\r
-/*!\r
- Rename object by entry.\r
- \param entry entry of the object\r
- \param name new name of the object\r
- \brief Return \c true if rename operation finished successfully, \c false otherwise.\r
-*/\r
-bool SalomeApp_Application::renameObject( const QString& entry, const QString& name )\r
-{\r
- SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
-\r
- int savePoint = ::getSelectedSavePoint( selectionMgr() );\r
-\r
- if(!aStudy || savePoint == -1)\r
- return false;\r
-\r
- if ( !name.isNull() && !name.isEmpty() ) {\r
- aStudy->setNameOfSavePoint( savePoint, name );\r
- updateSavePointDataObjects( aStudy );\r
-\r
- //Mark study as modified\r
- aStudy->Modified();\r
- return true;\r
- }\r
- return false;\r
-}\r
-\r
-/*!\r
- \return default windows( Object Browser, Python Console )\r
- Adds to map \a aMap.\r
- */\r
-void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const\r
-{\r
- LightApp_Application::defaultWindows(aMap);\r
- if(!aMap.contains(WT_NoteBook)) { \r
- if(!myNoteBook) {\r
- aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea );\r
- }\r
- }\r
-}\r
-\r
-/*!\r
- Gets current windows.\r
- \param winMap - output current windows map.\r
-*/\r
-void SalomeApp_Application::currentWindows(QMap<int, int>& aMap) const {\r
- LightApp_Application::currentWindows(aMap);\r
- if(!aMap.contains(WT_NoteBook) && myNoteBook)\r
- aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea );\r
-}\r
-\r
-//============================================================================\r
-/*! Function : onUpdateStudy\r
- * Purpose : Slot to update the study.\r
- */\r
-//============================================================================\r
-void SalomeApp_Application::onUpdateStudy()\r
-{\r
- QApplication::setOverrideCursor( Qt::WaitCursor );\r
-\r
- if( !updateStudy() )\r
- SUIT_MessageBox::warning( desktop(), tr( "ERROR" ), tr( "ERR_UPDATE_STUDY_FAILED" ) );\r
- \r
- QApplication::restoreOverrideCursor();\r
-}\r
-\r
-//============================================================================\r
-/*! Function : updateStudy\r
- * Purpose : Update study by dumping the study to Python script and loading it.\r
- * It is used to apply variable modifications done in NoteBook to created objects.\r
- */\r
-//============================================================================\r
-bool SalomeApp_Application::updateStudy()\r
-{\r
- SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );\r
- if( !study )\r
- return false;\r
-\r
- myNoteBook->setIsDumpedStudySaved( study->isSaved() );\r
- myNoteBook->setDumpedStudyName( study->studyName() );\r
-\r
- _PTR(Study) studyDS = study->studyDS();\r
-\r
- // get unique temporary directory name\r
- QString aTmpDir = QString::fromStdString( SALOMEDS_Tool::GetTmpDir() );\r
- if( aTmpDir.isEmpty() )\r
- return false;\r
-\r
- if( aTmpDir.right( 1 ).compare( QDir::separator() ) == 0 )\r
- aTmpDir.remove( aTmpDir.length() - 1, 1 );\r
-\r
- // dump study to the temporary directory\r
- QString aScriptName( "notebook" );\r
- bool toPublish = true;\r
- bool isMultiFile = false;\r
- bool toSaveGUI = true;\r
-\r
- int savePoint;\r
- _PTR(AttributeParameter) ap;\r
- _PTR(IParameters) ip = ClientFactory::getIParameters(ap);\r
- if(ip->isDumpPython(studyDS)) ip->setDumpPython(studyDS); //Unset DumpPython flag.\r
- if ( toSaveGUI ) { //SRN: Store a visual state of the study at the save point for DumpStudy method\r
- ip->setDumpPython(studyDS);\r
- savePoint = SalomeApp_VisualState( this ).storeState(); //SRN: create a temporary save point\r
- }\r
- bool ok = studyDS->DumpStudy( aTmpDir.toStdString(), aScriptName.toStdString(), toPublish, isMultiFile );\r
- if ( toSaveGUI )\r
- study->removeSavePoint(savePoint); //SRN: remove the created temporary save point.\r
-\r
- if( ok )\r
- myNoteBook->setDumpedStudyScript( aTmpDir + QDir::separator() + aScriptName + ".py" );\r
- else\r
- return false;\r
-\r
- QList<SUIT_Application*> aList = SUIT_Session::session()->applications();\r
- int anIndex = aList.indexOf( this );\r
-\r
- // Disconnect dialog from application desktop in case if:\r
- // 1) Application is not the first application in the session \r
- // 2) Application is the first application in session but not the only.\r
- bool changeDesktop = ((anIndex > 0) || (anIndex == 0 && aList.count() > 1));\r
-\r
- SalomeApp_Application* app;\r
- if( anIndex > 0 && anIndex < aList.count() )\r
- app = dynamic_cast<SalomeApp_Application*>( aList[ anIndex - 1 ] );\r
- else if(anIndex == 0 && aList.count() > 1)\r
- app = dynamic_cast<SalomeApp_Application*>( aList[ 1 ] );\r
-\r
- if( !app )\r
- return false;\r
-\r
- if( changeDesktop ) {\r
- // creation a new study and restoring will be done in another application\r
- connect( this, SIGNAL( dumpedStudyClosed( const QString&, const QString&, bool ) ),\r
- app, SLOT( onRestoreStudy( const QString&, const QString&, bool ) ), Qt::UniqueConnection );\r
- }\r
-\r
- QString aDumpScript = myNoteBook->getDumpedStudyScript();\r
- QString aStudyName = myNoteBook->getDumpedStudyName();\r
- bool isStudySaved = myNoteBook->isDumpedStudySaved();\r
- // clear a study (delete all objects)\r
- onCloseDoc( false );\r
-\r
- if( !changeDesktop ) {\r
- ok = onRestoreStudy( aDumpScript, \r
- aStudyName, \r
- isStudySaved );\r
- }\r
-\r
- return ok;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : onRestoreStudy\r
- * Purpose : Load the dumped study from Python script\r
- */\r
-//============================================================================\r
-bool SalomeApp_Application::onRestoreStudy( const QString& theDumpScript, \r
- const QString& theStudyName, \r
- bool theIsStudySaved )\r
-{\r
- bool ok = true;\r
-\r
- // create a new study\r
- onNewDoc();\r
-\r
- // get active application\r
- SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );\r
-\r
- // load study from the temporary directory\r
- QString command = QString( "execfile(r\"%1\")" ).arg( theDumpScript );\r
-\r
- PyConsole_Console* pyConsole = app->pythonConsole();\r
- if ( pyConsole )\r
- pyConsole->execAndWait( command );\r
-\r
- // remove temporary directory\r
- QFileInfo aScriptInfo = QFileInfo( theDumpScript );\r
- QString aStudyName = aScriptInfo.baseName();\r
- QDir aDir = aScriptInfo.absoluteDir();\r
- QStringList aFiles = aDir.entryList( QStringList( "*.py*" ) );\r
- for( QStringList::iterator it = aFiles.begin(), itEnd = aFiles.end(); it != itEnd; ++it )\r
- ok = aDir.remove( *it ) && ok;\r
- if( ok )\r
- ok = aDir.rmdir( aDir.absolutePath() );\r
-\r
- if( SalomeApp_Study* newStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) )\r
- {\r
- _PTR(Study) aStudyDS = newStudy->studyDS();\r
- app->getNoteBook()->Init( aStudyDS );\r
- if( theIsStudySaved ) {\r
- newStudy->markAsSavedIn( theStudyName );\r
- newStudy->Modified();\r
- }\r
- }\r
- else\r
- ok = false;\r
-\r
- return ok;\r
-}\r
-\r
-/*!\r
- Close the Application\r
-*/\r
-void SalomeApp_Application::closeApplication()\r
-{\r
- // emit signal to restore study from Python script\r
- emit dumpedStudyClosed( myNoteBook->getDumpedStudyScript(), \r
- myNoteBook->getDumpedStudyName(), \r
- myNoteBook->isDumpedStudySaved() );\r
-\r
- LightApp_Application::closeApplication();\r
-}\r
+// Copyright (C) 2007-2012 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.
+//
+// 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
+
+#ifdef WNT
+// 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 <Standard_math.hxx>
+#include <pymath.h>
+#endif
+
+#include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
+#include "SalomeApp_Application.h"
+#include "SalomeApp_Study.h"
+#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 "SalomeApp_ExitDlg.h"
+
+#include <LightApp_Application.h>
+#include <LightApp_Module.h>
+#include <LightApp_Preferences.h>
+#include <LightApp_SelectionMgr.h>
+#include <LightApp_NameDlg.h>
+#include <LightApp_DataOwner.h>
+#include <LightApp_Displayer.h>
+
+#include <CAM_Module.h>
+
+#include <SUIT_Tools.h>
+#include <SUIT_Session.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_DataBrowser.h>
+#include <SUIT_FileDlg.h>
+#include <SUIT_FileValidator.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_TreeModel.h>
+#include <SUIT_ViewWindow.h>
+#include <SUIT_ViewManager.h>
+#include <SUIT_ViewModel.h>
+
+#include <QtxTreeView.h>
+
+#include <SALOME_EventFilter.h>
+
+// temporary commented
+//#include <OB_ListItem.h>
+
+#include <PyConsole_Console.h>
+
+#include <Utils_ORB_INIT.hxx>
+#include <Utils_SINGLETON.hxx>
+#include <SALOME_LifeCycleCORBA.hxx>
+
+#include <QApplication>
+#include <QAction>
+#include <QRegExp>
+#include <QCheckBox>
+#include <QPushButton>
+#include <QLabel>
+#include <QListWidget>
+#include <QGridLayout>
+#include <QMenu>
+#include <QtDebug>
+
+#include <SALOMEDSClient_ClientFactory.hxx>
+#include <Basics_Utils.hxx>
+
+#include <SALOME_ListIO.hxx>
+#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_Prs.h>
+
+
+#include <ToolsGUI_CatalogGeneratorDlg.h>
+#include <ToolsGUI_RegWidget.h>
+
+#include <vector>
+
+#include <SALOMEDS_Tool.hxx>
+
+/*!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 );
+};
+
+void SalomeApp_Updater::update( SUIT_DataObject* theObj, OB_ListItem* theItem )
+{
+ if( !theObj || !theItem )
+ return;
+
+ SalomeApp_DataObject* SAObj = dynamic_cast<SalomeApp_DataObject*>( theObj );
+ if( !SAObj )
+ return;
+
+ _PTR(SObject) SObj = SAObj->object();
+ if( !SObj )
+ return;
+ _PTR( GenericAttribute ) anAttr;
+
+ // Selectable
+ if ( SObj->FindAttribute( anAttr, "AttributeSelectable" ) )
+ {
+ _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();
+}
+
+/*!Constructor.*/
+SalomeApp_Application::SalomeApp_Application()
+ : LightApp_Application()
+{
+ connect( desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
+ this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
+
+ setNoteBook(0);
+}
+
+/*!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()
+{
+ LightApp_Application::start();
+
+ SALOME_EventFilter::Init();
+
+ static bool isFirst = true;
+ if ( isFirst ) {
+ isFirst = false;
+
+ QString hdffile;
+ QStringList pyfiles;
+
+ 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=(.+)");
+ if ( rxp.indexIn( QString(qApp->argv()[i]) ) >= 0 && rxp.capturedTexts().count() > 1 ) {
+ QStringList files = rxp.capturedTexts()[1].split(",",QString::SkipEmptyParts);
+ pyfiles += files;
+ }
+ }
+ }
+
+ if ( !hdffile.isEmpty() ) // open hdf file given as parameter
+ onOpenDoc( hdffile );
+ else if ( pyfiles.count() > 0 ) // create new study
+ onNewDoc();
+
+ // import/execute python scripts
+ if ( pyfiles.count() > 0 && activeStudy() ) {
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ PyConsole_Console* pyConsole = pythonConsole();
+ if ( appStudy && pyConsole ) {
+ _PTR(Study) aStudy = appStudy->studyDS();
+ if ( !aStudy->GetProperties()->IsLocked() ) {
+ for (uint j = 0; j < pyfiles.count(); j++ ) {
+ QFileInfo fi ( pyfiles[j] );
+ QFileInfo fipy ( pyfiles[j] + ".py" );
+ QString command = QString( "execfile(r\"%1\")" );
+ if ( fi.isAbsolute() ) {
+ if ( fi.exists() )
+ pyConsole->exec( command.arg( fi.absoluteFilePath() ) );
+ else if ( fipy.exists() )
+ pyConsole->exec( command.arg( fipy.absoluteFilePath() ) );
+ else
+ qDebug() << "Can't execute file" << pyfiles[j];
+ }
+ else {
+ bool found = false;
+ QStringList dirs;
+ dirs << QDir::currentPath();
+ if ( ::getenv( "PYTHONPATH" ) )
+ dirs += QString( ::getenv( "PYTHONPATH" ) ).split( QRegExp( "[:|;]" ) );
+ foreach( QString dir, dirs ) {
+ qDebug() << "try" << QFileInfo( dir, pyfiles[j] ).absoluteFilePath();
+ qDebug() << "try" << QFileInfo( dir, pyfiles[j] + ".py" ).absoluteFilePath();
+ if ( QFileInfo( dir, pyfiles[j] ).exists() ) {
+ pyConsole->exec( command.arg( QFileInfo( dir, pyfiles[j] ).absoluteFilePath() ) );
+ found = true;
+ break;
+ }
+ else if ( QFileInfo( dir, pyfiles[j] + ".py" ).exists() ) {
+ pyConsole->exec( command.arg( QFileInfo( dir, pyfiles[j] + ".py" ).absoluteFilePath() ) );
+ found = true;
+ break;
+ }
+ }
+ if ( !found ) {
+ qDebug() << "Can't execute file" << pyfiles[j];
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+/*!Create actions:*/
+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" ),
+ 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
+
+
+ int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
+
+ // "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( FileLoadId, fileMenu, 0 ); //SRN: BugID IPAL9021, add a menu item "Load"
+
+ 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();
+ PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
+ PyObject* 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==NULL)
+ PyErr_Print();
+ Py_XDECREF(res);
+ PyGILState_Release(gstate);
+ // end of SALOME plugins loading
+
+}
+
+
+/*!Set desktop:*/
+void SalomeApp_Application::setDesktop( SUIT_Desktop* desk )
+{
+ LightApp_Application::setDesktop( desk );
+
+ if ( desk ) {
+ connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
+ this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection );
+ }
+}
+
+/*!
+ \brief Close application.
+*/
+void SalomeApp_Application::onExit()
+{
+ bool killServers = false;
+ bool result = true;
+
+ if ( exitConfirmation() ) {
+ SalomeApp_ExitDlg dlg( desktop() );
+ result = dlg.exec() == QDialog::Accepted;
+ killServers = dlg.isServersShutdown();
+ }
+
+ if ( result )
+ SUIT_Session::session()->closeSession( SUIT_Session::ASK, killServers );
+}
+
+/*!SLOT. Load document.*/
+void SalomeApp_Application::onLoadDoc()
+{
+ QString studyName;
+
+ std::vector<std::string> List = studyMgr()->GetOpenStudies();
+
+ SUIT_Session* aSession = SUIT_Session::session();
+ QList<SUIT_Application*> 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<SUIT_Application*> 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;
+ }
+
+ studyName = SalomeApp_LoadStudiesDlg::selectStudy( desktop(), unloadedStudies );
+ if ( studyName.isEmpty() )
+ return;
+
+#ifndef WIN32
+ // this code replaces marker of windows drive and path become invalid therefore
+ // defines placed there
+ studyName.replace( QRegExp(":"), "/" );
+#endif
+
+ if ( onLoadDoc( studyName ) ) {
+ updateWindows();
+ updateViewManagers();
+ updateObjectBrowser( true );
+ }
+}
+
+/*!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"));
+
+ QString anInitialPath = "";
+ if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
+ anInitialPath = QDir::currentPath();
+
+ QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
+
+ if ( !aFile.isEmpty() )
+ {
+ onNewDoc();
+
+ QString command = QString("execfile(r\"%1\")").arg(aFile);
+
+ PyConsole_Console* pyConsole = pythonConsole();
+
+ if ( pyConsole )
+ pyConsole->exec( command );
+ }
+}
+
+
+/*!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<SUIT_Application*> aAppList = aSession->applications();
+ bool isAlreadyOpen = false;
+ SalomeApp_Application* aApp = 0;
+ for ( QList<SUIT_Application*>::iterator it = aAppList.begin();
+ it != aAppList.end() && !isAlreadyOpen; ++it ) {
+ aApp = dynamic_cast<SalomeApp_Application*>( *it );
+ if ( aApp && aApp->activeStudy()->studyName() == aName )
+ isAlreadyOpen = true;
+ }
+ if ( !isAlreadyOpen ) {
+ aApp = dynamic_cast<SalomeApp_Application*>( startApplication( 0, 0 ) );
+ if ( aApp )
+ res = aApp->useStudy( aName );
+ }
+ else {
+ aApp->desktop()->activateWindow();
+ }
+ }
+
+ return res;
+}
+
+/*!SLOT. Copy objects to study maneger from selection maneger..*/
+void SalomeApp_Application::onCopy()
+{
+ SALOME_ListIO list;
+ LightApp_SelectionMgr* mgr = selectionMgr();
+ mgr->selectedObjects(list);
+
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(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(...) {
+ }
+ }
+}
+
+/*!SLOT. Paste objects to study maneger from selection manager.*/
+void SalomeApp_Application::onPaste()
+{
+ SALOME_ListIO list;
+ LightApp_SelectionMgr* mgr = selectionMgr();
+ mgr->selectedObjects(list);
+
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+ if(study == NULL) return;
+
+ _PTR(Study) stdDS = study->studyDS();
+ if(!stdDS) return;
+
+ if ( stdDS->GetProperties()->IsLocked() ) {
+ SUIT_MessageBox::warning( desktop(),
+ QObject::tr("WRN_WARNING"),
+ QObject::tr("WRN_STUDY_LOCKED") );
+ return;
+ }
+
+ 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(...) {
+ }
+ }
+}
+
+/*!Check the application on closing.
+ * \retval true if possible, else false
+ */
+bool SalomeApp_Application::isPossibleToClose( bool& closePermanently )
+{
+ return LightApp_Application::isPossibleToClose( closePermanently );
+}
+
+/*! Check if the study is locked */
+void SalomeApp_Application::onCloseDoc( bool ask )
+{
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+
+ 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;
+
+ }
+ }
+
+ LightApp_Application::onCloseDoc( ask );
+}
+
+/*!Sets enable or disable some actions on selection changed.*/
+void SalomeApp_Application::onSelectionChanged()
+{
+ SALOME_ListIO list;
+ LightApp_SelectionMgr* mgr = selectionMgr();
+ mgr->selectedObjects(list);
+
+ bool canCopy = false;
+ bool canPaste = false;
+
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+ if (study != NULL) {
+ _PTR(Study) stdDS = study->studyDS();
+
+ if (stdDS) {
+ SALOME_ListIteratorOfListIO it ( list );
+
+ 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);
+}
+
+/*!Delete references.*/
+void SalomeApp_Application::onDeleteInvalidReferences()
+{
+ SALOME_ListIO aList;
+ LightApp_SelectionMgr* mgr = selectionMgr();
+ mgr->selectedObjects( aList, QString(), false );
+
+ if( aList.IsEmpty() )
+ return;
+
+ SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
+ _PTR(Study) aStudyDS = aStudy->studyDS();
+ _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
+ _PTR(SObject) anObj;
+
+ 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();
+}
+
+/*!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();
+}
+
+/*!
+ Creates 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* ) ) );
+
+ //to receive signal in application that NoteBook's variable was modified
+ connect( aStudy, SIGNAL(notebookVarUpdated(QString)),
+ this, SIGNAL(notebookVarUpdated(QString)) );
+
+ return aStudy;
+}
+
+/*!
+ Enable/Disable menu items and toolbar buttons. Rebuild menu
+*/
+void SalomeApp_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() );
+
+ // 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 )
+ {
+ QGridLayout* grid = ::qobject_cast<QGridLayout*>( 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);
+}
+
+/*!Private SLOT. On dump study.*/
+void SalomeApp_Application::onDumpStudy( )
+{
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( !appStudy ) return;
+ _PTR(Study) aStudy = appStudy->studyDS();
+
+ QStringList aFilters;
+ aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
+
+ bool anIsPublish = true;
+ bool anIsMultiFile = false;
+ bool anIsSaveGUI = true;
+
+ 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 = appStudy->dump( aFileName, toPublish, isMultiFile, toSaveGUI );
+
+ if ( !res )
+ SUIT_MessageBox::warning( desktop(),
+ QObject::tr("WRN_WARNING"),
+ tr("WRN_DUMP_STUDY_FAILED") );
+ }
+ }
+}
+
+/*!Private SLOT. On load script.*/
+void SalomeApp_Application::onLoadScript( )
+{
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( 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();
+
+ QString aFile = SUIT_FileDlg::getFileName( desktop(), anInitialPath, filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
+
+ if ( !aFile.isEmpty() )
+ {
+ QString command = QString("execfile(r\"%1\")").arg(aFile);
+
+ PyConsole_Console* pyConsole = pythonConsole();
+
+ if ( pyConsole )
+ pyConsole->exec( command );
+ }
+}
+
+/*!Private SLOT. On save GUI state.*/
+void SalomeApp_Application::onSaveGUIState()
+{
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( study ) {
+ SalomeApp_VisualState( this ).storeState();
+ updateSavePointDataObjects( study );
+ updateObjectBrowser();
+ }
+ updateActions();
+}
+
+/*!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 )
+ {
+ SUIT_DataBrowser* ob = qobject_cast<SUIT_DataBrowser*>( 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<SUIT_AbstractModel*>( 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() );
+ */
+ }
+ }
+ else if ( flag == WT_PyConsole )
+ {
+ PyConsole_Console* pyCons = new PyConsole_Console( 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 )
+ {
+ SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( appStudy ) {
+ _PTR(Study) aStudy = appStudy->studyDS();
+ myNoteBook = new SalomeApp_NoteBook( desktop(), aStudy );
+ //to receive signal in NoteBook that it's variable was modified
+ connect( this, SIGNAL(notebookVarUpdated(QString)),
+ myNoteBook, SLOT(onVarUpdate(QString)) );
+ }
+ wid = myNoteBook;
+ }
+ return wid;
+}
+
+/*!Create preferences.*/
+void SalomeApp_Application::createPreferences( LightApp_Preferences* pref )
+{
+ LightApp_Application::createPreferences(pref);
+
+ if ( !pref )
+ return;
+
+ 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 );
+}
+
+/*!Update desktop title.*/
+void SalomeApp_Application::updateDesktopTitle() {
+ QString aTitle = applicationName();
+ QString aVer = applicationVersion();
+ if ( !aVer.isEmpty() )
+ aTitle += QString( " " ) + aVer;
+
+ if ( activeStudy() )
+ {
+ QString sName = SUIT_Tools::file( activeStudy()->studyName().trimmed(), false );
+ if ( !sName.isEmpty() ) {
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(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 );
+}
+
+int SalomeApp_Application::closeChoice( const QString& docName )
+{
+ int answer = SUIT_MessageBox::question( desktop(), tr( "APPCLOSE_CAPTION" ), tr( "APPCLOSE_DESCRIPTION" ).arg( docName ),
+ tr ("APPCLOSE_SAVE"), tr ("APPCLOSE_CLOSE"),
+ tr ("APPCLOSE_UNLOAD"), tr ("APPCLOSE_CANCEL"), 0 );
+
+ int res = CloseCancel;
+ if ( answer == 0 )
+ res = CloseSave;
+ else if ( answer == 1 )
+ res = CloseDiscard;
+ else if ( answer == 2 )
+ res = CloseUnload;
+
+ return res;
+}
+
+bool SalomeApp_Application::closeAction( const int choice, bool& closePermanently )
+{
+ bool res = true;
+ switch( choice )
+ {
+ 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;
+ }
+
+ return res;
+}
+
+int SalomeApp_Application::openChoice( const QString& aName )
+{
+ int choice = LightApp_Application::openChoice( aName );
+
+ if ( QFileInfo( aName ).exists() ) {
+ if ( choice == OpenNew ) { // The document isn't already open.
+ bool exist = false;
+ std::vector<std::string> 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 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
+ on the module activation.
+
+ The method should return the map of the kind \c {<id>:<name>}
+ where \c <id> is an integer identifier of the operation and
+ \c <name> 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.
+
+ \return map of the operations
+ \sa moduleActionSelected()
+*/
+QMap<int, QString> SalomeApp_Application::activateModuleActions() const
+{
+ QMap<int, QString> opmap = LightApp_Application::activateModuleActions();
+ opmap.insert( LoadStudyId, tr( "ACTIVATE_MODULE_OP_LOAD" ) );
+ opmap.insert( NewAndScriptId, tr( "ACTIVATE_MODULE_OP_SCRIPT" ) );
+ return opmap;
+}
+
+/*!
+ \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 )
+{
+ switch ( id ) {
+ case LoadStudyId:
+ onLoadDoc();
+ break;
+ case NewAndScriptId:
+ onNewWithScript();
+ break;
+ default:
+ LightApp_Application::moduleActionSelected( id );
+ break;
+ }
+}
+
+/*!Gets CORBA::ORB_var*/
+CORBA::ORB_var SalomeApp_Application::orb()
+{
+ ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
+ static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
+ return _orb;
+}
+
+/*!Create and return SALOMEDS_StudyManager.*/
+SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
+{
+ static _PTR(StudyManager) _sm;
+ if(!_sm) _sm = ClientFactory::StudyManager();
+ return _sm.get();
+}
+
+/*!Create and return SALOME_NamingService.*/
+SALOME_NamingService* SalomeApp_Application::namingService()
+{
+ static SALOME_NamingService _ns(orb());
+ return &_ns;
+}
+
+/*!Create and return SALOME_LifeCycleCORBA.*/
+SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
+{
+ static SALOME_LifeCycleCORBA _lcc( namingService() );
+ return &_lcc;
+}
+
+/*!Private SLOT. On preferences.*/
+void SalomeApp_Application::onProperties()
+{
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if( !study )
+ return;
+
+ _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
+ SB->NewCommand();
+
+ SalomeApp_StudyPropertiesDlg aDlg( desktop() );
+ int res = aDlg.exec();
+ if( res==QDialog::Accepted && aDlg.isChanged() )
+ SB->CommitCommand();
+ else
+ SB->AbortCommand();
+
+ //study->updateCaptions();
+ updateDesktopTitle();
+ updateActions();
+}
+
+/*!Insert items in popup, which necessary for current application*/
+void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePopup, QString& title )
+{
+ 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() ) );
+ }
+
+ // "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<SalomeApp_Study*>(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 )
+ {
+ 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<SalomeApp_Study*>( 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() ) );
+ }
+ }
+
+ mgr->setSelectionCacheEnabled( cacheIsOn );
+}
+
+/*!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 )
+{
+ // update "non-existing" (not loaded yet) data models
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+ if ( study )
+ {
+ _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 );
+ }
+ }
+ }
+
+ // create data objects that correspond to GUI state save points
+ if ( study ) updateSavePointDataObjects( study );
+
+ // update existing data models (already loaded SComponents)
+ LightApp_Application::updateObjectBrowser( updateModels );
+}
+
+/*!Display Catalog Genenerator dialog */
+void SalomeApp_Application::onCatalogGen()
+{
+ ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
+ aDlg.exec();
+}
+
+/*!Display Registry Display dialog */
+void SalomeApp_Application::onRegDisplay()
+{
+ CORBA::ORB_var anOrb = orb();
+ ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop() );
+ regWnd->show();
+ regWnd->raise();
+ regWnd->activateWindow();
+}
+
+/*!find original object by double click on item */
+void SalomeApp_Application::onDblClick( SUIT_DataObject* theObj )
+{
+ // Issue 21379: References are supported at LightApp_DataObject level
+ LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>( theObj );
+
+ if( obj && obj->isReference() )
+ {
+ QString entry = obj->refEntry();
+
+ SUIT_DataOwnerPtrList aList;
+ aList.append( new LightApp_DataOwner( entry ) );
+ selectionMgr()->setSelected( aList, false );
+
+ SUIT_DataBrowser* ob = objectBrowser();
+
+ QModelIndexList aSelectedIndexes = ob->selectedIndexes();
+ if ( !aSelectedIndexes.isEmpty() )
+ ob->treeView()->scrollTo( aSelectedIndexes.first() );
+ }
+}
+
+/*!
+ Creates new view manager
+ \param type - type of view manager
+*/
+SUIT_ViewManager* SalomeApp_Application::newViewManager(const QString& type)
+{
+ return createViewManager(type);
+}
+
+
+/*!Global utility funciton, returns selected GUI Save point object's ID */
+int getSelectedSavePoint( const LightApp_SelectionMgr* selMgr )
+{
+ 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;
+}
+
+/*!Called on Restore GUI State popup command*/
+void SalomeApp_Application::onRestoreGUIState()
+{
+ int savePoint = ::getSelectedSavePoint( selectionMgr() );
+ if ( savePoint == -1 )
+ return;
+ SalomeApp_VisualState( this ).restoreState( savePoint );
+}
+
+/*!Called on Delete GUI State popup command*/
+void SalomeApp_Application::onDeleteGUIState()
+{
+ int savePoint = ::getSelectedSavePoint( selectionMgr() );
+ if ( savePoint == -1 )
+ return;
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if ( !study )
+ return;
+
+ study->removeSavePoint( savePoint );
+ updateSavePointDataObjects( study );
+}
+
+/*!Called on New study operation*/
+void SalomeApp_Application::onStudyCreated( SUIT_Study* study )
+{
+ 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();
+}
+
+/*!Called on Save study operation*/
+void SalomeApp_Application::onStudySaved( SUIT_Study* study )
+{
+ LightApp_Application::onStudySaved( study );
+
+ // temporary commented
+ /*if ( objectBrowser() ) {
+ updateSavePointDataObjects( dynamic_cast<SalomeApp_Study*>( study ) );
+ objectBrowser()->updateTree( study->root() );
+ }*/
+}
+
+/*!Called on Open study operation*/
+void SalomeApp_Application::onStudyOpened( SUIT_Study* study )
+{
+ LightApp_Application::onStudyOpened( 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();
+
+ // temporary commented
+ /*if ( objectBrowser() ) {
+ updateSavePointDataObjects( dynamic_cast<SalomeApp_Study*>( study ) );
+ objectBrowser()->updateTree( study->root() );
+ }*/
+}
+
+/*! 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<SalomeApp_SavePointRootObject*>( *it ) ) {
+ guiRootObj = *it;
+ break;
+ }
+ }
+ std::vector<int> 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();
+ }
+
+ // store data objects in a map id-to-DataObject
+ QMap<int,SalomeApp_SavePointObject*> mapDO;
+ ch.clear();
+ guiRootObj->children( ch );
+ for( it = ch.begin(), last = ch.end(); it != last ; ++it ) {
+ SalomeApp_SavePointObject* dobj = dynamic_cast<SalomeApp_SavePointObject*>( *it );
+ if ( dobj )
+ mapDO[dobj->getId()] = dobj;
+ }
+
+ // 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<int,SalomeApp_SavePointObject*>::Iterator it = mapDO.begin(); it != mapDO.end(); ++it )
+ delete it.value();
+ ob->setAutoUpdate(isAutoUpdate);
+ }
+}
+
+/*! Check data object */
+bool SalomeApp_Application::checkDataObject(LightApp_DataObject* theObj)
+{
+ if (theObj)
+ return true;
+
+ return false;
+}
+
+/*!
+ 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<SalomeApp_Study*>( activeStudy() );
+ bool res = false;
+ if (aStudy)
+ res = aStudy->loadDocument( theName );
+ updateDesktopTitle();
+ updateCommandsStatus();
+ return res;
+}
+
+/*! Show/hide object browser colums according to preferences */
+void SalomeApp_Application::objectBrowserColumnsVisibility()
+{
+ 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 );
+ }
+}
+
+/*! Set SalomeApp_NoteBook pointer */
+void SalomeApp_Application::setNoteBook(SalomeApp_NoteBook* theNoteBook){
+ myNoteBook = theNoteBook;
+}
+
+/*! Return SalomeApp_NoteBook pointer */
+SalomeApp_NoteBook* SalomeApp_Application::getNoteBook() const
+{
+ return myNoteBook;
+}
+
+/*!
+ * 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:
+ * <section name="MODULENAME">
+ * <parameter name="popupitems" value="menuitem1:menuitem2:..."/>
+ * </section>
+ * <section name="importmed">
+ * <parameter name="title" value="My menu"/>
+ * <parameter name="objectid" value="VISU.Result"/>
+ * <parameter name="method" value="nameOfModuleMethod"/>
+ * </section>
+ */
+void SalomeApp_Application::createExtraActions()
+{
+ 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<<aModuleName<<aSlot;
+ aAction->setData(aData);
+ connect(aAction, SIGNAL(triggered()), this, SLOT(onExtAction()));
+ myExtActions[aId] = aAction;
+ }
+ }
+ }
+}
+
+/*!
+ * Called when extra action is selected
+ */
+void SalomeApp_Application::onExtAction()
+{
+ QAction* aAction = ::qobject_cast<QAction*>(sender());
+ if (!aAction)
+ return;
+
+ QVariant aData = aAction->data();
+ QStringList aDataList = aData.value<QStringList>();
+ 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]));
+}
+
+/*!
+ * Called when window activated
+ */
+void SalomeApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow )
+{
+ 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 );
+}
+
+/*!
+ Update visibility state of given objects
+ */
+void SalomeApp_Application::updateVisibilityState( DataObjectList& theList,
+ SUIT_ViewModel* theViewModel )
+{
+ LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
+
+ if(!theViewModel)
+ return;
+
+ SALOME_View* aView = dynamic_cast<SALOME_View*>( theViewModel );
+
+ if (theList.isEmpty() || !aView || !aStudy)
+ return;
+
+ for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) {
+ LightApp_DataObject* obj = dynamic_cast<LightApp_DataObject*>(*itr);
+
+ if (!obj || aStudy->isComponent(obj->entry()))
+ continue;
+
+ LightApp_Module* anObjModule = dynamic_cast<LightApp_Module*>(obj->module());
+ Qtx::VisibilityState anObjState = Qtx::UnpresentableState;
+
+ if(anObjModule) {
+ LightApp_Displayer* aDisplayer = anObjModule->displayer();
+ if(aDisplayer) {
+ if( aDisplayer->canBeDisplayed(obj->entry(), theViewModel->getType()) ) {
+ if(aDisplayer->IsDisplayed(obj->entry(),aView))
+ anObjState = Qtx::ShownState;
+ else
+ anObjState = Qtx::HiddenState;
+ }
+ }
+ aStudy->setVisibilityState( obj->entry(), anObjState );
+ }
+ }
+}
+
+/*!
+ Called then view manager removed
+*/
+void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* )
+{
+ ViewManagerList lst;
+ viewManagers(lst);
+ if( lst.count() == 1) { // in case if closed last view window
+ LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>(activeStudy());
+ if(aStudy)
+ aStudy->setVisibilityStateForAll(Qtx::UnpresentableState);
+ }
+}
+
+/*!
+ 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") );
+}
+
+/*!
+ 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 )
+{
+ SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+
+ 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;
+}
+
+/*!
+ \return default windows( Object Browser, Python Console )
+ Adds to map \a aMap.
+ */
+void SalomeApp_Application::defaultWindows( QMap<int, int>& aMap ) const
+{
+ LightApp_Application::defaultWindows(aMap);
+ if(!aMap.contains(WT_NoteBook)) {
+ if(!myNoteBook) {
+ aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea );
+ }
+ }
+}
+
+/*!
+ Gets current windows.
+ \param winMap - output current windows map.
+*/
+void SalomeApp_Application::currentWindows(QMap<int, int>& aMap) const {
+ LightApp_Application::currentWindows(aMap);
+ if(!aMap.contains(WT_NoteBook) && myNoteBook)
+ aMap.insert( WT_NoteBook, Qt::LeftDockWidgetArea );
+}
+
+//============================================================================
+/*! Function : onUpdateStudy
+ * Purpose : Slot to update the study.
+ */
+//============================================================================
+void SalomeApp_Application::onUpdateStudy()
+{
+ QApplication::setOverrideCursor( Qt::WaitCursor );
+
+ if( !updateStudy() )
+ SUIT_MessageBox::warning( desktop(), tr( "ERROR" ), tr( "ERR_UPDATE_STUDY_FAILED" ) );
+
+ QApplication::restoreOverrideCursor();
+}
+
+//============================================================================
+/*! 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()
+{
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
+ if( !study )
+ return false;
+
+ myNoteBook->setIsDumpedStudySaved( study->isSaved() );
+ myNoteBook->setDumpedStudyName( study->studyName() );
+
+ _PTR(Study) studyDS = study->studyDS();
+
+ // get unique temporary directory name
+ QString aTmpDir = QString::fromStdString( SALOMEDS_Tool::GetTmpDir() );
+ if( aTmpDir.isEmpty() )
+ return false;
+
+ 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.
+
+ if( ok )
+ myNoteBook->setDumpedStudyScript( aTmpDir + QDir::separator() + aScriptName + ".py" );
+ else
+ return false;
+
+ QList<SUIT_Application*> 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));
+
+ SalomeApp_Application* app;
+ if( anIndex > 0 && anIndex < aList.count() )
+ app = dynamic_cast<SalomeApp_Application*>( aList[ anIndex - 1 ] );
+ else if(anIndex == 0 && aList.count() > 1)
+ app = dynamic_cast<SalomeApp_Application*>( aList[ 1 ] );
+
+ if( !app )
+ return false;
+
+ if( changeDesktop ) {
+ // 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 );
+ }
+
+ return ok;
+}
+
+//============================================================================
+/*! Function : onRestoreStudy
+ * Purpose : Load the dumped study from Python script
+ */
+//============================================================================
+bool SalomeApp_Application::onRestoreStudy( const QString& theDumpScript,
+ const QString& theStudyName,
+ bool theIsStudySaved )
+{
+ bool ok = true;
+
+ // create a new study
+ onNewDoc();
+
+ // get active application
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+
+ // load study from the temporary directory
+ QString command = QString( "execfile(r\"%1\")" ).arg( theDumpScript );
+
+ PyConsole_Console* pyConsole = app->pythonConsole();
+ if ( pyConsole )
+ pyConsole->execAndWait( command );
+
+ // 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<SalomeApp_Study*>( app->activeStudy() ) )
+ {
+ _PTR(Study) aStudyDS = newStudy->studyDS();
+ app->getNoteBook()->Init( aStudyDS );
+ if( theIsStudySaved ) {
+ newStudy->markAsSavedIn( theStudyName );
+ newStudy->Modified();
+ }
+ }
+ else
+ ok = false;
+
+ return ok;
+}
+
+/*!
+ Close the Application
+*/
+void SalomeApp_Application::closeApplication()
+{
+ // emit signal to restore study from Python script
+ emit dumpedStudyClosed( myNoteBook->getDumpedStudyScript(),
+ myNoteBook->getDumpedStudyName(),
+ myNoteBook->isDumpedStudySaved() );
+
+ LightApp_Application::closeApplication();
+}
-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE\r
-//\r
-// This library is free software; you can redistribute it and/or\r
-// modify it under the terms of the GNU Lesser General Public\r
-// License as published by the Free Software Foundation; either\r
-// version 2.1 of the License.\r
-//\r
-// This library is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
-// Lesser General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU Lesser General Public\r
-// License along with this library; if not, write to the Free Software\r
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-//\r
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com\r
-//\r
-\r
-// File: SalomeApp_NoteBook.cxx\r
-// Author : Roman NIKOLAEV, Open CASCADE S.A.S.\r
-// Module : GUI\r
-//\r
-#include <PyConsole_Interp.h> // this include must be first (see PyInterp_base.h)!\r
-#include <PyConsole_Console.h>\r
-\r
-#include "SalomeApp_NoteBook.h"\r
-#include "SalomeApp_Application.h"\r
-#include "SalomeApp_Study.h"\r
-#include "SalomeApp_VisualState.h"\r
-\r
-#include <Qtx.h>\r
-\r
-#include <CAM_Module.h>\r
-\r
-#include <SUIT_Desktop.h>\r
-#include <SUIT_MessageBox.h>\r
-#include <SUIT_ResourceMgr.h>\r
-#include <SUIT_Session.h>\r
-\r
-#include <QWidget>\r
-#include <QGridLayout>\r
-#include <QTableWidget>\r
-#include <QTableWidgetItem>\r
-#include <QPushButton>\r
-#include <QFont>\r
-#include <QGroupBox>\r
-#include <QList>\r
-#include <QApplication>\r
-#include <QDir>\r
-\r
-#include <string>\r
-#include <vector>\r
-\r
-#define DEFAULT_MARGIN 11\r
-#define DEFAULT_SPACING 6\r
-#define SPACER_SIZE 100\r
-#define COLUMN_SIZE 100\r
-\r
-#define NAME_COLUMN 0\r
-#define VALUE_COLUMN 1\r
-\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// NoteBook_TableRow class //\r
-///////////////////////////////////////////////////////////////////////////\r
-//============================================================================\r
-/*! Function : NoteBook_TableRow\r
- * Purpose : Constructor\r
- */\r
-//============================================================================\r
-NoteBook_TableRow::NoteBook_TableRow(int index, NoteBook_Table* parentTable, QWidget* parent):\r
- QWidget(parent),\r
- myParentTable(parentTable),\r
- myIndex(index),\r
- myRowHeader(new QTableWidgetItem()),\r
- myVariableName(new QTableWidgetItem()),\r
- myVariableValue(new QTableWidgetItem())\r
-{\r
-}\r
-\r
-//============================================================================\r
-/*! Function : ~NoteBook_TableRow\r
- * Purpose : Destructor\r
- */\r
-//============================================================================\r
-NoteBook_TableRow::~NoteBook_TableRow()\r
-{\r
-}\r
-\r
-//============================================================================\r
-/*! Function : AddToTable\r
- * Purpose : Add this row to the table theTable\r
- */\r
-//============================================================================\r
-void NoteBook_TableRow::AddToTable(QTableWidget *theTable)\r
-{\r
- int aPosition = theTable->rowCount();\r
- int aRowCount = aPosition+1;\r
- theTable->setRowCount(aRowCount);\r
- myRowHeader->setText(QString::number(aRowCount));\r
-\r
- theTable->setVerticalHeaderItem(aPosition,myRowHeader);\r
- theTable->setItem(aPosition, NAME_COLUMN, myVariableName);\r
- theTable->setItem(aPosition, VALUE_COLUMN, myVariableValue);\r
-}\r
-\r
-//============================================================================\r
-/*! Function : SetName\r
- * Purpose : \r
- */\r
-//============================================================================\r
-void NoteBook_TableRow::SetName(const QString theName)\r
-{\r
- myVariableName->setText(theName);\r
-}\r
-\r
-//============================================================================\r
-/*! Function : SetValue\r
- * Purpose : \r
- */\r
-//============================================================================\r
-void NoteBook_TableRow::SetValue(const QString theValue)\r
-{\r
- myVariableValue->setText(theValue);\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetName\r
- * Purpose : Return variable name\r
- */\r
-//============================================================================\r
-QString NoteBook_TableRow::GetName() const\r
-{\r
- return myVariableName->text();\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetValue\r
- * Purpose : Return variable value\r
- */\r
-//============================================================================\r
-QString NoteBook_TableRow::GetValue() const\r
-{\r
- return myVariableValue->text(); \r
-}\r
-\r
-//============================================================================\r
-/*! Function : CheckName\r
- * Purpose : Return true if variable name correct, otherwise return false\r
- */\r
-//============================================================================\r
-bool NoteBook_TableRow::CheckName()\r
-{\r
- QString aName = GetName();\r
- int aPos = 0;\r
- QRegExpValidator aValidator( QRegExp("^([a-zA-Z]+)([a-zA-Z0-9_]*)$"), 0 );\r
- if( aName.isEmpty() || !aValidator.validate( aName, aPos ) )\r
- return false;\r
- return true;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : CheckValue\r
- * Purpose : Return true if variable value correct, otherwise return false\r
- */\r
-//============================================================================\r
-bool NoteBook_TableRow::CheckValue()\r
-{\r
- bool aResult = false;\r
- QString aValue = GetValue();\r
- if(!aValue.isEmpty() && \r
- (IsRealValue(aValue) ||\r
- IsIntegerValue(aValue) ||\r
- IsBooleanValue(aValue) ||\r
- IsValidStringValue(aValue)))\r
- aResult = true;\r
- \r
- return aResult;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetVariableItem\r
- * Purpose : \r
- */\r
-//============================================================================\r
-QTableWidgetItem* NoteBook_TableRow::GetVariableItem()\r
-{\r
- return myVariableValue;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetNameItem\r
- * Purpose : \r
- */\r
-//============================================================================\r
-QTableWidgetItem* NoteBook_TableRow::GetNameItem()\r
-{\r
- return myVariableName;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetHeaderItem\r
- * Purpose : \r
- */\r
-//============================================================================\r
-QTableWidgetItem* NoteBook_TableRow::GetHeaderItem()\r
-{\r
- return myRowHeader;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : IsRealValue\r
- * Purpose : Return true if theValue string is real value, otherwise return \r
- * false\r
- */\r
-//============================================================================\r
-bool NoteBook_TableRow::IsRealValue(const QString theValue, double* theResult)\r
-{\r
- bool aResult = false;\r
- double aDResult = theValue.toDouble(&aResult);\r
- if(aResult && theResult)\r
- *theResult = aDResult;\r
- \r
- return aResult;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : IsBooleanValue\r
- * Purpose : Return true if theValue String is boolean value, otherwise return \r
- * false\r
- */\r
-//============================================================================\r
-bool NoteBook_TableRow::IsBooleanValue(const QString theValue, bool* theResult){\r
- bool aResult = false;\r
- bool aBResult; \r
- if(theValue.compare("True") == 0) {\r
- aBResult = true;\r
- aResult = true;\r
- }\r
- else if(theValue.compare("False") == 0) {\r
- aBResult = false;\r
- aResult = true;\r
- }\r
- if(aResult && theResult)\r
- *theResult = aBResult;\r
- \r
- return aResult;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : IsIntegerValue\r
- * Purpose : Return true if theValue string is integer value, otherwise return \r
- * false\r
- */\r
-//============================================================================\r
-bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult)\r
-{\r
- bool aResult = false;\r
- int anIResult;\r
- anIResult = theValue.toInt(&aResult);\r
-\r
- if(aResult && theResult)\r
- *theResult = anIResult; \r
- \r
- return aResult;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : IsValidStringValue\r
- * Purpose : Return true if theValue string is valid, otherwise return \r
- * false\r
- * The string are always valid for the moment\r
- * The whole notebook is verified on apply\r
- */\r
-//============================================================================\r
-bool NoteBook_TableRow::IsValidStringValue(const QString theValue)\r
-{\r
- int aNumRows = myParentTable->myRows.count();\r
- if( aNumRows == 0 )\r
- return true;\r
-\r
- bool aLastRowIsEmpty = myParentTable->myRows[ aNumRows - 1 ]->GetName().isEmpty() &&\r
- myParentTable->myRows[ aNumRows - 1 ]->GetValue().isEmpty();\r
-\r
- SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );\r
- PyConsole_Console* pyConsole = app->pythonConsole();\r
- PyConsole_Interp* pyInterp = pyConsole->getInterp();\r
- PyLockWrapper aLock = pyInterp->GetLockWrapper();\r
- std::string command = "import salome_notebook ; ";\r
- command += "salome_notebook.checkThisNoteBook(";\r
- for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ ) {\r
- command += myParentTable->myRows[i]->GetName().toStdString();\r
- command += "=\"";\r
- command += myParentTable->myRows[i]->GetValue().toStdString();\r
- command += "\", ";\r
- }\r
- command += ") ";\r
-\r
- //rnv: fix for bug 21947 WinTC5.1.4: Wrong error management of "Salome NoteBook"\r
- bool oldSuppressValue = pyConsole->isSuppressOutput();\r
- pyConsole->setIsSuppressOutput(true); \r
- bool aResult = pyInterp->run(command.c_str());\r
- pyConsole->setIsSuppressOutput(oldSuppressValue); \r
- return !aResult;\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// NoteBook_Table class //\r
-///////////////////////////////////////////////////////////////////////////\r
-//============================================================================\r
-/*! Function : NoteBook_Table\r
- * Purpose : Constructor\r
- */\r
-//============================================================================\r
-NoteBook_Table::NoteBook_Table(QWidget * parent)\r
- :QTableWidget(parent),\r
- isProcessItemChangedSignal(false),\r
- myIsModified(false)\r
-{\r
- setColumnCount(2);\r
- setSelectionMode(QAbstractItemView::SingleSelection);\r
- \r
- //Add Headers Columns\r
- QFont aFont = QFont();\r
- aFont.setPointSize(10);\r
- \r
- //"Name" column\r
- QTableWidgetItem * aNameHeader = new QTableWidgetItem();\r
- aNameHeader->setText(tr("VARNAME_COLUMN"));\r
- aNameHeader->setFont(aFont);\r
- setHorizontalHeaderItem(0,aNameHeader);\r
- setColumnWidth ( 0, COLUMN_SIZE);\r
-\r
- //"Value" Column\r
- QTableWidgetItem * aValueHeader = new QTableWidgetItem();\r
- aValueHeader->setText(tr("VARVALUE_COLUMN"));\r
- aValueHeader->setFont(aFont);\r
- setHorizontalHeaderItem(1,aValueHeader);\r
- setColumnWidth ( 1, COLUMN_SIZE);\r
- setSortingEnabled(false);\r
- \r
- connect(this,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(onItemChanged(QTableWidgetItem*)));\r
-}\r
-\r
-//============================================================================\r
-/*! Function : ~NoteBook_Table\r
- * Purpose : Destructor\r
- */\r
-//============================================================================\r
-NoteBook_Table::~NoteBook_Table(){}\r
-\r
-//============================================================================\r
-/*! Function : getUniqueIndex\r
- * Purpose : Get a unique index for the new row\r
- */\r
-//============================================================================\r
-int NoteBook_Table::getUniqueIndex() const\r
-{\r
- int anIndex = 0;\r
- if( !myRows.isEmpty() )\r
- if( NoteBook_TableRow* aRow = myRows.last() )\r
- anIndex = aRow->GetIndex();\r
-\r
- int aMaxRemovedRow = 0;\r
- for( QListIterator<int> anIter( myRemovedRows ); anIter.hasNext(); )\r
- {\r
- int aRemovedRow = anIter.next();\r
- aMaxRemovedRow = qMax( aRemovedRow, aMaxRemovedRow );\r
- }\r
-\r
- anIndex = qMax( anIndex, aMaxRemovedRow ) + 1;\r
- return anIndex;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : Init\r
- * Purpose : Add variables in the table from theStudy\r
- */\r
-//============================================================================\r
-void NoteBook_Table::Init(_PTR(Study) theStudy)\r
-{\r
- isProcessItemChangedSignal = false;\r
-\r
- int aNumRows = myRows.count();\r
- if( aNumRows > 0 )\r
- {\r
- for( int i = 0; i < myRows.size(); i++ )\r
- {\r
- NoteBook_TableRow* aRow = myRows[ i ];\r
- if( aRow )\r
- {\r
- delete aRow;\r
- aRow = 0;\r
- }\r
- }\r
- myRows.clear();\r
- }\r
- setRowCount( 0 );\r
-\r
- myRemovedRows.clear();\r
- myVariableMapRef.clear();\r
- myVariableMap.clear();\r
-\r
- //Add all variables into the table\r
- std::vector<std::string> aVariables = theStudy->GetVariableNames();\r
- for(int iVar = 0; iVar < aVariables.size(); iVar++ ) {\r
- AddRow(QString(aVariables[iVar].c_str()),\r
- Variable2String(aVariables[iVar],theStudy));\r
- }\r
-\r
- //Add empty row\r
- AddEmptyRow();\r
- isProcessItemChangedSignal = true;\r
-\r
- ResetMaps();\r
-\r
- myStudy = theStudy;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : Variable2String\r
- * Purpose : Convert variable values to QString\r
- */\r
-//============================================================================\r
-QString NoteBook_Table::Variable2String(const std::string& theVarName,\r
- _PTR(Study) theStudy)\r
-{\r
- QString aResult;\r
- if( theStudy->IsReal(theVarName) )\r
- aResult = QString::number(theStudy->GetReal(theVarName));\r
- else if( theStudy->IsInteger(theVarName) )\r
- aResult = QString::number(theStudy->GetInteger(theVarName));\r
- else if( theStudy->IsBoolean(theVarName) )\r
- aResult = theStudy->GetBoolean(theVarName) ? QString("True") : QString("False");\r
- else if( theStudy->IsString(theVarName) )\r
- aResult = theStudy->GetString(theVarName).c_str();\r
- \r
- return aResult;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : IsValid\r
- * Purpose : Check validity of the table data\r
- */\r
-//============================================================================\r
-bool NoteBook_Table::IsValid() const\r
-{\r
- int aNumRows = myRows.count();\r
- if( aNumRows == 0 )\r
- return true;\r
-\r
- bool aLastRowIsEmpty = myRows[ aNumRows - 1 ]->GetName().isEmpty() &&\r
- myRows[ aNumRows - 1 ]->GetValue().isEmpty();\r
-\r
- for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ )\r
- if( !myRows[i]->CheckName() || !IsUniqueName( myRows[i] ) || !myRows[i]->CheckValue() )\r
- return false;\r
-\r
- SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );\r
- PyConsole_Console* pyConsole = app->pythonConsole();\r
- PyConsole_Interp* pyInterp = pyConsole->getInterp();\r
- PyLockWrapper aLock = pyInterp->GetLockWrapper();\r
- std::string command = "import salome_notebook ; ";\r
- command += "salome_notebook.checkThisNoteBook(";\r
- for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ )\r
- {\r
- command += myRows[i]->GetName().toStdString();\r
- command += "=\"";\r
- command += myRows[i]->GetValue().toStdString();\r
- command += "\",";\r
- }\r
- command += ")";\r
-\r
- //rnv: fix for bug 21947 WinTC5.1.4: Wrong error management of "Salome NoteBook"\r
- bool oldSuppressValue = pyConsole->isSuppressOutput();\r
- pyConsole->setIsSuppressOutput(true); \r
- bool aResult = pyInterp->run(command.c_str());\r
- pyConsole->setIsSuppressOutput(oldSuppressValue); \r
-\r
- return !aResult;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : RenumberRowItems\r
- * Purpose : renumber row items\r
- */\r
-//============================================================================\r
-void NoteBook_Table::RenumberRowItems() {\r
- for(int i=0; i<myRows.size();i++){\r
- myRows[i]->GetHeaderItem()->setText(QString::number(i+1));\r
- }\r
-}\r
-\r
-//============================================================================\r
-/*! Function : AddRow\r
- * Purpose : Add a row into the table\r
- */\r
-//============================================================================\r
-void NoteBook_Table::AddRow(const QString& theName, const QString& theValue)\r
-{\r
- int anIndex = getUniqueIndex();\r
- NoteBook_TableRow* aRow = new NoteBook_TableRow(anIndex, this, this);\r
- aRow->SetName(theName);\r
- aRow->SetValue(theValue);\r
- aRow->AddToTable(this);\r
- myRows.append(aRow);\r
-\r
- myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theValue ) );\r
-}\r
-\r
-//============================================================================\r
-/*! Function : AddEmptyRow\r
- * Purpose : Add an empty row into the end of the table\r
- */\r
-//============================================================================\r
-void NoteBook_Table::AddEmptyRow()\r
-{\r
- isProcessItemChangedSignal = false;\r
- AddRow();\r
- isProcessItemChangedSignal = true;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetRowByItem\r
- * Purpose : \r
- */\r
-//============================================================================\r
-NoteBook_TableRow* NoteBook_Table::GetRowByItem(const QTableWidgetItem* theItem) const\r
-{\r
- int aCurrentRow = row(theItem);\r
- \r
- if( (myRows.size() <= aCurrentRow ) && (aCurrentRow < 0))\r
- return NULL;\r
- else\r
- return myRows.at(aCurrentRow);\r
-}\r
-\r
-//============================================================================\r
-/*! Function : IsLastRow\r
- * Purpose : Return true if theRow is last row in the table\r
- */\r
-//============================================================================\r
-bool NoteBook_Table::IsLastRow(const NoteBook_TableRow* theRow) const\r
-{\r
- return (myRows.last() == theRow);\r
-}\r
-\r
-//============================================================================\r
-/*! Function : onItemChanged\r
- * Purpose : [slot] called when table item changed\r
- */\r
-//============================================================================\r
-void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem)\r
-{\r
- if(isProcessItemChangedSignal) {\r
- bool isModified = true;\r
- NoteBook_TableRow* aRow = GetRowByItem(theItem);\r
- if(aRow) {\r
- int aCurrentColumn = column(theItem);\r
- bool IsCorrect = true, IsVariableComplited = false;\r
- QString aMsg;\r
-\r
- if(aCurrentColumn == NAME_COLUMN) {\r
- int anIndex = aRow->GetIndex();\r
- if( myVariableMap.contains( anIndex ) )\r
- {\r
- const NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];\r
- if( !aVariable.Name.isEmpty() && myStudy->IsVariableUsed( std::string( aVariable.Name.toLatin1().constData() ) ) )\r
- {\r
- if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),\r
- tr( "RENAME_VARIABLE_IS_USED" ).arg( aVariable.Name ),\r
- QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )\r
- {\r
- bool isBlocked = blockSignals( true );\r
- aRow->SetName( aVariable.Name );\r
- blockSignals( isBlocked );\r
- return;\r
- }\r
- }\r
- }\r
- }\r
-\r
- //Case when variable name was changed.\r
- if(aCurrentColumn == NAME_COLUMN) {\r
- if(!aRow->CheckName()) {\r
- IsCorrect = false;\r
- aMsg = tr( "VARNAME_INCORRECT" ).arg(aRow->GetName());\r
- }\r
- else if(!IsUniqueName(aRow)) {\r
- IsCorrect = false;\r
- aMsg = tr( "VARNAME_EXISTS" ).arg(aRow->GetName());\r
- }\r
- else\r
- IsVariableComplited = aRow->CheckValue();\r
- }\r
- \r
- //Case when variable value was changed. \r
- else if(aCurrentColumn == VALUE_COLUMN){\r
- if(!aRow->CheckValue()) {\r
- IsCorrect = false;\r
- aMsg = tr( "VARVALUE_INCORRECT" ).arg(aRow->GetName());\r
- }\r
- else\r
- IsVariableComplited = aRow->CheckName() && IsUniqueName(aRow);\r
- }\r
-\r
- if(!IsCorrect && !aMsg.isEmpty())\r
- SUIT_MessageBox::warning( parentWidget(), tr( "WARNING" ), aMsg );\r
-\r
- bool isBlocked = blockSignals( true );\r
- theItem->setForeground( QBrush( IsCorrect ? Qt::black : Qt::red ) );\r
- blockSignals( isBlocked );\r
-\r
- int anIndex = aRow->GetIndex();\r
- if( myVariableMap.contains( anIndex ) )\r
- {\r
- NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];\r
- if( aVariable.Name.compare( aRow->GetName() ) != 0 ||\r
- aVariable.Value.compare( aRow->GetValue() ) != 0 )\r
- {\r
- aVariable.Name = aRow->GetName();\r
- aVariable.Value = aRow->GetValue();\r
- }\r
- else\r
- isModified = false;\r
- }\r
-\r
- if(IsCorrect && IsVariableComplited && IsLastRow(aRow))\r
- AddEmptyRow();\r
-\r
- if( aRow->CheckName() && aRow->CheckValue() )\r
- qobject_cast<SalomeApp_NoteBook*>(parentWidget())->onApply();\r
- }\r
-\r
- if( !myIsModified )\r
- myIsModified = isModified;\r
- }\r
-}\r
-\r
-//============================================================================\r
-/*! Function : IsUniqueName\r
- * Purpose : Return true if theName is unique name of the Variable\r
- */\r
-//============================================================================\r
-bool NoteBook_Table::IsUniqueName(const NoteBook_TableRow* theRow) const\r
-{\r
- for(int i=0; i<myRows.size();i++) {\r
- if(myRows[i] == theRow ) \r
- continue;\r
- if(myRows[i]->GetName().compare(theRow->GetName()) == 0)\r
- return false;\r
- }\r
- return true;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : RemoveSelected\r
- * Purpose : Remove selected rows in the table\r
- */\r
-//============================================================================\r
-void NoteBook_Table::RemoveSelected()\r
-{\r
- isProcessItemChangedSignal = false;\r
- QList<QTableWidgetItem*> aSelectedItems = selectedItems();\r
- if( !(aSelectedItems.size() > 0)) {\r
- isProcessItemChangedSignal = true;\r
- return;\r
- }\r
- bool removedFromStudy = false;\r
- for(int i=0; i < aSelectedItems.size(); i++ ) {\r
- NoteBook_TableRow* aRow = GetRowByItem(aSelectedItems[i]);\r
- if(aRow) {\r
- if(IsLastRow(aRow)) {\r
- aRow->SetName(QString());\r
- aRow->SetValue(QString());\r
- }\r
- else {\r
- int nRow = row(aSelectedItems[i]);\r
-\r
- if( myStudy->IsVariableUsed( std::string( aRow->GetName().toLatin1().constData() ) ) )\r
- {\r
- if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),\r
- tr( "REMOVE_VARIABLE_IS_USED" ).arg( aRow->GetName() ),\r
- QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )\r
- {\r
- isProcessItemChangedSignal = true;\r
- return;\r
- }\r
- }\r
-\r
- int index = aRow->GetIndex();\r
- QString aVarName = aRow->GetName();\r
- myRemovedRows.append( index );\r
- if( myVariableMap.contains( index ) )\r
- myVariableMap.remove( index );\r
- removeRow(nRow);\r
- myRows.removeAt(nRow);\r
- if(myStudy->IsVariable(aVarName.toLatin1().constData()))\r
- removedFromStudy = true;\r
- }\r
- }\r
- }\r
- if(removedFromStudy)\r
- myIsModified = true;\r
- RenumberRowItems();\r
- isProcessItemChangedSignal = true;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : SetProcessItemChangedSignalFlag\r
- * Purpose : \r
- */\r
-//============================================================================\r
-void NoteBook_Table::SetProcessItemChangedSignalFlag(const bool enable)\r
-{\r
- isProcessItemChangedSignal = enable;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetProcessItemChangedSignalFlag\r
- * Purpose : \r
- */\r
-//============================================================================\r
-bool NoteBook_Table::GetProcessItemChangedSignalFlag() const\r
-{\r
- return isProcessItemChangedSignal;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : GetRows\r
- * Purpose : \r
- */\r
-//============================================================================\r
-QList<NoteBook_TableRow*> NoteBook_Table::GetRows() const\r
-{\r
- return myRows;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : ResetMaps\r
- * Purpose : Reset variable maps\r
- */\r
-//============================================================================\r
-void NoteBook_Table::ResetMaps()\r
-{\r
- myIsModified = false;\r
- myVariableMapRef = myVariableMap;\r
- myRemovedRows.clear();\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-// SalomeApp_NoteBook class //\r
-///////////////////////////////////////////////////////////////////////////\r
-//============================================================================\r
-/*! Function : SalomeApp_NoteBook\r
- * Purpose : Constructor\r
- */\r
-//============================================================================\r
-SalomeApp_NoteBook::SalomeApp_NoteBook(QWidget * parent, _PTR(Study) theStudy):\r
- QWidget(parent),\r
- myStudy(theStudy)\r
-{\r
- setObjectName("SalomeApp_NoteBook");\r
- setWindowTitle(tr("NOTEBOOK_TITLE"));\r
- QGridLayout* aLayout = new QGridLayout(this);\r
-\r
- //Table\r
- myTable = new NoteBook_Table(this);\r
- aLayout->addWidget(myTable, 0, 0, 1, 3);\r
- \r
- //Buttons\r
- myRemoveButton = new QPushButton(tr("BUT_REMOVE"));\r
- aLayout->addWidget(myRemoveButton, 1, 0);\r
-\r
- QSpacerItem* spacer =\r
- new QSpacerItem(DEFAULT_SPACING, 5 , QSizePolicy::Expanding, QSizePolicy::Minimum);\r
- aLayout->addItem(spacer, 1, 1);\r
-\r
- myUpdateStudyBtn = new QPushButton(tr("BUT_UPDATE_STUDY"));\r
- aLayout->addWidget(myUpdateStudyBtn, 1, 2);\r
-\r
- QWidgetList aWidgetList;\r
- aWidgetList.append( myTable );\r
- aWidgetList.append( myUpdateStudyBtn );\r
- aWidgetList.append( myRemoveButton );\r
- Qtx::setTabOrder( aWidgetList );\r
-\r
- connect( myUpdateStudyBtn, SIGNAL(clicked()), this, SLOT(onUpdateStudy()) );\r
- connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));\r
- \r
- myTable->Init(myStudy);\r
-\r
- myDumpedStudyScript = ""; \r
- myIsDumpedStudySaved = false;\r
-}\r
-\r
-//============================================================================\r
-/*! Function : ~SalomeApp_NoteBook\r
- * Purpose : Destructor\r
- */\r
-//============================================================================\r
-SalomeApp_NoteBook::~SalomeApp_NoteBook(){}\r
-\r
-\r
-//============================================================================\r
-/*! Function : Init()\r
- * Purpose : init variable table\r
- */\r
-//============================================================================\r
-void SalomeApp_NoteBook::Init(_PTR(Study) theStudy){\r
- if(myStudy!= theStudy)\r
- myStudy = theStudy;\r
- myTable->Init(myStudy);\r
-}\r
-\r
-\r
-//============================================================================\r
-/*! Function : onVarUpdate\r
- * Purpose : [slot]\r
- */\r
-//============================================================================\r
-void SalomeApp_NoteBook::onVarUpdate(QString theVarName)\r
-{\r
- myTable->Init(myStudy);\r
-}\r
-\r
-//============================================================================\r
-/*! Function : onApply\r
- * Purpose : [slot]\r
- */\r
-//============================================================================\r
-void SalomeApp_NoteBook::onApply()\r
-{\r
- if( !myTable->IsValid() )\r
- {\r
- SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_DATA" ) );\r
- return;\r
- }\r
-\r
- double aDVal;\r
- int anIVal;\r
- bool aBVal;\r
-\r
- const QList<int>& aRemovedRows = myTable->GetRemovedRows();\r
- const VariableMap& aVariableMap = myTable->GetVariableMap();\r
- const VariableMap& aVariableMapRef = myTable->GetVariableMapRef();\r
-\r
- for( QListIterator<int> anIter( aRemovedRows ); anIter.hasNext(); )\r
- {\r
- int anIndex = anIter.next();\r
- if( aVariableMapRef.contains( anIndex ) )\r
- {\r
- QString aRemovedVariable = aVariableMapRef[ anIndex ].Name;\r
- myStudy->RemoveVariable( std::string( aRemovedVariable.toLatin1().constData() ) );\r
- }\r
- }\r
-\r
- VariableMap::const_iterator it = aVariableMap.constBegin(), itEnd = aVariableMap.constEnd();\r
- for( ; it != itEnd; ++it )\r
- {\r
- int anIndex = it.key();\r
- const NoteBoox_Variable& aVariable = it.value();\r
- QString aName = aVariable.Name;\r
- QString aValue = aVariable.Value;\r
-\r
- if( !aName.isEmpty() && !aValue.isEmpty() )\r
- {\r
- if( aVariableMapRef.contains( anIndex ) )\r
- {\r
- const NoteBoox_Variable& aVariableRef = aVariableMapRef[ anIndex ];\r
- QString aNameRef = aVariableRef.Name;\r
- QString aValueRef = aVariableRef.Value;\r
-\r
- if( !aNameRef.isEmpty() && !aValueRef.isEmpty() && aNameRef != aName )\r
- {\r
- myStudy->RenameVariable( std::string( aNameRef.toLatin1().constData() ),\r
- std::string( aName.toLatin1().constData() ) );\r
- }\r
- }\r
-\r
- if( NoteBook_TableRow::IsIntegerValue(aValue,&anIVal) )\r
- myStudy->SetInteger(std::string(aName.toLatin1().constData()),anIVal);\r
-\r
- else if( NoteBook_TableRow::IsRealValue(aValue,&aDVal) )\r
- myStudy->SetReal(std::string(aName.toLatin1().constData()),aDVal);\r
- \r
- else if( NoteBook_TableRow::IsBooleanValue(aValue,&aBVal) )\r
- myStudy->SetBoolean(std::string(aName.toLatin1().constData()),aBVal);\r
- \r
- else\r
- myStudy->SetString(std::string(aName.toLatin1().constData()),aValue.toStdString());\r
- }\r
- }\r
- myTable->ResetMaps();\r
-\r
- SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );\r
- if(app)\r
- app->updateActions();\r
- \r
- myStudy->Modified();\r
-}\r
-\r
-//============================================================================\r
-/*! Function : onRemove\r
- * Purpose : [slot]\r
- */\r
-//============================================================================\r
-void SalomeApp_NoteBook::onRemove()\r
-{\r
- myTable->RemoveSelected();\r
- onApply();\r
-}\r
-\r
-//============================================================================\r
-/*! Function : onUpdateStudy\r
- * Purpose : [slot]\r
- */\r
-//============================================================================\r
-void SalomeApp_NoteBook::onUpdateStudy()\r
-{\r
- onApply();\r
- if( !myTable->IsValid() )\r
- return;\r
- \r
- SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );\r
- if(!app)\r
- return;\r
- app->onUpdateStudy();\r
-}\r
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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.
+//
+// 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_NoteBook.cxx
+// Author : Roman NIKOLAEV, Open CASCADE S.A.S.
+// Module : GUI
+//
+#include <PyConsole_Interp.h> // this include must be first (see PyInterp_base.h)!
+#include <PyConsole_Console.h>
+
+#include "SalomeApp_NoteBook.h"
+#include "SalomeApp_Application.h"
+#include "SalomeApp_Study.h"
+#include "SalomeApp_VisualState.h"
+
+#include <Qtx.h>
+
+#include <CAM_Module.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+
+#include <QWidget>
+#include <QGridLayout>
+#include <QTableWidget>
+#include <QTableWidgetItem>
+#include <QPushButton>
+#include <QFont>
+#include <QGroupBox>
+#include <QList>
+#include <QApplication>
+#include <QDir>
+
+#include <string>
+#include <vector>
+
+#define DEFAULT_MARGIN 11
+#define DEFAULT_SPACING 6
+#define SPACER_SIZE 100
+#define COLUMN_SIZE 100
+
+#define NAME_COLUMN 0
+#define VALUE_COLUMN 1
+
+
+///////////////////////////////////////////////////////////////////////////
+// NoteBook_TableRow class //
+///////////////////////////////////////////////////////////////////////////
+//============================================================================
+/*! Function : NoteBook_TableRow
+ * Purpose : Constructor
+ */
+//============================================================================
+NoteBook_TableRow::NoteBook_TableRow(int index, NoteBook_Table* parentTable, QWidget* parent):
+ QWidget(parent),
+ myParentTable(parentTable),
+ myIndex(index),
+ myRowHeader(new QTableWidgetItem()),
+ myVariableName(new QTableWidgetItem()),
+ myVariableValue(new QTableWidgetItem())
+{
+}
+
+//============================================================================
+/*! Function : ~NoteBook_TableRow
+ * Purpose : Destructor
+ */
+//============================================================================
+NoteBook_TableRow::~NoteBook_TableRow()
+{
+}
+
+//============================================================================
+/*! Function : AddToTable
+ * Purpose : Add this row to the table theTable
+ */
+//============================================================================
+void NoteBook_TableRow::AddToTable(QTableWidget *theTable)
+{
+ int aPosition = theTable->rowCount();
+ int aRowCount = aPosition+1;
+ theTable->setRowCount(aRowCount);
+ myRowHeader->setText(QString::number(aRowCount));
+
+ theTable->setVerticalHeaderItem(aPosition,myRowHeader);
+ theTable->setItem(aPosition, NAME_COLUMN, myVariableName);
+ theTable->setItem(aPosition, VALUE_COLUMN, myVariableValue);
+}
+
+//============================================================================
+/*! Function : SetName
+ * Purpose :
+ */
+//============================================================================
+void NoteBook_TableRow::SetName(const QString theName)
+{
+ myVariableName->setText(theName);
+}
+
+//============================================================================
+/*! Function : SetValue
+ * Purpose :
+ */
+//============================================================================
+void NoteBook_TableRow::SetValue(const QString theValue)
+{
+ myVariableValue->setText(theValue);
+}
+
+//============================================================================
+/*! Function : GetName
+ * Purpose : Return variable name
+ */
+//============================================================================
+QString NoteBook_TableRow::GetName() const
+{
+ return myVariableName->text();
+}
+
+//============================================================================
+/*! Function : GetValue
+ * Purpose : Return variable value
+ */
+//============================================================================
+QString NoteBook_TableRow::GetValue() const
+{
+ return myVariableValue->text();
+}
+
+//============================================================================
+/*! Function : CheckName
+ * Purpose : Return true if variable name correct, otherwise return false
+ */
+//============================================================================
+bool NoteBook_TableRow::CheckName()
+{
+ QString aName = GetName();
+ int aPos = 0;
+ QRegExpValidator aValidator( QRegExp("^([a-zA-Z]+)([a-zA-Z0-9_]*)$"), 0 );
+ if( aName.isEmpty() || !aValidator.validate( aName, aPos ) )
+ return false;
+ return true;
+}
+
+//============================================================================
+/*! Function : CheckValue
+ * Purpose : Return true if variable value correct, otherwise return false
+ */
+//============================================================================
+bool NoteBook_TableRow::CheckValue()
+{
+ bool aResult = false;
+ QString aValue = GetValue();
+ if(!aValue.isEmpty() &&
+ (IsRealValue(aValue) ||
+ IsIntegerValue(aValue) ||
+ IsBooleanValue(aValue) ||
+ IsValidStringValue(aValue)))
+ aResult = true;
+
+ return aResult;
+}
+
+//============================================================================
+/*! Function : GetVariableItem
+ * Purpose :
+ */
+//============================================================================
+QTableWidgetItem* NoteBook_TableRow::GetVariableItem()
+{
+ return myVariableValue;
+}
+
+//============================================================================
+/*! Function : GetNameItem
+ * Purpose :
+ */
+//============================================================================
+QTableWidgetItem* NoteBook_TableRow::GetNameItem()
+{
+ return myVariableName;
+}
+
+//============================================================================
+/*! Function : GetHeaderItem
+ * Purpose :
+ */
+//============================================================================
+QTableWidgetItem* NoteBook_TableRow::GetHeaderItem()
+{
+ return myRowHeader;
+}
+
+//============================================================================
+/*! Function : IsRealValue
+ * Purpose : Return true if theValue string is real value, otherwise return
+ * false
+ */
+//============================================================================
+bool NoteBook_TableRow::IsRealValue(const QString theValue, double* theResult)
+{
+ bool aResult = false;
+ double aDResult = theValue.toDouble(&aResult);
+ if(aResult && theResult)
+ *theResult = aDResult;
+
+ return aResult;
+}
+
+//============================================================================
+/*! Function : IsBooleanValue
+ * Purpose : Return true if theValue String is boolean value, otherwise return
+ * false
+ */
+//============================================================================
+bool NoteBook_TableRow::IsBooleanValue(const QString theValue, bool* theResult){
+ bool aResult = false;
+ bool aBResult;
+ if(theValue.compare("True") == 0) {
+ aBResult = true;
+ aResult = true;
+ }
+ else if(theValue.compare("False") == 0) {
+ aBResult = false;
+ aResult = true;
+ }
+ if(aResult && theResult)
+ *theResult = aBResult;
+
+ return aResult;
+}
+
+//============================================================================
+/*! Function : IsIntegerValue
+ * Purpose : Return true if theValue string is integer value, otherwise return
+ * false
+ */
+//============================================================================
+bool NoteBook_TableRow::IsIntegerValue(const QString theValue, int* theResult)
+{
+ bool aResult = false;
+ int anIResult;
+ anIResult = theValue.toInt(&aResult);
+
+ if(aResult && theResult)
+ *theResult = anIResult;
+
+ return aResult;
+}
+
+//============================================================================
+/*! Function : IsValidStringValue
+ * Purpose : Return true if theValue string is valid, otherwise return
+ * false
+ * The string are always valid for the moment
+ * The whole notebook is verified on apply
+ */
+//============================================================================
+bool NoteBook_TableRow::IsValidStringValue(const QString theValue)
+{
+ int aNumRows = myParentTable->myRows.count();
+ if( aNumRows == 0 )
+ return true;
+
+ bool aLastRowIsEmpty = myParentTable->myRows[ aNumRows - 1 ]->GetName().isEmpty() &&
+ myParentTable->myRows[ aNumRows - 1 ]->GetValue().isEmpty();
+
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+ PyConsole_Console* pyConsole = app->pythonConsole();
+ PyConsole_Interp* pyInterp = pyConsole->getInterp();
+ PyLockWrapper aLock = pyInterp->GetLockWrapper();
+ std::string command = "import salome_notebook ; ";
+ command += "salome_notebook.checkThisNoteBook(";
+ for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ ) {
+ command += myParentTable->myRows[i]->GetName().toStdString();
+ command += "=\"";
+ command += myParentTable->myRows[i]->GetValue().toStdString();
+ command += "\", ";
+ }
+ command += ") ";
+
+ //rnv: fix for bug 21947 WinTC5.1.4: Wrong error management of "Salome NoteBook"
+ bool oldSuppressValue = pyConsole->isSuppressOutput();
+ pyConsole->setIsSuppressOutput(true);
+ bool aResult = pyInterp->run(command.c_str());
+ pyConsole->setIsSuppressOutput(oldSuppressValue);
+ return !aResult;
+}
+
+///////////////////////////////////////////////////////////////////////////
+// NoteBook_Table class //
+///////////////////////////////////////////////////////////////////////////
+//============================================================================
+/*! Function : NoteBook_Table
+ * Purpose : Constructor
+ */
+//============================================================================
+NoteBook_Table::NoteBook_Table(QWidget * parent)
+ :QTableWidget(parent),
+ isProcessItemChangedSignal(false),
+ myIsModified(false)
+{
+ setColumnCount(2);
+ setSelectionMode(QAbstractItemView::SingleSelection);
+
+ //Add Headers Columns
+ QFont aFont = QFont();
+ aFont.setPointSize(10);
+
+ //"Name" column
+ QTableWidgetItem * aNameHeader = new QTableWidgetItem();
+ aNameHeader->setText(tr("VARNAME_COLUMN"));
+ aNameHeader->setFont(aFont);
+ setHorizontalHeaderItem(0,aNameHeader);
+ setColumnWidth ( 0, COLUMN_SIZE);
+
+ //"Value" Column
+ QTableWidgetItem * aValueHeader = new QTableWidgetItem();
+ aValueHeader->setText(tr("VARVALUE_COLUMN"));
+ aValueHeader->setFont(aFont);
+ setHorizontalHeaderItem(1,aValueHeader);
+ setColumnWidth ( 1, COLUMN_SIZE);
+ setSortingEnabled(false);
+
+ connect(this,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(onItemChanged(QTableWidgetItem*)));
+}
+
+//============================================================================
+/*! Function : ~NoteBook_Table
+ * Purpose : Destructor
+ */
+//============================================================================
+NoteBook_Table::~NoteBook_Table(){}
+
+//============================================================================
+/*! Function : getUniqueIndex
+ * Purpose : Get a unique index for the new row
+ */
+//============================================================================
+int NoteBook_Table::getUniqueIndex() const
+{
+ int anIndex = 0;
+ if( !myRows.isEmpty() )
+ if( NoteBook_TableRow* aRow = myRows.last() )
+ anIndex = aRow->GetIndex();
+
+ int aMaxRemovedRow = 0;
+ for( QListIterator<int> anIter( myRemovedRows ); anIter.hasNext(); )
+ {
+ int aRemovedRow = anIter.next();
+ aMaxRemovedRow = qMax( aRemovedRow, aMaxRemovedRow );
+ }
+
+ anIndex = qMax( anIndex, aMaxRemovedRow ) + 1;
+ return anIndex;
+}
+
+//============================================================================
+/*! Function : Init
+ * Purpose : Add variables in the table from theStudy
+ */
+//============================================================================
+void NoteBook_Table::Init(_PTR(Study) theStudy)
+{
+ isProcessItemChangedSignal = false;
+
+ int aNumRows = myRows.count();
+ if( aNumRows > 0 )
+ {
+ for( int i = 0; i < myRows.size(); i++ )
+ {
+ NoteBook_TableRow* aRow = myRows[ i ];
+ if( aRow )
+ {
+ delete aRow;
+ aRow = 0;
+ }
+ }
+ myRows.clear();
+ }
+ setRowCount( 0 );
+
+ myRemovedRows.clear();
+ myVariableMapRef.clear();
+ myVariableMap.clear();
+
+ //Add all variables into the table
+ std::vector<std::string> aVariables = theStudy->GetVariableNames();
+ for(int iVar = 0; iVar < aVariables.size(); iVar++ ) {
+ AddRow(QString(aVariables[iVar].c_str()),
+ Variable2String(aVariables[iVar],theStudy));
+ }
+
+ //Add empty row
+ AddEmptyRow();
+ isProcessItemChangedSignal = true;
+
+ ResetMaps();
+
+ myStudy = theStudy;
+}
+
+//============================================================================
+/*! Function : Variable2String
+ * Purpose : Convert variable values to QString
+ */
+//============================================================================
+QString NoteBook_Table::Variable2String(const std::string& theVarName,
+ _PTR(Study) theStudy)
+{
+ QString aResult;
+ if( theStudy->IsReal(theVarName) )
+ aResult = QString::number(theStudy->GetReal(theVarName));
+ else if( theStudy->IsInteger(theVarName) )
+ aResult = QString::number(theStudy->GetInteger(theVarName));
+ else if( theStudy->IsBoolean(theVarName) )
+ aResult = theStudy->GetBoolean(theVarName) ? QString("True") : QString("False");
+ else if( theStudy->IsString(theVarName) )
+ aResult = theStudy->GetString(theVarName).c_str();
+
+ return aResult;
+}
+
+//============================================================================
+/*! Function : IsValid
+ * Purpose : Check validity of the table data
+ */
+//============================================================================
+bool NoteBook_Table::IsValid() const
+{
+ int aNumRows = myRows.count();
+ if( aNumRows == 0 )
+ return true;
+
+ bool aLastRowIsEmpty = myRows[ aNumRows - 1 ]->GetName().isEmpty() &&
+ myRows[ aNumRows - 1 ]->GetValue().isEmpty();
+
+ for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ )
+ if( !myRows[i]->CheckName() || !IsUniqueName( myRows[i] ) || !myRows[i]->CheckValue() )
+ return false;
+
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+ PyConsole_Console* pyConsole = app->pythonConsole();
+ PyConsole_Interp* pyInterp = pyConsole->getInterp();
+ PyLockWrapper aLock = pyInterp->GetLockWrapper();
+ std::string command = "import salome_notebook ; ";
+ command += "salome_notebook.checkThisNoteBook(";
+ for( int i = 0, n = aLastRowIsEmpty ? aNumRows - 1 : aNumRows; i < n; i++ )
+ {
+ command += myRows[i]->GetName().toStdString();
+ command += "=\"";
+ command += myRows[i]->GetValue().toStdString();
+ command += "\",";
+ }
+ command += ")";
+
+ //rnv: fix for bug 21947 WinTC5.1.4: Wrong error management of "Salome NoteBook"
+ bool oldSuppressValue = pyConsole->isSuppressOutput();
+ pyConsole->setIsSuppressOutput(true);
+ bool aResult = pyInterp->run(command.c_str());
+ pyConsole->setIsSuppressOutput(oldSuppressValue);
+
+ return !aResult;
+}
+
+//============================================================================
+/*! Function : RenumberRowItems
+ * Purpose : renumber row items
+ */
+//============================================================================
+void NoteBook_Table::RenumberRowItems() {
+ for(int i=0; i<myRows.size();i++){
+ myRows[i]->GetHeaderItem()->setText(QString::number(i+1));
+ }
+}
+
+//============================================================================
+/*! Function : AddRow
+ * Purpose : Add a row into the table
+ */
+//============================================================================
+void NoteBook_Table::AddRow(const QString& theName, const QString& theValue)
+{
+ int anIndex = getUniqueIndex();
+ NoteBook_TableRow* aRow = new NoteBook_TableRow(anIndex, this, this);
+ aRow->SetName(theName);
+ aRow->SetValue(theValue);
+ aRow->AddToTable(this);
+ myRows.append(aRow);
+
+ myVariableMap.insert( anIndex, NoteBoox_Variable( theName, theValue ) );
+}
+
+//============================================================================
+/*! Function : AddEmptyRow
+ * Purpose : Add an empty row into the end of the table
+ */
+//============================================================================
+void NoteBook_Table::AddEmptyRow()
+{
+ isProcessItemChangedSignal = false;
+ AddRow();
+ isProcessItemChangedSignal = true;
+}
+
+//============================================================================
+/*! Function : GetRowByItem
+ * Purpose :
+ */
+//============================================================================
+NoteBook_TableRow* NoteBook_Table::GetRowByItem(const QTableWidgetItem* theItem) const
+{
+ int aCurrentRow = row(theItem);
+
+ if( (myRows.size() <= aCurrentRow ) && (aCurrentRow < 0))
+ return NULL;
+ else
+ return myRows.at(aCurrentRow);
+}
+
+//============================================================================
+/*! Function : IsLastRow
+ * Purpose : Return true if theRow is last row in the table
+ */
+//============================================================================
+bool NoteBook_Table::IsLastRow(const NoteBook_TableRow* theRow) const
+{
+ return (myRows.last() == theRow);
+}
+
+//============================================================================
+/*! Function : onItemChanged
+ * Purpose : [slot] called when table item changed
+ */
+//============================================================================
+void NoteBook_Table::onItemChanged(QTableWidgetItem* theItem)
+{
+ if(isProcessItemChangedSignal) {
+ bool isModified = true;
+ NoteBook_TableRow* aRow = GetRowByItem(theItem);
+ if(aRow) {
+ int aCurrentColumn = column(theItem);
+ bool IsCorrect = true, IsVariableComplited = false;
+ QString aMsg;
+
+ if(aCurrentColumn == NAME_COLUMN) {
+ int anIndex = aRow->GetIndex();
+ if( myVariableMap.contains( anIndex ) )
+ {
+ const NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];
+ if( !aVariable.Name.isEmpty() && myStudy->IsVariableUsed( std::string( aVariable.Name.toLatin1().constData() ) ) )
+ {
+ if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),
+ tr( "RENAME_VARIABLE_IS_USED" ).arg( aVariable.Name ),
+ QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
+ {
+ bool isBlocked = blockSignals( true );
+ aRow->SetName( aVariable.Name );
+ blockSignals( isBlocked );
+ return;
+ }
+ }
+ }
+ }
+
+ //Case when variable name was changed.
+ if(aCurrentColumn == NAME_COLUMN) {
+ if(!aRow->CheckName()) {
+ IsCorrect = false;
+ aMsg = tr( "VARNAME_INCORRECT" ).arg(aRow->GetName());
+ }
+ else if(!IsUniqueName(aRow)) {
+ IsCorrect = false;
+ aMsg = tr( "VARNAME_EXISTS" ).arg(aRow->GetName());
+ }
+ else
+ IsVariableComplited = aRow->CheckValue();
+ }
+
+ //Case when variable value was changed.
+ else if(aCurrentColumn == VALUE_COLUMN){
+ if(!aRow->CheckValue()) {
+ IsCorrect = false;
+ aMsg = tr( "VARVALUE_INCORRECT" ).arg(aRow->GetName());
+ }
+ else
+ IsVariableComplited = aRow->CheckName() && IsUniqueName(aRow);
+ }
+
+ if(!IsCorrect && !aMsg.isEmpty())
+ SUIT_MessageBox::warning( parentWidget(), tr( "WARNING" ), aMsg );
+
+ bool isBlocked = blockSignals( true );
+ theItem->setForeground( QBrush( IsCorrect ? Qt::black : Qt::red ) );
+ blockSignals( isBlocked );
+
+ int anIndex = aRow->GetIndex();
+ if( myVariableMap.contains( anIndex ) )
+ {
+ NoteBoox_Variable& aVariable = myVariableMap[ anIndex ];
+ if( aVariable.Name.compare( aRow->GetName() ) != 0 ||
+ aVariable.Value.compare( aRow->GetValue() ) != 0 )
+ {
+ aVariable.Name = aRow->GetName();
+ aVariable.Value = aRow->GetValue();
+ }
+ else
+ isModified = false;
+ }
+
+ if(IsCorrect && IsVariableComplited && IsLastRow(aRow))
+ AddEmptyRow();
+
+ if( aRow->CheckName() && aRow->CheckValue() )
+ qobject_cast<SalomeApp_NoteBook*>(parentWidget())->onApply();
+ }
+
+ if( !myIsModified )
+ myIsModified = isModified;
+ }
+}
+
+//============================================================================
+/*! Function : IsUniqueName
+ * Purpose : Return true if theName is unique name of the Variable
+ */
+//============================================================================
+bool NoteBook_Table::IsUniqueName(const NoteBook_TableRow* theRow) const
+{
+ for(int i=0; i<myRows.size();i++) {
+ if(myRows[i] == theRow )
+ continue;
+ if(myRows[i]->GetName().compare(theRow->GetName()) == 0)
+ return false;
+ }
+ return true;
+}
+
+//============================================================================
+/*! Function : RemoveSelected
+ * Purpose : Remove selected rows in the table
+ */
+//============================================================================
+void NoteBook_Table::RemoveSelected()
+{
+ isProcessItemChangedSignal = false;
+ QList<QTableWidgetItem*> aSelectedItems = selectedItems();
+ if( !(aSelectedItems.size() > 0)) {
+ isProcessItemChangedSignal = true;
+ return;
+ }
+ bool removedFromStudy = false;
+ for(int i=0; i < aSelectedItems.size(); i++ ) {
+ NoteBook_TableRow* aRow = GetRowByItem(aSelectedItems[i]);
+ if(aRow) {
+ if(IsLastRow(aRow)) {
+ aRow->SetName(QString());
+ aRow->SetValue(QString());
+ }
+ else {
+ int nRow = row(aSelectedItems[i]);
+
+ if( myStudy->IsVariableUsed( std::string( aRow->GetName().toLatin1().constData() ) ) )
+ {
+ if( QMessageBox::warning( parentWidget(), tr( "WARNING" ),
+ tr( "REMOVE_VARIABLE_IS_USED" ).arg( aRow->GetName() ),
+ QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
+ {
+ isProcessItemChangedSignal = true;
+ return;
+ }
+ }
+
+ int index = aRow->GetIndex();
+ QString aVarName = aRow->GetName();
+ myRemovedRows.append( index );
+ if( myVariableMap.contains( index ) )
+ myVariableMap.remove( index );
+ removeRow(nRow);
+ myRows.removeAt(nRow);
+ if(myStudy->IsVariable(aVarName.toLatin1().constData()))
+ removedFromStudy = true;
+ }
+ }
+ }
+ if(removedFromStudy)
+ myIsModified = true;
+ RenumberRowItems();
+ isProcessItemChangedSignal = true;
+}
+
+//============================================================================
+/*! Function : SetProcessItemChangedSignalFlag
+ * Purpose :
+ */
+//============================================================================
+void NoteBook_Table::SetProcessItemChangedSignalFlag(const bool enable)
+{
+ isProcessItemChangedSignal = enable;
+}
+
+//============================================================================
+/*! Function : GetProcessItemChangedSignalFlag
+ * Purpose :
+ */
+//============================================================================
+bool NoteBook_Table::GetProcessItemChangedSignalFlag() const
+{
+ return isProcessItemChangedSignal;
+}
+
+//============================================================================
+/*! Function : GetRows
+ * Purpose :
+ */
+//============================================================================
+QList<NoteBook_TableRow*> NoteBook_Table::GetRows() const
+{
+ return myRows;
+}
+
+//============================================================================
+/*! Function : ResetMaps
+ * Purpose : Reset variable maps
+ */
+//============================================================================
+void NoteBook_Table::ResetMaps()
+{
+ myIsModified = false;
+ myVariableMapRef = myVariableMap;
+ myRemovedRows.clear();
+}
+
+///////////////////////////////////////////////////////////////////////////
+// SalomeApp_NoteBook class //
+///////////////////////////////////////////////////////////////////////////
+//============================================================================
+/*! Function : SalomeApp_NoteBook
+ * Purpose : Constructor
+ */
+//============================================================================
+SalomeApp_NoteBook::SalomeApp_NoteBook(QWidget * parent, _PTR(Study) theStudy):
+ QWidget(parent),
+ myStudy(theStudy)
+{
+ setObjectName("SalomeApp_NoteBook");
+ setWindowTitle(tr("NOTEBOOK_TITLE"));
+ QGridLayout* aLayout = new QGridLayout(this);
+
+ //Table
+ myTable = new NoteBook_Table(this);
+ aLayout->addWidget(myTable, 0, 0, 1, 3);
+
+ //Buttons
+ myRemoveButton = new QPushButton(tr("BUT_REMOVE"));
+ aLayout->addWidget(myRemoveButton, 1, 0);
+
+ QSpacerItem* spacer =
+ new QSpacerItem(DEFAULT_SPACING, 5 , QSizePolicy::Expanding, QSizePolicy::Minimum);
+ aLayout->addItem(spacer, 1, 1);
+
+ myUpdateStudyBtn = new QPushButton(tr("BUT_UPDATE_STUDY"));
+ aLayout->addWidget(myUpdateStudyBtn, 1, 2);
+
+ QWidgetList aWidgetList;
+ aWidgetList.append( myTable );
+ aWidgetList.append( myUpdateStudyBtn );
+ aWidgetList.append( myRemoveButton );
+ Qtx::setTabOrder( aWidgetList );
+
+ connect( myUpdateStudyBtn, SIGNAL(clicked()), this, SLOT(onUpdateStudy()) );
+ connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
+
+ myTable->Init(myStudy);
+
+ myDumpedStudyScript = "";
+ myIsDumpedStudySaved = false;
+}
+
+//============================================================================
+/*! Function : ~SalomeApp_NoteBook
+ * Purpose : Destructor
+ */
+//============================================================================
+SalomeApp_NoteBook::~SalomeApp_NoteBook(){}
+
+
+//============================================================================
+/*! Function : Init()
+ * Purpose : init variable table
+ */
+//============================================================================
+void SalomeApp_NoteBook::Init(_PTR(Study) theStudy){
+ if(myStudy!= theStudy)
+ myStudy = theStudy;
+ myTable->Init(myStudy);
+}
+
+
+//============================================================================
+/*! Function : onVarUpdate
+ * Purpose : [slot]
+ */
+//============================================================================
+void SalomeApp_NoteBook::onVarUpdate(QString theVarName)
+{
+ myTable->Init(myStudy);
+}
+
+//============================================================================
+/*! Function : onApply
+ * Purpose : [slot]
+ */
+//============================================================================
+void SalomeApp_NoteBook::onApply()
+{
+ if( !myTable->IsValid() )
+ {
+ SUIT_MessageBox::warning( this, tr( "WARNING" ), tr( "INCORRECT_DATA" ) );
+ return;
+ }
+
+ double aDVal;
+ int anIVal;
+ bool aBVal;
+
+ const QList<int>& aRemovedRows = myTable->GetRemovedRows();
+ const VariableMap& aVariableMap = myTable->GetVariableMap();
+ const VariableMap& aVariableMapRef = myTable->GetVariableMapRef();
+
+ for( QListIterator<int> anIter( aRemovedRows ); anIter.hasNext(); )
+ {
+ int anIndex = anIter.next();
+ if( aVariableMapRef.contains( anIndex ) )
+ {
+ QString aRemovedVariable = aVariableMapRef[ anIndex ].Name;
+ myStudy->RemoveVariable( std::string( aRemovedVariable.toLatin1().constData() ) );
+ }
+ }
+
+ VariableMap::const_iterator it = aVariableMap.constBegin(), itEnd = aVariableMap.constEnd();
+ for( ; it != itEnd; ++it )
+ {
+ int anIndex = it.key();
+ const NoteBoox_Variable& aVariable = it.value();
+ QString aName = aVariable.Name;
+ QString aValue = aVariable.Value;
+
+ if( !aName.isEmpty() && !aValue.isEmpty() )
+ {
+ if( aVariableMapRef.contains( anIndex ) )
+ {
+ const NoteBoox_Variable& aVariableRef = aVariableMapRef[ anIndex ];
+ QString aNameRef = aVariableRef.Name;
+ QString aValueRef = aVariableRef.Value;
+
+ if( !aNameRef.isEmpty() && !aValueRef.isEmpty() && aNameRef != aName )
+ {
+ myStudy->RenameVariable( std::string( aNameRef.toLatin1().constData() ),
+ std::string( aName.toLatin1().constData() ) );
+ }
+ }
+
+ if( NoteBook_TableRow::IsIntegerValue(aValue,&anIVal) )
+ myStudy->SetInteger(std::string(aName.toLatin1().constData()),anIVal);
+
+ else if( NoteBook_TableRow::IsRealValue(aValue,&aDVal) )
+ myStudy->SetReal(std::string(aName.toLatin1().constData()),aDVal);
+
+ else if( NoteBook_TableRow::IsBooleanValue(aValue,&aBVal) )
+ myStudy->SetBoolean(std::string(aName.toLatin1().constData()),aBVal);
+
+ else
+ myStudy->SetString(std::string(aName.toLatin1().constData()),aValue.toStdString());
+ }
+ }
+ myTable->ResetMaps();
+
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+ if(app)
+ app->updateActions();
+
+ myStudy->Modified();
+}
+
+//============================================================================
+/*! Function : onRemove
+ * Purpose : [slot]
+ */
+//============================================================================
+void SalomeApp_NoteBook::onRemove()
+{
+ myTable->RemoveSelected();
+ onApply();
+}
+
+//============================================================================
+/*! Function : onUpdateStudy
+ * Purpose : [slot]
+ */
+//============================================================================
+void SalomeApp_NoteBook::onUpdateStudy()
+{
+ onApply();
+ if( !myTable->IsValid() )
+ return;
+
+ SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+ if(!app)
+ return;
+ app->onUpdateStudy();
+}