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 <LightApp_DataOwner.h>
26 #include <SalomeApp_Study.h>
28 #include <OCCViewer_ViewModel.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ViewWindow.h>
32 #include <SUIT_ViewManager.h>
33 #include <SUIT_ViewModel.h>
35 #include <SALOMEDSClient_SObject.hxx>
36 #include <SALOMEDSClient_Study.hxx>
38 #include <SALOME_Prs.h>
39 #include <SALOME_InteractiveObject.hxx>
43 #include <SALOME_Actor.h>
45 #include <OCCViewer_ViewModel.h>
46 #include <SVTK_ViewModel.h>
48 #include "GEOMImpl_Types.hxx"
52 #include <AIS_InteractiveObject.hxx>
53 #include <AIS_ListOfInteractive.hxx>
56 #include <vtkActorCollection.h>
58 GEOMGUI_Selection::GEOMGUI_Selection()
62 GEOMGUI_Selection::~GEOMGUI_Selection()
66 QtxValue GEOMGUI_Selection::globalParam( const QString& p ) const
68 if ( p == "isOCC" ) return QtxValue( activeViewType() == OCCViewer_Viewer::Type() );
70 return LightApp_Selection::globalParam( p );
73 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
75 // if ( p == "isVisible" ) return QtxValue( isVisible( ind ) );
76 // parameter isVisible is calculated in base SalomeApp_Selection
79 return QtxValue( typeName( ind ) );
80 else if ( p == "displaymode" )
81 return QtxValue( displayMode( ind ) );
83 return LightApp_Selection::param( ind, p );
86 QString GEOMGUI_Selection::typeName( const int index ) const
88 if ( isComponent( index ) )
90 GEOM::GEOM_Object_var anObj = getObject( index );
91 if ( !CORBA::is_nil( anObj ) ) {
92 const int aGeomType = anObj->GetType();
93 if ( aGeomType == GEOM_GROUP )
101 bool GEOMGUI_Selection::isVisible( const int index ) const
103 GEOM::GEOM_Object_var obj = getObject( index );
104 SALOME_View* view = GEOM_Displayer::GetActiveView();
105 if ( !CORBA::is_nil( obj ) && view ) {
106 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
107 return view->isVisible( io );
112 QString GEOMGUI_Selection::displayMode( const int index ) const
114 SALOME_View* view = GEOM_Displayer::GetActiveView();
115 QString viewType = activeViewType();
116 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
117 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
119 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
120 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
121 AIS_ListOfInteractive lst;
122 occPrs->GetObjects( lst );
123 if ( lst.Extent() ) {
124 Handle(AIS_InteractiveObject) io = lst.First();
125 if ( !io.IsNull() ) {
126 int dm = io->DisplayMode();
127 if ( dm == AIS_WireFrame )
129 else if ( dm == AIS_Shaded )
131 else { // return default display mode of AIS_InteractiveContext
132 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
133 )->activeWindow()->getViewManager()->getViewModel();
134 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
135 dm = ic->DisplayMode();
136 if ( dm == AIS_WireFrame )
138 else if ( dm == AIS_Shaded )
144 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
145 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
146 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
148 lst->InitTraversal();
149 vtkActor* actor = lst->GetNextActor();
151 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
153 int dm = salActor->getDisplayMode();
158 } // if ( salome actor )
160 } // if ( lst == vtkPrs->GetObjects() )
167 bool GEOMGUI_Selection::isComponent( const int index ) const
169 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
170 (SUIT_Session::session()->activeApplication()->activeStudy());
172 if ( appStudy && index >= 0 && index < count() ) {
173 _PTR(Study) study = appStudy->studyDS();
174 QString anEntry = entry( index );
176 if ( study && !anEntry.isNull() ) {
177 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
178 if ( aSO && aSO->GetFatherComponent() )
179 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
185 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
187 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
188 (SUIT_Session::session()->activeApplication()->activeStudy());
190 if (appStudy && index >= 0 && index < count()) {
191 _PTR(Study) study = appStudy->studyDS();
192 QString anEntry = entry(index);
194 if (study && !anEntry.isNull()) {
195 _PTR(SObject) aSO (study->FindObjectID(anEntry.latin1()));
197 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
198 return GEOM::GEOM_Object::_narrow(anObj);
202 return GEOM::GEOM_Object::_nil();