Salome HOME
PAL16821 (Check Geometry feature should be hidden to the user)
[modules/geom.git] / src / GEOMGUI / GEOMGUI_Selection.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "GEOMGUI_Selection.h"
21
22 #include "GeometryGUI.h"
23 #include "GEOM_Displayer.h"
24
25 #include <LightApp_DataOwner.h>
26 #include <SalomeApp_Application.h>
27 #include <SalomeApp_Study.h>
28
29 #include <OCCViewer_ViewModel.h>
30
31 #include <SUIT_Session.h>
32 #include <SUIT_ViewWindow.h>
33 #include <SUIT_ViewManager.h>
34 #include <SUIT_ViewModel.h>
35
36 #include <SALOMEDSClient_SObject.hxx>
37 #include <SALOMEDSClient_Study.hxx>
38
39 #include <SALOME_Prs.h>
40 #include <SALOME_InteractiveObject.hxx>
41
42 #include <SOCC_Prs.h>
43 #include <SVTK_Prs.h>
44 #include <SALOME_Actor.h>
45
46 #include <OCCViewer_ViewModel.h>
47 #include <SVTK_ViewModel.h>
48
49 #include "GEOMImpl_Types.hxx"
50
51 // OCCT Includes
52 #include <AIS.hxx>
53 #include <AIS_InteractiveObject.hxx>
54 #include <AIS_ListOfInteractive.hxx>
55
56 // VTK Includes
57 #include <vtkActorCollection.h>
58
59 GEOMGUI_Selection::GEOMGUI_Selection()
60 {
61 }
62
63 GEOMGUI_Selection::~GEOMGUI_Selection()
64 {
65 }
66
67 QtxValue GEOMGUI_Selection::globalParam( const QString& p ) const
68 {
69   if ( p == "isOCC" ) return QtxValue( activeViewType() == OCCViewer_Viewer::Type() );
70   if ( p == "selectionmode" ){ 
71     return QtxValue(selectionMode()); 
72   }
73   return LightApp_Selection::globalParam( p );
74 }
75
76 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
77 {
78 //  if      ( p == "isVisible"   )    return QtxValue( isVisible( ind ) );
79 // parameter isVisible is calculated in base SalomeApp_Selection
80 //  else
81   if( p == "type" )
82     return QtxValue( typeName( ind ) );
83   else if ( p == "displaymode" )
84     return QtxValue( displayMode( ind ) );
85   else
86     return LightApp_Selection::param( ind, p );
87 }
88
89 QString GEOMGUI_Selection::typeName( const int index ) const
90 {
91   if ( isComponent( index ) )
92     return "Component";
93   GEOM::GEOM_Object_var anObj = getObject( index );
94   if ( !CORBA::is_nil( anObj ) ) {
95     const int aGeomType = anObj->GetType();
96     if ( aGeomType == GEOM_GROUP )
97       return "Group";
98     else
99       return "Shape";
100   }
101   return "Unknown";
102 }
103
104 bool GEOMGUI_Selection::isVisible( const int index ) const
105 {
106   GEOM::GEOM_Object_var obj = getObject( index );
107   SALOME_View* view = GEOM_Displayer::GetActiveView();
108   if ( !CORBA::is_nil( obj ) && view ) {
109     Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
110     return view->isVisible( io );
111   }
112   return false;
113 }
114
115 QString GEOMGUI_Selection::displayMode( const int index ) const
116 {
117   SALOME_View* view = GEOM_Displayer::GetActiveView();
118   QString viewType = activeViewType();
119   if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
120     SALOME_Prs* prs = view->CreatePrs( entry( index ) );
121     if ( prs ) {
122       if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
123         SOCC_Prs* occPrs = (SOCC_Prs*) prs;
124         AIS_ListOfInteractive lst;
125         occPrs->GetObjects( lst );
126         if ( lst.Extent() ) {
127           Handle(AIS_InteractiveObject) io = lst.First();
128           if ( !io.IsNull() ) {
129             int dm = io->DisplayMode();
130             if ( dm == AIS_WireFrame )
131               return "Wireframe";
132             else if ( dm == AIS_Shaded )
133               return "Shading";
134             else { // return default display mode of AIS_InteractiveContext
135               OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
136                                             )->activeWindow()->getViewManager()->getViewModel();
137               Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
138               dm = ic->DisplayMode();
139               if ( dm == AIS_WireFrame )
140                 return "Wireframe";
141               else if ( dm == AIS_Shaded )
142                 return "Shading";
143             }
144           }
145         }
146       }
147       else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
148         SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
149         vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
150         if ( lst ) {
151           lst->InitTraversal();
152           vtkActor* actor = lst->GetNextActor();
153           if ( actor ) {
154             SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
155             if ( salActor ) {
156               int dm = salActor->getDisplayMode();
157               if ( dm == 0 )
158                 return "Wireframe";
159               else if ( dm == 1 )
160                 return "Shading";
161             } // if ( salome actor )
162           } // if ( actor )
163         } // if ( lst == vtkPrs->GetObjects() )
164       } // if VTK
165     }
166   }
167   return "";
168 }
169
170 bool GEOMGUI_Selection::isComponent( const int index ) const
171 {
172   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
173     (SUIT_Session::session()->activeApplication()->activeStudy());
174
175   if ( appStudy && index >= 0 && index < count() )  {
176     _PTR(Study) study = appStudy->studyDS();
177     QString anEntry = entry( index );
178
179     if ( study && !anEntry.isNull() ) {
180       _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
181       if ( aSO && aSO->GetFatherComponent() )
182         return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
183     }
184   }
185   return false;
186 }
187
188 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
189 {
190   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
191     (SUIT_Session::session()->activeApplication()->activeStudy());
192
193   if (appStudy && index >= 0 && index < count()) {
194     _PTR(Study) study = appStudy->studyDS();
195     QString anEntry = entry(index);
196
197     if (study && !anEntry.isNull()) {
198       _PTR(SObject) aSO (study->FindObjectID(anEntry.latin1()));
199       if (aSO) {
200         CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
201         return GEOM::GEOM_Object::_narrow(anObj);
202       }
203     }
204   }
205   return GEOM::GEOM_Object::_nil();
206 }
207
208 QString GEOMGUI_Selection::selectionMode() const
209 {
210   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
211   if (app) {
212     GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
213     if (aGeomGUI) {
214       switch (aGeomGUI->getLocalSelectionMode())
215       {
216         case GEOM_POINT      : return "VERTEX";
217         case GEOM_EDGE       : return "EDGE";
218         case GEOM_WIRE       : return "WIRE";
219         case GEOM_FACE       : return "FACE";
220         case GEOM_SHELL      : return "SHELL";
221         case GEOM_SOLID      : return "SOLID";
222         case GEOM_COMPOUND   : return "COMPOUND";
223         case GEOM_ALLOBJECTS : return "ALL";
224         default: return "";
225       }
226     }
227   }
228   return "";
229 }