Salome HOME
796f2502db822068bbd9bcfb0665eb1c1849d637
[modules/smesh.git] / src / ADAPTGUI / MonCreateListGroupCAO.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 "MonCreateListGroupCAO.h"
21 #include "MonCreateHypothesis.h"
22 #include "MonCreateBoundaryCAO.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 MonCreateListGroupCAO::MonCreateListGroupCAO(MonCreateHypothesis* parentHyp, MonCreateBoundaryCAO* parentBound, bool modal,
41                                        HOMARD::HOMARD_Gen_var myHomardGen0, 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  MonCreateListGroupCAO")
51      myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
52     setupUi(this);
53     setModal(modal);
54     InitConnect();
55     InitGroupes();
56 }
57 // --------------------------------------------------------------------------------------------------------------
58 MonCreateListGroupCAO::MonCreateListGroupCAO(MonCreateHypothesis* parentHyp, MonCreateBoundaryCAO* parentBound,
59                                        HOMARD::HOMARD_Gen_var myHomardGen, 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     myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen);
69     setupUi(this);
70     InitConnect();
71 }
72
73 // ------------------------------------------------------------------------
74 MonCreateListGroupCAO::~MonCreateListGroupCAO()
75 // ------------------------------------------------------------------------
76 {
77     // no need to delete child widgets, Qt does it all for us
78 }
79 // ------------------------------------------------------------------------
80 void MonCreateListGroupCAO::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 MonCreateListGroupCAO::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 MonCreateListGroupCAO::PushOnOK()
108 // ------------------------------------------------------------------------
109 {
110      if (PushOnApply()) this->close();
111      if ( _parentHyp )   { _parentHyp->raise(); _parentHyp->activateWindow(); };
112      if ( _parentBound ) { _parentBound->raise(); _parentBound->activateWindow(); };
113 }
114 // ------------------------------------------------------------------------
115 void MonCreateListGroupCAO::PushOnHelp()
116 // ------------------------------------------------------------------------
117 {
118   std::string LanguageShort = myHomardGen->GetLanguageShort();
119   HOMARD_UTILS::PushOnHelp(QString("gui_create_hypothese.html"), QString(""), QString(LanguageShort.c_str()));
120 }
121 // ------------------------------------------------------------------------
122 void MonCreateListGroupCAO::InitGroupes()
123 // ------------------------------------------------------------------------
124 {
125   MESSAGE("Debut de MonCreateListGroupCAO::InitGroupes ");
126   for ( int row=0; row< TWGroupe->rowCount(); row++)
127       TWGroupe->removeRow(row);
128   TWGroupe->setRowCount(0);
129   if (_aCaseName == QString("")) { return; };
130   HOMARD::HOMARD_Cas_var monCas= myHomardGen->GetCase(_aCaseName.toStdString().c_str());
131   HOMARD::ListGroupType_var _listeGroupesCas = monCas->GetGroups();
132   for ( int i = 0; i < _listeGroupesCas->length(); i++ )
133   {
134     TWGroupe->insertRow(i);
135     TWGroupe->setItem( i, 0, new QTableWidgetItem( QString ("") ) );
136     TWGroupe->item( i, 0 )->setFlags( 0 );
137     TWGroupe->item( i, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
138     if (_listeGroupesHypo.contains (QString((_listeGroupesCas)[i])))
139       {TWGroupe->item( i, 0 )->setCheckState( Qt::Checked );}
140     else
141       {TWGroupe->item( i, 0 )->setCheckState( Qt::Unchecked );}
142     TWGroupe->setItem( i, 1, new QTableWidgetItem(QString((_listeGroupesCas)[i]).trimmed()));
143     TWGroupe->item( i, 1 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
144   }
145   TWGroupe->resizeColumnsToContents();
146   TWGroupe->resizeRowsToContents();
147   TWGroupe->clearSelection();
148 //   MESSAGE("Fin de MonCreateListGroupCAO::InitGroupes ");
149 }
150