1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : GEOMGUI_Selection.cxx
24 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S. (alexander.solovyov@opencascade.com)
26 #include "GEOMGUI_Selection.h"
27 #include <GEOMGUI_DimensionProperty.h>
28 #include <GEOMGUI_AnnotationAttrs.h>
29 #include <GEOMGUI_AnnotationMgr.h>
31 #include "GeometryGUI.h"
32 #include "GEOM_Displayer.h"
34 #include "Material_Model.h"
36 #include <GEOM_Constants.h>
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_Study.h>
41 #include "LightApp_DataOwner.h"
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>
49 #include <SALOME_Prs.h>
50 #include <SALOME_InteractiveObject.hxx>
54 #include <SALOME_Actor.h>
55 #include <GEOM_Actor.h>
57 #include <OCCViewer_ViewModel.h>
58 #include <SVTK_ViewModel.h>
60 #include <GEOMImpl_Types.hxx>
62 #include <GEOM_AISShape.hxx>
63 #include <GEOM_VTKPropertyMaterial.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>
75 #include <vtkActorCollection.h>
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" ); \
89 #define USE_VISUAL_PROP_MAP
91 #ifdef USE_VISUAL_PROP_MAP
92 #define VTK_DISPLAY_MODE_TO_STRING( str, dm ) { \
94 str = QString( "Wireframe" ); \
96 str = QString( "Shading" ); \
98 str = QString( "ShadingWithEdges" ); \
102 #define VTK_DISPLAY_MODE_TO_STRING( str, dm ) { \
104 str = QString( "Wireframe" ); \
105 else if ( dm == 1 ) \
106 str = QString( "Shading" ); \
107 else if ( dm == 3 ) \
108 str = QString( "ShadingWithEdges" ); \
113 GEOMGUI_Selection::GEOMGUI_Selection()
114 : LightApp_Selection()
118 GEOMGUI_Selection::~GEOMGUI_Selection()
122 void GEOMGUI_Selection::init( const QString& context, LightApp_SelectionMgr* selMgr )
124 LightApp_Selection::init( context, selMgr );
126 myObjects.resize( count() );
128 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
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() ) );
136 CORBA::Object_var varObj = GeometryGUI::ClientSObjectToObject( aSO );
137 myObjects[idx] = GEOM::GEOM_BaseObject::_narrow( varObj );
144 //QVariant GEOMGUI_Selection::contextParameter( const QString& p ) const
145 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
149 v = activeViewType() == OCCViewer_Viewer::Type();
150 else if ( p == "selectionmode" )
152 else if ( p == "hasImported" )
154 else if ( p == "allImported" )
156 else if (p == "annotationsCount")
157 v = annotationsCount();
159 v = LightApp_Selection::parameter( p );
163 //QVariant GEOMGUI_Selection::objectParameter( const int idx, const QString& p ) const
164 QVariant GEOMGUI_Selection::parameter( const int idx, const QString& p ) const
169 else if ( p == "typeid" )
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" )
183 else if ( p == "autoBringToFront" )
184 v = autoBringToFront( idx );
185 else if ( p == "hasChildren" )
186 v = hasChildren( idx );
187 else if ( p == "nbChildren" )
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" )
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);
210 v = LightApp_Selection::parameter( idx, p );
215 // the method to skip temporary objects from selection (called from LightApp)
216 bool GEOMGUI_Selection::processOwner( const LightApp_DataOwner* theOwner )
218 if ( theOwner->entry().contains( GEOMGUI_AnnotationMgr::GetEntrySeparator() ) ) {
219 myAnnotationEntries.append( theOwner->entry() );
221 return !theOwner->entry().contains("_");
224 QString GEOMGUI_Selection::typeName( const int index ) const
226 if ( isComponent( index ) )
228 if ( isFolder( index ) )
231 static QString aGroup( "Group" );
232 static QString aShape( "Shape" );
233 static QString aField( "Field" );
234 static QString aFieldStep( "FieldStep" );
235 static QString anUnknown( "Unknown" );
237 GEOM::GEOM_BaseObject_var anObj = getBaseObject( index );
238 if ( !CORBA::is_nil( anObj ) ) {
239 const int aGeomType = anObj->GetType();
240 switch ( aGeomType ) {
241 case GEOM_GROUP : return aGroup;
242 case GEOM_FIELD : return aField;
243 case GEOM_FIELD_STEP: return aFieldStep;
244 default : return aShape;
250 int GEOMGUI_Selection::typeId( const int index ) const
253 GEOM::GEOM_Object_var anObj = getObject( index );
254 if ( !CORBA::is_nil( anObj ) )
255 aType = (int)anObj->GetShapeType();
259 bool GEOMGUI_Selection::isVisible( const int index ) const
261 #ifdef USE_VISUAL_PROP_MAP
262 QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Visibility ) );
263 if ( v.canConvert( QVariant::Bool ) )
269 GEOM::GEOM_Object_var obj = getObject( index );
270 SALOME_View* view = GEOM_Displayer::GetActiveView();
271 if ( !CORBA::is_nil( obj ) && view ) {
272 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
273 res = view->isVisible( io );
279 bool GEOMGUI_Selection::isAutoColor( const int index ) const
281 GEOM::GEOM_Object_var obj = getObject( index );
282 if ( !CORBA::is_nil( obj ) )
283 return obj->GetAutoColor();
287 bool GEOMGUI_Selection::isImported( const int index ) const
289 GEOM::GEOM_Object_var obj = getObject( index );
290 if ( !CORBA::is_nil( obj ) )
291 return obj->GetType() == GEOM_IMPORT;
295 bool GEOMGUI_Selection::hasImported() const
298 for ( int i = 0; i < count() && !res; i++ )
299 res = isImported( i );
303 bool GEOMGUI_Selection::allImported() const
306 for ( int i = 0; i < count() && res; i++ )
307 res = isImported( i );
311 QVariant GEOMGUI_Selection::visibleProperty( const QString& entry, const QString& propName ) const
314 LightApp_Study* aStudy = study();
316 LightApp_Application* anApp = ::qobject_cast<LightApp_Application*>( aStudy->application() );
317 if ( anApp && anApp->activeViewManager() ) {
318 int id = anApp->activeViewManager()->getGlobalId();
319 v = aStudy->getObjectProperty( id, entry, propName, QVariant() );
325 QString GEOMGUI_Selection::displayMode( const int index ) const
328 QString viewType = activeViewType();
330 #ifdef USE_VISUAL_PROP_MAP
331 QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::DisplayMode ) );
332 if ( v.canConvert( QVariant::Int ) ) {
334 if ( viewType == OCCViewer_Viewer::Type() ) {
335 OCC_DISPLAY_MODE_TO_STRING( res, dm );
336 } else if ( viewType == SVTK_Viewer::Type() ) {
337 VTK_DISPLAY_MODE_TO_STRING( res, dm );
343 SALOME_View* view = GEOM_Displayer::GetActiveView();
344 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
345 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
347 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
348 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
349 AIS_ListOfInteractive lst;
350 occPrs->GetObjects( lst );
351 if ( lst.Extent() ) {
352 Handle(AIS_InteractiveObject) io = lst.First();
353 if ( !io.IsNull() ) {
355 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
357 dm = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
359 dm = io->DisplayMode();
361 OCC_DISPLAY_MODE_TO_STRING( res, dm );
362 if ( res.isEmpty() ) { // return default display mode of AIS_InteractiveContext
363 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*)SUIT_Session::session()->activeApplication()->
364 desktop()->activeWindow()->getViewManager()->getViewModel();
365 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
366 dm = ic->DisplayMode();
367 OCC_DISPLAY_MODE_TO_STRING( res, dm );
372 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
373 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
374 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
376 lst->InitTraversal();
377 vtkActor* actor = lst->GetNextActor();
379 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
381 int dm = salActor->getDisplayMode();
382 VTK_DISPLAY_MODE_TO_STRING( res, dm );
383 } // if ( salome actor )
385 } // if ( lst == vtkPrs->GetObjects() )
393 bool GEOMGUI_Selection::autoBringToFront( const int /*index*/ ) const
395 return SUIT_Session::session()->resourceMgr()->booleanValue( "Geometry", "auto_bring_to_front", "false" );
398 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
400 #ifdef USE_VISUAL_PROP_MAP
401 QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::EdgesDirection ) );
402 if ( v.canConvert( QVariant::Bool ) )
408 SALOME_View* view = GEOM_Displayer::GetActiveView();
409 QString viewType = activeViewType();
410 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
411 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
413 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
414 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
415 AIS_ListOfInteractive lst;
416 occPrs->GetObjects( lst );
417 if ( lst.Extent() ) {
418 Handle(AIS_InteractiveObject) io = lst.First();
419 if ( !io.IsNull() ) {
420 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
422 res = aSh->isShowVectors();
426 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
427 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
428 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
430 lst->InitTraversal();
431 vtkActor* actor = lst->GetNextActor();
433 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
435 res = aGeomActor->GetVectorMode();
445 bool GEOMGUI_Selection::isVerticesMode( const int index ) const
447 #ifdef USE_VISUAL_PROP_MAP
448 QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::Vertices ) );
449 if ( v.canConvert( QVariant::Bool ) )
455 SALOME_View* view = GEOM_Displayer::GetActiveView();
456 QString viewType = activeViewType();
457 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
458 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
460 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
461 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
462 AIS_ListOfInteractive lst;
463 occPrs->GetObjects( lst );
464 if ( lst.Extent() ) {
465 Handle(AIS_InteractiveObject) io = lst.First();
466 if ( !io.IsNull() ) {
467 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
469 res = aSh->isShowVertices();
473 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
474 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
475 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
477 lst->InitTraversal();
478 vtkActor* actor = lst->GetNextActor();
480 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
482 res = aGeomActor->GetVerticesMode();
492 bool GEOMGUI_Selection::isNameMode( const int index ) const
494 #ifdef USE_VISUAL_PROP_MAP
495 QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::ShowName ) );
496 if ( v.canConvert( QVariant::Bool ) )
502 SALOME_View* view = GEOM_Displayer::GetActiveView();
503 QString viewType = activeViewType();
504 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
505 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
507 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
508 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
509 AIS_ListOfInteractive lst;
510 occPrs->GetObjects( lst );
511 if ( lst.Extent() ) {
512 Handle(AIS_InteractiveObject) io = lst.First();
513 if ( !io.IsNull() ) {
514 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
516 res = aSh->isShowName();
520 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
521 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
522 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
524 lst->InitTraversal();
525 vtkActor* actor = lst->GetNextActor();
527 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
529 res = aGeomActor->GetNameMode();
539 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
542 // as soon as Use Case browser data tree was added
543 return obj->GetStudy()->GetUseCaseBuilder()->HasChildren( obj );
547 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
550 _PTR(GenericAttribute) anAttr;
551 if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
552 _PTR(AttributeExpandable) aAttrExp = anAttr;
553 exp = aAttrExp->IsExpandable();
558 bool GEOMGUI_Selection::isCompoundOfVertices( GEOM::GEOM_Object_ptr obj )
562 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
563 (SUIT_Session::session()->activeApplication()->activeStudy());*/
564 if ( /*appStudy && */!CORBA::is_nil( obj ) )
565 ret = obj->GetShapeType() == GEOM::COMPOUND && obj->GetMaxShapeType() == GEOM::VERTEX;
569 bool GEOMGUI_Selection::isFolder( const _PTR(SObject)& obj )
572 _PTR(GenericAttribute) anAttr;
573 if ( obj && obj->FindAttribute(anAttr, "AttributeLocalID") ) {
574 _PTR(AttributeLocalID) aLocalID( anAttr );
575 ret = aLocalID->Value() == 999;
580 bool GEOMGUI_Selection::hasChildren( const int index ) const
583 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
586 QString anEntry = entry( index );
587 _PTR(Study) study = appStudy->studyDS();
588 if ( study && !anEntry.isEmpty() ) {
589 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
590 ok = hasChildren( aSO );
596 int GEOMGUI_Selection::nbChildren( const int index ) const
599 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
602 QString anEntry = entry( index );
603 _PTR(Study) study = appStudy->studyDS();
604 if ( study && !anEntry.isEmpty() ) {
605 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
606 if ( aSO && aSO->GetStudy()->GetUseCaseBuilder()->IsUseCaseNode(aSO) ) {
607 _PTR(UseCaseIterator) it = aSO->GetStudy()->GetUseCaseBuilder()->GetUseCaseIterator( aSO );
608 for (it->Init(false); it->More(); it->Next()) nb++;
615 bool GEOMGUI_Selection::hasConcealedChildren( const int index ) const
618 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
621 QString anEntry = entry( index );
622 _PTR(Study) study = appStudy->studyDS();
623 if ( study && !anEntry.isEmpty() ) {
624 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
625 OK = !expandable( aSO ) && hasChildren( aSO );
631 bool GEOMGUI_Selection::hasDisclosedChildren( const int index ) const
634 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
637 QString anEntry = entry( index );
638 _PTR(Study) study = appStudy->studyDS();
639 if ( study && !anEntry.isEmpty() ) {
640 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
641 OK = expandable( aSO ) && hasChildren( aSO );
647 bool GEOMGUI_Selection::compoundOfVertices( const int index ) const
649 GEOM::GEOM_Object_var obj = getObject( index );
650 return isCompoundOfVertices( obj );
653 bool GEOMGUI_Selection::isComponent( const int index ) const
655 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
658 QString anEntry = entry( index );
659 _PTR(Study) study = appStudy->studyDS();
660 if ( study && !anEntry.isNull() ) {
661 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
662 if ( aSO && aSO->GetFatherComponent() )
663 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
669 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
671 GEOM::GEOM_Object_var o;
672 if ( 0 <= index && index < myObjects.size() )
673 o = GEOM::GEOM_Object::_narrow( myObjects[index] );
677 GEOM::GEOM_BaseObject_ptr GEOMGUI_Selection::getBaseObject( const int index ) const
679 GEOM::GEOM_BaseObject_var o;
680 if ( 0 <= index && index < myObjects.size() )
681 o = GEOM::GEOM_BaseObject::_duplicate( myObjects[index] );
685 QString GEOMGUI_Selection::selectionMode() const
687 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study()->application() );
689 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
691 switch ( aGeomGUI->getLocalSelectionMode() )
693 case GEOM_POINT : return "VERTEX";
694 case GEOM_EDGE : return "EDGE";
695 case GEOM_WIRE : return "WIRE";
696 case GEOM_FACE : return "FACE";
697 case GEOM_SHELL : return "SHELL";
698 case GEOM_SOLID : return "SOLID";
699 case GEOM_COMPOUND : return "COMPOUND";
700 case GEOM_ALLOBJECTS : return "ALL";
708 bool GEOMGUI_Selection::topLevel( const int index ) const
710 #ifdef USE_VISUAL_PROP_MAP
711 QVariant v = visibleProperty( entry( index ), GEOM::propertyName( GEOM::TopLevel ) );
712 if ( v.canConvert<bool>() )
718 SALOME_View* view = GEOM_Displayer::GetActiveView();
719 QString viewType = activeViewType();
720 if ( view && viewType == OCCViewer_Viewer::Type() ) {
721 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
723 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
724 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
725 AIS_ListOfInteractive lst;
726 occPrs->GetObjects( lst );
727 if ( lst.Extent() ) {
728 Handle(AIS_InteractiveObject) io = lst.First();
729 if ( !io.IsNull() ) {
730 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
732 res = (bool)aSh->isTopLevel();
741 bool GEOMGUI_Selection::isPhysicalMaterial( const int idx ) const
743 #ifdef USE_VISUAL_PROP_MAP
744 QVariant v = visibleProperty( entry( idx ), GEOM::propertyName( GEOM::Material ) );
745 if ( v.canConvert<QString>() ) {
746 Material_Model material;
747 material.fromProperties( v.toString() );
748 return material.isPhysical();
754 SALOME_View* view = GEOM_Displayer::GetActiveView();
755 QString viewType = activeViewType();
757 SALOME_Prs* prs = view->CreatePrs( entry( idx ).toLatin1().constData() );
759 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
760 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
761 AIS_ListOfInteractive lst;
762 occPrs->GetObjects( lst );
763 if ( lst.Extent() ) {
764 Handle(AIS_InteractiveObject) io = lst.First();
765 if ( !io.IsNull() ) {
766 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
768 res = (bool) aSh->Attributes()->ShadingAspect()->
769 Material(Aspect_TOFM_BOTH_SIDE).MaterialType( Graphic3d_MATERIAL_PHYSIC );
773 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
774 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
775 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
777 lst->InitTraversal();
778 vtkActor* actor = lst->GetNextActor();
780 GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( actor );
782 GEOM_VTKPropertyMaterial* mat = GEOM_VTKPropertyMaterial::SafeDownCast(aGeomGActor->GetProperty());
784 res = mat->GetPhysical();
785 } // if ( salome actor )
787 } // if ( lst == vtkPrs->GetObjects() )
795 bool GEOMGUI_Selection::isFolder( const int index ) const
798 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
801 QString anEntry = entry( index );
802 _PTR(Study) study = appStudy->studyDS();
803 if ( study && !anEntry.isNull() ) {
804 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
805 if ( aSO ) res = isFolder( aSO );
811 bool GEOMGUI_Selection::hasDimensions( const int theIndex, bool& theHidden, bool& theVisible ) const
813 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
820 QString anEntry = entry( theIndex );
821 _PTR(Study) aStudy = appStudy->studyDS();
822 if ( !aStudy || anEntry.isNull() )
827 GEOMGUI_DimensionProperty aDimensions( appStudy, anEntry.toStdString() );
832 for ( int it = 0; it < aDimensions.GetNumber(); ++it )
834 if ( aDimensions.IsVisible( it ) )
840 return aDimensions.GetNumber() > 0;
843 bool GEOMGUI_Selection::hasHiddenDimensions( const int theIndex ) const
845 bool isAnyVisible = false;
846 bool isAnyHidden = false;
847 if ( !hasDimensions( theIndex, isAnyHidden, isAnyVisible ) )
855 bool GEOMGUI_Selection::hasVisibleDimensions( const int theIndex ) const
857 bool isAnyVisible = false;
858 bool isAnyHidden = false;
859 if ( !hasDimensions( theIndex, isAnyHidden, isAnyVisible ) )
867 int GEOMGUI_Selection::annotationsCount() const
869 return myAnnotationEntries.size();
872 bool GEOMGUI_Selection::hasAnnotations( const int theIndex, bool& theHidden, bool& theVisible ) const
874 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( study() );
878 QString anEntry = entry( theIndex );
879 _PTR(Study) aStudy = appStudy->studyDS();
880 if ( !aStudy || anEntry.isNull() )
883 _PTR(SObject) aSObj = appStudy->studyDS()->FindObjectID( anEntry.toStdString() );
\r
885 const Handle(GEOMGUI_AnnotationAttrs)
\r
886 aShapeAnnotations = GEOMGUI_AnnotationAttrs::FindAttributes( aSObj );
\r
888 if ( aShapeAnnotations.IsNull() )
\r
894 const int aCount = aShapeAnnotations->GetNbAnnotation();
895 for ( int anI = 0; anI < aCount; ++anI )
897 if ( aShapeAnnotations->GetIsVisible( anI ) )
906 bool GEOMGUI_Selection::hasHiddenAnnotations( const int theIndex ) const
908 bool isAnyVisible, isAnyHidden = false;
909 if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )
917 bool GEOMGUI_Selection::hasVisibleAnnotations( const int theIndex ) const
919 bool isAnyVisible, isAnyHidden = false;
920 if ( !hasAnnotations( theIndex, isAnyHidden, isAnyVisible ) )