Salome HOME
Merge 'master' branch into 'V9_dev' branch.
[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
210     v = LightApp_Selection::parameter( idx, p );
211
212   return v;
213 }
214
215 // the method to skip temporary objects from selection (called from LightApp)
216 bool GEOMGUI_Selection::processOwner( const LightApp_DataOwner* theOwner )
217 {
218   if ( theOwner->entry().contains( GEOMGUI_AnnotationMgr::GetEntrySeparator() ) ) {
219     myAnnotationEntries.append( theOwner->entry() );
220   }
221   return !theOwner->entry().contains("_");
222 }
223
224 QString GEOMGUI_Selection::typeName( const int index ) const
225 {
226   if ( isComponent( index ) )
227     return "Component";
228   if ( isFolder( index ) )
229     return "Folder";
230
231   static QString aGroup( "Group" );
232   static QString aShape( "Shape" );
233   static QString aField( "Field" );
234   static QString aFieldStep( "FieldStep" );
235   static QString anUnknown( "Unknown" );
236
237   GEOM::GEOM_BaseObject_var anObj = getBaseObject( index );
238   if ( !CORBA::is_nil( anObj ) ) {
239     const int aGeomType = anObj->GetType();
240     switch ( aGeomType ) {
241     case GEOM_GROUP     : return aGroup;
242     case GEOM_FIELD     : return aField;
243     case GEOM_FIELD_STEP: return aFieldStep;
244     default             : return aShape;
245     }
246   }
247   return anUnknown;
248 }
249
250 int GEOMGUI_Selection::typeId( const int index ) const
251 {
252   int aType = -1;
253   GEOM::GEOM_Object_var anObj = getObject( index );
254   if ( !CORBA::is_nil( anObj ) )
255     aType = (int)anObj->GetShapeType();
256   return aType;
257 }
258
259 bool GEOMGUI_Selection::isVisible( const int index ) const
260 {
261 #ifdef USE_VISUAL_PROP_MAP
262   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Visibility ) );
263   if ( v.canConvert( QVariant::Bool ) )
264     return v.toBool();
265 #endif
266
267   bool res = false;
268
269   GEOM::GEOM_Object_var obj = getObject( index );
270   SALOME_View* view = GEOM_Displayer::GetActiveView();
271   if ( !CORBA::is_nil( obj ) && view ) {
272     Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
273     res = view->isVisible( io );
274   }
275
276   return res;
277 }
278
279 bool GEOMGUI_Selection::isAutoColor( const int index ) const
280 {
281   GEOM::GEOM_Object_var obj = getObject( index );
282   if ( !CORBA::is_nil( obj ) )
283     return obj->GetAutoColor();
284   return false;
285 }
286
287 bool GEOMGUI_Selection::isImported( const int index ) const
288 {
289   GEOM::GEOM_Object_var obj = getObject( index );
290   if ( !CORBA::is_nil( obj ) )
291     return obj->GetType() == GEOM_IMPORT;
292   return false;
293 }
294
295 bool GEOMGUI_Selection::hasImported() const
296 {
297   bool res = false;
298   for ( int i = 0; i < count() && !res; i++ )
299     res = isImported( i );
300   return res;
301 }
302
303 bool GEOMGUI_Selection::allImported() const
304 {
305   bool res = true;
306   for ( int i = 0; i < count() && res; i++ )
307     res = isImported( i );
308   return res;
309 }
310
311 QVariant GEOMGUI_Selection::visibleProperty( const QString& entry, const QString& propName ) const
312 {
313   QVariant v;
314   LightApp_Study* aStudy = study();
315   if ( aStudy ) {
316     LightApp_Application* anApp = ::qobject_cast<LightApp_Application*>( aStudy->application() );
317     if ( anApp && anApp->activeViewManager() ) {
318       int id = anApp->activeViewManager()->getGlobalId();
319       v = aStudy->getObjectProperty( id, entry, propName, QVariant() );
320     }
321   }
322   return v;
323 }
324
325 QString GEOMGUI_Selection::displayMode( const int index ) const
326 {
327   QString res;
328   QString viewType = activeViewType();
329   
330 #ifdef USE_VISUAL_PROP_MAP
331   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::DisplayMode ) );
332   if ( v.canConvert( QVariant::Int ) ) {
333     int dm = v.toInt();
334     if ( viewType == OCCViewer_Viewer::Type() ) {
335       OCC_DISPLAY_MODE_TO_STRING( res, dm );
336     } else if ( viewType == SVTK_Viewer::Type() ) {
337       VTK_DISPLAY_MODE_TO_STRING( res, dm );
338     }
339     return res;
340   }
341 #endif
342
343   SALOME_View* view = GEOM_Displayer::GetActiveView();
344   if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
345     SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
346     if ( prs ) {
347       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
348         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
349         AIS_ListOfInteractive lst;
350         occPrs->GetObjects( lst );
351         if ( lst.Extent() ) {
352           Handle(AIS_InteractiveObject) io = lst.First();
353           if ( !io.IsNull() ) {
354             int dm;
355             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
356             if(!aSh.IsNull()) {
357               dm = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
358             } else {
359               dm = io->DisplayMode();
360             }
361             OCC_DISPLAY_MODE_TO_STRING( res, dm );
362             if ( res.isEmpty() ) { // return default display mode of AIS_InteractiveContext
363               OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*)SUIT_Session::session()->activeApplication()->
364                 desktop()->activeWindow()->getViewManager()->getViewModel();
365               Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
366               dm = ic->DisplayMode();
367               OCC_DISPLAY_MODE_TO_STRING( res, dm );
368             }
369           }
370         }
371       }
372       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
373         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
374         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
375         if ( lst ) {
376           lst->InitTraversal();
377           vtkActor* actor = lst->GetNextActor();
378           if ( actor ) {
379             SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
380             if ( salActor ) {
381               int dm = salActor->getDisplayMode();
382               VTK_DISPLAY_MODE_TO_STRING( res, dm );
383             } // if ( salome actor )
384           } // if ( actor )
385         } // if ( lst == vtkPrs->GetObjects() )
386       } // if VTK
387     }
388   }
389
390   return res;
391 }
392
393 bool GEOMGUI_Selection::autoBringToFront( const int /*index*/ ) const
394 {
395   return SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front", "false" );
396 }
397
398 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
399 {
400 #ifdef USE_VISUAL_PROP_MAP
401   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::EdgesDirection ) );
402   if ( v.canConvert( QVariant::Bool ) )
403     return v.toBool();
404 #endif
405
406   bool res = false;
407   
408   SALOME_View* view = GEOM_Displayer::GetActiveView();
409   QString viewType = activeViewType();
410   if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
411     SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
412     if ( prs ) {
413       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
414         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
415         AIS_ListOfInteractive lst;
416         occPrs->GetObjects( lst );
417         if ( lst.Extent() ) {
418           Handle(AIS_InteractiveObject) io = lst.First();
419           if ( !io.IsNull() ) {
420             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
421             if ( !aSh.IsNull() )
422               res = aSh->isShowVectors();
423           }
424         }
425       }
426       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
427         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
428         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
429         if ( lst ) {
430           lst->InitTraversal();
431           vtkActor* actor = lst->GetNextActor();
432           if ( actor ) {
433             GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
434             if ( aGeomActor )
435               res = aGeomActor->GetVectorMode();
436             }
437         }
438       }
439     }
440   }
441
442   return res;
443 }
444
445 bool GEOMGUI_Selection::isVerticesMode( const int index ) const
446 {
447 #ifdef USE_VISUAL_PROP_MAP
448   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Vertices ) );
449   if ( v.canConvert( QVariant::Bool ) )
450     return v.toBool();
451 #endif
452
453   bool res = false;
454   
455   SALOME_View* view = GEOM_Displayer::GetActiveView();
456   QString viewType = activeViewType();
457   if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
458     SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
459     if ( prs ) {
460       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
461         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
462         AIS_ListOfInteractive lst;
463         occPrs->GetObjects( lst );
464         if ( lst.Extent() ) {
465           Handle(AIS_InteractiveObject) io = lst.First();
466           if ( !io.IsNull() ) {
467             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
468             if ( !aSh.IsNull() )
469               res = aSh->isShowVertices();
470           }
471         }
472       }
473       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
474         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
475         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
476         if ( lst ) {
477           lst->InitTraversal();
478           vtkActor* actor = lst->GetNextActor();
479           if ( actor ) {
480             GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
481             if ( aGeomActor )
482               res = aGeomActor->GetVerticesMode();
483             }
484         }
485       }
486     }
487   }
488
489   return res;
490 }
491
492 bool GEOMGUI_Selection::isNameMode( const int index ) const
493 {
494 #ifdef USE_VISUAL_PROP_MAP
495   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::ShowName ) );
496   if ( v.canConvert( QVariant::Bool ) )
497     return v.toBool();
498 #endif
499
500   bool res = false;
501
502   SALOME_View* view = GEOM_Displayer::GetActiveView();
503   QString viewType = activeViewType();
504   if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
505     SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
506     if ( prs ) {
507       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
508         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
509         AIS_ListOfInteractive lst;
510         occPrs->GetObjects( lst );
511         if ( lst.Extent() ) {
512           Handle(AIS_InteractiveObject) io = lst.First();
513           if ( !io.IsNull() ) {
514             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
515             if ( !aSh.IsNull() )
516               res = aSh->isShowName();
517           }
518         }
519       }
520       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
521         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
522         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
523         if ( lst ) {
524           lst->InitTraversal();
525           vtkActor* actor = lst->GetNextActor();
526           if ( actor ) {
527             GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
528             if ( aGeomActor )
529               res = aGeomActor->GetNameMode();
530             }
531         }
532       }
533     }
534   }
535
536   return res;
537 }
538
539 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
540 {
541   // as soon as Use Case browser data tree was added
542   return obj ? SalomeApp_Application::getStudy()->GetUseCaseBuilder()->HasChildren( obj ) : false;
543 }
544
545 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
546 {
547   bool exp = true;
548   _PTR(GenericAttribute) anAttr;
549   if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
550     _PTR(AttributeExpandable) aAttrExp = anAttr;
551     exp = aAttrExp->IsExpandable();
552   }
553   return exp;
554 }
555
556 bool GEOMGUI_Selection::isCompoundOfVertices( GEOM::GEOM_Object_ptr obj )
557 {
558   bool ret = false;
559   /*
560   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
561   (SUIT_Session::session()->activeApplication()->activeStudy());*/
562   if ( /*appStudy && */!CORBA::is_nil( obj ) )
563     ret = obj->GetShapeType() == GEOM::COMPOUND && obj->GetMaxShapeType() == GEOM::VERTEX;
564   return ret;
565 }
566
567 bool GEOMGUI_Selection::isFolder( const _PTR(SObject)& obj )
568 {
569   bool ret = false;
570   _PTR(GenericAttribute) anAttr;
571   if ( obj && obj->FindAttribute(anAttr, "AttributeLocalID") ) {
572     _PTR(AttributeLocalID) aLocalID( anAttr );
573     ret = aLocalID->Value() == 999;
574   }
575   return ret;
576 }
577
578 bool GEOMGUI_Selection::hasChildren( const int index ) const
579 {
580   bool ok = false;
581   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
582
583   if ( appStudy ) {
584     QString anEntry = entry( index );
585     _PTR(Study) study = appStudy->studyDS();
586     if ( study && !anEntry.isEmpty() ) {
587       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
588       ok = hasChildren( aSO );
589     }
590   }
591   return ok;
592 }
593
594 int GEOMGUI_Selection::nbChildren( const int index ) const
595 {
596   int nb = 0;
597   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
598
599   if ( appStudy ) {
600     QString anEntry = entry( index );
601     _PTR(Study) study = appStudy->studyDS();
602     if ( study && !anEntry.isEmpty() ) {
603       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
604       if ( aSO && study->GetUseCaseBuilder()->IsUseCaseNode(aSO) ) {
605         _PTR(UseCaseIterator) it = study->GetUseCaseBuilder()->GetUseCaseIterator( aSO );
606         for (it->Init(false); it->More(); it->Next()) nb++;
607       }
608     }
609   }
610   return nb;
611 }
612
613 bool GEOMGUI_Selection::hasConcealedChildren( const int index ) const
614 {
615   bool OK = false;
616   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
617
618   if ( appStudy ) {
619     QString anEntry = entry( index );
620     _PTR(Study) study = appStudy->studyDS();
621     if ( study && !anEntry.isEmpty() ) {
622       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
623       OK = !expandable( aSO ) && hasChildren( aSO );
624     }
625   }
626   return OK;
627 }
628
629 bool GEOMGUI_Selection::hasDisclosedChildren( const int index ) const
630 {
631   bool OK = false;
632   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
633
634   if ( appStudy )  {
635     QString anEntry = entry( index );
636     _PTR(Study) study = appStudy->studyDS();
637     if ( study && !anEntry.isEmpty() ) {
638       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
639       OK = expandable( aSO ) && hasChildren( aSO );
640     }
641   }
642   return OK;
643 }
644
645 bool GEOMGUI_Selection::compoundOfVertices( const int index ) const
646 {
647   GEOM::GEOM_Object_var obj = getObject( index );
648   return isCompoundOfVertices( obj );
649 }
650
651 bool GEOMGUI_Selection::isComponent( const int index ) const
652 {
653   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
654
655   if ( appStudy ) {
656     QString anEntry = entry( index );
657     _PTR(Study) study = appStudy->studyDS();
658     if ( study && !anEntry.isNull() ) {
659       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
660       if ( aSO && aSO->GetFatherComponent() )
661         return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
662     }
663   }
664   return false;
665 }
666
667 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
668 {
669   GEOM::GEOM_Object_var o;
670   if ( 0 <= index && index < myObjects.size() )
671     o = GEOM::GEOM_Object::_narrow( myObjects[index] );
672   return o._retn();
673 }
674
675 GEOM::GEOM_BaseObject_ptr GEOMGUI_Selection::getBaseObject( const int index ) const
676 {
677   GEOM::GEOM_BaseObject_var o;
678   if ( 0 <= index && index < myObjects.size() )
679     o = GEOM::GEOM_BaseObject::_duplicate( myObjects[index] );
680   return o._retn();
681 }
682
683 QString GEOMGUI_Selection::selectionMode() const
684 {
685   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study()->application() );
686   if ( app ) {
687     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
688     if ( aGeomGUI ) {
689       switch ( aGeomGUI->getLocalSelectionMode() )
690       {
691         case GEOM_POINT      : return "VERTEX";
692         case GEOM_EDGE       : return "EDGE";
693         case GEOM_WIRE       : return "WIRE";
694         case GEOM_FACE       : return "FACE";
695         case GEOM_SHELL      : return "SHELL";
696         case GEOM_SOLID      : return "SOLID";
697         case GEOM_COMPOUND   : return "COMPOUND";
698         case GEOM_ALLOBJECTS : return "ALL";
699         default: return "";
700       }
701     }
702   }
703   return "";
704 }
705
706 bool GEOMGUI_Selection::topLevel( const int index ) const
707 {
708 #ifdef USE_VISUAL_PROP_MAP
709   QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::TopLevel ) );
710   if ( v.canConvert<bool>() )
711     return v.toBool();
712 #endif
713
714   bool res = false;
715
716   SALOME_View* view = GEOM_Displayer::GetActiveView();
717   QString viewType = activeViewType();
718   if ( view && viewType == OCCViewer_Viewer::Type() ) {
719     SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
720     if ( prs ) {
721       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
722         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
723         AIS_ListOfInteractive lst;
724         occPrs->GetObjects( lst );
725         if ( lst.Extent() ) {
726           Handle(AIS_InteractiveObject) io = lst.First();
727           if ( !io.IsNull() ) {
728             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
729             if ( !aSh.IsNull() )
730               res = (bool)aSh->isTopLevel();
731           }
732         }
733       }
734     }
735   }
736   return res;
737 }
738
739 bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const
740 {
741 #ifdef USE_VISUAL_PROP_MAP
742   QVariant v = visibleProperty( entry( idx ), GEOM::propertyName( GEOM::Material ) );
743   if ( v.canConvert<QString>() ) {
744     Material_Model material;
745     material.fromProperties( v.toString() );
746     return material.isPhysical();
747   }
748 #endif
749
750   bool res = false;
751   
752   SALOME_View* view = GEOM_Displayer::GetActiveView();
753   QString viewType = activeViewType();
754   if ( view ) {
755     SALOME_Prs* prs = view->CreatePrs( entry( idx ).toLatin1().constData() );
756     if ( prs ) {
757       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
758         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
759         AIS_ListOfInteractive lst;
760         occPrs->GetObjects( lst );
761         if ( lst.Extent() ) {
762           Handle(AIS_InteractiveObject) io = lst.First();
763           if ( !io.IsNull() ) {
764             Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
765             if ( !aSh.IsNull() )
766               res = (bool) aSh->Attributes()->ShadingAspect()->
767                 Material(Aspect_TOFM_BOTH_SIDE).MaterialType( Graphic3d_MATERIAL_PHYSIC );
768           }
769         }
770       }
771       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
772         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
773         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
774         if ( lst ) {
775           lst->InitTraversal();
776           vtkActor* actor = lst->GetNextActor();
777           if ( actor ) {
778             GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( actor );
779             if ( aGeomGActor ) {
780               GEOM_VTKPropertyMaterial* mat  = GEOM_VTKPropertyMaterial::SafeDownCast(aGeomGActor->GetProperty());
781               if ( mat )
782                 res = mat->GetPhysical();
783             } // if ( salome actor )
784           } // if ( actor )
785         } // if ( lst == vtkPrs->GetObjects() )
786       }
787     }
788   }
789
790   return res;
791 }
792
793 bool GEOMGUI_Selection::isFolder( const int index ) const
794 {
795   bool res = false;
796   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
797
798   if ( appStudy ) {
799     QString anEntry = entry( index );
800     _PTR(Study) study = appStudy->studyDS();
801     if ( study && !anEntry.isNull() ) {
802       _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
803       if ( aSO ) res = isFolder( aSO );
804     }
805   }
806   return res;
807 }
808
809 bool GEOMGUI_Selection::hasDimensions( const int theIndex, bool& theHidden, bool& theVisible ) const
810 {
811   QString anEntry = entry( theIndex );
812   if ( anEntry.isNull() )
813   {
814     return false;
815   }
816
817   GEOMGUI_DimensionProperty aDimensions( anEntry.toStdString() );
818
819   theHidden  = false;
820   theVisible = false;
821
822   for ( int it = 0; it < aDimensions.GetNumber(); ++it )
823   {
824     if ( aDimensions.IsVisible( it ) )
825       theVisible = true;
826     else
827       theHidden = true;
828   }
829
830   return aDimensions.GetNumber() > 0;
831 }
832
833 bool GEOMGUI_Selection::hasHiddenDimensions( const int theIndex ) const
834 {
835   bool isAnyVisible = false;
836   bool isAnyHidden = false;
837   if ( !hasDimensions( theIndex, isAnyHidden, isAnyVisible ) )
838   {
839     return false;
840   }
841
842   return isAnyHidden;
843 }
844
845 bool GEOMGUI_Selection::hasVisibleDimensions( const int theIndex ) const
846 {
847   bool isAnyVisible = false;
848   bool isAnyHidden = false;
849   if ( !hasDimensions( theIndex, isAnyHidden, isAnyVisible ) )
850   {
851     return false;
852   }
853
854   return isAnyVisible;
855 }
856
857 int GEOMGUI_Selection::annotationsCount() const
858 {
859   return myAnnotationEntries.size();
860 }
861
862 bool GEOMGUI_Selection::hasAnnotations( const int theIndex, bool& theHidden, bool& theVisible ) const
863 {
864   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
865   if ( !appStudy )
866     return false;
867
868   QString anEntry = entry( theIndex );
869   _PTR(Study) aStudy = appStudy->studyDS();
870   if ( !aStudy || anEntry.isNull() )
871     return false;
872
873   _PTR(SObject) aSObj = appStudy->studyDS()->FindObjectID( anEntry.toStdString() );
874
875   const Handle(GEOMGUI_AnnotationAttrs)
876     aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
877
878   if ( aShapeAnnotations.IsNull() )
879     return false;
880
881   theHidden  = false;
882   theVisible = false;
883
884   const int aCount = aShapeAnnotations->GetNbAnnotation();
885   for ( int anI = 0; anI < aCount; ++anI )
886   {
887     if ( aShapeAnnotations->GetIsVisible( anI ) )
888       theVisible = true;
889     else
890       theHidden = true;
891   }
892
893   return aCount > 0;
894 }
895
896 bool GEOMGUI_Selection::hasHiddenAnnotations( const int theIndex ) const
897 {
898   bool isAnyVisible, isAnyHidden = false;
899   if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )
900   {
901     return false;
902   }
903
904   return isAnyHidden;
905 }
906
907 bool GEOMGUI_Selection::hasVisibleAnnotations( const int theIndex ) const
908 {
909   bool isAnyVisible, isAnyHidden = false;
910   if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )
911   {
912     return false;
913   }
914
915   return isAnyVisible;
916 }