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