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