Salome HOME
1aefb809e1bbfb6d003d159ab1d8dfc5c2d96366
[modules/yacs.git] / src / ydfx_gui / YDFXGUIMain.cxx
1 // Copyright (C) 2016-2022  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, 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 // Author : Anthony Geay (EDF R&D)
20
21 #include "YDFXGUIMain.hxx"
22 #include "YDFXGUIPortsSelector.hxx"
23 #include "YDFXGUIHostParametrizer.hxx"
24 #include "YDFXGUISeqInit.hxx"
25 #include "YDFXGUIPushButtons.hxx"
26
27 #include "YACSEvalYFX.hxx"
28
29 #include <QFileDialog>
30
31 /////////////
32
33 YDFXGUIMainEFXWidget::YDFXGUIMainEFXWidget(YACSEvalSession *session, YACSEvalYFXWrap *efx, QWidget *parent):QWidget(parent),_efx(efx),_ports(new YDFXGUIAllPorts(efx,this)),_run(0)
34 {
35   QVBoxLayout *mainLayout(new QVBoxLayout(this));
36   mainLayout->addWidget(_ports,1);
37   QHBoxLayout *buttonLayout(new QHBoxLayout);
38   QSpacerItem *si(new QSpacerItem(40,20,QSizePolicy::Expanding,QSizePolicy::Minimum));
39   buttonLayout->addItem(si);
40   _seqInit=new YDFXGUISeqInitButton(this,_efx,_ports);
41   buttonLayout->addWidget(_seqInit);
42   _run=new YDFXGUIRunButton(this,session,_efx);
43   _run->setEnabled(false);
44   connect(_seqInit,SIGNAL(sequenceWellDefined(bool)),_ports,SLOT(somethingChangedInPorts(bool)));
45   connect(_ports,SIGNAL(sequencesCanBeDefinedSignal(bool)),_seqInit,SLOT(setEnabled(bool)));
46   connect(_ports,SIGNAL(canBeExecutedSignal(bool)),_run,SLOT(setEnabled(bool)));
47   //
48   buttonLayout->addWidget(_run);
49   mainLayout->addLayout(buttonLayout);
50 }
51
52 YDFXGUIMainEFXWidget::~YDFXGUIMainEFXWidget()
53 {
54   delete _efx;
55 }
56
57 AddTabWidget::AddTabWidget(QWidget *parent):QWidget(parent)
58 {
59   QVBoxLayout *mainLayout(new QVBoxLayout);
60   QPushButton *pb(new QPushButton("Add from XML file",this));
61   mainLayout->addWidget(pb);
62   connect(pb,SIGNAL(clicked(bool)),this,SIGNAL(addNewTab()));
63   this->setLayout(mainLayout);
64 }
65
66 /////////////
67
68 TabEFXViews::TabEFXViews(QWidget *parent, YACSEvalSession *session):QTabWidget(parent),_addWidget(new AddTabWidget(this)),_session(session)
69 {
70   this->addTab(_addWidget,"+");
71   connect(_addWidget,SIGNAL(addNewTab()),this,SLOT(newTabFromXMLRequested()));
72   this->setTabsClosable(true);
73   connect(this,SIGNAL(tabCloseRequested(int)),this,SLOT(closeTabPlease(int)));
74 }
75
76 void TabEFXViews::newTabFromXMLRequested()
77 {
78   QFileDialog fd(this);
79   fd.setNameFilter("YACS XML files (*.xml)");
80   if(fd.exec())
81     {
82       QStringList fileNames(fd.selectedFiles());
83       if(fileNames.size()!=1)
84         return ;
85       QString fileName(fileNames[0]);
86       QFileInfo fn(fileName);
87       YACSEvalYFXWrap *efx(new YACSEvalYFXWrap(YACSEvalYFX::BuildFromFile(fileName.toStdString())));
88       YDFXGUIMainEFXWidget *newTab(new YDFXGUIMainEFXWidget(_session,efx,this));
89       int index(this->insertTab(count()-1,newTab,fn.baseName()));
90       this->setCurrentIndex(index);
91     }
92 }
93
94 void TabEFXViews::closeTabPlease(int tabId)
95 {
96   if(tabId==count()-1)
97     return ;
98   QWidget *tab(this->widget(tabId));
99   delete tab;
100 }
101
102 /////////////
103
104 YDFXGUI::YDFXGUI(YACSEvalSession *session):_tabWidget(new TabEFXViews(this,session))
105 {
106   QVBoxLayout *mainLayout(new QVBoxLayout);
107   mainLayout->addWidget(_tabWidget);
108   this->setLayout(mainLayout);
109 }