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