1 // Copyright (C) 2006-2012 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.
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 "FormContainer.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 bool FormContainer::_checked = false;
42 FormContainer::FormContainer(QWidget *parent)
49 icon.addFile("icons:icon_down.png");
50 icon.addFile("icons:icon_up.png",
51 QSize(), QIcon::Normal, QIcon::On);
52 tb_container->setIcon(icon);
53 on_tb_container_toggled(FormContainer::_checked);
54 on_ch_advance_stateChanged(0);
56 sb_mem->setMaximum(INT_MAX);
57 sb_cpu->setMaximum(INT_MAX);
58 sb_nbNodes->setMaximum(INT_MAX);
59 sb_procNode->setMaximum(INT_MAX);
60 sb_nbprocpar->setMaximum(INT_MAX);
61 sb_nbproc->setMaximum(INT_MAX);
64 FillPanel(0); // --- set widgets before signal connexion to avoid false modif detection
66 connect(le_name, SIGNAL(textChanged(const QString&)),
67 this, SLOT(onModifyName(const QString&)));
69 connect(cb_resource, SIGNAL(activated(const QString&)),
70 this, SLOT(onModifyResource(const QString&)));
72 connect(cb_policy, SIGNAL(activated(const QString&)),
73 this, SLOT(onModifyPolicy(const QString&)));
75 connect(cb_type, SIGNAL(activated(const QString&)),
76 this, SLOT(onModifyType(const QString&)));
78 connect(cb_parallel, SIGNAL(activated(const QString&)),
79 this, SLOT(onModifyParLib(const QString&)));
81 connect(le_workdir, SIGNAL(textChanged(const QString&)),
82 this, SLOT(onModifyWorkDir(const QString&)));
84 connect(le_contname, SIGNAL(textChanged(const QString&)),
85 this, SLOT(onModifyContName(const QString&)));
87 connect(le_os, SIGNAL(textChanged(const QString&)),
88 this, SLOT(onModifyOS(const QString&)));
90 connect(le_hostname, SIGNAL(textChanged(const QString&)),
91 this, SLOT(onModifyHostName(const QString&)));
93 connect(le_compolist, SIGNAL(textChanged(const QString&)),
94 this, SLOT(onModifyCompoList(const QString&)));
96 connect(le_resourceList, SIGNAL(textChanged(const QString&)),
97 this, SLOT(onModifyResourceList(const QString&)));
99 connect(ch_mpi, SIGNAL(clicked(bool)),
100 this, SLOT(onModifyIsMPI(bool)));
102 connect(sb_mem, SIGNAL(valueChanged(const QString&)),
103 this, SLOT(onModifyMem(const QString&)));
105 connect(sb_cpu, SIGNAL(valueChanged(const QString&)),
106 this, SLOT(onModifyClock(const QString&)));
108 connect(sb_nbNodes, SIGNAL(valueChanged(const QString&)),
109 this, SLOT(onModifyNodes(const QString&)));
111 connect(sb_procNode, SIGNAL(valueChanged(const QString&)),
112 this, SLOT(onModifyProcs(const QString&)));
114 connect(sb_nbprocpar, SIGNAL(valueChanged(const QString&)),
115 this, SLOT(onModifyProcPar(const QString&)));
117 connect(sb_nbproc, SIGNAL(valueChanged(const QString&)),
118 this, SLOT(onModifyProcRes(const QString&)));
121 FormContainer::~FormContainer()
125 void FormContainer::FillPanel(YACS::ENGINE::Container *container)
127 DEBTRACE("FormContainer::FillPanel");
128 _container = container;
131 _properties = _container->getProperties();
132 le_name->setText(_container->getName().c_str());
137 le_name->setText("not defined");
141 cb_type->addItem("mono");
142 cb_type->addItem("multi");
143 if(_properties.count("type") && _properties["type"]=="multi")
145 cb_type->setCurrentIndex(1);
146 cb_mode->setText("multi");
149 cb_mode->setText("mono");
152 vector<string> parlibs;
153 parlibs.push_back("");
154 parlibs.push_back("Mpi");
155 parlibs.push_back("Dummy");
156 cb_parallel->clear();
157 for(int i=0; i< parlibs.size(); i++)
158 cb_parallel->addItem(parlibs[i].c_str());
159 if(_properties.count("parallelLib"))
162 for(i=0; i< parlibs.size(); i++)
163 if(parlibs[i] == _properties["parallelLib"])
165 cb_parallel->setCurrentIndex(i);
170 cb_parallel->setCurrentIndex(0);
172 if(_properties.count("workingdir"))
173 le_workdir->setText(_properties["workingdir"].c_str());
175 le_workdir->setText("");
177 if(_properties.count("container_name"))
178 le_contname->setText(_properties["container_name"].c_str());
180 le_contname->setText("");
182 if(_properties.count("isMPI"))
184 DEBTRACE("_properties[isMPI]=" << _properties["isMPI"]);
185 if ((_properties["isMPI"] == "0") || (_properties["isMPI"] == "false"))
186 ch_mpi->setCheckState(Qt::Unchecked);
188 ch_mpi->setCheckState(Qt::Checked);
191 ch_mpi->setCheckState(Qt::Unchecked);
193 if(_properties.count("nb_parallel_procs"))
194 sb_nbprocpar->setValue(atoi(_properties["nb_parallel_procs"].c_str()));
196 sb_nbprocpar->setValue(0);
199 cb_resource->clear();
200 cb_resource->addItem("automatic"); // --- when no resource is selected
202 //add available resources
203 list<string> machines = QtGuiContext::getQtCurrent()->getGMain()->getMachineList();
204 list<string>::iterator itm = machines.begin();
205 for( ; itm != machines.end(); ++itm)
207 cb_resource->addItem(QString((*itm).c_str()));
210 std::string resource="";
211 if(_properties.count("name") && _properties["name"] != "")
213 //a resource has been specified
214 int index = cb_resource->findText(_properties["name"].c_str());
217 //the resource is found: use it
218 cb_resource->setCurrentIndex(index);
219 resource=_properties["name"];
223 //the resource has not been found: add a false item
224 std::string item="Unknown resource ("+_properties["name"]+")";
225 cb_resource->addItem(item.c_str());
226 cb_resource->setCurrentIndex(cb_resource->count()-1);
230 cb_resource->setCurrentIndex(0);
231 updateResource(resource);
233 if (!QtGuiContext::getQtCurrent()->isEdition())
235 //if the schema is in execution do not allow editing
236 le_name->setReadOnly(true);
237 cb_type->setEnabled(false);
238 cb_parallel->setEnabled(false);
239 le_workdir->setReadOnly(true);
240 le_contname->setReadOnly(true);
241 ch_mpi->setEnabled(false);
242 sb_nbprocpar->setReadOnly(true);
243 cb_resource->setEnabled(false);
244 le_hostname->setEnabled(false);
245 le_os->setEnabled(false);
246 sb_nbproc->setEnabled(false);
247 sb_mem->setEnabled(false);
248 sb_cpu->setEnabled(false);
249 sb_nbNodes->setEnabled(false);
250 sb_procNode->setEnabled(false);
251 cb_policy->setEnabled(false);
252 le_compolist->setEnabled(false);
253 le_resourceList->setEnabled(false);
257 void FormContainer::onModified()
259 DEBTRACE("FormContainer::onModified");
260 Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
262 YASSERT(QtGuiContext::getQtCurrent()->_mapOfEditionItem.count(sub));
263 QWidget *widget = QtGuiContext::getQtCurrent()->_mapOfEditionItem[sub];
264 ItemEdition *item = dynamic_cast<ItemEdition*>(widget);
266 item->setEdited(true);
269 void FormContainer::on_tb_container_toggled(bool checked)
271 DEBTRACE("FormContainer::on_tb_container_toggled " << checked);
273 if (_checked) gb_basic->show();
274 else gb_basic->hide();
277 void FormContainer::on_ch_advance_stateChanged(int state)
279 DEBTRACE("FormContainer::on_ch_advance_stateChanged " << state);
280 if (state) tw_advance->show();
281 else tw_advance->hide();
284 void FormContainer::onModifyName(const QString &text)
286 DEBTRACE("onModifyName " << text.toStdString());
287 SubjectContainer *scont =
288 QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container];
290 string name = scont->getName();
291 if (name != text.toStdString())
295 void FormContainer::updateResource(const std::string &resource)
297 DEBTRACE("FormContainer::updateResource " << resource);
300 //the resource is not specified: use automatic and allow editing
301 if(_properties.count("hostname"))
302 le_hostname->setText(_properties["hostname"].c_str());
304 le_hostname->setText("");
305 le_hostname->setEnabled(true);
307 if(_properties.count("OS"))
308 le_os->setText(_properties["OS"].c_str());
311 le_os->setEnabled(true);
313 if(_properties.count("nb_resource_procs"))
314 sb_nbproc->setValue(atoi(_properties["nb_resource_procs"].c_str()));
316 sb_nbproc->setValue(0);
317 sb_nbproc->setEnabled(true);
319 if(_properties.count("mem_mb"))
320 sb_mem->setValue(atoi(_properties["mem_mb"].c_str()));
323 sb_mem->setEnabled(true);
325 if(_properties.count("cpu_clock"))
326 sb_cpu->setValue(atoi(_properties["cpu_clock"].c_str()));
329 sb_cpu->setEnabled(true);
331 if(_properties.count("nb_node"))
332 sb_nbNodes->setValue(atoi(_properties["nb_node"].c_str()));
334 sb_nbNodes->setValue(0);
335 sb_nbNodes->setEnabled(true);
337 if(_properties.count("nb_proc_per_node"))
338 sb_procNode->setValue(atoi(_properties["nb_proc_per_node"].c_str()));
340 sb_procNode->setValue(0);
341 sb_procNode->setEnabled(true);
343 std::vector<std::string> policies;
344 policies.push_back("cycl");
345 policies.push_back("altcycl");
346 policies.push_back("best");
347 policies.push_back("first");
349 for(int i=0; i< policies.size(); i++)
350 cb_policy->addItem(policies[i].c_str());
351 if(_properties.count("policy"))
354 for(i=0; i< policies.size(); i++)
355 if(policies[i] == _properties["policy"])
357 cb_policy->setCurrentIndex(i);
362 cb_policy->setCurrentIndex(1);
363 cb_policy->setEnabled(true);
365 if(_properties.count("component_list"))
366 le_compolist->setText(_properties["component_list"].c_str());
368 le_compolist->setText("");
369 le_compolist->setEnabled(true);
371 if(_properties.count("resource_list"))
372 le_resourceList->setText(_properties["resource_list"].c_str());
374 le_resourceList->setText("");
375 le_resourceList->setEnabled(true);
379 //a specific resource has been chosen: properties are those declared in the resources manager
380 //properties can not be edited
381 std::map<std::string,std::string> properties= _container->getResourceProperties(resource);
382 if(properties.count("hostname"))
383 le_hostname->setText(properties["hostname"].c_str());
385 le_hostname->setText("");
386 le_hostname->setEnabled(false);
388 if(properties.count("OS"))
389 le_os->setText(properties["OS"].c_str());
392 le_os->setEnabled(false);
394 if(properties.count("nb_resource_procs"))
395 sb_nbproc->setValue(atoi(properties["nb_resource_procs"].c_str()));
397 sb_nbproc->setValue(0);
398 sb_nbproc->setEnabled(false);
400 if(properties.count("mem_mb"))
401 sb_mem->setValue(atoi(properties["mem_mb"].c_str()));
404 sb_mem->setEnabled(false);
406 if(properties.count("cpu_clock"))
407 sb_cpu->setValue(atoi(properties["cpu_clock"].c_str()));
410 sb_cpu->setEnabled(false);
412 if(properties.count("nb_node"))
413 sb_nbNodes->setValue(atoi(properties["nb_node"].c_str()));
415 sb_nbNodes->setValue(0);
416 sb_nbNodes->setEnabled(false);
418 if(properties.count("nb_proc_per_node"))
419 sb_procNode->setValue(atoi(properties["nb_proc_per_node"].c_str()));
421 sb_procNode->setValue(0);
422 sb_procNode->setEnabled(false);
425 cb_policy->setEnabled(false);
427 if(properties.count("component_list"))
428 le_compolist->setText(properties["component_list"].c_str());
430 le_compolist->setText("");
431 le_compolist->setEnabled(false);
433 if(properties.count("resource_list"))
434 le_resourceList->setText(properties["resource_list"].c_str());
436 le_resourceList->setText("");
437 le_resourceList->setEnabled(false);
441 void FormContainer::onModifyResource(const QString &text)
443 DEBTRACE("onModifyResource " << text.toStdString());
444 if (!_container) return;
445 std::string resource=text.toStdString();
446 if(resource=="automatic")resource="";
447 map<string,string> properties = _container->getProperties();
448 _properties["name"] = resource;
449 if (properties["name"] != resource)
451 // reset resource properties
452 _properties.erase("hostname");
453 _properties.erase("OS");
454 _properties.erase("nb_resource_procs");
455 _properties.erase("mem_mb");
456 _properties.erase("cpu_clock");
457 _properties.erase("nb_node");
458 _properties.erase("nb_proc_per_node");
459 _properties.erase("policy");
461 updateResource(resource);
465 void FormContainer::onModifyType(const QString &text)
467 DEBTRACE("onModifyType " << text.toStdString());
468 if (!_container) return;
469 std::string prop=_container->getProperty("type");
470 _properties["type"] = text.toStdString();
471 if (_properties["type"] == "mono")
472 cb_mode->setText("mono");
474 cb_mode->setText("multi");
475 if (prop != text.toStdString())
479 void FormContainer::onModifyPolicy(const QString &text)
481 DEBTRACE("onModifyPolicy " << text.toStdString());
482 if (!_container) return;
483 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
484 map<string,string> properties = _container->getProperties();
485 _properties["policy"] = text.toStdString();
486 if (properties["policy"] != text.toStdString())
492 void FormContainer::onModifyWorkDir(const QString &text)
494 DEBTRACE("onModifyWorkDir " << text.toStdString());
495 if (!_container) return;
496 map<string,string> properties = _container->getProperties();
497 _properties["workingdir"] = text.toStdString();
498 if (properties["workingdir"] != text.toStdString())
504 void FormContainer::onModifyContName(const QString &text)
506 DEBTRACE("onModifyContName " << text.toStdString());
507 if (!_container) return;
508 map<string,string> properties = _container->getProperties();
509 _properties["container_name"] = text.toStdString();
510 if (properties["container_name"] != text.toStdString())
516 void FormContainer::onModifyOS(const QString &text)
518 DEBTRACE("onModifyOS " << text.toStdString());
519 if (!_container) return;
520 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
521 map<string,string> properties = _container->getProperties();
522 _properties["OS"] = text.toStdString();
523 if (properties["OS"] != text.toStdString())
529 void FormContainer::onModifyParLib(const QString &text)
531 DEBTRACE("onModifyParLib " << text.toStdString());
532 if (!_container) return;
533 map<string,string> properties = _container->getProperties();
534 _properties["parallelLib"] = text.toStdString();
535 if (properties["parallelLib"] != text.toStdString())
541 void FormContainer::onModifyIsMPI(bool isMpi)
543 DEBTRACE("onModifyIsMPI " << isMpi);
544 if (!_container) return;
545 string text = "false";
546 if (isMpi) text = "true";
548 map<string,string> properties = _container->getProperties();
549 _properties["isMPI"] = text;
550 if (properties["isMPI"] != text)
556 void FormContainer::onModifyMem(const QString &text)
558 DEBTRACE("onModifyMem " << text.toStdString());
559 if (!_container) return;
560 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
561 map<string,string> properties = _container->getProperties();
562 if(properties.count("mem_mb")==0 )properties["mem_mb"]="0"; //default value
563 _properties["mem_mb"] = text.toStdString();
564 if (properties["mem_mb"] != text.toStdString())
570 void FormContainer::onModifyClock(const QString &text)
572 DEBTRACE("onModifyClock " << text.toStdString());
573 if (!_container) return;
574 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
575 map<string,string> properties = _container->getProperties();
576 if(properties.count("cpu_clock")==0 )properties["cpu_clock"]="0"; //default value
577 _properties["cpu_clock"] = text.toStdString();
578 if (properties["cpu_clock"] != text.toStdString())
584 void FormContainer::onModifyNodes(const QString &text)
586 DEBTRACE("onModifyNodes " << text.toStdString());
587 if (!_container) return;
588 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
589 map<string,string> properties = _container->getProperties();
590 if(properties.count("nb_node")==0 )properties["nb_node"]="0"; //default value
591 _properties["nb_node"] = text.toStdString();
592 if (properties["nb_node"] != text.toStdString())
598 void FormContainer::onModifyProcs(const QString &text)
600 DEBTRACE("onModifyProcs " << text.toStdString());
601 if (!_container) return;
602 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
603 map<string,string> properties = _container->getProperties();
604 if(properties.count("nb_proc_per_node")==0 )properties["nb_proc_per_node"]="0"; //default value
605 _properties["nb_proc_per_node"] = text.toStdString();
606 if (properties["nb_proc_per_node"] != text.toStdString())
612 void FormContainer::onModifyCompos(const QString &text)
614 DEBTRACE("onModifyCompo " << text.toStdString());
615 if (!_container) return;
616 map<string,string> properties = _container->getProperties();
617 _properties["nb_component_nodes"] = text.toStdString();
618 if (properties["nb_component_nodes"] != text.toStdString())
624 void FormContainer::onModifyProcPar(const QString &text)
626 DEBTRACE("onModifyProcPar " << text.toStdString());
627 if (!_container) return;
628 map<string,string> properties = _container->getProperties();
629 _properties["nb_parallel_procs"] = text.toStdString();
630 if (properties["nb_parallel_procs"] != text.toStdString())
636 void FormContainer::onModifyResourceName(const QString &text)
638 DEBTRACE("onModifyResourceName " << text.toStdString());
639 if (!_container) return;
640 map<string,string> properties = _container->getProperties();
641 _properties["resource_name"] = text.toStdString();
642 if (properties["resource_name"] != text.toStdString())
648 void FormContainer::onModifyHostName(const QString &text)
650 DEBTRACE("onModifyHostName " << text.toStdString());
651 if (!_container) return;
652 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
654 map<string,string> properties = _container->getProperties();
655 _properties["hostname"] = text.toStdString();
656 if (properties["hostname"] != text.toStdString())
662 void FormContainer::onModifyProcRes(const QString &text)
664 DEBTRACE("onModifyProcRes " << text.toStdString());
665 if (!_container) return;
666 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
667 map<string,string> properties = _container->getProperties();
668 if(properties.count("nb_resource_procs")==0 )properties["nb_resource_procs"]="0"; //default value
669 _properties["nb_resource_procs"] = text.toStdString();
670 if (properties["nb_resource_procs"] != text.toStdString())
676 void FormContainer::onModifyCompoList(const QString &text)
678 DEBTRACE("onModifyCompoList " << text.toStdString());
679 if (!_container) return;
680 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
681 map<string,string> properties = _container->getProperties();
682 _properties["component_list"] = text.toStdString();
683 if (properties["component_list"] != text.toStdString())
689 void FormContainer::onModifyResourceList(const QString &text)
691 DEBTRACE("onModifyResourceList " << text.toStdString());
692 if (!_container) return;
693 if(_properties.count("name") && _properties["name"] != "")return; //do not modify resource parameter when specific resource is set
694 map<string,string> properties = _container->getProperties();
695 _properties["resource_list"] = text.toStdString();
696 if (properties["resource_list"] != text.toStdString())
703 bool FormContainer::onApply()
705 SubjectContainer *scont =
706 QtGuiContext::getQtCurrent()->_mapOfSubjectContainer[_container];
708 bool ret = scont->setProperties(_properties);
710 if (ret) ret = scont->setName(le_name->text().toStdString());