]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GEOMGUI_Selection.cxx
Salome HOME
8896412aaa1981a2de2d4bc7825b8dfe19580652
[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
23 #include <OCCViewer_ViewModel.h>
24
25 #include <AIS.hxx>
26 #include <AIS_InteractiveObject.hxx>
27 #include <AIS_ListOfInteractive.hxx>
28
29 GEOMGUI_Selection::GEOMGUI_Selection()
30 {
31 }
32
33 GEOMGUI_Selection::~GEOMGUI_Selection()
34 {
35 }
36
37 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
38 {
39   QtxValue val( SalomeApp_Selection::param( ind, p ) );
40   if ( !val.isValid() ) {
41     if      ( p == "isVisible"   )  val = QtxValue( isVisible( ind ) );
42     else if ( p == "isOCC"       )  val = QtxValue( isOCC() );
43     else if ( p == "type"        )  val = QtxValue( typeName( ind ) );
44     else if ( p == "displaymode" )  val = QtxValue( displayMode( ind ) );
45   }
46
47   //printf( "--> param() : [%s] = %s\n", p.latin1(), val.toString ().latin1() );
48
49   return val;
50 }
51
52 QString GEOMGUI_Selection::typeName( const int index ) const
53 {
54   if ( isComponent( index ) )
55     return "Component";
56   GEOM::GEOM_Object_var anObj = getObject( index );
57   if ( !CORBA::is_nil( anObj ) ) {
58     const int aGeomType = anObj->GetType();
59     if ( aGeomType == GEOM_GROUP )
60       return "Group";
61     else
62       return "Shape";
63   }
64   return "Unknown";
65 }
66
67 bool GEOMGUI_Selection::isVisible( const int index ) const
68 {
69   GEOM::GEOM_Object_var obj = getObject( index );
70   SALOME_View* view = GEOM_Displayer::GetActiveView();
71   if ( !CORBA::is_nil( obj ) && view ) {
72     Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
73     return view->isVisible( io );
74   }
75   return false;
76 }
77
78 bool GEOMGUI_Selection::isOCC() const
79 {
80   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
81   return ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
82 }
83
84 QString GEOMGUI_Selection::displayMode( const int index ) const
85 {
86   SALOME_View* view = GEOM_Displayer::GetActiveView();
87   if ( view ) {
88     SALOME_Prs* prs = view->CreatePrs( entry( index ) );
89     if ( prs ) {
90       if ( isOCC() ) { // 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 { // assuming VTK
116
117       } 
118     }
119   }
120   return "";
121 }
122
123 bool GEOMGUI_Selection::isComponent( const int index ) const
124 {
125   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
126     (SUIT_Session::session()->activeApplication()->activeStudy());
127
128   if ( appStudy && index >= 0 && index < count() )  {
129     _PTR(Study) study = appStudy->studyDS();
130     QString anEntry = entry( index );
131
132     if ( study && !anEntry.isNull() ) { 
133       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
134       if ( aSO && aSO->GetFatherComponent() ) 
135         return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
136     }
137   }
138   return false;
139 }
140
141 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
142 {
143   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
144     (SUIT_Session::session()->activeApplication()->activeStudy());
145
146   if ( appStudy && index >= 0 && index < count() )  {
147     _PTR(Study) study = appStudy->studyDS();
148     QString anEntry = entry( index );
149
150     if ( study && !anEntry.isNull() ) { 
151       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
152       if ( aSO ) {
153         SALOMEDS_SObject* aDSObj = dynamic_cast<SALOMEDS_SObject*>( aSO.get() );
154         return GEOM::GEOM_Object::_narrow( aDSObj->GetObject() );
155       }
156     }
157   }
158   return GEOM::GEOM_Object::_nil();
159 }