Salome HOME
Merge remote branch 'origin/V7_dev' into V8_0_0_BR
[modules/yacs.git] / src / genericgui / EditionForEachLoop.cxx
index d5502ba755c5c82bb9a4fac86ac27056a3660308..0228567ddddd9d3db2be7c833a422ff795c0d4e6 100644 (file)
@@ -1,23 +1,28 @@
-//  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2015  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "EditionForEachLoop.hxx"
 #include "FormEachLoop.hxx"
+#include "Node.hxx"
+#include "ForEachLoop.hxx"
+#include "TypeCode.hxx"
+#include "QtGuiContext.hxx"
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
@@ -29,6 +34,7 @@ using namespace std;
 
 using namespace YACS;
 using namespace YACS::HMI;
+using namespace YACS::ENGINE;
 
 EditionForEachLoop::EditionForEachLoop(Subject* subject,
                                        QWidget* parent,
@@ -36,22 +42,49 @@ EditionForEachLoop::EditionForEachLoop(Subject* subject,
   : EditionNode(subject, parent, name)
 {
   _formEachLoop = new FormEachLoop(this);
+  _nbBranches = 1;
   _wid->gridLayout1->addWidget(_formEachLoop);
   _formEachLoop->sb_nbranch->setMinimum(1);
   _formEachLoop->sb_nbranch->setMaximum(INT_MAX);
-  connect(_formEachLoop->sb_nbranch, SIGNAL(valueChanged(const QString &)),
-          this, SLOT(onModifyNbBranches(const QString &)));
+  if (!QtGuiContext::getQtCurrent()->isEdition())
+    _formEachLoop->setEnabled (false);
+  Node* node=_subjectNode->getNode();
+  ForEachLoop *fe = dynamic_cast<ForEachLoop*>(node);
+  if(fe)
+    _formEachLoop->lineEdit->setText(fe->edGetSamplePort()->edGetType()->name());
+  connect(_formEachLoop->sb_nbranch, SIGNAL(editingFinished()),
+          this, SLOT(onNbBranchesEdited()));
+
+  connect(_formEachLoop->lineEdit_2, SIGNAL(editingFinished()),this,SLOT(onModifyCollection()));
+
 }
 
 EditionForEachLoop::~EditionForEachLoop()
 {
 }
 
-void EditionForEachLoop::onModifyNbBranches(const QString &text)
+void EditionForEachLoop::onModifyCollection()
 {
-  SubjectForEachLoop *sfe = dynamic_cast<SubjectForEachLoop*>(_subject);
-  assert(sfe);
-  sfe->setNbBranches(text.toStdString());
+  bool isOk = false;
+  Node* node=_subjectNode->getNode();
+  ForEachLoop *fe = dynamic_cast<ForEachLoop*>(node);
+  InputPort* dp=fe->edGetSeqOfSamplesPort();
+  SubjectDataPort* sdp = QtGuiContext::getQtCurrent()->_mapOfSubjectDataPort[dp];
+  isOk=sdp->setValue(_formEachLoop->lineEdit_2->text().toStdString());
+  DEBTRACE(isOk);
+}
+
+void EditionForEachLoop::onNbBranchesEdited()
+{
+  int newval = _formEachLoop->sb_nbranch->value();
+  DEBTRACE("EditionForEachLoop::onNbBranchesEdited " << _nbBranches << " --> " << newval);
+  if (newval != _nbBranches)
+    {
+      SubjectForEachLoop *sfe = dynamic_cast<SubjectForEachLoop*>(_subject);
+      YASSERT(sfe);
+      QString text = _formEachLoop->sb_nbranch->cleanText();
+      sfe->setNbBranches(text.toStdString());
+    }
 }
 
 void EditionForEachLoop::synchronize()
@@ -74,6 +107,11 @@ void EditionForEachLoop::update(GuiEvent event, int type, Subject* son)
       ss >> i;
       DEBTRACE(i);
       _formEachLoop->sb_nbranch->setValue(i);
+      _nbBranches = i; 
+
+      //smplscollection
+      InputPort* dp=_subjectNode->getNode()->getInputPort("SmplsCollection");
+      _formEachLoop->lineEdit_2->setText(dp->getAsString().c_str());
       break;
     }
 }