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