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