Salome HOME
Merge branch 'master' into gni/adaptation
[modules/smesh.git] / src / ADAPTGUI / MonCreateListGroup.cxx
1 // Copyright (C) 2011-2020  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
20 #include "MonCreateListGroup.h"
21 #include "MonCreateHypothesis.h"
22 #include "MonCreateBoundaryDi.h"
23
24 #include <QFileDialog>
25
26 #include "SalomeApp_Tools.h"
27 #include "HOMARDGUI_Utils.h"
28 #include "HomardQtCommun.h"
29 #include <utilities.h>
30
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewManager.h>
36
37 using namespace std;
38
39 // --------------------------------------------------------------------------------------------------------------
40 MonCreateListGroup::MonCreateListGroup(MonCreateHypothesis* parentHyp, MonCreateBoundaryDi* parentBound, bool modal,
41                                        ADAPT::ADAPT_Gen_var myAdaptGen0, QString aCaseName,  QStringList listeGroupesHypo) :
42 // --------------------------------------------------------------------------------------------------------------
43 //
44     QDialog(0), Ui_CreateListGroup(),
45     _aCaseName (aCaseName),
46     _listeGroupesHypo (listeGroupesHypo),
47     _parentHyp(parentHyp),
48     _parentBound(parentBound)
49 {
50     MESSAGE("Debut de  MonCreateListGroup")
51      myAdaptGen=ADAPT::ADAPT_Gen::_duplicate(myAdaptGen0);
52     setupUi(this);
53     setModal(modal);
54     InitConnect();
55     InitGroupes();
56 }
57 // --------------------------------------------------------------------------------------------------------------
58 MonCreateListGroup::MonCreateListGroup(MonCreateHypothesis* parentHyp, MonCreateBoundaryDi* parentBound,
59                                        ADAPT::ADAPT_Gen_var myAdaptGen, QString aCaseName,  QStringList listeGroupesHypo) :
60 // --------------------------------------------------------------------------------------------------------------
61 //
62     QDialog(0), Ui_CreateListGroup(),
63     _aCaseName (aCaseName),
64     _listeGroupesHypo (listeGroupesHypo),
65     _parentHyp(parentHyp),
66     _parentBound(parentBound)
67 {
68     myAdaptGen=ADAPT::ADAPT_Gen::_duplicate(myAdaptGen);
69     setupUi(this);
70     InitConnect();
71 }
72
73 // ------------------------------------------------------------------------
74 MonCreateListGroup::~MonCreateListGroup()
75 // ------------------------------------------------------------------------
76 {
77     // no need to delete child widgets, Qt does it all for us
78 }
79 // ------------------------------------------------------------------------
80 void MonCreateListGroup::InitConnect()
81 // ------------------------------------------------------------------------
82 {
83     connect( buttonOk,     SIGNAL( pressed() ), this, SLOT( PushOnOK() ) );
84     connect( buttonApply,  SIGNAL( pressed() ), this, SLOT( PushOnApply() ) );
85     connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( close() ) );
86     connect( buttonHelp,   SIGNAL( pressed() ), this, SLOT( PushOnHelp() ) );
87 }
88 // ------------------------------------------------------------------------
89 bool MonCreateListGroup::PushOnApply()
90 // ------------------------------------------------------------------------
91 // Appele lorsque l'un des boutons Ok ou Apply est presse
92 //
93 {
94   QStringList ListeGroup ;
95   for ( int row=0; row< TWGroupe->rowCount(); row++)
96   {
97       if ( TWGroupe->item( row, 0 )->checkState() ==  Qt::Checked )
98           ListeGroup.insert(0, QString(TWGroupe->item(row, 1)->text()) );
99   }
100   if ( _parentHyp )   { _parentHyp->setGroups(ListeGroup);};
101   if ( _parentBound ) { _parentBound->setGroups(ListeGroup);};
102   return true;
103 }
104
105
106 // ------------------------------------------------------------------------
107 void MonCreateListGroup::PushOnOK()
108 // ------------------------------------------------------------------------
109 {
110     if (PushOnApply())
111     {
112       this->close();
113       if ( _parentHyp )   { _parentHyp->raise(); _parentHyp->activateWindow(); };
114       if ( _parentBound ) { _parentBound->raise(); _parentBound->activateWindow(); };
115     }
116 }
117 // ------------------------------------------------------------------------
118 void MonCreateListGroup::PushOnHelp()
119 // ------------------------------------------------------------------------
120 {
121   std::string LanguageShort = myAdaptGen->GetLanguageShort();
122   HOMARD_UTILS::PushOnHelp(QString("gui_create_hypothese.html"), QString(""), QString(LanguageShort.c_str()));
123 }
124 // ------------------------------------------------------------------------
125 void MonCreateListGroup::InitGroupes()
126 // ------------------------------------------------------------------------
127 {
128   MESSAGE("Debut de MonCreateListGroup::InitGroupes ");
129   for ( int row=0; row< TWGroupe->rowCount(); row++)
130       TWGroupe->removeRow(row);
131   TWGroupe->setRowCount(0);
132   if (_aCaseName == QString("")) { return; };
133   ADAPT::HOMARD_Cas_var monCas= myAdaptGen->GetCase(_aCaseName.toStdString().c_str());
134   ADAPT::ListGroupType_var _listeGroupesCas = monCas->GetGroups();
135   for ( int i = 0; i < _listeGroupesCas->length(); i++ )
136   {
137     TWGroupe->insertRow(i);
138     TWGroupe->setItem( i, 0, new QTableWidgetItem( QString ("") ) );
139     TWGroupe->item( i, 0 )->setFlags( 0 );
140     TWGroupe->item( i, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
141     if (_listeGroupesHypo.contains (QString((_listeGroupesCas)[i])))
142       {TWGroupe->item( i, 0 )->setCheckState( Qt::Checked );}
143     else
144       {TWGroupe->item( i, 0 )->setCheckState( Qt::Unchecked );}
145     TWGroupe->setItem( i, 1, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
146     TWGroupe->item( i, 1 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
147   }
148   TWGroupe->resizeColumnsToContents();
149   TWGroupe->resizeRowsToContents();
150   TWGroupe->clearSelection();
151 //   MESSAGE("Fin de MonCreateListGroup::InitGroupes ");
152 }
153