Salome HOME
Synchronize adm files
[modules/homard.git] / src / HOMARDGUI / MonEditHypothesis.cxx
1 // Copyright (C) 2011-2014  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, or (at your option) any later version.
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 ExtraOutput = aHypothesis->GetExtraOutput();
107   if ( NivMax > 0 || DiamMin > 0 || AdapInit != 0 || ExtraOutput != 1 )
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 ( ExtraOutput % 2 == 0 )
135     {
136       CBOutputLevel->setChecked(true);
137       CBOutputLevel->setEnabled(false);
138     }
139     else { CBOutputLevel->setVisible(0) ; }
140     if ( ExtraOutput % 3 == 0 )
141     {
142       CBOutputQuality->setChecked(true);
143       CBOutputQuality->setEnabled(false);
144     }
145     else { CBOutputQuality->setVisible(0) ; }
146     if ( ExtraOutput % 5 == 0 )
147     {
148       CBOutputDiameter->setChecked(true);
149       CBOutputDiameter->setEnabled(false);
150     }
151     else { CBOutputDiameter->setVisible(0) ; }
152   }
153   else
154   { GBAdvancedOptions->setVisible(0); }
155 //
156 }
157 // ----------------------------------------
158 void MonEditHypothesis::InitAdaptUniforme()
159 // ----------------------------------------
160 // Affichage des informations pour une adaptation uniforme
161 {
162 //  Choix des options generales
163   GBFieldManagement->setVisible(0);
164   GBAreaManagement->setVisible(0);
165   GBUniform->setVisible(1);
166   RBUniforme->setChecked(true);
167   RBUniforme->setEnabled(false);
168   RBChamp->setEnabled(false);
169   RBZone->setEnabled(false);
170 //
171 // Raffinement ou deraffinement ?
172   if (_aTypeDera == 0)
173   {
174       VERIFICATION(_aTypeRaff==1);
175       RBUniDera->setChecked(false);
176       RBUniRaff->setChecked(true);
177   }
178   if (_aTypeDera == 1)
179   {
180       VERIFICATION(_aTypeRaff==0);
181       RBUniDera->setChecked(true);
182       RBUniRaff->setChecked(false);
183   }
184 //
185   adjustSize();
186 //
187 }
188 // -------------------------------------
189 void MonEditHypothesis::InitAdaptZone()
190 // -------------------------------------
191 // Affichage des informations pour une adaptation selon des zones :
192 {
193   MESSAGE ("Debut de InitAdaptZone");
194 //  Choix des options generales
195   GBUniform->setVisible(0);
196   GBFieldManagement->setVisible(0);
197   GBAreaManagement->setVisible(1);
198   RBZone->setChecked(true);
199   RBChamp->setEnabled(false);
200   RBUniforme->setEnabled(false);
201   RBZone->setEnabled(false);
202
203 //  Recuperation de toutes les zones decrites et notation de celles retenues
204   GetAllZones();
205   HOMARD::listeZonesHypo_var mesZonesAvant = aHypothesis->GetZones();
206   for (int i=0; i<mesZonesAvant->length(); i++)
207   {
208     MESSAGE ("i"<<i<<", zone :"<<string(mesZonesAvant[i])<<", type :"<<string(mesZonesAvant[i+1]));
209     for ( int j =0 ; j < TWZone->rowCount(); j++)
210     {
211       MESSAGE (". j"<<j<<", zone :"<<TWZone->item(j,2)->text().toStdString());
212       if ( TWZone->item(j,2)->text().toStdString() == string(mesZonesAvant[i]) )
213       {
214         MESSAGE ("OK avec "<<string(mesZonesAvant[i]));
215         if ( string(mesZonesAvant[i+1]) == "1" )
216         {
217           MESSAGE ("... RAFF");
218           TWZone->item( j,0 )->setCheckState( Qt::Checked );
219           TWZone->item( j,1 )->setCheckState( Qt::Unchecked ); }
220         else
221         {
222           MESSAGE ("... DERA");
223           TWZone->item( j,0 )->setCheckState( Qt::Unchecked );
224           TWZone->item( j,1 )->setCheckState( Qt::Checked ); }
225         break;
226       }
227     }
228     i += 1 ;
229   }
230 //
231 //  Inactivation des choix
232   for ( int j =0 ; j < TWZone->rowCount(); j++)
233   {
234     TWZone->item( j, 0 )->setFlags(0);
235     TWZone->item( j, 1 )->setFlags(0);
236   }
237   PBZoneNew->setVisible(0);
238 //
239   adjustSize();
240 //
241 }
242 // -------------------------------------
243 void MonEditHypothesis::InitAdaptChamps()
244 // -------------------------------------
245 // Affichage des informations pour une adaptation selon un champ :
246 // . Nom du champ
247 // . Composantes
248 // . Seuils
249 // . Absolu/relatif
250 {
251     MESSAGE ("Debut de InitAdaptChamps");
252 //  Choix des options generales
253     GBUniform->setVisible(0);
254     GBAreaManagement->setVisible(0);
255     GBFieldManagement->setVisible(1);
256     RBChamp->setChecked(true);
257     RBUniforme->setEnabled(false);
258     RBChamp->setEnabled(false);
259     RBZone->setEnabled(false);
260
261     HOMARD::InfosHypo_var  aInfosHypo = aHypothesis->GetField();
262     _aFieldName =  aInfosHypo->FieldName;
263     _TypeThR = aInfosHypo->TypeThR;
264     _ThreshR = aInfosHypo->ThreshR;
265     _TypeThC = aInfosHypo->TypeThC;
266     _ThreshC = aInfosHypo->ThreshC;
267     _UsField = aInfosHypo->UsField;
268     _UsCmpI  = aInfosHypo->UsCmpI;
269
270     CBFieldName->insertItem(0,_aFieldName);
271     CBFieldName->setCurrentIndex(0);
272     CBFieldName->setEnabled(false);
273     //SetFieldName(Qt::Unchecked);
274
275     HOMARD::listeComposantsHypo_var mesComposantsAvant = aHypothesis->GetComps();
276     TWCMP->clear();
277     TWCMP->setRowCount(0);
278     TWCMP->resizeRowsToContents();
279     for (int i=0; i<mesComposantsAvant->length(); i++)
280     {
281        TWCMP->insertRow(0);
282        TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
283        TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
284        TWCMP->item( 0, 0 )->setCheckState(Qt::Checked );
285        TWCMP->item( 0, 0 )->setFlags( 0 );
286        TWCMP->setItem( 0, 1, new QTableWidgetItem(QString(mesComposantsAvant[i]).trimmed()));
287        TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
288     }
289     TWCMP->resizeColumnsToContents();
290     TWCMP->resizeRowsToContents();
291     TWCMP->clearSelection();
292
293   // Les seuils de raffinement
294   RBRAbs->setEnabled(false) ;
295   RBRRel->setEnabled(false) ;
296   RBRPE->setEnabled(false) ;
297   RBRMuSigma->setEnabled(false) ;
298   RBRNo->setEnabled(false) ;
299   if (_aTypeRaff== 0 )
300   {
301     SetRNo();
302     RBRNo->setEnabled(true) ;
303   }
304   else
305   {
306     if ( _TypeThR == 1 ) { SpinBox_RAbs->setValue(_ThreshR); SetRAbs(); RBRAbs->setEnabled(true);}
307     if ( _TypeThR == 2 ) { SpinBox_RRel->setValue(_ThreshR); SetRRel(); RBRRel->setEnabled(true);}
308     if ( _TypeThR == 3 ) { SpinBox_RPE->setValue(_ThreshR);  SetRPE();  RBRPE->setEnabled(true);}
309     if ( _TypeThR == 4 ) { SpinBox_RMuSigma->setValue(_ThreshR);  SetRMS();  RBRMuSigma->setEnabled(true);}
310   }
311
312   // Les seuils de deraffinement
313   RBCAbs->setEnabled(false) ;
314   RBCRel->setEnabled(false) ;
315   RBCPE->setEnabled(false) ;
316   RBCMuSigma->setEnabled(false) ;
317   RBCNo->setEnabled(false) ;
318   if (_aTypeDera== 0 )
319   {
320     SetCNo();
321     RBCNo->setEnabled(true) ;
322   }
323   else
324   {
325     if ( _TypeThC == 1 ) { SpinBox_CAbs->setValue(_ThreshC); SetCAbs(); RBCAbs->setEnabled(true);}
326     if ( _TypeThC == 2 ) { SpinBox_CRel->setValue(_ThreshC); SetCRel(); RBCRel->setEnabled(true);}
327     if ( _TypeThC == 3 ) { SpinBox_CPE->setValue(_ThreshC);  SetCPE(); RBCPE->setEnabled(true);}
328     if ( _TypeThC == 4 ) { SpinBox_CMuSigma->setValue(_ThreshC);  SetCMS();  RBCMuSigma->setEnabled(true);}
329   }
330   // Le choix de la prise en compte des composantes
331   if ( TWCMP->rowCount() == 1 )
332   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
333     RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
334   }
335   else
336   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
337     RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
338   }
339   if ( _UsField == 0 ) { CBJump->hide(); }
340   else
341   {
342     CBJump->setChecked(true);
343     CBJump->setEnabled(false);
344   }
345   if ( _UsCmpI == 0 )
346   {
347     RBL2->setChecked(true);
348     RBL2->setEnabled(true);
349     RBInf->setEnabled(false) ;
350   }
351   else
352   {
353     RBL2->setEnabled(false) ;
354     RBInf->setChecked(true);
355     RBInf->setEnabled(true);
356   }
357 //
358   adjustSize();
359 }
360 // -------------------------------------
361 void MonEditHypothesis::InitFieldInterp()
362 // -------------------------------------
363 // Affichage des informations pour les interpolations
364 {
365     MESSAGE ("Debut de InitFieldInterp");
366 //  Choix des options generales
367     _TypeFieldInterp = aHypothesis->GetTypeFieldInterp();
368     MESSAGE ("_TypeFieldInterp = " << _TypeFieldInterp);
369 //
370 //  Aucune interpolation
371     if ( _TypeFieldInterp == 0 )
372     {
373       RBFieldNo->setChecked(true);
374       TWField->setVisible(0);
375     }
376 //  Interpolation de tous les champs
377     if ( _TypeFieldInterp == 1 )
378     {
379       RBFieldAll->setChecked(true);
380       TWField->setVisible(0);
381     }
382 //  Interpolation de champs choisis
383     if ( _TypeFieldInterp == 2 )
384     {
385       RBFieldChosen->setChecked(true);
386 //
387       TWField->setVisible(1);
388       HOMARD::listeFieldInterpsHypo_var mesChampsAvant = aHypothesis->GetFieldInterps();
389       TWField->clear();
390       TWField->setRowCount(0);
391       TWField->resizeRowsToContents();
392       for (int iaux=0; iaux<mesChampsAvant->length(); iaux++)
393       {
394         TWField->insertRow(0);
395         TWField->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
396         TWField->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
397         TWField->item( 0, 0 )->setCheckState(Qt::Checked );
398         TWField->item( 0, 0 )->setFlags( 0 );
399         TWField->setItem( 0, 1, new QTableWidgetItem(QString(mesChampsAvant[iaux]).trimmed()));
400         TWField->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
401         iaux++;
402       }
403       TWField->resizeColumnsToContents();
404       TWField->resizeRowsToContents();
405       TWField->clearSelection();
406     }
407     RBFieldNo->setEnabled(false) ;
408     RBFieldAll->setEnabled(false) ;
409     RBFieldChosen->setEnabled(false) ;
410 }
411
412 // -------------------------------------
413 bool MonEditHypothesis::PushOnApply()
414 // -------------------------------------
415 {
416 // Pour du raffinement selon un champ, les seuils ont-ils change ?
417   if ( _aTypeAdap ==  1 )
418   {
419     if (_aTypeRaff!= 0 )
420     {
421       if (_TypeThR == 1) { _ThreshR = SpinBox_RAbs->value(); }
422       if (_TypeThR == 2) { _ThreshR = SpinBox_RRel->value(); }
423       if (_TypeThR == 3) { _ThreshR = SpinBox_RPE->value();  }
424       if (_TypeThR == 4) { _ThreshR = SpinBox_RMuSigma->value();  }
425       aHypothesis->SetRefinThr(_TypeThR, _ThreshR) ;
426     }
427     if (_aTypeDera!= 0 )
428     {
429       if (_TypeThC == 1) { _ThreshC = SpinBox_CAbs->value() ; }
430       if (_TypeThC == 2) { _ThreshC = SpinBox_CRel->value() ; }
431       if (_TypeThC == 3) { _ThreshC = SpinBox_CPE->value() ; }
432       if (_TypeThC == 4) { _ThreshC = SpinBox_CMuSigma->value() ; }
433       aHypothesis->SetUnRefThr(_TypeThC, _ThreshC) ;
434     }
435
436     myHomardGen->InvalideHypo(_Name.toStdString().c_str());
437     HOMARD_UTILS::updateObjBrowser();
438   }
439   return true;
440 };
441 // ------------------------------------------------------------------------
442 void MonEditHypothesis::SetFiltrage()
443 // ------------------------------------------------------------------------
444 {
445   if (CBGroupe->isChecked())
446   {
447     MonEditListGroup *aDlg = new MonEditListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),_aCaseName, _aListeGroupes) ;
448     aDlg->show();
449   }
450 }
451