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