Salome HOME
dfbf7a401763c31237e1ea5cbbf540ca62dcd722
[tools/ydefx.git] / src / gui / QuickConfig.cxx
1 // Copyright (C) 2019  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, or (at your option) any later version.
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 #include "QuickConfig.hxx"
20
21 namespace ydefx
22 {
23 QuickConfigWidget::QuickConfigWidget(ydefx::JobParametersProxy& model,
24                                      QWidget* parent)
25 : QScrollArea(parent)
26 , _model(model)
27 {
28   QWidget* mainWidget = new QWidget();
29   QVBoxLayout *mainLayout = new QVBoxLayout();
30   mainWidget->setLayout(mainLayout);
31   
32   QHBoxLayout *hLayout = new QHBoxLayout();
33   QComboBox* resourcesComboBox = new QComboBox;
34   std::list<std::string> resources = _model.AvailableResources();
35   for(const std::string& it : resources)
36     resourcesComboBox->addItem(QString(it.c_str()));
37   resourcesComboBox->setCurrentIndex(
38                     resourcesComboBox->findText(model.resource_name().c_str()));
39   connect(resourcesComboBox, SIGNAL(currentIndexChanged( const QString &)),
40           this, SLOT(updateResource( const QString &)));
41
42   QPushButton* resetBtn = new QPushButton(tr("Default parameters"));
43   connect(resetBtn,SIGNAL(clicked()),this, SLOT(resetParams()));
44
45   QLabel * resourcesLabel = new QLabel(tr("Computing resource:"));
46   hLayout->addWidget(resourcesLabel);
47   hLayout->addWidget(resourcesComboBox);
48   hLayout->addWidget(resetBtn);
49   mainLayout->addLayout(hLayout);
50   
51   QLabel *nb_branchesLabel = new QLabel(tr("Number of parallel evaluations:"));
52   QSpinBox *nb_branchesEdit = new QSpinBox();
53   nb_branchesEdit->setRange(1, 10000);
54   nb_branchesEdit->setValue(_model.nb_branches());
55   hLayout = new QHBoxLayout();
56   hLayout->addWidget(nb_branchesLabel);
57   hLayout->addWidget(nb_branchesEdit);
58   mainLayout->addLayout(hLayout);
59   connect(this, SIGNAL(defaultNbBranches(int)),
60           nb_branchesEdit, SLOT(setValue(int)));
61   connect(nb_branchesEdit, SIGNAL(valueChanged(int)),
62           this, SLOT(updateNbBranches(int)));
63
64   hLayout = new QHBoxLayout();
65   QLabel *label = new QLabel(tr("Job name:"));
66   QLineEdit *editLine = new QLineEdit();
67   editLine->setText(_model.job_name().c_str());
68   hLayout->addWidget(label);
69   hLayout->addWidget(editLine);
70   mainLayout->addLayout(hLayout);
71   connect(editLine, SIGNAL(textChanged(const QString &)),
72           this, SLOT(updateJobName(const QString&)));
73
74   mainLayout->addStretch();
75   setWidget(mainWidget);
76   setWidgetResizable (true);
77 }
78
79 QuickConfigWidget::~QuickConfigWidget()
80 {
81 }
82
83 void QuickConfigWidget::updateJobName(const QString& value)
84 {
85   _model.job_name(value.toStdString());
86 }
87
88 void QuickConfigWidget::updateResource(const QString& value)
89 {
90   _model.resource_name(value.toStdString());
91 }
92
93 void QuickConfigWidget::resetParams()
94 {
95   _model.configureResource(_model.resource_name());
96   emit defaultNbBranches(_model.nb_branches());
97   emit defaultWorkingDir(_model.work_directory().c_str());
98   emit defaultWcKey(_model.wckey().c_str());
99 }
100
101 void QuickConfigWidget::updateNbBranches(int value)
102 {
103   _model.nb_branches(value);
104   emit defaultNbBranches(value);
105 }
106 }