Salome HOME
Merge multi-study removal branch.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Selection.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 // SMESH SMESHGUI_Selection
24 // File   : SMESHGUI_Selection.cxx
25 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S.
26 //
27
28 // SMESH includes
29 #include "SMESHGUI_Selection.h"
30
31 #include "SMESHGUI.h"
32 #include "SMESHGUI_ComputeDlg.h"
33 #include "SMESHGUI_ConvToQuadOp.h"
34 #include "SMESHGUI_GEOMGenUtils.h"
35 #include "SMESHGUI_Utils.h"
36 #include "SMESHGUI_VTKUtils.h"
37
38 #include <SMESH_Type.h>
39 #include <SMESH_Actor.h>
40 #include <SMESH_ScalarBarActor.h>
41
42 // SALOME GUI includes
43 #include <SalomeApp_Application.h>
44 #include <LightApp_VTKSelector.h>
45 #include <SVTK_ViewWindow.h>
46
47 // IDL includes
48 #include <SALOMEconfig.h>
49 #include CORBA_CLIENT_HEADER(SMESH_Gen)
50 #include CORBA_CLIENT_HEADER(SMESH_Mesh)
51 #include CORBA_CLIENT_HEADER(SMESH_Group)
52
53 //=======================================================================
54 //function : SMESHGUI_Selection
55 //purpose  : 
56 //=======================================================================
57 SMESHGUI_Selection::SMESHGUI_Selection()
58 : LightApp_Selection()
59 {
60 }
61
62 //=======================================================================
63 //function : ~SMESHGUI_Selection
64 //purpose  : 
65 //=======================================================================
66 SMESHGUI_Selection::~SMESHGUI_Selection()
67 {
68 }
69
70 //=======================================================================
71 //function : init
72 //purpose  : 
73 //=======================================================================
74 void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr )
75 {
76   LightApp_Selection::init( client, mgr );
77
78   if( mgr )
79   {
80     for( int i=0, n=count(); i<n; i++ ) {
81       myTypes.append( typeName( type( entry( i ) ) ) );
82       myControls.append( controlMode( i ) );
83     }
84   }
85 }
86
87 //=======================================================================
88 //function : processOwner
89 //purpose  : 
90 //=======================================================================
91 bool SMESHGUI_Selection::processOwner( const LightApp_DataOwner* ow )
92 {
93   const LightApp_SVTKDataOwner* owner =
94     dynamic_cast<const LightApp_SVTKDataOwner*> ( ow );
95   if( owner ) {
96     myActors.append( dynamic_cast<SMESH_Actor*>( owner->GetActor() ) );
97   }
98   else if ( ow ) { // SVTK selection disabled
99     QString entry = ow->entry();
100     myActors.append( SMESH::FindActorByEntry( entry.toStdString().c_str() ));
101   }
102   else {
103     myActors.append( 0 );
104   }
105   return true;
106 }
107
108 //=======================================================================
109 //function : parameter
110 //purpose  : 
111 //=======================================================================
112 QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
113 {
114   QVariant val;
115   if      ( p=="client" )               val = QVariant( LightApp_Selection::parameter( p ) );
116   else if ( p=="type" )                 val = QVariant( myTypes[ind] );
117   else if ( p=="hasActor" )             val = QVariant( getActor( ind ) != 0 );
118   else if ( p=="elemTypes" )            val = QVariant( elemTypes( ind, false ) );
119   else if ( p=="objElemTypes" )         val = QVariant( elemTypes( ind, true ) );
120   else if ( p=="isAutoColor" )          val = QVariant( isAutoColor( ind ) );
121   else if ( p=="numberOfNodes" )        val = QVariant( numberOfNodes( ind ) );
122   else if ( p=="dim" )                  val = QVariant( dim( ind ) );
123   else if ( p=="labeledTypes" )         val = QVariant( labeledTypes( ind ) );
124   else if ( p=="shrinkMode" )           val = QVariant( shrinkMode( ind ) );
125   else if ( p=="entityMode" )           val = QVariant( entityMode( ind ) );
126   else if ( p=="isNumFunctor" )         val = QVariant( isNumFunctor( ind ) );
127   else if ( p=="displayMode" )          val = QVariant( displayMode( ind ) );
128   else if ( p=="isComputable" )         val = QVariant( isComputable( ind ) );
129   else if ( p=="isPreComputable" )      val = QVariant( isPreComputable( ind ) );
130   else if ( p=="hasGeomReference" )     val = QVariant( hasGeomReference( ind ) );
131   else if ( p=="isEditableHyp" )        val = QVariant( isEditableHyp( ind ) );
132   else if ( p=="isImported" )           val = QVariant( isImported( ind ) );
133   else if ( p=="facesOrientationMode" ) val = QVariant( facesOrientationMode( ind ) );
134   else if ( p=="groupType" )            val = QVariant( groupType( ind ) );
135   else if ( p=="isQuadratic" )          val = QVariant( isQuadratic( ind ) );
136   else if ( p=="quadratic2DMode")       val = QVariant( quadratic2DMode( ind ) );
137   else if ( p=="isDistributionVisible") val = QVariant( isDistributionVisible( ind ) );
138   else if ( p=="isScalarBarVisible")    val = QVariant( isScalarBarVisible( ind ) );
139   else if ( p=="hasChildren")           val = QVariant( hasChildren( ind ) );
140   else if ( p=="nbChildren")            val = QVariant( nbChildren( ind ) );
141   else if ( p=="isContainer")           val = QVariant( isContainer( ind ) );
142   else if ( p=="guiState")              val = QVariant( guiState() );
143
144   if ( val.isValid() )
145     return val;
146   else
147     return LightApp_Selection::parameter( ind, p );
148 }
149
150 //=======================================================================
151 //function : parameter
152 //purpose  :
153 //=======================================================================
154 QVariant SMESHGUI_Selection::parameter( const QString& p ) const
155 {
156   QVariant val;
157   if ( p=="controlMode" ) val = QVariant( controlMode() );
158
159   if ( val.isValid() )
160     return val;
161   else
162     return LightApp_Selection::parameter( p );
163 }
164
165 //=======================================================================
166 //function : getVtkOwner
167 //purpose  :
168 //=======================================================================
169
170 SMESH_Actor* SMESHGUI_Selection::getActor( int ind ) const
171 {
172   if( ind >= 0 && ind < count() )
173     return myActors.isEmpty() ? 0 : myActors.at( ind );
174   else
175     return 0;
176 }
177
178 //=======================================================================
179 //function : elemTypes
180 //purpose  : may return {'Elem0d' 'Edge' 'Face' 'Volume' 'BallElem'} at most
181 //=======================================================================
182
183 QList<QVariant> SMESHGUI_Selection::elemTypes( int ind, bool fromObj ) const
184 {
185   QList<QVariant> types;
186   SMESH_Actor* actor = getActor( ind );
187   if ( actor ) {
188     TVisualObjPtr object = actor->GetObject();
189     if ( object ) {
190       if ( object->GetNbEntities( SMDSAbs_Edge ))      types.append( "Edge" );
191       if ( object->GetNbEntities( SMDSAbs_Face ))      types.append( "Face" );
192       if ( object->GetNbEntities( SMDSAbs_Volume ))    types.append( "Volume" );
193       if ( object->GetNbEntities( SMDSAbs_0DElement )) types.append( "Elem0d" );
194       if ( object->GetNbEntities( SMDSAbs_Ball ))      types.append( "BallElem" );
195     }
196   }
197   else if ( fromObj )
198   {
199     if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
200     {
201       _PTR(SObject) sobj = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
202       CORBA::Object_var obj = SMESH::SObjectToObject( sobj );
203       SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
204       if ( !CORBA::is_nil( idSrc ) )
205       {
206         SMESH::array_of_ElementType_var typeVar = idSrc->GetTypes();
207         for ( CORBA::ULong i = 0; i < typeVar->length(); ++i )
208           switch ( typeVar[i] ) {
209           case SMESH::EDGE:   types.append( "Edge" );     break;
210           case SMESH::FACE:   types.append( "Face" );     break;
211           case SMESH::VOLUME: types.append( "Volume" );   break;
212           case SMESH::ELEM0D: types.append( "Elem0d" );   break;
213           case SMESH::BALL:   types.append( "BallElem" ); break;
214           case SMESH::ALL:
215           case SMESH::NODE:
216           case SMESH::NB_ELEMENT_TYPES: break;
217           }
218       }
219     }
220   }
221   return types;
222 }
223
224 //=======================================================================
225 //function : labeledTypes
226 //purpose  : may return {'Point' 'Cell'} at most
227 //=======================================================================
228
229 QList<QVariant> SMESHGUI_Selection::labeledTypes( int ind ) const
230 {
231   QList<QVariant> types;
232   SMESH_Actor* actor = getActor( ind );
233   if ( actor ) {
234     if ( actor->GetPointsLabeled()) types.append( "Point" );
235     if ( actor->GetCellsLabeled())  types.append( "Cell" );
236   }
237   return types;
238 }
239
240 //=======================================================================
241 //function : displayMode
242 //purpose  : return SMESH_Actor::EReperesent
243 //=======================================================================
244
245 QString SMESHGUI_Selection::displayMode( int ind ) const
246 {
247   SMESH_Actor* actor = getActor( ind );
248   if ( actor ) {
249     switch( actor->GetRepresentation() ) {
250     case SMESH_Actor::eEdge:    return "eEdge";
251     case SMESH_Actor::eSurface: return "eSurface";
252     case SMESH_Actor::ePoint:   return "ePoint";
253     default: break;
254     }
255   }
256   return "Unknown";
257 }
258
259 //=======================================================================
260 //function : isQuadratic
261 //purpose  : return true if the mesh has quadratic/bi-quadratic type
262 //=======================================================================
263
264 bool SMESHGUI_Selection::isQuadratic( int ind ) const
265 {
266   _PTR(SObject) so = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
267   if ( !so )
268     return false;
269   SMESH::SMESH_IDSource_var idSource =  SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( so );
270   if ( idSource->_is_nil() )
271     return false;
272   SMESHGUI_ConvToQuadOp::MeshDestinationType meshTgtType = SMESHGUI_ConvToQuadOp::DestinationMesh( idSource );
273   if ( meshTgtType & SMESHGUI_ConvToQuadOp::Linear )
274     return true;
275   return false;
276 }
277
278 //=======================================================================
279 //function : quadratic2DMode
280 //purpose  : return SMESH_Actor::EQuadratic2DRepresentation
281 //=======================================================================
282 QString SMESHGUI_Selection::quadratic2DMode( int ind ) const
283 {
284   SMESH_Actor* actor = getActor( ind );
285   if ( actor ) {
286     switch( actor->GetQuadratic2DRepresentation() ) {
287     case SMESH_Actor::eLines: return "eLines";
288     case SMESH_Actor::eArcs:  return "eArcs";
289     default: break;
290     }
291   }
292   return "Unknown";
293 }
294
295 //=======================================================================
296 //function : isDistributionVisible
297 //purpose  : Visible/Invisible distribution of the ScalarBar Actor
298 //=======================================================================
299
300 bool SMESHGUI_Selection::isDistributionVisible(int ind) const {
301   SMESH_Actor* actor = getActor( ind );
302   return (actor && actor->GetScalarBarActor() && actor->GetScalarBarActor()->GetDistributionVisibility());
303
304
305 //=======================================================================
306 //function : isScalarBarVisible
307 //purpose  : Visible/Invisible Scalar Bar
308 //=======================================================================
309
310 bool SMESHGUI_Selection::isScalarBarVisible(int ind) const {
311   SMESH_Actor* actor = getActor( ind );
312   return (actor && actor->GetScalarBarActor() && actor->GetScalarBarActor()->GetVisibility());
313 }
314
315 //=======================================================================
316 //function : shrinkMode
317 //purpose  : return either 'IsSrunk', 'IsNotShrunk' or 'IsNotShrinkable'
318 //=======================================================================
319
320 QString SMESHGUI_Selection::shrinkMode( int ind ) const
321 {
322   SMESH_Actor* actor = getActor( ind );
323   if ( actor && actor->IsShrunkable() ) {
324     return actor->IsShrunk() ? "IsShrunk" : "IsNotShrunk";
325   }
326   return "IsNotShrinkable";
327 }
328
329 //=======================================================================
330 //function : entityMode
331 //purpose  : may return {'Elem0d' 'Edge' 'Face' 'Volume' 'BallElem' } at most
332 //=======================================================================
333
334 QList<QVariant> SMESHGUI_Selection::entityMode( int ind ) const
335 {
336   QList<QVariant> types;
337   SMESH_Actor* actor = getActor( ind );
338   if ( actor ) {
339     unsigned int aMode = actor->GetEntityMode();
340     if ( aMode & SMESH_Actor::eVolumes    ) types.append( "Volume" );
341     if ( aMode & SMESH_Actor::eFaces      ) types.append( "Face"   );
342     if ( aMode & SMESH_Actor::eEdges      ) types.append( "Edge"   );
343     if ( aMode & SMESH_Actor::e0DElements ) types.append( "Elem0d" );
344     if ( aMode & SMESH_Actor::eBallElem )   types.append( "BallElem" );
345   }
346   return types;
347 }
348
349 //=======================================================================
350 //function : controlMode
351 //purpose  : return SMESH_Actor::eControl
352 //=======================================================================
353
354 QString SMESHGUI_Selection::controlMode( int ind ) const
355 {
356   SMESH_Actor* actor = getActor( ind );
357   QString mode = "eNone";
358   if ( actor ) {
359     switch( actor->GetControlMode() ) {
360     case SMESH_Actor::eLength:                mode = "eLength";                break;
361     case SMESH_Actor::eLength2D:              mode = "eLength2D";              break;
362     case SMESH_Actor::eFreeEdges:             mode = "eFreeEdges";             break;
363     case SMESH_Actor::eFreeNodes:             mode = "eFreeNodes";             break;
364     case SMESH_Actor::eFreeBorders:           mode = "eFreeBorders";           break;
365     case SMESH_Actor::eFreeFaces:             mode = "eFreeFaces";             break;
366     case SMESH_Actor::eMultiConnection:       mode = "eMultiConnection";       break;
367     case SMESH_Actor::eMultiConnection2D:     mode = "eMultiConnection2D";     break;
368     case SMESH_Actor::eArea:                  mode = "eArea";                  break;
369     case SMESH_Actor::eVolume3D:              mode = "eVolume3D";              break;
370     case SMESH_Actor::eMaxElementLength2D:    mode = "eMaxElementLength2D";    break;
371     case SMESH_Actor::eMaxElementLength3D:    mode = "eMaxElementLength3D";    break;
372     case SMESH_Actor::eTaper:                 mode = "eTaper";                 break;
373     case SMESH_Actor::eAspectRatio:           mode = "eAspectRatio";           break;
374     case SMESH_Actor::eAspectRatio3D:         mode = "eAspectRatio3D";         break;
375     case SMESH_Actor::eMinimumAngle:          mode = "eMinimumAngle";          break;
376     case SMESH_Actor::eWarping:               mode = "eWarping";               break;
377     case SMESH_Actor::eSkew:                  mode = "eSkew";                  break;
378     case SMESH_Actor::eBareBorderFace:        mode = "eBareBorderFace";        break;
379     case SMESH_Actor::eBareBorderVolume:      mode = "eBareBorderVolume";      break;
380     case SMESH_Actor::eOverConstrainedFace:   mode = "eOverConstrainedFace";   break;
381     case SMESH_Actor::eOverConstrainedVolume: mode = "eOverConstrainedVolume"; break;
382     case SMESH_Actor::eCoincidentNodes:       mode = "eCoincidentNodes";       break;
383     case SMESH_Actor::eCoincidentElems1D:     mode = "eCoincidentElems1D";     break;
384     case SMESH_Actor::eCoincidentElems2D:     mode = "eCoincidentElems2D";     break;
385     case SMESH_Actor::eCoincidentElems3D:     mode = "eCoincidentElems3D";     break;
386     default:break;
387     }
388   }
389   return mode;
390 }
391
392 //=======================================================================
393 //function : controlMode
394 //purpose  : gets global control mode; return SMESH_Actor::eControl
395 //=======================================================================
396 QString SMESHGUI_Selection::controlMode() const
397 {
398   if( myControls.count() > 0 ) {
399     QString mode = myControls[0];
400     for( int ind = 1; ind < myControls.count(); ind++ ) {
401       if( mode != myControls[ind] )
402         return "eMixed"; // different controls used for different actors
403     }
404     return mode;
405   }
406   return "eNone";
407 }
408
409 bool SMESHGUI_Selection::isNumFunctor( int ind ) const
410 {
411   bool result = false;
412   SMESH_Actor* actor = getActor( ind );
413   if ( actor ) {
414     switch( actor->GetControlMode() ) {
415     case SMESH_Actor::eLength:
416     case SMESH_Actor::eLength2D:
417     case SMESH_Actor::eMultiConnection:
418     case SMESH_Actor::eMultiConnection2D:
419     case SMESH_Actor::eArea:
420     case SMESH_Actor::eVolume3D:
421     case SMESH_Actor::eMaxElementLength2D:
422     case SMESH_Actor::eMaxElementLength3D:
423     case SMESH_Actor::eTaper:
424     case SMESH_Actor::eAspectRatio:
425     case SMESH_Actor::eAspectRatio3D:
426     case SMESH_Actor::eMinimumAngle:
427     case SMESH_Actor::eWarping:
428     case SMESH_Actor::eSkew:
429       result = true;
430       break;
431     default:
432       break;
433     }
434   }
435   return result;
436 }
437
438 //=======================================================================
439 //function : facesOrientationMode
440 //purpose  : 
441 //=======================================================================
442
443 QString SMESHGUI_Selection::facesOrientationMode( int ind ) const
444 {
445   SMESH_Actor* actor = getActor( ind );
446   if ( actor ) {
447     return actor->GetFacesOriented() ? "IsOriented" : "IsNotOriented";
448   }
449   return "Unknown";
450 }
451
452 //=======================================================================
453 //function : isAutoColor
454 //purpose  : 
455 //=======================================================================
456
457 bool SMESHGUI_Selection::isAutoColor( int ind ) const
458 {
459   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
460   {
461     _PTR(SObject) sobj = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
462     CORBA::Object_var obj = SMESH::SObjectToObject( sobj );
463
464     if ( !CORBA::is_nil( obj ) ) {
465       SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
466       if ( !CORBA::is_nil( mesh ) )
467         return mesh->GetAutoColor();
468     }
469   }
470   return false;
471 }
472
473 //=======================================================================
474 //function : numberOfNodes
475 //purpose  : this method is actually used to check if an object is empty or not
476 //=======================================================================
477
478 int SMESHGUI_Selection::numberOfNodes( int ind ) const
479 {
480   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
481   {
482     _PTR(SObject) sobj = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
483     CORBA::Object_var obj = SMESH::SObjectToObject( sobj );
484
485     if ( !CORBA::is_nil( obj ) ) {
486       SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( obj );
487       if ( !CORBA::is_nil( mesh ) )
488         return mesh->NbNodes();
489       SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( obj );
490       if ( !CORBA::is_nil( aSubMeshObj ) )
491         return aSubMeshObj->GetNumberOfNodes(true);
492       SMESH::SMESH_GroupBase_var aGroupObj = SMESH::SMESH_GroupBase::_narrow( obj );
493       if ( !CORBA::is_nil( aGroupObj ) )
494         return aGroupObj->IsEmpty() ? 0 : 1; // aGroupObj->Size();
495     }
496   }
497   return 0;
498 }
499
500 //================================================================================
501 /*!
502  * \brief return dimension of elements of the selected object
503  *
504  *  \retval int - 0 for 0D elements, -1 for an empty object (the rest as usual)
505  */
506 //================================================================================
507
508 int SMESHGUI_Selection::dim( int ind ) const
509 {
510   int dim = -1;
511   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
512   {
513     _PTR(SObject) sobj = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
514     CORBA::Object_var obj = SMESH::SObjectToObject( sobj );
515
516     if ( !CORBA::is_nil( obj ) ) {
517       SMESH::SMESH_IDSource_var idSrc = SMESH::SMESH_IDSource::_narrow( obj );
518       if ( !CORBA::is_nil( idSrc ) )
519       {
520         SMESH::array_of_ElementType_var types = idSrc->GetTypes();
521         for ( size_t i = 0; i < types->length(); ++ i) {
522           switch ( types[i] ) {
523           case SMESH::EDGE  : dim = std::max( dim, 1 ); break;
524           case SMESH::FACE  : dim = std::max( dim, 2 ); break;
525           case SMESH::VOLUME: dim = std::max( dim, 3 ); break;
526           case SMESH::ELEM0D: dim = std::max( dim, 0 ); break;
527           case SMESH::BALL  : dim = std::max( dim, 0 ); break;
528           default: break;
529           }
530         }
531       }
532     }
533   }
534   return dim;
535 }
536
537 //=======================================================================
538 //function : isComputable
539 //purpose  : return true for a ready-to-compute mesh
540 //=======================================================================
541
542 bool SMESHGUI_Selection::isComputable( int ind ) const
543 {
544   if ( ind >= 0 && ind < myTypes.count() && ( myTypes[ind] == "Mesh" ||
545                                               myTypes[ind].startsWith("Mesh " )))
546   {
547     QMap<int,int> modeMap;
548     _PTR(SObject) meshSO = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
549
550     _PTR(SComponent) component = meshSO->GetFatherComponent();
551     if ( meshSO->Depth() - component->Depth() > 1 ) // sub-mesh, get a mesh
552       while ( meshSO->Depth() - component->Depth() > 1 )
553         meshSO = meshSO->GetFather();
554
555     SMESHGUI_PrecomputeOp::getAssignedAlgos( meshSO, modeMap );
556     return modeMap.size() > 0;
557   }
558   return false;
559 }
560
561 //=======================================================================
562 //function : isPreComputable
563 //purpose  : returns true for a mesh with algorithms
564 //=======================================================================
565
566 bool SMESHGUI_Selection::isPreComputable( int ind ) const
567 {
568   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Mesh" )
569   {
570     int maxDim = dim( ind );
571     if ( maxDim < 2 ) // we can preview 1D or 2D
572     {
573       QMap<int,int> modeMap;
574       _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
575       SMESHGUI_PrecomputeOp::getAssignedAlgos( pMesh, modeMap );
576       if ( modeMap.size() > 1 )
577         return (( modeMap.contains( SMESH::DIM_3D )) ||
578                 ( modeMap.contains( SMESH::DIM_2D ) && maxDim < 1 ));
579     }
580   }
581   return false;
582 }
583
584 //=======================================================================
585 //function : hasGeomReference
586 //purpose  : returns true for a mesh or sub-mesh on geometry
587 //=======================================================================
588
589 bool SMESHGUI_Selection::hasGeomReference( int ind ) const
590 {
591   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
592   {
593     _PTR(SObject) so = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
594     GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
595     return !shape->_is_nil();
596   }
597   return false;
598 }
599
600 //=======================================================================
601 //function : isEditableHyp
602 //purpose  : 
603 //=======================================================================
604
605 bool SMESHGUI_Selection::isEditableHyp( int ind ) const
606 {
607   bool isEditable = true;
608   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Hypothesis" )
609   {
610     _PTR(SObject) so = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
611     SMESH::SMESH_Hypothesis_var hyp = SMESH::SObjectToInterface<SMESH::SMESH_Hypothesis>( so );
612     if ( !hyp->_is_nil() )
613     {
614       isEditable = hyp->HasParameters();
615     }
616   }
617   return isEditable;
618 }
619
620 //=======================================================================
621 //function : isVisible
622 //purpose  : 
623 //=======================================================================
624
625 bool SMESHGUI_Selection::isVisible( int ind ) const
626 {
627   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
628   {
629     SMESH_Actor* actor = SMESH::FindActorByEntry( entry( ind ).toLatin1().data() );
630     if ( actor && actor->hasIO() ) {
631       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() )
632         return aViewWindow->isVisible( actor->getIO() );
633     }
634   }
635   return false;
636 }
637
638 //=======================================================================
639 //function : hasChildren
640 //purpose  : 
641 //=======================================================================
642
643 bool SMESHGUI_Selection::hasChildren( int ind ) const
644 {
645   if ( ind >= 0 )
646   {
647     _PTR(SObject) sobj = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().data() );
648     if ( sobj ) 
649       return SMESH::getStudy()->GetUseCaseBuilder()->HasChildren( sobj );
650   }
651   return false;
652 }
653
654 //=======================================================================
655 //function : hasChildren
656 //purpose  : 
657 //=======================================================================
658
659 int SMESHGUI_Selection::nbChildren( int ind ) const
660 {
661   int nb = 0;
662   if ( ind >= 0 )
663   {
664     _PTR(Study) study = SMESH::getStudy();
665     _PTR(SObject) sobj = study->FindObjectID( entry( ind ).toLatin1().data() );
666     if ( sobj && study->GetUseCaseBuilder()->IsUseCaseNode( sobj ) ) {
667       _PTR(UseCaseIterator) it = study->GetUseCaseBuilder()->GetUseCaseIterator( sobj );
668       for ( it->Init( false ); it->More(); it->Next() ) nb++;
669     }
670   }
671   return nb;
672 }
673
674 //=======================================================================
675 //function : isContainer
676 //purpose  : 
677 //=======================================================================
678
679 bool SMESHGUI_Selection::isContainer( int ind ) const
680 {
681   return ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Unknown";
682 }
683
684 //=======================================================================
685 //function : type
686 //purpose  : 
687 //=======================================================================
688
689 int SMESHGUI_Selection::type( const QString& entry )
690 {
691   int res = -1;
692   _PTR(SObject) obj = SalomeApp_Application::getStudy()->FindObjectID( entry.toLatin1().data() );
693   if ( obj ) {
694     _PTR(SObject) ref;
695     if ( obj->ReferencedObject( ref ) )
696       obj = ref;
697
698     _PTR(SObject) objFather = obj->GetFather();
699     _PTR(SComponent) objComponent = obj->GetFatherComponent();
700
701     if ( objComponent->ComponentDataType() == "SMESH" ) {
702       if ( objComponent->GetIOR() == obj->GetIOR() ) {
703         res = SMESH::COMPONENT;
704       }
705       else {
706         int aLevel = obj->Depth() - objComponent->Depth(),
707           aFTag = objFather->Tag(),
708           anOTag = obj->Tag();
709
710         switch ( aLevel )
711         {
712         case 1:
713           if ( anOTag >= SMESH::Tag_FirstMeshRoot )
714             res = SMESH::MESH;
715           break;
716         case 2:
717           switch ( aFTag )
718           {
719           case SMESH::Tag_HypothesisRoot: res = SMESH::HYPOTHESIS; break;
720           case SMESH::Tag_AlgorithmsRoot: res = SMESH::ALGORITHM;  break;
721           default: break;
722           }
723           break;
724         case 3:
725           switch ( aFTag )
726           {
727           case SMESH::Tag_SubMeshOnVertex:   res = SMESH::SUBMESH_VERTEX;   break;
728           case SMESH::Tag_SubMeshOnEdge:     res = SMESH::SUBMESH_EDGE;     break;
729           case SMESH::Tag_SubMeshOnFace:     res = SMESH::SUBMESH_FACE;     break;
730           case SMESH::Tag_SubMeshOnSolid:    res = SMESH::SUBMESH_SOLID;    break;
731           case SMESH::Tag_SubMeshOnCompound: res = SMESH::SUBMESH_COMPOUND; break;
732           default:
733             if ( aFTag >= SMESH::Tag_FirstGroup) res = SMESH::GROUP;
734             else                                 res = SMESH::SUBMESH;
735             break;
736           }
737           break;
738         }
739       }
740     }
741   }
742   return res;
743 }
744
745 //=======================================================================
746 //function : typeName
747 //purpose  : 
748 //=======================================================================
749
750 QString SMESHGUI_Selection::typeName( const int t )
751 {
752   QString res = "Unknown";
753   switch( t )
754   {
755   case SMESH::HYPOTHESIS:
756     res = "Hypothesis"; break;
757   case SMESH::ALGORITHM:
758     res = "Algorithm"; break;
759   case SMESH::MESH:
760     res = "Mesh"; break;
761   case SMESH::SUBMESH:
762     res = "SubMesh"; break;
763   case SMESH::MESHorSUBMESH:
764     res = "Mesh or submesh"; break;
765   case SMESH::SUBMESH_VERTEX:
766     res = "Mesh vertex"; break;
767   case SMESH::SUBMESH_EDGE:
768     res = "Mesh edge"; break;
769   case SMESH::SUBMESH_FACE:
770     res = "Mesh face"; break;
771   case SMESH::SUBMESH_SOLID:
772     res = "Mesh solid"; break;
773   case SMESH::SUBMESH_COMPOUND:
774     res = "Mesh compound"; break;
775   case SMESH::GROUP:
776     res = "Group"; break;
777   case SMESH::COMPONENT:
778     res = "Component"; break;
779   default:
780      break;
781   }
782   return res;
783 }
784
785 bool SMESHGUI_Selection::isImported( const int ind ) const
786 {
787   bool res = false;
788   _PTR(SObject) sobj = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().constData() );
789   if ( sobj )
790   {
791     SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( sobj ) );
792     if( !aMesh->_is_nil() )
793     {
794       SMESH::MedFileInfo_var inf = aMesh->GetMEDFileInfo();
795       res = strlen( (char*)inf->fileName ) > 0;
796     }
797   }
798   return res;
799 }
800
801 //=======================================================================
802 //function : guiState
803 //purpose  : 
804 //=======================================================================
805
806 int SMESHGUI_Selection::guiState()
807 {
808   return SMESHGUI::GetSMESHGUI() ? SMESHGUI::GetSMESHGUI()->GetState() : -1;
809 }
810
811 //=======================================================================
812 //function : groupType
813 //purpose  : 
814 //=======================================================================
815
816 QString SMESHGUI_Selection::groupType( int ind ) const
817 {
818   _PTR(SObject) sobj = SMESH::getStudy()->FindObjectID( entry( ind ).toLatin1().constData() );
819   if ( sobj )
820   {
821     SMESH::SMESH_Group_var g = SMESH::SObjectToInterface<SMESH::SMESH_Group>( sobj );
822     if ( !CORBA::is_nil( g ) )
823       return "Group";
824     SMESH::SMESH_GroupOnGeom_var gog = SMESH::SObjectToInterface<SMESH::SMESH_GroupOnGeom>( sobj );
825     if( !CORBA::is_nil( gog ) )
826       return "GroupOnGeom";
827     SMESH::SMESH_GroupOnFilter_var gof = SMESH::SObjectToInterface<SMESH::SMESH_GroupOnFilter>( sobj );
828     if ( !CORBA::is_nil( gof ) )
829       return "GroupOnFilter";
830   }
831   return "";
832 }