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