Salome HOME
Initial commit
[modules/jobmanager.git] / src / genericgui / BL_JobTab.cxx
1 //  Copyright (C) 2009 CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BL_JobTab.hxx"
21 #include "BL_Traces.hxx"
22
23 BL::JobTab::JobTab(QWidget *parent, BL::JobsManager_QT * jobs_manager) : QTabWidget(parent)
24 {
25   DEBTRACE("Creating BL::JobTab");
26   BL_ASSERT(parent);
27   BL_ASSERT(jobs_manager);
28   _parent = parent;
29   _jobs_manager = jobs_manager;
30   _model = NULL;
31
32   createJobSummaryTab();
33   createJobFilesTab();
34
35   addTab(_summary_tab, "Job Summary");
36   addTab(_files_tab, "Job Files");
37 }
38
39 BL::JobTab::~JobTab()
40 {
41   DEBTRACE("Destroying BL::JobTab");
42 }
43
44 void
45 BL::JobTab::setModel(QStandardItemModel * model)
46 {
47   DEBTRACE("Call setModel BL::JobTab");
48   BL_ASSERT(model);
49
50   _model = model;
51 }
52
53 void
54 BL::JobTab::createJobSummaryTab()
55 {
56   _summary_tab = new QWidget(this);
57
58   QLabel * job_name_label = new QLabel("Name:");
59   _job_name_label_value = new QLabel("");
60   QLabel * job_type_label = new QLabel("Type:");
61   _job_type_label_value = new QLabel("");
62   QLabel * job_state_label = new QLabel("State:");
63   _job_state_label_value = new QLabel("");
64   QLabel * job_machine_label = new QLabel("Machine:");
65   _job_machine_label_value = new QLabel("");
66   _job_command_label = new QLabel("Schema or Command:");
67   _job_command_label_value = new QLabel("");
68
69   QGroupBox * main_values_box = new QGroupBox("Main values");
70   QFormLayout * values_form = new QFormLayout;
71   values_form->insertRow(0, job_name_label, _job_name_label_value);
72   values_form->insertRow(1, job_type_label, _job_type_label_value);
73   values_form->insertRow(2, job_state_label, _job_state_label_value);
74   values_form->insertRow(3, job_machine_label, _job_machine_label_value);
75   values_form->insertRow(4, _job_command_label, _job_command_label_value);
76   main_values_box->setLayout(values_form);
77
78   QLabel * job_nif_label = new QLabel("Number of Input Files:");
79   _job_nif_label_value = new QLabel("");
80   QLabel * job_nof_label = new QLabel("Number of Output Files:");
81   _job_nof_label_value = new QLabel("");
82   QLabel * job_bd_label = new QLabel("Execution directory:");
83   _job_bd_label_value = new QLabel("");
84   QLabel * job_rd_label = new QLabel("Result directory:");
85   _job_rd_label_value = new QLabel("");
86
87   QLabel * job_edt_label = new QLabel("Expected during time:");
88   _job_edt_label_value = new QLabel("");
89   QLabel * job_em_label = new QLabel("Expected memory:");
90   _job_em_label_value = new QLabel("");
91   QLabel * job_nop_label = new QLabel("Number of processors:");
92   _job_nop_label_value = new QLabel("");
93
94   QGroupBox * run_values_box = new QGroupBox("Run values");
95   QFormLayout * run_values_form = new QFormLayout;
96   run_values_form->insertRow(0, job_nif_label, _job_nif_label_value);
97   run_values_form->insertRow(1, job_nof_label, _job_nof_label_value);
98   run_values_form->insertRow(2, job_bd_label, _job_bd_label_value);
99   run_values_form->insertRow(3, job_rd_label, _job_rd_label_value);
100   QFormLayout * other_run_values_form = new QFormLayout;
101   other_run_values_form->insertRow(0, job_edt_label, _job_edt_label_value);
102   other_run_values_form->insertRow(1, job_em_label, _job_em_label_value);
103   other_run_values_form->insertRow(2, job_nop_label, _job_nop_label_value);
104   QHBoxLayout * box_layout = new QHBoxLayout();
105   box_layout->addLayout(run_values_form);
106   box_layout->addLayout(other_run_values_form);
107   run_values_box->setLayout(box_layout);
108
109   QVBoxLayout * mainLayout = new QVBoxLayout();
110   mainLayout->addWidget(main_values_box);
111   mainLayout->addWidget(run_values_box);
112   _summary_tab->setLayout(mainLayout);
113 }
114
115 void
116 BL::JobTab::createJobFilesTab()
117 {
118   _files_tab = new QWidget(this);
119   
120   _input_files_list = new QListWidget(this);
121   _input_files_list->setSelectionMode(QAbstractItemView::NoSelection);
122   QGroupBox * input_files_box = new QGroupBox("Input Files");
123   QVBoxLayout * input_layout = new QVBoxLayout();
124   input_layout->addWidget(_input_files_list);
125   input_files_box->setLayout(input_layout);
126
127   _output_files_list = new QListWidget(this);
128   _output_files_list->setSelectionMode(QAbstractItemView::NoSelection);
129   QGroupBox * output_files_box = new QGroupBox("Output Files");
130   QVBoxLayout * output_layout = new QVBoxLayout();
131   output_layout->addWidget(_output_files_list);
132   output_files_box->setLayout(output_layout);
133
134   QVBoxLayout * mainLayout = new QVBoxLayout();
135   mainLayout->addWidget(input_files_box);
136   mainLayout->addWidget(output_files_box);
137   _files_tab->setLayout(mainLayout);
138 }
139
140 void
141 BL::JobTab::job_selected(const QModelIndex & index)
142 {
143   DEBTRACE("BL::JobTab::job_selected slot");
144   QStandardItem * item = _model->itemFromIndex(index);
145   QStandardItem * item_name = _model->item(item->row());
146   if (item)
147   {
148     BL::Job * job = _jobs_manager->getJob(item_name->text().toStdString());
149
150     _job_name_label_value->setText(QString(job->getName().c_str()));
151
152     if (job->getState() == BL::Job::CREATED)
153       _job_state_label_value->setText("Created");
154     else if (job->getState() == BL::Job::IN_PROCESS)
155       _job_state_label_value->setText("In Process");
156     else if (job->getState() == BL::Job::QUEUED)
157       _job_state_label_value->setText("Queued");
158     else if (job->getState() == BL::Job::RUNNING)
159       _job_state_label_value->setText("Running");
160     else if (job->getState() == BL::Job::PAUSED)
161       _job_state_label_value->setText("Paused");
162     else if (job->getState() == BL::Job::ERROR)
163       _job_state_label_value->setText("Error");
164     else 
165       _job_state_label_value->setText("Finished");
166
167     if (job->getType() == BL::Job::YACS_SCHEMA)
168     {
169       _job_command_label->setText("Schema:");
170       _job_command_label_value->setText(QString(job->getYACSFile().c_str()));
171       _job_type_label_value->setText("YACS_Schema");
172     }
173     else
174     {
175       _job_command_label->setText("Command:");
176       _job_command_label_value->setText(QString(job->getCommand().c_str()));
177       _job_type_label_value->setText("Command");
178     }
179
180     _job_machine_label_value->setText(QString(job->getMachine().c_str()));
181
182     BL::Job::BatchParam batch_params = job->getBatchParameters();
183
184     BL::Job::FilesParam files_params = job->getFilesParameters();
185     int nif = files_params.input_files_list.size();
186     _job_nif_label_value->setText(QVariant(nif).toString());
187     int nof = files_params.output_files_list.size();
188     _job_nof_label_value->setText(QVariant(nof).toString());
189     _job_bd_label_value->setText(QString(batch_params.batch_directory.c_str()));
190     _job_rd_label_value->setText(QString(files_params.result_directory.c_str()));
191
192     _job_edt_label_value->setText(QString(batch_params.expected_during_time.c_str()));
193     _job_em_label_value->setText(QString(batch_params.expected_memory.c_str()));
194     _job_nop_label_value->setText(QVariant(batch_params.nb_proc).toString());
195
196     std::list<std::string>::iterator it;
197     for (it = files_params.input_files_list.begin(); it != files_params.input_files_list.end(); it++)
198     {
199       std::string file = *it;
200       _input_files_list->addItem(QString(file.c_str()));
201     }
202     for (it = files_params.output_files_list.begin(); it != files_params.output_files_list.end(); it++)
203     {
204       std::string file = *it;
205       _output_files_list->addItem(QString(file.c_str()));
206     }
207
208   }
209   else
210     DEBTRACE ("itemFromIndex returns 0 !");
211 }
212
213 void 
214 BL::JobTab::itemChanged(QStandardItem * item)
215 {
216   DEBTRACE("BL::JobTab::itemChanged slot");
217
218   QStandardItem * item_name = _model->item(item->row());
219   BL::Job * job = _jobs_manager->getJob(item_name->text().toStdString());
220
221   if (_job_name_label_value->text() == QString(job->getName().c_str()))
222   {
223     if (job->getState() == BL::Job::CREATED)
224       _job_state_label_value->setText("Created");
225     else if (job->getState() == BL::Job::IN_PROCESS)
226       _job_state_label_value->setText("In Process");
227     else if (job->getState() == BL::Job::QUEUED)
228       _job_state_label_value->setText("Queued");
229     else if (job->getState() == BL::Job::RUNNING)
230       _job_state_label_value->setText("Running");
231     else if (job->getState() == BL::Job::PAUSED)
232       _job_state_label_value->setText("Paused");
233     else if (job->getState() == BL::Job::ERROR)
234       _job_state_label_value->setText("Error");
235     else 
236       _job_state_label_value->setText("Finished");
237   }
238 }
239
240 void
241 BL::JobTab::reset(QString job_name)
242 {
243   _job_name_label_value->setText("");
244   _job_type_label_value->setText("");
245   _job_state_label_value->setText("");
246   _job_machine_label_value->setText("");
247   _job_nif_label_value->setText("");
248   _job_nof_label_value->setText("");
249   _job_bd_label_value->setText("");
250   _job_rd_label_value->setText("");
251   _job_edt_label_value->setText("");
252   _job_em_label_value->setText("");
253   _job_nop_label_value->setText("");
254   _job_command_label->setText("Schema or Command:");
255   _job_command_label_value->setText("");
256
257   _input_files_list->clear();
258   _output_files_list->clear();
259 }