Salome HOME
1035eae63aae542abafb41a443ddcf66da82a22f
[modules/homard.git] / src / HOMARDGUI / MonEditCase.cxx
1 // Copyright (C) 2011-2016  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
78 // Suivi de frontiere
79 // A priori, aucun affichage
80   GBTypeBoun->setVisible(0);
81   CBBoundaryD->setVisible(0);
82   CBBoundaryA->setVisible(0);
83   GBBoundaryC->setVisible(0);
84   GBBoundaryD->setVisible(0);
85   GBBoundaryA->setVisible(0);
86 //    On passe en revue tous les couples (frontiere,groupe) du cas
87   HOMARD::ListBoundaryGroupType_var mesBoundarys = aCase->GetBoundaryGroup();
88   if (mesBoundarys->length()>0)
89   {
90     QStringList ListeFron ;
91     QString NomFron ;
92     bool BounCAO = false ;
93     bool BounDi = false ;
94     bool BounAn = false ;
95     for (int i=0; i<mesBoundarys->length(); i++)
96     {
97 //    Nom de la frontiere
98       NomFron = mesBoundarys[i++];
99       MESSAGE("NomFron "<<NomFron.toStdString().c_str());
100 //    L'objet associe pour en deduire le type
101       HOMARD::HOMARD_Boundary_var myBoundary = myHomardGen->GetBoundary(NomFron.toStdString().c_str());
102       int type_obj = myBoundary->GetType() ;
103       MESSAGE("type_obj "<<type_obj);
104 //        C'est une frontiere CAO
105 //        Remarque : on ne gere pas les groupes
106       if ( type_obj==-1 )
107       {
108         BounCAO = true ;
109         CBBoundaryCAO->addItem(NomFron);
110       }
111 //        C'est une frontiere discrete
112 //        Rermarque : on ne gere pas les groupes
113       else if ( type_obj==0 )
114       {
115         BounDi = true ;
116         CBBoundaryDi->addItem(NomFron);
117       }
118 //        C'est une frontiere analytique
119       else
120       {
121         BounAn = true ;
122         int nbcol = TWBoundary->columnCount();
123 //          On ajoute une ligne pour le groupe
124         TWBoundary->insertRow(0);
125 //          La colonne 0 comporte le nom du groupe
126         TWBoundary->setItem( 0, 0, new QTableWidgetItem(QString(mesBoundarys[i]).trimmed()));
127 //             TWBoundary->item( 0, 0 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
128 //          Chacune des colonnes suivantes est associĆ© a une frontiere deja presente : on y met une
129 //          case non cochee
130         for ( int j = 1; j < nbcol; j++ )
131         {
132           TWBoundary->setItem( 0, j, new QTableWidgetItem( QString ("") ) );
133           TWBoundary->item( 0, j )->setFlags( 0 );
134           TWBoundary->item( 0, j )->setFlags( Qt::ItemIsUserCheckable  );
135           TWBoundary->item( 0, j )->setCheckState( Qt::Unchecked );
136         }
137 //          On cherche si la frontiere en cours d'examen a deja ete rencontree :
138 //          si oui, on stocke son numero de colonne
139         int ok = -1 ;
140         for ( int nufr = 0 ; nufr<ListeFron.size(); nufr++)
141         { if ( ListeFron[nufr] == NomFron ) ok = nufr+1 ; }
142 //            si non, on ajoute une colonne
143         if ( ok < 0 )
144         {
145           ListeFron.append(NomFron);
146           ok = ListeFron.size() ;
147           AddBoundaryAn(NomFron);
148         }
149 //          on coche la case correspondant au couple (frontiere,groupe) en cours d'examen
150         TWBoundary->item( 0, ok )->setCheckState( Qt::Checked );
151       }
152     }
153     MESSAGE("BounCAO "<<BounCAO<<",BounDi "<<BounDi<<", BounAn "<<BounAn);
154     GBTypeBoun->setVisible(1);
155     if ( BounCAO )
156     { RBBoundaryCAO->setChecked(true);
157       GBBoundaryC->setVisible(1);
158       CBBoundaryCAO->setDisabled(true);
159       PBBoundaryCAONew->setVisible(0);
160       PBBoundaryCAOHelp->setVisible(0); }
161     if ( BounDi )
162     { RBBoundaryNonCAO->setChecked(true);
163       GBBoundaryD->setVisible(1);
164       CBBoundaryDi->setDisabled(true);
165       PBBoundaryDiNew->setVisible(0);
166       PBBoundaryDiHelp->setVisible(0); }
167     if ( BounAn )
168     { RBBoundaryNonCAO->setChecked(true);
169       GBBoundaryA->setVisible(1);
170 //    On rend les cases non modifiables.
171 //    On ne peut pas le faire pour tout le tableau sinon on perd l'ascenseur !
172       int nbcol = TWBoundary->columnCount();
173       int nbrow = TWBoundary->rowCount();
174       for ( int i = 0; i < nbrow; i++ )
175       { for ( int j = 0; j < nbcol; j++ ) TWBoundary->item( i, j )->setFlags( Qt::ItemIsSelectable ); }
176 //    on met un nom blanc au coin
177       QTableWidgetItem *__colItem = new QTableWidgetItem();
178       __colItem->setText(QApplication::translate("CreateCase", "", 0));
179       TWBoundary->setHorizontalHeaderItem(0, __colItem);
180 //    on cache les boutons inutiles
181       PBBoundaryAnNew->setVisible(0);
182       PBBoundaryAnHelp->setVisible(0);
183     }
184     RBBoundaryNo->setEnabled(false);
185     RBBoundaryCAO->setEnabled(false);
186     RBBoundaryNonCAO->setEnabled(false);
187   }
188 //
189 // Les options avancees (non modifiables)
190   CBAdvanced->setVisible(0) ;
191   CBAdvanced->setEnabled(false) ;
192   int Pyram = aCase->GetPyram();
193   MESSAGE("Pyram "<<Pyram);
194   if ( ( Pyram > 0 ) || ( ConfType < 0 ) || ( ConfType > 1 ) || ( ExtType > 0 ) )
195   { GBAdvancedOptions->setVisible(1);
196 //
197     if ( Pyram > 0 )
198     { CBPyramid->setChecked(true);
199       CBPyramid->setVisible(1);
200     }
201     else
202     { CBPyramid->setChecked(false);
203       CBPyramid->setVisible(0);
204     }
205     CBPyramid->setEnabled(false);
206 //
207     if ( ( ConfType == 0 ) || ( ConfType == -1 ) )
208     { if ( ConfType == 0 ) { RBStandard->setChecked(true); }
209       else                 { RBBox->setChecked(true); }
210       RBStandard->setVisible(1);
211       RBBox->setVisible(1);
212       RBNC1NpA->setVisible(0);
213       RBNCQuelconque->setVisible(0);
214     }
215     else
216     { if (ConfType==-2) { RBBox->setChecked(true);};
217       if (ConfType==1) { RBStandard->setChecked(true);};
218       if (ConfType==2) { RBNC1NpA->setChecked(true);};
219       if (ConfType==3) { RBNCQuelconque->setChecked(true);};
220       RBStandard->setVisible(1);
221       RBBox->setVisible(1);
222       RBNC1NpA->setVisible(1);
223       RBNCQuelconque->setVisible(1);
224     }
225     RBStandard->setEnabled(false);
226     RBBox->setEnabled(false);
227     RBNC1NpA->setEnabled(false);
228     RBNCQuelconque->setEnabled(false);
229 //
230     if ( ExtType == 0 )
231     { GBFormat->setVisible(0);
232       RBMED->setChecked(true);
233     }
234     else
235     { GBFormat->setVisible(1);
236       RBMED->setVisible(1);
237       RBSaturne->setVisible(1);
238       RBSaturne2D->setVisible(1);
239       if ( ExtType == 1 ) { RBSaturne->setChecked(true); }
240       else                { RBSaturne2D->setChecked(true); }
241     }
242     RBMED->setEnabled(false);
243     RBSaturne->setEnabled(false);
244     RBSaturne2D->setEnabled(false);
245   }
246   else
247   { GBAdvancedOptions->setVisible(0);
248     CBPyramid->setChecked(false);
249     RBStandard->setChecked(true);
250     RBMED->setChecked(true);
251   }
252 //
253 // L'etat
254   int etat = aCase->GetState();
255   MESSAGE("etat "<<etat);
256   if ( etat == 0 ) { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE_0", 0)); }
257   else             { Comment->setText(QApplication::translate("CreateCase", "HOM_CASE_EDIT_STATE", 0)); }
258
259   Comment->setVisible(1);
260 //
261   adjustSize();
262 }
263
264 // -------------------------------------
265 bool MonEditCase::PushOnApply()
266 // -------------------------------------
267 {
268   return true ;
269 };