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