1 #include "GEOMGUI_Selection.h"
3 #include "GeometryGUI.h"
4 #include "GEOM_Displayer.h"
6 #include <SalomeApp_DataOwner.h>
7 #include <SalomeApp_Study.h>
9 #include <OCCViewer_ViewModel.h>
11 #include <SUIT_Session.h>
12 #include <SUIT_ViewWindow.h>
13 #include <SUIT_ViewManager.h>
14 #include <SUIT_ViewModel.h>
16 #include <SALOMEDSClient_SObject.hxx>
17 #include <SALOMEDSClient_Study.hxx>
19 #include <SALOME_Prs.h>
20 #include <SALOME_InteractiveObject.hxx>
24 #include <SALOME_Actor.h>
26 #include <OCCViewer_ViewModel.h>
27 #include <VTKViewer_ViewModel.h>
29 #include "GEOMImpl_Types.hxx"
33 #include <AIS_InteractiveObject.hxx>
34 #include <AIS_ListOfInteractive.hxx>
37 #include <vtkActorCollection.h>
39 GEOMGUI_Selection::GEOMGUI_Selection()
43 GEOMGUI_Selection::~GEOMGUI_Selection()
47 QtxValue GEOMGUI_Selection::globalParam( const QString& p ) const
49 if ( p == "isOCC" ) return QtxValue( activeViewType() == OCCViewer_Viewer::Type() );
51 return SalomeApp_Selection::globalParam( p );
54 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
56 // if ( p == "isVisible" ) return QtxValue( isVisible( ind ) );
57 // parameter isVisible is calculated in base SalomeApp_Selection
60 return QtxValue( typeName( ind ) );
61 else if ( p == "displaymode" )
62 return QtxValue( displayMode( ind ) );
64 return SalomeApp_Selection::param( ind, p );
67 QString GEOMGUI_Selection::typeName( const int index ) const
69 if ( isComponent( index ) )
71 GEOM::GEOM_Object_var anObj = getObject( index );
72 if ( !CORBA::is_nil( anObj ) ) {
73 const int aGeomType = anObj->GetType();
74 if ( aGeomType == GEOM_GROUP )
82 bool GEOMGUI_Selection::isVisible( const int index ) const
84 GEOM::GEOM_Object_var obj = getObject( index );
85 SALOME_View* view = GEOM_Displayer::GetActiveView();
86 if ( !CORBA::is_nil( obj ) && view ) {
87 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
88 return view->isVisible( io );
93 QString GEOMGUI_Selection::displayMode( const int index ) const
95 SALOME_View* view = GEOM_Displayer::GetActiveView();
96 QString viewType = activeViewType();
97 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == VTKViewer_Viewer::Type() ) ) {
98 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
100 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
101 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
102 AIS_ListOfInteractive lst;
103 occPrs->GetObjects( lst );
104 if ( lst.Extent() ) {
105 Handle(AIS_InteractiveObject) io = lst.First();
106 if ( !io.IsNull() ) {
107 int dm = io->DisplayMode();
108 if ( dm == AIS_WireFrame )
110 else if ( dm == AIS_Shaded )
112 else { // return default display mode of AIS_InteractiveContext
113 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
114 )->activeWindow()->getViewManager()->getViewModel();
115 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
116 dm = ic->DisplayMode();
117 if ( dm == AIS_WireFrame )
119 else if ( dm == AIS_Shaded )
125 else if ( viewType == VTKViewer_Viewer::Type() ) { // assuming VTK
126 SVTK_Prs* vtkPrs = (SVTK_Prs*) prs;
127 vtkActorCollection* lst = vtkPrs->GetObjects();
129 lst->InitTraversal();
130 vtkActor* actor = lst->GetNextActor();
132 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
134 int dm = salActor->getDisplayMode();
139 } // if ( salome actor )
141 } // if ( lst == vtkPrs->GetObjects() )
148 bool GEOMGUI_Selection::isComponent( const int index ) const
150 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
151 (SUIT_Session::session()->activeApplication()->activeStudy());
153 if ( appStudy && index >= 0 && index < count() ) {
154 _PTR(Study) study = appStudy->studyDS();
155 QString anEntry = entry( index );
157 if ( study && !anEntry.isNull() ) {
158 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
159 if ( aSO && aSO->GetFatherComponent() )
160 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
166 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
168 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
169 (SUIT_Session::session()->activeApplication()->activeStudy());
171 if (appStudy && index >= 0 && index < count()) {
172 _PTR(Study) study = appStudy->studyDS();
173 QString anEntry = entry(index);
175 if (study && !anEntry.isNull()) {
176 _PTR(SObject) aSO (study->FindObjectID(anEntry.latin1()));
178 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
179 return GEOM::GEOM_Object::_narrow(anObj);
183 return GEOM::GEOM_Object::_nil();