]> SALOME platform Git repositories - plugins/blsurfplugin.git/blob - src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx
Salome HOME
Merge from BR_V5_DEV 17Feb09
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
1 //  Copyright (C) 2007-2008  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 // File    : BLSURFPluginGUI_HypothesisCreator.cxx
21 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
22 //           & Aurelien ALLEAUME (DISTENE)
23 // ---
24 //
25 #include "BLSURFPluginGUI_HypothesisCreator.h"
26
27 #include <SMESHGUI_Utils.h>
28 #include <SMESHGUI_HypothesesUtils.h>
29
30 #include <SUIT_Session.h>
31 #include <SUIT_MessageBox.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Tools.h>
34 #include <QtxDoubleSpinBox.h>
35
36 #include <QComboBox>
37 #include <QLabel>
38 #include <QGroupBox>
39 #include <QFrame>
40 #include <QVBoxLayout>
41 #include <QGridLayout>
42 #include <QLineEdit>
43 #include <QCheckBox>
44 #include <QTabWidget>
45 #include <QSpinBox>
46 #include <QPushButton>
47 #include <QMenu>
48 #include <QTableWidget>
49 #include <QHeaderView>
50 #include <QApplication>
51
52 #define WITH_SIZE_BOUNDARIES
53
54 enum Topology {
55     FromCAD,
56     Process,
57     Process2
58   };
59
60 enum PhysicalMesh
61   {
62     DefaultSize = 0,
63     PhysicalUserDefined
64   };
65
66 enum GeometricMesh
67   {
68     DefaultGeom = 0,
69     UserDefined
70   };
71
72 enum {
73   STD_TAB = 0,
74   ADV_TAB,
75   OPTION_ID_COLUMN = 0,
76   OPTION_NAME_COLUMN,
77   OPTION_VALUE_COLUMN,
78   NB_COLUMNS
79 };
80
81 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
82   : SMESHGUI_GenericHypothesisCreator( theHypType )
83 {
84 }
85
86 BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
87 {
88 }
89
90 namespace {
91   inline bool isDouble( const QString& theText, const bool emptyOK=false ) {
92     QString str = theText.trimmed();
93     bool isOk = true;
94     if ( !str.isEmpty() )
95       str.toDouble(&isOk);
96     else
97       isOk = emptyOK;
98     return isOk;
99   }
100 }
101
102 bool BLSURFPluginGUI_HypothesisCreator::checkParams() const
103 {
104   bool ok = true;
105   if ( !isDouble( myPhySize->text(), false )) {
106     if ( myPhySize->text().isEmpty() )
107       myPhySize->setText(tr("OBLIGATORY_VALUE"));
108     myPhySize->selectAll();
109     ok = false;
110   }
111   if ( !isDouble( myPhyMin->text(), true )) {
112     myPhyMin->selectAll();
113     ok = false;
114   }
115   if ( !isDouble( myPhyMax->text(), true )) {
116     myPhyMax->selectAll();
117     ok = false;
118   }
119   if ( !isDouble( myGeoMin->text(), true )) {
120     myGeoMin->selectAll();
121     ok = false;
122   }
123   if ( !isDouble( myGeoMin->text(), true )) {
124     myGeoMin->selectAll();
125     ok = false;
126   }
127   if ( ok )
128   {
129     myOptionTable->setFocus();
130     QApplication::instance()->processEvents();
131
132     BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
133       BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
134
135     int row = 0, nbRows = myOptionTable->rowCount();
136     for ( ; row < nbRows; ++row )
137     {
138       QString name  = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
139       QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
140       if ( !value.isEmpty() ) {
141         try {
142           h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
143         }
144         catch ( const SALOME::SALOME_Exception& ex )
145         {
146           SUIT_MessageBox::critical( dlg(),
147                                      tr("SMESH_ERROR"),
148                                      ex.details.text.in() );
149           ok = false;
150         }
151       }
152     }
153     h->SetOptionValues( myOptions ); // restore values
154   }
155
156   return ok;
157 }
158
159 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
160 {
161   QFrame* fr = new QFrame( 0 );
162   QVBoxLayout* lay = new QVBoxLayout( fr );
163   lay->setMargin( 5 );
164   lay->setSpacing( 0 );
165
166   // tab
167   QTabWidget* tab = new QTabWidget( fr );
168   tab->setTabShape( QTabWidget::Rounded );
169   tab->setTabPosition( QTabWidget::North );
170   lay->addWidget( tab );
171
172   // basic parameters
173   myStdGroup = new QWidget();
174   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
175   aStdLayout->setSpacing( 6 );
176   aStdLayout->setMargin( 11 );
177
178   int row = 0;
179   myName = 0;
180   if( isCreation() ) {
181     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ), row, 0, 1, 1 );
182     myName = new QLineEdit( myStdGroup );
183     aStdLayout->addWidget( myName, row++, 1, 1, 1 );
184   }
185
186   aStdLayout->addWidget( new QLabel( tr( "BLSURF_PHY_MESH" ), myStdGroup ), row, 0, 1, 1 );
187   myPhysicalMesh = new QComboBox( myStdGroup );
188   aStdLayout->addWidget( myPhysicalMesh, row++, 1, 1, 1 );
189   QStringList physicalTypes;
190   physicalTypes << tr( "BLSURF_DEFAULT_USER" ) << tr( "BLSURF_CUSTOM_USER" );
191   myPhysicalMesh->addItems( physicalTypes );
192
193   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYDEF" ), myStdGroup), row, 0, 1, 1 );
194   myPhySize = new QLineEdit( myStdGroup );
195   aStdLayout->addWidget( myPhySize, row++, 1, 1, 1 );
196
197 #ifdef WITH_SIZE_BOUNDARIES
198   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMIN" ), myStdGroup ), row, 0, 1, 1 );
199   myPhyMin = new QLineEdit( myStdGroup );
200   aStdLayout->addWidget( myPhyMin, row++, 1, 1, 1 );
201
202   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HPHYMAX" ), myStdGroup ), row, 0, 1, 1 );
203   myPhyMax = new QLineEdit( myStdGroup );
204   aStdLayout->addWidget( myPhyMax, row++, 1, 1, 1 );
205 #endif
206
207   aStdLayout->addWidget( new QLabel( tr( "BLSURF_GEOM_MESH" ), myStdGroup ), row, 0, 1, 1 );
208   myGeometricMesh = new QComboBox( myStdGroup );
209   aStdLayout->addWidget( myGeometricMesh, row++, 1, 1, 1 );
210   QStringList types;
211   types << tr( "BLSURF_DEFAULT_GEOM" ) << tr( "BLSURF_CUSTOM_GEOM" );
212   myGeometricMesh->addItems( types );
213
214   aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_S" ), myStdGroup ), row, 0, 1, 1 );
215   myAngleMeshS = new QtxDoubleSpinBox( myStdGroup );
216   aStdLayout->addWidget( myAngleMeshS, row++, 1, 1, 1 );
217   myAngleMeshS->setMinimum( 0 );
218   myAngleMeshS->setMaximum( 16 );
219   myAngleMeshS->setSingleStep( 0.5 );
220   
221   aStdLayout->addWidget( new QLabel( tr( "BLSURF_ANGLE_MESH_C" ), myStdGroup ), row, 0, 1, 1 );
222   myAngleMeshC = new QtxDoubleSpinBox( myStdGroup );
223   aStdLayout->addWidget( myAngleMeshC, row++, 1, 1, 1 );
224   myAngleMeshC->setMinimum( 0 );
225   myAngleMeshC->setMaximum( 16 );
226   myAngleMeshC->setSingleStep( 0.5 );
227   
228   aStdLayout->addWidget( new QLabel( tr( "BLSURF_GRADATION" ), myStdGroup ), row, 0, 1, 1 );
229   myGradation = new QtxDoubleSpinBox( myStdGroup );
230   aStdLayout->addWidget( myGradation, row++, 1, 1, 1 );
231   myGradation->setMinimum( 1.1 );
232   myGradation->setMaximum( 2.5 );
233   myGradation->setSingleStep( 0.1 );
234
235 #ifdef WITH_SIZE_BOUNDARIES
236   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMIN" ), myStdGroup ), row, 0, 1, 1 );
237   myGeoMin = new QLineEdit( myStdGroup );
238   aStdLayout->addWidget( myGeoMin, row++, 1, 1, 1 );
239
240   aStdLayout->addWidget( new QLabel( tr( "BLSURF_HGEOMAX" ), myStdGroup ), row, 0, 1, 1 );
241   myGeoMax = new QLineEdit( myStdGroup );
242   aStdLayout->addWidget( myGeoMax, row++, 1, 1, 1 );
243 #endif
244
245   myAllowQuadrangles = new QCheckBox( tr( "BLSURF_ALLOW_QUADRANGLES" ), myStdGroup );
246   aStdLayout->addWidget( myAllowQuadrangles, row++, 0, 1, 2 );
247
248   myDecimesh = new QCheckBox( tr( "BLSURF_DECIMESH" ), myStdGroup );
249   aStdLayout->addWidget( myDecimesh, row++, 0, 1, 2 );
250   
251   // advanced parameters
252   myAdvGroup = new QWidget();
253   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
254   anAdvLayout->setSpacing( 6 );
255   anAdvLayout->setMargin( 11 );
256
257   anAdvLayout->addWidget( new QLabel( tr( "BLSURF_TOPOLOGY" ), myAdvGroup ), 0, 0, 1, 1 );
258   myTopology = new QComboBox( myAdvGroup );
259   anAdvLayout->addWidget( myTopology, 0, 1, 1, 1 );
260   QStringList topologyTypes;
261   topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
262   myTopology->addItems( topologyTypes );
263
264   anAdvLayout->addWidget( new QLabel( tr( "BLSURF_VERBOSITY" ), myAdvGroup ), 1, 0, 1, 1 );
265   myVerbosity = new QSpinBox( myAdvGroup );
266   anAdvLayout->addWidget( myVerbosity, 1, 1, 1, 1 );
267   myVerbosity->setMinimum( 0 );
268   myVerbosity->setMaximum( 100 );
269   myVerbosity->setSingleStep( 5 );
270
271   myOptionTable = new QTableWidget( 0, NB_COLUMNS, myAdvGroup );
272   anAdvLayout->addWidget( myOptionTable, 2, 0, 3, 2 );
273   QStringList headers;
274   headers << tr( "OPTION_ID_COLUMN" ) << tr( "OPTION_NAME_COLUMN" ) << tr( "OPTION_VALUE_COLUMN" );
275   myOptionTable->setHorizontalHeaderLabels( headers );
276   myOptionTable->horizontalHeader()->hideSection( OPTION_ID_COLUMN );
277   //myOptionTable->setColumnReadOnly( OPTION_NAME_COLUMN, TRUE );//////
278   //myOptionTable->setColumnReadOnly( OPTION_VALUE_COLUMN, FALSE );/////
279   myOptionTable->verticalHeader()->hide();
280   //myOptionTable->setSelectionBehavior( QAbstractItemView::SelectRows );
281
282   QPushButton* addBtn = new QPushButton( tr( "ADD_OPTION"),  myAdvGroup );
283   anAdvLayout->addWidget( addBtn, 2, 2, 1, 1 );
284   addBtn->setMenu( new QMenu() );
285
286   QPushButton* rmBtn = new QPushButton( tr( "REMOVE_OPTION"), myAdvGroup );
287   anAdvLayout->addWidget( rmBtn, 3, 2, 1, 1 );
288
289   anAdvLayout->setRowStretch( 4, 5 );
290   anAdvLayout->setColumnStretch( 1, 5 );
291
292   // ---
293   tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
294   tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) );
295   tab->setCurrentIndex( STD_TAB );
296
297   // ---
298   connect( myGeometricMesh, SIGNAL( activated( int ) ), this, SLOT( onGeometricMeshChanged() ) );
299   connect( myPhysicalMesh,  SIGNAL( activated( int ) ), this, SLOT( onPhysicalMeshChanged() ) );
300   connect( addBtn->menu(),  SIGNAL( aboutToShow() ),    this, SLOT( onAddOption() ) );
301   connect( addBtn->menu(),  SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
302   connect( rmBtn,           SIGNAL( clicked()),         this, SLOT( onDeleteOption() ) );
303
304   return fr;
305 }
306
307 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
308 {
309   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
310
311   BlsurfHypothesisData data;
312   that->readParamsFromHypo( data );
313
314   if ( myName ) {
315     myName->setText( data.myName );
316     QFontMetrics metrics( myName->font() );
317     myName->setMinimumWidth( metrics.width( data.myName )+5 );
318   }
319   myTopology->setCurrentIndex( data.myTopology );
320   myPhysicalMesh->setCurrentIndex( data.myPhysicalMesh );
321   myPhySize->setText( data.myPhySize );
322 #ifdef WITH_SIZE_BOUNDARIES
323   myPhyMin->setText( data.myPhyMin );
324   myPhyMax->setText( data.myPhyMax );
325   myGeoMin->setText( data.myGeoMin );
326   myGeoMax->setText( data.myGeoMax );
327 #endif
328   myGeometricMesh->setCurrentIndex( data.myGeometricMesh );
329   myAngleMeshS->setValue( data.myAngleMeshS );
330   myAngleMeshC->setValue( data.myAngleMeshC );
331   myGradation->setValue( data.myGradation );
332   myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
333   myDecimesh->setChecked( data.myDecimesh );
334   myVerbosity->setValue( data.myVerbosity );
335
336   if ( myOptions.operator->() ) {
337     printf("retrieveParams():myOptions->length()=%d\n",myOptions->length());
338     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
339       QString option = that->myOptions[i].in();
340       QStringList name_value = option.split( ":", QString::KeepEmptyParts );
341       if ( name_value.count() > 1 ) {
342         QString idStr = QString("%1").arg( i );
343         int row = myOptionTable->rowCount();
344         myOptionTable->setRowCount( row+1 );
345         myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
346         myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
347         myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
348         myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
349         myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
350         myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable | 
351                                                                    Qt::ItemIsEditable   | 
352                                                                    Qt::ItemIsEnabled );
353       }
354     } 
355   }
356   myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
357
358   // update widgets
359   that->onPhysicalMeshChanged();
360   that->onGeometricMeshChanged();
361 }
362
363 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
364 {
365   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
366
367   BlsurfHypothesisData data;
368   QString guiHyp = that->readParamsFromWidgets( data );
369   that->storeParamsToHypo( data );
370
371   return guiHyp;
372 }
373
374 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
375 {
376   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
377     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
378
379   HypothesisData* data = SMESH::GetHypothesisData( hypType() );
380   h_data.myName = isCreation() && data ? hypName() : "";
381
382   h_data.myTopology         = (int) h->GetTopology();
383   h_data.myPhysicalMesh     = (int) h->GetPhysicalMesh();
384   h_data.myPhySize          = QString::number( h->GetPhySize() );
385   h_data.myGeometricMesh    = (int) h->GetGeometricMesh();
386   h_data.myAngleMeshS       = h->GetAngleMeshS();
387   h_data.myAngleMeshC       = h->GetAngleMeshC();
388   h_data.myGradation        = h->GetGradation();
389   h_data.myAllowQuadrangles = h->GetQuadAllowed();
390   h_data.myDecimesh         = h->GetDecimesh();
391   h_data.myVerbosity        = h->GetVerbosity();
392
393 #ifdef WITH_SIZE_BOUNDARIES
394   double PhyMin = h->GetPhyMin();
395   double PhyMax = h->GetPhyMax();
396   double GeoMin = h->GetGeoMin();
397   double GeoMax = h->GetGeoMax();
398   if ( PhyMin > 0 )
399   h_data.myPhyMin = PhyMin > 0 ? QString::number( h->GetPhyMin() ) : QString("");
400   h_data.myPhyMax = PhyMax > 0 ? QString::number( h->GetPhyMax() ) : QString("");
401   h_data.myGeoMin = GeoMin > 0 ? QString::number( h->GetGeoMin() ) : QString("");
402   h_data.myGeoMax = GeoMax > 0 ? QString::number( h->GetGeoMax() ) : QString("");
403 #endif
404
405   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
406   that->myOptions = h->GetOptionValues();
407
408   return true;
409 }
410
411 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
412 {
413   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
414     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
415
416   bool ok = true;
417   try
418   {
419     if( isCreation() )
420       SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.toLatin1().constData() );
421
422     if ( h->GetTopology() != h_data.myTopology ) // avoid duplication of DumpPython commands
423       h->SetTopology( (int) h_data.myTopology );
424     if ( h->GetPhysicalMesh() != h_data.myPhysicalMesh )
425       h->SetPhysicalMesh( (int) h_data.myPhysicalMesh );
426     if ( h->GetGeometricMesh() != (int) h_data.myGeometricMesh )
427       h->SetGeometricMesh( (int) h_data.myGeometricMesh );
428     if ( h->GetGradation() !=  h_data.myGradation )
429       h->SetGradation( h_data.myGradation );
430     if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
431       h->SetQuadAllowed( h_data.myAllowQuadrangles );
432     if ( h->GetDecimesh() != h_data.myDecimesh )
433       h->SetDecimesh( h_data.myDecimesh );
434     if ( h->GetVerbosity() != h_data.myVerbosity )
435       h->SetVerbosity( h_data.myVerbosity );
436
437     if( (int) h_data.myPhysicalMesh == PhysicalUserDefined ) {
438       if ( h->GetPhySize() != h_data.myPhySize.toDouble() )
439         h->SetPhySize( h_data.myPhySize.toDouble() );
440     }
441     if( (int) h_data.myGeometricMesh == UserDefined ) {
442       if ( h->GetAngleMeshS() != h_data.myAngleMeshS )
443         h->SetAngleMeshS( h_data.myAngleMeshS );
444       if ( h->GetAngleMeshC() != h_data.myAngleMeshC )
445         h->SetAngleMeshC( h_data.myAngleMeshC );
446     }
447 #ifdef WITH_SIZE_BOUNDARIES
448     if ( !isDouble( h_data.myPhyMin ))
449       h->SetPhyMin( -1 );
450     else if ( h->GetPhyMin() != h_data.myPhyMin.toDouble() )
451       h->SetPhyMin( h_data.myPhyMin.toDouble() );
452     if ( !isDouble( h_data.myPhyMax ))
453       h->SetPhyMax( -1 );
454     else if ( h->GetPhyMax() != h_data.myPhyMax.toDouble() )
455       h->SetPhyMax( h_data.myPhyMax.toDouble() );
456     if ( !isDouble( h_data.myGeoMin ))
457       h->SetGeoMin( -1 );
458     else if ( h->GetGeoMin() != h_data.myGeoMin.toDouble() )
459       h->SetGeoMin( h_data.myGeoMin.toDouble() );
460     if ( !isDouble( h_data.myGeoMax ))
461       h->SetGeoMax( -1 );
462     else if ( h->GetGeoMax() != h_data.myGeoMax.toDouble() )
463       h->SetGeoMax( h_data.myGeoMax.toDouble() );
464 #endif
465
466     printf("storeParamsToHypo():myOptions->length()=%d\n",myOptions->length());
467     h->SetOptionValues( myOptions ); // is set in checkParams()
468   }
469   catch(const SALOME::SALOME_Exception& ex)
470   {
471     SalomeApp_Tools::QtCatchCorbaException(ex);
472     ok = false;
473   }
474   return ok;
475 }
476
477 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
478 {
479   h_data.myName             = myName ? myName->text() : "";
480   h_data.myTopology         = myTopology->currentIndex();
481   h_data.myPhysicalMesh     = myPhysicalMesh->currentIndex();
482   h_data.myPhySize          = myPhySize->text();
483 #ifdef WITH_SIZE_BOUNDARIES
484   h_data.myPhyMin           = myPhyMin->text();
485   h_data.myPhyMax           = myPhyMax->text();
486   h_data.myGeoMin           = myGeoMin->text();
487   h_data.myGeoMax           = myGeoMax->text();
488 #endif
489   h_data.myGeometricMesh    = myGeometricMesh->currentIndex();
490   h_data.myAngleMeshS       = myAngleMeshS->value();
491   h_data.myAngleMeshC       = myAngleMeshC->value();
492   h_data.myGradation        = myGradation->value();
493   h_data.myAllowQuadrangles = myAllowQuadrangles->isChecked();
494   h_data.myDecimesh         = myDecimesh->isChecked();
495   h_data.myVerbosity        = myVerbosity->value();
496
497   QString guiHyp;
498   guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
499   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
500   guiHyp += tr("BLSURF_HPHYDEF") + " = " + h_data.myPhySize + "; ";
501   guiHyp += tr("BLSURF_GEOM_MESH") + " = " + QString::number( h_data.myGeometricMesh ) + "; ";
502   guiHyp += tr("BLSURF_ANGLE_MESH_S") + " = " + QString::number( h_data.myAngleMeshS ) + "; ";
503   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
504   guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
505   guiHyp += tr("BLSURF_DECIMESH") + " = " + QString(h_data.myDecimesh ? "yes" : "no") + "; ";
506 #ifdef WITH_SIZE_BOUNDARIES
507   if ( isDouble( h_data.myPhyMin )) guiHyp += "hphymin = " + h_data.myPhyMin + "; ";
508   if ( isDouble( h_data.myPhyMax )) guiHyp += "hphymax = " + h_data.myPhyMax + "; ";
509   if ( isDouble( h_data.myGeoMin )) guiHyp += "hgeomin = " + h_data.myGeoMin + "; ";
510   if ( isDouble( h_data.myGeoMax )) guiHyp += "hgeomax = " + h_data.myGeoMax + "; ";
511 #endif
512
513   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
514   int row = 0, nbRows = myOptionTable->rowCount();
515   for ( ; row < nbRows; ++row )
516   {
517     int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
518     if ( id >= 0 && id < myOptions->length() )
519     {
520       QString name  = myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
521       QString value = myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
522       if ( value.isNull() )
523         value = "";
524       that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
525       if ( value != "" )
526         guiHyp += name + " = " + value + "; ";
527     }
528   }
529
530   cout << "guiHyp : " << guiHyp.toLatin1().data() << endl;
531
532   return guiHyp;
533 }
534
535 void BLSURFPluginGUI_HypothesisCreator::onPhysicalMeshChanged() {
536   bool isCustom = (myPhysicalMesh->currentIndex() == PhysicalUserDefined);
537   myPhySize->setEnabled(isCustom);
538   myPhyMax->setEnabled(isCustom);
539   myPhyMin->setEnabled(isCustom);
540
541   if ( !isCustom ) {
542     QString aPhySize = "";
543     switch( myPhysicalMesh->currentIndex() ) {
544       case DefaultSize:
545       default:
546         aPhySize = "10";
547         break;
548       }
549     myPhySize->setText( aPhySize );
550     if ( !isDouble( myPhyMin->text(), true ))
551       myPhyMin->setText("");
552     if ( !isDouble( myPhyMax->text(), true ))
553       myPhyMax->setText("");
554     if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
555       myGeometricMesh->setCurrentIndex( UserDefined );
556       onGeometricMeshChanged();
557     }
558   }
559 }
560
561 void BLSURFPluginGUI_HypothesisCreator::onGeometricMeshChanged() {
562   bool isCustom = (myGeometricMesh->currentIndex() == UserDefined);
563   myAngleMeshS->setEnabled(isCustom);
564   myAngleMeshC->setEnabled(isCustom);
565   myGradation->setEnabled(isCustom);
566   myGeoMax->setEnabled(isCustom);
567   myGeoMin->setEnabled(isCustom);
568
569   if ( ! isCustom ) {
570     double aAngleMeshS, aGradation;
571     switch( myGeometricMesh->currentIndex() ) {
572       case DefaultGeom:
573       default:
574         aAngleMeshS = 8;
575         aGradation = 1.1;
576         break;
577       }
578     myAngleMeshS->setValue( aAngleMeshS );
579     myAngleMeshC->setValue( aAngleMeshS );
580     myGradation->setValue( aGradation );
581     if ( !isDouble( myGeoMin->text(), true ))
582       myGeoMin->setText("");
583     if ( !isDouble( myGeoMax->text(), true ))
584       myGeoMax->setText("");
585     //  hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
586     if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
587       myPhysicalMesh->setCurrentIndex( PhysicalUserDefined );
588       onPhysicalMeshChanged();
589     }
590   }
591 }
592
593 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
594 {
595   QMenu* menu = (QMenu*)sender();
596   // fill popup with option names
597   menu->clear();
598   if ( myOptions.operator->() ) {
599     for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
600       QString name_value = myOptions[i].in();
601       QString name = name_value.split( ":", QString::KeepEmptyParts )[0];
602       menu->addAction( name );
603     }
604   }
605 }
606
607 void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
608 {
609   myOptionTable->setFocus();
610   QMenu* menu = (QMenu*)( a->parent() );
611   
612   int idx = menu->actions().indexOf( a );
613   QString idStr = QString("%1").arg( idx );
614   QString option = myOptions[idx].in();
615   QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
616
617   // look for a row with optionName
618   int row = 0, nbRows = myOptionTable->rowCount();
619   for ( ; row < nbRows; ++row )
620     if ( myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
621       break;
622   // add a row if not found
623   if ( row == nbRows ) {
624     myOptionTable->setRowCount( row+1 );
625     myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
626     myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
627     myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
628     myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
629     myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
630     myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable | 
631                                                                Qt::ItemIsEditable   | 
632                                                                Qt::ItemIsEnabled );
633     myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
634   }
635   myOptionTable->clearSelection();
636   myOptionTable->scrollToItem( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
637   //myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
638   myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
639   //myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
640 }
641     
642 void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
643 {
644   // clear option values and remember selected row
645   QList<int> selectedRows;
646   QList<QTableWidgetItem*> selected = myOptionTable->selectedItems(); 
647   QTableWidgetItem* item;
648   foreach( item, selected ) {
649     int row = item->row();
650     if ( !selectedRows.contains( row ) ) {
651       selectedRows.append( row );
652       int id = myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
653       if ( id >= 0 && id < myOptions->length() )
654         myOptions[ id ] = myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
655     }
656   }
657   qSort( selectedRows );
658   QListIterator<int> it( selectedRows );
659   it.toBack();
660   while ( it.hasPrevious() )
661     myOptionTable->removeRow( it.previous() );
662 }
663
664  
665 QString BLSURFPluginGUI_HypothesisCreator::caption() const
666 {
667   return tr( "BLSURF_TITLE" );
668 }
669
670 QPixmap BLSURFPluginGUI_HypothesisCreator::icon() const
671 {
672   return SUIT_Session::session()->resourceMgr()->loadPixmap( "BLSURFPlugin", tr( "ICON_DLG_BLSURF_PARAMETERS") );
673 }
674
675 QString BLSURFPluginGUI_HypothesisCreator::type() const
676 {
677   return tr( "BLSURF_HYPOTHESIS" );
678 }
679
680 QString BLSURFPluginGUI_HypothesisCreator::helpPage() const
681 {
682   return "blsurf_hypo_page.html";
683 }