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