+
+/*
+ Opens a file dialog to choose a python script.
+*/
+QString SalomeApp_Application::getScriptFileName()
+{
+ QStringList filtersList;
+ filtersList.append(tr("PYTHON_FILES_FILTER"));
+ filtersList.append(tr("ALL_FILES_FILTER"));
+
+ const QString anInitialPath =
+ SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : "";
+
+ return SUIT_FileDlg::getFileName(desktop(), anInitialPath, filtersList, tr("TOT_DESK_FILE_LOAD_SCRIPT"), true, true);
+}
+
+/*
+ Execute script in python console.
+*/
+void SalomeApp_Application::execScript(bool isNewDoc)
+{
+ const QString aFile = getScriptFileName();
+ if (aFile.isEmpty())
+ {
+ return;
+ }
+
+ if (isNewDoc)
+ {
+ onNewDoc();
+ }
+
+#ifndef DISABLE_PYCONSOLE
+ PyConsole_Console* pyConsole = pythonConsole();
+ PropertyMgr propm(this, "IsLoadedScript", true);
+ if (pyConsole)
+ {
+ QString command = QString("exec(compile(open('%1', 'rb').read(), '%1', 'exec'))").arg(aFile);
+ SUIT_Tools::addTraceToPythonCommand(aFile, command);
+
+ pyConsole->exec(command);
+ }
+#endif
+}
+
+void SalomeApp_Application::ensureShaperIsActivated()
+{
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+ _PTR(Study) studyDS = getStudy();
+ if ( study && studyDS )
+ {
+ _PTR(SObject) shaper = studyDS->FindObjectByPath("/Shaper"); // non null result if shaper data is present in the study
+ bool shaperIsActive = false;
+ QList<CAM_DataModel*> models;
+ study->dataModels( models );
+ for( int i = 0; i < models.count() && !shaperIsActive; i++ )
+ shaperIsActive = models[i]->module()->moduleName() == "Shaper";
+
+ if (shaper && !shaperIsActive)
+ onDesktopMessage("register_module_in_study/Shaper");
+ }
+}
+
+void SalomeApp_Application::addCatalogue( const QString& moduleName, const QString& catalogue )
+{
+ CORBA::Object_var obj = namingService()->Resolve( "/Kernel/ModulCatalog" );
+ SALOME_ModuleCatalog::ModuleCatalog_var moduleCatalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow( obj );
+ QFileInfo fi( catalogue );
+ if ( !CORBA::is_nil( moduleCatalogue ) && fi.isFile() )
+ {
+ SALOME_ModuleCatalog::ListOfComponents_var known = moduleCatalogue->GetComponentList();
+ bool loaded = false;
+ for ( int i = 0; i < (int)known->length() && !loaded; i++ )
+ loaded = QString( known[i].in() ) == moduleName;
+ if ( !loaded )
+ moduleCatalogue->ImportXmlCatalogFile( catalogue.toUtf8().constData() );
+ }
+}