1 // Copyright (C) 2006-2015 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 "EditionForEachLoop.hxx"
21 #include "FormEachLoop.hxx"
23 #include "ForEachLoop.hxx"
24 #include "TypeCode.hxx"
25 #include "QtGuiContext.hxx"
28 #include "YacsTrace.hxx"
36 using namespace YACS::HMI;
37 using namespace YACS::ENGINE;
39 EditionForEachLoop::EditionForEachLoop(Subject* subject,
42 : EditionNode(subject, parent, name)
44 _formEachLoop = new FormEachLoop(this);
46 _wid->gridLayout1->addWidget(_formEachLoop);
47 _formEachLoop->sb_nbranch->setMinimum(1);
48 _formEachLoop->sb_nbranch->setMaximum(INT_MAX);
49 if (!QtGuiContext::getQtCurrent()->isEdition())
50 _formEachLoop->setEnabled (false);
51 Node* node=_subjectNode->getNode();
52 ForEachLoop *fe = dynamic_cast<ForEachLoop*>(node);
54 _formEachLoop->lineEdit->setText(fe->edGetSamplePort()->edGetType()->name());
55 connect(_formEachLoop->sb_nbranch, SIGNAL(editingFinished()),
56 this, SLOT(onNbBranchesEdited()));
58 connect(_formEachLoop->lineEdit_2, SIGNAL(editingFinished()),this,SLOT(onModifyCollection()));
62 EditionForEachLoop::~EditionForEachLoop()
66 void EditionForEachLoop::onModifyCollection()
69 Node* node=_subjectNode->getNode();
70 ForEachLoop *fe = dynamic_cast<ForEachLoop*>(node);
71 InputPort* dp=fe->edGetSeqOfSamplesPort();
72 SubjectDataPort* sdp = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[dp];
73 isOk=sdp->setValue(_formEachLoop->lineEdit_2->text().toStdString());
77 void EditionForEachLoop::onNbBranchesEdited()
79 int newval = _formEachLoop->sb_nbranch->value();
80 DEBTRACE("EditionForEachLoop::onNbBranchesEdited " << _nbBranches << " --> " << newval);
81 if (newval != _nbBranches)
83 SubjectForEachLoop *sfe = dynamic_cast<SubjectForEachLoop*>(_subject);
85 QString text = _formEachLoop->sb_nbranch->cleanText();
86 sfe->setNbBranches(text.toStdString());
90 void EditionForEachLoop::synchronize()
92 _subject->update(SETVALUE, 0, _subject);
95 void EditionForEachLoop::update(GuiEvent event, int type, Subject* son)
97 DEBTRACE("EditionForEachLoop::update " << eventName(event) << " " << type);
98 EditionNode::update(event, type, son);
102 SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
103 string val = scn->getValue();
104 istringstream ss(val);
109 _formEachLoop->sb_nbranch->setValue(i);
113 InputPort* dp=_subjectNode->getNode()->getInputPort("SmplsCollection");
114 _formEachLoop->lineEdit_2->setText(dp->getAsString().c_str());