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( isOCC() );
44 else if ( p == "isActiveViewer" ) return QtxValue( isActiveViewer() );
46 return SalomeApp_Selection::globalParam( p );
49 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
51 if ( p == "isVisible" ) return QtxValue( isVisible( ind ) );
52 else if ( p == "type" ) return QtxValue( typeName( ind ) );
53 else if ( p == "displaymode" ) return QtxValue( displayMode( ind ) );
55 return SalomeApp_Selection::param( ind, p );
58 QString GEOMGUI_Selection::typeName( const int index ) const
60 if ( isComponent( index ) )
62 GEOM::GEOM_Object_var anObj = getObject( index );
63 if ( !CORBA::is_nil( anObj ) ) {
64 const int aGeomType = anObj->GetType();
65 if ( aGeomType == GEOM_GROUP )
73 bool GEOMGUI_Selection::isVisible( const int index ) const
75 GEOM::GEOM_Object_var obj = getObject( index );
76 SALOME_View* view = GEOM_Displayer::GetActiveView();
77 if ( !CORBA::is_nil( obj ) && view ) {
78 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
79 return view->isVisible( io );
84 bool GEOMGUI_Selection::isOCC() const
86 return activeViewType( OCCViewer_Viewer::Type() );
89 QString GEOMGUI_Selection::displayMode( const int index ) const
91 SALOME_View* view = GEOM_Displayer::GetActiveView();
92 if ( view /*fix for 9320==>*/&& ( isOCC() || activeViewType( VTKViewer_Viewer::Type() ) ) ) {
93 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
95 if ( isOCC() ) { // assuming OCC
96 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
97 AIS_ListOfInteractive lst;
98 occPrs->GetObjects( lst );
100 Handle(AIS_InteractiveObject) io = lst.First();
101 if ( !io.IsNull() ) {
102 int dm = io->DisplayMode();
103 if ( dm == AIS_WireFrame )
105 else if ( dm == AIS_Shaded )
107 else { // return default display mode of AIS_InteractiveContext
108 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
109 )->activeWindow()->getViewManager()->getViewModel();
110 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
111 dm = ic->DisplayMode();
112 if ( dm == AIS_WireFrame )
114 else if ( dm == AIS_Shaded )
120 else if ( activeViewType( VTKViewer_Viewer::Type() ) ) { // assuming VTK
121 SVTK_Prs* vtkPrs = (SVTK_Prs*) prs;
122 vtkActorCollection* lst = vtkPrs->GetObjects();
124 lst->InitTraversal();
125 vtkActor* actor = lst->GetNextActor();
127 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
129 int dm = salActor->getDisplayMode();
134 } // if ( salome actor )
136 } // if ( lst == vtkPrs->GetObjects() )
143 bool GEOMGUI_Selection::isComponent( const int index ) const
145 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
146 (SUIT_Session::session()->activeApplication()->activeStudy());
148 if ( appStudy && index >= 0 && index < count() ) {
149 _PTR(Study) study = appStudy->studyDS();
150 QString anEntry = entry( index );
152 if ( study && !anEntry.isNull() ) {
153 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
154 if ( aSO && aSO->GetFatherComponent() )
155 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
161 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
163 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
164 (SUIT_Session::session()->activeApplication()->activeStudy());
166 if ( appStudy && index >= 0 && index < count() ) {
167 _PTR(Study) study = appStudy->studyDS();
168 QString anEntry = entry( index );
170 if ( study && !anEntry.isNull() ) {
171 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
173 SALOMEDS_SObject* aDSObj = dynamic_cast<SALOMEDS_SObject*>( aSO.get() );
174 return GEOM::GEOM_Object::_narrow( aDSObj->GetObject() );
178 return GEOM::GEOM_Object::_nil();
181 SUIT_ViewWindow* activeVW()
183 SUIT_Session* session = SUIT_Session::session();
185 SUIT_Application* app = session->activeApplication();
187 SUIT_Desktop* desk = app->desktop();
189 return desk->activeWindow();
195 bool GEOMGUI_Selection::isActiveViewer() const
197 return ( activeVW() != 0 );
200 bool GEOMGUI_Selection::activeViewType( const QString& type ) const
202 SUIT_ViewWindow* win = activeVW();
204 SUIT_ViewManager* vm = win->getViewManager();
205 return ( vm && vm->getType() == type );