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