1 // Copyright (C) 2006-2024 CEA, EDF
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&)));
67 connect(ch_pycache,SIGNAL(stateChanged(int)),this,SLOT(onModifyUsePyCache(int)));
70 FormAdvParamContainer::~FormAdvParamContainer()
74 void FormAdvParamContainer::FillPanel(const std::string& resource, YACS::ENGINE::Container *container)
76 DEBTRACE("FormContainer::FillPanel");
77 _container = container;
80 _properties = _container->getProperties();
87 if(_properties.count("type") && _properties["type"]=="multi")
88 cb_mode->setText("multi");
90 cb_mode->setText("mono");
92 vector<string> parlibs;
93 parlibs.push_back("");
94 parlibs.push_back("Mpi");
95 parlibs.push_back("Dummy");
97 for(int i=0; i< parlibs.size(); i++)
98 cb_parallel->addItem(parlibs[i].c_str());
99 if(_properties.count("parallelLib"))
102 for(i=0; i< parlibs.size(); i++)
103 if(parlibs[i] == _properties["parallelLib"])
105 cb_parallel->setCurrentIndex(i);
110 cb_parallel->setCurrentIndex(0);
112 if(_properties.count("workingdir"))
113 le_workdir->setText(_properties["workingdir"].c_str());
115 le_workdir->setText("");
118 ch_pycache->setCheckState(_container->isUsingPythonCache()?Qt::Checked:Qt::Unchecked);
120 ch_pycache->setCheckState(Qt::Unchecked);
122 if(_properties.count("container_name"))
123 le_contname->setText(_properties["container_name"].c_str());
125 le_contname->setText("");
127 if(_properties.count("isMPI"))
129 DEBTRACE("_properties[isMPI]=" << _properties["isMPI"]);
130 if ((_properties["isMPI"] == "0") || (_properties["isMPI"] == "false"))
131 ch_mpi->setCheckState(Qt::Unchecked);
133 ch_mpi->setCheckState(Qt::Checked);
136 ch_mpi->setCheckState(Qt::Unchecked);
138 if(_properties.count("nb_parallel_procs"))
139 sb_nbprocpar->setValue(atoi(_properties["nb_parallel_procs"].c_str()));
141 sb_nbprocpar->setValue(0);
143 updateResource(resource);
145 if (!QtGuiContext::getQtCurrent()->isEdition())
147 //if the schema is in execution do not allow editing
148 cb_parallel->setEnabled(false);
149 le_workdir->setReadOnly(true);
150 le_contname->setReadOnly(true);
151 ch_mpi->setEnabled(false);
152 sb_nbprocpar->setReadOnly(true);
153 le_hostname->setEnabled(false);
154 le_os->setEnabled(false);
155 sb_nbproc->setEnabled(false);
156 sb_mem->setEnabled(false);
157 sb_cpu->setEnabled(false);
158 sb_nbNodes->setEnabled(false);
159 sb_procNode->setEnabled(false);
160 cb_policy->setEnabled(false);
161 le_compolist->setEnabled(false);
162 le_resourceList->setEnabled(false);
166 void FormAdvParamContainer::onModified()
168 DEBTRACE("FormContainer::onModified");
169 Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
171 YASSERT(QtGuiContext::getQtCurrent()->_mapOfEditionItem.count(sub));
172 QWidget *widget = QtGuiContext::getQtCurrent()->_mapOfEditionItem[sub];
173 ItemEdition *item = dynamic_cast<ItemEdition*>(widget);
175 item->setEdited(true);
178 void FormAdvParamContainer::updateResource(const std::string &resource)
180 DEBTRACE("FormContainer::updateResource " << resource);
183 //the resource is not specified: use automatic and allow editing
184 if(_properties.count("hostname"))
185 le_hostname->setText(_properties["hostname"].c_str());
187 le_hostname->setText("");
188 le_hostname->setEnabled(true);
190 if(_properties.count("OS"))
191 le_os->setText(_properties["OS"].c_str());
194 le_os->setEnabled(true);
196 if(_properties.count("nb_resource_procs"))
197 sb_nbproc->setValue(atoi(_properties["nb_resource_procs"].c_str()));
199 sb_nbproc->setValue(0);
200 sb_nbproc->setEnabled(true);
202 if(_properties.count("mem_mb"))
203 sb_mem->setValue(atoi(_properties["mem_mb"].c_str()));
206 sb_mem->setEnabled(true);
208 if(_properties.count("cpu_clock"))
209 sb_cpu->setValue(atoi(_properties["cpu_clock"].c_str()));
212 sb_cpu->setEnabled(true);
214 if(_properties.count("nb_node"))
215 sb_nbNodes->setValue(atoi(_properties["nb_node"].c_str()));
217 sb_nbNodes->setValue(0);
218 sb_nbNodes->setEnabled(true);
220 if(_properties.count("nb_proc_per_node"))
221 sb_procNode->setValue(atoi(_properties["nb_proc_per_node"].c_str()));
223 sb_procNode->setValue(0);
224 sb_procNode->setEnabled(true);
226 std::vector<std::string> policies;
227 policies.push_back("cycl");
228 policies.push_back("altcycl");
229 policies.push_back("best");
230 policies.push_back("first");
232 for(int i=0; i< policies.size(); i++)
233 cb_policy->addItem(policies[i].c_str());
234 if(_properties.count("policy"))
237 for(i=0; i< policies.size(); i++)
238 if(policies[i] == _properties["policy"])
240 cb_policy->setCurrentIndex(i);
245 cb_policy->setCurrentIndex(1);
246 cb_policy->setEnabled(true);
248 if(_properties.count("component_list"))
249 le_compolist->setText(_properties["component_list"].c_str());
251 le_compolist->setText("");
252 le_compolist->setEnabled(true);
254 if(_properties.count("resource_list"))
255 le_resourceList->setText(_properties["resource_list"].c_str());
257 le_resourceList->setText("");
258 le_resourceList->setEnabled(true);
262 //a specific resource has been chosen: properties are those declared in the resources manager
263 //properties can not be edited
264 std::map<std::string,std::string> properties(_container->getResourceProperties(resource));
265 if(properties.count("hostname"))
266 le_hostname->setText(properties["hostname"].c_str());
268 le_hostname->setText("");
269 le_hostname->setEnabled(false);
271 if(properties.count("OS"))
272 le_os->setText(properties["OS"].c_str());
275 le_os->setEnabled(false);
277 if(properties.count("nb_resource_procs"))
278 sb_nbproc->setValue(atoi(properties["nb_resource_procs"].c_str()));
280 sb_nbproc->setValue(0);
281 sb_nbproc->setEnabled(false);
283 if(properties.count("mem_mb"))
284 sb_mem->setValue(atoi(properties["mem_mb"].c_str()));
287 sb_mem->setEnabled(false);
289 if(properties.count("cpu_clock"))
290 sb_cpu->setValue(atoi(properties["cpu_clock"].c_str()));
293 sb_cpu->setEnabled(false);
295 if(properties.count("nb_node"))
296 sb_nbNodes->setValue(atoi(properties["nb_node"].c_str()));
298 sb_nbNodes->setValue(0);
299 sb_nbNodes->setEnabled(false);
301 if(properties.count("nb_proc_per_node"))
302 sb_procNode->setValue(atoi(properties["nb_proc_per_node"].c_str()));
304 sb_procNode->setValue(0);
305 sb_procNode->setEnabled(false);
308 cb_policy->setEnabled(false);
310 if(properties.count("component_list"))
311 le_compolist->setText(properties["component_list"].c_str());
313 le_compolist->setText("");
314 le_compolist->setEnabled(false);
316 if(properties.count("resource_list"))
317 le_resourceList->setText(properties["resource_list"].c_str());
319 le_resourceList->setText("");
320 le_resourceList->setEnabled(false);
324 void FormAdvParamContainer::setModeText(const std::string& mode)
326 cb_mode->setText(mode.c_str());
329 void FormAdvParamContainer::onModifyResource(const QString &text)
331 DEBTRACE("onModifyResource " << text.toStdString());
332 if (!_container) return;
333 std::string resource=text.toStdString();
334 if(resource=="automatic")resource="";
335 map<string,string> properties = _container->getProperties();
336 _properties["name"] = resource;
337 if (properties["name"] != resource)
339 // reset resource properties
340 _properties.erase("hostname");
341 _properties.erase("OS");
342 _properties.erase("nb_resource_procs");
343 _properties.erase("mem_mb");
344 _properties.erase("cpu_clock");
345 _properties.erase("nb_node");
346 _properties.erase("nb_proc_per_node");
347 _properties.erase("policy");
349 updateResource(resource);
353 void FormAdvParamContainer::onModifyPolicy(const QString &text)
355 DEBTRACE("onModifyPolicy " << text.toStdString());
356 if (!_container) return;
357 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
358 map<string,string> properties = _container->getProperties();
359 _properties["policy"] = text.toStdString();
360 if (properties["policy"] != text.toStdString())
364 void FormAdvParamContainer::onModifyWorkDir(const QString &text)
366 DEBTRACE("onModifyWorkDir " << text.toStdString());
367 if (!_container) return;
368 map<string,string> properties = _container->getProperties();
369 _properties["workingdir"] = text.toStdString();
370 if (properties["workingdir"] != text.toStdString())
374 void FormAdvParamContainer::onModifyContName(const QString &text)
376 DEBTRACE("onModifyContName " << text.toStdString());
377 if (!_container) return;
378 map<string,string> properties = _container->getProperties();
379 _properties["container_name"] = text.toStdString();
380 if (properties["container_name"] != text.toStdString())
384 void FormAdvParamContainer::onModifyOS(const QString &text)
386 DEBTRACE("onModifyOS " << text.toStdString());
387 if (!_container) return;
388 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
389 map<string,string> properties = _container->getProperties();
390 _properties["OS"] = text.toStdString();
391 if (properties["OS"] != text.toStdString())
395 void FormAdvParamContainer::onModifyParLib(const QString &text)
397 DEBTRACE("onModifyParLib " << text.toStdString());
398 if (!_container) return;
399 map<string,string> properties = _container->getProperties();
400 _properties["parallelLib"] = text.toStdString();
401 if (properties["parallelLib"] != text.toStdString())
405 void FormAdvParamContainer::onModifyIsMPI(bool isMpi)
407 DEBTRACE("onModifyIsMPI " << isMpi);
408 if (!_container) return;
409 string text = "false";
410 if (isMpi) text = "true";
412 map<string,string> properties = _container->getProperties();
413 _properties["isMPI"] = text;
414 if (properties["isMPI"] != text)
418 void FormAdvParamContainer::onModifyMem(const QString &text)
420 DEBTRACE("onModifyMem " << text.toStdString());
421 if (!_container) return;
422 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
423 map<string,string> properties = _container->getProperties();
424 if(properties.count("mem_mb")==0 )properties["mem_mb"]="0"; //default value
425 _properties["mem_mb"] = text.toStdString();
426 if (properties["mem_mb"] != text.toStdString())
430 void FormAdvParamContainer::onModifyClock(const QString &text)
432 DEBTRACE("onModifyClock " << text.toStdString());
433 if (!_container) return;
434 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
435 map<string,string> properties = _container->getProperties();
436 if(properties.count("cpu_clock")==0 )properties["cpu_clock"]="0"; //default value
437 _properties["cpu_clock"] = text.toStdString();
438 if (properties["cpu_clock"] != text.toStdString())
442 void FormAdvParamContainer::onModifyNodes(const QString &text)
444 DEBTRACE("onModifyNodes " << text.toStdString());
445 if (!_container) return;
446 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
447 map<string,string> properties = _container->getProperties();
448 if(properties.count("nb_node")==0 )properties["nb_node"]="0"; //default value
449 _properties["nb_node"] = text.toStdString();
450 if (properties["nb_node"] != text.toStdString())
454 void FormAdvParamContainer::onModifyProcs(const QString &text)
456 DEBTRACE("onModifyProcs " << text.toStdString());
457 if (!_container) return;
458 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
459 map<string,string> properties = _container->getProperties();
460 if(properties.count("nb_proc_per_node")==0 )properties["nb_proc_per_node"]="0"; //default value
461 _properties["nb_proc_per_node"] = text.toStdString();
462 if (properties["nb_proc_per_node"] != text.toStdString())
466 void FormAdvParamContainer::onModifyCompos(const QString &text)
468 DEBTRACE("onModifyCompo " << text.toStdString());
469 if (!_container) return;
470 map<string,string> properties = _container->getProperties();
471 _properties["nb_component_nodes"] = text.toStdString();
472 if (properties["nb_component_nodes"] != text.toStdString())
476 void FormAdvParamContainer::onModifyProcPar(const QString &text)
478 DEBTRACE("onModifyProcPar " << text.toStdString());
479 if (!_container) return;
480 map<string,string> properties = _container->getProperties();
481 _properties["nb_parallel_procs"] = text.toStdString();
482 if (properties["nb_parallel_procs"] != text.toStdString())
486 void FormAdvParamContainer::onModifyResourceName(const QString &text)
488 DEBTRACE("onModifyResourceName " << text.toStdString());
489 if (!_container) return;
490 map<string,string> properties = _container->getProperties();
491 _properties["resource_name"] = text.toStdString();
492 if (properties["resource_name"] != text.toStdString())
496 void FormAdvParamContainer::onModifyHostName(const QString &text)
498 DEBTRACE("onModifyHostName " << text.toStdString());
499 if (!_container) return;
500 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
502 map<string,string> properties = _container->getProperties();
503 _properties["hostname"] = text.toStdString();
504 if (properties["hostname"] != text.toStdString())
508 void FormAdvParamContainer::onModifyProcRes(const QString &text)
510 DEBTRACE("onModifyProcRes " << text.toStdString());
511 if (!_container) return;
512 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
513 map<string,string> properties = _container->getProperties();
514 if(properties.count("nb_resource_procs")==0 )properties["nb_resource_procs"]="0"; //default value
515 _properties["nb_resource_procs"] = text.toStdString();
516 if (properties["nb_resource_procs"] != text.toStdString())
520 void FormAdvParamContainer::onModifyCompoList(const QString &text)
522 DEBTRACE("onModifyCompoList " << text.toStdString());
523 if (!_container) return;
524 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
525 map<string,string> properties = _container->getProperties();
526 _properties["component_list"] = text.toStdString();
527 if (properties["component_list"] != text.toStdString())
531 void FormAdvParamContainer::onModifyResourceList(const QString &text)
533 DEBTRACE("onModifyResourceList " << text.toStdString());
534 if (!_container) return;
535 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
536 map<string,string> properties = _container->getProperties();
537 _properties["resource_list"] = text.toStdString();
538 if (properties["resource_list"] != text.toStdString())
542 void FormAdvParamContainer::onModifyUsePyCache(int val)
547 if(val==Qt::Unchecked)
551 bool prop = _container->isUsingPythonCache();
554 _container->usePythonCache(val2);
555 map<string,string> properties = _container->getProperties();
556 _properties[Container::USE_PYCACHE_PROPERTY] = properties[Container::USE_PYCACHE_PROPERTY];