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()
58 : LightApp_Selection()
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 ) );
84 else if ( p == "isAutoColor" )
85 return QVariant( isAutoColor( ind ) );
87 return LightApp_Selection::parameter( ind, p );
90 QString GEOMGUI_Selection::typeName( const int index ) const
92 if ( isComponent( index ) )
94 GEOM::GEOM_Object_var anObj = getObject( index );
95 if ( !CORBA::is_nil( anObj ) ) {
96 const int aGeomType = anObj->GetType();
97 if ( aGeomType == GEOM_GROUP )
105 bool GEOMGUI_Selection::isVisible( const int index ) const
107 GEOM::GEOM_Object_var obj = getObject( index );
108 SALOME_View* view = GEOM_Displayer::GetActiveView();
109 if ( !CORBA::is_nil( obj ) && view ) {
110 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
111 return view->isVisible( io );
116 bool GEOMGUI_Selection::isAutoColor( const int index ) const
118 GEOM::GEOM_Object_var obj = getObject( index );
119 if ( !CORBA::is_nil( obj ) )
120 return obj->GetAutoColor();
124 QString GEOMGUI_Selection::displayMode( const int index ) const
126 SALOME_View* view = GEOM_Displayer::GetActiveView();
127 QString viewType = activeViewType();
128 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
129 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
131 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
132 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
133 AIS_ListOfInteractive lst;
134 occPrs->GetObjects( lst );
135 if ( lst.Extent() ) {
136 Handle(AIS_InteractiveObject) io = lst.First();
137 if ( !io.IsNull() ) {
138 int dm = io->DisplayMode();
139 if ( dm == AIS_WireFrame )
141 else if ( dm == AIS_Shaded )
143 else { // return default display mode of AIS_InteractiveContext
144 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
145 )->activeWindow()->getViewManager()->getViewModel();
146 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
147 dm = ic->DisplayMode();
148 if ( dm == AIS_WireFrame )
150 else if ( dm == AIS_Shaded )
156 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
157 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
158 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
160 lst->InitTraversal();
161 vtkActor* actor = lst->GetNextActor();
163 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
165 int dm = salActor->getDisplayMode();
170 } // if ( salome actor )
172 } // if ( lst == vtkPrs->GetObjects() )
179 bool GEOMGUI_Selection::isComponent( const int index ) const
181 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
182 (SUIT_Session::session()->activeApplication()->activeStudy());
184 if ( appStudy && index >= 0 && index < count() ) {
185 _PTR(Study) study = appStudy->studyDS();
186 QString anEntry = entry( index );
188 if ( study && !anEntry.isNull() ) {
189 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
190 if ( aSO && aSO->GetFatherComponent() )
191 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
197 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
199 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
200 (SUIT_Session::session()->activeApplication()->activeStudy());
202 if (appStudy && index >= 0 && index < count()) {
203 _PTR(Study) study = appStudy->studyDS();
204 QString anEntry = entry(index);
206 if (study && !anEntry.isNull()) {
207 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
209 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
210 return GEOM::GEOM_Object::_narrow(anObj);
214 return GEOM::GEOM_Object::_nil();
217 QString GEOMGUI_Selection::selectionMode() const
219 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
221 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
223 switch (aGeomGUI->getLocalSelectionMode())
225 case GEOM_POINT : return "VERTEX";
226 case GEOM_EDGE : return "EDGE";
227 case GEOM_WIRE : return "WIRE";
228 case GEOM_FACE : return "FACE";
229 case GEOM_SHELL : return "SHELL";
230 case GEOM_SOLID : return "SOLID";
231 case GEOM_COMPOUND : return "COMPOUND";
232 case GEOM_ALLOBJECTS : return "ALL";