Salome HOME
Merge Qt5 porting.
[modules/homard.git] / src / HOMARDGUI / MonEditCase.cxx
1 // Copyright (C) 2011-2015  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 "MonEditCase.h"
21
22 #include "SalomeApp_Tools.h"
23 #include "HOMARDGUI_Utils.h"
24 #include "HomardQtCommun.h"
25 #include <utilities.h>
26
27 using namespace std;
28
29 // -------------------------------------------------------------
30 /* Constructs a MonEditCase
31     herite de MonCreateCase
32 */
33 // -------------------------------------------------------------
34 MonEditCase::MonEditCase ( bool modal,
35                            HOMARD::HOMARD_Gen_var myHomardGen,
36                            QString CaseName ):
37    MonCreateCase(modal, myHomardGen)
38 {
39     MESSAGE("Debut de MonEditCase" << CaseName.toStdString().c_str());
40     setWindowTitle(QObject::tr("HOM_CASE_EDIT_WINDOW_TITLE"));
41     _aCaseName = CaseName;
42     aCase = myHomardGen->GetCase(_aCaseName.toStdString().c_str());
43     InitValEdit();
44 }
45 // ------------------------------
46 MonEditCase::~MonEditCase()
47 // ------------------------------
48 {
49 }
50 // ------------------------------
51 void MonEditCase::InitValEdit()
52 // ------------------------------
53 {
54   MESSAGE("InitValEdit");
55   LEName->setText(_aCaseName);
56   LEName->setReadOnly(true);
57
58   QString aDirName = aCase->GetDirName();
59   LEDirName->setText(aDirName);
60   LEDirName->setReadOnly(true);
61   PushDir->setVisible(0);
62
63   QString _aitername=aCase->GetIter0Name();
64   HOMARD::HOMARD_Iteration_var aIter = myHomardGen->GetIteration(_aitername.toStdString().c_str());
65   QString aFileName = aIter->GetMeshFile();
66   LEFileName->setText(aFileName);
67   LEFileName->setReadOnly(true);
68   PushFichier->setVisible(0);
69
70   int ConfType=aCase->GetConfType();
71   if ( ( ConfType == 0 ) || ( ConfType == -1 ) ) { RBConforme->setChecked(true); }
72   else                                           { RBNonConforme->setChecked(true); };
73   RBConforme->setEnabled(false);
74   RBNonConforme->setEnabled(false);
75   int ExtType=aCase->GetExtType();
76
77 //    Non affichage du mode de suivi de frontiere
78   CBBoundaryA->setVisible(0);
79   GBBoundaryA->setVisible(0);
80   CBBoundaryD->setVisible(0);
81   GBBoundaryD->setVisible(0);
82
83 //    On passe en revue tous les couples (frontiere,groupe) du cas
84   HOMARD::ListBoundaryGroupType_var mesBoundarys = aCase->GetBoundaryGroup();
85   if (mesBoundarys->length()>0)
86   {
87     QStringList ListeFron ;
88     QString NomFron ;
89     bool BounDi = false ;
90     bool BounAn = false ;
91     for (int i=0; i<mesBoundarys->length(); i++)
92     {
93 //        Nom de la frontiere
94       NomFron = mesBoundarys[i++];
95       MESSAGE("NomFron "<<NomFron.toStdString().c_str());
96 //        L'objet associe pour en deduire le type
97       HOMARD::HOMARD_Boundary_var myBoundary = myHomardGen->GetBoundary(NomFron.toStdString().c_str());
98       int type_obj = myBoundary->GetType() ;
99 //        C'est une frontiere discrete
100 //        Rermarque : on ne gere pas les groupes
101       if ( type_obj==0 )
102       {
103         BounDi = true ;
104         CBBoundaryDi->addItem(NomFron);
105       }
106 //        C'est une frontiere analytique
107       else
108       {
109         BounAn = true ;
110         int nbcol = TWBoundary->columnCount();
111 //          On ajoute une ligne pour le groupe
112         TWBoundary->insertRow(0);
113 //          La colonne 0 comporte le nom du groupe
114         TWBoundary->setItem( 0, 0, new QTableWidgetItem(QString(mesBoundarys[i]).trimmed()));
115 //             TWBoundary->item( 0, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
116 //          Chacune des colonnes suivantes est associĆ© a une frontiere deja presente : on y met une
117 //          case non cochee
118         for ( int j = 1; j < nbcol; j++ )
119         {
120           TWBoundary->setItem( 0, j, new QTableWidgetItem( QString ("") ) );
121           TWBoundary->item( 0, j )->setFlags( 0 );
122           TWBoundary->item( 0, j )->setFlags( Qt::ItemIsUserCheckable  );
123           TWBoundary->item( 0, j )->setCheckState( Qt::Unchecked );
124         }
125 //          On cherche si la frontiere en cours d'examen a deja ete rencontree :
126 //          si oui, on stocke son numero de colonne
127         int ok = -1 ;
128         for ( int nufr = 0 ; nufr<ListeFron.size(); nufr++)
129         { if ( ListeFron[nufr] == NomFron ) ok = nufr+1 ; }
130 //            si non, on ajoute une colonne
131         if ( ok < 0 )
132         {
133           ListeFron.append(NomFron);
134           ok = ListeFron.size() ;
135           AddBoundaryAn(NomFron);
136         }
137 //          on coche la case correspondant au couple (frontiere,groupe) en cours d'examen
138         TWBoundary->item( 0, ok )->setCheckState( Qt::Checked );
139       }
140     }
141     MESSAGE("BounDi "<<BounDi<<", BounAn "<<BounAn);
142     if ( BounAn )
143     { GBBoundaryA->setVisible(1);
144 //    On rend les cases non modifiables.
145 //    On ne peut pas le faire pour tout le tableau sinon on perd l'ascenseur !
146       int nbcol = TWBoundary->columnCount();
147       int nbrow = TWBoundary->rowCount();
148       for ( int i = 0; i < nbrow; i++ )
149       { for ( int j = 0; j < nbcol; j++ ) TWBoundary->item( i, j )->setFlags( Qt::ItemIsSelectable ); }
150 //    on met un nom blanc au coin
151       QTableWidgetItem *__colItem = new QTableWidgetItem();
152       __colItem->setText(QApplication::translate("CreateCase", "", 0));
153       TWBoundary->setHorizontalHeaderItem(0, __colItem);
154 //    on cache les boutons inutiles
155       PBBoundaryAnNew->setVisible(0);
156       PBBoundaryAnHelp->setVisible(0);
157     }
158     if ( BounDi )
159     { GBBoundaryD->setVisible(1);
160       CBBoundaryDi->setDisabled(true);
161       PBBoundaryDiNew->setVisible(0);
162       PBBoundaryDiHelp->setVisible(0); }
163   }
164 //
165 // Les options avancees (non modifiables)
166   CBAdvanced->setVisible(0) ;
167   CBAdvanced->setEnabled(false) ;
168   int Pyram = aCase->GetPyram();
169   MESSAGE("Pyram "<<Pyram);
170   if ( ( Pyram > 0 ) || ( ConfType < 0 ) || ( ConfType > 1 ) || ( ExtType > 0 ) )
171   { GBAdvancedOptions->setVisible(1);
172 //
173     if ( Pyram > 0 )
174     { CBPyramid->setChecked(true);
175       CBPyramid->setVisible(1);
176     }
177     else
178     { CBPyramid->setChecked(false);
179       CBPyramid->setVisible(0);
180     }
181     CBPyramid->setEnabled(false);
182 //
183     if ( ( ConfType == 0 ) || ( ConfType == -1 ) )
184     { if ( ConfType == 0 ) { RBStandard->setChecked(true); }
185       else                 { RBBox->setChecked(true); }
186       RBStandard->setVisible(1);
187       RBBox->setVisible(1);
188       RBNC1NpA->setVisible(0);
189       RBNCQuelconque->setVisible(0);
190     }
191     else
192     { if (ConfType==-2) { RBBox->setChecked(true);};
193       if (ConfType==1) { RBStandard->setChecked(true);};
194       if (ConfType==2) { RBNC1NpA->setChecked(true);};
195       if (ConfType==3) { RBNCQuelconque->setChecked(true);};
196       RBStandard->setVisible(1);
197       RBBox->setVisible(1);
198       RBNC1NpA->setVisible(1);
199       RBNCQuelconque->setVisible(1);
200     }
201     RBStandard->setEnabled(false);
202     RBBox->setEnabled(false);
203     RBNC1NpA->setEnabled(false);
204     RBNCQuelconque->setEnabled(false);
205 //
206     if ( ExtType == 0 )
207     { GBFormat->setVisible(0);
208       RBMED->setChecked(true);
209     }
210     else
211     { GBFormat->setVisible(1);
212       RBMED->setVisible(1);
213       RBSaturne2D->setVisible(1);
214       RBSaturne2D->setChecked(true);
215     }
216     RBMED->setEnabled(false);
217     RBSaturne2D->setEnabled(false);
218   }
219   else
220   { GBAdvancedOptions->setVisible(0);
221     CBPyramid->setChecked(false);
222     RBStandard->setChecked(true);
223     RBMED->setChecked(true);
224   }
225 //
226 // L'etat
227   int etat = aCase->GetState();
228   MESSAGE("etat "<<etat);
229   if ( etat == 0 ) { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE_0", 0)); }
230   else             { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE", 0)); }
231
232   Comment->setVisible(1);
233 //
234   adjustSize();
235 }
236
237 // -------------------------------------
238 bool MonEditCase::PushOnApply()
239 // -------------------------------------
240 {
241   return true ;
242 };