]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOMGUI_Selection.cxx
Salome HOME
897b85bb55644526e764167c1e4d6f4faa5971b2
[modules/geom.git] / src / GEOMGUI / GEOMGUI_Selection.cxx
1 #include <OCCViewer_ViewModel.h>
2
3 #include "GEOMGUI_Selection.h"
4 #include "GEOM_Displayer.h"
5 #include "GEOMImpl_Types.hxx"
6
7 #include <SalomeApp_DataOwner.h>
8 #include <SalomeApp_Study.h>
9
10 #include <SUIT_Session.h>
11 #include <SUIT_ViewWindow.h>
12 #include <SUIT_ViewManager.h>
13 #include <SUIT_ViewModel.h>
14
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>
20
21 #include <SOCC_Prs.h>
22 #include <SVTK_Prs.h>
23 #include <SALOME_Actor.h>
24 #include <vtkActorCollection.h>
25
26 #include <OCCViewer_ViewModel.h>
27 #include <VTKViewer_ViewModel.h>
28
29 #include <AIS.hxx>
30 #include <AIS_InteractiveObject.hxx>
31 #include <AIS_ListOfInteractive.hxx>
32
33 GEOMGUI_Selection::GEOMGUI_Selection()
34 {
35 }
36
37 GEOMGUI_Selection::~GEOMGUI_Selection()
38 {
39 }
40
41 QtxValue GEOMGUI_Selection::globalParam( const QString& p ) const
42 {
43   if      ( p == "isOCC"          ) return QtxValue( isOCC() );
44   else if ( p == "isActiveViewer" ) return QtxValue( isActiveViewer() );
45
46   return SalomeApp_Selection::globalParam( p );
47 }
48
49 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
50 {
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 ) );
54
55   return SalomeApp_Selection::param( ind, p );
56 }
57
58 QString GEOMGUI_Selection::typeName( const int index ) const
59 {
60   if ( isComponent( index ) )
61     return "Component";
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 )
66       return "Group";
67     else
68       return "Shape";
69   }
70   return "Unknown";
71 }
72
73 bool GEOMGUI_Selection::isVisible( const int index ) const
74 {
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 );
80   }
81   return false;
82 }
83
84 bool GEOMGUI_Selection::isOCC() const
85 {
86   return activeViewType( OCCViewer_Viewer::Type() );
87 }
88
89 QString GEOMGUI_Selection::displayMode( const int index ) const
90 {
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 ) );
94     if ( prs ) {
95       if ( isOCC() ) { // assuming OCC
96         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
97         AIS_ListOfInteractive lst;
98         occPrs->GetObjects( lst );
99         if ( lst.Extent() ) {
100           Handle(AIS_InteractiveObject) io = lst.First();
101           if ( !io.IsNull() ) {
102             int dm = io->DisplayMode();
103             if ( dm == AIS_WireFrame )
104               return "Wireframe";
105             else if ( dm == AIS_Shaded )
106               return "Shading";
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 )
113                 return "Wireframe";
114               else if ( dm == AIS_Shaded )
115                 return "Shading";
116             }
117           }
118         }
119       } 
120       else if ( activeViewType( VTKViewer_Viewer::Type() ) ) { // assuming VTK
121         SVTK_Prs* vtkPrs = (SVTK_Prs*) prs;
122         vtkActorCollection* lst = vtkPrs->GetObjects();
123         if ( lst ) {
124           lst->InitTraversal();
125           vtkActor* actor = lst->GetNextActor();
126           if ( actor ) {
127             SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
128             if ( salActor ) {
129               int dm = salActor->getDisplayMode();
130               if ( dm == 0 )
131                 return "Wireframe";
132               else if ( dm == 1 ) 
133                 return "Shading";
134             } // if ( salome actor )
135           } // if ( actor )
136         } // if ( lst == vtkPrs->GetObjects() )
137       } // if VTK
138     }
139   }
140   return "";
141 }
142
143 bool GEOMGUI_Selection::isComponent( const int index ) const
144 {
145   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
146     (SUIT_Session::session()->activeApplication()->activeStudy());
147
148   if ( appStudy && index >= 0 && index < count() )  {
149     _PTR(Study) study = appStudy->studyDS();
150     QString anEntry = entry( index );
151
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();
156     }
157   }
158   return false;
159 }
160
161 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
162 {
163   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
164     (SUIT_Session::session()->activeApplication()->activeStudy());
165
166   if ( appStudy && index >= 0 && index < count() )  {
167     _PTR(Study) study = appStudy->studyDS();
168     QString anEntry = entry( index );
169
170     if ( study && !anEntry.isNull() ) { 
171       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
172       if ( aSO ) {
173         SALOMEDS_SObject* aDSObj = dynamic_cast<SALOMEDS_SObject*>( aSO.get() );
174         return GEOM::GEOM_Object::_narrow( aDSObj->GetObject() );
175       }
176     }
177   }
178   return GEOM::GEOM_Object::_nil();
179 }
180
181 SUIT_ViewWindow* activeVW()
182 {
183   SUIT_Session* session = SUIT_Session::session();
184   if ( session ) {
185     SUIT_Application* app = session->activeApplication();
186     if ( app ) {
187       SUIT_Desktop* desk = app->desktop();
188       if ( desk ) 
189         return desk->activeWindow();
190     }
191   }
192   return 0;
193 }
194
195 bool GEOMGUI_Selection::isActiveViewer() const
196 {
197   return ( activeVW() != 0 );
198 }
199
200 bool GEOMGUI_Selection::activeViewType( const QString& type ) const
201 {
202   SUIT_ViewWindow* win = activeVW();
203   if ( win ) {
204     SUIT_ViewManager* vm = win->getViewManager();
205     return ( vm && vm->getType() == type );
206   }
207   return false;
208 }