From: ribes Date: Tue, 26 Jan 2010 10:19:39 +0000 (+0000) Subject: - Edit Job and Restart Job work X-Git-Tag: V5_1_4a1~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=757a3e88bb76f0846e5416372950834137926871;p=modules%2Fjobmanager.git - Edit Job and Restart Job work --- diff --git a/src/genericgui/BL_Buttons.cxx b/src/genericgui/BL_Buttons.cxx index 2e82557..b634a93 100644 --- a/src/genericgui/BL_Buttons.cxx +++ b/src/genericgui/BL_Buttons.cxx @@ -28,6 +28,7 @@ BL::Buttons::Buttons(QWidget * parent) : QGroupBox(parent) _create_button = new QPushButton("Create a Job", this); _edit_clone_button = new QPushButton("Edit/Clone a Job", this); _start_button = new QPushButton("Start a Job", this); + _restart_button = new QPushButton("Restart a Job", this); _delete_button = new QPushButton("Delete a Job", this); _get_results_button = new QPushButton("Get Job Results", this); _refresh_button = new QPushButton("Refresh Jobs", this); @@ -36,6 +37,7 @@ BL::Buttons::Buttons(QWidget * parent) : QGroupBox(parent) mainLayout->addWidget(_create_button); mainLayout->addWidget(_edit_clone_button); mainLayout->addWidget(_start_button); + mainLayout->addWidget(_restart_button); mainLayout->addWidget(_delete_button); mainLayout->addWidget(_get_results_button); mainLayout->addWidget(_refresh_button); @@ -73,6 +75,12 @@ BL::Buttons::setStartButtonSlot(QObject * receiver, const char * name) connect(_start_button, SIGNAL(clicked()), receiver, name); } +void +BL::Buttons::setReStartButtonSlot(QObject * receiver, const char * name) +{ + connect(_restart_button, SIGNAL(clicked()), receiver, name); +} + void BL::Buttons::setDeleteButtonSlot(QObject * receiver, const char * name) { @@ -115,6 +123,18 @@ BL::Buttons::disable_start_button() _start_button->setEnabled(false); } +void +BL::Buttons::enable_restart_button() +{ + _restart_button->setEnabled(true); +} + +void +BL::Buttons::disable_restart_button() +{ + _restart_button->setEnabled(false); +} + void BL::Buttons::enable_delete_button() { diff --git a/src/genericgui/BL_Buttons.hxx b/src/genericgui/BL_Buttons.hxx index e364cd7..b26f583 100644 --- a/src/genericgui/BL_Buttons.hxx +++ b/src/genericgui/BL_Buttons.hxx @@ -37,6 +37,7 @@ namespace BL void setCreateButtonSlot(QObject * receiver, const char * name); void setEditCloneButtonSlot(QObject * receiver, const char * name); void setStartButtonSlot(QObject * receiver, const char * name); + void setReStartButtonSlot(QObject * receiver, const char * name); void setDeleteButtonSlot(QObject * receiver, const char * name); void setRefreshButtonSlot(QObject * receiver, const char * name); void setGetResultsButtonSlot(QObject * receiver, const char * name); @@ -47,6 +48,9 @@ namespace BL void enable_start_button(); void disable_start_button(); + void enable_restart_button(); + void disable_restart_button(); + void enable_delete_button(); void disable_delete_button(); @@ -57,6 +61,7 @@ namespace BL QPushButton * _create_button; QPushButton * _edit_clone_button; QPushButton * _start_button; + QPushButton * _restart_button; QPushButton * _delete_button; QPushButton * _get_results_button; QPushButton * _refresh_button; diff --git a/src/genericgui/BL_CreateJobWizard.cxx b/src/genericgui/BL_CreateJobWizard.cxx index e247c87..a2eab56 100644 --- a/src/genericgui/BL_CreateJobWizard.cxx +++ b/src/genericgui/BL_CreateJobWizard.cxx @@ -18,6 +18,7 @@ // #include "BL_CreateJobWizard.hxx" +#include "BL_JobsManager_QT.hxx" BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services) { @@ -75,10 +76,11 @@ BL::CreateJobWizard::clone(const std::string & name) { BL::Job * job = _jobs_manager->getJob(name); - // We can only edit a job in CREATED, ERROR or FINISHED - if (job->getState() == BL::Job::CREATED or BL::Job::FINISHED or BL::Job::ERROR) + // We can only edit a job in CREATED, ERROR + if (job->getState() == BL::Job::CREATED or job->getState() == BL::Job::ERROR) { setField("job_name", QString(name.c_str())); + _job_name_page->_check_name = false; } if (job->getType() == BL::Job::YACS_SCHEMA) @@ -241,6 +243,7 @@ BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager : QWizardPage(parent) { _jobs_manager = jobs_manager; + _check_name = true; setTitle("Create a new job"); QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name"); @@ -330,7 +333,7 @@ BL::JobNamePage::validatePage() // Check if job name already exists else { - if (_jobs_manager->job_already_exist(job_name.toStdString()) == false) + if (_jobs_manager->job_already_exist(job_name.toStdString()) == false or _check_name == false) { return_value = true; } diff --git a/src/genericgui/BL_CreateJobWizard.hxx b/src/genericgui/BL_CreateJobWizard.hxx index 9ee5789..15a0881 100644 --- a/src/genericgui/BL_CreateJobWizard.hxx +++ b/src/genericgui/BL_CreateJobWizard.hxx @@ -23,7 +23,6 @@ #include #include "BL_Traces.hxx" -#include "BL_JobsManager_QT.hxx" #include "BL_SALOMEServices.hxx" #include "JM_ResourceCatalog.hxx" @@ -117,6 +116,7 @@ namespace BL{ QRadioButton * _yacs_schema_button; QRadioButton * _command_button; QRadioButton * _python_salome_button; + bool _check_name; }; class ConclusionPage: virtual public QWizardPage diff --git a/src/genericgui/BL_GenericGui.cxx b/src/genericgui/BL_GenericGui.cxx index 66e912a..022f939 100644 --- a/src/genericgui/BL_GenericGui.cxx +++ b/src/genericgui/BL_GenericGui.cxx @@ -33,7 +33,7 @@ BL::GenericGui::GenericGui(BL::MainWindows_Wrap * wrapper) : QObject(wrapper->ge _salome_services = new BL::SALOMEServices(); if (_salome_services->initNS() == false) DEBMSG("WARNING !!!!! SALOME IS NOT REACHABLE !!!!"); - _jobs_manager = new BL::JobsManager_QT(_dock_parent, _salome_services); + _jobs_manager = new BL::JobsManager_QT(_dock_parent, this, _salome_services); _model_manager = new BL::QModelManager(this, _jobs_manager); _model = _model_manager->getModel(); @@ -45,6 +45,7 @@ BL::GenericGui::GenericGui(BL::MainWindows_Wrap * wrapper) : QObject(wrapper->ge _buttons->setCreateButtonSlot(this, SLOT(create_job())); _buttons->setEditCloneButtonSlot(this, SLOT(edit_clone_job())); _buttons->setStartButtonSlot(this, SLOT(start_job())); + _buttons->setReStartButtonSlot(this, SLOT(restart_job())); _buttons->setDeleteButtonSlot(this, SLOT(delete_job())); _buttons->setRefreshButtonSlot(this, SLOT(refresh_job())); _buttons->setGetResultsButtonSlot(this, SLOT(get_results_job())); @@ -141,6 +142,7 @@ BL::GenericGui::createActions() _create_job_action = _wrapper->createAction("Create a Job", QIcon(), "Create a Job", "Create a Job", 0, _dock_parent, false, this, SLOT(create_job())); _edit_clone_job_action = _wrapper->createAction("Edit/Clone a Job", QIcon(), "Edit/Clone a Job", "Edit/Clone a Job", 0, _dock_parent, false, this, SLOT(edit_clone_job())); _start_job_action = _wrapper->createAction("Start a Job", QIcon(), "Start a Job", "Start a Job", 0, _dock_parent, false, this, SLOT(start_job())); + _restart_job_action = _wrapper->createAction("Restart a Job", QIcon(), "Restart a Job", "Restart a Job", 0, _dock_parent, false, this, SLOT(restart_job())); _delete_job_action = _wrapper->createAction("Delete a Job", QIcon(), "Delete a Job", "Delete a Job", 0, _dock_parent, false, this, SLOT(delete_job())); _refresh_job_action = _wrapper->createAction("Refresh Jobs", QIcon(), "Refresh Jobs", "Refresh Jobs", 0, _dock_parent, false, this, SLOT(refresh_job())); _get_results_job_action = _wrapper->createAction("Get Job Results", QIcon(), "Get Job Results", "Get Job Results", 0, _dock_parent, false, this, SLOT(refresh_job())); @@ -154,6 +156,7 @@ BL::GenericGui::createMenus() _wrapper->addActionToMenu(_create_job_action, menu_id); _wrapper->addActionToMenu(_edit_clone_job_action, menu_id); _wrapper->addActionToMenu(_start_job_action, menu_id); + _wrapper->addActionToMenu(_restart_job_action, menu_id); _wrapper->addActionToMenu(_delete_job_action, menu_id); _wrapper->addActionToMenu(_get_results_job_action, menu_id); _wrapper->addActionToMenu(_refresh_job_action, menu_id); @@ -163,14 +166,14 @@ void BL::GenericGui::create_job() { DEBTRACE("Create Job Slot BL::GenericGui"); - _jobs_manager->create_job_wizard(); + _jobs_manager->create_job(); } void BL::GenericGui::edit_clone_job() { DEBTRACE("Edit/Clone Job Slot BL::GenericGui"); - _jobs_manager->create_job_wizard(_job_name_selected.toStdString()); + _jobs_manager->edit_clone_job(_job_name_selected.toStdString()); } void @@ -181,6 +184,14 @@ BL::GenericGui::start_job() updateButtonsStates(); } +void +BL::GenericGui::restart_job() +{ + DEBTRACE("Restart Job Slot BL::GenericGui"); + _jobs_manager->restart_job(_job_name_selected.toStdString()); + updateButtonsStates(); +} + void BL::GenericGui::refresh_job() { @@ -204,15 +215,21 @@ BL::GenericGui::delete_job() QMessageBox::Ok); if (ret == QMessageBox::Ok) { - _jobs_manager->delete_job(_job_name_selected); - _model_manager->deleteJob(_row_selected); - emit job_deleted(_job_name_selected); - _row_selected = -1; - _job_name_selected = ""; - updateButtonsStates(); + delete_job_internal(); } } +void +BL::GenericGui::delete_job_internal() +{ + _jobs_manager->delete_job(_job_name_selected); + _model_manager->deleteJob(_row_selected); + emit job_deleted(_job_name_selected); + _row_selected = -1; + _job_name_selected = ""; + updateButtonsStates(); +} + void BL::GenericGui::job_selected(const QModelIndex & index) { @@ -246,6 +263,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_get_results_button(); _edit_clone_job_action->setEnabled(false); _buttons->disable_edit_clone_button(); + _restart_job_action->setEnabled(false); + _buttons->disable_restart_button(); } else if (_job_name_selected != "" and _row_selected != -1) { @@ -263,6 +282,8 @@ BL::GenericGui::updateButtonsStates() _buttons->enable_start_button(); _buttons->enable_delete_button(); _buttons->disable_get_results_button(); + _restart_job_action->setEnabled(false); + _buttons->disable_restart_button(); break; case BL::Job::IN_PROCESS: @@ -272,6 +293,8 @@ BL::GenericGui::updateButtonsStates() _buttons->disable_delete_button(); _get_results_job_action->setEnabled(false); _buttons->disable_get_results_button(); + _restart_job_action->setEnabled(false); + _buttons->disable_restart_button(); break; case BL::Job::QUEUED: @@ -281,6 +304,8 @@ BL::GenericGui::updateButtonsStates() _buttons->enable_delete_button(); _get_results_job_action->setEnabled(false); _buttons->disable_get_results_button(); + _restart_job_action->setEnabled(false); + _buttons->disable_restart_button(); break; case BL::Job::RUNNING: @@ -290,6 +315,8 @@ BL::GenericGui::updateButtonsStates() _buttons->enable_delete_button(); _get_results_job_action->setEnabled(false); _buttons->disable_get_results_button(); + _restart_job_action->setEnabled(false); + _buttons->disable_restart_button(); break; case BL::Job::PAUSED: @@ -299,6 +326,8 @@ BL::GenericGui::updateButtonsStates() _buttons->enable_delete_button(); _get_results_job_action->setEnabled(false); _buttons->disable_get_results_button(); + _restart_job_action->setEnabled(false); + _buttons->disable_restart_button(); break; case BL::Job::ERROR: @@ -308,6 +337,8 @@ BL::GenericGui::updateButtonsStates() _buttons->enable_delete_button(); _get_results_job_action->setEnabled(false); _buttons->disable_get_results_button(); + _restart_job_action->setEnabled(true); + _buttons->enable_restart_button(); break; case BL::Job::FINISHED: @@ -317,6 +348,8 @@ BL::GenericGui::updateButtonsStates() _buttons->enable_delete_button(); _get_results_job_action->setEnabled(true); _buttons->enable_get_results_button(); + _restart_job_action->setEnabled(true); + _buttons->enable_restart_button(); break; } } diff --git a/src/genericgui/BL_GenericGui.hxx b/src/genericgui/BL_GenericGui.hxx index 0d0c03d..bc623b6 100644 --- a/src/genericgui/BL_GenericGui.hxx +++ b/src/genericgui/BL_GenericGui.hxx @@ -50,10 +50,13 @@ namespace BL void createActions(); void createMenus(); + void delete_job_internal(); + public slots: void create_job(); void edit_clone_job(); void start_job(); + void restart_job(); void delete_job(); void refresh_job(); void get_results_job(); @@ -83,6 +86,7 @@ namespace BL QAction * _create_job_action; QAction * _edit_clone_job_action; QAction * _start_job_action; + QAction * _restart_job_action; QAction * _delete_job_action; QAction * _get_results_job_action; QAction * _refresh_job_action; diff --git a/src/genericgui/BL_JobsManager_QT.cxx b/src/genericgui/BL_JobsManager_QT.cxx index db22286..5e75ecb 100644 --- a/src/genericgui/BL_JobsManager_QT.cxx +++ b/src/genericgui/BL_JobsManager_QT.cxx @@ -18,6 +18,7 @@ // #include "BL_JobsManager_QT.hxx" +#include "BL_GenericGui.hxx" BL::JobManagerEvent::JobManagerEvent(const std::string & action_i, const std::string & event_name_i, @@ -32,10 +33,11 @@ BL::JobManagerEvent::JobManagerEvent(const std::string & action_i, BL::JobManagerEvent::~JobManagerEvent() {} -BL::JobsManager_QT::JobsManager_QT(QWidget * parent, BL::SALOMEServices * salome_services) : +BL::JobsManager_QT::JobsManager_QT(QWidget * parent, BL::GenericGui * main_gui, BL::SALOMEServices * salome_services) : QDockWidget(parent), BL::JobsManager(salome_services) { DEBTRACE("Creating BL::JobsManager_QT"); + _main_gui = main_gui; setObserver(this); // Widget Part @@ -149,57 +151,51 @@ BL::JobsManager_QT::one_hour_refresh() _timer->start(1 * 60 * 60 * 1000); } +void +BL::JobsManager_QT::restart_job(const std::string & name) +{ + DEBTRACE("Restart job with name: " << name); + BL::CreateJobWizard wizard(this, _salome_services); + wizard.clone(name); + wizard.end(1); + wizard.job_name = name; + wizard.start_job = true; + _main_gui->delete_job_internal(); + create_job_with_wizard(wizard); +} + +void +BL::JobsManager_QT::edit_clone_job(const std::string & name) +{ + BL::CreateJobWizard wizard(this, _salome_services); + wizard.clone(name); + wizard.exec(); + + // Check if the job has the same name + if (name == wizard.job_name) + { + DEBTRACE("Job " << name << " has been changed"); + _main_gui->delete_job_internal(); + } + + if (wizard.job_name != "") + { + create_job_with_wizard(wizard); + } + else + { + DEBTRACE("User cancel Create Job Wizard"); + } +} + void -BL::JobsManager_QT::create_job_wizard(const std::string & name) +BL::JobsManager_QT::create_job() { BL::CreateJobWizard wizard(this, _salome_services); - if (name != "") - wizard.clone(name); wizard.exec(); - if (wizard.job_name != "") { - BL::Job * new_job = createJob(wizard.job_name); - if (wizard.yacs_file != "") - { - // YACS schema job - new_job->setType(BL::Job::YACS_SCHEMA); - new_job->setJobFile(wizard.yacs_file); - } - else if (wizard.command != "") - { - // Command Job - new_job->setType(BL::Job::COMMAND); - new_job->setJobFile(wizard.command); - } - else if (wizard.python_salome_file != "") - { - // Command Job - new_job->setType(BL::Job::PYTHON_SALOME); - new_job->setJobFile(wizard.python_salome_file); - } - - // For all jobs - new_job->setEnvFile(wizard.env_file); - BL::Job::BatchParam param; - param.batch_directory = wizard.batch_directory; - param.maximum_duration = wizard.maximum_duration; - param.expected_memory = wizard.expected_memory; - param.nb_proc = wizard.nb_proc; - new_job->setBatchParameters(param); - BL::Job::FilesParam files_params; - files_params.result_directory = wizard.result_directory; - files_params.input_files_list = wizard.input_files_list; - files_params.output_files_list = wizard.output_files_list; - new_job->setFilesParameters(files_params); - new_job->setResource(wizard.resource_choosed); - new_job->setBatchQueue(wizard.batch_queue); - - // End - addJobToLauncher(wizard.job_name); - emit new_job_added(QString::fromStdString(wizard.job_name)); - if (wizard.start_job) - start_job(wizard.job_name); + create_job_with_wizard(wizard); } else { @@ -207,6 +203,52 @@ BL::JobsManager_QT::create_job_wizard(const std::string & name) } } +void +BL::JobsManager_QT::create_job_with_wizard(BL::CreateJobWizard & wizard) +{ + BL::Job * new_job = createJob(wizard.job_name); + if (wizard.yacs_file != "") + { + // YACS schema job + new_job->setType(BL::Job::YACS_SCHEMA); + new_job->setJobFile(wizard.yacs_file); + } + else if (wizard.command != "") + { + // Command Job + new_job->setType(BL::Job::COMMAND); + new_job->setJobFile(wizard.command); + } + else if (wizard.python_salome_file != "") + { + // Command Job + new_job->setType(BL::Job::PYTHON_SALOME); + new_job->setJobFile(wizard.python_salome_file); + } + + // For all jobs + new_job->setEnvFile(wizard.env_file); + BL::Job::BatchParam param; + param.batch_directory = wizard.batch_directory; + param.maximum_duration = wizard.maximum_duration; + param.expected_memory = wizard.expected_memory; + param.nb_proc = wizard.nb_proc; + new_job->setBatchParameters(param); + BL::Job::FilesParam files_params; + files_params.result_directory = wizard.result_directory; + files_params.input_files_list = wizard.input_files_list; + files_params.output_files_list = wizard.output_files_list; + new_job->setFilesParameters(files_params); + new_job->setResource(wizard.resource_choosed); + new_job->setBatchQueue(wizard.batch_queue); + + // End + addJobToLauncher(wizard.job_name); + emit new_job_added(QString::fromStdString(wizard.job_name)); + if (wizard.start_job) + start_job(wizard.job_name); +} + void BL::JobsManager_QT::delete_job(QString job_name) { diff --git a/src/genericgui/BL_JobsManager_QT.hxx b/src/genericgui/BL_JobsManager_QT.hxx index 86cfb1a..46f19a2 100644 --- a/src/genericgui/BL_JobsManager_QT.hxx +++ b/src/genericgui/BL_JobsManager_QT.hxx @@ -46,6 +46,7 @@ namespace BL{ std::string data; }; + class GenericGui; class JobsManager_QT: virtual public QDockWidget, virtual public BL::JobsManager, virtual public BL::Observer @@ -53,11 +54,14 @@ namespace BL{ Q_OBJECT public: - JobsManager_QT(QWidget * parent, BL::SALOMEServices * salome_services); + JobsManager_QT(QWidget * parent, BL::GenericGui * main_gui, BL::SALOMEServices * salome_services); virtual ~JobsManager_QT(); void delete_job(QString job_name); - void create_job_wizard(const std::string & name = ""); + + void create_job(); + void edit_clone_job(const std::string & name); + void restart_job(const std::string & name); virtual void sendEvent(const std::string & action, const std::string & event_name, @@ -68,6 +72,9 @@ namespace BL{ void write_normal_text(const QString & text); void write_error_text(const QString & text); + protected: + void create_job_with_wizard(BL::CreateJobWizard & wizard); + public slots: void RefreshJobs(); void no_auto_refresh(); @@ -88,6 +95,7 @@ namespace BL{ QPushButton * _auto_refresh_jobs; QTimer * _timer; QTextEdit * _log; + BL::GenericGui * _main_gui; }; }