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