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 ) );
85 else if ( p == "isAutoColor" )
86 return QtxValue( isAutoColor( ind ) );
88 return LightApp_Selection::param( ind, p );
91 QString GEOMGUI_Selection::typeName( const int index ) const
93 if ( isComponent( index ) )
95 GEOM::GEOM_Object_var anObj = getObject( index );
96 if ( !CORBA::is_nil( anObj ) ) {
97 const int aGeomType = anObj->GetType();
98 if ( aGeomType == GEOM_GROUP )
106 bool GEOMGUI_Selection::isVisible( const int index ) const
108 GEOM::GEOM_Object_var obj = getObject( index );
109 SALOME_View* view = GEOM_Displayer::GetActiveView();
110 if ( !CORBA::is_nil( obj ) && view ) {
111 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
112 return view->isVisible( io );
117 bool GEOMGUI_Selection::isAutoColor( const int index ) const
119 GEOM::GEOM_Object_var obj = getObject( index );
120 if ( !CORBA::is_nil( obj ) )
121 return obj->GetAutoColor();
125 QString GEOMGUI_Selection::displayMode( const int index ) const
127 SALOME_View* view = GEOM_Displayer::GetActiveView();
128 QString viewType = activeViewType();
129 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
130 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
132 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
133 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
134 AIS_ListOfInteractive lst;
135 occPrs->GetObjects( lst );
136 if ( lst.Extent() ) {
137 Handle(AIS_InteractiveObject) io = lst.First();
138 if ( !io.IsNull() ) {
139 int dm = io->DisplayMode();
140 if ( dm == AIS_WireFrame )
142 else if ( dm == AIS_Shaded )
144 else { // return default display mode of AIS_InteractiveContext
145 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
146 )->activeWindow()->getViewManager()->getViewModel();
147 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
148 dm = ic->DisplayMode();
149 if ( dm == AIS_WireFrame )
151 else if ( dm == AIS_Shaded )
157 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
158 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
159 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
161 lst->InitTraversal();
162 vtkActor* actor = lst->GetNextActor();
164 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
166 int dm = salActor->getDisplayMode();
171 } // if ( salome actor )
173 } // if ( lst == vtkPrs->GetObjects() )
180 bool GEOMGUI_Selection::isComponent( const int index ) const
182 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
183 (SUIT_Session::session()->activeApplication()->activeStudy());
185 if ( appStudy && index >= 0 && index < count() ) {
186 _PTR(Study) study = appStudy->studyDS();
187 QString anEntry = entry( index );
189 if ( study && !anEntry.isNull() ) {
190 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
191 if ( aSO && aSO->GetFatherComponent() )
192 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
198 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
200 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
201 (SUIT_Session::session()->activeApplication()->activeStudy());
203 if (appStudy && index >= 0 && index < count()) {
204 _PTR(Study) study = appStudy->studyDS();
205 QString anEntry = entry(index);
207 if (study && !anEntry.isNull()) {
208 _PTR(SObject) aSO (study->FindObjectID(anEntry.latin1()));
210 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
211 return GEOM::GEOM_Object::_narrow(anObj);
215 return GEOM::GEOM_Object::_nil();
218 QString GEOMGUI_Selection::selectionMode() const
220 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
222 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
224 switch (aGeomGUI->getLocalSelectionMode())
226 case GEOM_POINT : return "VERTEX";
227 case GEOM_EDGE : return "EDGE";
228 case GEOM_WIRE : return "WIRE";
229 case GEOM_FACE : return "FACE";
230 case GEOM_SHELL : return "SHELL";
231 case GEOM_SOLID : return "SOLID";
232 case GEOM_COMPOUND : return "COMPOUND";
233 case GEOM_ALLOBJECTS : return "ALL";