Salome HOME
INT PAL 0053058: '2D Quadratic' item is shown in VTK context menu for non-quadratic...
[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 #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::MeshDestinationType::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   {
523     QMap<int,int> modeMap;
524     _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
525     SMESHGUI_PrecomputeOp::getAssignedAlgos( so, modeMap );
526     return modeMap.size() > 0;
527   }
528   return false;
529 }
530
531 //=======================================================================
532 //function : isPreComputable
533 //purpose  : returns true for a mesh with algorithms
534 //=======================================================================
535
536 bool SMESHGUI_Selection::isPreComputable( int ind ) const
537 {
538   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Mesh" )
539   {
540     int maxDim = dim( ind );
541     if ( maxDim < 2 ) // we can preview 1D or 2D
542     {
543       QMap<int,int> modeMap;
544       _PTR(SObject) pMesh = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
545       SMESHGUI_PrecomputeOp::getAssignedAlgos( pMesh, modeMap );
546       if ( modeMap.size() > 1 )
547         return (( modeMap.contains( SMESH::DIM_3D )) ||
548                 ( modeMap.contains( SMESH::DIM_2D ) && maxDim < 1 ));
549     }
550   }
551   return false;
552 }
553
554 //=======================================================================
555 //function : hasGeomReference
556 //purpose  : returns true for a mesh or sub-mesh on geometry
557 //=======================================================================
558
559 bool SMESHGUI_Selection::hasGeomReference( int ind ) const
560 {
561   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
562   {
563     _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
564     GEOM::GEOM_Object_var shape = SMESH::GetShapeOnMeshOrSubMesh( so );
565     return !shape->_is_nil();
566   }
567   return false;
568 }
569
570 //=======================================================================
571 //function : isEditableHyp
572 //purpose  : 
573 //=======================================================================
574
575 bool SMESHGUI_Selection::isEditableHyp( int ind ) const
576 {
577   bool isEditable = true;
578   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Hypothesis" )
579   {
580     _PTR(SObject) so = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
581     SMESH::SMESH_Hypothesis_var hyp = SMESH::SObjectToInterface<SMESH::SMESH_Hypothesis>( so );
582     if ( !hyp->_is_nil() )
583     {
584       isEditable = hyp->HasParameters();
585     }
586   }
587   return isEditable;
588 }
589
590 //=======================================================================
591 //function : isVisible
592 //purpose  : 
593 //=======================================================================
594
595 bool SMESHGUI_Selection::isVisible( int ind ) const
596 {
597   if ( ind >= 0 && ind < myTypes.count() && myTypes[ind] != "Unknown" )
598   {
599     SMESH_Actor* actor = SMESH::FindActorByEntry( entry( ind ).toLatin1().data() );
600     if ( actor && actor->hasIO() ) {
601       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() )
602         return aViewWindow->isVisible( actor->getIO() );
603     }
604   }
605   return false;
606 }
607
608 //=======================================================================
609 //function : hasChildren
610 //purpose  : 
611 //=======================================================================
612
613 bool SMESHGUI_Selection::hasChildren( int ind ) const
614 {
615   if ( ind >= 0 )
616   {
617     _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
618     if ( sobj ) 
619       return SMESH::GetActiveStudyDocument()->GetUseCaseBuilder()->HasChildren( sobj );
620   }
621   return false;
622 }
623
624 //=======================================================================
625 //function : hasChildren
626 //purpose  : 
627 //=======================================================================
628
629 int SMESHGUI_Selection::nbChildren( int ind ) const
630 {
631   int nb = 0;
632   if ( ind >= 0 )
633   {
634     _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().data() );
635     if ( sobj && sobj->GetStudy()->GetUseCaseBuilder()->IsUseCaseNode( sobj ) ) {
636       _PTR(UseCaseIterator) it = sobj->GetStudy()->GetUseCaseBuilder()->GetUseCaseIterator( sobj ); 
637       for ( it->Init( false ); it->More(); it->Next() ) nb++;
638     }
639   }
640   return nb;
641 }
642
643 //=======================================================================
644 //function : isContainer
645 //purpose  : 
646 //=======================================================================
647
648 bool SMESHGUI_Selection::isContainer( int ind ) const
649 {
650   return ind >= 0 && ind < myTypes.count() && myTypes[ind] == "Unknown";
651 }
652
653 //=======================================================================
654 //function : type
655 //purpose  : 
656 //=======================================================================
657
658 int SMESHGUI_Selection::type( const QString& entry, _PTR(Study) study )
659 {
660   int res = -1;
661   _PTR(SObject) obj = study->FindObjectID( entry.toLatin1().data() );
662   if ( obj ) {
663     _PTR(SObject) ref;
664     if ( obj->ReferencedObject( ref ) )
665       obj = ref;
666
667     _PTR(SObject) objFather = obj->GetFather();
668     _PTR(SComponent) objComponent = obj->GetFatherComponent();
669
670     if ( objComponent->ComponentDataType() == "SMESH" ) {
671       if ( objComponent->GetIOR() == obj->GetIOR() ) {
672         res = SMESH::COMPONENT;
673       }
674       else {
675         int aLevel = obj->Depth() - objComponent->Depth(),
676           aFTag = objFather->Tag(),
677           anOTag = obj->Tag();
678
679         switch ( aLevel )
680         {
681         case 1:
682           if ( anOTag >= SMESH::Tag_FirstMeshRoot )
683             res = SMESH::MESH;
684           break;
685         case 2:
686           switch ( aFTag )
687           {
688           case SMESH::Tag_HypothesisRoot: res = SMESH::HYPOTHESIS; break;
689           case SMESH::Tag_AlgorithmsRoot: res = SMESH::ALGORITHM;  break;
690           default: break;
691           }
692           break;
693         case 3:
694           switch ( aFTag )
695           {
696           case SMESH::Tag_SubMeshOnVertex:   res = SMESH::SUBMESH_VERTEX;   break;
697           case SMESH::Tag_SubMeshOnEdge:     res = SMESH::SUBMESH_EDGE;     break;
698           case SMESH::Tag_SubMeshOnFace:     res = SMESH::SUBMESH_FACE;     break;
699           case SMESH::Tag_SubMeshOnSolid:    res = SMESH::SUBMESH_SOLID;    break;
700           case SMESH::Tag_SubMeshOnCompound: res = SMESH::SUBMESH_COMPOUND; break;
701           default:
702             if ( aFTag >= SMESH::Tag_FirstGroup) res = SMESH::GROUP;
703             else                                 res = SMESH::SUBMESH;
704             break;
705           }
706           break;
707         }
708       }
709     }
710   }
711   return res;
712 }
713
714 //=======================================================================
715 //function : typeName
716 //purpose  : 
717 //=======================================================================
718
719 QString SMESHGUI_Selection::typeName( const int t )
720 {
721   QString res = "Unknown";
722   switch( t )
723   {
724   case SMESH::HYPOTHESIS:
725     res = "Hypothesis"; break;
726   case SMESH::ALGORITHM:
727     res = "Algorithm"; break;
728   case SMESH::MESH:
729     res = "Mesh"; break;
730   case SMESH::SUBMESH:
731     res = "SubMesh"; break;
732   case SMESH::MESHorSUBMESH:
733     res = "Mesh or submesh"; break;
734   case SMESH::SUBMESH_VERTEX:
735     res = "Mesh vertex"; break;
736   case SMESH::SUBMESH_EDGE:
737     res = "Mesh edge"; break;
738   case SMESH::SUBMESH_FACE:
739     res = "Mesh face"; break;
740   case SMESH::SUBMESH_SOLID:
741     res = "Mesh solid"; break;
742   case SMESH::SUBMESH_COMPOUND:
743     res = "Mesh compound"; break;
744   case SMESH::GROUP:
745     res = "Group"; break;
746   case SMESH::COMPONENT:
747     res = "Component"; break;
748   default:
749      break;
750   }
751   return res;
752 }
753
754 bool SMESHGUI_Selection::isImported( const int ind ) const
755 {
756   bool res = false;
757   _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().constData() );
758   if ( sobj )
759   {
760     SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( sobj ) );
761     if( !aMesh->_is_nil() )
762     {
763       SMESH::MedFileInfo_var inf = aMesh->GetMEDFileInfo();
764       res = strlen( (char*)inf->fileName ) > 0;
765     }
766   }
767   return res;
768 }
769
770 //=======================================================================
771 //function : groupType
772 //purpose  : 
773 //=======================================================================
774
775 QString SMESHGUI_Selection::groupType( int ind ) const
776 {
777   _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID( entry( ind ).toLatin1().constData() );
778   if ( sobj )
779   {
780     SMESH::SMESH_Group_var g = SMESH::SObjectToInterface<SMESH::SMESH_Group>( sobj );
781     if ( !CORBA::is_nil( g ) )
782       return "Group";
783     SMESH::SMESH_GroupOnGeom_var gog = SMESH::SObjectToInterface<SMESH::SMESH_GroupOnGeom>( sobj );
784     if( !CORBA::is_nil( gog ) )
785       return "GroupOnGeom";
786     SMESH::SMESH_GroupOnFilter_var gof = SMESH::SObjectToInterface<SMESH::SMESH_GroupOnFilter>( sobj );
787     if ( !CORBA::is_nil( gof ) )
788       return "GroupOnFilter";
789   }
790   return "";
791 }