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