]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOMGUI_Selection.cxx
Salome HOME
1d1111eeef7f33e41fe2e94e7d8ddd6b8b614b86
[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( activeViewType() == OCCViewer_Viewer::Type() );
44  
45   return SalomeApp_Selection::globalParam( p );
46 }
47
48 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
49 {
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 ) );
53
54   return SalomeApp_Selection::param( ind, p );
55 }
56
57 QString GEOMGUI_Selection::typeName( const int index ) const
58 {
59   if ( isComponent( index ) )
60     return "Component";
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 )
65       return "Group";
66     else
67       return "Shape";
68   }
69   return "Unknown";
70 }
71
72 bool GEOMGUI_Selection::isVisible( const int index ) const
73 {
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 );
79   }
80   return false;
81 }
82
83 QString GEOMGUI_Selection::displayMode( const int index ) const
84 {
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 ) );
89     if ( prs ) {
90       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
91         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
92         AIS_ListOfInteractive lst;
93         occPrs->GetObjects( lst );
94         if ( lst.Extent() ) {
95           Handle(AIS_InteractiveObject) io = lst.First();
96           if ( !io.IsNull() ) {
97             int dm = io->DisplayMode();
98             if ( dm == AIS_WireFrame )
99               return "Wireframe";
100             else if ( dm == AIS_Shaded )
101               return "Shading";
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 )
108                 return "Wireframe";
109               else if ( dm == AIS_Shaded )
110                 return "Shading";
111             }
112           }
113         }
114       } 
115       else if ( viewType == VTKViewer_Viewer::Type() ) { // assuming VTK
116         SVTK_Prs* vtkPrs = (SVTK_Prs*) prs;
117         vtkActorCollection* lst = vtkPrs->GetObjects();
118         if ( lst ) {
119           lst->InitTraversal();
120           vtkActor* actor = lst->GetNextActor();
121           if ( actor ) {
122             SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
123             if ( salActor ) {
124               int dm = salActor->getDisplayMode();
125               if ( dm == 0 )
126                 return "Wireframe";
127               else if ( dm == 1 ) 
128                 return "Shading";
129             } // if ( salome actor )
130           } // if ( actor )
131         } // if ( lst == vtkPrs->GetObjects() )
132       } // if VTK
133     }
134   }
135   return "";
136 }
137
138 bool GEOMGUI_Selection::isComponent( const int index ) const
139 {
140   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
141     (SUIT_Session::session()->activeApplication()->activeStudy());
142
143   if ( appStudy && index >= 0 && index < count() )  {
144     _PTR(Study) study = appStudy->studyDS();
145     QString anEntry = entry( index );
146
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();
151     }
152   }
153   return false;
154 }
155
156 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
157 {
158   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
159     (SUIT_Session::session()->activeApplication()->activeStudy());
160
161   if ( appStudy && index >= 0 && index < count() )  {
162     _PTR(Study) study = appStudy->studyDS();
163     QString anEntry = entry( index );
164
165     if ( study && !anEntry.isNull() ) { 
166       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
167       if ( aSO ) {
168         SALOMEDS_SObject* aDSObj = dynamic_cast<SALOMEDS_SObject*>( aSO.get() );
169         return GEOM::GEOM_Object::_narrow( aDSObj->GetObject() );
170       }
171     }
172   }
173   return GEOM::GEOM_Object::_nil();
174 }
175