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