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