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_Application.h>
27 #include <SalomeApp_Study.h>
29 #include <OCCViewer_ViewModel.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_ViewWindow.h>
33 #include <SUIT_ViewManager.h>
34 #include <SUIT_ViewModel.h>
36 #include <SALOMEDSClient_SObject.hxx>
37 #include <SALOMEDSClient_Study.hxx>
39 #include <SALOME_Prs.h>
40 #include <SALOME_InteractiveObject.hxx>
44 #include <SALOME_Actor.h>
46 #include <OCCViewer_ViewModel.h>
47 #include <SVTK_ViewModel.h>
49 #include "GEOMImpl_Types.hxx"
53 #include <AIS_InteractiveObject.hxx>
54 #include <AIS_ListOfInteractive.hxx>
57 #include <vtkActorCollection.h>
59 GEOMGUI_Selection::GEOMGUI_Selection()
63 GEOMGUI_Selection::~GEOMGUI_Selection()
67 QtxValue GEOMGUI_Selection::globalParam( const QString& p ) const
69 if ( p == "isOCC" ) return QtxValue( activeViewType() == OCCViewer_Viewer::Type() );
70 if ( p == "selectionmode" ){
71 return QtxValue(selectionMode());
73 return LightApp_Selection::globalParam( p );
76 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
78 // if ( p == "isVisible" ) return QtxValue( isVisible( ind ) );
79 // parameter isVisible is calculated in base SalomeApp_Selection
82 return QtxValue( typeName( ind ) );
83 else if ( p == "displaymode" )
84 return QtxValue( displayMode( ind ) );
86 return LightApp_Selection::param( ind, p );
89 QString GEOMGUI_Selection::typeName( const int index ) const
91 if ( isComponent( index ) )
93 GEOM::GEOM_Object_var anObj = getObject( index );
94 if ( !CORBA::is_nil( anObj ) ) {
95 const int aGeomType = anObj->GetType();
96 if ( aGeomType == GEOM_GROUP )
104 bool GEOMGUI_Selection::isVisible( const int index ) const
106 GEOM::GEOM_Object_var obj = getObject( index );
107 SALOME_View* view = GEOM_Displayer::GetActiveView();
108 if ( !CORBA::is_nil( obj ) && view ) {
109 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
110 return view->isVisible( io );
115 QString GEOMGUI_Selection::displayMode( const int index ) const
117 SALOME_View* view = GEOM_Displayer::GetActiveView();
118 QString viewType = activeViewType();
119 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
120 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
122 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
123 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
124 AIS_ListOfInteractive lst;
125 occPrs->GetObjects( lst );
126 if ( lst.Extent() ) {
127 Handle(AIS_InteractiveObject) io = lst.First();
128 if ( !io.IsNull() ) {
129 int dm = io->DisplayMode();
130 if ( dm == AIS_WireFrame )
132 else if ( dm == AIS_Shaded )
134 else { // return default display mode of AIS_InteractiveContext
135 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
136 )->activeWindow()->getViewManager()->getViewModel();
137 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
138 dm = ic->DisplayMode();
139 if ( dm == AIS_WireFrame )
141 else if ( dm == AIS_Shaded )
147 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
148 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
149 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
151 lst->InitTraversal();
152 vtkActor* actor = lst->GetNextActor();
154 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
156 int dm = salActor->getDisplayMode();
161 } // if ( salome actor )
163 } // if ( lst == vtkPrs->GetObjects() )
170 bool GEOMGUI_Selection::isComponent( const int index ) const
172 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
173 (SUIT_Session::session()->activeApplication()->activeStudy());
175 if ( appStudy && index >= 0 && index < count() ) {
176 _PTR(Study) study = appStudy->studyDS();
177 QString anEntry = entry( index );
179 if ( study && !anEntry.isNull() ) {
180 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
181 if ( aSO && aSO->GetFatherComponent() )
182 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
188 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
190 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
191 (SUIT_Session::session()->activeApplication()->activeStudy());
193 if (appStudy && index >= 0 && index < count()) {
194 _PTR(Study) study = appStudy->studyDS();
195 QString anEntry = entry(index);
197 if (study && !anEntry.isNull()) {
198 _PTR(SObject) aSO (study->FindObjectID(anEntry.latin1()));
200 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
201 return GEOM::GEOM_Object::_narrow(anObj);
205 return GEOM::GEOM_Object::_nil();
208 QString GEOMGUI_Selection:: selectionMode() const
210 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
212 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
214 switch(aGeomGUI->getLocalSelectionMode())
216 case GEOM_POINT : return "VERTEX";
217 case GEOM_EDGE : return "EDGE";
218 case GEOM_WIRE : return "WIRE";
219 case GEOM_FACE : return "FACE";
220 case GEOM_SHELL : return "SHELL";
221 case GEOM_SOLID : return "SOLID";
222 case GEOM_COMPOUND : return "COMPOUND";
223 case GEOM_ALLOBJECTS : return "ALL";