X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSalomeApp%2FSalomeApp_Application.cxx;h=742ecab766d682827e33d10b0f4be24d7fa3a1b1;hb=8dbafb1f41a091c06ba2ea767627fb6221045558;hp=c33026683fbb56b8ec2c4e5652ba07526082bef4;hpb=a947e05a9b21d1c671fb63c69db4a643f6c17532;p=modules%2Fgui.git diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index c33026683..742ecab76 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -9,15 +9,24 @@ #include "SalomeApp_Study.h" #include "SalomeApp_Module.h" +#include "SalomeApp_OBFilter.h" +#include "SalomeApp_DataModel.h" +#include "SalomeApp_DataObject.h" +#include "SalomeApp_EventFilter.h" +#include "SalomeApp_WidgetContainer.h" + +#include "SalomeApp_AboutDlg.h" +#include "SalomeApp_ModuleDlg.h" +#include "SalomeApp_Preferences.h" +#include "SalomeApp_PreferencesDlg.h" +#include "SalomeApp_StudyPropertiesDlg.h" +#include "SalomeApp_CheckFileDlg.h" + #include "SalomeApp_GLSelector.h" #include "SalomeApp_OBSelector.h" #include "SalomeApp_OCCSelector.h" #include "SalomeApp_VTKSelector.h" -#include "SalomeApp_EventFilter.h" #include "SalomeApp_SelectionMgr.h" -#include "SalomeApp_EventFilter.h" -#include "SalomeApp_WidgetContainer.h" -#include "SalomeApp_ModuleDlg.h" #include @@ -25,6 +34,7 @@ #include #include +#include #include #include @@ -34,16 +44,22 @@ #include +#include "STD_LoadStudiesDlg.h" + #include #include +#include #include +#include #include +#include #include #include +#include #include #include #include @@ -51,8 +67,10 @@ #include #include #include +#include #include +#include #include #include #include @@ -60,11 +78,20 @@ #include #include #include +#include +#include #include "SALOMEDS_StudyManager.hxx" +#include "SALOME_ListIteratorOfListIO.hxx" +#include "SALOME_ListIO.hxx" + +#include "ToolsGUI_CatalogGeneratorDlg.h" +#include "ToolsGUI_RegWidget.h" + #define OBJECT_BROWSER_WIDTH 300 +/*!Image for empty icon.*/ static const char* imageEmptyIcon[] = { "20 20 1 1", ". c None", @@ -89,25 +116,30 @@ static const char* imageEmptyIcon[] = { "....................", "...................."}; +/*!Create new instance of SalomeApp_Application.*/ extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication() { return new SalomeApp_Application(); } +SalomeApp_Preferences* SalomeApp_Application::_prefs_ = 0; + /* Class : SalomeApp_Application Description : Application containing SalomeApp module */ +/*!Constructor.*/ SalomeApp_Application::SalomeApp_Application() -: CAM_Application( false ) +: CAM_Application( false ), +myPrefs( 0 ) { STD_TabDesktop* desk = new STD_TabDesktop(); setDesktop( desk ); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) ); + QPixmap aLogo = aResMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false ); desktop()->setIcon( aLogo ); desktop()->setDockableMenuBar( true ); @@ -117,12 +149,43 @@ SalomeApp_Application::SalomeApp_Application() mySelMgr = new SalomeApp_SelectionMgr( this ); + myAccel = new SUIT_Accel( desktop() ); + myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, OCCViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanLeft, CTRL+Key_Left, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanRight, CTRL+Key_Right, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanUp, CTRL+Key_Up, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::PanDown, CTRL+Key_Down, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomIn, CTRL+Key_Plus, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomOut, CTRL+Key_Minus, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::ZoomFit, CTRL+Key_Asterisk, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateLeft, ALT+Key_Left, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateRight, ALT+Key_Right, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateUp, ALT+Key_Up, VTKViewer_Viewer::Type() ); + myAccel->setActionKey( SUIT_Accel::RotateDown, ALT+Key_Down, VTKViewer_Viewer::Type() ); + connect( desk, SIGNAL( closing( SUIT_Desktop*, QCloseEvent* ) ), this, SLOT( onDesktopClosing( SUIT_Desktop*, QCloseEvent* ) ) ); connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) ); } +/*!Destructor. + *\li Save window geometry. + *\li Save desktop geometry. + *\li Save resource maneger. + *\li Delete selection manager. + *\li Destroy event filter. + */ SalomeApp_Application::~SalomeApp_Application() { saveWindowsGeometry(); @@ -139,6 +202,7 @@ SalomeApp_Application::~SalomeApp_Application() SalomeApp_EventFilter::Destroy(); } +/*!Start application.*/ void SalomeApp_Application::start() { if ( desktop() ) @@ -158,11 +222,47 @@ void SalomeApp_Application::start() putInfo( "" ); } -QString SalomeApp_Application::applicationName() const -{ - return "SalomeApp"; +/*!Gets application name.*/ +QString SalomeApp_Application::applicationName() const +{ + return tr( "APP_NAME" ); +} + +/*!Gets application version.*/ +QString SalomeApp_Application::applicationVersion() const +{ + static QString _app_version; + + if ( _app_version.isEmpty() ) + { + QString path( ::getenv( "GUI_ROOT_DIR" ) ); + if ( !path.isEmpty() ) + path += QDir::separator(); + path += QString( "bin/salome/VERSION" ); + + QFile vf( path ); + if ( vf.open( IO_ReadOnly ) ) + { + QString line; + vf.readLine( line, 1024 ); + vf.close(); + + if ( !line.isEmpty() ) + { + while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) ) + line.remove( line.length() - 1, 1 ); + + int idx = line.findRev( ":" ); + if ( idx != -1 ) + _app_version = line.mid( idx + 1 ).stripWhiteSpace(); + } + } + } + + return _app_version; } +/*!Load module by \a name.*/ CAM_Module* SalomeApp_Application::loadModule( const QString& name ) { CAM_Module* mod = CAM_Application::loadModule( name ); @@ -175,6 +275,7 @@ CAM_Module* SalomeApp_Application::loadModule( const QString& name ) return mod; } +/*!Activate module by \a modName*/ bool SalomeApp_Application::activateModule( const QString& modName ) { QString actName; @@ -186,12 +287,16 @@ bool SalomeApp_Application::activateModule( const QString& modName ) if ( actName == modName ) return true; + putInfo( tr( "ACTIVATING_MODULE" ).arg( modName ) ); + saveWindowsGeometry(); bool status = CAM_Application::activateModule( modName ); updateModuleActions(); + putInfo( "" ); + if ( !status ) return false; @@ -201,11 +306,13 @@ bool SalomeApp_Application::activateModule( const QString& modName ) return true; } +/*!Gets selection manager.*/ SalomeApp_SelectionMgr* SalomeApp_Application::selectionMgr() const { return mySelMgr; } +/*!Create actions:*/ void SalomeApp_Application::createActions() { STD_Application::createActions(); @@ -213,13 +320,48 @@ void SalomeApp_Application::createActions() SUIT_Desktop* desk = desktop(); SUIT_ResourceMgr* resMgr = resourceMgr(); - // default icon for neutral point ('SALOME' module) - QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ) ); + //! Dump study + createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(), + tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ), + 0, desk, false, this, SLOT( onDumpStudy() ) ); + + //! Load script + createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(), + tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ), + 0, desk, false, this, SLOT( onLoadScript() ) ); + + //! Properties + createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(), + tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ), + 0, desk, false, this, SLOT( onProperties() ) ); + + //! Preferences + createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIconSet(), + tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ), + CTRL+Key_P, desk, false, this, SLOT( onPreferences() ) ); + + //! Catalog Generator + createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ), QIconSet(), + tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ), + 0, desk, false, this, SLOT( onCatalogGen() ) ); + + //! Registry Display + createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ), QIconSet(), + tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ), + 0, desk, false, this, SLOT( onRegDisplay() ) ); + + //! MRU + QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), desk ); + connect( mru, SIGNAL( activated( QString ) ), this, SLOT( onMRUActivated( QString ) ) ); + registerAction( MRUId, mru ); + + //! default icon for neutral point ('SALOME' module) + QPixmap defIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_DEFAULT_ICO" ), false ); if ( defIcon.isNull() ) defIcon = QPixmap( imageEmptyIcon ); - // default icon for any module - QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ) ); + //! default icon for any module + QPixmap modIcon = resMgr->loadPixmap( "SalomeApp", tr( "APP_MODULE_ICO" ), false ); if ( modIcon.isNull() ) modIcon = QPixmap( imageEmptyIcon ); @@ -257,7 +399,7 @@ void SalomeApp_Application::createActions() QString modName = moduleName( *it ); - QPixmap icon = resMgr->loadPixmap( modName, iconName ); + QPixmap icon = resMgr->loadPixmap( modName, iconName, false ); if ( icon.isNull() ) icon = modIcon; @@ -272,24 +414,52 @@ void SalomeApp_Application::createActions() SUIT_Tools::simplifySeparators( modTBar ); - // New window + //! New window int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 ); int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); createMenu( separator(), windowMenu, -1, 1 ); + QMap accelMap; + accelMap[NewGLViewId] = ALT+Key_G; + accelMap[NewPlot2dId] = ALT+Key_P; + accelMap[NewOCCViewId] = ALT+Key_O; + accelMap[NewVTKViewId] = ALT+Key_K; + for ( int id = NewGLViewId; id <= NewVTKViewId; id++ ) { - QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(), - tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), - tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), - 0, desk, false, this, SLOT( onNewWindow() ) ); + QAction* a = createAction( id, tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), QIconSet(), + tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), + tr( QString( "NEW_WINDOW_%1" ).arg( id - NewGLViewId ) ), + accelMap.contains( id ) ? accelMap[id] : 0, desk, false, this, SLOT( onNewWindow() ) ); createMenu( a, newWinMenu, -1 ); } - connect( modGroup, SIGNAL( selected( QAction* ) ), this, SLOT( onModuleActivation( QAction* ) ) ); + + int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 ); + + createMenu( DumpStudyId, fileMenu, 10, -1 ); + createMenu( separator(), fileMenu, -1, 15, -1 ); + createMenu( LoadScriptId, fileMenu, 10, -1 ); + createMenu( separator(), fileMenu, -1, 15, -1 ); + createMenu( PropertiesId, fileMenu, 10, -1 ); + createMenu( separator(), fileMenu, -1, 15, -1 ); + createMenu( PreferencesId, fileMenu, 15, -1 ); + createMenu( separator(), fileMenu, -1, 15, -1 ); + + int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 ); + createMenu( CatalogGenId, toolsMenu, 10, -1 ); + createMenu( RegDisplayId, toolsMenu, 10, -1 ); + createMenu( separator(), toolsMenu, -1, 15, -1 ); + + /* + createMenu( separator(), fileMenu, -1, 100, -1 ); + createMenu( MRUId, fileMenu, 100, -1 ); + createMenu( separator(), fileMenu, -1, 100, -1 ); + */ } +/*!On module activation action.*/ void SalomeApp_Application::onModuleActivation( QAction* a ) { if ( !a ) @@ -302,7 +472,9 @@ void SalomeApp_Application::onModuleActivation( QAction* a ) // Force user to create/open a study before module activation QMap iconMap; moduleIconNames( iconMap ); - QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ] ); + QPixmap icon = resourceMgr()->loadPixmap( moduleName( modName ), iconMap[ modName ], false ); + if ( icon.isNull() ) + icon = resourceMgr()->loadPixmap( "SalomeApp", tr( "APP_MODULE_BIG_ICO" ), false ); // default icon for any module bool cancelled = false; while ( !modName.isEmpty() && !activeStudy() && !cancelled ){ @@ -331,15 +503,17 @@ void SalomeApp_Application::onModuleActivation( QAction* a ) activateModule( modName ); } +/*!Default module activation.*/ QString SalomeApp_Application::defaultModule() const { QStringList aModuleNames; modules( aModuleNames, false ); // obtain a complete list of module names for the current configuration - // If there's the one and only module --> activate it automatically - // TODO: Possible improvement - default module can be taken from preferences + //! If there's the one and only module --> activate it automatically + //! TODO: Possible improvement - default module can be taken from preferences return aModuleNames.count() > 1 ? "" : ( aModuleNames.count() ? aModuleNames.first() : "" ); } +/*!On new window slot.*/ void SalomeApp_Application::onNewWindow() { const QObject* obj = sender(); @@ -369,8 +543,8 @@ void SalomeApp_Application::onNewWindow() } //======================================================================= -// name : onNewDoc -// Purpose : SLOT. Create new document +// name : onNewDoc +/*! Purpose : SLOT. Create new document*/ //======================================================================= void SalomeApp_Application::onNewDoc() { @@ -379,7 +553,7 @@ void SalomeApp_Application::onNewDoc() saveWindowsGeometry(); CAM_Application::onNewDoc(); - + if ( !study ) // new study will be create in THIS application { updateWindows(); @@ -389,7 +563,7 @@ void SalomeApp_Application::onNewDoc() //======================================================================= // name : onOpenDoc -// Purpose : SLOT. Open new document +/*! Purpose : SLOT. Open new document*/ //======================================================================= void SalomeApp_Application::onOpenDoc() { @@ -397,7 +571,7 @@ void SalomeApp_Application::onOpenDoc() saveWindowsGeometry(); CAM_Application::onOpenDoc(); - + if ( !study ) // new study will be create in THIS application { updateWindows(); @@ -405,6 +579,88 @@ void SalomeApp_Application::onOpenDoc() } } +/*! Purpose : SLOT. Open new document with \a aName.*/ +bool SalomeApp_Application::onOpenDoc( const QString& aName ) +{ + bool res = CAM_Application::onOpenDoc( aName ); + + QAction* a = action( MRUId ); + if ( a && a->inherits( "QtxMRUAction" ) ) + { + QtxMRUAction* mru = (QtxMRUAction*)a; + if ( res ) + mru->insert( aName ); + else + mru->remove( aName ); + } + return res; +} + +/*!SLOT. Load document.*/ +void SalomeApp_Application::onLoadDoc() +{ + QString name, studyname, ext; + + STD_LoadStudiesDlg aDlg( desktop(), TRUE); + + std::vector List = studyMgr()->GetOpenStudies(); + + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList aAppList = aSession->applications(); + SUIT_Application* aApp = 0; + + for (unsigned int ind = 0; ind < List.size(); ind++) { + studyname = List[ind].c_str(); + //Add to list only unloaded studies + bool isAlreadyOpen = false; + for ( QPtrListIterator it( aAppList ); it.current() && !isAlreadyOpen; ++it ) + { + aApp = it.current(); + if(!aApp || !aApp->activeStudy()) continue; + if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true; + } + + if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname ); + } + + int retVal = aDlg.exec(); + studyname = aDlg.ListComponent->currentText(); + + if (retVal == QDialog::Rejected) + return; + + if ( studyname.isNull() || studyname.isEmpty() ) + return; + + name = studyname; + name.replace( QRegExp(":"), "/" ); + + if(onLoadDoc(name)) { + updateWindows(); + updateViewManagers(); + updateObjectBrowser(true); + } +} + + +/*!SLOT. Load document with \a aName.*/ +bool SalomeApp_Application::onLoadDoc( const QString& aName ) +{ + bool res = CAM_Application::onLoadDoc( aName ); + + /*jfa tmp:QAction* a = action( MRUId ); + if ( a && a->inherits( "QtxMRUAction" ) ) + { + QtxMRUAction* mru = (QtxMRUAction*)a; + if ( res ) + mru->insert( aName ); + else + mru->remove( aName ); + }*/ + return res; +} + +/*!Private SLOT. Selection.*/ void SalomeApp_Application::onSelection() { onSelectionChanged(); @@ -413,37 +669,189 @@ void SalomeApp_Application::onSelection() ((SalomeApp_Module*)activeModule())->selectionChanged(); } +/*!SLOT. Copy objects to study maneger from selection maneger..*/ +void SalomeApp_Application::onCopy() +{ + SALOME_ListIO list; + SalomeApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(list); + + SalomeApp_Study* study = dynamic_cast(activeStudy()); + if(study == NULL) return; + + _PTR(Study) stdDS = study->studyDS(); + if(!stdDS) return; + + SALOME_ListIteratorOfListIO it( list ); + if(it.More()) + { + _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); + try { + studyMgr()->Copy(so); + onSelectionChanged(); + } + catch(...) { + } + } +} + +/*!SLOT. Paste objects to study maneger from selection manager.*/ +void SalomeApp_Application::onPaste() +{ + SALOME_ListIO list; + SalomeApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(list); + + SalomeApp_Study* study = dynamic_cast(activeStudy()); + if(study == NULL) return; + + _PTR(Study) stdDS = study->studyDS(); + if(!stdDS) return; + + SALOME_ListIteratorOfListIO it( list ); + if(it.More()) + { + _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); + try { + studyMgr()->Paste(so); + updateObjectBrowser( true ); + updateActions(); //SRN: BugID IPAL9377, case 3 + } + catch(...) { + } + } +} + +/*!Sets enable or disable some actions on selection changed.*/ void SalomeApp_Application::onSelectionChanged() { + SALOME_ListIO list; + SalomeApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(list); + + SalomeApp_Study* study = dynamic_cast(activeStudy()); + if(study == NULL) return; + + _PTR(Study) stdDS = study->studyDS(); + if(!stdDS) return; + + QAction* qaction; + + SALOME_ListIteratorOfListIO it( list ); + if(it.More() && list.Extent() == 1) + { + _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry()); + + qaction = action(EditCopyId); + if(studyMgr()->CanCopy(so) ) qaction->setEnabled(true); + else qaction->setEnabled(false); + + qaction = action(EditPasteId); + if( studyMgr()->CanPaste(so) ) qaction->setEnabled(true); + else qaction->setEnabled(false); + } + else { + qaction = action(EditCopyId); + qaction->setEnabled(false); + qaction = action(EditPasteId); + qaction->setEnabled(false); + } +} + +/*!Update object browser.*/ +void SalomeApp_Application::onRefresh() +{ + updateObjectBrowser( true ); +} + +/*!Delete references.*/ +void SalomeApp_Application::onDeleteReferences() +{ + SALOME_ListIO aList; + SalomeApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(aList); + + if (aList.Extent() < 1) return; + + SalomeApp_Study* aStudy = dynamic_cast(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() ); + if ( aSObject->ReferencedObject(anObj) ) + aStudyBuilder->RemoveReference(aSObject); + } + } + + updateObjectBrowser(); +} + +/*!Private SLOT. */ +void SalomeApp_Application::onOpenWith() +{ + QApplication::setOverrideCursor( Qt::waitCursor ); + SALOME_ListIO aList; + SalomeApp_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(); +} + +bool SalomeApp_Application::useStudy(const QString& theName) +{ + createEmptyStudy(); + SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); + bool res = false; + if (aStudy) + res = aStudy->loadDocument( theName ); + updateDesktopTitle(); + updateCommandsStatus(); + return res; } +/*!Set active study. + *\param study - SUIT_Study. + */ void SalomeApp_Application::setActiveStudy( SUIT_Study* study ) { CAM_Application::setActiveStudy( study ); - + activateWindows(); } //======================================================================= // name : createNewStudy -// Purpose : Create new study +/*! Purpose : Create new study*/ //======================================================================= -SUIT_Study* SalomeApp_Application::createNewStudy() -{ - SalomeApp_Study* aStudy = new SalomeApp_Study( this ); - +SUIT_Study* SalomeApp_Application::createNewStudy() +{ + SalomeApp_Study* aStudy = new SalomeApp_Study( this ); + // Set up processing of major study-related events connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) ); connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) ); connect( aStudy, SIGNAL( saved ( SUIT_Study* ) ), this, SLOT( onStudySaved ( SUIT_Study* ) ) ); connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) ); - return aStudy; + return aStudy; } //======================================================================= // name : createNewStudy -// Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu +/*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/ //======================================================================= void SalomeApp_Application::updateCommandsStatus() { @@ -455,29 +863,36 @@ void SalomeApp_Application::updateCommandsStatus() if ( a ) a->setEnabled( activeStudy() ); } + + // Dump study menu + QAction* a = action( DumpStudyId ); + if ( a ) + a->setEnabled( activeStudy() ); + + // Load script menu + a = action( LoadScriptId ); + if ( a ) + a->setEnabled( activeStudy() ); + + a = action( PropertiesId ); + if( a ) + a->setEnabled( activeStudy() ); + + a = action(EditCopyId); + a->setEnabled(false); + a = action(EditPasteId); + a->setEnabled(false); } //======================================================================= // name : onHelpAbout -// Purpose : SLOT. Display "About" message box +/*! Purpose : SLOT. Display "About" message box*/ //======================================================================= void SalomeApp_Application::onHelpAbout() { - QMessageBox aDlg( desktop(), "AboutDlg" ); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap aPixmap = aResMgr->loadPixmap( "SalomeApp", tr( "ABOUT_ICO" ) ); - - QFontMetrics m( aDlg.font() ); - QImage anImage = aPixmap.convertToImage(); - int w = m.height() * 5; - anImage = anImage.scale( w, w ); - aPixmap.convertFromImage( anImage ); - - aDlg.setCaption( tr( "ABOUT" ) ); - aDlg.setText( tr( "APP_NAME_LONG" ).arg( APP_VERSION ) ); - aDlg.setIconPixmap( aPixmap ); - aDlg.exec(); + SalomeApp_AboutDlg* dlg = new SalomeApp_AboutDlg( applicationName(), applicationVersion(), desktop() ); + dlg->exec(); + delete dlg; } QWidget* SalomeApp_Application::window( const int flag, const int studyId ) const @@ -499,6 +914,12 @@ QWidget* SalomeApp_Application::window( const int flag, const int studyId ) cons return wid; } +/*!Adds window to application. + *\param wid - QWidget + *\param flag - key wor window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int studyId ) { if ( !wid ) @@ -527,11 +948,23 @@ void SalomeApp_Application::addWindow( QWidget* wid, const int flag, const int s myWindows[flag]->setName( QString( "dock_window_%1" ).arg( flag ) ); } + QFont f; + if( wid->inherits( "PythonConsole" ) ) + f = ( ( PythonConsole* )wid )->font(); + else + f = wid->font(); + myWindows[flag]->insert( sId, wid ); + wid->setFont( f ); setWindowShown( flag, !myWindows[flag]->isEmpty() ); } +/*!Remove window from application. + *\param flag - key wor window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ void SalomeApp_Application::removeWindow( const int flag, const int studyId ) { if ( !myWindows.contains( flag ) ) @@ -546,11 +979,18 @@ void SalomeApp_Application::removeWindow( const int flag, const int studyId ) sId = activeStudy()->id(); } + QWidget* wid = myWindows[flag]->widget( sId ); myWindows[flag]->remove( sId ); + delete wid; setWindowShown( flag, !myWindows[flag]->isEmpty() ); } +/*!Gets window. + *\param flag - key wor window + *\param studyId - study id + * Flag used how identificator of window in windows list. + */ QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId ) { QWidget* wid = window( flag, studyId ); @@ -560,6 +1000,7 @@ QWidget* SalomeApp_Application::getWindow( const int flag, const int studyId ) return wid; } +/*!Check is window visible?(with identificator \a type)*/ bool SalomeApp_Application::isWindowVisible( const int type ) const { bool res = false; @@ -571,6 +1012,10 @@ bool SalomeApp_Application::isWindowVisible( const int type ) const return res; } +/*!Sets window show or hide. + *\param type - window identificator. + *\param on - true/false (window show/hide) + */ void SalomeApp_Application::setWindowShown( const int type, const bool on ) { if ( !desktop() || !myWindows.contains( type ) ) @@ -590,6 +1035,7 @@ OB_Browser* SalomeApp_Application::objectBrowser() return ob; } +/*!Gets "LogWindow".*/ LogWindow* SalomeApp_Application::logWindow() { LogWindow* lw = 0; @@ -599,24 +1045,49 @@ LogWindow* SalomeApp_Application::logWindow() return lw; } +/*!Get "PythonConsole"*/ +PythonConsole* SalomeApp_Application::pythonConsole() +{ + PythonConsole* console = 0; + QWidget* wid = getWindow( WT_PyConsole ); + if ( wid->inherits( "PythonConsole" ) ) + console = (PythonConsole*)wid; + return console; +} + +/*!Gets preferences.*/ +SalomeApp_Preferences* SalomeApp_Application::preferences() const +{ + return preferences( false ); +} + +/*!Gets view manager*/ SUIT_ViewManager* SalomeApp_Application::getViewManager( const QString& vmType, const bool create ) { SUIT_ViewManager* aVM = viewManager( vmType ); SUIT_ViewManager* anActiveVM = CAM_Application::activeViewManager(); + if ( anActiveVM && anActiveVM->getType() == vmType ) aVM = anActiveVM; - else if ( aVM ) + + if ( aVM && create ) { if ( !aVM->getActiveView() ) aVM->createView(); + else + aVM->getActiveView()->setFocus(); } else if ( create ) aVM = createViewManager( vmType ); + return aVM; } +/*!Create view manager.*/ SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmType ) { + SUIT_ResourceMgr* resMgr = resourceMgr(); + SUIT_ViewManager* viewMgr = 0; if ( vmType == GLViewer_Viewer::Type() ) { @@ -624,16 +1095,30 @@ SUIT_ViewManager* SalomeApp_Application::createViewManager( const QString& vmTyp new SalomeApp_GLSelector( (GLViewer_Viewer2d*)viewMgr->getViewModel(), mySelMgr ); } else if ( vmType == Plot2d_Viewer::Type() ) + { viewMgr = new Plot2d_ViewManager( activeStudy(), desktop() ); + viewMgr->setViewModel( new SPlot2d_Viewer() );// custom view model, which extends SALOME_View interface + } else if ( vmType == OCCViewer_Viewer::Type() ) { viewMgr = new OCCViewer_ViewManager( activeStudy(), desktop() ); - viewMgr->setViewModel( new SOCC_Viewer() );// custom view model, which extends SALOME_View interface + SOCC_Viewer* vm = new SOCC_Viewer(); + vm->setBackgroundColor( resMgr->colorValue( "OCCViewer", "background", vm->backgroundColor() ) ); + vm->setTrihedronSize( resMgr->integerValue( "OCCViewer", "trihedron_size", vm->trihedronSize() ) ); + int u( 1 ), v( 1 ); + vm->isos( u, v ); + u = resMgr->integerValue( "OCCViewer", "iso_number_u", u ); + v = resMgr->integerValue( "OCCViewer", "iso_number_v", v ); + vm->setIsos( u, v ); + viewMgr->setViewModel( vm );// custom view model, which extends SALOME_View interface new SalomeApp_OCCSelector( (OCCViewer_Viewer*)viewMgr->getViewModel(), mySelMgr ); } else if ( vmType == SVTK_Viewer::Type() ) { viewMgr = new SVTK_ViewManager( activeStudy(), desktop() ); + SVTK_Viewer* vm = (SVTK_Viewer*)viewMgr->getViewModel(); + vm->setBackgroundColor( resMgr->colorValue( "VTKViewer", "background", vm->backgroundColor() ) ); + vm->setTrihedronSize( resMgr->integerValue( "VTKViewer", "trihedron_size", vm->trihedronSize() ) ); new SalomeApp_VTKSelector((SVTK_Viewer*)viewMgr->getViewModel(),mySelMgr); } @@ -657,6 +1142,7 @@ void SalomeApp_Application::onCloseView( SUIT_ViewManager* theVM ) removeViewManager( theVM ); } +/*!Private SLOT. On study created.*/ void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy ) { SUIT_DataObject* aRoot = 0; @@ -669,8 +1155,11 @@ void SalomeApp_Application::onStudyCreated( SUIT_Study* theStudy ) objectBrowser()->setRootObject( aRoot ); activateModule( defaultModule() ); + + activateWindows(); } +/*!Private SLOT. On study opened.*/ void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy ) { SUIT_DataObject* aRoot = 0; @@ -683,10 +1172,10 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* theStudy ) objectBrowser()->setRootObject( aRoot ); } - activateWindows(); - activateModule( defaultModule() ); + activateWindows(); + emit studyOpened(); } @@ -695,22 +1184,119 @@ void SalomeApp_Application::onStudySaved( SUIT_Study* ) emit studySaved(); } +/*!Private SLOT. On study closed.*/ void SalomeApp_Application::onStudyClosed( SUIT_Study* ) { emit studyClosed(); activateModule( "" ); - if ( objectBrowser() != 0 ) - objectBrowser()->setRootObject( 0 ); saveWindowsGeometry(); } +/*!Private SLOT. On dump study.*/ +void SalomeApp_Application::onDumpStudy( ) +{ + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( !appStudy ) return; + _PTR(Study) aStudy = appStudy->studyDS(); + + QStringList aFilters; + aFilters.append( tr( "PYTHON_FILES_FILTER" ) ); + + SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true); + fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) ); + fd->setFilters( aFilters ); + fd->SetChecked(true); + fd->exec(); + QString aFileName = fd->selectedFile(); + bool toPublish = fd->IsChecked(); + delete fd; + + if(!aFileName.isEmpty()) { + QFileInfo aFileInfo(aFileName); + aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish ); + } +} + +/*!Private SLOT. On load script.*/ +void SalomeApp_Application::onLoadScript( ) +{ + SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); + if ( !appStudy ) return; + _PTR(Study) aStudy = appStudy->studyDS(); + + if ( aStudy->GetProperties()->IsLocked() ) { + SUIT_MessageBox::warn1 ( desktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED"), + QObject::tr("BUT_OK") ); + return; + } + + QStringList filtersList; + filtersList.append(tr("PYTHON_FILES_FILTER")); + filtersList.append(tr("ALL_FILES_FILTER")); + + QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true ); + + if ( !aFile.isEmpty() ) + { + QString command = QString("execfile(\"%1\")").arg(aFile); + + PythonConsole* pyConsole = pythonConsole(); + + if ( pyConsole ) + pyConsole->exec( command ); + } +} + +/*!Private SLOT. On preferences.*/ +void SalomeApp_Application::onPreferences() +{ + QApplication::setOverrideCursor( Qt::waitCursor ); + + SalomeApp_PreferencesDlg* prefDlg = new SalomeApp_PreferencesDlg( preferences( true ), desktop()); + + QApplication::restoreOverrideCursor(); + + if ( !prefDlg ) + return; + + prefDlg->exec(); + + delete prefDlg; +} + +/*!Private SLOT. On open document with name \a aName.*/ +void SalomeApp_Application::onMRUActivated( QString aName ) +{ + onOpenDoc( aName ); +} + +/*!Private SLOT. On preferences changed.*/ +void SalomeApp_Application::onPreferenceChanged( QString& modName, QString& section, QString& param ) +{ + SalomeApp_Module* sMod = 0; + CAM_Module* mod = module( modName ); + if ( mod && mod->inherits( "SalomeApp_Module" ) ) + sMod = (SalomeApp_Module*)mod; + + if ( sMod ) + sMod->preferencesChanged( section, param ); + else + preferencesChanged( section, param ); +} + +/*!Gets file filter. + *\retval QString "(*.hdf)" + */ QString SalomeApp_Application::getFileFilter() const { return "(*.hdf)"; } +/*!Remove all windows from study.*/ void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s ) { CAM_Application::beforeCloseDoc( s ); @@ -719,29 +1305,38 @@ void SalomeApp_Application::beforeCloseDoc( SUIT_Study* s ) removeWindow( itr.key(), s->id() ); } -void SalomeApp_Application::afterCloseDoc() -{ - updateWindows(); - - CAM_Application::afterCloseDoc(); -} - +/*!Update actions.*/ void SalomeApp_Application::updateActions() { updateCommandsStatus(); } +/*!Create window.*/ QWidget* SalomeApp_Application::createWindow( const int flag ) { QWidget* wid = 0; + SUIT_ResourceMgr* resMgr = resourceMgr(); + if ( flag == WT_ObjectBrowser ) { OB_Browser* ob = new OB_Browser( desktop() ); - + ob->setAutoUpdate( true ); + ob->setAutoOpenLevel( 1 ); ob->setCaption( tr( "OBJECT_BROWSER" ) ); ob->resize( OBJECT_BROWSER_WIDTH, ob->height() ); - ob->setAutoUpdate( true ); + ob->setFilter( new SalomeApp_OBFilter( selectionMgr() ) ); + + ob->setNameTitle( tr( "OBJ_BROWSER_NAME" ) ); + + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); + for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; 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 ) ); + } + ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); // Create OBSelector new SalomeApp_OBSelector( ob, mySelMgr ); @@ -754,6 +1349,7 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) { PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() ); pyCons->setCaption( tr( "PYTHON_CONSOLE" ) ); + pyCons->setFont( resMgr->fontValue( "PyConsole", "font" ) ); wid = pyCons; // pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); @@ -766,20 +1362,354 @@ QWidget* SalomeApp_Application::createWindow( const int flag ) logWin->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) ); } - + return wid; } +/*!Default windows(Object Browser, Python Console). + * Adds to map \a aMap. + */ void SalomeApp_Application::defaultWindows( QMap& aMap ) const { aMap.insert( WT_ObjectBrowser, Qt::DockLeft ); aMap.insert( WT_PyConsole, Qt::DockBottom ); + // aMap.insert( WT_LogWindow, Qt::DockBottom ); } +/*!Default view manager.*/ void SalomeApp_Application::defaultViewManagers( QStringList& ) const { + /*!Do nothing.*/ +} + +/*!Gets preferences. + * Create preferences, if \a crt = true. + */ +SalomeApp_Preferences* SalomeApp_Application::preferences( const bool crt ) const +{ + if ( myPrefs ) + return myPrefs; + + SalomeApp_Application* that = (SalomeApp_Application*)this; + + if ( !_prefs_ && crt ) + { + _prefs_ = new SalomeApp_Preferences( resourceMgr() ); + that->createPreferences( _prefs_ ); + } + + that->myPrefs = _prefs_; + + QPtrList appList = SUIT_Session::session()->applications(); + for ( QPtrListIterator appIt ( appList ); appIt.current(); ++appIt ) + { + if ( !appIt.current()->inherits( "SalomeApp_Application" ) ) + continue; + + SalomeApp_Application* app = (SalomeApp_Application*)appIt.current(); + + QStringList modNameList; + app->modules( modNameList, false ); + for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it ) + { + int id = _prefs_->addPreference( *it ); + _prefs_->setItemProperty( id, "info", tr( "PREFERENCES_NOT_LOADED" ).arg( *it ) ); + } + + ModuleList modList; + app->modules( modList ); + for ( ModuleListIterator itr( modList ); itr.current(); ++itr ) + { + SalomeApp_Module* mod = 0; + if ( itr.current()->inherits( "SalomeApp_Module" ) ) + mod = (SalomeApp_Module*)itr.current(); + + if ( mod && !_prefs_->hasModule( mod->moduleName() ) ) + { + int modCat = _prefs_->addPreference( mod->moduleName() ); + _prefs_->setItemProperty( modCat, "info", QString::null ); + mod->createPreferences(); + } + } + } + + connect( myPrefs, SIGNAL( preferenceChanged( QString&, QString&, QString& ) ), + this, SLOT( onPreferenceChanged( QString&, QString&, QString& ) ) ); + + return myPrefs; +} + +/*!Add new module to application.*/ +void SalomeApp_Application::moduleAdded( CAM_Module* mod ) +{ + CAM_Application::moduleAdded( mod ); + + SalomeApp_Module* salomeMod = 0; + if ( mod && mod->inherits( "SalomeApp_Module" ) ) + salomeMod = (SalomeApp_Module*)mod; + + if ( myPrefs && salomeMod && !myPrefs->hasModule( salomeMod->moduleName() ) ) + { + int modCat = myPrefs->addPreference( mod->moduleName() ); + myPrefs->setItemProperty( modCat, "info", QString::null ); + salomeMod->createPreferences(); + } +} + +/*!Create preferences.*/ +void SalomeApp_Application::createPreferences( SalomeApp_Preferences* pref ) +{ + if ( !pref ) + return; + + int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) ); + + int genTab = pref->addPreference( tr( "PREF_TAB_GENERAL" ), salomeCat ); + int studyGroup = pref->addPreference( tr( "PREF_GROUP_STUDY" ), genTab ); + pref->setItemProperty( studyGroup, "columns", 1 ); + + pref->addPreference( tr( "PREF_MULTI_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "multi_file" ); + pref->addPreference( tr( "PREF_ASCII_FILE" ), studyGroup, SalomeApp_Preferences::Bool, "Study", "ascii_file" ); + int undoPref = pref->addPreference( tr( "PREF_UNDO_LEVEL" ), studyGroup, SalomeApp_Preferences::IntSpin, "Study", "undo_level" ); + pref->setItemProperty( undoPref, "min", 1 ); + pref->setItemProperty( undoPref, "max", 100 ); + + int extgroup = pref->addPreference( tr( "PREF_GROUP_EXT_BROWSER" ), genTab ); + pref->setItemProperty( extgroup, "columns", 1 ); + int apppref = pref->addPreference( tr( "PREF_APP" ), extgroup, SalomeApp_Preferences::File, "ExternalBrowser", "application" ); + pref->setItemProperty( apppref, "existing", true ); + pref->setItemProperty( apppref, "flags", QFileInfo::ExeUser ); + + pref->addPreference( tr( "PREF_PARAM" ), extgroup, SalomeApp_Preferences::String, "ExternalBrowser", "parameters" ); + + int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab ); + pref->setItemProperty( pythonConsoleGroup, "columns", 1 ); + pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, SalomeApp_Preferences::Font, "PyConsole", "font" ); + + + + int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat ); + int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab ); + for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ ) + { + pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols, + SalomeApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) ); + } + pref->setItemProperty( defCols, "columns", 1 ); + + int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab ); + pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, SalomeApp_Preferences::Bool, "ObjectBrowser", "auto_size" ); + + int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat ); + + int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab ); + + int vtkGroup = pref->addPreference( tr( "PREF_GROUP_VTKVIEWER" ), viewTab ); + + int plot2dGroup = pref->addPreference( tr( "PREF_GROUP_PLOT2DVIEWER" ), viewTab ); + + pref->setItemProperty( occGroup, "columns", 1 ); + pref->setItemProperty( vtkGroup, "columns", 1 ); + pref->setItemProperty( plot2dGroup, "columns", 1 ); + + int occTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), occGroup, + SalomeApp_Preferences::IntSpin, "OCCViewer", "trihedron_size" ); + pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup, + SalomeApp_Preferences::Color, "OCCViewer", "background" ); + + pref->setItemProperty( occTS, "min", 1 ); + pref->setItemProperty( occTS, "max", 150 ); + + int isoU = pref->addPreference( tr( "PREF_ISOS_U" ), occGroup, + SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_u" ); + int isoV = pref->addPreference( tr( "PREF_ISOS_V" ), occGroup, + SalomeApp_Preferences::IntSpin, "OCCViewer", "iso_number_v" ); + + pref->setItemProperty( isoU, "min", 0 ); + pref->setItemProperty( isoU, "max", 100000 ); + + pref->setItemProperty( isoV, "min", 0 ); + pref->setItemProperty( isoV, "max", 100000 ); + + int vtkTS = pref->addPreference( tr( "PREF_TRIHEDRON_SIZE" ), vtkGroup, + SalomeApp_Preferences::IntSpin, "VTKViewer", "trihedron_size" ); + pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), vtkGroup, + SalomeApp_Preferences::Color, "VTKViewer", "background" ); + + pref->setItemProperty( vtkTS, "min", 1 ); + pref->setItemProperty( vtkTS, "max", 150 ); + + pref->addPreference( tr( "PREF_SHOW_LEGEND" ), plot2dGroup, + SalomeApp_Preferences::Bool, "Plot2d", "ShowLegend" ); + + int legendPosition = pref->addPreference( tr( "PREF_LEGEND_POSITION" ), plot2dGroup, + SalomeApp_Preferences::Selector, "Plot2d", "LegendPos" ); + QStringList aLegendPosList; + aLegendPosList.append( tr("PREF_LEFT") ); + aLegendPosList.append( tr("PREF_RIGHT") ); + aLegendPosList.append( tr("PREF_TOP") ); + aLegendPosList.append( tr("PREF_BOTTOM") ); + + QValueList anIndexesList; + anIndexesList.append(0); + anIndexesList.append(1); + anIndexesList.append(2); + anIndexesList.append(3); + + pref->setItemProperty( legendPosition, "strings", aLegendPosList ); + pref->setItemProperty( legendPosition, "indexes", anIndexesList ); + + int curveType = pref->addPreference( tr( "PREF_CURVE_TYPE" ), plot2dGroup, + SalomeApp_Preferences::Selector, "Plot2d", "CurveType" ); + QStringList aCurveTypesList; + aCurveTypesList.append( tr("PREF_POINTS") ); + aCurveTypesList.append( tr("PREF_LINES") ); + aCurveTypesList.append( tr("PREF_SPLINE") ); + + anIndexesList.clear(); + anIndexesList.append(0); + anIndexesList.append(1); + anIndexesList.append(2); + + pref->setItemProperty( curveType, "strings", aCurveTypesList ); + pref->setItemProperty( curveType, "indexes", anIndexesList ); + + int markerSize = pref->addPreference( tr( "PREF_MARKER_SIZE" ), plot2dGroup, + SalomeApp_Preferences::IntSpin, "Plot2d", "MarkerSize" ); + + pref->setItemProperty( markerSize, "min", 0 ); + pref->setItemProperty( markerSize, "max", 100 ); + + QStringList aScaleModesList; + aScaleModesList.append( tr("PREF_LINEAR") ); + aScaleModesList.append( tr("PREF_LOGARITHMIC") ); + + anIndexesList.clear(); + anIndexesList.append(0); + anIndexesList.append(1); + + int horScale = pref->addPreference( tr( "PREF_HOR_AXIS_SCALE" ), plot2dGroup, + SalomeApp_Preferences::Selector, "Plot2d", "HorScaleMode" ); + + pref->setItemProperty( horScale, "strings", aScaleModesList ); + pref->setItemProperty( horScale, "indexes", anIndexesList ); + + int verScale = pref->addPreference( tr( "PREF_VERT_AXIS_SCALE" ), plot2dGroup, + SalomeApp_Preferences::Selector, "Plot2d", "VerScaleMode" ); + + pref->setItemProperty( verScale, "strings", aScaleModesList ); + pref->setItemProperty( verScale, "indexes", anIndexesList ); + + pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), plot2dGroup, + SalomeApp_Preferences::Color, "Plot2d", "Background" ); + + int dirTab = pref->addPreference( tr( "PREF_TAB_DIRECTORIES" ), salomeCat ); + int dirGroup = pref->addPreference( tr( "PREF_GROUP_DIRECTORIES" ), dirTab ); + pref->setItemProperty( dirGroup, "columns", 1 ); + pref->addPreference( tr( "" ), dirGroup, + SalomeApp_Preferences::DirList, "FileDlg", "QuickDirList" ); +} + +void SalomeApp_Application::preferencesChanged( const QString& sec, const QString& param ) +{ + SUIT_ResourceMgr* resMgr = resourceMgr(); + if ( !resMgr ) + return; + + if ( sec == QString( "OCCViewer" ) && param == QString( "trihedron_size" ) ) + { + int sz = resMgr->integerValue( sec, param, -1 ); + QPtrList lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + for ( QPtrListIterator it( lst ); it.current() && sz >= 0; ++it ) + { + SUIT_ViewModel* vm = it.current()->getViewModel(); + if ( !vm || !vm->inherits( "OCCViewer_Viewer" ) ) + continue; + + OCCViewer_Viewer* occVM = (OCCViewer_Viewer*)vm; + occVM->setTrihedronSize( sz ); + occVM->getAISContext()->UpdateCurrentViewer(); + } + } + + if ( sec == QString( "VTKViewer" ) && param == QString( "trihedron_size" ) ) + { + int sz = resMgr->integerValue( sec, param, -1 ); + QPtrList lst; + viewManagers( SVTK_Viewer::Type(), lst ); + for ( QPtrListIterator it( lst ); it.current() && sz >= 0; ++it ) + { + SUIT_ViewModel* vm = it.current()->getViewModel(); + if ( !vm || !vm->inherits( "SVTK_Viewer" ) ) + continue; + + SVTK_Viewer* vtkVM = (SVTK_Viewer*)vm; + vtkVM->setTrihedronSize( sz ); + vtkVM->Repaint(); + } + } + + if ( sec == QString( "OCCViewer" ) && ( param == QString( "iso_number_u" ) || param == QString( "iso_number_v" ) ) ) + { + QPtrList lst; + viewManagers( OCCViewer_Viewer::Type(), lst ); + int u = resMgr->integerValue( sec, "iso_number_u" ); + int v = resMgr->integerValue( sec, "iso_number_v" ); + for ( QPtrListIterator it( lst ); it.current(); ++it ) + ((OCCViewer_Viewer*)it.current())->setIsos( u, v ); + } + + if( sec=="ObjectBrowser" ) + { + if( param=="auto_size" ) + { + OB_Browser* ob = objectBrowser(); + if( !ob ) + return; + + bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false ); + ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual ); + + updateObjectBrowser( false ); + } + } + + if( sec=="PyConsole" ) + { + if( param=="font" ) + if( pythonConsole() ) + pythonConsole()->setFont( resMgr->fontValue( "PyConsole", "font" ) ); + } +} + +/*!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().stripWhiteSpace(), false ); + if ( !sName.isEmpty() ) { + SalomeApp_Study* study = dynamic_cast(activeStudy()); + _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()->setCaption( aTitle ); } +/*!Update windows after close document.*/ void SalomeApp_Application::afterCloseDoc() { updateWindows(); @@ -787,32 +1717,38 @@ void SalomeApp_Application::afterCloseDoc() CAM_Application::afterCloseDoc(); } +/*!Gets CORBA::ORB_var*/ CORBA::ORB_var SalomeApp_Application::orb() { ORB_INIT& init = *SINGLETON_::Instance(); - CORBA::ORB_var& orb = init( qApp->argc(), qApp->argv() ); - - return orb; + static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() ); + return _orb; } +/*!Create and return SALOMEDS_StudyManager.*/ SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr() { - static SALOMEDSClient_StudyManager* aStudyManager = NULL; - - if(!aStudyManager) { - aStudyManager = new SALOMEDS_StudyManager(); - } - return aStudyManager; + static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager(); + return _sm; } +/*!Create and return SALOME_NamingService.*/ SALOME_NamingService* SalomeApp_Application::namingService() { - return new SALOME_NamingService( orb() ); + static SALOME_NamingService* _ns = new SALOME_NamingService( orb() ); + return _ns; +} + +/*!Create and return SALOME_LifeCycleCORBA.*/ +SALOME_LifeCycleCORBA* SalomeApp_Application::lcc() +{ + static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() ); + return _lcc; } QString SalomeApp_Application::defaultEngineIOR() { - // Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence) + /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence) QString anIOR( "" ); CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" ); if ( !CORBA::is_nil( anEngine ) ) @@ -820,6 +1756,7 @@ QString SalomeApp_Application::defaultEngineIOR() return anIOR; } +/*!Adds icon names for modules.*/ void SalomeApp_Application::moduleIconNames( QMap& iconMap ) const { iconMap.clear(); @@ -847,6 +1784,7 @@ void SalomeApp_Application::moduleIconNames( QMap& iconMap ) c } } +/*!Update module action.*/ void SalomeApp_Application::updateModuleActions() { QString modName; @@ -857,6 +1795,9 @@ void SalomeApp_Application::updateModuleActions() myActions[modName]->setOn( true ); } +/*!Gets current windows. + *\param winMap - output current windows map. + */ void SalomeApp_Application::currentWindows( QMap& winMap ) const { winMap.clear(); @@ -869,6 +1810,9 @@ void SalomeApp_Application::currentWindows( QMap& winMap ) const defaultWindows( winMap ); } +/*!Gets current view managers. + *\param lst - output current view managers list. + */ void SalomeApp_Application::currentViewManagers( QStringList& lst ) const { lst.clear(); @@ -881,6 +1825,7 @@ void SalomeApp_Application::currentViewManagers( QStringList& lst ) const defaultViewManagers( lst ); } +/*!Update windows.*/ void SalomeApp_Application::updateWindows() { QMap winMap; @@ -895,6 +1840,7 @@ void SalomeApp_Application::updateWindows() setWindowShown( itr.key(), !itr.data()->isEmpty() && winMap.contains( itr.key() ) ); } +/*!Update view managers.*/ void SalomeApp_Application::updateViewManagers() { QStringList lst; @@ -904,6 +1850,7 @@ void SalomeApp_Application::updateViewManagers() getViewManager( *it, true ); } +/*!Load windows geometry.*/ void SalomeApp_Application::loadWindowsGeometry() { QtxDockAction* dockMgr = 0; @@ -918,16 +1865,16 @@ void SalomeApp_Application::loadWindowsGeometry() QString modName; if ( activeModule() ) modName = moduleLibrary( activeModule()->moduleName(), false ); - + QString section = QString( "windows_geometry" ); if ( !modName.isEmpty() ) section += QString( "." ) + modName; - dockMgr->loadGeometry( resourceMgr(), section, false ); dockMgr->restoreGeometry(); } +/*!Save windows geometry.*/ void SalomeApp_Application::saveWindowsGeometry() { QtxDockAction* dockMgr = 0; @@ -942,7 +1889,7 @@ void SalomeApp_Application::saveWindowsGeometry() QString modName; if ( activeModule() ) modName = moduleLibrary( activeModule()->moduleName(), false ); - + QString section = QString( "windows_geometry" ); if ( !modName.isEmpty() ) section += QString( "." ) + modName; @@ -951,6 +1898,7 @@ void SalomeApp_Application::saveWindowsGeometry() dockMgr->saveGeometry( resourceMgr(), section, false ); } +/*!Activate windows.*/ void SalomeApp_Application::activateWindows() { if ( activeStudy() ) @@ -959,3 +1907,203 @@ void SalomeApp_Application::activateWindows() itr.data()->activate( activeStudy()->id() ); } } + +/*!Private SLOT. On preferences.*/ +void SalomeApp_Application::onProperties() +{ + SalomeApp_Study* study = dynamic_cast( 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(); +} + +/*!*/ +QString SalomeApp_Application::getFileName( bool open, const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ) +{ + if ( !parent ) + parent = desktop(); + QStringList fls = QStringList::split( ";;", filters, false ); + return SUIT_FileDlg::getFileName( parent, initial, fls, caption, open, true ); +} + +/*!*/ +QString SalomeApp_Application::getDirectory( const QString& initial, const QString& caption, QWidget* parent ) +{ + if ( !parent ) + parent = desktop(); + return SUIT_FileDlg::getExistingDirectory( parent, initial, caption, true ); +} + +/*!*/ +QStringList SalomeApp_Application::getOpenFileNames( const QString& initial, const QString& filters, + const QString& caption, QWidget* parent ) +{ + if ( !parent ) + parent = desktop(); + QStringList fls = QStringList::split( ";;", filters, false ); + return SUIT_FileDlg::getOpenFileNames( parent, initial, fls, caption, true ); +} + +/*!*/ +void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title ) +{ + CAM_Application::contextMenuPopup( type, thePopup, title ); + + OB_Browser* ob = objectBrowser(); + if ( !ob || type != ob->popupClientType() ) + return; + + thePopup->insertSeparator(); + thePopup->insertItem( tr( "MEN_REFRESH" ), this, SLOT( onRefresh() ) ); + + // Get selected objects + SALOME_ListIO aList; + SalomeApp_SelectionMgr* mgr = selectionMgr(); + mgr->selectedObjects(aList); + + // "Delete reference" item should appear only for invalid references + + // Check if selected objects is invalid references + bool isInvalidRefs = true; + + if ( aList.Extent() < 1 ) + isInvalidRefs = false; + + if ( isInvalidRefs ) + { + SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); + _PTR(Study) aStudyDS = aStudy->studyDS(); + _PTR(SObject) anObj; + + for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() ) + { + if ( it.Value()->hasEntry() ) + { + _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() ); + if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() ) + isInvalidRefs = false; + } + } + } + + // Add "Delete refrence" item to popup + if ( isInvalidRefs ) + { + thePopup->insertSeparator(); + thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) ); + return; + } + + // "Activate module" item should appear only if it's necessary + if (aList.Extent() != 1) + return; + Handle(SALOME_InteractiveObject) aIObj = aList.First(); + QString aModuleName(aIObj->getComponentDataType()); + QString aModuleTitle = moduleTitle(aModuleName); + CAM_Module* currentModule = activeModule(); + if (currentModule && currentModule->moduleName() == aModuleTitle) + return; + thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) ); + +} + +/*!Update obect browser*/ +void SalomeApp_Application::updateObjectBrowser( const bool updateModels ) +{ + // update existing data models (already loaded SComponents) + if ( updateModels ) + { + for ( ModuleListIterator it = modules(); it.current(); ++it ) + { + CAM_DataModel* camDM = it.current()->dataModel(); + if ( camDM && camDM->inherits( "SalomeApp_DataModel" ) ) + ((SalomeApp_DataModel*)camDM)->update(); + } + } + // update "non-existing" (not loaded yet) data models + SalomeApp_Study* study = dynamic_cast(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() ); + + if ( aComponent->ComponentDataType() == "Interface Applicative" ) + continue; // skip the magic "Interface Applicative" component + + SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true ); + } + } + } + + if ( objectBrowser() ) + { + objectBrowser()->updateGeometry(); + objectBrowser()->updateTree(); + } +} + +/*!Protected SLOT.On desktop activated.*/ +void SalomeApp_Application::onDesktopActivated() +{ + CAM_Application::onDesktopActivated(); + SalomeApp_Module* aModule = dynamic_cast(activeModule()); + if(aModule) + aModule->studyActivated(); +} + +/*!Create empty study.*/ +void SalomeApp_Application::createEmptyStudy() +{ + CAM_Application::createEmptyStudy(); + if ( objectBrowser() ) + objectBrowser()->updateTree(); +} + +/*!Activate module \a mod.*/ +bool SalomeApp_Application::activateModule( CAM_Module* mod ) +{ + bool res = CAM_Application::activateModule( mod ); + if ( objectBrowser() ) + objectBrowser()->updateTree(); + return res; +} + +/*!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(), "Registry" ); + regWnd->show(); + regWnd->raise(); + regWnd->setActiveWindow(); +} + +/*!return keyborad accelerators manager object */ +SUIT_Accel* SalomeApp_Application::accel() const +{ + return myAccel; +}