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 #include "GEOMGUI_Selection.h"
22 #include "GeometryGUI.h"
23 #include "GEOM_Displayer.h"
25 #include <SalomeApp_Application.h>
26 #include <SalomeApp_Study.h>
28 #include <SUIT_Desktop.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_ViewWindow.h>
31 #include <SUIT_ViewManager.h>
33 #include <SALOME_Prs.h>
34 #include <SALOME_InteractiveObject.hxx>
38 #include <SALOME_Actor.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <SVTK_ViewModel.h>
43 #include "GEOMImpl_Types.hxx"
47 #include <AIS_InteractiveObject.hxx>
48 #include <AIS_ListOfInteractive.hxx>
51 #include <vtkActorCollection.h>
53 GEOMGUI_Selection::GEOMGUI_Selection( const QString& client, LightApp_SelectionMgr* mgr )
54 :LightApp_Selection( client, mgr )
58 GEOMGUI_Selection::~GEOMGUI_Selection()
62 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
64 if ( p == "isOCC" ) return QVariant( activeViewType() == OCCViewer_Viewer::Type() );
65 if ( p == "selectionmode" ){
66 return QVariant(selectionMode());
68 return LightApp_Selection::parameter( p );
71 QVariant GEOMGUI_Selection::parameter( const int ind, const QString& p ) const
73 // if ( p == "isVisible" ) return QVariant( isVisible( ind ) );
74 // parameter isVisible is calculated in base SalomeApp_Selection
77 return QVariant( typeName( ind ) );
78 else if ( p == "displaymode" )
79 return QVariant( displayMode( ind ) );
81 return LightApp_Selection::parameter( ind, p );
84 QString GEOMGUI_Selection::typeName( const int index ) const
86 if ( isComponent( index ) )
88 GEOM::GEOM_Object_var anObj = getObject( index );
89 if ( !CORBA::is_nil( anObj ) ) {
90 const int aGeomType = anObj->GetType();
91 if ( aGeomType == GEOM_GROUP )
99 bool GEOMGUI_Selection::isVisible( const int index ) const
101 GEOM::GEOM_Object_var obj = getObject( index );
102 SALOME_View* view = GEOM_Displayer::GetActiveView();
103 if ( !CORBA::is_nil( obj ) && view ) {
104 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1(), "GEOM", "TEMP_IO" );
105 return view->isVisible( io );
110 QString GEOMGUI_Selection::displayMode( const int index ) const
112 SALOME_View* view = GEOM_Displayer::GetActiveView();
113 QString viewType = activeViewType();
114 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
115 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
117 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
118 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
119 AIS_ListOfInteractive lst;
120 occPrs->GetObjects( lst );
121 if ( lst.Extent() ) {
122 Handle(AIS_InteractiveObject) io = lst.First();
123 if ( !io.IsNull() ) {
124 int dm = io->DisplayMode();
125 if ( dm == AIS_WireFrame )
127 else if ( dm == AIS_Shaded )
129 else { // return default display mode of AIS_InteractiveContext
130 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
131 )->activeWindow()->getViewManager()->getViewModel();
132 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
133 dm = ic->DisplayMode();
134 if ( dm == AIS_WireFrame )
136 else if ( dm == AIS_Shaded )
142 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
143 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
144 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
146 lst->InitTraversal();
147 vtkActor* actor = lst->GetNextActor();
149 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
151 int dm = salActor->getDisplayMode();
156 } // if ( salome actor )
158 } // if ( lst == vtkPrs->GetObjects() )
165 bool GEOMGUI_Selection::isComponent( const int index ) const
167 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
168 (SUIT_Session::session()->activeApplication()->activeStudy());
170 if ( appStudy && index >= 0 && index < count() ) {
171 _PTR(Study) study = appStudy->studyDS();
172 QString anEntry = entry( index );
174 if ( study && !anEntry.isNull() ) {
175 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
176 if ( aSO && aSO->GetFatherComponent() )
177 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
183 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
185 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
186 (SUIT_Session::session()->activeApplication()->activeStudy());
188 if (appStudy && index >= 0 && index < count()) {
189 _PTR(Study) study = appStudy->studyDS();
190 QString anEntry = entry(index);
192 if (study && !anEntry.isNull()) {
193 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
195 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
196 return GEOM::GEOM_Object::_narrow(anObj);
200 return GEOM::GEOM_Object::_nil();
203 QString GEOMGUI_Selection:: selectionMode() const
205 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
207 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
209 switch(aGeomGUI->getLocalSelectionMode())
211 case GEOM_POINT : return "VERTEX";
212 case GEOM_EDGE : return "EDGE";
213 case GEOM_WIRE : return "WIRE";
214 case GEOM_FACE : return "FACE";
215 case GEOM_SHELL : return "SHELL";
216 case GEOM_SOLID : return "SOLID";
217 case GEOM_COMPOUND : return "COMPOUND";
218 case GEOM_ALLOBJECTS : return "ALL";