Salome HOME
c3a27b7d4921015690ecddc158721fde1a3206ed
[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 Name,
33                                       QString caseName,  QString aFieldFile ):
34 // ----------------------------------------------------------------------------
35 /* Constructs a MonEditHypothesis
36     herite de MonCreateHypothesis
37 */
38     MonCreateHypothesis(parent, modal,myHomardGen, Name, caseName, aFieldFile)
39 {
40     MESSAGE("Hypothese " << Name.toStdString().c_str());
41     setWindowTitle(QObject::tr("HOM_HYPO_EDIT_WINDOW_TITLE"));
42     aHypothesis    = myHomardGen->GetHypothesis(_Name.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   LEName->setText(_Name);
69   LEName->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     HOMARD::InfosHypo_var  aInfosHypo = aHypothesis->GetField();
250     _aFieldName =  aInfosHypo->FieldName;
251     _TypeThR = aInfosHypo->TypeThR;
252     _ThreshR = aInfosHypo->ThreshR;
253     _TypeThC = aInfosHypo->TypeThC;
254     _ThreshC = aInfosHypo->ThreshC;
255     _UsField = aInfosHypo->UsField;
256     _UsCmpI  = aInfosHypo->UsCmpI;
257
258     CBFieldName->insertItem(0,_aFieldName);
259     CBFieldName->setCurrentIndex(0);
260     CBFieldName->setEnabled(false);
261     //SetFieldName(Qt::Unchecked);
262
263     HOMARD::listeComposantsHypo_var mesComposantsAvant = aHypothesis->GetListComp();
264     TWCMP->clear();
265     TWCMP->setRowCount(0);
266     TWCMP->resizeRowsToContents();
267     for (int i=0; i<mesComposantsAvant->length(); i++)
268     {
269        TWCMP->insertRow(0);
270        TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
271        TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
272        TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
273        TWCMP->item( 0, 0 )->setFlags( 0 );
274        TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
275        TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
276     }
277     TWCMP->resizeColumnsToContents();
278     TWCMP->resizeRowsToContents();
279     TWCMP->clearSelection();
280
281   // Les seuils de raffinement
282   RBRAbs->setEnabled(false) ;
283   RBRRel->setEnabled(false) ;
284   RBRPE->setEnabled(false) ;
285   RBRMuSigma->setEnabled(false) ;
286   RBRNo->setEnabled(false) ;
287   if (_aTypeRaff== 0 )
288   {
289     SetRNo();
290     RBRNo->setEnabled(true) ;
291   }
292   else
293   {
294     if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
295     if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
296     if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR);  SetRPE();  RBRPE->setEnabled(true);}
297     if ( _TypeThR == 4 ) { SpinBox_RMuSigma->setValue(_ThreshR);  SetRMS();  RBRMuSigma->setEnabled(true);}
298   }
299
300   // Les seuils de deraffinement
301   RBCAbs->setEnabled(false) ;
302   RBCRel->setEnabled(false) ;
303   RBCPE->setEnabled(false) ;
304   RBCMuSigma->setEnabled(false) ;
305   RBCNo->setEnabled(false) ;
306   if (_aTypeDera== 0 )
307   {
308     SetCNo();
309     RBCNo->setEnabled(true) ;
310   }
311   else
312   {
313     if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
314     if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
315     if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC);  SetCPE(); RBCPE->setEnabled(true);}
316     if ( _TypeThC == 4 ) { SpinBox_CMuSigma->setValue(_ThreshC);  SetCMS();  RBCMuSigma->setEnabled(true);}
317   }
318   // Le choix de la prise en compte des composantes
319   if ( TWCMP->rowCount() == 1 )
320   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
321     RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
322   }
323   else
324   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
325     RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
326   }
327   if ( _UsField == 0 ) { CBJump->hide(); }
328   else
329   {
330     CBJump->setChecked(true);
331     CBJump->setEnabled(false);
332   }
333   if ( _UsCmpI == 0 )
334   {
335     RBL2->setChecked(true);
336     RBL2->setEnabled(true);
337     RBInf->setEnabled(false) ;
338   }
339   else
340   {
341     RBL2->setEnabled(false) ;
342     RBInf->setChecked(true);
343     RBInf->setEnabled(true);
344   }
345 }
346 // -------------------------------------
347 void MonEditHypothesis::InitFieldInterp()
348 // -------------------------------------
349 // Affichage des informations pour les interpolations
350 {
351     MESSAGE ("Debut de InitFieldInterp");
352 //  Choix des options generales
353     _TypeFieldInterp = aHypothesis->GetTypeFieldInterp();
354     MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
355 //
356 //  Aucune interpolation
357     if ( _TypeFieldInterp == 0 )
358     {
359       RBFieldNo->setChecked(true);
360       TWField->setVisible(0);
361     }
362 //  Interpolation de tous les champs
363     if ( _TypeFieldInterp == 1 )
364     {
365       RBFieldAll->setChecked(true);
366       TWField->setVisible(0);
367     }
368 //  Interpolation de champs choisis
369     if ( _TypeFieldInterp == 2 )
370     {
371       RBFieldChosen->setChecked(true);
372 //
373       TWField->setVisible(1);
374       HOMARD::listFieldInterpHypo_var mesChampsAvant = aHypothesis->GetListFieldInterp();
375       TWField->clear();
376       TWField->setRowCount(0);
377       TWField->resizeRowsToContents();
378       for (int i=0; i<mesChampsAvant->length(); i++)
379       {
380         TWField->insertRow(0);
381         TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
382         TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
383         TWField->item( 0, 0 )->setCheckState(Qt::Checked );
384         TWField->item( 0, 0 )->setFlags( 0 );
385         TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[i]).trimmed()));
386         TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
387       }
388       TWField->resizeColumnsToContents();
389       TWField->resizeRowsToContents();
390       TWField->clearSelection();
391     }
392     RBFieldNo->setEnabled(false) ;
393     RBFieldAll->setEnabled(false) ;
394     RBFieldChosen->setEnabled(false) ;
395 }
396
397 // -------------------------------------
398 bool MonEditHypothesis::PushOnApply()
399 // -------------------------------------
400 {
401 // Pour du raffinement selon un champ, les seuils ont-ils change ?
402   if ( _aTypeAdap ==  1 )
403   {
404     if (_aTypeRaff!= 0 )
405     {
406       if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
407       if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
408       if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value();  }
409       if (_TypeThR == 4) { _ThreshR = SpinBox_RMuSigma->value();  }
410       aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
411     }
412     if (_aTypeDera!= 0 )
413     {
414       if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
415       if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
416       if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
417       if (_TypeThC == 4) { _ThreshC = SpinBox_CMuSigma->value() ; }
418       aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
419     }
420
421     myHomardGen->InvalideHypo(_Name.toStdString().c_str());
422     HOMARD_UTILS::updateObjBrowser();
423   }
424   return true;
425 };
426 // ------------------------------------------------------------------------
427 void MonEditHypothesis::SetFiltrage()
428 // ------------------------------------------------------------------------
429 {
430   if (CBGroupe->isChecked())
431   {
432     MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),_aCaseName, _aListeGroupes) ;
433     aDlg->show();
434   }
435 }
436