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