Version: 9.16.0
EditionForEachLoop.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
21#include "FormEachLoop.hxx"
22#include "Node.hxx"
23#include "ForEachLoop.hxx"
24#include "TypeCode.hxx"
25#include "QtGuiContext.hxx"
26
27//#define _DEVDEBUG_
28#include "YacsTrace.hxx"
29
30#include <cassert>
31#include <sstream>
32
33using namespace std;
34
35using namespace YACS;
36using namespace YACS::HMI;
37using namespace YACS::ENGINE;
38
39EditionForEachLoop::EditionForEachLoop(Subject* subject,
40 QWidget* parent,
41 const char* name)
42 : EditionNode(subject, parent, name)
43{
44 _formEachLoop = new FormEachLoop(this);
45 _nbBranches = 1;
46 _wid->gridLayout1->addWidget(_formEachLoop);
47 _formEachLoop->sb_nbranch->setMinimum(1);
48 _formEachLoop->sb_nbranch->setMaximum(INT_MAX);
49 if (!QtGuiContext::getQtCurrent()->isEdition())
50 _formEachLoop->setEnabled (false);
51 Node* node=_subjectNode->getNode();
52 ForEachLoopGen *fe = dynamic_cast<ForEachLoopGen*>(node);
53 if(fe)
54 _formEachLoop->lineEdit->setText(fe->edGetSamplePort()->edGetType()->name());
55 connect(_formEachLoop->sb_nbranch, SIGNAL(editingFinished()),
56 this, SLOT(onNbBranchesEdited()));
57
58 connect(_formEachLoop->lineEdit_2, SIGNAL(editingFinished()),this,SLOT(onModifyCollection()));
59
60}
61
63{
64}
65
67{
68 bool isOk = false;
69 Node* node=_subjectNode->getNode();
70 ForEachLoopGen *fe = dynamic_cast<ForEachLoopGen*>(node);
73 isOk=sdp->setValue(_formEachLoop->lineEdit_2->text().toStdString());
74 DEBTRACE(isOk);
75}
76
78{
79 int newval = _formEachLoop->sb_nbranch->value();
80 DEBTRACE("EditionForEachLoop::onNbBranchesEdited " << _nbBranches << " --> " << newval);
81 if (newval != _nbBranches)
82 {
83 SubjectForEachLoop *sfe = dynamic_cast<SubjectForEachLoop*>(_subject);
84 YASSERT(sfe);
85 QString text = _formEachLoop->sb_nbranch->cleanText();
86 sfe->setNbBranches(text.toStdString());
87 }
88}
89
91{
93}
94
95void EditionForEachLoop::update(GuiEvent event, int type, Subject* son)
96{
97 DEBTRACE("EditionForEachLoop::update " << eventName(event) << " " << type);
98 EditionNode::update(event, type, son);
99 switch (event)
100 {
101 case SETVALUE:
102 SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
103 string val = scn->getValue();
104 istringstream ss(val);
105 DEBTRACE( val);
106 int i = 0;
107 ss >> i;
108 DEBTRACE(i);
109 _formEachLoop->sb_nbranch->setValue(i);
110 _nbBranches = i;
111
112 //smplscollection
113 InputPort* dp=_subjectNode->getNode()->getInputPort("SmplsCollection");
114 _formEachLoop->lineEdit_2->setText(dp->getAsString().c_str());
115 break;
116 }
117}
#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
TypeCode * edGetType() const
Definition: DataPort.hxx:53
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Definition: DataPort.cxx:84
OutputPort * edGetSamplePort()
Definition: DynParaLoop.hxx:90
InputPort * edGetSeqOfSamplesPort()
Base class for Input Ports.
Definition: InputPort.hxx:44
Base class for all nodes.
Definition: Node.hxx:70
virtual InputPort * getInputPort(const std::string &name) const
Definition: Node.cxx:260
virtual const char * name() const
Definition: TypeCode.cxx:72
virtual void update(GuiEvent event, int type, Subject *son)
SubjectNode * _subjectNode
Definition: EditionNode.hxx:48
virtual void update(GuiEvent event, int type, Subject *son)
Definition: EditionNode.cxx:64
std::map< YACS::ENGINE::DataPort *, YACS::HMI::SubjectDataPort * > _mapOfSubjectDataPort
Definition: guiContext.hxx:71
static std::string eventName(GuiEvent event)
static QtGuiContext * getQtCurrent()
virtual std::string getValue()
virtual bool setValue(std::string value)
virtual bool setNbBranches(std::string nbBranches)
virtual YACS::ENGINE::Node * getNode()
virtual void update(GuiEvent event, int type, Subject *son)