Salome HOME
Porting HOMARD SALOME module on WIN32 platform.
[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   adjustSize();
147 }
148 // ----------------------------------------
149 void MonEditHypothesis::InitAdaptUniforme()
150 // ----------------------------------------
151 // Affichage des informations pour une adaptation uniforme
152 {
153 //  Choix des options generales
154     GBFieldManagement->setVisible(0);
155     GBAreaManagement->setVisible(0);
156     GBUniform->setVisible(1);
157     adjustSize();
158     RBUniforme->setChecked(true);
159     RBUniforme->setEnabled(false);
160     RBChamp->setEnabled(false);
161     RBZone->setEnabled(false);
162 //
163 // Raffinement ou deraffinement ?
164     if (_aTypeDera == 0)
165     {
166         VERIFICATION(_aTypeRaff==1);
167         RBUniDera->setChecked(false);
168         RBUniRaff->setChecked(true);
169     }
170     if (_aTypeDera == 1)
171     {
172         VERIFICATION(_aTypeRaff==0);
173         RBUniDera->setChecked(true);
174         RBUniRaff->setChecked(false);
175     }
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     adjustSize();
189     RBZone->setChecked(true);
190     RBChamp->setEnabled(false);
191     RBUniforme->setEnabled(false);
192     RBZone->setEnabled(false);
193
194 //  Recuperation de toutes les zones decrites et notation de celles retenues
195     GetAllZones();
196     HOMARD::listeZonesHypo_var mesZonesAvant = aHypothesis->GetZones();
197     for (int i=0; i<mesZonesAvant->length(); i++)
198     {
199       MESSAGE ("i"<<i<<", zone :"<<string(mesZonesAvant[i])<<", type :"<<string(mesZonesAvant[i+1]));
200       for ( int j =0 ; j < TWZone->rowCount(); j++)
201       {
202         MESSAGE (". j"<<j<<", zone :"<<TWZone->item(j,2)->text().toStdString());
203         if ( TWZone->item(j,2)->text().toStdString() == string(mesZonesAvant[i]) )
204         {
205           MESSAGE ("OK avec "<<string(mesZonesAvant[i]));
206           if ( string(mesZonesAvant[i+1]) == "1" )
207           {
208             MESSAGE ("... RAFF");
209             TWZone->item( j,0 )->setCheckState( Qt::Checked );
210             TWZone->item( j,1 )->setCheckState( Qt::Unchecked ); }
211           else
212           {
213             MESSAGE ("... DERA");
214             TWZone->item( j,0 )->setCheckState( Qt::Unchecked );
215             TWZone->item( j,1 )->setCheckState( Qt::Checked ); }
216           break;
217         }
218       }
219       i += 1 ;
220     }
221 //
222 //  Inactivation des choix
223     for ( int j =0 ; j < TWZone->rowCount(); j++)
224     {
225       TWZone->item( j, 0 )->setFlags(0);
226       TWZone->item( j, 1 )->setFlags(0);
227     }
228     PBZoneNew->setVisible(0);
229 //
230 }
231 // -------------------------------------
232 void MonEditHypothesis::InitAdaptChamps()
233 // -------------------------------------
234 // Affichage des informations pour une adaptation selon un champ :
235 // . Nom du champ
236 // . Composantes
237 // . Seuils
238 // . Absolu/relatif
239 {
240     MESSAGE ("Debut de InitAdaptChamps");
241 //  Choix des options generales
242     GBUniform->setVisible(0);
243     GBAreaManagement->setVisible(0);
244     GBFieldManagement->setVisible(1);
245     adjustSize();
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 // -------------------------------------
349 void MonEditHypothesis::InitFieldInterp()
350 // -------------------------------------
351 // Affichage des informations pour les interpolations
352 {
353     MESSAGE ("Debut de InitFieldInterp");
354 //  Choix des options generales
355     _TypeFieldInterp = aHypothesis->GetTypeFieldInterp();
356     MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
357 //
358 //  Aucune interpolation
359     if ( _TypeFieldInterp == 0 )
360     {
361       RBFieldNo->setChecked(true);
362       TWField->setVisible(0);
363     }
364 //  Interpolation de tous les champs
365     if ( _TypeFieldInterp == 1 )
366     {
367       RBFieldAll->setChecked(true);
368       TWField->setVisible(0);
369     }
370 //  Interpolation de champs choisis
371     if ( _TypeFieldInterp == 2 )
372     {
373       RBFieldChosen->setChecked(true);
374 //
375       TWField->setVisible(1);
376       HOMARD::listeFieldInterpsHypo_var mesChampsAvant = aHypothesis->GetFieldInterps();
377       TWField->clear();
378       TWField->setRowCount(0);
379       TWField->resizeRowsToContents();
380       for (int iaux=0; iaux<mesChampsAvant->length(); iaux++)
381       {
382         TWField->insertRow(0);
383         TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
384         TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
385         TWField->item( 0, 0 )->setCheckState(Qt::Checked );
386         TWField->item( 0, 0 )->setFlags( 0 );
387         TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[iaux]).trimmed()));
388         TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
389         iaux++;
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(_Name.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