oss << "NODE = " << nnc->getChildName(*it1) << std::endl;
oss << "STATUS = " << nsm[st0] << std::endl;
oss << "BRANCH ID = " << j << std::endl;
- std::list<YACS::ENGINE::InputPort *> inps((*it1)->getSetOfInputPort());
- for(std::list<YACS::ENGINE::InputPort *>::const_iterator it2=inps.begin();it2!=inps.end();it2++)
- {
- std::string d((*it2)->getHumanRepr());
- if(d.size()>10000)
- d=d.substr(0,MAX_LGTH_OF_INP_DUMP);
- oss << "INPUT \"" << (*it2)->getName() << "\" = " << d << std::endl;
- }
oss << "DETAILS = " << std::endl;
oss << (*it1)->getErrorDetails();
}
node->setExecutionMode(YACS::ENGINE::InlineNode::REMOTE_STR);
node->setContainer(schema->containerMap["DefaultContainer"]);
return schema;
+}
+
+std::string Py2yacs::getAllErrors()const
+{
+ std::stringstream buffer;
+ buffer.clear();
+ if(! _global_errors.empty())
+ {
+ buffer << "Global errors:" << std::endl;
+ std::list<std::string>::const_iterator it;
+ for(it=_global_errors.begin(); it!=_global_errors.end(); it++)
+ {
+ buffer << *it << std::endl;
+ }
+ buffer << "-----------------------------------------" << std::endl;
+ }
+
+ std::list<FunctionProperties>::const_iterator it_fp;
+ for(it_fp=_functions.begin();it_fp!=_functions.end();it_fp++)
+ {
+ if(! it_fp->_errors.empty())
+ {
+ buffer << "Function " << it_fp->_name << " has errors:" << std::endl;
+ std::list<std::string>::const_iterator it;
+ buffer << "Errors :" ;
+ for(it=it_fp->_errors.begin();it!=it_fp->_errors.end();it++)
+ buffer << *it << std::endl;
+ buffer << "-----------------------------------------" << std::endl;
+ }
+ }
+ return buffer.str();
+}
+
+std::string Py2yacs::getFunctionErrors(const std::string& functionName)const
+{
+ std::stringstream buffer;
+ buffer.clear();
+ if(! _global_errors.empty())
+ {
+ buffer << "Global errors:" << std::endl;
+ std::list<std::string>::const_iterator it;
+ for(it=_global_errors.begin(); it!=_global_errors.end(); it++)
+ {
+ buffer << *it << std::endl;
+ }
+ buffer << "-----------------------------------------" << std::endl;
+ }
+
+ bool nameFound = false;
+ std::list<FunctionProperties>::const_iterator it_fp;
+ for(it_fp=_functions.begin(); it_fp!=_functions.end() && !nameFound; it_fp++)
+ {
+ if(it_fp->_name == functionName)
+ {
+ nameFound = true;
+ if(! it_fp->_errors.empty())
+ {
+ buffer << "Function " << it_fp->_name << " has errors:" << std::endl;
+ std::list<std::string>::const_iterator it;
+ buffer << "Errors :" ;
+ for(it=it_fp->_errors.begin();it!=it_fp->_errors.end();it++)
+ buffer << *it << std::endl;
+ buffer << "-----------------------------------------" << std::endl;
+ }
+ }
+ }
+
+ if(!nameFound)
+ {
+ buffer << "Function " << functionName << " not found." << std::endl;
+ }
+ return buffer.str();
}
\ No newline at end of file
*/
YACS::ENGINE::Proc* createProc(const std::string& python_function)const;
+ /*!
+ * Syntax errors when parsing python and py2yacs global errors.
+ * \return a list of errors.
+ */
const std::list<std::string>& getGlobalErrors() const;
+
const std::list<FunctionProperties>& getFunctionProperties()const;
+ /*!
+ * Get a string containing global errors and errors specific to py2yacs for
+ * every function in python script.
+ * An empty string means there is no error.
+ */
+ std::string getAllErrors()const;
+
+ /*!
+ * Same as getAllErrors but only for one function.
+ * py2yacs errors for other functions are ignored.
+ * If the function name is not found, you get an error message in the
+ * returned string.
+ */
+ std::string getFunctionErrors(const std::string& functionName)const;
+
private:
std::string _python_parser_module;
std::string _python_parser_function;
SET(_moc_HEADERS
Py2YacsDialog.hxx
Py2YacsModel.hxx
+ Py2YacsDialog_raw.hxx
)
# sources / moc wrappings
Py2YacsModel.hxx
Py2YacsDialog.hxx
config_py2yacsgui.hxx
+ Py2YacsDialog_raw.hxx
)
SET(py2yacsgui_SOURCES
Py2YacsDialog.cxx
Py2YacsModel.cxx
+ Py2YacsDialog_raw.cxx
${_moc_SOURCES}
)
ADD_EXECUTABLE(py2yacsgui py2yacsgui.cxx)
TARGET_LINK_LIBRARIES(py2yacsgui py2yacsguilib)
+ADD_EXECUTABLE(py2yacsgui_rich py2yacsgui_rich.cxx)
+TARGET_LINK_LIBRARIES(py2yacsgui_rich py2yacsguilib)
+
INSTALL(TARGETS py2yacsguilib EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
INSTALL(TARGETS py2yacsgui DESTINATION ${SALOME_INSTALL_BINS})
+INSTALL(TARGETS py2yacsgui_rich DESTINATION ${SALOME_INSTALL_BINS})
INSTALL(FILES ${py2yacsgui_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include <QtWidgets>
-#include <QSettings>
-#ifdef HAS_PYEDITOR
-#include <PyEditor_Editor.h>
-#endif
#include "Py2YacsDialog.hxx"
+#include <PyEditor_Window.h>
+#include <PyEditor_Widget.h>
+#include <py2yacs.hxx>
Py2YacsDialog::Py2YacsDialog( QWidget* parent)
-: QDialog(parent)
+: QDialog(parent),
+ _yacsFile(),
+ _pyEditorWindow(0),
+ _errorMessages(0),
+ _okButton(0)
{
- QHBoxLayout *fileLayout = new QHBoxLayout;
- QPushButton *loadButton = new QPushButton(tr("&Load"));
- _saveButton = new QPushButton(tr("&Save"));
- QPushButton *saveAsButton = new QPushButton(tr("Save &as ..."));
- fileLayout->addWidget(loadButton);
- fileLayout->addWidget(_saveButton);
- fileLayout->addWidget(saveAsButton);
-
-#ifdef HAS_PYEDITOR
- _pyEditor = new PyEditor_Editor(this);
-#else
- _pyEditor = new QTextEdit(this);
-#endif
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ _pyEditorWindow = new PyEditor_Window;
- QPushButton * applyButton = new QPushButton(tr("A&pply"));
- QTextEdit *errorMessages = new QTextEdit(this);
- errorMessages->setReadOnly(true);
+ _errorMessages = new QTextEdit(this);
+ _errorMessages->setReadOnly(true);
+ _errorMessages->hide();
+ QSplitter * splitterW = new QSplitter(Qt::Vertical);
+ splitterW->addWidget(_pyEditorWindow);
+ splitterW->addWidget(_errorMessages);
+ mainLayout->addWidget(splitterW);
- QHBoxLayout *exportLayout = new QHBoxLayout;
- _functionChosen = new QComboBox(this);
- _exportButton = new QPushButton(tr("E&xport to YACS schema..."));
- exportLayout->addWidget(new QLabel(tr("Function to run:")));
- exportLayout->addWidget(_functionChosen);
-
QHBoxLayout *validationLayout = new QHBoxLayout;
- _okButton = new QPushButton(tr("Save YACS schema and &quit"));
+ _okButton = new QPushButton(tr("py -> &YACS"));
QPushButton * cancelButton = new QPushButton(tr("&Cancel"));
validationLayout->addWidget(_okButton);
validationLayout->addWidget(cancelButton);
-
- QGroupBox *editWidget = new QGroupBox(tr("Python script:"));
- QVBoxLayout *editLayout = new QVBoxLayout;
- editLayout->addLayout(fileLayout);
- editLayout->addWidget(_pyEditor);
- editLayout->addWidget(applyButton);
- editLayout->addLayout(exportLayout);
- editWidget->setLayout(editLayout);
-
- QGroupBox *messageWidget = new QGroupBox(tr("Messages:"));
- QVBoxLayout *messageLayout = new QVBoxLayout;
- messageLayout->addWidget(errorMessages);
- messageWidget->setLayout(messageLayout);
-
- QSplitter * splitterW = new QSplitter(Qt::Vertical);
- splitterW->addWidget(editWidget);
- splitterW->addWidget(messageWidget);
-
- QVBoxLayout *mainLayout = new QVBoxLayout;
- mainLayout->addWidget(splitterW);
mainLayout->addLayout(validationLayout);
+
setLayout(mainLayout);
setWindowTitle(tr("Python to YACS schema editor"));
-
- invalidModel();
- _saveButton->setEnabled(false);
- connect(_pyEditor, SIGNAL(textChanged()), this, SLOT(invalidModel()));
- connect(applyButton,SIGNAL(clicked()),this, SLOT(onApply()));
-
- connect(&_model, SIGNAL(scriptChanged(const QString&)),
- _pyEditor, SLOT(setText(const QString&)));
- connect(&_model, SIGNAL(errorChanged(const QString&)),
- errorMessages, SLOT(setText(const QString&)));
- connect(&_model, SIGNAL(functionsChanged(std::list<std::string>)),
- this, SLOT(onFunctionNamesChange(std::list<std::string>)));
- connect(_functionChosen,SIGNAL(currentIndexChanged(const QString &)),
- &_model, SLOT(setFunctionName(const QString&)));
- connect(loadButton,SIGNAL(clicked()),this, SLOT(onLoad()));
- connect(_saveButton,SIGNAL(clicked()),this, SLOT(onSave()));
- connect(saveAsButton,SIGNAL(clicked()),this, SLOT(onSaveAs()));
- connect(_exportButton,SIGNAL(clicked()),this, SLOT(onExport()));
+
connect(cancelButton,SIGNAL(clicked()),this, SLOT(reject()));
connect(_okButton,SIGNAL(clicked()),this, SLOT(onExport()));
-}
-void Py2YacsDialog::onFunctionNamesChange(std::list<std::string> validFunctionNames)
-{
- int new_index = 0;
- int count = 0;
- QString lastChoice = _functionChosen->currentText();
- _functionChosen->clear();
- std::list<std::string>::const_iterator it;
- for(it=validFunctionNames.begin(); it!=validFunctionNames.end(); it++)
- {
- _functionChosen->addItem(it->c_str());
- if(lastChoice == it->c_str())
- new_index = count;
- count++;
- }
- _functionChosen->setCurrentIndex(new_index);
+ // PyEditor_Window has a button "exit".
+ // Trigger "cancel" when the editor is closed.
+ _pyEditorWindow->setAttribute(Qt::WA_DeleteOnClose);
+ connect(_pyEditorWindow,SIGNAL(destroyed()),this, SLOT(reject()));
}
-void Py2YacsDialog::onLoad()
+void Py2YacsDialog::onExport()
{
- QSettings settings;
- QString currentDir = settings.value("currentDir").toString();
- if (currentDir.isEmpty())
- currentDir = QDir::homePath();
- QString fileName = QFileDialog::getOpenFileName(this, tr("Python script to import..."),
- currentDir,
- tr("Python script (*.py);;"));
-
- if (!fileName.isEmpty())
+ PyEditor_Widget* pyEdit = dynamic_cast<PyEditor_Widget*>
+ (_pyEditorWindow->centralWidget());
+ if(!pyEdit)
{
- QFile file(fileName);
- settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
-
- _model.loadFile(fileName.toStdString());
- _saveButton->setEnabled(_model.savePossible());
- checkModel();
+ reject();
+ return;
}
-}
-void Py2YacsDialog::onExport()
-{
- QSettings settings;
- QString currentDir = settings.value("currentDir").toString();
- if (currentDir.isEmpty())
- currentDir = QDir::homePath();
- QString fileName = QFileDialog::getSaveFileName(this,
+ Py2yacs converter;
+ std::string text = pyEdit->text().toStdString();
+ try
+ {
+ converter.load(text);
+ // _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 (!fileName.endsWith(".xml"))
- fileName += ".xml";
- QFile file(fileName);
- settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
-
- if(_model.exportToXml(fileName.toStdString()))
+ 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
{
- _yacsFile = fileName;
- accept();
+ _errorMessages->show();
+ _errorMessages->setText(errors.c_str());
}
}
-}
-
-void Py2YacsDialog::onApply()
-{
- _model.setScript(_pyEditor->toPlainText().toStdString());
- checkModel();
-}
-
-void Py2YacsDialog::invalidModel()
-{
- _okButton->setEnabled(false);
- _exportButton->setEnabled(false);
- _functionChosen->setEnabled(false);
-}
-
-void Py2YacsDialog::checkModel()
-{
- bool modelState = _model.schemaAvailable();
- _okButton->setEnabled(modelState);
- _exportButton->setEnabled(modelState);
- _functionChosen->setEnabled(modelState);
-}
-
-void Py2YacsDialog::onSave()
-{
- _model.setScript(_pyEditor->toPlainText().toStdString());
- _model.save();
- checkModel();
-}
-
-void Py2YacsDialog::onSaveAs()
-{
- QSettings settings;
- QString currentDir = settings.value("currentDir").toString();
- if (currentDir.isEmpty())
- currentDir = QDir::homePath();
- QString fileName = QFileDialog::getSaveFileName(this,
- tr("Save to python file..."),
- currentDir,
- QString("%1 (*.py)" ).arg( tr("python files")));
- if (!fileName.isEmpty())
+ catch(Py2yacsException& e)
{
- if (!fileName.endsWith(".py"))
- fileName += ".py";
- QFile file(fileName);
- settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
-
- _model.setScript(_pyEditor->toPlainText().toStdString());
- _model.saveAs(fileName.toStdString());
- _saveButton->setEnabled(_model.savePossible());
- checkModel();
+ const char * error = e.what();
+ _errorMessages->show();
+ _errorMessages->setText(QString(error));
+ return;
}
}
-YACS::ENGINE::Proc* Py2YacsDialog::getYacsSchema()
-{
- return _model.getProc();
-}
-
QString Py2YacsDialog::getYacsFile()
{
return _yacsFile;
#define PY2YACSDIALOG_HXX
#include "config_py2yacsgui.hxx"
-#include "Py2YacsModel.hxx"
-#include <QDialog>
-
-#ifdef HAS_PYEDITOR
- class PyEditor_Editor;
-#else
- class QTextEdit;
-#endif
- class QComboBox;
- class QPushButton;
+#include <QtWidgets>
+class PyEditor_Window;
class PY2YACSGUILIB_EXPORT Py2YacsDialog : public QDialog
{
Q_OBJECT
public:
Py2YacsDialog( QWidget* parent=0);
- YACS::ENGINE::Proc* getYacsSchema();
QString getYacsFile();
-
+
public slots:
- virtual void onFunctionNamesChange(std::list<std::string> validFunctionNames);
- virtual void onLoad();
virtual void onExport();
- virtual void checkModel();
- virtual void invalidModel();
- virtual void onApply();
- virtual void onSave();
- virtual void onSaveAs();
+
private:
- Py2YacsModel _model;
QString _yacsFile;
-#ifdef HAS_PYEDITOR
- PyEditor_Editor *_pyEditor;
-#else
- QTextEdit *_pyEditor;
-#endif
- QComboBox *_functionChosen;
- QPushButton *_saveButton;
- QPushButton *_exportButton;
+ PyEditor_Window *_pyEditorWindow;
+ QTextEdit * _errorMessages;
QPushButton *_okButton;
};
--- /dev/null
+// Copyright (C) 2016-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#include <QtWidgets>
+#include <QSettings>
+#ifdef HAS_PYEDITOR
+#include <PyEditor_Editor.h>
+#endif
+
+#include "Py2YacsDialog_raw.hxx"
+
+Py2YacsDialog_raw::Py2YacsDialog_raw( QWidget* parent)
+: QDialog(parent)
+{
+ QHBoxLayout *fileLayout = new QHBoxLayout;
+ QPushButton *loadButton = new QPushButton(tr("&Load"));
+ _saveButton = new QPushButton(tr("&Save"));
+ QPushButton *saveAsButton = new QPushButton(tr("Save &as ..."));
+ fileLayout->addWidget(loadButton);
+ fileLayout->addWidget(_saveButton);
+ fileLayout->addWidget(saveAsButton);
+
+#ifdef HAS_PYEDITOR
+ _pyEditor = new PyEditor_Editor(this);
+#else
+ _pyEditor = new QTextEdit(this);
+#endif
+
+ QPushButton * applyButton = new QPushButton(tr("A&pply"));
+ QTextEdit *errorMessages = new QTextEdit(this);
+ errorMessages->setReadOnly(true);
+
+ QHBoxLayout *exportLayout = new QHBoxLayout;
+ _functionChosen = new QComboBox(this);
+ _exportButton = new QPushButton(tr("E&xport to YACS schema..."));
+ exportLayout->addWidget(new QLabel(tr("Function to run:")));
+ exportLayout->addWidget(_functionChosen);
+
+ QHBoxLayout *validationLayout = new QHBoxLayout;
+ _okButton = new QPushButton(tr("Save YACS schema and &quit"));
+ QPushButton * cancelButton = new QPushButton(tr("&Cancel"));
+ validationLayout->addWidget(_okButton);
+ validationLayout->addWidget(cancelButton);
+
+ QGroupBox *editWidget = new QGroupBox(tr("Python script:"));
+ QVBoxLayout *editLayout = new QVBoxLayout;
+ editLayout->addLayout(fileLayout);
+ editLayout->addWidget(_pyEditor);
+ editLayout->addWidget(applyButton);
+ editLayout->addLayout(exportLayout);
+ editWidget->setLayout(editLayout);
+
+ QGroupBox *messageWidget = new QGroupBox(tr("Messages:"));
+ QVBoxLayout *messageLayout = new QVBoxLayout;
+ messageLayout->addWidget(errorMessages);
+ messageWidget->setLayout(messageLayout);
+
+ QSplitter * splitterW = new QSplitter(Qt::Vertical);
+ splitterW->addWidget(editWidget);
+ splitterW->addWidget(messageWidget);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(splitterW);
+ mainLayout->addLayout(validationLayout);
+ setLayout(mainLayout);
+ setWindowTitle(tr("Python to YACS schema editor"));
+
+ invalidModel();
+ _saveButton->setEnabled(false);
+ connect(_pyEditor, SIGNAL(textChanged()), this, SLOT(invalidModel()));
+ connect(applyButton,SIGNAL(clicked()),this, SLOT(onApply()));
+
+ connect(&_model, SIGNAL(scriptChanged(const QString&)),
+ _pyEditor, SLOT(setText(const QString&)));
+ connect(&_model, SIGNAL(errorChanged(const QString&)),
+ errorMessages, SLOT(setText(const QString&)));
+ connect(&_model, SIGNAL(functionsChanged(std::list<std::string>)),
+ this, SLOT(onFunctionNamesChange(std::list<std::string>)));
+ connect(_functionChosen,SIGNAL(currentIndexChanged(const QString &)),
+ &_model, SLOT(setFunctionName(const QString&)));
+ connect(loadButton,SIGNAL(clicked()),this, SLOT(onLoad()));
+ connect(_saveButton,SIGNAL(clicked()),this, SLOT(onSave()));
+ connect(saveAsButton,SIGNAL(clicked()),this, SLOT(onSaveAs()));
+ connect(_exportButton,SIGNAL(clicked()),this, SLOT(onExport()));
+ connect(cancelButton,SIGNAL(clicked()),this, SLOT(reject()));
+ connect(_okButton,SIGNAL(clicked()),this, SLOT(onExport()));
+}
+
+void Py2YacsDialog_raw::onFunctionNamesChange(std::list<std::string> validFunctionNames)
+{
+ int new_index = 0;
+ int count = 0;
+ QString lastChoice = _functionChosen->currentText();
+ _functionChosen->clear();
+ std::list<std::string>::const_iterator it;
+ for(it=validFunctionNames.begin(); it!=validFunctionNames.end(); it++)
+ {
+ _functionChosen->addItem(it->c_str());
+ if(lastChoice == it->c_str())
+ new_index = count;
+ count++;
+ }
+ _functionChosen->setCurrentIndex(new_index);
+}
+
+void Py2YacsDialog_raw::onLoad()
+{
+ QSettings settings;
+ QString currentDir = settings.value("currentDir").toString();
+ if (currentDir.isEmpty())
+ currentDir = QDir::homePath();
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Python script to import..."),
+ currentDir,
+ tr("Python script (*.py);;"));
+
+ if (!fileName.isEmpty())
+ {
+ QFile file(fileName);
+ settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
+
+ _model.loadFile(fileName.toStdString());
+ _saveButton->setEnabled(_model.savePossible());
+ checkModel();
+ }
+}
+
+void Py2YacsDialog_raw::onExport()
+{
+ 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());
+ if(_model.exportToXml(fileName.toStdString()))
+ {
+ _yacsFile = fileName;
+ accept();
+ }
+ }
+}
+
+void Py2YacsDialog_raw::onApply()
+{
+ _model.setScript(_pyEditor->toPlainText().toStdString());
+ checkModel();
+}
+
+void Py2YacsDialog_raw::invalidModel()
+{
+ _okButton->setEnabled(false);
+ _exportButton->setEnabled(false);
+ _functionChosen->setEnabled(false);
+}
+
+void Py2YacsDialog_raw::checkModel()
+{
+ bool modelState = _model.schemaAvailable();
+ _okButton->setEnabled(modelState);
+ _exportButton->setEnabled(modelState);
+ _functionChosen->setEnabled(modelState);
+}
+
+void Py2YacsDialog_raw::onSave()
+{
+ _model.setScript(_pyEditor->toPlainText().toStdString());
+ _model.save();
+ checkModel();
+}
+
+void Py2YacsDialog_raw::onSaveAs()
+{
+ QSettings settings;
+ QString currentDir = settings.value("currentDir").toString();
+ if (currentDir.isEmpty())
+ currentDir = QDir::homePath();
+ QString fileName = QFileDialog::getSaveFileName(this,
+ tr("Save to python file..."),
+ currentDir,
+ QString("%1 (*.py)" ).arg( tr("python files")));
+ if (!fileName.isEmpty())
+ {
+ if (!fileName.endsWith(".py"))
+ fileName += ".py";
+ QFile file(fileName);
+ settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
+ _model.setScript(_pyEditor->toPlainText().toStdString());
+ _model.saveAs(fileName.toStdString());
+ _saveButton->setEnabled(_model.savePossible());
+ checkModel();
+ }
+}
+
+YACS::ENGINE::Proc* Py2YacsDialog_raw::getYacsSchema()
+{
+ return _model.getProc();
+}
+
+QString Py2YacsDialog_raw::getYacsFile()
+{
+ return _yacsFile;
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2016-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#ifndef PY2YACSDIALOG_RAW_HXX
+#define PY2YACSDIALOG_RAW_HXX
+
+#include "config_py2yacsgui.hxx"
+#include "Py2YacsModel.hxx"
+#include <QDialog>
+
+#ifdef HAS_PYEDITOR
+ class PyEditor_Editor;
+#else
+ class QTextEdit;
+#endif
+ class QComboBox;
+ class QPushButton;
+
+class PY2YACSGUILIB_EXPORT Py2YacsDialog_raw : public QDialog
+{
+ Q_OBJECT
+ public:
+ Py2YacsDialog_raw( QWidget* parent=0);
+ YACS::ENGINE::Proc* getYacsSchema();
+ QString getYacsFile();
+ public slots:
+ virtual void onFunctionNamesChange(std::list<std::string> validFunctionNames);
+ virtual void onLoad();
+ virtual void onExport();
+ virtual void checkModel();
+ virtual void invalidModel();
+ virtual void onApply();
+ virtual void onSave();
+ virtual void onSaveAs();
+ private:
+ Py2YacsModel _model;
+ QString _yacsFile;
+#ifdef HAS_PYEDITOR
+ PyEditor_Editor *_pyEditor;
+#else
+ QTextEdit *_pyEditor;
+#endif
+ QComboBox *_functionChosen;
+ QPushButton *_saveButton;
+ QPushButton *_exportButton;
+ QPushButton *_okButton;
+};
+
+#endif // PY2YACSDIALOG_RAW_HXX
void Py2YacsModel::setScript(const std::string& texte)
{
- std::stringstream buffer;
_script = texte;
emit scriptChanged(_script.c_str());
_functionName = "";
try
{
_data.load(_script);
-
- // get the errors
- buffer.clear();
- const std::list<std::string>& globalErrors = _data.getGlobalErrors();
- if(! globalErrors.empty())
- {
- buffer << "Global errors:" << std::endl;
- std::list<std::string>::const_iterator it;
- for(it=globalErrors.begin(); it!=globalErrors.end(); it++)
- {
- buffer << *it << std::endl;
- }
- buffer << "-----------------------------------------" << std::endl;
- }
-
- std::list<FunctionProperties>::const_iterator it_fp;
- const std::list<FunctionProperties>& functions = _data.getFunctionProperties();
- for(it_fp=functions.begin();it_fp!=functions.end();it_fp++)
- {
- if(! it_fp->_errors.empty())
- {
- buffer << "Function " << it_fp->_name << " has errors:" << std::endl;
- std::list<std::string>::const_iterator it;
- buffer << "Errors :" ;
- for(it=it_fp->_errors.begin();it!=it_fp->_errors.end();it++)
- buffer << *it << std::endl;
- buffer << "-----------------------------------------" << std::endl;
- }
- }
- _lastError = buffer.str();
+ _lastError = _data.getAllErrors();
}
catch(Py2yacsException& e)
{
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#include "Py2YacsDialog.hxx"
+#include "Py2YacsDialog_raw.hxx"
#include <QApplication>
#include "RuntimeSALOME.hxx"
#include "Proc.hxx"
{
QApplication app(argc,argv);
YACS::ENGINE::RuntimeSALOME::setRuntime();
- Py2YacsDialog mygui;
+ Py2YacsDialog_raw mygui;
if(mygui.exec())
{
std::cout << "Accepted" << std::endl;
--- /dev/null
+// Copyright (C) 2016-2017 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#include "Py2YacsDialog.hxx"
+#include <QApplication>
+#include "RuntimeSALOME.hxx"
+#include "Proc.hxx"
+#include <PyEditor_StdSettings.h>
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc,argv);
+ app.setOrganizationName( "salome" );
+ app.setOrganizationDomain( "www.salome-platform.org" );
+ app.setApplicationName( "py2yacs" );
+
+ YACS::ENGINE::RuntimeSALOME::setRuntime();
+ Py2YacsDialog mygui;
+ if(mygui.exec())
+ {
+ std::cout << "Accepted:" << mygui.getYacsFile().toStdString() << std::endl;
+ }
+ else
+ {
+ std::cout << "Not accepted" << std::endl;
+ }
+ return 0;
+}