Salome HOME
Merge from V5_1_main 14/05/2010
[modules/smesh.git] / src / StdMeshersGUI / StdMeshersGUI_StdHypothesisCreator.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : StdMeshersGUI_StdHypothesisCreator.cxx
24 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
25 // SMESH includes
26 //
27 #include "StdMeshersGUI_StdHypothesisCreator.h"
28
29 #include <SMESHGUI.h>
30 #include <SMESHGUI_SpinBox.h>
31 #include <SMESHGUI_HypothesesUtils.h>
32 #include <SMESHGUI_Utils.h>
33 #include <SMESH_TypeFilter.hxx>
34 #include <SMESH_NumberFilter.hxx>
35 #include "StdMeshersGUI_ObjectReferenceParamWdg.h"
36 #include "StdMeshersGUI_LayerDistributionParamWdg.h"
37 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
38 #include "StdMeshersGUI_FixedPointsParamWdg.h"
39 #include <SALOMEDSClient_Study.hxx>
40
41 // SALOME GUI includes
42 #include <SUIT_ResourceMgr.h>
43
44 // IDL includes
45 #include <SALOMEconfig.h>
46 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
47 #include CORBA_SERVER_HEADER(SMESH_Mesh)
48
49 // Qt includes
50 #include <QHBoxLayout>
51 #include <QSlider>
52 #include <QLabel>
53 #include <QCheckBox>
54
55 const double VALUE_MAX = 1.0e+15, // COORD_MAX
56              VALUE_MAX_2  = VALUE_MAX * VALUE_MAX,
57              VALUE_MAX_3  = VALUE_MAX_2 * VALUE_MAX,
58              VALUE_SMALL = 1.0e-15,
59              VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL,
60              VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL;
61
62 //================================================================================
63 /*!
64  * \brief Constructor
65   * \param type - hypothesis type
66  */
67 //================================================================================
68
69 StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type )
70 : SMESHGUI_GenericHypothesisCreator( type )
71 {
72 }
73
74 //================================================================================
75 /*!
76  * \brief Destructor
77  */
78 //================================================================================
79
80 StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator()
81 {
82 }
83
84 //================================================================================
85 /*!
86  * \brief Return widget for i-th hypothesis parameter (got from myParamWidgets)
87   * \param i - index of hypothesis parameter
88   * \retval QWidget* - found widget
89  */
90 //================================================================================
91
92 QWidget* StdMeshersGUI_StdHypothesisCreator::getWidgetForParam( int i ) const
93 {
94   QWidget* w = 0;
95   if ( isCreation() ) ++i; // skip widget of 'name' parameter
96
97   if ( i < myCustomWidgets.count() ) {
98     QList<QWidget*>::const_iterator anIt  = myCustomWidgets.begin();
99     QList<QWidget*>::const_iterator aLast = myCustomWidgets.end();
100     for ( int j = 0 ; !w && anIt != aLast; ++anIt, ++j )
101       if ( i == j )
102         w = *anIt;
103   }
104   if ( !w ) {
105     // list has no at() const, so we iterate
106     QList<QWidget*>::const_iterator anIt  = widgets().begin();
107     QList<QWidget*>::const_iterator aLast = widgets().end();
108     for( int j = 0; !w && anIt!=aLast; anIt++, ++j ) {
109       if ( i == j )
110         w = *anIt;
111     }
112   }
113   return w;
114 }
115
116 //================================================================================
117 /*!
118  * \brief Allow modifing myCustomWidgets in const methods
119   * \retval ListOfWidgets* - non-const pointer to myCustomWidgets
120  */
121 //================================================================================
122
123 StdMeshersGUI_StdHypothesisCreator::ListOfWidgets*
124 StdMeshersGUI_StdHypothesisCreator::customWidgets() const
125 {
126   return const_cast< ListOfWidgets* >( & myCustomWidgets );
127 }
128
129 //================================================================================
130 /*!
131  * \brief Builds dlg layout
132   * \retval QFrame* - the built widget
133  */
134 //================================================================================
135
136 QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame()
137 {
138   return buildStdFrame();
139 }
140
141 //================================================================================
142 /*!
143  * \brief Initialise parameter values in controls
144  */
145 //================================================================================
146
147 void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const
148 {
149   // buildStdFrame() sets values itself calling stdParams()
150
151   if ( hypType().startsWith("ProjectionSource" ))
152   {
153     // we use this method to connect depending custom widgets
154     StdMeshersGUI_ObjectReferenceParamWdg* widgetToActivate = 0;
155     ListOfWidgets::const_iterator anIt = myCustomWidgets.begin();
156     for ( ; anIt != myCustomWidgets.end(); anIt++)
157     {
158       if ( *anIt && (*anIt)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
159       {
160         StdMeshersGUI_ObjectReferenceParamWdg * w1 =
161           ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
162         ListOfWidgets::const_iterator anIt2 = anIt;
163         for ( ++anIt2; anIt2 != myCustomWidgets.end(); anIt2++)
164           if ( *anIt2 && (*anIt2)->inherits("StdMeshersGUI_ObjectReferenceParamWdg"))
165           {
166             StdMeshersGUI_ObjectReferenceParamWdg * w2 =
167               ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt2 );
168             w1->AvoidSimultaneousSelection( w2 );
169           }
170         if ( !widgetToActivate )
171           widgetToActivate = w1;
172       }
173     }
174     if ( widgetToActivate )
175       widgetToActivate->activateSelection();
176   }
177
178   if ( dlg() )
179     dlg()->setMinimumSize( dlg()->minimumSizeHint().width(), dlg()->minimumSizeHint().height() );
180 }
181
182 namespace {
183
184   //================================================================================
185   /*!
186    * \brief Widget: slider with left and right labels
187    */
188   //================================================================================
189
190   class TDoubleSliderWith2Lables: public QWidget
191   {
192   public:
193     TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel,
194                               const double   initValue, const double   bottom,
195                               const double   top      , const double   precision,
196                               QWidget *      parent=0 , const char *   name=0 )
197       :QWidget(parent), _bottom(bottom), _precision(precision)
198     {
199       setObjectName(name);
200
201       QHBoxLayout* aHBoxL = new QHBoxLayout(this);
202       
203       if ( !leftLabel.isEmpty() ) {
204         QLabel* aLeftLabel = new QLabel( this );
205         aLeftLabel->setText( leftLabel );
206         aHBoxL->addWidget( aLeftLabel );
207       }
208
209       _slider = new QSlider( Qt::Horizontal, this );
210       _slider->setRange( 0, toInt( top ));
211       _slider->setValue( toInt( initValue ));
212       aHBoxL->addWidget( _slider );
213
214       if ( !rightLabel.isEmpty() ) {
215         QLabel* aRightLabel = new QLabel( this );
216         aRightLabel->setText( rightLabel );
217         aHBoxL->addWidget( aRightLabel );
218       }
219
220       setLayout( aHBoxL );
221     }
222     double value() const { return _bottom + _slider->value() * _precision; }
223     QSlider * getSlider() const { return _slider; }
224     int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); }
225   private:
226     double _bottom, _precision;
227     QSlider * _slider;
228   };
229
230   //================================================================================
231   /*!
232    * \brief Retrieve GEOM_Object held by widget
233    */
234   //================================================================================
235
236   inline GEOM::GEOM_Object_var geomFromWdg(const QWidget* wdg)
237   {
238     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
239       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
240     if ( objRefWdg )
241       return objRefWdg->GetObject< GEOM::GEOM_Object >();
242
243     return GEOM::GEOM_Object::_nil();
244   }
245   //================================================================================
246   /*!
247    * \brief Retrieve SMESH_Mesh held by widget
248    */
249   //================================================================================
250
251   inline SMESH::SMESH_Mesh_var meshFromWdg(const QWidget* wdg)
252   {
253     const StdMeshersGUI_ObjectReferenceParamWdg * objRefWdg =
254       dynamic_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( wdg );
255     if ( objRefWdg )
256       return objRefWdg->GetObject< SMESH::SMESH_Mesh >();
257
258     return SMESH::SMESH_Mesh::_nil();
259   }
260   //================================================================================
261   /*!
262    * \brief creates a filter for selection of shapes of given dimension
263     * \param dim - dimension
264     * \param subShapeType - required type of subshapes, number of which must be \a nbSubShapes
265     * \param nbSubShapes - number of subshapes of given type
266     * \param closed - required closeness flag of a shape
267     * \retval SUIT_SelectionFilter* - created filter
268    */
269   //================================================================================
270
271   SUIT_SelectionFilter* filterForShapeOfDim(const int        dim,
272                                             TopAbs_ShapeEnum subShapeType = TopAbs_SHAPE,
273                                             const int        nbSubShapes = 0,
274                                             bool             closed = false)
275   {
276     TColStd_MapOfInteger shapeTypes;
277     switch ( dim ) {
278     case 0: shapeTypes.Add( TopAbs_VERTEX ); break;
279     case 1:
280       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_EDGE;
281       shapeTypes.Add( TopAbs_EDGE );
282       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
283       break;
284     case 2:
285       if ( subShapeType == TopAbs_SHAPE ) subShapeType = TopAbs_FACE;
286       shapeTypes.Add( TopAbs_FACE );
287       shapeTypes.Add( TopAbs_COMPOUND ); // for a group
288       break;
289     case 3:
290       shapeTypes.Add( TopAbs_SHELL );
291       shapeTypes.Add( TopAbs_SOLID );
292       shapeTypes.Add( TopAbs_COMPSOLID );
293       shapeTypes.Add( TopAbs_COMPOUND );
294       break;
295     }
296     return new SMESH_NumberFilter("GEOM", subShapeType, nbSubShapes,
297                                   shapeTypes, GEOM::GEOM_Object::_nil(), closed);
298   }
299
300   //================================================================================
301   /*!
302    * \brief Create a widget for object selection
303     * \param object - initial object
304     * \param filter - selection filter
305     * \retval QWidget* - created widget
306    */
307   //================================================================================
308
309   QWidget* newObjRefParamWdg( SUIT_SelectionFilter* filter,
310                               CORBA::Object_var     object)
311   {
312     StdMeshersGUI_ObjectReferenceParamWdg* w =
313       new StdMeshersGUI_ObjectReferenceParamWdg( filter, 0);
314     w->SetObject( object.in() );
315     return w;
316   }
317
318   //================================================================================
319   /*!
320    * \brief calls deactivateSelection() for StdMeshersGUI_ObjectReferenceParamWdg
321     * \param widgetList - list of widgets
322    */
323   //================================================================================
324
325   void deactivateObjRefParamWdg( QList<QWidget*>* widgetList )
326   {
327     StdMeshersGUI_ObjectReferenceParamWdg* w = 0;
328     QList<QWidget*>::iterator anIt  = widgetList->begin();
329     QList<QWidget*>::iterator aLast = widgetList->end();
330     for ( ; anIt != aLast; anIt++ ) {
331       if ( (*anIt) && (*anIt)->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
332       {
333         w = (StdMeshersGUI_ObjectReferenceParamWdg* )( *anIt );
334         w->deactivateSelection();
335       }
336     }
337   }
338 }
339
340 //================================================================================
341 /*!
342  * \brief Check parameter values before accept()
343   * \retval bool - true if OK
344  */
345 //================================================================================
346
347 bool StdMeshersGUI_StdHypothesisCreator::checkParams( QString& msg ) const
348 {
349   if( !SMESHGUI_GenericHypothesisCreator::checkParams( msg ) )
350     return false;
351
352   // check if object reference parameter is set, as it has no default value
353   bool ok = true;
354   if ( hypType().startsWith("ProjectionSource" ))
355   {
356     StdMeshersGUI_ObjectReferenceParamWdg* w =
357       widget< StdMeshersGUI_ObjectReferenceParamWdg >( 0 );
358     ok = ( w->IsObjectSelected() );
359     if ( !ok ) w->SetObject( CORBA::Object::_nil() );
360     int nbAssocVert = ( hypType() == "ProjectionSource1D" ? 1 : 2 );
361     for ( int i = 0; ok && i < nbAssocVert; i += 2)
362     {
363       QString srcV, tgtV;
364       StdMeshersGUI_ObjectReferenceParamWdg* w1 =
365         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+2 );
366       StdMeshersGUI_ObjectReferenceParamWdg* w2 =
367         widget< StdMeshersGUI_ObjectReferenceParamWdg >( i+3 );
368       srcV = w1->GetValue();
369       tgtV = w2->GetValue();
370       ok = (( srcV.isEmpty()  && tgtV.isEmpty() ) ||
371             ( !srcV.isEmpty() && !tgtV.isEmpty() && srcV != tgtV ));
372       if ( !ok ) {
373         w1->SetObject( CORBA::Object::_nil() );
374         w2->SetObject( CORBA::Object::_nil() );
375       }
376     }
377
378     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
379     if ( ok )
380       deactivateObjRefParamWdg( customWidgets() );
381   }
382   else if ( hypType() == "LayerDistribution" || hypType() == "LayerDistribution2D" )
383   {
384     StdMeshersGUI_LayerDistributionParamWdg* w = 
385       widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
386     ok = ( w && w->IsOk() );
387   }
388   else if ( hypType() == "QuadrangleParams" )
389   {
390     StdMeshersGUI_SubShapeSelectorWdg* w = 
391       widget< StdMeshersGUI_SubShapeSelectorWdg >( 0 );
392     ok = ( w->GetListSize() > 0 );
393   }
394   return ok;
395 }
396
397 //================================================================================
398 /*!
399  * \brief Store params from GUI controls to a hypothesis
400   * \retval QString - text representation of parameters
401  */
402 //================================================================================
403
404 QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
405 {
406   ListOfStdParams params;
407   bool res = getStdParamFromDlg( params );
408   if( isCreation() )
409   {
410     SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().toLatin1().data() );
411     params.erase( params.begin() );
412   }
413
414   QString valueStr = stdParamValues( params );
415   QStringList aVariablesList = getVariablesFromDlg();
416
417   if( res && !params.isEmpty() )
418   {
419     if( hypType()=="LocalLength" )
420     {
421       StdMeshers::StdMeshers_LocalLength_var h =
422         StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
423
424       h->SetLength( params[0].myValue.toDouble() );
425       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
426       h->SetPrecision( params[1].myValue.toDouble() );
427       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
428     }
429     else if( hypType()=="MaxLength" )
430     {
431       StdMeshers::StdMeshers_MaxLength_var h =
432         StdMeshers::StdMeshers_MaxLength::_narrow( hypothesis() );
433
434       h->SetLength( params[0].myValue.toDouble() );
435       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
436       h->SetUsePreestimatedLength( widget< QCheckBox >( 1 )->isChecked() );
437       if ( !h->HavePreestimatedLength() && !h->_is_equivalent( initParamsHypothesis() )) {
438         StdMeshers::StdMeshers_MaxLength_var hInit =
439           StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
440         h->SetPreestimatedLength( hInit->GetPreestimatedLength() );
441       }
442     }
443     else if( hypType()=="SegmentLengthAroundVertex" )
444     {
445       StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
446         StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() );
447
448       h->SetLength( params[0].myValue.toDouble() );
449       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
450     }
451     else if( hypType()=="Arithmetic1D" )
452     {
453       StdMeshers::StdMeshers_Arithmetic1D_var h =
454         StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() );
455
456       StdMeshersGUI_SubShapeSelectorWdg* w = 
457         widget< StdMeshersGUI_SubShapeSelectorWdg >( 2 );
458
459       h->SetStartLength( params[0].myValue.toDouble() );
460       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
461       h->SetEndLength( params[1].myValue.toDouble() );
462       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
463       if (w) {
464         h->SetReversedEdges( w->GetListOfIDs() );
465         h->SetObjectEntry( w->GetMainShapeEntry() );
466       }
467     }
468     else if( hypType()=="FixedPoints1D" )
469     {
470       StdMeshers::StdMeshers_FixedPoints1D_var h =
471         StdMeshers::StdMeshers_FixedPoints1D::_narrow( hypothesis() );
472
473       StdMeshersGUI_FixedPointsParamWdg* w1 = 
474         widget< StdMeshersGUI_FixedPointsParamWdg >( 0 );
475
476       StdMeshersGUI_SubShapeSelectorWdg* w2 = 
477         widget< StdMeshersGUI_SubShapeSelectorWdg >( 1 );
478
479       if (w1) {
480         h->SetParameters(aVariablesList.join(":").toLatin1().constData());
481         h->SetPoints( w1->GetListOfPoints() );
482         h->SetNbSegments( w1->GetListOfSegments() );
483       }
484       if (w2) {
485         h->SetReversedEdges( w2->GetListOfIDs() );
486         h->SetObjectEntry( w2->GetMainShapeEntry() );
487       }
488     }
489     else if( hypType()=="MaxElementArea" )
490     {
491       StdMeshers::StdMeshers_MaxElementArea_var h =
492         StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() );
493       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
494       h->SetMaxElementArea( params[0].myValue.toDouble() );
495     }
496     else if( hypType()=="MaxElementVolume" )
497     {
498       StdMeshers::StdMeshers_MaxElementVolume_var h =
499         StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() );
500
501       h->SetMaxElementVolume( params[0].myValue.toDouble() );
502       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
503     }
504     else if( hypType()=="StartEndLength" )
505     {
506       StdMeshers::StdMeshers_StartEndLength_var h =
507         StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() );
508
509       StdMeshersGUI_SubShapeSelectorWdg* w = 
510         widget< StdMeshersGUI_SubShapeSelectorWdg >( 2 );
511
512       h->SetStartLength( params[0].myValue.toDouble() );
513       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
514       h->SetEndLength( params[1].myValue.toDouble() );
515       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
516       if (w) {
517         h->SetReversedEdges( w->GetListOfIDs() );
518         h->SetObjectEntry( w->GetMainShapeEntry() );
519       }
520     }
521     else if( hypType()=="Deflection1D" )
522     {
523       StdMeshers::StdMeshers_Deflection1D_var h =
524         StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() );
525       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
526       h->SetDeflection( params[0].myValue.toDouble() );
527     }
528     else if( hypType()=="AutomaticLength" )
529     {
530       StdMeshers::StdMeshers_AutomaticLength_var h =
531         StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() );
532
533       h->SetFineness( params[0].myValue.toDouble() );
534     }
535     else if( hypType()=="NumberOfLayers" )
536     {
537       StdMeshers::StdMeshers_NumberOfLayers_var h =
538         StdMeshers::StdMeshers_NumberOfLayers::_narrow( hypothesis() );
539
540       h->SetNumberOfLayers( params[0].myValue.toInt() );
541       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
542     }
543     else if( hypType()=="LayerDistribution" )
544     {
545       StdMeshers::StdMeshers_LayerDistribution_var h =
546         StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() );
547       StdMeshersGUI_LayerDistributionParamWdg* w = 
548         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
549       
550       h->SetLayerDistribution( w->GetHypothesis() );
551       h->SetParameters(w->GetHypothesis()->GetParameters());
552       w->GetHypothesis()->ClearParameters();
553     }
554     else if( hypType()=="NumberOfLayers2D" )
555     {
556       StdMeshers::StdMeshers_NumberOfLayers2D_var h =
557         StdMeshers::StdMeshers_NumberOfLayers2D::_narrow( hypothesis() );
558
559       h->SetNumberOfLayers( params[0].myValue.toInt() );
560       h->SetParameters(aVariablesList.join(":").toLatin1().constData());
561     }
562     else if( hypType()=="LayerDistribution2D" )
563     {
564       StdMeshers::StdMeshers_LayerDistribution2D_var h =
565         StdMeshers::StdMeshers_LayerDistribution2D::_narrow( hypothesis() );
566       StdMeshersGUI_LayerDistributionParamWdg* w = 
567         widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 );
568       
569       h->SetLayerDistribution( w->GetHypothesis() );
570       h->SetParameters(w->GetHypothesis()->GetParameters());
571       w->GetHypothesis()->ClearParameters();
572     }
573     else if( hypType()=="ProjectionSource1D" )
574     {
575       StdMeshers::StdMeshers_ProjectionSource1D_var h =
576         StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hypothesis() );
577
578       h->SetSourceEdge       ( geomFromWdg ( getWidgetForParam( 0 )));
579       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
580       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )),
581                                geomFromWdg ( getWidgetForParam( 3 )));
582     }
583     else if( hypType()=="ProjectionSource2D" )
584     {
585       StdMeshers::StdMeshers_ProjectionSource2D_var h =
586         StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hypothesis() );
587
588       h->SetSourceFace       ( geomFromWdg ( getWidgetForParam( 0 )));
589       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
590       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
591                                geomFromWdg ( getWidgetForParam( 4 )), // src2
592                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
593                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
594     }
595     else if( hypType()=="ProjectionSource3D" )
596     {
597       StdMeshers::StdMeshers_ProjectionSource3D_var h =
598         StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hypothesis() );
599
600       h->SetSource3DShape    ( geomFromWdg ( getWidgetForParam( 0 )));
601       h->SetSourceMesh       ( meshFromWdg ( getWidgetForParam( 1 )));
602       h->SetVertexAssociation( geomFromWdg ( getWidgetForParam( 2 )), // src1
603                                geomFromWdg ( getWidgetForParam( 4 )), // src2
604                                geomFromWdg ( getWidgetForParam( 3 )), // tgt1
605                                geomFromWdg ( getWidgetForParam( 5 ))); // tgt2
606     }
607     else if( hypType()=="QuadrangleParams" )
608     {
609       StdMeshers::StdMeshers_QuadrangleParams_var h =
610         StdMeshers::StdMeshers_QuadrangleParams::_narrow( hypothesis() );
611       StdMeshersGUI_SubShapeSelectorWdg* w = 
612         widget< StdMeshersGUI_SubShapeSelectorWdg >( 0 );
613       if (w) {
614         if( w->GetListSize() > 0 ) {
615           h->SetTriaVertex( w->GetListOfIDs()[0] ); // getlist must be called once
616           const char * entry = w->GetMainShapeEntry();
617           h->SetObjectEntry( entry );
618         }
619       }
620     }
621   }
622   return valueStr;
623 }
624
625 //================================================================================
626 /*!
627  * \brief Return parameter values as SMESHGUI_GenericHypothesisCreator::StdParam
628   * \param p - list of parameters
629   * \retval bool - success flag
630   *
631   * Is called from SMESHGUI_GenericHypothesisCreator::buildStdFrame().
632   * Parameters will be shown using "standard" controls:
633   *   Int by QtxIntSpinBox
634   *   Double by SMESHGUI_SpinBox
635   *   String by QLineEdit
636   * getCustomWidget() allows to redefine control for a parameter
637  */
638 //================================================================================
639
640 bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
641 {
642   bool res = true;
643   SMESHGUI_GenericHypothesisCreator::StdParam item;
644
645   p.clear();
646   customWidgets()->clear();
647   if( isCreation() )
648   {
649     HypothesisData* data = SMESH::GetHypothesisData( hypType() );
650     item.myName = tr( "SMESH_NAME" );
651     item.myValue = data ? hypName() : QString();
652     p.append( item );
653     customWidgets()->append(0);
654   }
655   
656   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
657   SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters();
658
659   if( hypType()=="LocalLength" )
660   {
661     StdMeshers::StdMeshers_LocalLength_var h =
662       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
663     
664     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
665     if(!initVariableName(aParameters,item,0))
666       item.myValue = h->GetLength();
667     p.append( item );     
668     
669     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
670     if(!initVariableName(aParameters,item,1))
671       item.myValue = h->GetPrecision(); 
672     p.append( item );
673     
674   }
675   else if( hypType()=="MaxLength" )
676   {
677     StdMeshers::StdMeshers_MaxLength_var h =
678       StdMeshers::StdMeshers_MaxLength::_narrow( hyp );
679     // try to set a right preestimated length to edited hypothesis
680     bool noPreestimatedAtEdition = false;
681     if ( !isCreation() ) {
682       StdMeshers::StdMeshers_MaxLength_var initHyp =
683         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis(true) );
684       noPreestimatedAtEdition =
685         ( initHyp->_is_nil() || !initHyp->HavePreestimatedLength() );
686       if ( !noPreestimatedAtEdition )
687         h->SetPreestimatedLength( initHyp->GetPreestimatedLength() );
688     }
689
690     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
691     if(!initVariableName(aParameters,item,0))
692       item.myValue = h->GetLength();
693     p.append( item );
694     customWidgets()->append(0);
695
696     item.myName = tr("SMESH_USE_PREESTIMATED_LENGTH");
697     p.append( item );
698     QCheckBox* aQCheckBox = new QCheckBox(dlg());
699     if ( !noPreestimatedAtEdition && h->HavePreestimatedLength() ) {
700       aQCheckBox->setChecked( h->GetUsePreestimatedLength() );
701       connect( aQCheckBox, SIGNAL(  stateChanged(int) ), this, SLOT( onValueChanged() ) );
702     }
703     else {
704       aQCheckBox->setChecked( false );
705       aQCheckBox->setEnabled( false );
706     }
707     customWidgets()->append( aQCheckBox );
708   }
709   else if( hypType()=="SegmentLengthAroundVertex" )
710   {
711     StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h =
712       StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp );
713
714     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
715     if(!initVariableName(aParameters,item,0))
716       item.myValue = h->GetLength();
717     
718     p.append( item );
719   }
720   else if( hypType()=="Arithmetic1D" )
721   {
722     StdMeshers::StdMeshers_Arithmetic1D_var h =
723       StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp );
724
725     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
726     if(!initVariableName(aParameters,item,0))
727       item.myValue = h->GetLength( true );
728     p.append( item );
729
730     customWidgets()->append (0);
731
732     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
733     if(!initVariableName(aParameters,item,1))
734       item.myValue = h->GetLength( false );
735     p.append( item );
736
737     customWidgets()->append (0);
738
739     item.myName = tr( "SMESH_REVERSED_EDGES" );
740     p.append( item );
741
742     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
743       new StdMeshersGUI_SubShapeSelectorWdg();
744     QString aGeomEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
745     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
746     if ( aGeomEntry == "" )
747       aGeomEntry = h->GetObjectEntry();
748
749     aDirectionWidget->SetGeomShapeEntry( aGeomEntry );
750     aDirectionWidget->SetMainShapeEntry( aMainEntry );
751     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
752     aDirectionWidget->showPreview( true );
753     customWidgets()->append ( aDirectionWidget );
754   }
755
756
757   else if( hypType()=="FixedPoints1D" )
758   {
759     StdMeshers::StdMeshers_FixedPoints1D_var h =
760       StdMeshers::StdMeshers_FixedPoints1D::_narrow( hyp );
761
762     item.myName = tr( "SMESH_FIXED_POINTS" );
763     p.append( item );
764
765     StdMeshersGUI_FixedPointsParamWdg* aFixedPointsWidget =
766       new StdMeshersGUI_FixedPointsParamWdg();
767
768     if ( !isCreation() ) {
769       aFixedPointsWidget->SetListOfPoints( h->GetPoints() );
770       aFixedPointsWidget->SetListOfSegments( h->GetNbSegments() );
771     }
772     customWidgets()->append( aFixedPointsWidget );
773
774     item.myName = tr( "SMESH_REVERSED_EDGES" );
775     p.append( item );
776
777     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
778       new StdMeshersGUI_SubShapeSelectorWdg();
779     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
780     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
781     if ( anEntry == "" )
782       anEntry = h->GetObjectEntry();
783     aDirectionWidget->SetGeomShapeEntry( anEntry );
784     aDirectionWidget->SetMainShapeEntry( aMainEntry );
785     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
786     aDirectionWidget->showPreview( true );
787     customWidgets()->append ( aDirectionWidget );
788   }
789
790
791   else if( hypType()=="MaxElementArea" )
792   {
793     StdMeshers::StdMeshers_MaxElementArea_var h =
794       StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp );
795
796     item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" );
797     if(!initVariableName(aParameters,item,0))
798       item.myValue = h->GetMaxElementArea();
799     p.append( item );
800     
801   }
802   else if( hypType()=="MaxElementVolume" )
803   {
804     StdMeshers::StdMeshers_MaxElementVolume_var h =
805       StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp );
806
807     item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" );
808     if(!initVariableName(aParameters,item,0))
809       item.myValue = h->GetMaxElementVolume();
810     p.append( item );
811   }
812   else if( hypType()=="StartEndLength" )
813   {
814     StdMeshers::StdMeshers_StartEndLength_var h =
815       StdMeshers::StdMeshers_StartEndLength::_narrow( hyp );
816
817     item.myName = tr( "SMESH_START_LENGTH_PARAM" );
818
819     if(!initVariableName(aParameters,item,0)) 
820       item.myValue = h->GetLength( true );
821     p.append( item );
822     customWidgets()->append(0);
823
824     item.myName = tr( "SMESH_END_LENGTH_PARAM" );
825     if(!initVariableName(aParameters,item,1)) 
826       item.myValue = h->GetLength( false );
827     p.append( item );
828     customWidgets()->append(0);
829
830     item.myName = tr( "SMESH_REVERSED_EDGES" );
831     p.append( item );
832
833     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
834       new StdMeshersGUI_SubShapeSelectorWdg();
835     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
836     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
837     if ( anEntry == "" )
838       anEntry = h->GetObjectEntry();
839     aDirectionWidget->SetGeomShapeEntry( anEntry );
840     aDirectionWidget->SetMainShapeEntry( aMainEntry );
841     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
842     aDirectionWidget->showPreview( true );
843     customWidgets()->append ( aDirectionWidget );
844   }
845   else if( hypType()=="Deflection1D" )
846   {
847     StdMeshers::StdMeshers_Deflection1D_var h =
848       StdMeshers::StdMeshers_Deflection1D::_narrow( hyp );
849     
850     item.myName = tr( "SMESH_DEFLECTION1D_PARAM" );
851     if(!initVariableName(aParameters,item,0)) 
852       item.myValue = h->GetDeflection();
853     p.append( item );
854   }
855   else if( hypType()=="AutomaticLength" )
856   {
857     StdMeshers::StdMeshers_AutomaticLength_var h =
858       StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp );
859
860     item.myName = tr( "SMESH_FINENESS_PARAM" );
861     //item.myValue = h->GetFineness();
862     p.append( item );
863     customWidgets()->append
864       ( new TDoubleSliderWith2Lables( "0 ", " 1", h->GetFineness(), 0, 1, 0.01, 0 ));
865   }
866   else if( hypType()=="NumberOfLayers" )
867   {
868     StdMeshers::StdMeshers_NumberOfLayers_var h =
869       StdMeshers::StdMeshers_NumberOfLayers::_narrow( hyp );
870
871     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
872     if(!initVariableName(aParameters,item,0))     
873       item.myValue = (int) h->GetNumberOfLayers();
874     p.append( item );
875   }
876   else if( hypType()=="LayerDistribution" ) {
877     StdMeshers::StdMeshers_LayerDistribution_var h =
878       StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp );
879     
880     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
881     
882     //Set into not published hypo last variables
883     QStringList aLastVarsList;
884     for(int i = 0;i<aParameters->length();i++) 
885       aLastVarsList.append(QString(aParameters[i].in()));
886
887     if(!aLastVarsList.isEmpty())
888       h->GetLayerDistribution()->SetLastParameters(aLastVarsList.join(":").toLatin1().constData());
889     
890     customWidgets()->append
891       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
892   }
893   else if( hypType()=="NumberOfLayers2D" ) {
894     StdMeshers::StdMeshers_NumberOfLayers2D_var h =
895       StdMeshers::StdMeshers_NumberOfLayers2D::_narrow( hyp );
896     
897     item.myName = tr( "SMESH_NUMBER_OF_LAYERS" );
898     if(!initVariableName(aParameters,item,0))     
899       item.myValue = (int) h->GetNumberOfLayers();
900     p.append( item );
901   }
902   else if( hypType()=="LayerDistribution2D" ) {
903     StdMeshers::StdMeshers_LayerDistribution2D_var h =
904       StdMeshers::StdMeshers_LayerDistribution2D::_narrow( hyp );
905
906     item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item );
907     
908     //Set into not published hypo last variables
909     QStringList aLastVarsList;
910     for(int i = 0;i<aParameters->length();i++) 
911       aLastVarsList.append(QString(aParameters[i].in()));
912
913     if(!aLastVarsList.isEmpty())
914       h->GetLayerDistribution()->SetLastParameters(aLastVarsList.join(":").toLatin1().constData());
915     
916     customWidgets()->append
917       ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg()));
918   }
919   else if( hypType()=="ProjectionSource1D" )
920   {
921     StdMeshers::StdMeshers_ProjectionSource1D_var h =
922       StdMeshers::StdMeshers_ProjectionSource1D::_narrow( hyp );
923
924     item.myName = tr( "SMESH_SOURCE_EDGE" ); p.append( item );
925     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 1 ),
926                                                h->GetSourceEdge()));
927     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
928     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
929                                                h->GetSourceMesh()));
930     item.myName = tr( "SMESH_SOURCE_VERTEX" ); p.append( item );
931     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
932                                                h->GetSourceVertex()));
933     item.myName = tr( "SMESH_TARGET_VERTEX" ); p.append( item );
934     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
935                                                h->GetTargetVertex()));
936   }
937   else if( hypType()=="ProjectionSource2D" )
938   {
939     StdMeshers::StdMeshers_ProjectionSource2D_var h =
940       StdMeshers::StdMeshers_ProjectionSource2D::_narrow( hyp );
941
942     item.myName = tr( "SMESH_SOURCE_FACE" ); p.append( item );
943     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 2 ),
944                                                h->GetSourceFace()));
945     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
946     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
947                                                h->GetSourceMesh()));
948     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
949     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
950                                                h->GetSourceVertex( 1 )));
951     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
952     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
953                                                h->GetTargetVertex( 1 )));
954     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
955     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
956                                                h->GetSourceVertex( 2 )));
957     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
958     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
959                                                h->GetTargetVertex( 2 )));
960   }
961   else if( hypType()=="ProjectionSource3D" )
962   {
963     StdMeshers::StdMeshers_ProjectionSource3D_var h =
964       StdMeshers::StdMeshers_ProjectionSource3D::_narrow( hyp );
965
966     item.myName = tr( "SMESH_SOURCE_3DSHAPE" ); p.append( item );
967     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 3, TopAbs_FACE, 6, true ),
968                                                h->GetSource3DShape()));
969     item.myName = tr( "SMESH_SOURCE_MESH" ); p.append( item );
970     customWidgets()->append( newObjRefParamWdg( new SMESH_TypeFilter( MESH ),
971                                                h->GetSourceMesh()));
972     item.myName = tr( "SMESH_SOURCE_VERTEX1" ); p.append( item );
973     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
974                                                h->GetSourceVertex( 1 )));
975     item.myName = tr( "SMESH_TARGET_VERTEX1" ); p.append( item );
976     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
977                                                h->GetTargetVertex( 1 )));
978     item.myName = tr( "SMESH_SOURCE_VERTEX2" ); p.append( item );
979     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
980                                                h->GetSourceVertex( 2 )));
981     item.myName = tr( "SMESH_TARGET_VERTEX2" ); p.append( item );
982     customWidgets()->append( newObjRefParamWdg( filterForShapeOfDim( 0 ),
983                                                h->GetTargetVertex( 2 )));
984   }
985   else if( hypType()=="QuadrangleParams" )
986   {
987     StdMeshers::StdMeshers_QuadrangleParams_var h =
988       StdMeshers::StdMeshers_QuadrangleParams::_narrow( hyp );
989
990     item.myName = tr( "SMESH_BASE_VERTEX" );
991     p.append( item );
992
993     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
994       new StdMeshersGUI_SubShapeSelectorWdg();
995     aDirectionWidget->SetMaxSize(1);
996     aDirectionWidget->SetSubShType(TopAbs_VERTEX);
997     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
998     QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
999     if ( anEntry == "" )
1000       anEntry = h->GetObjectEntry();
1001     aDirectionWidget->SetGeomShapeEntry( anEntry );
1002     aDirectionWidget->SetMainShapeEntry( aMainEntry );
1003     if ( !isCreation() ) {
1004       SMESH::long_array_var aVec = new SMESH::long_array;
1005       int vertID = h->GetTriaVertex();
1006       if(vertID>0) {
1007         aVec->length(1);
1008         aVec[0] = vertID;
1009         aDirectionWidget->SetListOfIDs( aVec );
1010       }
1011     }
1012     aDirectionWidget->showPreview( true );
1013     customWidgets()->append ( aDirectionWidget );
1014   }
1015   else
1016     res = false;
1017   return res;
1018 }
1019
1020 //================================================================================
1021 /*!
1022  * \brief tune "standard" control
1023   * \param w - control widget
1024   * \param int - parameter index
1025  */
1026 //================================================================================
1027
1028 void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget (QWidget* w, const int) const
1029 {
1030   SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0;
1031   if( hypType()=="LocalLength" &&  sb )
1032   {
1033     if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PARAM"))
1034       sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1035     else if (sb->objectName() == tr("SMESH_LOCAL_LENGTH_PRECISION"))
1036       sb->RangeStepAndValidator( 0.0, 1.0, 0.05, "len_tol_precision" );
1037   }
1038   else if( hypType()=="Arithmetic1D" && sb )
1039   {
1040     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "parametric_precision" );
1041   }
1042   else if( hypType()=="MaxLength" && sb )
1043   {
1044     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1045     sb->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1046   }
1047   else if( hypType()=="MaxElementArea" && sb )
1048   {
1049     sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, "area_precision" );
1050   }
1051   else if( hypType()=="MaxElementVolume" && sb )
1052   {
1053     sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, "vol_precision" );
1054   }
1055   else if( hypType()=="StartEndLength" && sb )
1056   {
1057     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1058   }
1059   else if( hypType()=="Deflection1D" && sb )
1060   {
1061     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "parametric_precision" );
1062   }
1063   else if ( sb ) // default validator for possible ancestors
1064   {
1065     sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, "length_precision" );
1066   }
1067 }
1068
1069 //================================================================================
1070 /*!
1071  * \brief Return dlg title
1072   * \retval QString - title string
1073  */
1074 //================================================================================
1075
1076 QString StdMeshersGUI_StdHypothesisCreator::caption() const
1077 {
1078   return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1079 }
1080
1081 //================================================================================
1082 /*!
1083  * \brief return pixmap for dlg icon
1084   * \retval QPixmap - 
1085  */
1086 //================================================================================
1087
1088 QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const
1089 {
1090   QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1091   return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName );
1092 }
1093
1094 //================================================================================
1095 /*!
1096  * \brief Return hypothesis type name to show in dlg
1097   * \retval QString - 
1098  */
1099 //================================================================================
1100
1101 QString StdMeshersGUI_StdHypothesisCreator::type() const
1102 {
1103   return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ).toLatin1().data() );
1104 }
1105
1106 //================================================================================
1107 /*!
1108  * \brief String to insert in "SMESH_%1_HYPOTHESIS" to get hypothesis type name
1109  * from message resouce file
1110   * \param t - hypothesis type
1111   * \retval QString - result string
1112  */
1113 //================================================================================
1114
1115 QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const
1116 {
1117   static QMap<QString,QString>  types;
1118   if( types.isEmpty() )
1119   {
1120     types.insert( "LocalLength", "LOCAL_LENGTH" );
1121     types.insert( "NumberOfSegments", "NB_SEGMENTS" );
1122     types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" );
1123     types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" );
1124     types.insert( "StartEndLength", "START_END_LENGTH" );
1125     types.insert( "Deflection1D", "DEFLECTION1D" );
1126     types.insert( "Arithmetic1D", "ARITHMETIC_1D" );
1127     types.insert( "FixedPoints1D", "FIXED_POINTS_1D" );
1128     types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" );
1129     types.insert( "ProjectionSource1D", "PROJECTION_SOURCE_1D" );
1130     types.insert( "ProjectionSource2D", "PROJECTION_SOURCE_2D" );
1131     types.insert( "ProjectionSource3D", "PROJECTION_SOURCE_3D" );
1132     types.insert( "NumberOfLayers", "NUMBER_OF_LAYERS" );
1133     types.insert( "LayerDistribution", "LAYER_DISTRIBUTION" );
1134     types.insert( "NumberOfLayers2D", "NUMBER_OF_LAYERS_2D" );
1135     types.insert( "LayerDistribution2D", "LAYER_DISTRIBUTION" );
1136     types.insert( "SegmentLengthAroundVertex", "SEGMENT_LENGTH_AROUND_VERTEX" );
1137     types.insert( "MaxLength", "MAX_LENGTH" );
1138     types.insert( "QuadrangleParams", "QUADRANGLE_PARAMS" );
1139   }
1140
1141   QString res;
1142   if( types.contains( t ) )
1143     res = types[ t ];
1144
1145   return res;
1146 }
1147
1148
1149 //=======================================================================
1150 //function : getCustomWidget
1151 //purpose  : is called from buildStdFrame()
1152 //=======================================================================
1153
1154 QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param,
1155                                                               QWidget*         parent,
1156                                                               const int        index) const
1157 {
1158   QWidget* w = 0;
1159   if ( index < customWidgets()->count() ) {
1160     w = customWidgets()->at( index );
1161     if ( w ) {
1162       w->setParent( parent );
1163       w->move( QPoint( 0, 0 ) );
1164     }
1165   }
1166   return w;
1167 }
1168
1169 //================================================================================
1170 /*!
1171  * \brief Set param value taken from a custom widget
1172   * \param param - SMESHGUI_GenericHypothesisCreator::StdParam structure
1173   * \param widget - widget presenting param
1174   * \retval bool - success flag
1175  * 
1176  * this method is called from getStdParamFromDlg()
1177  */
1178 //================================================================================
1179
1180 bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param,
1181                                                                    QWidget*   widget) const
1182 {
1183   if ( hypType()=="AutomaticLength" ) {
1184     TDoubleSliderWith2Lables* w = dynamic_cast<TDoubleSliderWith2Lables*>( widget );
1185     if ( w ) {
1186       param.myValue = w->value();
1187       return true;
1188     }
1189   }
1190   if ( hypType() == "MaxLength" ) {
1191     param.myValue = "";
1192     return true;
1193   }
1194   if ( widget->inherits( "StdMeshersGUI_ObjectReferenceParamWdg" ))
1195   {
1196     // show only 1st reference value
1197     if ( true /*widget == getWidgetForParam( 0 )*/) {
1198       const StdMeshersGUI_ObjectReferenceParamWdg * w =
1199         static_cast<const StdMeshersGUI_ObjectReferenceParamWdg*>( widget );
1200       param.myValue = w->GetValue();
1201     }
1202     return true;
1203   }
1204   if ( widget->inherits( "StdMeshersGUI_LayerDistributionParamWdg" ))
1205   {
1206     const StdMeshersGUI_LayerDistributionParamWdg * w =
1207       static_cast<const StdMeshersGUI_LayerDistributionParamWdg*>( widget );
1208     param.myValue = w->GetValue();
1209     return true;
1210   }
1211   if ( widget->inherits( "StdMeshersGUI_SubShapeSelectorWdg" ))
1212   {
1213     const StdMeshersGUI_SubShapeSelectorWdg * w =
1214       static_cast<const StdMeshersGUI_SubShapeSelectorWdg*>( widget );
1215     param.myValue = w->GetValue();
1216     return true;
1217   }
1218   if ( widget->inherits( "StdMeshersGUI_FixedPointsParamWdg" ))
1219   {
1220     const StdMeshersGUI_FixedPointsParamWdg * w =
1221       static_cast<const StdMeshersGUI_FixedPointsParamWdg*>( widget );
1222     param.myValue = w->GetValue();
1223     return true;
1224   }
1225   return false;
1226 }
1227
1228 //================================================================================
1229 /*!
1230  * \brief called when operation cancelled
1231  */
1232 //================================================================================
1233
1234 void StdMeshersGUI_StdHypothesisCreator::onReject()
1235 {
1236   if ( hypType().startsWith("ProjectionSource" ))
1237   {
1238     // Uninstall filters of StdMeshersGUI_ObjectReferenceParamWdg
1239     deactivateObjRefParamWdg( customWidgets() );
1240   }
1241 }
1242
1243 //================================================================================
1244 /*!
1245  * \brief 
1246  */
1247 //================================================================================
1248
1249 void StdMeshersGUI_StdHypothesisCreator::valueChanged( QWidget* paramWidget)
1250 {
1251   if ( hypType() == "MaxLength" && paramWidget == getWidgetForParam(1) ) {
1252     getWidgetForParam(0)->setEnabled( !widget< QCheckBox >( 1 )->isChecked() );
1253     if ( !getWidgetForParam(0)->isEnabled() ) {
1254       StdMeshers::StdMeshers_MaxLength_var h =
1255         StdMeshers::StdMeshers_MaxLength::_narrow( initParamsHypothesis() );
1256       widget< QtxDoubleSpinBox >( 0 )->setValue( h->GetPreestimatedLength() );
1257     }
1258   }
1259 }
1260
1261 //================================================================================
1262 /*!
1263  *
1264  */
1265 //================================================================================
1266
1267 bool StdMeshersGUI_StdHypothesisCreator::initVariableName(SMESH::ListOfParameters_var theParameters, 
1268                                                           StdParam &theParams, 
1269                                                           int order) const
1270 {
1271   QString aVaribaleName = (theParameters->length() > order) ? QString(theParameters[order].in()) : QString("");
1272   theParams.isVariable = !aVaribaleName.isEmpty();
1273   if(theParams.isVariable) 
1274     theParams.myValue = aVaribaleName;
1275
1276   return theParams.isVariable;
1277 }