1 // Copyright (C) 2016-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "Py2YacsDialog.hxx"
21 #include <PyEditor_Window.h>
22 #include <PyEditor_Widget.h>
23 #include <py2yacs.hxx>
25 Py2YacsDialog::Py2YacsDialog( QWidget* parent)
32 QVBoxLayout *mainLayout = new QVBoxLayout;
33 _pyEditorWindow = new PyEditor_Window;
35 _errorMessages = new QTextEdit(this);
36 _errorMessages->setReadOnly(true);
37 _errorMessages->hide();
38 QSplitter * splitterW = new QSplitter(Qt::Vertical);
39 splitterW->addWidget(_pyEditorWindow);
40 splitterW->addWidget(_errorMessages);
41 mainLayout->addWidget(splitterW);
43 QHBoxLayout *validationLayout = new QHBoxLayout;
44 _okButton = new QPushButton(tr("py -> &YACS"));
45 QPushButton * cancelButton = new QPushButton(tr("&Cancel"));
46 validationLayout->addWidget(_okButton);
47 validationLayout->addWidget(cancelButton);
48 mainLayout->addLayout(validationLayout);
50 setLayout(mainLayout);
51 setWindowTitle(tr("Python to YACS schema editor"));
53 connect(cancelButton,SIGNAL(clicked()),this, SLOT(reject()));
54 connect(_okButton,SIGNAL(clicked()),this, SLOT(onExport()));
56 // PyEditor_Window has a button "exit".
57 // Trigger "cancel" when the editor is closed.
58 _pyEditorWindow->setAttribute(Qt::WA_DeleteOnClose);
59 connect(_pyEditorWindow,SIGNAL(destroyed()),this, SLOT(reject()));
62 void Py2YacsDialog::onExport()
64 PyEditor_Widget* pyEdit = dynamic_cast<PyEditor_Widget*>
65 (_pyEditorWindow->centralWidget());
73 std::string text = pyEdit->text().toStdString();
77 // _exec -> default name for OPENTURNS functions
78 std::string errors = converter.getFunctionErrors("_exec");
82 QString currentDir = settings.value("currentDir").toString();
83 if (currentDir.isEmpty())
84 currentDir = QDir::homePath();
85 QString fileName = QFileDialog::getSaveFileName(this,
86 tr("Save to YACS schema..."),
88 QString("%1 (*.xml)" ).arg( tr("xml files")));
89 if (!fileName.isEmpty())
91 if (!fileName.endsWith(".xml"))
94 settings.setValue("currentDir", QFileInfo(fileName).absolutePath());
95 converter.save(fileName.toStdString(), "_exec");
102 _errorMessages->show();
103 _errorMessages->setText(errors.c_str());
106 catch(Py2yacsException& e)
108 const char * error = e.what();
109 _errorMessages->show();
110 _errorMessages->setText(QString(error));
115 QString Py2YacsDialog::getYacsFile()