Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_HomardListGroup.cxx
1 // Copyright (C) 2011-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
20 #include "SMESHGUI_HomardListGroup.h"
21
22 #include "SMESHGUI_HomardBoundaryDlg.h"
23 #include "SMESHGUI_HomardUtils.h"
24 #include "SMESHGUI_Utils.h"
25
26 #include "SalomeApp_Tools.h"
27
28 #include <SUIT_Desktop.h>
29 #include <SUIT_MessageBox.h>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ViewManager.h>
33
34 #include <utilities.h>
35
36 #include <QFileDialog>
37
38 using namespace std;
39
40 // ------------------------------------------------------------------------------------
41 SMESH_CreateListGroupCAO::SMESH_CreateListGroupCAO(SMESH_CreateBoundaryCAO* parentBound,
42                                                    bool modal,
43                                                    SMESHHOMARD::HOMARD_Gen_var myHomardGen0,
44                                                    QString aCaseName,
45                                                    QStringList listeGroupesHypo)
46   : QDialog(0), SMESH_Ui_CreateListGroup(),
47     _aCaseName (aCaseName),
48     _listeGroupesHypo (listeGroupesHypo),
49     _parentBound(parentBound)
50 {
51   MESSAGE("Debut de SMESH_CreateListGroupCAO");
52   myHomardGen = SMESHHOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
53   setupUi(this);
54   setModal(modal);
55   InitConnect();
56   InitGroupes();
57 }
58 // ------------------------------------------------------------------------------------
59 SMESH_CreateListGroupCAO::SMESH_CreateListGroupCAO(SMESH_CreateBoundaryCAO* parentBound,
60                                                    SMESHHOMARD::HOMARD_Gen_var myHomardGen0,
61                                                    QString aCaseName,
62                                                    QStringList listeGroupesHypo)
63   : QDialog(0), SMESH_Ui_CreateListGroup(),
64     _aCaseName (aCaseName),
65     _listeGroupesHypo (listeGroupesHypo),
66     _parentBound(parentBound)
67 {
68     myHomardGen = SMESHHOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
69     setupUi(this);
70     InitConnect();
71 }
72
73 // ------------------------------------------------------------------------
74 SMESH_CreateListGroupCAO::~SMESH_CreateListGroupCAO()
75 // ------------------------------------------------------------------------
76 {
77     // no need to delete child widgets, Qt does it all for us
78 }
79 // ------------------------------------------------------------------------
80 void SMESH_CreateListGroupCAO::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 SMESH_CreateListGroupCAO::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 ( _parentBound ) { _parentBound->setGroups(ListeGroup);};
101   return true;
102 }
103
104
105 // ------------------------------------------------------------------------
106 void SMESH_CreateListGroupCAO::PushOnOK()
107 // ------------------------------------------------------------------------
108 {
109      if (PushOnApply()) this->close();
110      if ( _parentBound ) { _parentBound->raise(); _parentBound->activateWindow(); };
111 }
112 // ------------------------------------------------------------------------
113 void SMESH_CreateListGroupCAO::PushOnHelp()
114 // ------------------------------------------------------------------------
115 {
116   SMESH::ShowHelpFile(QString("homard_create_boundary.html#filtering-by-the-groups"));
117 }
118 // ------------------------------------------------------------------------
119 void SMESH_CreateListGroupCAO::InitGroupes()
120 // ------------------------------------------------------------------------
121 {
122   MESSAGE("Debut de SMESH_CreateListGroupCAO::InitGroupes ");
123   for ( int row=0; row< TWGroupe->rowCount(); row++)
124       TWGroupe->removeRow(row);
125   TWGroupe->setRowCount(0);
126   if (_aCaseName == QString("")) { return; };
127   SMESHHOMARD::HOMARD_Cas_var monCas = myHomardGen->GetCase();
128   SMESHHOMARD::ListGroupType_var _listeGroupesCas = monCas->GetGroups();
129   for ( int i = 0; i < _listeGroupesCas->length(); i++ ) {
130     TWGroupe->insertRow(i);
131     TWGroupe->setItem( i, 0, new QTableWidgetItem( QString ("") ) );
132     TWGroupe->item( i, 0 )->setFlags( 0 );
133     TWGroupe->item( i, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
134     if (_listeGroupesHypo.contains (QString((_listeGroupesCas)[i])))
135       {TWGroupe->item( i, 0 )->setCheckState( Qt::Checked );}
136     else
137       {TWGroupe->item( i, 0 )->setCheckState( Qt::Unchecked );}
138     TWGroupe->setItem( i, 1, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
139     TWGroupe->item( i, 1 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
140   }
141   TWGroupe->resizeColumnsToContents();
142   TWGroupe->resizeRowsToContents();
143   TWGroupe->clearSelection();
144 //   MESSAGE("Fin de SMESH_CreateListGroupCAO::InitGroupes ");
145 }
146
147
148 // ------------------------------------------------------------------------
149 SMESH_CreateListGroup::SMESH_CreateListGroup(SMESH_CreateBoundaryDi* parentBound, bool modal,
150                                              SMESHHOMARD::HOMARD_Gen_var myHomardGen0,
151                                              QString aCaseName,  QStringList listeGroupesHypo)
152   : QDialog(0), SMESH_Ui_CreateListGroup(),
153     _aCaseName (aCaseName),
154     _listeGroupesHypo (listeGroupesHypo),
155     _parentBound(parentBound)
156 {
157   MESSAGE("Debut de SMESH_CreateListGroup");
158   myHomardGen = SMESHHOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
159   setupUi(this);
160   setModal(modal);
161   InitConnect();
162   InitGroupes();
163 }
164
165 // ------------------------------------------------------------------------
166 SMESH_CreateListGroup::SMESH_CreateListGroup(SMESH_CreateBoundaryDi* parentBound,
167                                              SMESHHOMARD::HOMARD_Gen_var myHomardGen0,
168                                              QString aCaseName,  QStringList listeGroupesHypo)
169   : QDialog(0), SMESH_Ui_CreateListGroup(),
170     _aCaseName (aCaseName),
171     _listeGroupesHypo (listeGroupesHypo),
172     _parentBound(parentBound)
173 {
174   myHomardGen = SMESHHOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
175   setupUi(this);
176   InitConnect();
177 }
178
179 // ------------------------------------------------------------------------
180 SMESH_CreateListGroup::~SMESH_CreateListGroup()
181 {
182   // no need to delete child widgets, Qt does it all for us
183 }
184 // ------------------------------------------------------------------------
185 void SMESH_CreateListGroup::InitConnect()
186 // ------------------------------------------------------------------------
187 {
188     connect( buttonOk,     SIGNAL( pressed() ), this, SLOT( PushOnOK() ) );
189     connect( buttonApply,  SIGNAL( pressed() ), this, SLOT( PushOnApply() ) );
190     connect( buttonCancel, SIGNAL( pressed() ), this, SLOT( close() ) );
191     connect( buttonHelp,   SIGNAL( pressed() ), this, SLOT( PushOnHelp() ) );
192 }
193 // ------------------------------------------------------------------------
194 bool SMESH_CreateListGroup::PushOnApply()
195 // ------------------------------------------------------------------------
196 // Appele lorsque l'un des boutons Ok ou Apply est presse
197 //
198 {
199   QStringList ListeGroup ;
200   for ( int row=0; row< TWGroupe->rowCount(); row++)
201   {
202       if ( TWGroupe->item( row, 0 )->checkState() ==  Qt::Checked )
203           ListeGroup.insert(0, QString(TWGroupe->item(row, 1)->text()) );
204   }
205   if ( _parentBound ) { _parentBound->setGroups(ListeGroup);};
206   return true;
207 }
208
209
210 // ------------------------------------------------------------------------
211 void SMESH_CreateListGroup::PushOnOK()
212 // ------------------------------------------------------------------------
213 {
214     if (PushOnApply())
215     {
216       this->close();
217       if ( _parentBound ) { _parentBound->raise(); _parentBound->activateWindow(); };
218     }
219 }
220 // ------------------------------------------------------------------------
221 void SMESH_CreateListGroup::PushOnHelp()
222 // ------------------------------------------------------------------------
223 {
224   SMESH::ShowHelpFile(QString("homard_create_boundary.html#filtering-by-the-groups"));
225 }
226 // ------------------------------------------------------------------------
227 void SMESH_CreateListGroup::InitGroupes()
228 // ------------------------------------------------------------------------
229 {
230   MESSAGE("Debut de SMESH_CreateListGroup::InitGroupes ");
231   for ( int row=0; row< TWGroupe->rowCount(); row++)
232       TWGroupe->removeRow(row);
233   TWGroupe->setRowCount(0);
234   if (_aCaseName == QString("")) { return; };
235   SMESHHOMARD::HOMARD_Cas_var monCas = myHomardGen->GetCase();
236   SMESHHOMARD::ListGroupType_var _listeGroupesCas = monCas->GetGroups();
237   for ( int i = 0; i < _listeGroupesCas->length(); i++ )
238   {
239     TWGroupe->insertRow(i);
240     TWGroupe->setItem( i, 0, new QTableWidgetItem( QString ("") ) );
241     TWGroupe->item( i, 0 )->setFlags( 0 );
242     TWGroupe->item( i, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
243     if (_listeGroupesHypo.contains (QString((_listeGroupesCas)[i])))
244       {TWGroupe->item( i, 0 )->setCheckState( Qt::Checked );}
245     else
246       {TWGroupe->item( i, 0 )->setCheckState( Qt::Unchecked );}
247     TWGroupe->setItem( i, 1, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
248     TWGroupe->item( i, 1 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
249   }
250   TWGroupe->resizeColumnsToContents();
251   TWGroupe->resizeRowsToContents();
252   TWGroupe->clearSelection();
253 //   MESSAGE("Fin de SMESH_CreateListGroup::InitGroupes ");
254 }
255
256 //---------------------------------------------------------------------
257 SMESH_EditListGroupCAO::SMESH_EditListGroupCAO( SMESH_CreateBoundaryCAO* parentBound,
258                                                 bool modal,
259                                                 SMESHHOMARD::HOMARD_Gen_var myHomardGen0,
260                                                 QString aCaseName,
261                                                 QStringList listeGroupesHypo):
262 //---------------------------------------------------------------------
263 SMESH_CreateListGroupCAO(parentBound,myHomardGen0,aCaseName,listeGroupesHypo)
264 {
265   MESSAGE("Debut de SMESH_EditListGroupCAO");
266     setWindowTitle(QObject::tr("HOM_GROU_EDIT_WINDOW_TITLE"));
267   setModal(true);
268   InitGroupes();
269 }
270
271 //------------------------------------
272 SMESH_EditListGroupCAO:: ~SMESH_EditListGroupCAO()
273 //------------------------------------
274 {
275 }
276 // -------------------------------------
277 void SMESH_EditListGroupCAO:: InitGroupes()
278 // -------------------------------------
279 {
280   for (int i = 0; i < _listeGroupesHypo.size(); i++ )
281   {
282      std::cerr << _listeGroupesHypo[i].toStdString().c_str() << std::endl;
283      TWGroupe->insertRow(i);
284      TWGroupe->setItem( i, 0, new QTableWidgetItem( QString ("") ) );
285      TWGroupe->item( i, 0 )->setFlags( 0 );
286      TWGroupe->item( i, 0 )->setCheckState( Qt::Checked );
287      TWGroupe->setItem( i, 1, new QTableWidgetItem(_listeGroupesHypo[i]));
288    }
289    TWGroupe->resizeRowsToContents();
290 }
291
292 //---------------------------------------------------------------------
293 SMESH_EditListGroup::SMESH_EditListGroup( SMESH_CreateBoundaryDi* parentBound,
294                                           bool modal,
295                                           SMESHHOMARD::HOMARD_Gen_var myHomardGen0,
296                                           QString aCaseName,
297                                           QStringList listeGroupesHypo):
298 //---------------------------------------------------------------------
299 SMESH_CreateListGroup(parentBound,myHomardGen0,aCaseName,listeGroupesHypo)
300 {
301   MESSAGE("Debut de SMESH_EditListGroup");
302     setWindowTitle(QObject::tr("HOM_GROU_EDIT_WINDOW_TITLE"));
303   setModal(true);
304   InitGroupes();
305 }
306
307 //------------------------------------
308 SMESH_EditListGroup::~SMESH_EditListGroup()
309 //------------------------------------
310 {
311 }
312 // -------------------------------------
313 void SMESH_EditListGroup::InitGroupes()
314 // -------------------------------------
315 {
316   for (int i = 0; i < _listeGroupesHypo.size(); i++ )
317   {
318      std::cerr << _listeGroupesHypo[i].toStdString().c_str() << std::endl;
319      TWGroupe->insertRow(i);
320      TWGroupe->setItem( i, 0, new QTableWidgetItem( QString ("") ) );
321      TWGroupe->item( i, 0 )->setFlags( 0 );
322      TWGroupe->item( i, 0 )->setCheckState( Qt::Checked );
323      TWGroupe->setItem( i, 1, new QTableWidgetItem(_listeGroupesHypo[i]));
324    }
325    TWGroupe->resizeRowsToContents();
326 }