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