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