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