+ w->setWindowTitle( name );
+}
+
+/*!
+ Closes active window of desktop
+*/
+void LightApp_Application::onCloseWindow()
+{
+ if( !desktop() )
+ return;
+
+ QWidget* w = desktop()->activeWindow();
+ if( !w )
+ return;
+
+ w->close();
+}
+
+/*!
+ Closes all windows of desktop
+*/
+void LightApp_Application::onCloseAllWindow()
+{
+ STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
+ if( !desk )
+ return;
+
+ QList<SUIT_ViewWindow*> wndList = desk->windows();
+ SUIT_ViewWindow* wnd;
+ foreach( wnd, wndList )
+ {
+ if ( wnd )
+ wnd->close();
+ }
+}
+
+/*!
+ Groups all windows of desktop
+*/
+void LightApp_Application::onGroupAllWindow()
+{
+ STD_TabDesktop* desk = dynamic_cast<STD_TabDesktop*>( desktop() );
+ if( !desk )
+ return;
+
+ QtxWorkstack* wgStack = desk->workstack();
+ if ( wgStack )
+ wgStack->stack();
+}
+
+/*!
+ \return if the library of module exists
+ \param moduleTitle - title of module
+*/
+bool LightApp_Application::isLibExists( const QString& moduleTitle ) const
+{
+ if( moduleTitle.isEmpty() )
+ return false;
+
+ QString lib = moduleLibrary( moduleTitle );
+
+ //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32
+ bool isPythonModule = lib.contains("SalomePyQtGUI");
+ bool isPythonLightModule = lib.contains("SalomePyQtGUILight");
+
+ QStringList paths;
+#ifdef WIN32
+ paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
+#else
+ paths = QString(::getenv( "LD_LIBRARY_PATH" )).split( ":", QString::SkipEmptyParts );
+#endif
+
+ bool isLibFound = false;
+ QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
+ for( ; anIt!=aLast; anIt++ )
+ {
+ QFileInfo inf( Qtx::addSlash( *anIt ) + lib );
+
+ if( inf.exists() )
+ {
+ isLibFound = true;
+ break;
+ }
+ }
+
+ if ( !isLibFound )
+ {
+ INFOS( "\n****************************************************************" << std::endl
+ << "* Warning: library " << lib.toLatin1().constData() << " cannot be found" << std::endl
+ << "* Module " << moduleTitle.toLatin1().constData() << " will not be available in GUI mode" << std::endl
+ << "****************************************************************" << std::endl );
+ }
+ else if ( !isPythonModule && !isPythonLightModule)
+ return true;
+
+ if ( isPythonModule || isPythonLightModule)
+ {
+ QString pylib = moduleName( moduleTitle ) + QString(".py");
+ QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py");
+
+ // Check the python library
+// #ifdef WIN32
+// paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts );
+// #else
+ paths = QString(::getenv( "PYTHONPATH" )).split( ":", QString::SkipEmptyParts );
+// #endif
+ bool isPyLib = false, isPyGuiLib = false;
+ QStringList::const_iterator anIt = paths.begin(), aLast = paths.end();
+ for( ; anIt!=aLast; anIt++ )
+ {
+ QFileInfo inf( Qtx::addSlash( *anIt ) + pylib );
+ QFileInfo infgui( Qtx::addSlash( *anIt ) + pylibgui );
+
+ if(!isPythonLightModule)
+ if( !isPyLib && inf.exists() )
+ isPyLib = true;
+
+ if( !isPyGuiLib && infgui.exists() )
+ isPyGuiLib = true;
+
+ if ((isPyLib || isPythonLightModule ) && isPyGuiLib && isLibFound)
+ return true;
+ }
+
+ printf( "\n****************************************************************\n" );
+ printf( "* Warning: python library for %s cannot be found:\n", moduleTitle.toLatin1().constData() );
+ if (!isPyLib)
+ printf( "* No module named %s\n", moduleName( moduleTitle ).toLatin1().constData() );
+ if (!isPyGuiLib)
+ printf( "* No module named %s\n", (moduleName( moduleTitle ) + QString("GUI")).toLatin1().constData() );
+ printf( "****************************************************************\n" );
+ return true;
+ }
+ return false;
+}
+
+/*!
+ \return default name for an active study
+*/
+void LightApp_Application::setDefaultStudyName( const QString& theName )
+{
+ QStringList anInfoList;
+ modules( anInfoList, false );
+
+ LightApp_Study* aStudy = (LightApp_Study*)activeStudy();
+ if( anInfoList.count() == 1 && // to avoid a conflict between different modules
+ !aStudy->isSaved() )
+ {
+ aStudy->setStudyName( theName );
+ updateDesktopTitle();
+ }
+}
+
+/*!
+ Custom event handler
+*/
+bool LightApp_Application::event( QEvent* e )
+{
+ if( e && e->type()==2000 )
+ {
+ SALOME_CustomEvent* ce = ( SALOME_CustomEvent* )e;
+ QString* d = ( QString* )ce->data();
+ if( SUIT_MessageBox::question(0, tr("WRN_WARNING"),
+ d ? *d : "",
+ SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+ SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
+ showPreferences( tr( "PREF_APP" ) );
+ if( d )
+ delete d;
+ return true;
+ }
+ return CAM_Application::event( e );
+}
+
+/*! Check data object */
+bool LightApp_Application::checkDataObject(LightApp_DataObject* theObj)
+{
+ if (theObj)
+ {
+ bool isSuitable = !theObj->entry().isEmpty() &&
+ !theObj->componentDataType().isEmpty() &&
+ !theObj->name().isEmpty();
+ return isSuitable;
+ }
+
+ return false;
+}
+
+int LightApp_Application::openChoice( const QString& aName )
+{
+ int choice = CAM_Application::openChoice( aName );
+
+ if ( choice == OpenExist ) // The document is already open.
+ {
+ // Do you want to reload it?
+ if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "QUE_DOC_ALREADYOPEN" ).arg( aName ),
+ SUIT_MessageBox::Yes | SUIT_MessageBox::No, SUIT_MessageBox::No ) == SUIT_MessageBox::Yes )
+ choice = OpenReload;
+ }
+
+ return choice;
+}
+
+bool LightApp_Application::openAction( const int choice, const QString& aName )
+{
+ bool res = false;
+ switch ( choice )
+ {
+ case OpenReload:
+ {
+ STD_Application* app = 0;
+ SUIT_Session* session = SUIT_Session::session();
+ QList<SUIT_Application*> appList = session->applications();
+ for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !app; ++it )
+ {
+ if ( (*it)->activeStudy() && (*it)->activeStudy()->studyName() == aName )
+ app = ::qobject_cast<STD_Application*>( *it );
+ }
+
+ if ( app )
+ {
+ app->onCloseDoc( false );
+ appList = session->applications();
+ STD_Application* other = 0;
+ for ( QList<SUIT_Application*>::iterator it = appList.begin(); it != appList.end() && !other; ++it )
+ other = ::qobject_cast<STD_Application*>( *it );
+
+ if ( other )
+ res = other->onOpenDoc( aName );
+ }
+ }
+ break;
+ default:
+ res = CAM_Application::openAction( choice, aName );
+ break;
+ }
+
+ return res;
+}
+
+QStringList LightApp_Application::viewManagersTypes() const
+{
+ QStringList aTypesList;
+ aTypesList += myUserWmTypes;
+#ifndef DISABLE_GLVIEWER
+ aTypesList<<GLViewer_Viewer::Type();
+#endif
+#ifndef DISABLE_PLOT2DVIEWER
+ aTypesList<<Plot2d_Viewer::Type();
+#endif
+#ifndef DISABLE_QXGRAPHVIEWER
+ aTypesList<<QxScene_Viewer::Type();
+#endif
+#ifndef DISABLE_OCCVIEWER
+ aTypesList<<OCCViewer_Viewer::Type();
+#endif
+#ifndef DISABLE_VTKVIEWER
+ #ifndef DISABLE_SALOMEOBJECT
+ aTypesList<<SVTK_Viewer::Type();
+ #else
+ aTypesList<<VTKViewer_Viewer::Type();
+ #endif
+#endif
+ return aTypesList;
+}
+/*!
+ * Removes all view managers of known types
+ * Other view managers are ignored
+ */
+void LightApp_Application::clearKnownViewManagers()
+{
+ QStringList aTypesList = viewManagersTypes();
+ QList<SUIT_ViewManager*> aMgrList;
+ viewManagers( aMgrList );
+ foreach (SUIT_ViewManager* aMgr, aMgrList) {
+ if (aTypesList.contains(aMgr->getType()))
+ removeViewManager(aMgr);
+ }
+}
+
+/*!
+ Copy of current selection
+ */
+void LightApp_Application::onCopy()
+{
+ LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
+ if( m )
+ m->copy();
+}
+
+/*!
+ Paste of current data in clipboard
+ */
+void LightApp_Application::onPaste()
+{
+ LightApp_Module* m = dynamic_cast<LightApp_Module*>( activeModule() );
+ if( m )
+ m->paste();
+}
+
+/*!
+ Browse (i.e. set focus on) the published objects
+ \param theIsApplyAndClose - flag indicating that the dialog for creating objects
+ has been accepted by Ok (or Apply & Close) button
+ \param theIsOptimizedBrowsing - flag switching to optimized browsing mode
+ (to select the first published object only)
+ \return entry of the selected object
+ */
+QString LightApp_Application::browseObjects( const QStringList& theEntryList,
+ const bool theIsApplyAndClose,
+ const bool theIsOptimizedBrowsing )
+{
+ QString aResult;
+ if( SUIT_ResourceMgr* aResourceMgr = resourceMgr() )
+ {
+ int aBrowsePolicy = aResourceMgr->integerValue( "ObjectBrowser", "browse_published_object", (int)BP_Never );
+ switch( aBrowsePolicy )
+ {
+ case BP_Never:
+ return aResult;
+ case BP_ApplyAndClose:
+ if( !theIsApplyAndClose )
+ return aResult;
+ case BP_Always:
+ default:
+ break;
+ }
+ }
+
+ LightApp_Study* aStudy = dynamic_cast<LightApp_Study*>( activeStudy() );
+ if( !aStudy )
+ return aResult;
+
+ SUIT_DataBrowser* anOB = objectBrowser();
+ if( !anOB )
+ return aResult;
+
+ SUIT_AbstractModel* aModel = dynamic_cast<SUIT_AbstractModel*>( anOB->model() );
+ if( !aModel )
+ return aResult;
+
+ QStringListIterator anIter( theEntryList );
+ if( theIsOptimizedBrowsing )
+ {
+ // go to the last entry
+ anIter.toBack();
+ if( anIter.hasPrevious() )
+ anIter.previous();
+ }
+
+ // scroll to each entry in the list
+ // (in optimized mode - to the last entry only)
+ QString anEntry;
+ LightApp_DataObject* anObject = 0;
+ while( anIter.hasNext() )
+ {
+ anEntry = anIter.next();
+ if( !anEntry.isEmpty() )
+ {
+ anObject = aStudy->findObjectByEntry( anEntry );
+ if( anObject )
+ {
+ QModelIndex anIndex = aModel->index( anObject );
+ anOB->treeView()->scrollTo( anIndex );
+ }
+ }
+ }
+
+ // always select the last object
+ if( anObject && !anEntry.isEmpty() )
+ {
+ QList<SUIT_Selector*> aSelectorList;
+ selectionMgr()->selectors( "ObjectBrowser", aSelectorList );
+ if( !aSelectorList.isEmpty() )
+ {
+ if( LightApp_OBSelector* aSelector = dynamic_cast<LightApp_OBSelector*>( aSelectorList.first() ) )
+ {
+ bool anIsAutoBlock = aSelector->autoBlock();
+
+ // temporarily disable auto block, to emit LightApp_SelectionMgr::currentSelectionChanged() signal
+ aSelector->setAutoBlock( false );
+
+ SUIT_DataOwnerPtrList aList;
+#ifndef DISABLE_SALOMEOBJECT
+ Handle(SALOME_InteractiveObject) aSObj = new SALOME_InteractiveObject
+ ( anObject->entry().toLatin1().constData(),
+ anObject->componentDataType().toLatin1().constData(),
+ anObject->name().toLatin1().constData() );
+ LightApp_DataOwner* owner = new LightApp_DataOwner( aSObj );
+#else
+ LightApp_DataOwner* owner = new LightApp_DataOwner( anEntry );
+#endif
+
+ aList.append( owner );
+ selectionMgr()->setSelected( aList );
+ aResult = anEntry;
+
+ // restore auto block flag
+ aSelector->setAutoBlock( anIsAutoBlock );
+ }
+ }
+ }
+
+ return aResult;
+}
+
+SUIT_DataObject* LightApp_Application::findObject( const QString& id ) const
+{
+ LightApp_Study* study = dynamic_cast<LightApp_Study*>( activeStudy() );
+ return study ? study->findObjectByEntry( id ) : 0;
+}
+
+/*!
+ Checks that an object can be renamed.
+ \param entry entry of the object
+ \brief Return \c true if object can be renamed
+*/
+bool LightApp_Application::renameAllowed( const QString& /*entry*/) const {
+ return false;
+}
+
+/*!
+ 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 LightApp_Application::renameObject( const QString& entry, const QString& ) {
+ return false;
+}
+
+/*! Process standard messages from desktop */
+void LightApp_Application::onDesktopMessage( const QString& message )
+{
+ const QString sectionSeparator = "/";
+
+ if ( message.toLower() == "updateobjectbrowser" ||
+ message.toLower() == "updateobjbrowser" ) {
+ // update object browser
+ updateObjectBrowser();
+ }
+ else {
+ QStringList data = message.split( sectionSeparator );
+ if ( data.count() > 1 ) {
+ QString msgType = data[0].trimmed();
+ LightApp_Module* sMod = 0;
+ CAM_Module* mod = module( msgType );
+ if ( !mod )
+ mod = module( moduleTitle( msgType ) );
+ if ( mod && mod->inherits( "LightApp_Module" ) )
+ sMod = (LightApp_Module*)mod;
+
+ if ( msgType.toLower() == "preferences" ) {
+ // requested preferences change: should be given as "preferences/<section>/<name>/<value>"
+ // for example "preferences/Study/multi_file_dump/true"
+ if ( data.count() > 3 ) {
+ QString section = data[1].trimmed();
+ QString param = data[2].trimmed();
+ QString value = QStringList( data.mid(3) ).join( sectionSeparator );
+ resourceMgr()->setValue( section, param, value );
+ }
+ }
+ else if ( sMod ) {
+ // received message for the module
+ QString msg = QStringList( data.mid(1) ).join( sectionSeparator );
+ sMod->message( msg );
+ }
+ }
+ }
+}
+
+/*!
+ Internal method.
+ Returns all top level toolbars.
+ Note : Result list contains only main window toolbars, not including toolbars from viewers.
+*/
+QList<QToolBar*> LightApp_Application::findToolBars() {
+ QList<QToolBar*> aResult;
+ QList<QToolBar*> tbList = qFindChildren<QToolBar*>( desktop() );
+ for ( QList<QToolBar*>::iterator tit = tbList.begin(); tit != tbList.end(); ++tit ) {
+ QToolBar* tb = *tit;
+ QObject* po = Qtx::findParent( tb, "QMainWindow" );
+ if ( po != desktop() )
+ continue;
+ aResult.append(tb);
+ }
+ return aResult;
+}
+
+/*!
+ Internal method to parse toolbars and dockable windows state.
+ */
+QByteArray LightApp_Application::processState(QByteArray& input,
+ const bool processWin,
+ const bool processTb,
+ const bool isRestoring,
+ QByteArray defaultState) {
+
+ QByteArray aRes;
+ bool hasDefaultState = !defaultState.isEmpty();
+ bool isDockWinWriten = false;
+ int nbDocWin = -1;
+ //Write date from users settings
+ if(isRestoring){
+ QDataStream tmpInputData(&input, QIODevice::ReadOnly);
+ int marker, version;
+ uchar dockmarker;
+ tmpInputData >> marker;
+ tmpInputData >> version;
+ tmpInputData >> dockmarker;
+ tmpInputData >> nbDocWin;
+ }
+ if(processWin && processTb && !isRestoring) {
+ aRes = input;
+ } else if(!processWin && !processTb ) {
+ if(hasDefaultState)
+ aRes = defaultState;
+ } else {
+ QDataStream aData(&aRes, QIODevice::WriteOnly);
+ QList<QToolBar*> aToolBars = findToolBars();
+
+ QStringList aNames;
+ for ( QList<QToolBar*>::iterator tit = aToolBars.begin(); tit != aToolBars.end(); ++tit ) {
+ QToolBar* tb = *tit;
+ aNames.append(tb->objectName());
+ }
+
+ int toolBarMarkerIndex = getToolbarMarkerIndex(input,aNames);
+ QDataStream anInputData(&input, QIODevice::ReadOnly);
+ if(toolBarMarkerIndex < 0)
+ return aRes;
+
+ int toolBarMarkerIndexDef;
+ if(hasDefaultState) {
+ toolBarMarkerIndexDef = getToolbarMarkerIndex(defaultState, aNames);
+ if(toolBarMarkerIndexDef < 0)
+ return aRes;
+ }
+ QDataStream anInputDataDef(&defaultState, QIODevice::ReadOnly);
+
+ QDataStream* aTargetData = 0;
+ int aTargetIndex = -1;
+
+ QByteArray currentArr = desktop()->saveState();
+ QDataStream anInputDataCur(¤tArr, QIODevice::ReadOnly);
+ bool useInputData = !isRestoring || (isRestoring && nbDocWin > 0);
+ if(processWin && useInputData) {
+ aTargetData = &anInputData;
+ aTargetIndex = toolBarMarkerIndex;
+ } else {
+ //Write date from default settings
+ if(hasDefaultState) {
+ aTargetData = &anInputDataDef;
+ aTargetIndex = toolBarMarkerIndexDef;
+ } else {
+ //If no default state, write current snapshot of the dockable windows
+ if(isRestoring) {
+ aTargetData = &anInputDataCur;
+ int toolBarMarkerIndexCur = getToolbarMarkerIndex(currentArr, aNames);
+ aTargetIndex = toolBarMarkerIndexCur;
+ }
+ }
+ }
+
+ if(aTargetData && aTargetIndex >= 0 ) {
+ aTargetData->device()->seek(0);
+ while( aTargetData->device()->pos() < aTargetIndex ) {
+ uchar ch;
+ *aTargetData >> ch;
+ aData<<ch;
+ }
+ isDockWinWriten = true;
+ }
+
+ aTargetData = 0;
+ aTargetIndex = -1;
+
+ if(processTb) {
+ aTargetData = &anInputData;
+ aTargetIndex = toolBarMarkerIndex;
+ } else {
+ if(hasDefaultState) {
+ aTargetData = &anInputDataDef;
+ aTargetIndex = toolBarMarkerIndexDef;
+ }
+ }
+
+ if(aTargetData && aTargetIndex >= 0) {
+ int index;
+ if(!isDockWinWriten ) {
+ //Write version marker
+ int marker, version;
+ aTargetData->device()->seek(0);
+ *aTargetData >> marker;
+ *aTargetData >> version;
+ aData << marker;
+ aData << version;
+ aData << (uchar) QDockWidgetMarker;
+ aData << (int) 0;
+ int shift = 4*sizeof(int) + sizeof(QSize);
+ index = aTargetIndex - shift;
+ } else {
+ index = aTargetIndex;
+ }
+
+ aTargetData->device()->seek(index);
+ while(!aTargetData->atEnd()) {
+ uchar ch;
+ *aTargetData >> ch;
+ aData << ch;
+ }
+ } else { // Not treat toolbars
+ aData << (uchar) QToolBarMarker;
+ aData << (int) 0; //Nb toolbars = 0
+ }
+ }
+ return aRes;
+}
+
+/*!
+ \brief Emits operationFinished signal.
+ \param theModuleName the name of the module which perfomed the operation
+ \param theOperationName the operation name
+ \param theEntryList the list of the created objects entries
+*/
+void LightApp_Application::emitOperationFinished( const QString& theModuleName,
+ const QString& theOperationName,
+ const QStringList& theEntryList )
+{
+ emit operationFinished( theModuleName, theOperationName, theEntryList );