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