1 // Copyright (C) 2006-2014 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 <qsciscintilla.h>
31 #include <qscilexerpython.h>
37 #include "YacsTrace.hxx"
42 using namespace YACS::HMI;
43 using namespace YACS::ENGINE;
46 EditionPyFunc::EditionPyFunc(Subject* subject,
49 : EditionScript(subject, parent, name)
55 _subFuncNode = dynamic_cast<SubjectPyFuncNode*>(_subject);
56 YASSERT(_subFuncNode);
58 YACS::ENGINE::InlineFuncNode *pyFuncNode
59 = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(_subFuncNode->getNode());
62 _glayout->removeWidget( _sci );
64 QGridLayout *glt = new QGridLayout();
65 _funcName = pyFuncNode->getFname();
66 QLabel* laFuncName = new QLabel("laFuncName", this );
67 glt->addWidget(laFuncName, 0, 0, 1, 1);
68 laFuncName->setText("Function Name:");
69 _liFuncName = new QLineEdit( "liFuncName", this );
70 glt->addWidget(_liFuncName, 0, 1, 1, 1);
71 _liFuncName->setText(_funcName.c_str());
72 QPushButton* gener_template = new QPushButton("Template",this);
73 connect(gener_template,SIGNAL(clicked()),this, SLOT(onTemplate()));
74 glt->addWidget(gener_template, 0, 2, 1, 1);
75 _glayout->addLayout( glt , 1);
77 _glayout->addWidget( _sci );
78 if (!QtGuiContext::getQtCurrent()->isEdition())
80 gener_template->setEnabled (false);
81 _liFuncName->setEnabled (false);
85 connect(_liFuncName, SIGNAL(textChanged(const QString&)),
86 this, SLOT(onFuncNameModified(const QString&)));
89 EditionPyFunc::~EditionPyFunc()
93 void EditionPyFunc::onApply()
95 bool funcNameEdited = false;
96 string funcName = _liFuncName->text().toStdString();
99 _liFuncName->setText(_funcName.c_str());
100 funcName = _funcName;
102 if (funcName != _funcName)
104 funcNameEdited = true;
105 bool ret = _subFuncNode->setFunctionName(funcName);
108 funcNameEdited = false;
109 _funcName = funcName;
112 _isEdited = _isEdited || funcNameEdited;
113 EditionScript::onApply();
116 void EditionPyFunc::onCancel()
118 _liFuncName->setText(_funcName.c_str());
119 EditionScript::onCancel();
122 void EditionPyFunc::onFuncNameModified(const QString &text)
124 if (_funcName != text.toStdString()) setEdited(true);
127 void EditionPyFunc::onTemplate()
129 if(_funcName=="")return;
131 ElementaryNode* node = dynamic_cast<ElementaryNode*>(_subFuncNode->getNode());
134 text = "def " + _funcName + "(";
136 std::list<InputPort*> iplist = node->getSetOfInputPort();
137 std::list<InputPort*>::iterator ipos = iplist.begin();
138 for (; ipos != iplist.end(); ipos++)
140 text = text + (*ipos)->getName() + ",";
142 text = text + "):\n";
143 text = text + " return ";
145 std::list<OutputPort*> oplist = node->getSetOfOutputPort();
146 std::list<OutputPort*>::iterator opos = oplist.begin();
147 for (; opos != oplist.end(); opos++)
149 text = text + (*opos)->getName() + ",";
151 text[text.length()-1]=' ';
153 _sci->append(text.c_str());