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 "EditionLoop.hxx"
21 #include "FormLoop.hxx"
23 #include "OutputPort.hxx"
24 #include "QtGuiContext.hxx"
27 #include "YacsTrace.hxx"
35 using namespace YACS::HMI;
37 EditionLoop::EditionLoop(Subject* subject,
40 : EditionNode(subject, parent, name)
42 _formLoop = new FormLoop(this);
44 _wid->gridLayout1->addWidget(_formLoop);
46 QHBoxLayout* _hbl_index = new QHBoxLayout();
47 QLabel* _la_index = new QLabel(this);
48 _hbl_index->addWidget(_la_index);
49 _la_index->setText("index:");
50 _le_index = new QLineEdit(this);
51 _le_index->setText(QString::number(0));
52 _le_index->setReadOnly(true);
53 _hbl_index->addWidget(_le_index);
54 _formLoop->gridLayout->addLayout(_hbl_index, 1, 0);
56 _formLoop->sb_nsteps->setMinimum(0);
57 _formLoop->sb_nsteps->setMaximum(INT_MAX);
58 if (!QtGuiContext::getQtCurrent()->isEdition())
59 _formLoop->setEnabled (false);
61 connect(_formLoop->sb_nsteps, SIGNAL(editingFinished()),
62 this, SLOT(onNbStepsEdited()));
65 EditionLoop::~EditionLoop()
69 void EditionLoop::onNbStepsEdited()
71 int newval = _formLoop->sb_nsteps->value();
72 DEBTRACE("EditionLoop::onNbStepsEdited " << _nbsteps << " --> " << newval);
73 if (newval != _nbsteps)
75 SubjectForLoop *sfl = dynamic_cast<SubjectForLoop*>(_subject);
77 QString text = _formLoop->sb_nsteps->cleanText();
78 sfl->setNbSteps(text.toStdString());
82 void EditionLoop::synchronize()
84 _subject->update(SETVALUE, 0, _subject);
87 void EditionLoop::update(GuiEvent event, int type, Subject* son)
89 DEBTRACE("EditionLoop::update " <<eventName(event) << " " << type);
90 EditionNode::update(event, type, son);
95 SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
96 string val = scn->getValue();
97 istringstream ss(val);
102 _formLoop->sb_nsteps->setValue(i);
105 YACS::ENGINE::OutputPort* odp=scn->getNode()->getOutputPort("index");
106 SubjectDataPort* sodp = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[odp];
107 _le_index->setText(QString::fromStdString(sodp->getExecValue()));
112 SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
113 YACS::ENGINE::OutputPort* odp=scn->getNode()->getOutputPort("index");
114 SubjectDataPort* sodp = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[odp];
115 _le_index->setText(QString::fromStdString(sodp->getExecValue()));