1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FormAdvParamContainer.hxx"
21 #include "FormComponent.hxx"
22 #include "QtGuiContext.hxx"
23 #include "Container.hxx"
30 #include "YacsTrace.hxx"
37 using namespace YACS::HMI;
38 using namespace YACS::ENGINE;
40 FormAdvParamContainer::FormAdvParamContainer(std::map<std::string, std::string>& prop, QWidget *parent):QWidget(parent),_properties(prop)
43 sb_mem->setMaximum(INT_MAX);
44 sb_cpu->setMaximum(INT_MAX);
45 sb_nbNodes->setMaximum(INT_MAX);
46 sb_procNode->setMaximum(INT_MAX);
47 sb_nbprocpar->setMaximum(INT_MAX);
48 sb_nbproc->setMaximum(INT_MAX);
50 FillPanel("",0); // --- set widgets before signal connexion to avoid false modif detection
52 connect(cb_policy, SIGNAL(activated(const QString&)), this, SLOT(onModifyPolicy(const QString&)));
53 connect(cb_parallel, SIGNAL(activated(const QString&)), this, SLOT(onModifyParLib(const QString&)));
54 connect(le_workdir, SIGNAL(textChanged(const QString&)), this, SLOT(onModifyWorkDir(const QString&)));
55 connect(le_contname, SIGNAL(textChanged(const QString&)), this, SLOT(onModifyContName(const QString&)));
56 connect(le_os, SIGNAL(textChanged(const QString&)), this, SLOT(onModifyOS(const QString&)));
57 connect(le_hostname, SIGNAL(textChanged(const QString&)), this, SLOT(onModifyHostName(const QString&)));
58 connect(le_compolist, SIGNAL(textChanged(const QString&)), this, SLOT(onModifyCompoList(const QString&)));
59 connect(le_resourceList, SIGNAL(textChanged(const QString&)), this, SLOT(onModifyResourceList(const QString&)));
60 connect(ch_mpi, SIGNAL(clicked(bool)), this, SLOT(onModifyIsMPI(bool)));
61 connect(sb_mem, SIGNAL(valueChanged(const QString&)), this, SLOT(onModifyMem(const QString&)));
62 connect(sb_cpu, SIGNAL(valueChanged(const QString&)), this, SLOT(onModifyClock(const QString&)));
63 connect(sb_nbNodes, SIGNAL(valueChanged(const QString&)), this, SLOT(onModifyNodes(const QString&)));
64 connect(sb_procNode, SIGNAL(valueChanged(const QString&)), this, SLOT(onModifyProcs(const QString&)));
65 connect(sb_nbprocpar, SIGNAL(valueChanged(const QString&)), this, SLOT(onModifyProcPar(const QString&)));
66 connect(sb_nbproc, SIGNAL(valueChanged(const QString&)), this, SLOT(onModifyProcRes(const QString&)));
69 FormAdvParamContainer::~FormAdvParamContainer()
73 void FormAdvParamContainer::FillPanel(const std::string& resource, YACS::ENGINE::Container *container)
75 DEBTRACE("FormContainer::FillPanel");
76 _container = container;
79 _properties = _container->getProperties();
86 if(_properties.count("type") && _properties["type"]=="multi")
87 cb_mode->setText("multi");
89 cb_mode->setText("mono");
91 vector<string> parlibs;
92 parlibs.push_back("");
93 parlibs.push_back("Mpi");
94 parlibs.push_back("Dummy");
96 for(int i=0; i< parlibs.size(); i++)
97 cb_parallel->addItem(parlibs[i].c_str());
98 if(_properties.count("parallelLib"))
101 for(i=0; i< parlibs.size(); i++)
102 if(parlibs[i] == _properties["parallelLib"])
104 cb_parallel->setCurrentIndex(i);
109 cb_parallel->setCurrentIndex(0);
111 if(_properties.count("workingdir"))
112 le_workdir->setText(_properties["workingdir"].c_str());
114 le_workdir->setText("");
116 if(_properties.count("container_name"))
117 le_contname->setText(_properties["container_name"].c_str());
119 le_contname->setText("");
121 if(_properties.count("isMPI"))
123 DEBTRACE("_properties[isMPI]=" << _properties["isMPI"]);
124 if ((_properties["isMPI"] == "0") || (_properties["isMPI"] == "false"))
125 ch_mpi->setCheckState(Qt::Unchecked);
127 ch_mpi->setCheckState(Qt::Checked);
130 ch_mpi->setCheckState(Qt::Unchecked);
132 if(_properties.count("nb_parallel_procs"))
133 sb_nbprocpar->setValue(atoi(_properties["nb_parallel_procs"].c_str()));
135 sb_nbprocpar->setValue(0);
137 updateResource(resource);
139 if (!QtGuiContext::getQtCurrent()->isEdition())
141 //if the schema is in execution do not allow editing
142 cb_parallel->setEnabled(false);
143 le_workdir->setReadOnly(true);
144 le_contname->setReadOnly(true);
145 ch_mpi->setEnabled(false);
146 sb_nbprocpar->setReadOnly(true);
147 le_hostname->setEnabled(false);
148 le_os->setEnabled(false);
149 sb_nbproc->setEnabled(false);
150 sb_mem->setEnabled(false);
151 sb_cpu->setEnabled(false);
152 sb_nbNodes->setEnabled(false);
153 sb_procNode->setEnabled(false);
154 cb_policy->setEnabled(false);
155 le_compolist->setEnabled(false);
156 le_resourceList->setEnabled(false);
160 void FormAdvParamContainer::onModified()
162 DEBTRACE("FormContainer::onModified");
163 Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
165 YASSERT(QtGuiContext::getQtCurrent()->_mapOfEditionItem.count(sub));
166 QWidget *widget = QtGuiContext::getQtCurrent()->_mapOfEditionItem[sub];
167 ItemEdition *item = dynamic_cast<ItemEdition*>(widget);
169 item->setEdited(true);
172 void FormAdvParamContainer::updateResource(const std::string &resource)
174 DEBTRACE("FormContainer::updateResource " << resource);
177 //the resource is not specified: use automatic and allow editing
178 if(_properties.count("hostname"))
179 le_hostname->setText(_properties["hostname"].c_str());
181 le_hostname->setText("");
182 le_hostname->setEnabled(true);
184 if(_properties.count("OS"))
185 le_os->setText(_properties["OS"].c_str());
188 le_os->setEnabled(true);
190 if(_properties.count("nb_resource_procs"))
191 sb_nbproc->setValue(atoi(_properties["nb_resource_procs"].c_str()));
193 sb_nbproc->setValue(0);
194 sb_nbproc->setEnabled(true);
196 if(_properties.count("mem_mb"))
197 sb_mem->setValue(atoi(_properties["mem_mb"].c_str()));
200 sb_mem->setEnabled(true);
202 if(_properties.count("cpu_clock"))
203 sb_cpu->setValue(atoi(_properties["cpu_clock"].c_str()));
206 sb_cpu->setEnabled(true);
208 if(_properties.count("nb_node"))
209 sb_nbNodes->setValue(atoi(_properties["nb_node"].c_str()));
211 sb_nbNodes->setValue(0);
212 sb_nbNodes->setEnabled(true);
214 if(_properties.count("nb_proc_per_node"))
215 sb_procNode->setValue(atoi(_properties["nb_proc_per_node"].c_str()));
217 sb_procNode->setValue(0);
218 sb_procNode->setEnabled(true);
220 std::vector<std::string> policies;
221 policies.push_back("cycl");
222 policies.push_back("altcycl");
223 policies.push_back("best");
224 policies.push_back("first");
226 for(int i=0; i< policies.size(); i++)
227 cb_policy->addItem(policies[i].c_str());
228 if(_properties.count("policy"))
231 for(i=0; i< policies.size(); i++)
232 if(policies[i] == _properties["policy"])
234 cb_policy->setCurrentIndex(i);
239 cb_policy->setCurrentIndex(1);
240 cb_policy->setEnabled(true);
242 if(_properties.count("component_list"))
243 le_compolist->setText(_properties["component_list"].c_str());
245 le_compolist->setText("");
246 le_compolist->setEnabled(true);
248 if(_properties.count("resource_list"))
249 le_resourceList->setText(_properties["resource_list"].c_str());
251 le_resourceList->setText("");
252 le_resourceList->setEnabled(true);
256 //a specific resource has been chosen: properties are those declared in the resources manager
257 //properties can not be edited
258 std::map<std::string,std::string> properties(_container->getResourceProperties(resource));
259 if(properties.count("hostname"))
260 le_hostname->setText(properties["hostname"].c_str());
262 le_hostname->setText("");
263 le_hostname->setEnabled(false);
265 if(properties.count("OS"))
266 le_os->setText(properties["OS"].c_str());
269 le_os->setEnabled(false);
271 if(properties.count("nb_resource_procs"))
272 sb_nbproc->setValue(atoi(properties["nb_resource_procs"].c_str()));
274 sb_nbproc->setValue(0);
275 sb_nbproc->setEnabled(false);
277 if(properties.count("mem_mb"))
278 sb_mem->setValue(atoi(properties["mem_mb"].c_str()));
281 sb_mem->setEnabled(false);
283 if(properties.count("cpu_clock"))
284 sb_cpu->setValue(atoi(properties["cpu_clock"].c_str()));
287 sb_cpu->setEnabled(false);
289 if(properties.count("nb_node"))
290 sb_nbNodes->setValue(atoi(properties["nb_node"].c_str()));
292 sb_nbNodes->setValue(0);
293 sb_nbNodes->setEnabled(false);
295 if(properties.count("nb_proc_per_node"))
296 sb_procNode->setValue(atoi(properties["nb_proc_per_node"].c_str()));
298 sb_procNode->setValue(0);
299 sb_procNode->setEnabled(false);
302 cb_policy->setEnabled(false);
304 if(properties.count("component_list"))
305 le_compolist->setText(properties["component_list"].c_str());
307 le_compolist->setText("");
308 le_compolist->setEnabled(false);
310 if(properties.count("resource_list"))
311 le_resourceList->setText(properties["resource_list"].c_str());
313 le_resourceList->setText("");
314 le_resourceList->setEnabled(false);
318 void FormAdvParamContainer::setModeText(const std::string& mode)
320 cb_mode->setText(mode.c_str());
323 void FormAdvParamContainer::onModifyResource(const QString &text)
325 DEBTRACE("onModifyResource " << text.toStdString());
326 if (!_container) return;
327 std::string resource=text.toStdString();
328 if(resource=="automatic")resource="";
329 map<string,string> properties = _container->getProperties();
330 _properties["name"] = resource;
331 if (properties["name"] != resource)
333 // reset resource properties
334 _properties.erase("hostname");
335 _properties.erase("OS");
336 _properties.erase("nb_resource_procs");
337 _properties.erase("mem_mb");
338 _properties.erase("cpu_clock");
339 _properties.erase("nb_node");
340 _properties.erase("nb_proc_per_node");
341 _properties.erase("policy");
343 updateResource(resource);
347 void FormAdvParamContainer::onModifyPolicy(const QString &text)
349 DEBTRACE("onModifyPolicy " << text.toStdString());
350 if (!_container) return;
351 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
352 map<string,string> properties = _container->getProperties();
353 _properties["policy"] = text.toStdString();
354 if (properties["policy"] != text.toStdString())
358 void FormAdvParamContainer::onModifyWorkDir(const QString &text)
360 DEBTRACE("onModifyWorkDir " << text.toStdString());
361 if (!_container) return;
362 map<string,string> properties = _container->getProperties();
363 _properties["workingdir"] = text.toStdString();
364 if (properties["workingdir"] != text.toStdString())
368 void FormAdvParamContainer::onModifyContName(const QString &text)
370 DEBTRACE("onModifyContName " << text.toStdString());
371 if (!_container) return;
372 map<string,string> properties = _container->getProperties();
373 _properties["container_name"] = text.toStdString();
374 if (properties["container_name"] != text.toStdString())
378 void FormAdvParamContainer::onModifyOS(const QString &text)
380 DEBTRACE("onModifyOS " << text.toStdString());
381 if (!_container) return;
382 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
383 map<string,string> properties = _container->getProperties();
384 _properties["OS"] = text.toStdString();
385 if (properties["OS"] != text.toStdString())
389 void FormAdvParamContainer::onModifyParLib(const QString &text)
391 DEBTRACE("onModifyParLib " << text.toStdString());
392 if (!_container) return;
393 map<string,string> properties = _container->getProperties();
394 _properties["parallelLib"] = text.toStdString();
395 if (properties["parallelLib"] != text.toStdString())
399 void FormAdvParamContainer::onModifyIsMPI(bool isMpi)
401 DEBTRACE("onModifyIsMPI " << isMpi);
402 if (!_container) return;
403 string text = "false";
404 if (isMpi) text = "true";
406 map<string,string> properties = _container->getProperties();
407 _properties["isMPI"] = text;
408 if (properties["isMPI"] != text)
412 void FormAdvParamContainer::onModifyMem(const QString &text)
414 DEBTRACE("onModifyMem " << text.toStdString());
415 if (!_container) return;
416 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
417 map<string,string> properties = _container->getProperties();
418 if(properties.count("mem_mb")==0 )properties["mem_mb"]="0"; //default value
419 _properties["mem_mb"] = text.toStdString();
420 if (properties["mem_mb"] != text.toStdString())
424 void FormAdvParamContainer::onModifyClock(const QString &text)
426 DEBTRACE("onModifyClock " << text.toStdString());
427 if (!_container) return;
428 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
429 map<string,string> properties = _container->getProperties();
430 if(properties.count("cpu_clock")==0 )properties["cpu_clock"]="0"; //default value
431 _properties["cpu_clock"] = text.toStdString();
432 if (properties["cpu_clock"] != text.toStdString())
436 void FormAdvParamContainer::onModifyNodes(const QString &text)
438 DEBTRACE("onModifyNodes " << text.toStdString());
439 if (!_container) return;
440 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
441 map<string,string> properties = _container->getProperties();
442 if(properties.count("nb_node")==0 )properties["nb_node"]="0"; //default value
443 _properties["nb_node"] = text.toStdString();
444 if (properties["nb_node"] != text.toStdString())
448 void FormAdvParamContainer::onModifyProcs(const QString &text)
450 DEBTRACE("onModifyProcs " << text.toStdString());
451 if (!_container) return;
452 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
453 map<string,string> properties = _container->getProperties();
454 if(properties.count("nb_proc_per_node")==0 )properties["nb_proc_per_node"]="0"; //default value
455 _properties["nb_proc_per_node"] = text.toStdString();
456 if (properties["nb_proc_per_node"] != text.toStdString())
460 void FormAdvParamContainer::onModifyCompos(const QString &text)
462 DEBTRACE("onModifyCompo " << text.toStdString());
463 if (!_container) return;
464 map<string,string> properties = _container->getProperties();
465 _properties["nb_component_nodes"] = text.toStdString();
466 if (properties["nb_component_nodes"] != text.toStdString())
470 void FormAdvParamContainer::onModifyProcPar(const QString &text)
472 DEBTRACE("onModifyProcPar " << text.toStdString());
473 if (!_container) return;
474 map<string,string> properties = _container->getProperties();
475 _properties["nb_parallel_procs"] = text.toStdString();
476 if (properties["nb_parallel_procs"] != text.toStdString())
480 void FormAdvParamContainer::onModifyResourceName(const QString &text)
482 DEBTRACE("onModifyResourceName " << text.toStdString());
483 if (!_container) return;
484 map<string,string> properties = _container->getProperties();
485 _properties["resource_name"] = text.toStdString();
486 if (properties["resource_name"] != text.toStdString())
490 void FormAdvParamContainer::onModifyHostName(const QString &text)
492 DEBTRACE("onModifyHostName " << text.toStdString());
493 if (!_container) return;
494 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
496 map<string,string> properties = _container->getProperties();
497 _properties["hostname"] = text.toStdString();
498 if (properties["hostname"] != text.toStdString())
502 void FormAdvParamContainer::onModifyProcRes(const QString &text)
504 DEBTRACE("onModifyProcRes " << text.toStdString());
505 if (!_container) return;
506 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
507 map<string,string> properties = _container->getProperties();
508 if(properties.count("nb_resource_procs")==0 )properties["nb_resource_procs"]="0"; //default value
509 _properties["nb_resource_procs"] = text.toStdString();
510 if (properties["nb_resource_procs"] != text.toStdString())
514 void FormAdvParamContainer::onModifyCompoList(const QString &text)
516 DEBTRACE("onModifyCompoList " << text.toStdString());
517 if (!_container) return;
518 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
519 map<string,string> properties = _container->getProperties();
520 _properties["component_list"] = text.toStdString();
521 if (properties["component_list"] != text.toStdString())
525 void FormAdvParamContainer::onModifyResourceList(const QString &text)
527 DEBTRACE("onModifyResourceList " << text.toStdString());
528 if (!_container) return;
529 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
530 map<string,string> properties = _container->getProperties();
531 _properties["resource_list"] = text.toStdString();
532 if (properties["resource_list"] != text.toStdString())