Salome HOME
0282afbf26aa10d48f727b39f1eacee8030000c9
[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   QLabel * resourcesLabel = new QLabel(tr("Computing resource:"));
43   hLayout->addWidget(resourcesLabel);
44   hLayout->addWidget(resourcesComboBox);
45   mainLayout->addLayout(hLayout);
46   
47   QLabel *nb_branchesLabel = new QLabel(tr("Number of parallel evaluations:"));
48   QSpinBox *nb_branchesEdit = new QSpinBox();
49   nb_branchesEdit->setRange(1, 10000);
50   nb_branchesEdit->setValue(_model.nb_branches());
51   hLayout = new QHBoxLayout();
52   hLayout->addWidget(nb_branchesLabel);
53   hLayout->addWidget(nb_branchesEdit);
54   mainLayout->addLayout(hLayout);
55   connect(this, SIGNAL(defaultNbBranches(int)),
56           nb_branchesEdit, SLOT(setValue(int)));
57   connect(nb_branchesEdit, SIGNAL(valueChanged(int)),
58           this, SLOT(updateNbBranches(int)));
59
60   mainLayout->addStretch();
61   setWidget(mainWidget);
62   setWidgetResizable (true);
63 }
64
65 QuickConfigWidget::~QuickConfigWidget()
66 {
67 }
68
69 void QuickConfigWidget::updateResource(const QString& value)
70 {
71   _model.configureResource(value.toStdString());
72   emit defaultNbBranches(_model.nb_branches());
73   emit defaultWorkingDir(_model.work_directory().c_str());
74   emit defaultWcKey(_model.wckey().c_str());
75 }
76
77 void QuickConfigWidget::updateNbBranches(int value)
78 {
79   _model.nb_branches(value);
80   emit defaultNbBranches(value);
81 }
82 }