1 #include <OCCViewer_ViewModel.h>
3 #include "GEOMGUI_Selection.h"
4 #include "GEOM_Displayer.h"
5 #include "GEOMImpl_Types.hxx"
7 #include <SalomeApp_DataOwner.h>
8 #include <SalomeApp_Study.h>
10 #include <SUIT_Session.h>
11 #include <SUIT_ViewWindow.h>
12 #include <SUIT_ViewManager.h>
13 #include <SUIT_ViewModel.h>
15 #include <SALOMEDSClient_SObject.hxx>
16 #include <SALOMEDSClient_Study.hxx>
17 #include <SALOMEDS_SObject.hxx>
18 #include <SALOME_Prs.h>
19 #include <SALOME_InteractiveObject.hxx>
23 #include <SALOME_Actor.h>
24 #include <vtkActorCollection.h>
26 #include <OCCViewer_ViewModel.h>
27 #include <VTKViewer_ViewModel.h>
30 #include <AIS_InteractiveObject.hxx>
31 #include <AIS_ListOfInteractive.hxx>
33 GEOMGUI_Selection::GEOMGUI_Selection()
37 GEOMGUI_Selection::~GEOMGUI_Selection()
41 QtxValue GEOMGUI_Selection::globalParam( const QString& p ) const
43 if ( p == "isOCC" ) return QtxValue( activeViewType() == OCCViewer_Viewer::Type() );
45 return SalomeApp_Selection::globalParam( p );
48 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
50 if ( p == "isVisible" ) return QtxValue( isVisible( ind ) );
51 else if ( p == "type" ) return QtxValue( typeName( ind ) );
52 else if ( p == "displaymode" ) return QtxValue( displayMode( ind ) );
54 return SalomeApp_Selection::param( ind, p );
57 QString GEOMGUI_Selection::typeName( const int index ) const
59 if ( isComponent( index ) )
61 GEOM::GEOM_Object_var anObj = getObject( index );
62 if ( !CORBA::is_nil( anObj ) ) {
63 const int aGeomType = anObj->GetType();
64 if ( aGeomType == GEOM_GROUP )
72 bool GEOMGUI_Selection::isVisible( const int index ) const
74 GEOM::GEOM_Object_var obj = getObject( index );
75 SALOME_View* view = GEOM_Displayer::GetActiveView();
76 if ( !CORBA::is_nil( obj ) && view ) {
77 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
78 return view->isVisible( io );
83 QString GEOMGUI_Selection::displayMode( const int index ) const
85 SALOME_View* view = GEOM_Displayer::GetActiveView();
86 QString viewType = activeViewType();
87 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == VTKViewer_Viewer::Type() ) ) {
88 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
90 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
91 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
92 AIS_ListOfInteractive lst;
93 occPrs->GetObjects( lst );
95 Handle(AIS_InteractiveObject) io = lst.First();
97 int dm = io->DisplayMode();
98 if ( dm == AIS_WireFrame )
100 else if ( dm == AIS_Shaded )
102 else { // return default display mode of AIS_InteractiveContext
103 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
104 )->activeWindow()->getViewManager()->getViewModel();
105 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
106 dm = ic->DisplayMode();
107 if ( dm == AIS_WireFrame )
109 else if ( dm == AIS_Shaded )
115 else if ( viewType == VTKViewer_Viewer::Type() ) { // assuming VTK
116 SVTK_Prs* vtkPrs = (SVTK_Prs*) prs;
117 vtkActorCollection* lst = vtkPrs->GetObjects();
119 lst->InitTraversal();
120 vtkActor* actor = lst->GetNextActor();
122 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
124 int dm = salActor->getDisplayMode();
129 } // if ( salome actor )
131 } // if ( lst == vtkPrs->GetObjects() )
138 bool GEOMGUI_Selection::isComponent( const int index ) const
140 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
141 (SUIT_Session::session()->activeApplication()->activeStudy());
143 if ( appStudy && index >= 0 && index < count() ) {
144 _PTR(Study) study = appStudy->studyDS();
145 QString anEntry = entry( index );
147 if ( study && !anEntry.isNull() ) {
148 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
149 if ( aSO && aSO->GetFatherComponent() )
150 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
156 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
158 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
159 (SUIT_Session::session()->activeApplication()->activeStudy());
161 if ( appStudy && index >= 0 && index < count() ) {
162 _PTR(Study) study = appStudy->studyDS();
163 QString anEntry = entry( index );
165 if ( study && !anEntry.isNull() ) {
166 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
168 SALOMEDS_SObject* aDSObj = dynamic_cast<SALOMEDS_SObject*>( aSO.get() );
169 return GEOM::GEOM_Object::_narrow( aDSObj->GetObject() );
173 return GEOM::GEOM_Object::_nil();