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