Salome HOME
0023552: Unable to use the contextual menu of Object Browser window
[modules/geom.git] / src / GEOMGUI / GEOMGUI_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 // File   : GEOMGUI_Selection.cxx
24 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S. (alexander.solovyov@opencascade.com)
25
26 #include "GEOMGUI_Selection.h"
27 #include <GEOMGUI_DimensionProperty.h>
28 #include <GEOMGUI_AnnotationAttrs.h>
29 #include <GEOMGUI_AnnotationMgr.h>
30
31 #include "GeometryGUI.h"
32 #include "GEOM_Displayer.h"
33
34 #include "Material_Model.h"
35
36 #include <GEOM_Constants.h>
37
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_Study.h>
40
41 #include "LightApp_DataOwner.h"
42
43 #include <SUIT_Session.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ViewWindow.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_ResourceMgr.h>
48
49 #include <SALOME_Prs.h>
50 #include <SALOME_InteractiveObject.hxx>
51
52 #include <SOCC_Prs.h>
53 #include <SVTK_Prs.h>
54 #include <SALOME_Actor.h>
55 #include <GEOM_Actor.h>
56
57 #include <OCCViewer_ViewModel.h>
58 #include <SVTK_ViewModel.h>
59
60 #include <GEOMImpl_Types.hxx>
61
62 #include <GEOM_AISShape.hxx>
63 #include <GEOM_VTKPropertyMaterial.hxx>
64
65 // OCCT Includes
66 #include <AIS.hxx>
67 #include <AIS_InteractiveObject.hxx>
68 #include <AIS_ListOfInteractive.hxx>
69 #include <AIS_GraphicTool.hxx>
70 #include <Aspect_TypeOfFacingModel.hxx>
71 #include <Prs3d_ShadingAspect.hxx>
72 #include<Graphic3d_MaterialAspect.hxx>
73
74 // VTK Includes
75 #include <vtkActorCollection.h>
76
77 #define OCC_DISPLAY_MODE_TO_STRING( str, dm ) { \
78     if ( dm == AIS_WireFrame ) \
79       str = QString( "Wireframe" ); \
80     else if ( dm == AIS_Shaded )    \
81       str = QString( "Shading" ); \
82     else if ( dm == GEOM_AISShape::ShadingWithEdges )    \
83       str = QString( "ShadingWithEdges" ); \
84     else if ( dm == GEOM_AISShape::TexturedShape )    \
85       str = QString( "Texture" ); \
86     else \
87       str = QString(); }
88
89 #define USE_VISUAL_PROP_MAP
90
91 #ifdef USE_VISUAL_PROP_MAP
92   #define VTK_DISPLAY_MODE_TO_STRING( str, dm ) { \
93       if ( dm == 0 ) \
94         str = QString( "Wireframe" ); \
95       else if ( dm == 1 )    \
96         str = QString( "Shading" ); \
97       else if ( dm == 2 )    \
98         str = QString( "ShadingWithEdges" ); \
99       else \
100         str = QString(); }
101 #else
102   #define VTK_DISPLAY_MODE_TO_STRING( str, dm ) { \
103       if ( dm == 0 ) \
104         str = QString( "Wireframe" ); \
105       else if ( dm == 1 )    \
106         str = QString( "Shading" ); \
107       else if ( dm == 3 )    \
108         str = QString( "ShadingWithEdges" ); \
109       else \
110         str = QString(); }
111 #endif
112
113 GEOMGUI_Selection::GEOMGUI_Selection()
114 : LightApp_Selection()
115 {
116 }
117
118 GEOMGUI_Selection::~GEOMGUI_Selection()
119 {
120 }
121
122 void GEOMGUI_Selection::init( const QString& context, LightApp_SelectionMgr* selMgr )
123 {
124   LightApp_Selection::init( context, selMgr );
125
126   myObjects.resize( count() );
127
128   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
129   if ( appStudy ) {
130     _PTR(Study) study = appStudy->studyDS();
131     for ( int idx = 0; idx < count(); idx++ ) {
132       QString anEntry = entry( idx );
133       if ( study && !anEntry.isEmpty() ) {
134         _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
135         if ( aSO ) {
136           CORBA::Object_var varObj = GeometryGUI::ClientSObjectToObject( aSO );
137           myObjects[idx] = GEOM::GEOM_BaseObject::_narrow( varObj );
138         }
139       }
140     }
141   }
142 }
143
144 //QVariant GEOMGUI_Selection::contextParameter( const QString& p ) const
145 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
146 {
147   QVariant v;
148   if ( p == "isOCC" )
149     v = activeViewType() == OCCViewer_Viewer::Type();
150   else if ( p == "selectionmode" )
151     v = selectionMode();
152   else if ( p == "hasImported" )
153     v = hasImported();
154   else if ( p == "allImported" )
155     v = allImported();
156   else if (p == "annotationsCount")
157     v = annotationsCount();
158   else
159     v = LightApp_Selection::parameter( p );
160   return v;
161 }
162
163 //QVariant GEOMGUI_Selection::objectParameter( const int idx, const QString& p ) const
164 QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const
165 {
166   QVariant v;
167   if ( p == "type" )
168     v = typeName( idx );
169   else if ( p == "typeid" )
170     v = typeId( idx );
171   else if ( p == "displaymode" )
172     v = displayMode( idx );
173   else if ( p == "isAutoColor" )
174     v = isAutoColor( idx );
175   else if ( p == "isVectorsMode" )
176     v = isVectorsMode( idx );
177   else if ( p == "isVerticesMode" )
178     v = isVerticesMode( idx );
179   else if ( p == "isNameMode" )
180     v = isNameMode( idx );
181   else if ( p == "topLevel" )
182     v = topLevel( idx );
183   else if ( p == "autoBringToFront" )
184     v = autoBringToFront( idx );
185   else if ( p == "hasChildren" )
186     v = hasChildren( idx );
187   else if ( p == "nbChildren" )
188     v = nbChildren(idx);
189   else if ( p == "hasConcealedChildren" )
190     v = hasConcealedChildren( idx );
191   else if ( p == "hasDisclosedChildren" )
192     v = hasDisclosedChildren( idx );
193   else if ( p == "compoundOfVertices" )
194     v = compoundOfVertices( idx );
195   else if ( p == "imported" )
196     v = isImported( idx );
197   else if ( p == "isPhysicalMaterial" )
198     v = isPhysicalMaterial(idx);
199   else if ( p == "isFolder" )
200     v = isFolder(idx);
201   else if ( p == "hasHiddenDimensions" )
202     v = hasHiddenDimensions(idx);
203   else if ( p == "hasVisibleDimensions" )
204     v = hasVisibleDimensions(idx);
205   else if ( p == "hasHiddenAnnotations" )
206     v = hasHiddenAnnotations(idx);
207   else if ( p == "hasVisibleAnnotations" )
208     v = hasVisibleAnnotations(idx);
209   else if ( p == "matMenu" )
210     v = SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "predef_materials", false );
211   else
212     v = LightApp_Selection::parameter( idx, p );
213
214   return v;
215 }
216
217 // the method to skip temporary objects from selection (called from LightApp)
218 bool GEOMGUI_Selection::processOwner( const LightApp_DataOwner* theOwner )
219 {
220   if ( theOwner->entry().contains( GEOMGUI_AnnotationMgr::GetEntrySeparator() ) ) {
221     myAnnotationEntries.append( theOwner->entry() );
222   }
223   return !theOwner->entry().contains("_");
224 }
225
226 QString GEOMGUI_Selection::typeName( const int index ) const
227 {
228   if ( isComponent( index ) )
229     return "Component";
230   if ( isFolder( index ) )
231     return "Folder";
232
233   static QString aGroup( "Group" );
234   static QString aShape( "Shape" );
235   static QString aField( "Field" );
236   static QString aFieldStep( "FieldStep" );
237   static QString anUnknown( "Unknown" );
238
239   GEOM::GEOM_BaseObject_var anObj = getBaseObject( index );
240   if ( !CORBA::is_nil( anObj ) ) {
241     const int aGeomType = anObj->GetType();
242     switch ( aGeomType ) {
243     case GEOM_GROUP     : return aGroup;
244     case GEOM_FIELD     : return aField;
245     case GEOM_FIELD_STEP: return aFieldStep;
246     default             : return aShape;
247     }
248   }
249   return anUnknown;
250 }
251
252 int GEOMGUI_Selection::typeId( const int index ) const
253 {
254   int aType = -1;
255   GEOM::GEOM_Object_var anObj = getObject( index );
256   if ( !CORBA::is_nil( anObj ) )
257     aType = (int)anObj->GetShapeType();
258   return aType;
259 }
260
261 bool GEOMGUI_Selection::isVisible( const int index ) const
262 {
263 #ifdef USE_VISUAL_PROP_MAP
264   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Visibility ) );
265   if ( v.canConvert( QVariant::Bool ) )
266     return v.toBool();
267 #endif
268
269   bool res = false;
270
271   GEOM::GEOM_Object_var obj = getObject( index );
272   SALOME_View* view = GEOM_Displayer::GetActiveView();
273   if ( !CORBA::is_nil( obj ) && view ) {
274     Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toUtf8().constData(), "GEOM", "TEMP_IO" );
275     res = view->isVisible( io );
276   }
277
278   return res;
279 }
280
281 bool GEOMGUI_Selection::isAutoColor( const int index ) const
282 {
283   GEOM::GEOM_Object_var obj = getObject( index );
284   if ( !CORBA::is_nil( obj ) )
285     return obj->GetAutoColor();
286   return false;
287 }
288
289 bool GEOMGUI_Selection::isImported( const int index ) const
290 {
291   GEOM::GEOM_Object_var obj = getObject( index );
292   if ( !CORBA::is_nil( obj ) )
293     return obj->GetType() == GEOM_IMPORT;
294   return false;
295 }
296
297 bool GEOMGUI_Selection::hasImported() const
298 {
299   bool res = false;
300   for ( int i = 0; i < count() && !res; i++ )
301     res = isImported( i );
302   return res;
303 }
304
305 bool GEOMGUI_Selection::allImported() const
306 {
307   bool res = true;
308   for ( int i = 0; i < count() && res; i++ )
309     res = isImported( i );
310   return res;
311 }
312
313 QVariant GEOMGUI_Selection::visibleProperty( const QString& entry, const QString& propName ) const
314 {
315   QVariant v;
316   LightApp_Study* aStudy = study();
317   if ( aStudy ) {
318     LightApp_Application* anApp = ::qobject_cast<LightApp_Application*>( aStudy->application() );
319     if ( anApp && anApp->activeViewManager() ) {
320       int id = anApp->activeViewManager()->getGlobalId();
321       v = aStudy->getObjectProperty( id, entry, propName, QVariant() );
322     }
323   }
324   return v;
325 }
326
327 QString GEOMGUI_Selection::displayMode( const int index ) const
328 {
329   QString res;
330   QString viewType = activeViewType();
331   
332 #ifdef USE_VISUAL_PROP_MAP
333   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::DisplayMode ) );
334   if ( v.canConvert( QVariant::Int ) ) {
335     int dm = v.toInt();
336     if ( viewType == OCCViewer_Viewer::Type() ) {
337       OCC_DISPLAY_MODE_TO_STRING( res, dm );
338     } else if ( viewType == SVTK_Viewer::Type() ) {
339       VTK_DISPLAY_MODE_TO_STRING( res, dm );
340     }
341     return res;
342   }
343 #endif
344
345   SALOME_View* view = GEOM_Displayer::GetActiveView();
346   if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
347     SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
348     if ( prs ) {
349       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
350         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
351         AIS_ListOfInteractive lst;
352         occPrs->GetObjects( lst );
353         if ( lst.Extent() ) {
354           Handle(AIS_InteractiveObject) io = lst.First();
355           if ( !io.IsNull() ) {
356             int dm;
357             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
358             if(!aSh.IsNull()) {
359               dm = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
360             } else {
361               dm = io->DisplayMode();
362             }
363             OCC_DISPLAY_MODE_TO_STRING( res, dm );
364             if ( res.isEmpty() ) { // return default display mode of AIS_InteractiveContext
365               OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*)SUIT_Session::session()->activeApplication()->
366                 desktop()->activeWindow()->getViewManager()->getViewModel();
367               Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
368               dm = ic->DisplayMode();
369               OCC_DISPLAY_MODE_TO_STRING( res, dm );
370             }
371           }
372         }
373       }
374       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
375         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
376         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
377         if ( lst ) {
378           lst->InitTraversal();
379           vtkActor* actor = lst->GetNextActor();
380           if ( actor ) {
381             SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
382             if ( salActor ) {
383               int dm = salActor->getDisplayMode();
384               VTK_DISPLAY_MODE_TO_STRING( res, dm );
385             } // if ( salome actor )
386           } // if ( actor )
387         } // if ( lst == vtkPrs->GetObjects() )
388       } // if VTK
389     }
390   }
391
392   return res;
393 }
394
395 bool GEOMGUI_Selection::autoBringToFront( const int /*index*/ ) const
396 {
397   return SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front", false );
398 }
399
400 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
401 {
402 #ifdef USE_VISUAL_PROP_MAP
403   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::EdgesDirection ) );
404   if ( v.canConvert( QVariant::Bool ) )
405     return v.toBool();
406 #endif
407
408   bool res = false;
409   
410   SALOME_View* view = GEOM_Displayer::GetActiveView();
411   QString viewType = activeViewType();
412   if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
413     SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
414     if ( prs ) {
415       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
416         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
417         AIS_ListOfInteractive lst;
418         occPrs->GetObjects( lst );
419         if ( lst.Extent() ) {
420           Handle(AIS_InteractiveObject) io = lst.First();
421           if ( !io.IsNull() ) {
422             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
423             if ( !aSh.IsNull() )
424               res = aSh->isShowVectors();
425           }
426         }
427       }
428       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
429         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
430         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
431         if ( lst ) {
432           lst->InitTraversal();
433           vtkActor* actor = lst->GetNextActor();
434           if ( actor ) {
435             GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
436             if ( aGeomActor )
437               res = aGeomActor->GetVectorMode();
438             }
439         }
440       }
441     }
442   }
443
444   return res;
445 }
446
447 bool GEOMGUI_Selection::isVerticesMode( const int index ) const
448 {
449 #ifdef USE_VISUAL_PROP_MAP
450   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Vertices ) );
451   if ( v.canConvert( QVariant::Bool ) )
452     return v.toBool();
453 #endif
454
455   bool res = false;
456   
457   SALOME_View* view = GEOM_Displayer::GetActiveView();
458   QString viewType = activeViewType();
459   if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
460     SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
461     if ( prs ) {
462       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
463         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
464         AIS_ListOfInteractive lst;
465         occPrs->GetObjects( lst );
466         if ( lst.Extent() ) {
467           Handle(AIS_InteractiveObject) io = lst.First();
468           if ( !io.IsNull() ) {
469             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
470             if ( !aSh.IsNull() )
471               res = aSh->isShowVertices();
472           }
473         }
474       }
475       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
476         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
477         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
478         if ( lst ) {
479           lst->InitTraversal();
480           vtkActor* actor = lst->GetNextActor();
481           if ( actor ) {
482             GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
483             if ( aGeomActor )
484               res = aGeomActor->GetVerticesMode();
485             }
486         }
487       }
488     }
489   }
490
491   return res;
492 }
493
494 bool GEOMGUI_Selection::isNameMode( const int index ) const
495 {
496 #ifdef USE_VISUAL_PROP_MAP
497   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::ShowName ) );
498   if ( v.canConvert( QVariant::Bool ) )
499     return v.toBool();
500 #endif
501
502   bool res = false;
503
504   SALOME_View* view = GEOM_Displayer::GetActiveView();
505   QString viewType = activeViewType();
506   if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
507     SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
508     if ( prs ) {
509       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
510         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
511         AIS_ListOfInteractive lst;
512         occPrs->GetObjects( lst );
513         if ( lst.Extent() ) {
514           Handle(AIS_InteractiveObject) io = lst.First();
515           if ( !io.IsNull() ) {
516             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
517             if ( !aSh.IsNull() )
518               res = aSh->isShowName();
519           }
520         }
521       }
522       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
523         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
524         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
525         if ( lst ) {
526           lst->InitTraversal();
527           vtkActor* actor = lst->GetNextActor();
528           if ( actor ) {
529             GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
530             if ( aGeomActor )
531               res = aGeomActor->GetNameMode();
532             }
533         }
534       }
535     }
536   }
537
538   return res;
539 }
540
541 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
542 {
543   // as soon as Use Case browser data tree was added
544   return obj ? SalomeApp_Application::getStudy()->GetUseCaseBuilder()->HasChildren( obj ) : false;
545 }
546
547 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
548 {
549   bool exp = true;
550   _PTR(GenericAttribute) anAttr;
551   if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
552     _PTR(AttributeExpandable) aAttrExp = anAttr;
553     exp = aAttrExp->IsExpandable();
554   }
555   return exp;
556 }
557
558 bool GEOMGUI_Selection::isCompoundOfVertices( GEOM::GEOM_Object_ptr obj )
559 {
560   bool ret = false;
561   /*
562   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
563   (SUIT_Session::session()->activeApplication()->activeStudy());*/
564   if ( /*appStudy && */!CORBA::is_nil( obj ) )
565     ret = obj->GetShapeType() == GEOM::COMPOUND && obj->GetMaxShapeType() == GEOM::VERTEX;
566   return ret;
567 }
568
569 bool GEOMGUI_Selection::isFolder( const _PTR(SObject)& obj )
570 {
571   bool ret = false;
572   _PTR(GenericAttribute) anAttr;
573   if ( obj && obj->FindAttribute(anAttr, "AttributeLocalID") ) {
574     _PTR(AttributeLocalID) aLocalID( anAttr );
575     ret = aLocalID->Value() == 999;
576   }
577   return ret;
578 }
579
580 bool GEOMGUI_Selection::hasChildren( const int index ) const
581 {
582   bool ok = false;
583   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
584
585   if ( appStudy ) {
586     QString anEntry = entry( index );
587     _PTR(Study) study = appStudy->studyDS();
588     if ( study && !anEntry.isEmpty() ) {
589       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
590       ok = hasChildren( aSO );
591     }
592   }
593   return ok;
594 }
595
596 int GEOMGUI_Selection::nbChildren( const int index ) const
597 {
598   int nb = 0;
599   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
600
601   if ( appStudy ) {
602     QString anEntry = entry( index );
603     _PTR(Study) study = appStudy->studyDS();
604     if ( study && !anEntry.isEmpty() ) {
605       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
606       if ( aSO && study->GetUseCaseBuilder()->IsUseCaseNode(aSO) ) {
607         _PTR(UseCaseIterator) it = study->GetUseCaseBuilder()->GetUseCaseIterator( aSO );
608         for (it->Init(false); it->More(); it->Next()) nb++;
609       }
610     }
611   }
612   return nb;
613 }
614
615 bool GEOMGUI_Selection::hasConcealedChildren( const int index ) const
616 {
617   bool OK = false;
618   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
619
620   if ( appStudy ) {
621     QString anEntry = entry( index );
622     _PTR(Study) study = appStudy->studyDS();
623     if ( study && !anEntry.isEmpty() ) {
624       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
625       OK = !expandable( aSO ) && hasChildren( aSO );
626     }
627   }
628   return OK;
629 }
630
631 bool GEOMGUI_Selection::hasDisclosedChildren( const int index ) const
632 {
633   bool OK = false;
634   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
635
636   if ( appStudy )  {
637     QString anEntry = entry( index );
638     _PTR(Study) study = appStudy->studyDS();
639     if ( study && !anEntry.isEmpty() ) {
640       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
641       OK = expandable( aSO ) && hasChildren( aSO );
642     }
643   }
644   return OK;
645 }
646
647 bool GEOMGUI_Selection::compoundOfVertices( const int index ) const
648 {
649   GEOM::GEOM_Object_var obj = getObject( index );
650   return isCompoundOfVertices( obj );
651 }
652
653 bool GEOMGUI_Selection::isComponent( const int index ) const
654 {
655   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
656
657   if ( appStudy ) {
658     QString anEntry = entry( index );
659     _PTR(Study) study = appStudy->studyDS();
660     if ( study && !anEntry.isNull() ) {
661       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
662       if ( aSO && aSO->GetFatherComponent() )
663         return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
664     }
665   }
666   return false;
667 }
668
669 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
670 {
671   GEOM::GEOM_Object_var o;
672   if ( 0 <= index && index < myObjects.size() )
673     o = GEOM::GEOM_Object::_narrow( myObjects[index] );
674   return o._retn();
675 }
676
677 GEOM::GEOM_BaseObject_ptr GEOMGUI_Selection::getBaseObject( const int index ) const
678 {
679   GEOM::GEOM_BaseObject_var o;
680   if ( 0 <= index && index < myObjects.size() )
681     o = GEOM::GEOM_BaseObject::_duplicate( myObjects[index] );
682   return o._retn();
683 }
684
685 QString GEOMGUI_Selection::selectionMode() const
686 {
687   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study()->application() );
688   if ( app ) {
689     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
690     if ( aGeomGUI ) {
691       switch ( aGeomGUI->getLocalSelectionMode() )
692       {
693         case GEOM_POINT      : return "VERTEX";
694         case GEOM_EDGE       : return "EDGE";
695         case GEOM_WIRE       : return "WIRE";
696         case GEOM_FACE       : return "FACE";
697         case GEOM_SHELL      : return "SHELL";
698         case GEOM_SOLID      : return "SOLID";
699         case GEOM_COMPOUND   : return "COMPOUND";
700         case GEOM_ALLOBJECTS : return "ALL";
701         default: return "";
702       }
703     }
704   }
705   return "";
706 }
707
708 bool GEOMGUI_Selection::topLevel( const int index ) const
709 {
710 #ifdef USE_VISUAL_PROP_MAP
711   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::TopLevel ) );
712   if ( v.canConvert<bool>() )
713     return v.toBool();
714 #endif
715
716   bool res = false;
717
718   SALOME_View* view = GEOM_Displayer::GetActiveView();
719   QString viewType = activeViewType();
720   if ( view && viewType == OCCViewer_Viewer::Type() ) {
721     SALOME_Prs* prs = view->CreatePrs( entry( index ).toUtf8().constData() );
722     if ( prs ) {
723       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
724         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
725         AIS_ListOfInteractive lst;
726         occPrs->GetObjects( lst );
727         if ( lst.Extent() ) {
728           Handle(AIS_InteractiveObject) io = lst.First();
729           if ( !io.IsNull() ) {
730             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
731             if ( !aSh.IsNull() )
732               res = (bool)aSh->isTopLevel();
733           }
734         }
735       }
736     }
737   }
738   return res;
739 }
740
741 bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const
742 {
743 #ifdef USE_VISUAL_PROP_MAP
744   QVariant v = visibleProperty( entry( idx ), GEOM::propertyName( GEOM::Material ) );
745   if ( v.canConvert<QString>() ) {
746     Material_Model material;
747     material.fromProperties( v.toString() );
748     return material.isPhysical();
749   }
750 #endif
751
752   bool res = false;
753   
754   SALOME_View* view = GEOM_Displayer::GetActiveView();
755   QString viewType = activeViewType();
756   if ( view ) {
757     SALOME_Prs* prs = view->CreatePrs( entry( idx ).toUtf8().constData() );
758     if ( prs ) {
759       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
760         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
761         AIS_ListOfInteractive lst;
762         occPrs->GetObjects( lst );
763         if ( lst.Extent() ) {
764           Handle(AIS_InteractiveObject) io = lst.First();
765           if ( !io.IsNull() ) {
766             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
767             if ( !aSh.IsNull() )
768               res = (bool) aSh->Attributes()->ShadingAspect()->
769                 Material(Aspect_TOFM_BOTH_SIDE).MaterialType( Graphic3d_MATERIAL_PHYSIC );
770           }
771         }
772       }
773       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
774         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
775         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
776         if ( lst ) {
777           lst->InitTraversal();
778           vtkActor* actor = lst->GetNextActor();
779           if ( actor ) {
780             GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( actor );
781             if ( aGeomGActor ) {
782               GEOM_VTKPropertyMaterial* mat  = GEOM_VTKPropertyMaterial::SafeDownCast(aGeomGActor->GetProperty());
783               if ( mat )
784                 res = mat->GetPhysical();
785             } // if ( salome actor )
786           } // if ( actor )
787         } // if ( lst == vtkPrs->GetObjects() )
788       }
789     }
790   }
791
792   return res;
793 }
794
795 bool GEOMGUI_Selection::isFolder( const int index ) const
796 {
797   bool res = false;
798   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
799
800   if ( appStudy ) {
801     QString anEntry = entry( index );
802     _PTR(Study) study = appStudy->studyDS();
803     if ( study && !anEntry.isNull() ) {
804       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
805       if ( aSO ) res = isFolder( aSO );
806     }
807   }
808   return res;
809 }
810
811 bool GEOMGUI_Selection::hasDimensions( const int theIndex, bool& theHidden, bool& theVisible ) const
812 {
813   QString anEntry = entry( theIndex );
814   if ( anEntry.isNull() )
815   {
816     return false;
817   }
818
819   GEOMGUI_DimensionProperty aDimensions( anEntry.toStdString() );
820
821   theHidden  = false;
822   theVisible = false;
823
824   for ( int it = 0; it < aDimensions.GetNumber(); ++it )
825   {
826     if ( aDimensions.IsVisible( it ) )
827       theVisible = true;
828     else
829       theHidden = true;
830   }
831
832   return aDimensions.GetNumber() > 0;
833 }
834
835 bool GEOMGUI_Selection::hasHiddenDimensions( const int theIndex ) const
836 {
837   bool isAnyVisible = false;
838   bool isAnyHidden = false;
839   if ( !hasDimensions( theIndex, isAnyHidden, isAnyVisible ) )
840   {
841     return false;
842   }
843
844   return isAnyHidden;
845 }
846
847 bool GEOMGUI_Selection::hasVisibleDimensions( const int theIndex ) const
848 {
849   bool isAnyVisible = false;
850   bool isAnyHidden = false;
851   if ( !hasDimensions( theIndex, isAnyHidden, isAnyVisible ) )
852   {
853     return false;
854   }
855
856   return isAnyVisible;
857 }
858
859 int GEOMGUI_Selection::annotationsCount() const
860 {
861   return myAnnotationEntries.size();
862 }
863
864 bool GEOMGUI_Selection::hasAnnotations( const int theIndex, bool& theHidden, bool& theVisible ) const
865 {
866   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
867   if ( !appStudy )
868     return false;
869
870   QString anEntry = entry( theIndex );
871   _PTR(Study) aStudy = appStudy->studyDS();
872   if ( !aStudy || anEntry.isNull() )
873     return false;
874
875   _PTR(SObject) aSObj = appStudy->studyDS()->FindObjectID( anEntry.toStdString() );
876
877   const Handle(GEOMGUI_AnnotationAttrs)
878     aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
879
880   if ( aShapeAnnotations.IsNull() )
881     return false;
882
883   theHidden  = false;
884   theVisible = false;
885
886   const int aCount = aShapeAnnotations->GetNbAnnotation();
887   for ( int anI = 0; anI < aCount; ++anI )
888   {
889     if ( aShapeAnnotations->GetIsVisible( anI ) )
890       theVisible = true;
891     else
892       theHidden = true;
893   }
894
895   return aCount > 0;
896 }
897
898 bool GEOMGUI_Selection::hasHiddenAnnotations( const int theIndex ) const
899 {
900   bool isAnyVisible, isAnyHidden = false;
901   if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )
902   {
903     return false;
904   }
905
906   return isAnyHidden;
907 }
908
909 bool GEOMGUI_Selection::hasVisibleAnnotations( const int theIndex ) const
910 {
911   bool isAnyVisible, isAnyHidden = false;
912   if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )
913   {
914     return false;
915   }
916
917   return isAnyVisible;
918 }