From a2ed75cf3547845acf2cdd95cfae7766f5798722 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 29 Apr 2011 14:00:50 +0000 Subject: [PATCH] Add in preferences: 'Publish in study in python dump' and 'Save GUI state in python dump'. Both are used in 'Dump Study' dlg. --- src/SalomeApp/SalomeApp_Application.cxx | 174 +++++++++++--------- src/SalomeApp/resources/SalomeApp.xml | 6 +- src/SalomeApp/resources/SalomeApp_msg_en.ts | 10 +- src/SalomeApp/resources/SalomeApp_msg_fr.ts | 2 +- 4 files changed, 106 insertions(+), 86 deletions(-) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index afbcbb1d0..4f9c611ae 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -18,12 +18,11 @@ // 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 @@ -223,38 +222,38 @@ void SalomeApp_Application::start() 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]; - } + 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]; + } } } } @@ -358,13 +357,13 @@ void SalomeApp_Application::setDesktop( SUIT_Desktop* desk ) return; LightApp_Application::setDesktop( desk ); - + if ( desk != 0 ) { connect( desk, SIGNAL( message( const QString& ) ), this, SLOT( onDesktopMessage( const QString& ) ), Qt::UniqueConnection); connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), - this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); } } @@ -438,7 +437,7 @@ 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(); @@ -694,7 +693,7 @@ void SalomeApp_Application::updateCommandsStatus() a = action(NoteBookId); if( a ) a->setEnabled( activeStudy() ); - + // Load script menu a = action( LoadScriptId ); if ( a ) @@ -783,25 +782,31 @@ void SalomeApp_Application::onDumpStudy( ) QStringList aFilters; aFilters.append( tr( "PYTHON_FILES_FILTER" ) ); + bool anIsPublish = true; bool anIsMultiFile = false; - if ( SUIT_ResourceMgr* aResourceMgr = resourceMgr() ) + 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( true ); + fd.myPublishChk->setChecked( anIsPublish ); fd.myMultiFileChk->setChecked( anIsMultiFile ); - fd.mySaveGUIChk->setChecked( true ); + 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 @@ -865,7 +870,7 @@ void SalomeApp_Application::onLoadScript( ) QStringList filtersList; filtersList.append(tr("PYTHON_FILES_FILTER")); filtersList.append(tr("ALL_FILES_FILTER")); - + QString anInitialPath = ""; if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) anInitialPath = QDir::currentPath(); @@ -1006,8 +1011,13 @@ void SalomeApp_Application::createPreferences( LightApp_Preferences* pref ) // 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_MULTI_FILE_PYTHON_DUMP" ), studyGroup, LightApp_Preferences::Bool, "Study", "multi_file_dump" ); 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.*/ @@ -1108,7 +1118,7 @@ int SalomeApp_Application::openChoice( const QString& aName ) QObject::tr("WRN_FILE_NOT_EXIST").arg(aName.toLatin1().data())); return false; } - + return choice; } @@ -1268,9 +1278,9 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePop 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() ) ); + 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 @@ -1314,7 +1324,7 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePop SalomeApp_Study* study = dynamic_cast(activeStudy()); if ( study ) { _PTR(Study) stdDS = study->studyDS(); - if ( stdDS ) { + if ( stdDS ) { _PTR(SObject) aSO = stdDS->FindObjectID( aIObj->getEntry() ); if ( aSO ) { _PTR( GenericAttribute ) anAttr; @@ -1363,7 +1373,7 @@ void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) _PTR(SComponent) aComponent ( it->Value() ); #ifndef WITH_SALOMEDS_OBSERVER - // with GUI observers this check is not needed anymore + // with GUI observers this check is not needed anymore if ( aComponent->ComponentDataType() == study->getVisualComponentName().toLatin1().constData() ) continue; // skip the magic "Interface Applicative" component #endif @@ -1415,13 +1425,13 @@ void SalomeApp_Application::onDblClick( SUIT_DataObject* theObj ) if( sobj && sobj->ReferencedObject( ref ) ) { entry = ref->GetID().c_str(); - + 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() ); @@ -1484,7 +1494,7 @@ void SalomeApp_Application::onDeleteGUIState() void SalomeApp_Application::onStudyCreated( SUIT_Study* study ) { LightApp_Application::onStudyCreated( study ); - + connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); @@ -1513,7 +1523,7 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* study ) this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); objectBrowserColumnsVisibility(); - + // temporary commented /*if ( objectBrowser() ) { updateSavePointDataObjects( dynamic_cast( study ) ); @@ -1643,10 +1653,10 @@ SalomeApp_NoteBookDlg* SalomeApp_Application::getNoteBook() const /*! * 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, + * 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: *
@@ -1676,11 +1686,11 @@ void SalomeApp_Application::createExtraActions() 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<hasEntry()) + if (!anIO->hasEntry()) return; - + QString aEntry(anIO->getEntry()); QApplication::setOverrideCursor( Qt::WaitCursor ); @@ -1744,7 +1754,7 @@ void SalomeApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow ) return; DataObjectList listObj = rootObj->children( true ); - + SUIT_ViewModel* vmod = 0; if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() ) vmod = vman->getViewModel(); @@ -1760,30 +1770,30 @@ void SalomeApp_Application::updateVisibilityState( DataObjectList& theList, if(!theViewModel) return; - + SALOME_View* aView = dynamic_cast( theViewModel ); - + if (theList.isEmpty() || !aView || !aStudy) return; - + for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) { LightApp_DataObject* obj = dynamic_cast(*itr); - + if (!obj || aStudy->isComponent(obj->entry())) continue; - + LightApp_Module* anObjModule = dynamic_cast(obj->module()); Qtx::VisibilityState anObjState = Qtx::UnpresentableState; - + if(anObjModule) { - LightApp_Displayer* aDisplayer = anObjModule->displayer(); + 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; - } + 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 ); } @@ -1793,7 +1803,7 @@ void SalomeApp_Application::updateVisibilityState( DataObjectList& theList, /*! Called then view manager removed */ -void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) { +void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) { ViewManagerList lst; viewManagers(lst); if( lst.count() == 1) { // in case if closed last view window @@ -1819,14 +1829,14 @@ bool SalomeApp_Application::renameAllowed( const QString& entry) const { \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( activeStudy() ); - + int savePoint = ::getSelectedSavePoint( selectionMgr() ); - + if(!aStudy || savePoint == -1) return false; - + if ( !name.isNull() && !name.isEmpty() ) { aStudy->setNameOfSavePoint( savePoint, name ); updateSavePointDataObjects( aStudy ); diff --git a/src/SalomeApp/resources/SalomeApp.xml b/src/SalomeApp/resources/SalomeApp.xml index d513b2e3d..0c24b6f0f 100644 --- a/src/SalomeApp/resources/SalomeApp.xml +++ b/src/SalomeApp/resources/SalomeApp.xml @@ -59,7 +59,7 @@
- + @@ -71,7 +71,9 @@
- + + +
diff --git a/src/SalomeApp/resources/SalomeApp_msg_en.ts b/src/SalomeApp/resources/SalomeApp_msg_en.ts index 66857a854..c248a811d 100644 --- a/src/SalomeApp/resources/SalomeApp_msg_en.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_en.ts @@ -128,9 +128,17 @@ Python file must include only letters, digits and underscores and start from let Load python script - PREF_MULTI_FILE_PYTHON_DUMP + PREF_PYDUMP_PUBLISH + Publish in study in python dump + + + PREF_PYDUMP_MULTI_FILE Multi file python dump + + PREF_PYDUMP_SAVE_GUI + Save GUI state in python dump + PREF_STORE_VISUAL_STATE Store/restore last GUI state diff --git a/src/SalomeApp/resources/SalomeApp_msg_fr.ts b/src/SalomeApp/resources/SalomeApp_msg_fr.ts index ccc8ee16a..81abd7d28 100755 --- a/src/SalomeApp/resources/SalomeApp_msg_fr.ts +++ b/src/SalomeApp/resources/SalomeApp_msg_fr.ts @@ -128,7 +128,7 @@ Un fichier Python ne doit être composé que de lettres, chiffres et tirets bas Exécuter un script python - PREF_MULTI_FILE_PYTHON_DUMP + PREF_PYDUMP_MULTI_FILE Dump Python multi-fichiers -- 2.39.2