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