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