1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : GEOMGUI_Selection.cxx
21 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S. (alexander.solovyov@opencascade.com)
24 #include "GEOMGUI_Selection.h"
26 #include "GeometryGUI.h"
27 #include "GEOM_Displayer.h"
29 #include <SalomeApp_Application.h>
30 #include <SalomeApp_Study.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ViewWindow.h>
35 #include <SUIT_ViewManager.h>
37 #include <SALOME_Prs.h>
38 #include <SALOME_InteractiveObject.hxx>
42 #include <SALOME_Actor.h>
44 #include <OCCViewer_ViewModel.h>
45 #include <SVTK_ViewModel.h>
47 #include <GEOMImpl_Types.hxx>
51 #include <AIS_InteractiveObject.hxx>
52 #include <AIS_ListOfInteractive.hxx>
55 #include <vtkActorCollection.h>
57 GEOMGUI_Selection::GEOMGUI_Selection( const QString& client, LightApp_SelectionMgr* mgr )
58 : LightApp_Selection( client, mgr )
62 GEOMGUI_Selection::~GEOMGUI_Selection()
66 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
68 if ( p == "isOCC" ) return QVariant( activeViewType() == OCCViewer_Viewer::Type() );
69 if ( p == "selectionmode" ){
70 return QVariant(selectionMode());
72 return LightApp_Selection::parameter( p );
75 QVariant GEOMGUI_Selection::parameter( const int ind, const QString& p ) const
77 // if ( p == "isVisible" ) return QVariant( isVisible( ind ) );
78 // parameter isVisible is calculated in base SalomeApp_Selection
81 return QVariant( typeName( ind ) );
82 else if ( p == "displaymode" )
83 return QVariant( displayMode( ind ) );
85 return LightApp_Selection::parameter( ind, p );
88 QString GEOMGUI_Selection::typeName( const int index ) const
90 if ( isComponent( index ) )
92 GEOM::GEOM_Object_var anObj = getObject( index );
93 if ( !CORBA::is_nil( anObj ) ) {
94 const int aGeomType = anObj->GetType();
95 if ( aGeomType == GEOM_GROUP )
103 bool GEOMGUI_Selection::isVisible( const int index ) const
105 GEOM::GEOM_Object_var obj = getObject( index );
106 SALOME_View* view = GEOM_Displayer::GetActiveView();
107 if ( !CORBA::is_nil( obj ) && view ) {
108 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1(), "GEOM", "TEMP_IO" );
109 return view->isVisible( io );
114 QString GEOMGUI_Selection::displayMode( const int index ) const
116 SALOME_View* view = GEOM_Displayer::GetActiveView();
117 QString viewType = activeViewType();
118 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
119 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
121 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
122 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
123 AIS_ListOfInteractive lst;
124 occPrs->GetObjects( lst );
125 if ( lst.Extent() ) {
126 Handle(AIS_InteractiveObject) io = lst.First();
127 if ( !io.IsNull() ) {
128 int dm = io->DisplayMode();
129 if ( dm == AIS_WireFrame )
131 else if ( dm == AIS_Shaded )
133 else { // return default display mode of AIS_InteractiveContext
134 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
135 )->activeWindow()->getViewManager()->getViewModel();
136 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
137 dm = ic->DisplayMode();
138 if ( dm == AIS_WireFrame )
140 else if ( dm == AIS_Shaded )
146 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
147 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
148 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
150 lst->InitTraversal();
151 vtkActor* actor = lst->GetNextActor();
153 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
155 int dm = salActor->getDisplayMode();
160 } // if ( salome actor )
162 } // if ( lst == vtkPrs->GetObjects() )
169 bool GEOMGUI_Selection::isComponent( const int index ) const
171 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
172 (SUIT_Session::session()->activeApplication()->activeStudy());
174 if ( appStudy && index >= 0 && index < count() ) {
175 _PTR(Study) study = appStudy->studyDS();
176 QString anEntry = entry( index );
178 if ( study && !anEntry.isNull() ) {
179 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
180 if ( aSO && aSO->GetFatherComponent() )
181 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
187 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
189 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
190 (SUIT_Session::session()->activeApplication()->activeStudy());
192 if (appStudy && index >= 0 && index < count()) {
193 _PTR(Study) study = appStudy->studyDS();
194 QString anEntry = entry(index);
196 if (study && !anEntry.isNull()) {
197 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
199 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
200 return GEOM::GEOM_Object::_narrow(anObj);
204 return GEOM::GEOM_Object::_nil();
207 QString GEOMGUI_Selection:: selectionMode() const
209 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
211 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
213 switch(aGeomGUI->getLocalSelectionMode())
215 case GEOM_POINT : return "VERTEX";
216 case GEOM_EDGE : return "EDGE";
217 case GEOM_WIRE : return "WIRE";
218 case GEOM_FACE : return "FACE";
219 case GEOM_SHELL : return "SHELL";
220 case GEOM_SOLID : return "SOLID";
221 case GEOM_COMPOUND : return "COMPOUND";
222 case GEOM_ALLOBJECTS : return "ALL";