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