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