]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Py2YacsDialog for future use in OTGUI
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 26 Feb 2019 15:48:17 +0000 (16:48 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 26 Feb 2019 15:48:17 +0000 (16:48 +0100)
Add an option to Py2YacsDialog in order to avoid the creation of the yacs file.
The dialog box can be used to edit a python file and verify that it respects
the format for py2yacs.

src/py2yacsgui/Py2YacsDialog.cxx
src/py2yacsgui/Py2YacsDialog.hxx

index d2490561ca96bba30da7f56141973bc8b88a30e8..ccf3777f1b561fc07f80271bf9931267479f3aa3 100644 (file)
 #include <PyEditor_Widget.h>
 #include <py2yacs.hxx>
 
-Py2YacsDialog::Py2YacsDialog( QWidget* parent)
+Py2YacsDialog::Py2YacsDialog( QWidget* parent, bool exportXml)
 : QDialog(parent),
   _yacsFile(),
   _pyEditorWindow(0),
   _errorMessages(0),
-  _okButton(0)
+  _okButton(0),
+  _exportXml(exportXml),
+  _pyScript()
 {
   QVBoxLayout *mainLayout = new QVBoxLayout;
   _pyEditorWindow = new PyEditor_Window;
@@ -70,32 +72,37 @@ void Py2YacsDialog::onExport()
   }
 
   Py2yacs converter;
-  std::string text = pyEdit->text().toStdString();
+  _pyScript = pyEdit->text().toStdString();
   try
   {
-    converter.load(text);
+    converter.load(_pyScript);
     // _exec -> default name for OPENTURNS functions
     std::string errors = converter.getFunctionErrors("_exec");
     if(errors.empty())
     {
-      QSettings settings;
-      QString currentDir = settings.value("currentDir").toString();
-      if (currentDir.isEmpty())
-        currentDir = QDir::homePath();
-      QString fileName = QFileDialog::getSaveFileName(this,
-                                  tr("Save to YACS schema..."),
-                                  currentDir,
-                                  QString("%1 (*.xml)" ).arg( tr("xml files")));
-      if (!fileName.isEmpty())
+      if(_exportXml)
       {
-        if (!fileName.endsWith(".xml"))
-          fileName += ".xml";
-        QFile file(fileName);
-        settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
-        converter.save(fileName.toStdString(), "_exec");
-        _yacsFile = fileName;
-        accept();
+        QSettings settings;
+        QString currentDir = settings.value("currentDir").toString();
+        if (currentDir.isEmpty())
+          currentDir = QDir::homePath();
+        QString fileName = QFileDialog::getSaveFileName(this,
+                                    tr("Save to YACS schema..."),
+                                    currentDir,
+                                    QString("%1 (*.xml)" ).arg( tr("xml files")));
+        if (!fileName.isEmpty())
+        {
+          if (!fileName.endsWith(".xml"))
+            fileName += ".xml";
+          QFile file(fileName);
+          settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
+          converter.save(fileName.toStdString(), "_exec");
+          _yacsFile = fileName;
+          accept();
+        }
       }
+      else
+        accept();
     }
     else
     {
@@ -115,4 +122,9 @@ void Py2YacsDialog::onExport()
 QString Py2YacsDialog::getYacsFile()
 {
   return _yacsFile;
-}
\ No newline at end of file
+}
+
+std::string Py2YacsDialog::getScriptText()
+{
+  return _pyScript;
+}
index 6144ae17ecb1231c3afd8971b0bc4f575175acfe..78253373886c9e3f6fd20918de1ec3a98b651d3a 100644 (file)
@@ -27,8 +27,9 @@ class PY2YACSGUILIB_EXPORT Py2YacsDialog : public QDialog
 {
   Q_OBJECT
   public:
-    Py2YacsDialog( QWidget* parent=0);
+    Py2YacsDialog( QWidget* parent=0, bool exportXml = true);
     QString getYacsFile();
+    std::string getScriptText();
 
   public slots:
     virtual void onExport();
@@ -38,6 +39,8 @@ class PY2YACSGUILIB_EXPORT Py2YacsDialog : public QDialog
     PyEditor_Window *_pyEditorWindow;
     QTextEdit * _errorMessages;
     QPushButton *_okButton;
+    bool _exportXml;
+    std::string _pyScript;
 };
 
 #endif // PY2YACSDIALOG_HXX