Salome HOME
Filtrage des types de fichiers dans la sélection
[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 #include "MonEditHypothesis.h"
21 #include "MonEditListGroup.h"
22
23 #include "SalomeApp_Tools.h"
24 #include "HOMARDGUI_Utils.h"
25 #include "HomardQtCommun.h"
26 #include "HOMARD.hxx"
27 #include <utilities.h>
28
29 using namespace std;
30
31 // ----------------------------------------------------------------------------
32 MonEditHypothesis::MonEditHypothesis( MonCreateIteration* parent, bool modal,
33                                       HOMARD::HOMARD_Gen_var myHomardGen,
34                                       QString Name,
35                                       QString caseName,  QString aFieldFile ):
36 // ----------------------------------------------------------------------------
37 /* Constructs a MonEditHypothesis
38     herite de MonCreateHypothesis
39 */
40     MonCreateHypothesis(parent, modal,myHomardGen, Name, caseName, aFieldFile)
41 {
42     MESSAGE("Hypothese " << Name.toStdString().c_str());
43     setWindowTitle(QObject::tr("HOM_HYPO_EDIT_WINDOW_TITLE"));
44     aHypothesis    = myHomardGen->GetHypothesis(_Name.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   LEName->setText(_Name);
71   LEName->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 || _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 // Les options avancees (non modifiables)
102   CBAdvanced->setVisible(0) ;
103   int NivMax = aHypothesis->GetNivMax();
104   double DiamMin = aHypothesis->GetDiamMin();
105   int AdapInit = aHypothesis->GetAdapInit();
106   int LevelOutput = aHypothesis->GetLevelOutput();
107   if ( NivMax > 0 || DiamMin > 0 || AdapInit != 0 || LevelOutput != 0 )
108   { GBAdvancedOptions->setVisible(1);
109     if ( NivMax > 0 )
110     { SpinBoxNivMax->setValue(NivMax);
111       SpinBoxNivMax->setDisabled(true); }
112     else
113     { TLMaximalLevel->setVisible(0);
114       SpinBoxNivMax->setVisible(0); }
115     if ( DiamMin > 0 )
116     { doubleSpinBoxDiamMin->setValue(DiamMin);
117       doubleSpinBoxDiamMin->setDisabled(true); }
118     else
119     { TLMinimalDiameter->setVisible(0);
120       doubleSpinBoxDiamMin->setVisible(0); }
121     if ( AdapInit != 0 )
122     {
123       if ( AdapInit > 0 )
124       { RBAIR->setChecked(true); }
125       else
126       { RBAID->setChecked(true); }
127       RBAIN->setEnabled(false);
128       RBAIR->setEnabled(false);
129       RBAID->setEnabled(false);
130     }
131     else
132     { GBAdapInit->setVisible(0) ;
133     }
134     if ( LevelOutput != 0 )
135     {
136       CBLevelOutput->setChecked(true);
137       CBLevelOutput->setEnabled(false);
138     }
139     else
140     { CBLevelOutput->setVisible(0) ;
141     }
142   }
143   else
144   { GBAdvancedOptions->setVisible(0); }
145 //
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   RBUniforme->setChecked(true);
157   RBUniforme->setEnabled(false);
158   RBChamp->setEnabled(false);
159   RBZone->setEnabled(false);
160 //
161 // Raffinement ou deraffinement ?
162   if (_aTypeDera == 0)
163   {
164       VERIFICATION(_aTypeRaff==1);
165       RBUniDera->setChecked(false);
166       RBUniRaff->setChecked(true);
167   }
168   if (_aTypeDera == 1)
169   {
170       VERIFICATION(_aTypeRaff==0);
171       RBUniDera->setChecked(true);
172       RBUniRaff->setChecked(false);
173   }
174 //
175   adjustSize();
176 //
177 }
178 // -------------------------------------
179 void MonEditHypothesis::InitAdaptZone()
180 // -------------------------------------
181 // Affichage des informations pour une adaptation selon des zones :
182 {
183   MESSAGE ("Debut de InitAdaptZone");
184 //  Choix des options generales
185   GBUniform->setVisible(0);
186   GBFieldManagement->setVisible(0);
187   GBAreaManagement->setVisible(1);
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   adjustSize();
230 //
231 }
232 // -------------------------------------
233 void MonEditHypothesis::InitAdaptChamps()
234 // -------------------------------------
235 // Affichage des informations pour une adaptation selon un champ :
236 // . Nom du champ
237 // . Composantes
238 // . Seuils
239 // . Absolu/relatif
240 {
241     MESSAGE ("Debut de InitAdaptChamps");
242 //  Choix des options generales
243     GBUniform->setVisible(0);
244     GBAreaManagement->setVisible(0);
245     GBFieldManagement->setVisible(1);
246     RBChamp->setChecked(true);
247     RBUniforme->setEnabled(false);
248     RBChamp->setEnabled(false);
249     RBZone->setEnabled(false);
250
251     HOMARD::InfosHypo_var  aInfosHypo = aHypothesis->GetField();
252     _aFieldName =  aInfosHypo->FieldName;
253     _TypeThR = aInfosHypo->TypeThR;
254     _ThreshR = aInfosHypo->ThreshR;
255     _TypeThC = aInfosHypo->TypeThC;
256     _ThreshC = aInfosHypo->ThreshC;
257     _UsField = aInfosHypo->UsField;
258     _UsCmpI  = aInfosHypo->UsCmpI;
259
260     CBFieldName->insertItem(0,_aFieldName);
261     CBFieldName->setCurrentIndex(0);
262     CBFieldName->setEnabled(false);
263     //SetFieldName(Qt::Unchecked);
264
265     HOMARD::listeComposantsHypo_var mesComposantsAvant = aHypothesis->GetComps();
266     TWCMP->clear();
267     TWCMP->setRowCount(0);
268     TWCMP->resizeRowsToContents();
269     for (int i=0; i<mesComposantsAvant->length(); i++)
270     {
271        TWCMP->insertRow(0);
272        TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
273        TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
274        TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
275        TWCMP->item( 0, 0 )->setFlags( 0 );
276        TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
277        TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
278     }
279     TWCMP->resizeColumnsToContents();
280     TWCMP->resizeRowsToContents();
281     TWCMP->clearSelection();
282
283   // Les seuils de raffinement
284   RBRAbs->setEnabled(false) ;
285   RBRRel->setEnabled(false) ;
286   RBRPE->setEnabled(false) ;
287   RBRMuSigma->setEnabled(false) ;
288   RBRNo->setEnabled(false) ;
289   if (_aTypeRaff== 0 )
290   {
291     SetRNo();
292     RBRNo->setEnabled(true) ;
293   }
294   else
295   {
296     if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
297     if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
298     if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR);  SetRPE();  RBRPE->setEnabled(true);}
299     if ( _TypeThR == 4 ) { SpinBox_RMuSigma->setValue(_ThreshR);  SetRMS();  RBRMuSigma->setEnabled(true);}
300   }
301
302   // Les seuils de deraffinement
303   RBCAbs->setEnabled(false) ;
304   RBCRel->setEnabled(false) ;
305   RBCPE->setEnabled(false) ;
306   RBCMuSigma->setEnabled(false) ;
307   RBCNo->setEnabled(false) ;
308   if (_aTypeDera== 0 )
309   {
310     SetCNo();
311     RBCNo->setEnabled(true) ;
312   }
313   else
314   {
315     if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
316     if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
317     if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC);  SetCPE(); RBCPE->setEnabled(true);}
318     if ( _TypeThC == 4 ) { SpinBox_CMuSigma->setValue(_ThreshC);  SetCMS();  RBCMuSigma->setEnabled(true);}
319   }
320   // Le choix de la prise en compte des composantes
321   if ( TWCMP->rowCount() == 1 )
322   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
323     RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
324   }
325   else
326   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
327     RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
328   }
329   if ( _UsField == 0 ) { CBJump->hide(); }
330   else
331   {
332     CBJump->setChecked(true);
333     CBJump->setEnabled(false);
334   }
335   if ( _UsCmpI == 0 )
336   {
337     RBL2->setChecked(true);
338     RBL2->setEnabled(true);
339     RBInf->setEnabled(false) ;
340   }
341   else
342   {
343     RBL2->setEnabled(false) ;
344     RBInf->setChecked(true);
345     RBInf->setEnabled(true);
346   }
347 //
348   adjustSize();
349 }
350 // -------------------------------------
351 void MonEditHypothesis::InitFieldInterp()
352 // -------------------------------------
353 // Affichage des informations pour les interpolations
354 {
355     MESSAGE ("Debut de InitFieldInterp");
356 //  Choix des options generales
357     _TypeFieldInterp = aHypothesis->GetTypeFieldInterp();
358     MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
359 //
360 //  Aucune interpolation
361     if ( _TypeFieldInterp == 0 )
362     {
363       RBFieldNo->setChecked(true);
364       TWField->setVisible(0);
365     }
366 //  Interpolation de tous les champs
367     if ( _TypeFieldInterp == 1 )
368     {
369       RBFieldAll->setChecked(true);
370       TWField->setVisible(0);
371     }
372 //  Interpolation de champs choisis
373     if ( _TypeFieldInterp == 2 )
374     {
375       RBFieldChosen->setChecked(true);
376 //
377       TWField->setVisible(1);
378       HOMARD::listeFieldInterpsHypo_var mesChampsAvant = aHypothesis->GetFieldInterps();
379       TWField->clear();
380       TWField->setRowCount(0);
381       TWField->resizeRowsToContents();
382       for (int iaux=0; iaux<mesChampsAvant->length(); iaux++)
383       {
384         TWField->insertRow(0);
385         TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
386         TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
387         TWField->item( 0, 0 )->setCheckState(Qt::Checked );
388         TWField->item( 0, 0 )->setFlags( 0 );
389         TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[iaux]).trimmed()));
390         TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
391         iaux++;
392       }
393       TWField->resizeColumnsToContents();
394       TWField->resizeRowsToContents();
395       TWField->clearSelection();
396     }
397     RBFieldNo->setEnabled(false) ;
398     RBFieldAll->setEnabled(false) ;
399     RBFieldChosen->setEnabled(false) ;
400 }
401
402 // -------------------------------------
403 bool MonEditHypothesis::PushOnApply()
404 // -------------------------------------
405 {
406 // Pour du raffinement selon un champ, les seuils ont-ils change ?
407   if ( _aTypeAdap ==  1 )
408   {
409     if (_aTypeRaff!= 0 )
410     {
411       if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
412       if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
413       if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value();  }
414       if (_TypeThR == 4) { _ThreshR = SpinBox_RMuSigma->value();  }
415       aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
416     }
417     if (_aTypeDera!= 0 )
418     {
419       if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
420       if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
421       if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
422       if (_TypeThC == 4) { _ThreshC = SpinBox_CMuSigma->value() ; }
423       aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
424     }
425
426     myHomardGen->InvalideHypo(_Name.toStdString().c_str());
427     HOMARD_UTILS::updateObjBrowser();
428   }
429   return true;
430 };
431 // ------------------------------------------------------------------------
432 void MonEditHypothesis::SetFiltrage()
433 // ------------------------------------------------------------------------
434 {
435   if (CBGroupe->isChecked())
436   {
437     MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),_aCaseName, _aListeGroupes) ;
438     aDlg->show();
439   }
440 }
441