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