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