]> SALOME platform Git repositories - modules/yacs.git/blob - src/genericgui/EditionLoop.cxx
Salome HOME
Fixed compilation error
[modules/yacs.git] / src / genericgui / EditionLoop.cxx
1 // Copyright (C) 2006-2013  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "EditionLoop.hxx"
21 #include "FormLoop.hxx"
22 #include "Node.hxx"
23 #include "OutputPort.hxx"
24 #include "QtGuiContext.hxx"
25
26 //#define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28
29 #include <cassert>
30 #include <sstream>
31
32 using namespace std;
33
34 using namespace YACS;
35 using namespace YACS::HMI;
36
37 EditionLoop::EditionLoop(Subject* subject,
38                          QWidget* parent,
39                          const char* name)
40   : EditionNode(subject, parent, name)
41 {
42   _formLoop = new FormLoop(this);
43   _nbsteps = 0;
44   _wid->gridLayout1->addWidget(_formLoop);
45
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);
55
56   _formLoop->sb_nsteps->setMinimum(0);
57   _formLoop->sb_nsteps->setMaximum(INT_MAX);
58   connect(_formLoop->sb_nsteps, SIGNAL(editingFinished()),
59           this, SLOT(onNbStepsEdited()));
60 }
61
62 EditionLoop::~EditionLoop()
63 {
64 }
65
66 void EditionLoop::onNbStepsEdited()
67 {
68   int newval = _formLoop->sb_nsteps->value();
69   DEBTRACE("EditionLoop::onNbStepsEdited " << _nbsteps << " --> " << newval);
70   if (newval != _nbsteps)
71     {
72       SubjectForLoop *sfl = dynamic_cast<SubjectForLoop*>(_subject);
73       YASSERT(sfl);
74       QString text = _formLoop->sb_nsteps->cleanText();
75       sfl->setNbSteps(text.toStdString());
76     }
77 }
78
79 void EditionLoop::synchronize()
80 {
81   _subject->update(SETVALUE, 0, _subject);
82 }
83
84 void EditionLoop::update(GuiEvent event, int type, Subject* son)
85 {
86   DEBTRACE("EditionLoop::update " <<eventName(event) << " " << type);
87   EditionNode::update(event, type, son);
88   switch (event)
89     {
90     case SETVALUE:
91       {
92         SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
93         string val = scn->getValue();
94         istringstream ss(val);
95         DEBTRACE(val);
96         int i = 0;
97         ss >> i;
98         DEBTRACE(i);
99         _formLoop->sb_nsteps->setValue(i);
100         _nbsteps = i;
101
102         YACS::ENGINE::OutputPort* odp=scn->getNode()->getOutputPort("index");
103         SubjectDataPort* sodp = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[odp];
104         _le_index->setText(QString::fromStdString(sodp->getExecValue()));
105         break;
106       }
107     case UPDATEPROGRESS:
108       {
109         SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
110         YACS::ENGINE::OutputPort* odp=scn->getNode()->getOutputPort("index");
111         SubjectDataPort* sodp = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[odp];
112         _le_index->setText(QString::fromStdString(sodp->getExecValue()));
113         break;
114       }
115     }
116 }