1 // Copyright (C) 2006-2016 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 "EditionPyFunc.hxx"
21 #include "InlineNode.hxx"
22 #include "InputPort.hxx"
23 #include "OutputPort.hxx"
24 #include "QtGuiContext.hxx"
25 #include "Container.hxx"
27 #include <QToolButton>
30 #include <PyEditor_Editor.h>
36 #include "YacsTrace.hxx"
41 using namespace YACS::HMI;
42 using namespace YACS::ENGINE;
45 EditionPyFunc::EditionPyFunc(Subject* subject,
48 : EditionScript(subject, parent, name)
54 _subFuncNode = dynamic_cast<SubjectPyFuncNode*>(_subject);
55 YASSERT(_subFuncNode);
57 YACS::ENGINE::InlineFuncNode *pyFuncNode
58 = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(_subFuncNode->getNode());
61 _glayout->removeWidget( _sci );
63 QGridLayout *glt = new QGridLayout();
64 _funcName = pyFuncNode->getFname();
65 QLabel* laFuncName = new QLabel("laFuncName", this );
66 glt->addWidget(laFuncName, 0, 0, 1, 1);
67 laFuncName->setText("Function Name:");
68 _liFuncName = new QLineEdit( "liFuncName", this );
69 glt->addWidget(_liFuncName, 0, 1, 1, 1);
70 _liFuncName->setText(_funcName.c_str());
71 QPushButton* gener_template = new QPushButton("Template",this);
72 connect(gener_template,SIGNAL(clicked()),this, SLOT(onTemplate()));
73 glt->addWidget(gener_template, 0, 2, 1, 1);
74 _glayout->addLayout( glt , 1);
76 _glayout->addWidget( _sci );
77 if (!QtGuiContext::getQtCurrent()->isEdition())
79 gener_template->setEnabled (false);
80 _liFuncName->setEnabled (false);
84 connect(_liFuncName, SIGNAL(textChanged(const QString&)),
85 this, SLOT(onFuncNameModified(const QString&)));
88 EditionPyFunc::~EditionPyFunc()
92 void EditionPyFunc::onApply()
94 bool funcNameEdited = false;
95 string funcName = _liFuncName->text().toStdString();
98 _liFuncName->setText(_funcName.c_str());
101 if (funcName != _funcName)
103 funcNameEdited = true;
104 bool ret = _subFuncNode->setFunctionName(funcName);
107 funcNameEdited = false;
108 _funcName = funcName;
111 _isEdited = _isEdited || funcNameEdited;
112 EditionScript::onApply();
115 void EditionPyFunc::onCancel()
117 _liFuncName->setText(_funcName.c_str());
118 EditionScript::onCancel();
121 void EditionPyFunc::onFuncNameModified(const QString &text)
123 if (_funcName != text.toStdString()) setEdited(true);
126 void EditionPyFunc::onTemplate()
128 if(_funcName=="")return;
130 ElementaryNode* node = dynamic_cast<ElementaryNode*>(_subFuncNode->getNode());
133 text = "def " + _funcName + "(";
135 std::list<InputPort*> iplist = node->getSetOfInputPort();
136 std::list<InputPort*>::iterator ipos = iplist.begin();
137 for (; ipos != iplist.end(); ipos++)
139 text = text + (*ipos)->getName() + ",";
141 text = text + "):\n";
142 text = text + " return ";
144 std::list<OutputPort*> oplist = node->getSetOfOutputPort();
145 std::list<OutputPort*>::iterator opos = oplist.begin();
146 for (; opos != oplist.end(); opos++)
148 text = text + (*opos)->getName() + ",";
150 text[text.length()-1]=' ';
152 _sci->append(text.c_str());