]> SALOME platform Git repositories - modules/yacs.git/blob - src/genericgui/EditionForEachLoop.cxx
Salome HOME
Fix English translation: Choose Batch Job to watch
[modules/yacs.git] / src / genericgui / EditionForEachLoop.cxx
1 // Copyright (C) 2006-2014  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, 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 "EditionForEachLoop.hxx"
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
33 using namespace std;
34
35 using namespace YACS;
36 using namespace YACS::HMI;
37 using namespace YACS::ENGINE;
38
39 EditionForEachLoop::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   Node* node=_subjectNode->getNode();
50   ForEachLoop *fe = dynamic_cast<ForEachLoop*>(node);
51   if(fe)
52     _formEachLoop->lineEdit->setText(fe->edGetSamplePort()->edGetType()->name());
53   connect(_formEachLoop->sb_nbranch, SIGNAL(editingFinished()),
54           this, SLOT(onNbBranchesEdited()));
55
56   connect(_formEachLoop->lineEdit_2, SIGNAL(editingFinished()),this,SLOT(onModifyCollection()));
57
58 }
59
60 EditionForEachLoop::~EditionForEachLoop()
61 {
62 }
63
64 void EditionForEachLoop::onModifyCollection()
65 {
66   bool isOk = false;
67   Node* node=_subjectNode->getNode();
68   ForEachLoop *fe = dynamic_cast<ForEachLoop*>(node);
69   InputPort* dp=fe->edGetSeqOfSamplesPort();
70   SubjectDataPort* sdp = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[dp];
71   isOk=sdp->setValue(_formEachLoop->lineEdit_2->text().toStdString());
72   DEBTRACE(isOk);
73 }
74
75 void EditionForEachLoop::onNbBranchesEdited()
76 {
77   int newval = _formEachLoop->sb_nbranch->value();
78   DEBTRACE("EditionForEachLoop::onNbBranchesEdited " << _nbBranches << " --> " << newval);
79   if (newval != _nbBranches)
80     {
81       SubjectForEachLoop *sfe = dynamic_cast<SubjectForEachLoop*>(_subject);
82       YASSERT(sfe);
83       QString text = _formEachLoop->sb_nbranch->cleanText();
84       sfe->setNbBranches(text.toStdString());
85     }
86 }
87
88 void EditionForEachLoop::synchronize()
89 {
90   _subject->update(SETVALUE, 0, _subject);
91 }
92
93 void EditionForEachLoop::update(GuiEvent event, int type, Subject* son)
94 {
95   DEBTRACE("EditionForEachLoop::update " << eventName(event) << " " << type);
96   EditionNode::update(event, type, son);
97   switch (event)
98     {
99     case SETVALUE:
100       SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
101       string val = scn->getValue();
102       istringstream ss(val);
103       DEBTRACE( val);
104       int i = 0;
105       ss >> i;
106       DEBTRACE(i);
107       _formEachLoop->sb_nbranch->setValue(i);
108       _nbBranches = i; 
109
110       //smplscollection
111       InputPort* dp=_subjectNode->getNode()->getInputPort("SmplsCollection");
112       _formEachLoop->lineEdit_2->setText(dp->getAsString().c_str());
113       break;
114     }
115 }