1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMGUI_Selection.cxx
23 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S. (alexander.solovyov@opencascade.com)
25 #include "GEOMGUI_Selection.h"
27 #include "GeometryGUI.h"
28 #include "GEOM_Displayer.h"
30 #include <SalomeApp_Application.h>
31 #include <SalomeApp_Study.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
38 #include <SALOME_Prs.h>
39 #include <SALOME_InteractiveObject.hxx>
43 #include <SALOME_Actor.h>
44 #include <GEOM_Actor.h>
46 #include <OCCViewer_ViewModel.h>
47 #include <SVTK_ViewModel.h>
49 #include <GEOMImpl_Types.hxx>
51 #include <GEOM_AISShape.hxx>
55 #include <AIS_InteractiveObject.hxx>
56 #include <AIS_ListOfInteractive.hxx>
59 #include <vtkActorCollection.h>
61 GEOMGUI_Selection::GEOMGUI_Selection()
62 : LightApp_Selection()
66 GEOMGUI_Selection::~GEOMGUI_Selection()
70 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
72 if ( p == "isOCC" ) return QVariant( activeViewType() == OCCViewer_Viewer::Type() );
73 if ( p == "selectionmode" ){
74 return QVariant(selectionMode());
76 return LightApp_Selection::parameter( p );
79 QVariant GEOMGUI_Selection::parameter( const int ind, const QString& p ) const
81 // if ( p == "isVisible" ) return QVariant( isVisible( ind ) );
82 // parameter isVisible is calculated in base SalomeApp_Selection
85 return QVariant( typeName( ind ) );
86 else if ( p == "displaymode" )
87 return QVariant( displayMode( ind ) );
88 else if ( p == "isAutoColor" )
89 return QVariant( isAutoColor( ind ) );
90 else if ( p == "isVectorsMode" )
91 return QVariant( isVectorsMode( ind ) );
93 return LightApp_Selection::parameter( ind, p );
96 QString GEOMGUI_Selection::typeName( const int index ) const
98 if ( isComponent( index ) )
100 GEOM::GEOM_Object_var anObj = getObject( index );
101 if ( !CORBA::is_nil( anObj ) ) {
102 const int aGeomType = anObj->GetType();
103 if ( aGeomType == GEOM_GROUP )
111 bool GEOMGUI_Selection::isVisible( const int index ) const
113 GEOM::GEOM_Object_var obj = getObject( index );
114 SALOME_View* view = GEOM_Displayer::GetActiveView();
115 if ( !CORBA::is_nil( obj ) && view ) {
116 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
117 return view->isVisible( io );
122 bool GEOMGUI_Selection::isAutoColor( const int index ) const
124 GEOM::GEOM_Object_var obj = getObject( index );
125 if ( !CORBA::is_nil( obj ) )
126 return obj->GetAutoColor();
130 QString GEOMGUI_Selection::displayMode( const int index ) const
132 SALOME_View* view = GEOM_Displayer::GetActiveView();
133 QString viewType = activeViewType();
134 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
135 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
137 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
138 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
139 AIS_ListOfInteractive lst;
140 occPrs->GetObjects( lst );
141 if ( lst.Extent() ) {
142 Handle(AIS_InteractiveObject) io = lst.First();
143 if ( !io.IsNull() ) {
144 int dm = io->DisplayMode();
145 if ( dm == AIS_WireFrame )
147 else if ( dm == AIS_Shaded )
149 else { // return default display mode of AIS_InteractiveContext
150 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
151 )->activeWindow()->getViewManager()->getViewModel();
152 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
153 dm = ic->DisplayMode();
154 if ( dm == AIS_WireFrame )
156 else if ( dm == AIS_Shaded )
162 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
163 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
164 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
166 lst->InitTraversal();
167 vtkActor* actor = lst->GetNextActor();
169 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
171 int dm = salActor->getDisplayMode();
176 } // if ( salome actor )
178 } // if ( lst == vtkPrs->GetObjects() )
185 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
188 SALOME_View* view = GEOM_Displayer::GetActiveView();
189 QString viewType = activeViewType();
190 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
191 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
193 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
194 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
195 AIS_ListOfInteractive lst;
196 occPrs->GetObjects( lst );
197 if ( lst.Extent() ) {
198 Handle(AIS_InteractiveObject) io = lst.First();
199 if ( !io.IsNull() ) {
200 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
201 ret = aSh->isShowVectors();
204 } else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
205 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
206 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
208 lst->InitTraversal();
209 vtkActor* actor = lst->GetNextActor();
211 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
213 ret = aGeomActor->GetVectorMode();
222 bool GEOMGUI_Selection::isComponent( const int index ) const
224 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
225 (SUIT_Session::session()->activeApplication()->activeStudy());
227 if ( appStudy && index >= 0 && index < count() ) {
228 _PTR(Study) study = appStudy->studyDS();
229 QString anEntry = entry( index );
231 if ( study && !anEntry.isNull() ) {
232 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
233 if ( aSO && aSO->GetFatherComponent() )
234 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
240 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
242 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
243 (SUIT_Session::session()->activeApplication()->activeStudy());
245 if (appStudy && index >= 0 && index < count()) {
246 _PTR(Study) study = appStudy->studyDS();
247 QString anEntry = entry(index);
249 if (study && !anEntry.isNull()) {
250 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
252 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
253 return GEOM::GEOM_Object::_narrow(anObj);
257 return GEOM::GEOM_Object::_nil();
260 QString GEOMGUI_Selection::selectionMode() const
262 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
264 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
266 switch (aGeomGUI->getLocalSelectionMode())
268 case GEOM_POINT : return "VERTEX";
269 case GEOM_EDGE : return "EDGE";
270 case GEOM_WIRE : return "WIRE";
271 case GEOM_FACE : return "FACE";
272 case GEOM_SHELL : return "SHELL";
273 case GEOM_SOLID : return "SOLID";
274 case GEOM_COMPOUND : return "COMPOUND";
275 case GEOM_ALLOBJECTS : return "ALL";