Version: 9.16.0
EditionWhile.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
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, or (at your option) any later version.
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#include "QtGuiContext.hxx"
24
25//#define _DEVDEBUG_
26#include "YacsTrace.hxx"
27
28#include <cassert>
29#include <sstream>
30
31using namespace std;
32
33using namespace YACS;
34using namespace YACS::HMI;
35
36EditionWhile::EditionWhile(Subject* subject,
37 QWidget* parent,
38 const char* name)
39 : EditionNode(subject, parent, name)
40{
41 _formWhile = new FormLoop(this);
42 _condition = 0;
43 _wid->gridLayout1->addWidget(_formWhile);
44 _formWhile->sb_nsteps->setMinimum(0);
45 _formWhile->sb_nsteps->setMaximum(1);
46 _formWhile->label->setText("Condition");
47 if (!QtGuiContext::getQtCurrent()->isEdition())
48 _formWhile->setEnabled (false);
49 connect(_formWhile->sb_nsteps, SIGNAL(editingFinished()),
50 this, SLOT(onConditionEdited()));
51}
52
54{
55}
56
58{
59 int newval = _formWhile->sb_nsteps->value();
60 DEBTRACE("EditionWhile::onConditionEdited " << _condition << " --> " << newval);
61 if (newval != _condition)
62 {
63 SubjectWhileLoop *swl = dynamic_cast<SubjectWhileLoop*>(_subject);
64 YASSERT(swl);
65 QString text = _formWhile->sb_nsteps->cleanText();
66 swl->setCondition(text.toStdString());
67 }
68}
69
71{
73}
74
75void EditionWhile::update(GuiEvent event, int type, Subject* son)
76{
77 DEBTRACE("EditionWhile::update " << eventName(event) << " " << type);
78 EditionNode::update(event, type, son);
79 switch (event)
80 {
81 case SETVALUE:
82 SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
83 string val = scn->getValue();
84 if (val == "True") val = "1";
85 else if (val == "False") val = "0";
86 DEBTRACE(val);
87 istringstream ss(val);
88 bool i = 0;
89 ss >> i;
90 DEBTRACE(i);
91 _formWhile->sb_nsteps->setValue(i);
92 _condition = i;
93 break;
94 }
95}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
WidEditItem * _wid
virtual void update(GuiEvent event, int type, Subject *son)
Definition: EditionNode.cxx:64
virtual void onConditionEdited()
virtual void synchronize()
virtual void update(GuiEvent event, int type, Subject *son)
static std::string eventName(GuiEvent event)
static QtGuiContext * getQtCurrent()
virtual std::string getValue()
virtual bool setCondition(std::string condition)
virtual void update(GuiEvent event, int type, Subject *son)