+
+ 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() || !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(aView && 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 || !myNoteBook )
+ 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));
+ if( changeDesktop ) {
+
+ SalomeApp_Application* app = this;
+ 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;
+
+ // 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 );
+ newStudy->updateFromNotebook(theStudyName, theIsStudySaved);
+ newStudy->Modified();
+ updateDesktopTitle();
+ updateActions();
+ }
+ else
+ ok = false;
+
+ return ok;
+}
+
+/*!
+ Close the Application
+*/
+void SalomeApp_Application::afterCloseDoc()
+{
+ // emit signal to restore study from Python script
+ if ( myNoteBook ) {
+ emit dumpedStudyClosed( myNoteBook->getDumpedStudyScript(),
+ myNoteBook->getDumpedStudyName(),
+ myNoteBook->isDumpedStudySaved() );
+ }
+ LightApp_Application::afterCloseDoc();