1 // Copyright (C) 2009-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 "BL_CreateJobWizard.hxx"
21 #include "BL_JobsManager_QT.hxx"
26 #include <sys/types.h>
34 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
36 DEBTRACE("Creating BL::CreateJobWizard");
37 BL_ASSERT(jobs_manager);
38 BL_ASSERT(salome_services);
39 _jobs_manager = jobs_manager;
40 _salome_services = salome_services;
45 python_salome_file = "";
48 maximum_duration = "";
52 result_directory = "";
54 resource_choosed = "";
61 setOptions(QWizard::NoBackButtonOnStartPage);
64 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
66 setPage(Page_JobName, _job_name_page);
67 setPage(Page_BatchParameters, new BL::BatchParametersPage(this, salome_services));
68 setPage(Page_Files, new BL::FilesPage(this));
69 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
70 setPage(Page_Conclusion, new BL::ConclusionPage(this));
73 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
74 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
75 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
77 setWindowTitle("Create Job Wizard");
78 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
81 BL::CreateJobWizard::~CreateJobWizard()
83 DEBTRACE("Destroying BL::CreateJobWizard");
87 BL::CreateJobWizard::clone(const std::string & name)
89 if (_jobs_manager->job_already_exist(name) == true)
91 BL::Job * job = _jobs_manager->getJob(name);
93 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
94 if (job->getState() == BL::Job::CREATED ||
95 job->getState() == BL::Job::ERROR ||
96 job->getState() == BL::Job::FAILED ||
97 job->getState() == BL::Job::NOT_CREATED)
99 setField("job_name", QString(name.c_str()));
100 _job_name_page->_check_name = false;
103 if (job->getType() == BL::Job::YACS_SCHEMA)
105 setField("yacs_file", QString(job->getJobFile().c_str()));
106 _job_name_page->_yacs_schema_button->click();
107 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
108 if (job->getDumpYACSState() != -1)
111 value.setNum(job->getDumpYACSState());
112 setField("dump_yacs_state", value);
115 else if (job->getType() == BL::Job::COMMAND)
117 setField("command", QString(job->getJobFile().c_str()));
118 _job_name_page->_command_button->click();
119 setField("env_command_file", QString(job->getEnvFile().c_str()));
121 else if (job->getType() == BL::Job::PYTHON_SALOME)
123 setField("PythonSalome", QString(job->getJobFile().c_str()));
124 _job_name_page->_python_salome_button->click();
125 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
128 BL::Job::BatchParam batch_params = job->getBatchParameters();
129 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
131 proc_value.setNum(batch_params.nb_proc);
132 setField("proc_value", proc_value);
134 if (batch_params.maximum_duration == "")
136 setField("duration_hour", 0);
137 setField("duration_min", 0);
141 std::size_t pos = batch_params.maximum_duration.find(":");
142 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
144 std::istringstream iss_hour(hour_str);
146 setField("duration_hour", hour);
148 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
150 std::istringstream iss_min(min_str);
152 setField("duration_min", min);
155 std::string mem_type = batch_params.expected_memory.substr(batch_params.expected_memory.size() - 2, 2);
156 if (mem_type == "mb")
157 setField("mem_type", 0);
159 setField("mem_type", 1);
160 std::string mem_value = batch_params.expected_memory.substr(0, batch_params.expected_memory.find(mem_type));
162 std::istringstream iss_mem(mem_value);
164 setField("mem_value", mem_val);
166 BL::Job::FilesParam files_params = job->getFilesParameters();
168 std::list<std::string>::iterator it = files_params.input_files_list.begin();
169 for (; it != files_params.input_files_list.end(); it++)
170 _input_files_list->addItem(QString((*it).c_str()));
171 it = files_params.output_files_list.begin();
172 for (; it != files_params.output_files_list.end(); it++)
173 _output_files_list->addItem(QString((*it).c_str()));
175 setField("result_directory", QString(files_params.result_directory.c_str()));
176 setField("resource_choosed", QString(job->getResource().c_str()));
177 setField("batch_queue", QString(job->getBatchQueue().c_str()));
178 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
183 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
185 _input_files_list = input_files_list;
186 _output_files_list = output_files_list;
190 BL::CreateJobWizard::end(int result)
192 DEBTRACE("End of BL::CreateJobWizard");
196 QString f_job_name = field("job_name").toString();
197 job_name = f_job_name.toStdString();
200 QString f_yacs_file = field("yacs_file").toString();
201 yacs_file = f_yacs_file.toStdString();
202 dump_yacs_state = field("dump_yacs_state").toInt();
205 QString f_command = field("command").toString();
206 command = f_command.toStdString();
209 QString f_python_salome_file = field("PythonSalome").toString();
210 python_salome_file = f_python_salome_file.toStdString();
214 f_env_file = field("env_yacs_file").toString();
215 else if (command != "")
216 f_env_file = field("env_command_file").toString();
217 else if (python_salome_file != "")
218 f_env_file = field("env_PythonSalome_file").toString();
219 env_file = f_env_file.toStdString();
222 QString f_batch_directory = field("batch_directory").toString();
223 batch_directory = f_batch_directory.toStdString();
227 if(field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0)
229 maximum_duration = "";
233 if (field("duration_hour").toInt() < 10)
234 time_hour = "0" + field("duration_hour").toString();
236 time_hour = field("duration_hour").toString();
237 if (field("duration_min").toInt() < 10)
238 time_min = "0" + field("duration_min").toString();
240 time_min = field("duration_min").toString();
241 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
244 QString mem = field("mem_value").toString();
245 int mem_type_i = field("mem_type").toInt();
246 QString mem_type("gb");
249 expected_memory = mem.toStdString() + mem_type.toStdString();
251 nb_proc = field("proc_value").toInt();
254 QString f_result_directory = field("result_directory").toString();
255 result_directory = f_result_directory.toStdString();
256 for (int i = 0; i < _input_files_list->count(); ++i)
258 QListWidgetItem * item = _input_files_list->item(i);
259 QString item_text = item->text();
260 input_files_list.push_back(item_text.toStdString());
262 for (int i = 0; i < _output_files_list->count(); ++i)
264 QListWidgetItem * item = _output_files_list->item(i);
265 QString item_text = item->text();
266 output_files_list.push_back(item_text.toStdString());
270 QString f_resource_choosed = field("resource_choosed").toString();
271 resource_choosed = f_resource_choosed.toStdString();
274 QString f_batch_queue = field("batch_queue").toString();
275 batch_queue = f_batch_queue.toStdString();
277 // LoadLeveler JobType
278 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
279 std::string batch = resource_descr.batch.c_str();
282 QString f_ll_jobtype = field("ll_jobtype").toString();
283 ll_jobtype = f_ll_jobtype.toStdString();
290 start_job = field("start_job").toBool();
295 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
296 : QWizardPage(parent)
298 _jobs_manager = jobs_manager;
300 setTitle("Create a new job");
302 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
303 label->setWordWrap(true);
304 QLabel * nameLabel = new QLabel("Job Name:");
305 QLineEdit * _nameLineEdit = new QLineEdit(this);
306 registerField("job_name", _nameLineEdit);
308 QLabel * label_type = new QLabel("Choose type of batch job:");
309 QGroupBox *groupBox = new QGroupBox("Type of job");
310 _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
311 _yacs_schema_button->setChecked(true);
312 _command_button = new QRadioButton(tr("Command"));
313 _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
314 QVBoxLayout *vbox = new QVBoxLayout;
315 vbox->addWidget(_yacs_schema_button);
316 vbox->addWidget(_command_button);
317 vbox->addWidget(_python_salome_button);
319 groupBox->setLayout(vbox);
321 QGroupBox * explanationBox = new QGroupBox("Explanation");
322 QVBoxLayout *explanationvbox = new QVBoxLayout;
323 _explanation = new QLabel();
324 _explanation->setWordWrap(true);
325 explanationvbox->addWidget(_explanation);
326 explanationvbox->addStretch(1);
327 explanationBox->setLayout(explanationvbox);
330 QVBoxLayout * main_layout = new QVBoxLayout;
331 main_layout->addWidget(label);
332 QGridLayout *layout = new QGridLayout;
333 layout->addWidget(nameLabel, 0, 0);
334 layout->addWidget(_nameLineEdit, 0, 1);
335 main_layout->insertLayout(-1, layout);
336 layout->addWidget(label_type, 2, 0);
337 layout->addWidget(groupBox, 3, 0, 1, -1);
338 layout->addWidget(explanationBox, 4, 0, 1, -1);
339 setLayout(main_layout);
341 connect(_yacs_schema_button, SIGNAL(clicked(bool)), this, SLOT(yacs_schema_button(bool)));
342 connect(_command_button, SIGNAL(clicked(bool)), this, SLOT(command_button(bool)));
343 connect(_python_salome_button, SIGNAL(clicked(bool)), this, SLOT(python_salome_button(bool)));
346 yacs_schema_button(true);
349 BL::JobNamePage::~JobNamePage()
353 BL::JobNamePage::yacs_schema_button(bool checked)
356 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
360 BL::JobNamePage::command_button(bool checked)
363 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
367 BL::JobNamePage::python_salome_button(bool checked)
370 _explanation->setText("This job permits to launch a python script into a SALOME application");
374 BL::JobNamePage::validatePage()
376 DEBTRACE("Calling validatePage of BL::JobNamePage");
378 QString job_name = field("job_name").toString();
380 // Check if job name is empty
383 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
384 return_value = false;
387 // Check if job name already exists
389 if (_jobs_manager->job_already_exist(job_name.toStdString()) == false || _check_name == false)
395 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
397 setField("job_name", value);
398 return_value = false;
406 BL::JobNamePage::nextId() const
408 if (_yacs_schema_button->isChecked())
410 return BL::CreateJobWizard::Page_YACSSchema;
412 else if (_command_button->isChecked())
414 return BL::CreateJobWizard::Page_Command_Main_Definitions;
418 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
422 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
423 : QWizardPage(parent)
425 setTitle("Configure YACS Execution");
427 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
428 label->setWordWrap(true);
430 QGroupBox * files_param_box = new QGroupBox("YACS job files");
431 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
432 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
433 _yacs_file_text = new QLineEdit(this);
434 _yacs_file_text->setText("");
435 registerField("yacs_file", _yacs_file_text);
436 _yacs_file_text->setReadOnly(true);
437 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
438 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
439 _line_env_file = new QLineEdit(this);
440 registerField("env_yacs_file", _line_env_file);
441 _line_env_file->setReadOnly(true);
442 QGridLayout * files_layout = new QGridLayout;
443 files_layout->addWidget(yacs_file_button, 0, 0);
444 files_layout->addWidget(_yacs_file_text, 0, 1);
445 files_layout->addWidget(command_env_file_button, 1, 0);
446 files_layout->addWidget(_line_env_file, 1, 1);
447 files_param_box->setLayout(files_layout);
449 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
450 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
451 QLabel * label_dump_warning = new QLabel("(WARNING: can only be used with SALOME >= 6.3.0)");
452 QSpinBox * spin_dump = new QSpinBox(this);
453 spin_dump->setMinimum(0);
454 spin_dump->setMaximum(1000000);
455 registerField("dump_yacs_state", spin_dump);
456 QGridLayout * specific_layout = new QGridLayout;
457 specific_layout->addWidget(label_dump, 0, 0);
458 specific_layout->addWidget(spin_dump, 0, 1);
459 specific_layout->addWidget(label_dump_warning, 1, 0);
460 spec_param_box->setLayout(specific_layout);
462 QVBoxLayout * main_layout = new QVBoxLayout;
463 main_layout->addWidget(label);
464 main_layout->addWidget(files_param_box);
465 main_layout->addWidget(spec_param_box);
467 setLayout(main_layout);
470 BL::YACSSchemaPage::~YACSSchemaPage()
474 BL::YACSSchemaPage::validatePage()
477 QString yacs_file = field("yacs_file").toString();
484 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
485 return_value = false;
491 BL::YACSSchemaPage::choose_file()
493 QString yacs_file = QFileDialog::getOpenFileName(this,
494 tr("Open YACS files"), "",
495 tr("XML (*.xml);;All Files (*)"));
496 _yacs_file_text->setReadOnly(false);
497 _yacs_file_text->setText(yacs_file);
498 _yacs_file_text->setReadOnly(true);
502 BL::YACSSchemaPage::choose_env_file()
504 QString env_file = QFileDialog::getOpenFileName(this,
505 tr("Open environnement file"), "",
506 tr("sh (*.sh);;All Files (*)"));
507 _line_env_file->setReadOnly(false);
508 _line_env_file->setText(env_file);
509 _line_env_file->setReadOnly(true);
514 BL::YACSSchemaPage::nextId() const
516 return BL::CreateJobWizard::Page_Resource;
519 BL::CommandMainPage::CommandMainPage(QWidget * parent)
520 : QWizardPage(parent)
522 setTitle("Define command job");
523 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
524 label->setWordWrap(true);
527 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
528 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
529 _line_command = new QLineEdit(this);
530 registerField("command", _line_command);
531 _line_command->setReadOnly(true);
533 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
534 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
535 _line_env_file = new QLineEdit(this);
536 registerField("env_command_file", _line_env_file);
537 _line_env_file->setReadOnly(true);
539 QGridLayout *layout = new QGridLayout;
540 layout->addWidget(command_file_button, 0, 0);
541 layout->addWidget(_line_command, 0, 1);
542 layout->addWidget(command_env_file_button, 1, 0);
543 layout->addWidget(_line_env_file, 1, 1);
545 QVBoxLayout * main_layout = new QVBoxLayout;
546 main_layout->addWidget(label);
547 main_layout->insertLayout(-1, layout);
548 setLayout(main_layout);
551 BL::CommandMainPage::~CommandMainPage()
555 BL::CommandMainPage::choose_command_file()
557 QString command_file = QFileDialog::getOpenFileName(this,
558 tr("Open command file"), "",
559 tr("sh (*.sh);;All Files (*)"));
560 _line_command->setReadOnly(false);
561 _line_command->setText(command_file);
562 _line_command->setReadOnly(true);
566 BL::CommandMainPage::choose_env_file()
568 QString env_file = QFileDialog::getOpenFileName(this,
569 tr("Open environnement file"), "",
570 tr("sh (*.sh);;All Files (*)"));
571 _line_env_file->setReadOnly(false);
572 _line_env_file->setText(env_file);
573 _line_env_file->setReadOnly(true);
577 BL::CommandMainPage::validatePage()
579 QString command = field("command").toString();
582 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
590 BL::CommandMainPage::nextId() const
592 return BL::CreateJobWizard::Page_Resource;
595 BL::BatchParametersPage::BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
596 : QWizardPage(parent)
598 setTitle("Enter Batch Parameters");
599 resource_choosed = "";
601 _salome_services = salome_services;
603 QLabel *label = new QLabel("In this step you define the parameters of your job");
604 label->setWordWrap(true);
605 QVBoxLayout * main_layout = new QVBoxLayout;
606 main_layout->addWidget(label);
609 QLabel * label_directory = new QLabel("Remote work directory: ");
610 QLineEdit * line_directory = new QLineEdit(this);
611 registerField("batch_directory", line_directory);
613 // exected during time
614 QLabel * label_duration = new QLabel("Maximum during time: ");
615 QSpinBox * spin_duration_hour = new QSpinBox(this);
616 QLabel * label_duration_hour = new QLabel("Hours");
617 spin_duration_hour->setMinimum(0);
618 spin_duration_hour->setMaximum(1000000);
619 registerField("duration_hour", spin_duration_hour);
620 QSpinBox * spin_duration_min = new QSpinBox(this);
621 QLabel * label_duration_min = new QLabel("Minutes");
622 spin_duration_min->setMinimum(0);
623 spin_duration_min->setMaximum(59);
624 registerField("duration_min", spin_duration_min);
627 QLabel * label_memory = new QLabel("Memory per nodes expected: ");
628 QSpinBox * spin_memory = new QSpinBox(this);
629 spin_memory->setMinimum(0);
630 spin_memory->setMaximum(1000000);
631 registerField("mem_value", spin_memory);
632 QComboBox * combo_memory = new QComboBox(this);
633 combo_memory->addItem("MB");
634 combo_memory->addItem("GB");
635 combo_memory->setCurrentIndex(1);
636 registerField("mem_type", combo_memory);
639 QLabel * label_proc = new QLabel("Number of proc expected: ");
640 QSpinBox * spin_proc = new QSpinBox(this);
641 spin_proc->setMinimum(1);
642 spin_proc->setMaximum(1000000);
643 registerField("proc_value", spin_proc);
645 QGridLayout *layout = new QGridLayout;
646 layout->addWidget(label_directory, 0, 0);
647 layout->addWidget(line_directory, 0, 1, 1, -1);
648 layout->addWidget(label_duration, 1, 0);
649 layout->addWidget(spin_duration_hour, 1, 1);
650 layout->addWidget(label_duration_hour, 1, 2);
651 layout->addWidget(spin_duration_min, 1, 3);
652 layout->addWidget(label_duration_min, 1, 4);
653 layout->addWidget(label_memory, 2, 0);
654 layout->addWidget(spin_memory, 2, 1);
655 layout->addWidget(combo_memory, 2, 2);
656 layout->addWidget(label_proc, 3, 0);
657 layout->addWidget(spin_proc, 3, 1);
659 main_layout->insertLayout(-1, layout);
661 setLayout(main_layout);
664 BL::BatchParametersPage::~BatchParametersPage()
667 void BL::BatchParametersPage::cleanupPage() {}
670 BL::BatchParametersPage::initializePage()
672 QString f_resource_choosed = field("resource_choosed").toString();
673 if (f_resource_choosed != resource_choosed)
675 resource_choosed = f_resource_choosed;
676 // If choosed resource has a working_directory set
677 // Generates a default remote working directory
678 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toStdString());
679 QString res_work_dir = resource_descr.working_directory.c_str();
680 if (res_work_dir != "")
684 std::string launch_date = ctime(&rawtime);
685 for (int i = 0; i < launch_date.size(); i++)
686 if (launch_date[i] == '/' ||
687 launch_date[i] == '-' ||
688 launch_date[i] == ':' ||
689 launch_date[i] == ' ')
690 launch_date[i] = '_';
691 launch_date.erase(--launch_date.end()); // Last caracter is a \n
692 QString date = launch_date.c_str();
693 setField("batch_directory", res_work_dir + "/" + date);
699 BL::BatchParametersPage::validatePage()
701 QString batch_directory = field("batch_directory").toString();
702 if (batch_directory == "")
704 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
708 int mem = field("mem_value").toInt();
711 QMessageBox::warning(NULL, "Memory Error", "Please enter an expected memory");
719 BL::BatchParametersPage::nextId() const
721 return BL::CreateJobWizard::Page_Files;
724 BL::FilesPage::FilesPage(BL::CreateJobWizard * parent)
725 : QWizardPage(parent)
727 setTitle("Enter Input and Output Files");
729 QLabel * main_label = new QLabel("In this step you define input and output files of your job");
730 main_label->setWordWrap(true);
733 QGroupBox * input_group_box = new QGroupBox("Input Files");
734 _input_files_button = new QPushButton("Add input files");
735 _input_files_button->show();
736 connect(_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
737 _remove_input_files_button = new QPushButton("Remove input files");
738 _remove_input_files_button->show();
739 _remove_input_files_button->setEnabled(false);
740 connect(_remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
741 _input_files_list = new QListWidget();
742 _input_files_list->setSelectionMode(QAbstractItemView::MultiSelection);
743 connect(_input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
745 QGridLayout * input_box = new QGridLayout;
746 input_box->addWidget(_input_files_button, 0, 0);
747 input_box->addWidget(_remove_input_files_button, 0, 1);
748 input_box->addWidget(_input_files_list, 1, 0, 1, -1);
749 input_group_box->setLayout(input_box);
752 QGroupBox * output_group_box = new QGroupBox("Output Files");
753 _output_files_button = new QPushButton("Add output file");
754 _output_files_button->show();
755 connect(_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
756 _remove_output_files_button = new QPushButton("Remove output files");
757 _remove_output_files_button->show();
758 _remove_output_files_button->setEnabled(false);
759 connect(_remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
760 _output_files_list = new QListWidget();
761 _output_files_list->setSelectionMode(QAbstractItemView::MultiSelection);
762 _output_files_list->setEditTriggers(QAbstractItemView::DoubleClicked);
763 connect(_output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
766 QPushButton * button_result = new QPushButton("Local Result directory");
767 connect(button_result, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
768 _result_directory = new QLineEdit(this);
770 // Default result directory is home directory (if we found it)
773 _result_directory->setText(getenv("HOME"));
776 _result_directory->setText(getenv("HOME"));
778 // Second try -> getpwuid
779 struct passwd * pass_struct = getpwuid(getuid());
781 _result_directory->setText(pass_struct->pw_dir);
784 registerField("result_directory", _result_directory);
786 QGridLayout * output_box = new QGridLayout;
787 output_box->addWidget(_output_files_button, 0, 0);
788 output_box->addWidget(_remove_output_files_button, 0, 1);
789 output_box->addWidget(_output_files_list, 1, 0, 1, -1);
790 output_box->addWidget(button_result, 2, 0);
791 output_box->addWidget(_result_directory, 2, 1, 1, -1);
792 output_group_box->setLayout(output_box);
794 QVBoxLayout * main_layout = new QVBoxLayout;
795 main_layout->addWidget(main_label);
796 main_layout->addWidget(input_group_box);
797 main_layout->addWidget(output_group_box);
798 setLayout(main_layout);
800 parent->setFilesList(_input_files_list, _output_files_list);
803 BL::FilesPage::~FilesPage()
807 BL::FilesPage::validatePage()
809 QString result_directory = field("result_directory").toString();
811 for (int i = 0; i < _output_files_list->count(); ++i)
813 QListWidgetItem * item = _output_files_list->item(i);
814 if (item->text() == "TO EDIT!")
816 QMessageBox::warning(NULL, "Ouput Files Error", "Some output files are not defined !");
821 if (result_directory == "" && _output_files_list->count() != 0)
823 QMessageBox::warning(NULL, "Result Directory Error", "Please enter a result directory or remove output files");
831 BL::FilesPage::choose_input_files()
833 QStringList files = QFileDialog::getOpenFileNames(this,
834 tr("Add input files"), "",
835 tr("All Files (*)"));
836 for (int i = 0; i < files.size(); ++i)
838 if (_input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
839 _input_files_list->addItem(files.at(i));
844 BL::FilesPage::choose_local_directory()
846 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
848 QFileDialog::ShowDirsOnly
849 | QFileDialog::DontResolveSymlinks);
852 _result_directory->setText(dir);
856 BL::FilesPage::remove_input_files()
858 QList<QListWidgetItem *> list = _input_files_list->selectedItems();
859 for (int i = 0; i < list.size(); ++i)
861 int row = _input_files_list->row( list.at(i) );
862 delete _input_files_list->takeItem(row);
867 BL::FilesPage::input_itemSelectionChanged()
869 if (_input_files_list->selectedItems().size() > 0)
870 _remove_input_files_button->setEnabled(true);
872 _remove_input_files_button->setEnabled(false);
876 BL::FilesPage::add_output_file()
878 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
879 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
880 _output_files_list->addItem(new_item);
884 BL::FilesPage::remove_output_files()
886 QList<QListWidgetItem *> list = _output_files_list->selectedItems();
887 for (int i = 0; i < list.size(); ++i)
889 int row = _output_files_list->row( list.at(i) );
890 delete _output_files_list->takeItem(row);
895 BL::FilesPage::output_itemSelectionChanged()
897 if (_output_files_list->selectedItems().size() > 0)
898 _remove_output_files_button->setEnabled(true);
900 _remove_output_files_button->setEnabled(false);
904 BL::FilesPage::nextId() const
906 return BL::CreateJobWizard::Page_Conclusion;
909 BL::ConclusionPage::ConclusionPage(QWidget * parent)
910 : QWizardPage(parent)
912 setTitle("Job definition is finished");
913 QCheckBox * check_box = new QCheckBox("Start job after creation");
914 registerField("start_job", check_box);
915 QVBoxLayout * main_layout = new QVBoxLayout;
916 main_layout->addWidget(check_box);
917 setLayout(main_layout);
920 BL::ConclusionPage::~ConclusionPage()
924 BL::ConclusionPage::validatePage()
930 BL::ConclusionPage::nextId() const
935 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
936 : QWizardPage(parent)
938 _salome_services = salome_services;
939 setTitle("Select a Resource");
941 QLabel * main_label = new QLabel("In this step you select the resource of your job");
942 main_label->setWordWrap(true);
945 QGroupBox * resource_group_box = new QGroupBox("Resource List");
946 _resource_list = new JM::ResourceCatalog(this, _salome_services);
947 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
949 QVBoxLayout * resource_list_layout = new QVBoxLayout();
950 resource_list_layout->addWidget(_resource_list);
951 resource_group_box->setLayout(resource_list_layout);
953 QLabel * resource_label = new QLabel("Resource selected: ");
954 _resource_choosed = new QLineEdit();
955 _resource_choosed->setText("");
956 _resource_choosed->setReadOnly(true);
957 registerField("resource_choosed", _resource_choosed);
959 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
960 QLineEdit * _bqLineEdit = new QLineEdit(this);
961 registerField("batch_queue", _bqLineEdit);
963 _ll_label = new QLabel("LoadLeveler JobType:", this);
964 _ll_value = new QLineEdit(this);
965 registerField("ll_jobtype", _ll_value);
969 _main_layout = new QGridLayout;
970 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
971 _main_layout->addWidget(resource_label, 1, 0);
972 _main_layout->addWidget(_resource_choosed, 1, 1);
973 _main_layout->addWidget(bqLabel, 2, 0);
974 _main_layout->addWidget(_bqLineEdit, 2, 1);
975 setLayout(_main_layout);
979 BL::ResourcePage::~ResourcePage()
983 BL::ResourcePage::initializePage()
985 if (field("ll_jobtype").toString() != "")
987 _main_layout->addWidget(_ll_label, 3, 0);
988 _main_layout->addWidget(_ll_value, 3, 1);
995 BL::ResourcePage::validatePage()
997 QString resource_choosed = field("resource_choosed").toString();
998 if (resource_choosed == "")
1000 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1004 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toStdString());
1005 std::string batch = resource_descr.batch.c_str();
1008 QString ll_jobtype = field("ll_jobtype").toString();
1009 if (ll_jobtype == "")
1011 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1019 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1021 _resource_choosed->setReadOnly(false);
1022 _resource_choosed->setText(item->text());
1023 _resource_choosed->setReadOnly(true);
1025 //Specific parameters for LoadLeveler
1026 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toStdString());
1027 std::string batch = resource_descr.batch.c_str();
1030 _main_layout->addWidget(_ll_label, 3, 0);
1031 _main_layout->addWidget(_ll_value, 3, 1);
1037 _main_layout->removeWidget(_ll_value);
1038 _main_layout->removeWidget(_ll_label);
1045 BL::ResourcePage::nextId() const
1047 return BL::CreateJobWizard::Page_BatchParameters;
1050 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1051 : QWizardPage(parent)
1053 setTitle("Define a Python script in SALOME job");
1054 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1055 label->setWordWrap(true);
1058 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1059 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1060 _line_PythonSalome = new QLineEdit(this);
1061 registerField("PythonSalome", _line_PythonSalome);
1062 _line_PythonSalome->setReadOnly(true);
1064 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1065 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1066 _line_env_file = new QLineEdit(this);
1067 registerField("env_PythonSalome_file", _line_env_file);
1068 _line_env_file->setReadOnly(true);
1070 QGridLayout *layout = new QGridLayout;
1071 layout->addWidget(PythonSalome_file_button, 0, 0);
1072 layout->addWidget(_line_PythonSalome, 0, 1);
1073 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1074 layout->addWidget(_line_env_file, 1, 1);
1076 QVBoxLayout * main_layout = new QVBoxLayout;
1077 main_layout->addWidget(label);
1078 main_layout->insertLayout(-1, layout);
1079 setLayout(main_layout);
1082 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1086 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1088 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1089 tr("Open Python script file"), "",
1090 tr("py (*.py);;All Files (*)"));
1091 _line_PythonSalome->setReadOnly(false);
1092 _line_PythonSalome->setText(PythonSalome_file);
1093 _line_PythonSalome->setReadOnly(true);
1097 BL::PythonSalomeMainPage::choose_env_file()
1099 QString env_file = QFileDialog::getOpenFileName(this,
1100 tr("Open environnement file"), "",
1101 tr("sh (*.sh);;All Files (*)"));
1102 _line_env_file->setReadOnly(false);
1103 _line_env_file->setText(env_file);
1104 _line_env_file->setReadOnly(true);
1108 BL::PythonSalomeMainPage::validatePage()
1110 QString PythonSalome = field("PythonSalome").toString();
1111 if (PythonSalome == "")
1113 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1121 BL::PythonSalomeMainPage::nextId() const
1123 return BL::CreateJobWizard::Page_Resource;