Salome HOME
Update copyrights 2014.
[modules/homard.git] / src / HOMARDGUI / MonCreateHypothesis.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 "MonCreateHypothesis.h"
21 #include "MonCreateListGroup.h"
22 #include "MonCreateIteration.h"
23 #include "MonCreateZone.h"
24 #include "MonEditZone.h"
25
26 #include <QFileDialog>
27 #include <QMessageBox>
28
29 #include "SalomeApp_Tools.h"
30 #include "HOMARDGUI_Utils.h"
31 #include "HomardQtCommun.h"
32 #include <utilities.h>
33
34 using namespace std;
35
36 // -------------------------------------------------------------------------------
37 MonCreateHypothesis::MonCreateHypothesis(MonCreateIteration* parent, bool modal,
38                                          HOMARD::HOMARD_Gen_var myHomardGen0,
39                                          QString Name,
40                                          QString caseName, QString aFieldFile)
41 // ---------------------------------------------------------------------------------
42 /* Constructs a MonCreateHypothesis */
43     :
44     QScrollArea(0), Ui_CreateHypothesis(),
45     _parent(parent), _Name(Name),
46     _aCaseName(caseName), _aFieldFile(aFieldFile),
47     _aFieldName(""),
48     _aTypeAdap(-2), _aTypeRaff(1), _aTypeDera(0),
49     _TypeThR(3), _ThreshR(0),
50     _TypeThC(0), _ThreshC(0),
51     _UsField(0), _UsCmpI(0), _TypeFieldInterp(0),
52     _NivMax(-1),
53     _DiamMin(-1.),
54     _AdapInit(0),
55     _LevelOutput(0)
56
57 {
58       MESSAGE("Constructeur") ;
59       myHomardGen=HOMARD::HOMARD_Gen::_duplicate(myHomardGen0);
60       setupUi(this);
61       if ( modal ) { setWindowModality(Qt::WindowModal); }
62       else         { setWindowModality(Qt::NonModal); }
63       setWindowFlags( Qt::WindowStaysOnTopHint ) ;
64       InitConnect();
65
66       SetNewName();
67       if (_aFieldFile != QString(""))
68       { RBChamp->setChecked(1);
69         SetChamp();
70       }
71       else
72       { RBUniforme->setChecked(1);
73         SetUniforme();
74       }
75       SetFieldNo();
76       GBAdvancedOptions->setVisible(0);
77       CBLevelOutput->setChecked(false);
78 //
79       adjustSize();
80 }
81
82 // ------------------------------------------------------------------------
83 MonCreateHypothesis::~MonCreateHypothesis()
84 // ------------------------------------------------------------------------
85 {
86     // no need to delete child widgets, Qt does it all for us
87 }
88 // ------------------------------------------------------------------------
89 void MonCreateHypothesis::InitConnect()
90 // ------------------------------------------------------------------------
91 {
92     connect( RBUniforme,   SIGNAL(clicked()), this, SLOT(SetUniforme()));
93     connect( RBChamp,      SIGNAL(clicked()), this, SLOT(SetChamp()));
94     connect( RBZone,       SIGNAL(clicked()), this, SLOT(SetZone()));
95     connect( RBUniRaff,    SIGNAL(clicked()), this, SLOT(SetUniRaff()));
96     connect( RBUniDera,    SIGNAL(clicked()), this, SLOT(SetUniDera()));
97
98     connect( CBFieldName,  SIGNAL(activated(int)), this, SLOT( SetFieldName()));
99     connect( RBRPE,        SIGNAL(clicked()), this, SLOT(SetRPE()));
100     connect( RBRRel,       SIGNAL(clicked()), this, SLOT(SetRRel()));
101     connect( RBRMuSigma,   SIGNAL(clicked()), this, SLOT(SetRMS()));
102     connect( RBRAbs,       SIGNAL(clicked()), this, SLOT(SetRAbs()));
103     connect( RBRNo,        SIGNAL(clicked()), this, SLOT(SetRNo()));
104     connect( RBCPE,        SIGNAL(clicked()), this, SLOT(SetCPE()));
105     connect( RBCRel,       SIGNAL(clicked()), this, SLOT(SetCRel()));
106     connect( RBCMuSigma,   SIGNAL(clicked()), this, SLOT(SetCMS()));
107     connect( RBCAbs,       SIGNAL(clicked()), this, SLOT(SetCAbs()));
108     connect( RBCNo,        SIGNAL(clicked()), this, SLOT(SetCNo()));
109     connect( RBL2,         SIGNAL(clicked()), this, SLOT(SetUCL2()));
110     connect( RBInf,        SIGNAL(clicked()), this, SLOT(SetUCInf()));
111     connect( CBJump,       SIGNAL(stateChanged(int)), this, SLOT(SetUseField()));
112     connect( PBZoneNew,    SIGNAL(pressed()), this, SLOT(PushZoneNew()));
113     connect( PBZoneEdit,   SIGNAL(pressed()), this, SLOT(PushZoneEdit()) );
114     connect( PBZoneDelete, SIGNAL(pressed()), this, SLOT(PushZoneDelete()) );
115     connect( CBGroupe,     SIGNAL(stateChanged(int)), this, SLOT(SetFiltrage()));
116
117     connect( RBFieldNo,    SIGNAL(clicked()), this, SLOT(SetFieldNo()));
118     connect( RBFieldAll,   SIGNAL(clicked()), this, SLOT(SetFieldAll()));
119     connect( RBFieldChosen,SIGNAL(clicked()), this, SLOT(SetFieldChosen()));
120
121     connect( CBAdvanced,   SIGNAL(stateChanged(int)), this, SLOT(SetAdvanced()));
122     connect( RBAIN,        SIGNAL(clicked()), this, SLOT(SetAIN()));
123     connect( RBAIR,        SIGNAL(clicked()), this, SLOT(SetAIR()));
124     connect( RBAID,        SIGNAL(clicked()), this, SLOT(SetAID()));
125
126     connect( buttonOk,     SIGNAL(pressed()), this, SLOT( PushOnOK()));
127     connect( buttonApply,  SIGNAL(pressed()), this, SLOT( PushOnApply()));
128     connect( buttonCancel, SIGNAL(pressed()), this, SLOT(close()));
129     connect( buttonHelp,   SIGNAL(pressed()), this, SLOT( PushOnHelp()));
130 }
131
132 // ------------------------------------------------------------------------
133 bool MonCreateHypothesis::PushOnApply()
134 // ------------------------------------------------------------------------
135 // Appele lorsque l'un des boutons Ok ou Apply est presse
136 //
137 {
138 // Verifications
139
140
141   if (LEName->text().trimmed()=="") {
142     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
143                               QObject::tr("HOM_HYPO_NAME") );
144     return false;
145   }
146
147   if (VerifieZone()      == false)  return false;
148   if (VerifieComposant() == false)  return false;
149
150 // Creation de l'objet CORBA si ce n'est pas deja fait sous le meme nom
151   if (LEName->text().trimmed() != _Name)
152   {
153     _Name=LEName->text().trimmed();
154     try
155     {
156      aHypothesis=myHomardGen->CreateHypothesis(CORBA::string_dup(_Name.toStdString().c_str()) );
157      _parent->addHypothese(_Name);
158     }
159     catch( SALOME::SALOME_Exception& S_ex )
160     {
161       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
162                                 QString(CORBA::string_dup(S_ex.details.text)) );
163       return false;
164     }
165   }
166
167 // Mise en place des attributs
168   aHypothesis->SetAdapRefinUnRef(_aTypeAdap,_aTypeRaff,_aTypeDera);
169   aHypothesis->SetTypeFieldInterp(_TypeFieldInterp);
170   aHypothesis->SetCaseCreation(_aCaseName.toStdString().c_str());
171
172   AssocieLesZones();
173   AssocieComposants();
174   AssocieLesGroupes();
175   AssocieFieldInterp();
176
177 // Options avancees
178   if (CBAdvanced->isChecked())
179   {
180 // Enregistrement du niveau maximal
181     _NivMax = SpinBoxNivMax->value() ;
182     aHypothesis->SetNivMax(_NivMax);
183 // Enregistrement du diametre minimal
184     _DiamMin = doubleSpinBoxDiamMin->value() ;
185     aHypothesis->SetDiamMin(_DiamMin);
186 // Enregistrement de l'intialisation de l'adaptation
187     aHypothesis->SetAdapInit(_AdapInit);
188 // Sortie des niveaux de raffinement
189     if (CBLevelOutput->isChecked()) { _LevelOutput = 1 ; }
190     aHypothesis->SetLevelOutput(_LevelOutput);
191   }
192
193   HOMARD_UTILS::updateObjBrowser() ;
194
195   return true;
196 }
197
198
199 // ------------------------------------------------------------------------
200 void MonCreateHypothesis::PushOnOK()
201 // ------------------------------------------------------------------------
202 {
203      if (PushOnApply()) this->close();
204      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
205 }
206 // ------------------------------------------------------------------------
207 void MonCreateHypothesis::PushOnHelp()
208 // ------------------------------------------------------------------------
209 {
210   std::string LanguageShort = myHomardGen->GetLanguageShort();
211   HOMARD_UTILS::PushOnHelp(QString("gui_create_hypothese.html"), QString(""), QString(LanguageShort.c_str()));
212 }
213 // -------------------------------------------------
214 void MonCreateHypothesis::SetNewName()
215 // --------------------------------------------------
216 {
217
218   HOMARD::listeHypotheses_var  MyObjects = myHomardGen->GetAllHypothesesName();
219   int num = 0;//
220   QString aName="";
221   while (aName=="" )
222   {
223     aName.setNum(num+1) ;
224     aName.insert(0, QString("Hypo_")) ;
225     for ( int i=0; i<MyObjects->length(); i++)
226     {
227       if ( aName ==  QString(MyObjects[i]))
228       {
229         num ++ ;
230         aName = "" ;
231         break ;
232       }
233     }
234   }
235   LEName->setText(aName);
236 }
237
238 //
239 // ------------------------------------------------------------------------
240 void MonCreateHypothesis::SetUniforme()
241 // ------------------------------------------------------------------------
242 {
243   GBFieldManagement->setVisible(0);
244   if ( _TypeFieldInterp == 0 ) { GBFieldFile->setVisible(0); }
245   else                         { GBFieldFile->setVisible(1); }
246   GBAreaManagement->setVisible(0);
247   GBUniform->setVisible(1);
248
249   _aTypeAdap = -1 ;
250 //
251   adjustSize();
252 }
253 // ------------------------------------------------------------------------
254 void MonCreateHypothesis::SetChamp()
255 // ------------------------------------------------------------------------
256 {
257   if (_aFieldFile == QString(""))
258   {
259     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
260                               QObject::tr("HOM_HYPO_FIELD_FILE") );
261      close();
262      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
263      return;
264   }
265   LEFieldFile->setText(_aFieldFile);
266   LEFieldFile->setReadOnly(1);
267   InitFields();
268   GBUniform->setVisible(0);
269   GBAreaManagement->setVisible(0);
270   GBFieldManagement->setVisible(1);
271   GBFieldFile->setVisible(1);
272
273   GBUniform->adjustSize();
274   GBAreaManagement->adjustSize();
275   GBFieldManagement->adjustSize();
276   GBFieldFile->adjustSize();
277
278   _aTypeAdap = 1 ;
279 //
280   adjustSize();
281 }
282 // ------------------------------------------------------------------------
283 void MonCreateHypothesis::SetZone()
284 // ------------------------------------------------------------------------
285 {
286   GetAllZones();
287   GBUniform->setVisible(0);
288   GBFieldManagement->setVisible(0);
289   if ( _TypeFieldInterp == 0 ) { GBFieldFile->setVisible(0); }
290   else                         { GBFieldFile->setVisible(1); }
291   GBAreaManagement->setVisible(1);
292
293   _aTypeRaff = 1 ;
294   _aTypeDera = 0 ;
295   _aTypeAdap = 0 ;
296 //
297   adjustSize();
298 }
299
300 // ------------------------------------------------------------------------
301 void MonCreateHypothesis::PushZoneNew()
302 // ------------------------------------------------------------------------
303 {
304   MESSAGE("Debut de MonCreateHypothesis::PushZoneNew")
305   MonCreateZone *aDlg = new MonCreateZone(this, TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName) ;
306   aDlg->show();
307 }
308
309 // ------------------------------------------------------------------------
310 void MonCreateHypothesis::PushZoneEdit()
311 // ------------------------------------------------------------------------
312 {
313   MESSAGE("Debut de MonCreateHypothesis::PushZoneEdit")
314   int colonne = TWZone->currentColumn();
315   QTableWidgetItem * monItem = TWZone->currentItem();
316   if (colonne !=2  || monItem == NULL)
317   {
318     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
319                               QObject::tr("HOM_HYPO_ZONE_1") );
320     return;
321   }
322   QString zoneName = monItem->text().trimmed();
323   MonEditZone *aDlg = new MonEditZone(this, TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen), _aCaseName, zoneName) ;
324   aDlg->show();
325 }
326 // ------------------------------------------------------------------------
327 void MonCreateHypothesis::PushZoneDelete()
328 // ------------------------------------------------------------------------
329 {
330   MESSAGE("Debut de MonCreateHypothesis::PushZoneDelete")
331   QMessageBox::warning( 0, QObject::tr("HOM_WARNING"),
332                           QObject::tr("HOM_INACTIVE_BUTTON") );
333   return;
334 }
335
336 // ------------------------------------------------------------------------
337 void MonCreateHypothesis::GetAllZones()
338 // ------------------------------------------------------------------------
339 // Recuperation de toutes les zones enregistrees dans l'arbre d'etude
340 // et affichage dans le tableau
341 // Par defaut, aucune n'est selectionnee
342 {
343   MESSAGE("Debut de GetAllZones") ;
344   HOMARD::listeZones_var mesZones = myHomardGen->GetAllZonesName();
345   int nbrow=TWZone->rowCount();
346   for ( int row=0; row< nbrow; row++)
347   {
348      TWZone->removeRow(row);
349   }
350   TWZone->setRowCount(0);
351   int row=0;
352   for (int i=0; i<mesZones->length(); i++)
353   {
354     TWZone->insertRow(row);
355 //
356     TWZone->setItem( row, 0, new QTableWidgetItem( QString ("") ) );
357     TWZone->item( row, 0 )->setFlags( 0 );
358     TWZone->item( row, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
359     TWZone->item( row, 0 )->setCheckState( Qt::Unchecked );
360 //
361     TWZone->setItem( row, 1, new QTableWidgetItem( QString ("") ) );
362     TWZone->item( row, 1 )->setFlags( 0 );
363     TWZone->item( row, 1 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
364     TWZone->item( row, 1 )->setCheckState( Qt::Unchecked );
365 //
366     TWZone->setItem( row, 2, new QTableWidgetItem(QString(mesZones[i]).trimmed()));
367     TWZone->item( row, 2 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
368 //
369     row += 1;
370   }
371   TWZone->resizeColumnsToContents();
372   TWZone->resizeRowsToContents();
373   TWZone->clearSelection();
374 }
375 // ------------------------------------------------------------------------
376 void MonCreateHypothesis::addZoneinTWZone(QString newZone)
377 // ------------------------------------------------------------------------
378 {
379   MESSAGE("Debut de addZoneinTWZone") ;
380   int row = TWZone->rowCount() ;
381 // Par defaut, on suppose qu'une nouvelle zone est destinee au raffinement
382   TWZone->setRowCount( row+1 );
383 //
384   TWZone->setItem( row, 0, new QTableWidgetItem( QString ("") ) );
385   TWZone->item( row, 0 )->setFlags( Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
386   TWZone->item( row, 0 )->setCheckState( Qt::Checked );
387 //
388   TWZone->setItem( row, 1, new QTableWidgetItem( QString ("") ) );
389   TWZone->item( row, 1 )->setFlags( Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
390   TWZone->item( row, 1 )->setCheckState( Qt::Unchecked );
391 //
392   TWZone->setItem( row, 2, new QTableWidgetItem( newZone ) );
393   TWZone->scrollToItem( TWZone->item( row, 2 ) );
394 //
395   TWZone->resizeRowsToContents();
396   TWZone->resizeColumnToContents(1);
397   TWZone->clearSelection();
398 //
399   TWZone->item( row, 2 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
400 }
401 // ------------------------------------------------------------------------
402 QStringList MonCreateHypothesis::GetZonesChecked()
403 // ------------------------------------------------------------------------
404 // Retourne les zones enregistrees
405 {
406   MESSAGE("Debut de GetZonesChecked") ;
407   QStringList ListeZone ;
408 // On ne peut pas avoir selectionne les deux options
409   int Pbm = 0 ;
410   for ( int row=0; row< TWZone->rowCount(); row++)
411   {
412     if ( ( TWZone->item( row, 0 )->checkState() == Qt::Checked ) && ( TWZone->item( row, 1 )->checkState() == Qt::Checked ) )
413     {
414       QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
415                                 QObject::tr("HOM_HYPO_ZONE_3") );
416       Pbm = 1 ;
417     }
418   }
419 // Si tout va bien, on affecte
420 // Attention, on insere en tete, donc on commence d'inserer le type, psui le nom de la zone
421   if ( Pbm == 0 )
422   {
423     QString Raff =  "1" ;
424     QString Dera = "-1" ;
425     for ( int row=0; row< TWZone->rowCount(); row++)
426     {
427 //     MESSAGE ("row "<<row<<", zone : "<<TWZone->item(row, 2)->text().toStdString());
428 //  En raffinement :
429       if ( TWZone->item(row,0)->checkState() == Qt::Checked )
430       { ListeZone.insert(0, Raff) ;
431         ListeZone.insert(0, QString(TWZone->item(row, 2)->text()) ) ; }
432 //  En deraffinement :
433       if ( TWZone->item(row,1)->checkState() == Qt::Checked )
434       { ListeZone.insert(0, Dera) ;
435         ListeZone.insert(0, QString(TWZone->item(row, 2)->text()) ) ; }
436     }
437   MESSAGE("Fin de GetZonesChecked ; longueur de ListeZone : "<<ListeZone.count()) ;
438   }
439 //
440 return ListeZone ;
441 }
442 // ------------------------------------------------------------------------
443 QStringList MonCreateHypothesis::GetListCompChecked()
444 // ------------------------------------------------------------------------
445 // Retourne les composantes retenues
446 {
447   MESSAGE( "Debut de GetListCompChecked" );
448   QStringList ListeComposant ;
449
450   ListeComposant.clear();
451   for ( int row=0; row< TWCMP->rowCount(); row++)
452       if ( TWCMP->item( row, 0 )->checkState() == Qt::Checked )
453           ListeComposant.insert(0, QString(TWCMP->item(row, 1)->text()) ) ;
454   // Choix du texte des radio-boutons selon 1 ou plusieurs composantes
455   if ( ListeComposant.count() < 2 )
456   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
457     RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
458   }
459   else
460   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
461     RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
462   }
463   return ListeComposant ;
464 //
465 }
466 // ------------------------------------------------------------------------
467 void MonCreateHypothesis::AssocieFieldInterp()
468 // ------------------------------------------------------------------------
469 {
470   if ( _TypeFieldInterp != 2 ) return;
471   for ( int row=0; row< TWField->rowCount(); row++)
472   {
473     if ( TWField->item( row, 0 )->checkState() == Qt::Checked )
474     {
475       aHypothesis->AddFieldInterp(TWField->item(row, 1)->text().toStdString().c_str());
476     }
477   }
478 }
479 // ------------------------------------------------------------------------
480 void MonCreateHypothesis::SetUniRaff()
481 // ------------------------------------------------------------------------
482 {
483   _aTypeRaff = 1 ;
484   _aTypeDera = 0 ;
485 }
486 // ------------------------------------------------------------------------
487 void MonCreateHypothesis::SetUniDera()
488 // ------------------------------------------------------------------------
489 {
490   _aTypeRaff = 0 ;
491   _aTypeDera = 1 ;
492 }
493
494 // ------------------------------------------------------------------------
495 void MonCreateHypothesis::InitFields()
496 // ------------------------------------------------------------------------
497 {
498   CBFieldName->clear();
499   std::list<QString> listeChamp = HOMARD_QT_COMMUN::GetListeChamps(QString(_aFieldFile) );
500   // Mise en place de la liste dans le menu pour l'indicateur d'erreur
501   std:: list<QString>::const_iterator it;
502   for ( it=listeChamp.begin() ; it != listeChamp.end(); it++)
503   {
504        CBFieldName->insertItem(0,QString(*it));
505   }
506   SetFieldName();
507 }
508 // ---------------------------------------
509 void MonCreateHypothesis::SetFieldName()
510 // -------------------------------------------
511 {
512   MESSAGE("Debut de SetFieldName");
513   _aFieldName=CBFieldName->currentText();
514   if (QString(_aFieldFile) == QString("") || QString(_aFieldName) == QString("") ) { return; }
515
516   int nbrow= TWCMP->rowCount() ;
517   for ( int row=0; row < nbrow ; row++)
518   {
519      TWCMP->removeRow(row);
520   }
521   TWCMP->setRowCount(0);
522   //TWCMP->resizeRowsToContents();
523
524   std::list<QString>  maListe =HOMARD_QT_COMMUN::GetListeComposants(_aFieldFile, _aFieldName);
525   std::list<QString>::const_iterator it;
526   for ( it=maListe.begin() ; it != maListe.end(); it++)
527   {
528        TWCMP->insertRow(0);
529        TWCMP->setItem( 0, 0, new QTableWidgetItem( QString ("") ) );
530        TWCMP->item( 0, 0 )->setFlags( 0 );
531        TWCMP->item( 0, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
532        TWCMP->item( 0, 0 )->setCheckState( Qt::Checked );
533        TWCMP->setItem( 0, 1, new QTableWidgetItem(QString((*it)).trimmed()));
534        TWCMP->item( 0, 1 )->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable );
535   }
536   TWCMP->resizeColumnsToContents();
537   TWCMP->resizeRowsToContents();
538   TWCMP->clearSelection();
539   // Choix du texte des radio-boutons selon 1 ou plusieurs composantes
540   if ( TWCMP->rowCount() == 1 )
541   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_ABS"));
542     RBInf->setText(QObject::tr("HOM_HYPO_NORM_REL"));
543   }
544   else
545   { RBL2->setText(QObject::tr("HOM_HYPO_NORM_L2"));
546     RBInf->setText(QObject::tr("HOM_HYPO_NORM_INF"));
547   }
548   // Par defaut, on propose la valeur absolue / norme L2
549   SetUCL2();
550 }
551 // ------------------------------------------------------------------------
552 void MonCreateHypothesis::SetRPE()
553 // ------------------------------------------------------------------------
554 {
555   _aTypeRaff = 1 ;
556   _TypeThR = 3 ;
557   RBRPE->setChecked(true);
558   SpinBox_RPE->setEnabled(true);
559   SpinBox_RRel->setEnabled(false);
560   SpinBox_RAbs->setEnabled(false);
561   SpinBox_RMuSigma->setEnabled(false);
562 }
563 // ------------------------------------------------------------------------
564 void MonCreateHypothesis::SetRRel()
565 // ------------------------------------------------------------------------
566 {
567   _aTypeRaff = 1 ;
568   _TypeThR = 2 ;
569   RBRRel->setChecked(true);
570   SpinBox_RPE->setEnabled(false);
571   SpinBox_RRel->setEnabled(true);
572   SpinBox_RAbs->setEnabled(false);
573   SpinBox_RMuSigma->setEnabled(false);
574 }
575 // ------------------------------------------------------------------------
576 void MonCreateHypothesis::SetRAbs()
577 // ------------------------------------------------------------------------
578 {
579   _aTypeRaff = 1 ;
580   _TypeThR = 1 ;
581   RBRAbs->setChecked(true);
582   SpinBox_RPE->setEnabled(false);
583   SpinBox_RRel->setEnabled(false);
584   SpinBox_RAbs->setEnabled(true);
585   SpinBox_RMuSigma->setEnabled(false);
586 }
587 // ------------------------------------------------------------------------
588 void MonCreateHypothesis::SetRMS()
589 // ------------------------------------------------------------------------
590 {
591   _aTypeRaff = 1 ;
592   _TypeThR = 4 ;
593   RBRMuSigma->setChecked(true);
594   SpinBox_RPE->setEnabled(false);
595   SpinBox_RRel->setEnabled(false);
596   SpinBox_RAbs->setEnabled(false);
597   SpinBox_RMuSigma->setEnabled(true);
598 }
599 // ------------------------------------------------------------------------
600 void MonCreateHypothesis::SetRNo()
601 // ------------------------------------------------------------------------
602 {
603   _aTypeRaff = 0 ;
604   _TypeThR = 0;
605   RBRNo->setChecked(true);
606   SpinBox_RPE->setEnabled(false);
607   SpinBox_RRel->setEnabled(false);
608   SpinBox_RAbs->setEnabled(false);
609   SpinBox_RMuSigma->setEnabled(false);
610 }
611 // ------------------------------------------------------------------------
612 void MonCreateHypothesis::SetCPE()
613 // ------------------------------------------------------------------------
614 {
615   _aTypeDera = 1 ;
616   _TypeThC = 3 ;
617   RBCPE->setChecked(true);
618   SpinBox_CPE->setEnabled(true);
619   SpinBox_CRel->setEnabled(false);
620   SpinBox_CAbs->setEnabled(false);
621   SpinBox_CMuSigma->setEnabled(false);
622 }
623 // ------------------------------------------------------------------------
624 void MonCreateHypothesis::SetCRel()
625 // ------------------------------------------------------------------------
626 {
627   _aTypeDera = 1 ;
628   _TypeThC = 2 ;
629   RBCRel->setChecked(true);
630   SpinBox_CPE->setEnabled(false);
631   SpinBox_CRel->setEnabled(true);
632   SpinBox_CAbs->setEnabled(false);
633   SpinBox_CMuSigma->setEnabled(false);
634 }
635 // ------------------------------------------------------------------------
636 void MonCreateHypothesis::SetCAbs()
637 // ------------------------------------------------------------------------
638 {
639   _aTypeDera = 1 ;
640   _TypeThC = 1 ;
641   RBCAbs->setChecked(true);
642   SpinBox_CPE->setEnabled(false);
643   SpinBox_CRel->setEnabled(false);
644   SpinBox_CAbs->setEnabled(true);
645   SpinBox_CMuSigma->setEnabled(false);
646 }
647 // ------------------------------------------------------------------------
648 void MonCreateHypothesis::SetCMS()
649 // ------------------------------------------------------------------------
650 {
651   _aTypeDera = 1 ;
652   _TypeThC = 4 ;
653   RBCMuSigma->setChecked(true);
654   SpinBox_CPE->setEnabled(false);
655   SpinBox_CRel->setEnabled(false);
656   SpinBox_CAbs->setEnabled(false);
657   SpinBox_CMuSigma->setEnabled(true);
658 }
659 // ------------------------------------------------------------------------
660 void MonCreateHypothesis::SetCNo()
661 // ------------------------------------------------------------------------
662 {
663   _aTypeDera = 0 ;
664   _TypeThC = 0;
665   RBCNo->setChecked(true);
666   SpinBox_CPE->setEnabled(false);
667   SpinBox_CRel->setEnabled(false);
668   SpinBox_CAbs->setEnabled(false);
669   SpinBox_CMuSigma->setEnabled(false);
670 }
671 // ------------------------------------------------------------------------
672 void MonCreateHypothesis::SetUCL2()
673 // ------------------------------------------------------------------------
674 {
675   _UsCmpI = 0 ;
676   RBL2->setChecked(true);
677 }
678 // ------------------------------------------------------------------------
679 void MonCreateHypothesis::SetUCInf()
680 // ------------------------------------------------------------------------
681 {
682   _UsCmpI = 1 ;
683   RBInf->setChecked(true);
684 }
685 // ------------------------------------------------------------------------
686 void MonCreateHypothesis::SetUseField()
687 // ------------------------------------------------------------------------
688 {
689   if ( CBJump->isChecked() ) { _UsField = 1 ; }
690   else                       { _UsField = 0 ; }
691 }
692 // ------------------------------------------------------------------------
693 void MonCreateHypothesis::SetFiltrage()
694 // ------------------------------------------------------------------------
695 {
696   if (!CBGroupe->isChecked()) return;
697   MonCreateListGroup *aDlg = new MonCreateListGroup(this, NULL, TRUE, HOMARD::HOMARD_Gen::_duplicate(myHomardGen),_aCaseName, _aListeGroupes) ;
698   aDlg->show();
699 }
700
701 // ------------------------------------------------------------------------
702 void MonCreateHypothesis::setGroups(QStringList listGroup)
703 // ------------------------------------------------------------------------
704 {
705     _aListeGroupes=listGroup;
706 }
707 // ------------------------------------------------------------------------
708 bool MonCreateHypothesis::VerifieZone()
709 // ------------------------------------------------------------------------
710 {
711   if ( _aTypeAdap != 0 ) return true;
712   MESSAGE("Debut de VerifieZone") ;
713   _aListeZone = GetZonesChecked() ;
714   MESSAGE(". Longueur de _aListeZone : "<<_aListeZone.count()) ;
715   if (_aListeZone.count() == 0)
716   {
717     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
718                               QObject::tr("HOM_HYPO_ZONE_2") );
719      return false;
720   }
721   MESSAGE("Fin de VerifieZone") ;
722   return true;
723 }
724 // ------------------------------------------------------------------------
725 bool MonCreateHypothesis::VerifieComposant()
726 // ------------------------------------------------------------------------
727 {
728   if ( _aTypeAdap != 1 ) return true;
729   _aListeComposant = GetListCompChecked() ;
730   if (_aListeComposant.count() == 0)
731   {
732     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
733                               QObject::tr("HOM_HYPO_COMP") );
734      return false;
735   }
736   return true;
737 }
738
739 // ------------------------------------------------------------------------
740 void MonCreateHypothesis::AssocieLesZones()
741 // ------------------------------------------------------------------------
742 {
743   MESSAGE( "Debut de AssocieLesZones" );
744   if ( _aTypeAdap != 0 ) return;
745   _aListeZone = GetZonesChecked() ;
746   MESSAGE(". Longueur de _aListeZone : "<<_aListeZone.count()) ;
747   QString Raff =  "1" ;
748   int TypeUse ;
749   for ( int i=0 ; i< _aListeZone.count() ; i++ )
750   { if ( _aListeZone[i+1] == Raff ) { TypeUse =  1 ; }
751     else                            { TypeUse = -1 ; }
752     aHypothesis->AddZone(_aListeZone[i].toStdString().c_str(), TypeUse);
753     i += 1 ;
754   }
755   MESSAGE( "Fin de AssocieLesZones" );
756 };
757 // ------------------------------------------------------------------------
758 void MonCreateHypothesis::AssocieComposants()
759 // ------------------------------------------------------------------------
760 {
761   if ( _aTypeAdap != 1 ) return;
762   MESSAGE( "Dans AssocieComposants, _TypeThC : " << _TypeThC );
763   MESSAGE( "Dans AssocieComposants, _TypeThR : " << _TypeThR );
764
765   _ThreshR = 0;
766   if ( _TypeThR == 1 ) { _ThreshR = SpinBox_RAbs->value();}
767   if ( _TypeThR == 2 ) { _ThreshR = SpinBox_RRel->value();}
768   if ( _TypeThR == 3 ) { _ThreshR = SpinBox_RPE->value(); }
769   if ( _TypeThR == 4 ) { _ThreshR = SpinBox_RMuSigma->value(); }
770
771   _ThreshC = 0;
772   if ( _TypeThC == 1 ) { _ThreshC = SpinBox_CAbs->value();}
773   if ( _TypeThC == 2 ) { _ThreshC = SpinBox_CRel->value();}
774   if ( _TypeThC == 3 ) { _ThreshC = SpinBox_CPE->value(); }
775   if ( _TypeThC == 4 ) { _ThreshC = SpinBox_CMuSigma->value(); }
776
777   _aFieldName=CBFieldName->currentText();
778   aHypothesis->SetField(CORBA::string_dup(_aFieldName.toStdString().c_str()) ) ;
779   aHypothesis->SetRefinThr( _TypeThR, _ThreshR ) ;
780   aHypothesis->SetUnRefThr( _TypeThC, _ThreshC ) ;
781   aHypothesis->SetUseField( _UsField ) ;
782   aHypothesis->SetUseComp( _UsCmpI ) ;
783   _aListeComposant = GetListCompChecked() ;
784   for ( int i=0 ; i< _aListeComposant.count() ; i++ )
785       { aHypothesis->AddComp(_aListeComposant[i].toStdString().c_str()); }
786 };
787 // ------------------------------------------------------------------------
788 void MonCreateHypothesis::AssocieLesGroupes()
789 // ------------------------------------------------------------------------
790 {
791   HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
792   aSeqGroupe->length(_aListeGroupes.size());
793   QStringList::const_iterator it;
794   int i=0;
795   for (it = _aListeGroupes.constBegin(); it != _aListeGroupes.constEnd(); it++)
796      aSeqGroupe[i++]=(*it).toStdString().c_str();
797   aHypothesis->SetGroups(aSeqGroupe);
798
799 }
800 // ------------------------------------------------------------------------
801 void MonCreateHypothesis::SetFieldNo()
802 // ------------------------------------------------------------------------
803 // Par defaut, on n'interpole rien
804 {
805   if ( _aTypeAdap == 1 ) { GBFieldFile->setVisible(1); }
806   else                   { GBFieldFile->setVisible(0); }
807   TWField->setVisible(0);
808 //
809   _TypeFieldInterp = 0 ;
810 //
811   adjustSize();
812 }
813 // ------------------------------------------------------------------------
814 void MonCreateHypothesis::SetFieldAll()
815 // ------------------------------------------------------------------------
816 // Par defaut, on interpole tout
817 {
818   if (_aFieldFile == QString(""))
819   {
820     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
821                               QObject::tr("HOM_HYPO_FIELD_FILE") );
822      close();
823      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
824      return;
825   }
826   LEFieldFile->setText(_aFieldFile);
827   LEFieldFile->setReadOnly(1);
828   GBFieldFile->setVisible(1);
829   TWField->setVisible(0);
830 //
831   _TypeFieldInterp = 1 ;
832 //
833   adjustSize();
834 }
835 // ------------------------------------------------------------------------
836 void MonCreateHypothesis::SetFieldChosen()
837 // ------------------------------------------------------------------------
838 {
839   if (_aFieldFile == QString(""))
840   {
841     QMessageBox::critical( 0, QObject::tr("HOM_ERROR"),
842                               QObject::tr("HOM_HYPO_FIELD_FILE") );
843      close();
844      if ( _parent ) { _parent->raise(); _parent->activateWindow(); };
845      return;
846   }
847   LEFieldFile->setText(_aFieldFile);
848   LEFieldFile->setReadOnly(1);
849   GBFieldFile->setVisible(1);
850   // Recuperation de la liste des champs contenus dans le fichier _aFieldFile
851   std::list<QString> listeChamp = HOMARD_QT_COMMUN::GetListeChamps(QString(_aFieldFile) );
852
853   // Initialisation de la table
854   TWField->clear();
855   int nbrow=TWField->rowCount();
856   for ( int row=0; row< nbrow; row++)
857   {
858      TWField->removeRow(row);
859   }
860   TWField->setRowCount(0);
861   std:: list<QString>::const_iterator it;
862   int row=0;
863   for ( it=listeChamp.begin() ; it != listeChamp.end(); it++)
864   {
865     TWField->insertRow(row);
866     TWField->setItem( row, 0, new QTableWidgetItem( QString ("") ) );
867     TWField->item( row, 0 )->setFlags( 0 );
868     TWField->item( row, 0 )->setFlags( Qt::ItemIsUserCheckable|Qt::ItemIsEnabled  );
869     TWField->item( row, 0 )->setCheckState( Qt::Unchecked );
870     TWField->setItem( row, 1, new QTableWidgetItem(QString(*it).trimmed()));
871     TWField->item( row, 1 )->setFlags(Qt::ItemIsEnabled |Qt::ItemIsSelectable );
872     row=row+1;
873   }
874   TWField->resizeColumnsToContents();
875   TWField->resizeRowsToContents();
876   TWField->clearSelection();
877   TWField->setVisible(1);
878
879   _TypeFieldInterp = 2 ;
880 //
881   adjustSize();
882 }
883 // ------------------------------------------------------------------------
884 void MonCreateHypothesis::SetAdvanced()
885 // ------------------------------------------------------------------------
886 {
887   MESSAGE("Debut de SetAdvanced ");
888   if (CBAdvanced->isChecked())
889   { GBAdvancedOptions->setVisible(1);
890     if (_aFieldFile != QString(""))
891     { GBAdapInit->setVisible(1) ;
892     }
893     else
894     { GBAdapInit->setVisible(0) ;
895     }
896   }
897   else
898   { GBAdvancedOptions->setVisible(0);
899     _NivMax = -1 ;
900     _DiamMin = -1. ;
901     _AdapInit = 0 ;
902     CBLevelOutput->setChecked(false);
903     _LevelOutput = 0 ;
904   }
905 //
906   adjustSize();
907 }
908 // ------------------------------------------------------------------------
909 void MonCreateHypothesis::SetAIN()
910 // ------------------------------------------------------------------------
911 {
912   MESSAGE("Debut de SetAIN ");
913   _AdapInit = 0 ;
914 }
915 // ------------------------------------------------------------------------
916 void MonCreateHypothesis::SetAIR()
917 // ------------------------------------------------------------------------
918 {
919   MESSAGE("Debut de SetAIR ");
920   _AdapInit = 1 ;
921 }
922 // ------------------------------------------------------------------------
923 void MonCreateHypothesis::SetAID()
924 // ------------------------------------------------------------------------
925 {
926   MESSAGE("Debut de SetAID ");
927   _AdapInit = -1 ;
928 }