]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/MonEditHypothesis.cxx
Salome HOME
Modif Gerald 09/11
[modules/homard.git] / src / HOMARDGUI / MonEditHypothesis.cxx
1 // Copyright (C) 2011  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.
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 using namespace std;
21
22 #include "MonEditHypothesis.h"
23 #include "MonEditListGroup.h"
24
25 #include "SalomeApp_Tools.h"
26 #include "HOMARDGUI_Utils.h"
27 #include "HomardQtCommun.h"
28 #include <utilities.h>
29
30
31 // -------------------------------------------------------------------------------------------------------------------------------------
32 MonEditHypothesis::MonEditHypothesis( MonCreateIteration* parent, bool modal,
33                                       HOMARD::HOMARD_Gen_var myHomardGen,
34                                       QString aHypothesisName,
35                                       QString caseName,  QString aFieldFile ):
36 // -------------------------------------------------------------------------------------------------------------------------------------
37 /* Constructs a MonEditHypothesis
38     herite de MonCreateHypothesis
39 */
40     MonCreateHypothesis(parent, modal,myHomardGen, aHypothesisName, caseName, aFieldFile)
41 {
42     MESSAGE("Hypothese " << aHypothesisName.toStdString().c_str());
43     setWindowTitle(QObject::tr("HOM_HYPO_EDIT_WINDOW_TITLE"));
44     _aHypothesis    = _myHomardGen->GetHypothesis(_aHypothesisName.toStdString().c_str());
45     if (caseName == QString("") ){ _aCaseName = _aHypothesis->GetCaseCreation();}
46     InitValEdit();
47     InitGroupes();
48 }
49 // ------------------------------
50 MonEditHypothesis::~MonEditHypothesis()
51 // ------------------------------
52 {
53 }
54 // ------------------------------
55 void MonEditHypothesis::InitGroupes()
56 // ------------------------------
57 {
58     HOMARD::ListGroupType_var maListe = _aHypothesis->GetGroups();
59     for ( int i = 0; i < maListe->length(); i++ )
60        _aListeGroupes << QString(maListe[i]);
61
62     if (maListe->length() == 0) { CBGroupe->hide();}
63 }
64
65 // ------------------------------
66 void MonEditHypothesis::InitValEdit()
67 // ------------------------------
68 {
69       MESSAGE("Debut de InitValEdit");
70       LEHypothesisName->setText(_aHypothesisName);
71       LEHypothesisName->setReadOnly(true);
72       HOMARD::listeTypes_var ListTypes (_aHypothesis->GetAdapRefinUnRef());
73       ASSERT( ListTypes->length()==3) ;
74       _aTypeAdap = ListTypes[0];
75       _aTypeRaff = ListTypes[1];
76       _aTypeDera = ListTypes[2];
77
78       if (_aTypeAdap == -1) InitAdaptUniforme();
79       if (_aTypeAdap ==  0) InitAdaptZone();
80       if (_aTypeAdap ==  1) InitAdaptChamps();
81
82       RBUniDera->setDisabled(true);
83       RBUniRaff->setDisabled(true);
84
85       InitFieldInterp();
86
87       if (_aTypeAdap == 1 or _TypeFieldInterp >= 1 )
88       {
89         if (_aFieldFile == QString("")) { GBFieldFile->setVisible(0); }
90         else
91         {
92           GBFieldFile->setVisible(1);
93           LEFieldFile->setText(_aFieldFile);
94           LEFieldFile->setReadOnly(1);
95         }
96       }
97       else
98       {
99         GBFieldFile->setVisible(0);
100       }
101       adjustSize();
102 }
103 // ----------------------------------------
104 void MonEditHypothesis::InitAdaptUniforme()
105 // ----------------------------------------
106 // Affichage des informations pour une adaptation uniforme
107 {
108 //  Choix des options generales
109     GBFieldManagement->setVisible(0);
110     GBAreaManagement->setVisible(0);
111     GBUniform->setVisible(1);
112     adjustSize();
113     RBUniforme->setChecked(true);
114     RBUniforme->setEnabled(false);
115     RBChamp->setEnabled(false);
116     RBZone->setEnabled(false);
117 //
118 // Raffinement ou deraffinement ?
119     if (_aTypeDera == 0)
120     {
121         ASSERT(_aTypeRaff==1);
122         RBUniDera->setChecked(false);
123         RBUniRaff->setChecked(true);
124     }
125     if (_aTypeDera == 1)
126     {
127         ASSERT(_aTypeRaff==0);
128         RBUniDera->setChecked(true);
129         RBUniRaff->setChecked(false);
130     }
131 //
132 }
133 // -------------------------------------
134 void MonEditHypothesis::InitAdaptZone()
135 // -------------------------------------
136 // Affichage des informations pour une adaptation selon des zones :
137 {
138 // . Liste des zones
139
140 //  Choix des options generales
141     GBUniform->setVisible(0);
142     GBFieldManagement->setVisible(0);
143     GBAreaManagement->setVisible(1);
144     adjustSize();
145     RBZone->setChecked(true);
146     RBChamp->setEnabled(false);
147     RBUniforme->setEnabled(false);
148     RBZone->setEnabled(false);
149
150 //  Recuperation de toutes les zones decrites et notation de celles retenues
151     GetAllZones();
152     HOMARD::listeZonesHypo_var mesZonesAvant = _aHypothesis->GetZones();
153     for (int i=0; i<mesZonesAvant->length(); i++)
154     {
155         for ( int j =0 ; j < TWZone->rowCount(); j++)
156         {
157             if (TWZone->item(j,1)->text().toStdString() == string(mesZonesAvant[i]))
158             {
159                TWZone->item( j,0 )->setCheckState( Qt::Checked );
160                break;
161             }
162         }
163     }
164 //
165 //  Inactivation des choix
166     for ( int j =0 ; j < TWZone->rowCount(); j++)
167     {
168         TWZone->item( j, 0 )->setFlags(0);
169     }
170     PBZoneNew->setVisible(0);
171 //
172 }
173
174 // -------------------------------------
175 void MonEditHypothesis::InitAdaptChamps()
176 // -------------------------------------
177 // Affichage des informations pour une adaptation selon un champ :
178 // . Nom du champ
179 // . Composantes
180 // . Seuils
181 // . Absolu/relatif
182 {
183     MESSAGE ("Debut de InitAdaptChamps");
184 //  Choix des options generales
185     GBUniform->setVisible(0);
186     GBAreaManagement->setVisible(0);
187     GBFieldManagement->setVisible(1);
188     adjustSize();
189     RBChamp->setChecked(true);
190     RBUniforme->setEnabled(false);
191     RBChamp->setEnabled(false);
192     RBZone->setEnabled(false);
193
194
195
196     HOMARD::InfosHypo_var  aInfosHypo = _aHypothesis->GetField();
197     _aFieldName =  aInfosHypo->FieldName;
198     _TypeThR = aInfosHypo->TypeThR;
199     _ThreshR = aInfosHypo->ThreshR;
200     _TypeThC = aInfosHypo->TypeThC;
201     _ThreshC = aInfosHypo->ThreshC;
202     _UsField = aInfosHypo->UsField;
203     _UsCmpI  = aInfosHypo->UsCmpI;
204
205
206     CBFieldName->insertItem(0,_aFieldName);
207     CBFieldName->setCurrentIndex(0);
208     CBFieldName->setEnabled(false);
209     //SetFieldName(Qt::Unchecked);
210
211     HOMARD::listeComposantsHypo_var mesComposantsAvant = _aHypothesis->GetListComp();
212     TWCMP->clear();
213     TWCMP->setRowCount(0);
214     TWCMP->resizeRowsToContents();
215     for (int i=0; i<mesComposantsAvant->length(); i++)
216     {
217        TWCMP->insertRow(0);
218        TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
219        TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
220        TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
221        TWCMP->item( 0, 0 )->setFlags( 0 );
222        TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
223        TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
224     }
225     TWCMP->resizeColumnsToContents();
226     TWCMP->resizeRowsToContents();
227     TWCMP->clearSelection();
228
229   // Les seuils de raffinement
230   RBRAbs->setEnabled(false) ;
231   RBRRel->setEnabled(false) ;
232   RBRPE->setEnabled(false) ;
233   RBRNo->setEnabled(false) ;
234   if (_aTypeRaff== 0 )
235   {
236     SetRNo();
237     RBRNo->setEnabled(true) ;
238   }
239   else
240   {
241     if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
242     if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
243     if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR);  SetRPE();  RBRPE->setEnabled(true);}
244   }
245
246   // Les seuils de deraffinement
247   RBCAbs->setEnabled(false) ;
248   RBCRel->setEnabled(false) ;
249   RBCPE->setEnabled(false) ;
250   RBCNo->setEnabled(false) ;
251   if (_aTypeDera== 0 )
252   {
253     SetCNo();
254     RBCNo->setEnabled(true) ;
255   }
256   else
257   {
258     if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
259     if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
260     if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC);  SetCPE(); RBCPE->setEnabled(true);}
261   }
262   // Le choix de la prise en compte des composantes
263   if ( TWCMP->rowCount() == 1 )
264   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
265     RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
266   }
267   else
268   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
269     RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
270   }
271   if ( _UsField == 0 ) { CBJump->hide(); }
272   else
273   {
274     CBJump->setChecked(true);
275     CBJump->setEnabled(false);
276   }
277   if ( _UsCmpI == 0 )
278   {
279     RBL2->setChecked(true);
280     RBL2->setEnabled(true);
281     RBInf->setEnabled(false) ;
282   }
283   else
284   {
285     RBL2->setEnabled(false) ;
286     RBInf->setChecked(true);
287     RBInf->setEnabled(true);
288   }
289 }
290 // -------------------------------------
291 void MonEditHypothesis::InitFieldInterp()
292 // -------------------------------------
293 // Affichage des informations pour les interpolations
294 {
295     MESSAGE ("Debut de InitFieldInterp");
296 //  Choix des options generales
297     _TypeFieldInterp = _aHypothesis->GetTypeFieldInterp();
298     MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
299 //
300 //  Aucune interpolation
301     if ( _TypeFieldInterp == 0 )
302     {
303       RBFieldNo->setChecked(true);
304       TWField->setVisible(0);
305     }
306 //  Interpolation de tous les champs
307     if ( _TypeFieldInterp == 1 )
308     {
309       RBFieldAll->setChecked(true);
310       TWField->setVisible(0);
311     }
312 //  Interpolation de champs choisis
313     if ( _TypeFieldInterp == 2 )
314     {
315       RBFieldChosen->setChecked(true);
316 //
317       TWField->setVisible(1);
318       HOMARD::listFieldInterpHypo_var mesChampsAvant = _aHypothesis->GetListFieldInterp();
319       TWField->clear();
320       TWField->setRowCount(0);
321       TWField->resizeRowsToContents();
322       for (int i=0; i<mesChampsAvant->length(); i++)
323       {
324         TWField->insertRow(0);
325         TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
326         TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
327         TWField->item( 0, 0 )->setCheckState(Qt::Checked );
328         TWField->item( 0, 0 )->setFlags( 0 );
329         TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[i]).trimmed()));
330         TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
331       }
332       TWField->resizeColumnsToContents();
333       TWField->resizeRowsToContents();
334       TWField->clearSelection();
335     }
336     RBFieldNo->setEnabled(false) ;
337     RBFieldAll->setEnabled(false) ;
338     RBFieldChosen->setEnabled(false) ;
339 }
340
341 // -------------------------------------
342 bool MonEditHypothesis::PushOnApply()
343 // -------------------------------------
344 {
345 // Pour du raffinement selon un champ, les seuils ont-ils change ?
346   if ( _aTypeAdap ==  1 )
347   {
348     if (_aTypeRaff!= 0 )
349     {
350       if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
351       if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
352       if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value();  }
353       _aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
354     }
355     if (_aTypeDera!= 0 )
356     {
357       if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
358       if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
359       if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
360       _aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
361     }
362
363     _myHomardGen->InvalideHypo(_aHypothesisName.toStdString().c_str());
364     HOMARD_UTILS::updateObjBrowser();
365   }
366   return true;
367 };
368 // ------------------------------------------------------------------------
369 void MonEditHypothesis::SetFiltrage()
370 // ------------------------------------------------------------------------
371 {
372   if (CBGroupe->isChecked())
373   {
374     MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(_myHomardGen),_aCaseName, _aListeGroupes) ;
375     aDlg->show();
376   }
377 }
378