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>
29 #include <AIS_InteractiveObject.hxx>
30 #include <AIS_ListOfInteractive.hxx>
32 GEOMGUI_Selection::GEOMGUI_Selection()
36 GEOMGUI_Selection::~GEOMGUI_Selection()
40 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
42 QtxValue val( SalomeApp_Selection::param( ind, p ) );
43 if ( !val.isValid() ) {
44 if ( p == "isVisible" ) val = QtxValue( isVisible( ind ) );
45 else if ( p == "isOCC" ) val = QtxValue( isOCC() );
46 else if ( p == "type" ) val = QtxValue( typeName( ind ) );
47 else if ( p == "displaymode" ) val = QtxValue( displayMode( ind ) );
48 else if ( p == "isActiveViewer" ) val = QtxValue( isActiveViewer() );
51 printf( "--> param() : [%s] = %s\n", p.latin1(), val.toString ().latin1() );
56 QString GEOMGUI_Selection::typeName( const int index ) const
58 if ( isComponent( index ) )
60 GEOM::GEOM_Object_var anObj = getObject( index );
61 if ( !CORBA::is_nil( anObj ) ) {
62 const int aGeomType = anObj->GetType();
63 if ( aGeomType == GEOM_GROUP )
71 bool GEOMGUI_Selection::isVisible( const int index ) const
73 GEOM::GEOM_Object_var obj = getObject( index );
74 SALOME_View* view = GEOM_Displayer::GetActiveView();
75 if ( !CORBA::is_nil( obj ) && view ) {
76 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
77 return view->isVisible( io );
82 bool GEOMGUI_Selection::isOCC() const
84 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
85 return ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
88 QString GEOMGUI_Selection::displayMode( const int index ) const
90 SALOME_View* view = GEOM_Displayer::GetActiveView();
92 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
94 if ( isOCC() ) { // assuming OCC
95 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
96 AIS_ListOfInteractive lst;
97 occPrs->GetObjects( lst );
99 Handle(AIS_InteractiveObject) io = lst.First();
100 if ( !io.IsNull() ) {
101 int dm = io->DisplayMode();
102 if ( dm == AIS_WireFrame )
104 else if ( dm == AIS_Shaded )
106 else { // return default display mode of AIS_InteractiveContext
107 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
108 )->activeWindow()->getViewManager()->getViewModel();
109 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
110 dm = ic->DisplayMode();
111 if ( dm == AIS_WireFrame )
113 else if ( dm == AIS_Shaded )
119 else { // assuming VTK
120 SVTK_Prs* vtkPrs = (SVTK_Prs*) prs;
121 vtkActorCollection* lst = vtkPrs->GetObjects();
123 lst->InitTraversal();
124 vtkActor* actor = lst->GetNextActor();
126 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
128 int dm = salActor->getDisplayMode();
133 } // if ( salome actor )
135 } // if ( lst == vtkPrs->GetObjects() )
142 bool GEOMGUI_Selection::isComponent( const int index ) const
144 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
145 (SUIT_Session::session()->activeApplication()->activeStudy());
147 if ( appStudy && index >= 0 && index < count() ) {
148 _PTR(Study) study = appStudy->studyDS();
149 QString anEntry = entry( index );
151 if ( study && !anEntry.isNull() ) {
152 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
153 if ( aSO && aSO->GetFatherComponent() )
154 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
160 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
162 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
163 (SUIT_Session::session()->activeApplication()->activeStudy());
165 if ( appStudy && index >= 0 && index < count() ) {
166 _PTR(Study) study = appStudy->studyDS();
167 QString anEntry = entry( index );
169 if ( study && !anEntry.isNull() ) {
170 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
172 SALOMEDS_SObject* aDSObj = dynamic_cast<SALOMEDS_SObject*>( aSO.get() );
173 return GEOM::GEOM_Object::_narrow( aDSObj->GetObject() );
177 return GEOM::GEOM_Object::_nil();
180 bool GEOMGUI_Selection::isActiveViewer() const
182 return ( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() != 0 );