Version: 8.3.0
EditionOptimizerLoop.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 "EditionOptimizerLoop.hxx"
21 #include "FormOptimizerLoop.hxx"
22 #include "Node.hxx"
23 #include "OptimizerLoop.hxx"
24 #include "TypeCode.hxx"
25 #include "QtGuiContext.hxx"
26 #include "Message.hxx"
27 
28 //#define _DEVDEBUG_
29 #include "YacsTrace.hxx"
30 
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 EditionOptimizerLoop::EditionOptimizerLoop(Subject* subject,
40  QWidget* parent,
41  const char* name)
42  : EditionNode(subject, parent, name)
43 {
45  _nbBranches = 1;
46  _wid->gridLayout1->addWidget(_formOptimizerLoop);
47  _formOptimizerLoop->sb_nbranch->setMinimum(1);
48  _formOptimizerLoop->sb_nbranch->setMaximum(INT_MAX);
49 
50  connect(_formOptimizerLoop->sb_nbranch, SIGNAL(editingFinished()),
51  this, SLOT(onNbBranchesEdited()));
52  connect(_formOptimizerLoop->lineEdit_initValue, SIGNAL(editingFinished()),
53  this, SLOT(onModifyInitFile()));
54  connect(_formOptimizerLoop->lineEdit_entry, SIGNAL(editingFinished()),
55  this, SLOT(onModifyEntry()));
56  connect(_formOptimizerLoop->lineEdit_lib, SIGNAL(editingFinished()),
57  this, SLOT(onModifyLib()));
58 }
59 
61 {
62 }
63 
65 {
66  bool isOk = false;
67  Node* node=_subjectNode->getNode();
68  OptimizerLoop *ol = dynamic_cast<OptimizerLoop*>(node);
69  InputPort * dp = ol->edGetAlgoInitPort();
71  isOk=sdp->setValue(_formOptimizerLoop->lineEdit_initValue->text().toStdString());
72  DEBTRACE(isOk);
73 }
74 
76 {
77  DEBTRACE("EditionOptimizerLoop::onModifyEntry");
78  OptimizerLoop *oloop = dynamic_cast<OptimizerLoop*>(_subjectNode->getNode());
79  if (oloop->getSymbol() == _formOptimizerLoop->lineEdit_entry->text().toStdString()) return;
80 
81  bool isOk = false;
83  isOk=ol->setAlgorithm(_formOptimizerLoop->lineEdit_lib->text().toStdString(),
84  _formOptimizerLoop->lineEdit_entry->text().toStdString());
85  if(!isOk)
86  Message mess;
87  DEBTRACE(isOk);
88 }
89 
91 {
92  DEBTRACE("EditionOptimizerLoop::onModifyLib");
93  OptimizerLoop *oloop = dynamic_cast<OptimizerLoop*>(_subjectNode->getNode());
94  if(oloop->getAlgLib() == _formOptimizerLoop->lineEdit_lib->text().toStdString()) return;
95 
96  bool isOk = false;
98  isOk=ol->setAlgorithm(_formOptimizerLoop->lineEdit_lib->text().toStdString(),
99  _formOptimizerLoop->lineEdit_entry->text().toStdString());
100  if (!isOk && !_formOptimizerLoop->lineEdit_lib->text().isEmpty() &&
101  !_formOptimizerLoop->lineEdit_entry->text().isEmpty())
102  Message mess;
103  DEBTRACE(isOk);
104 }
105 
107 {
108  int newval = _formOptimizerLoop->sb_nbranch->value();
109  DEBTRACE("EditionOptimizerLoop::onNbBranchesEdited " << _nbBranches << " --> " << newval);
110  if (newval != _nbBranches)
111  {
112  SubjectOptimizerLoop *sol = dynamic_cast<SubjectOptimizerLoop*>(_subject);
113  YASSERT(sol);
114  QString text = _formOptimizerLoop->sb_nbranch->cleanText();
115  sol->setNbBranches(text.toStdString());
116  }
117 }
118 
120 {
122 }
123 
124 void EditionOptimizerLoop::update(GuiEvent event, int type, Subject* son)
125 {
126  DEBTRACE("EditionOptimizerLoop::update " << eventName(event) << " " << type);
127  EditionNode::update(event, type, son);
128  switch (event)
129  {
130  case SETVALUE:
131  // Nb branches
132  SubjectComposedNode * scn = dynamic_cast<SubjectComposedNode*>(_subject);
133  string val = scn->getValue();
134  istringstream ss(val);
135  DEBTRACE( val);
136  int i = 0;
137  ss >> i;
138  DEBTRACE(i);
139  _formOptimizerLoop->sb_nbranch->setValue(i);
140  _nbBranches = i;
141 
142  OptimizerLoop * ol = dynamic_cast<OptimizerLoop *>(_subjectNode->getNode());
143 
144  // Algo init value
145  InputPort * dp = ol->edGetAlgoInitPort();
146  _formOptimizerLoop->lineEdit_initValue->setText(dp->getAsString().c_str());
147 
148  // Algo library and entry
149  _formOptimizerLoop->lineEdit_entry->setText(QString::fromStdString(ol->getSymbol()));
150  _formOptimizerLoop->lineEdit_lib->setText(QString::fromStdString(ol->getAlgLib()));
151 
152  // Type names
153  _formOptimizerLoop->label_evalSampleType->setText(ol->edGetSamplePort()->edGetType()->name());
154  _formOptimizerLoop->label_evalResultType->setText(ol->edGetPortForOutPool()->edGetType()->name());
155  _formOptimizerLoop->label_algoInitType->setText(ol->edGetAlgoInitPort()->edGetType()->name());
156  _formOptimizerLoop->label_algoResultType->setText(ol->edGetAlgoResultPort()->edGetType()->name());
157  break;
158  }
159 }