Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / EditionWhile.cxx
1 //  Copyright (C) 2006-2008  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 #include "EditionWhile.hxx"
20 #include "FormLoop.hxx"
21 #include "guiObservers.hxx"
22
23 //#define _DEVDEBUG_
24 #include "YacsTrace.hxx"
25
26 #include <cassert>
27 #include <sstream>
28
29 using namespace std;
30
31 using namespace YACS;
32 using namespace YACS::HMI;
33
34 EditionWhile::EditionWhile(Subject* subject,
35                          QWidget* parent,
36                          const char* name)
37   : EditionNode(subject, parent, name)
38 {
39   _formWhile = new FormLoop(this);
40   _wid->gridLayout1->addWidget(_formWhile);
41   _formWhile->sb_nsteps->setMinimum(0);
42   _formWhile->sb_nsteps->setMaximum(1);
43   _formWhile->label->setText("Condition");
44   connect(_formWhile->sb_nsteps, SIGNAL(valueChanged(const QString &)),
45           this, SLOT(onModifyCondition(const QString &)));
46 }
47
48 EditionWhile::~EditionWhile()
49 {
50 }
51
52 void EditionWhile::onModifyCondition(const QString &text)
53 {
54   DEBTRACE("EditionWhile::onModifyCondition " << text.toStdString());
55   SubjectWhileLoop *swl = dynamic_cast<SubjectWhileLoop*>(_subject);
56   assert(swl);
57   swl->setCondition(text.toStdString());
58 }
59
60 void EditionWhile::synchronize()
61 {
62   _subject->update(SETVALUE, 0, _subject);
63 }
64
65 void EditionWhile::update(GuiEvent event, int type, Subject* son)
66 {
67   DEBTRACE("EditionWhile::update " << eventName(event) << " " << type);
68   EditionNode::update(event, type, son);
69   switch (event)
70     {
71     case SETVALUE:
72       SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
73       string val = scn->getValue();
74       if (val == "True") val = "1";
75       else if (val == "False") val = "0";
76       DEBTRACE(val);
77       istringstream ss(val);
78       bool i = 0;
79       ss >> i;
80       DEBTRACE(i);
81       _formWhile->sb_nsteps->setValue(i);
82       break;
83     }
84 }