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