1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "GEOMGUI_Selection.h"
24 #include "GeometryGUI.h"
25 #include "GEOM_Displayer.h"
27 #include <LightApp_DataOwner.h>
28 #include <SalomeApp_Application.h>
29 #include <SalomeApp_Study.h>
31 #include <OCCViewer_ViewModel.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ViewWindow.h>
35 #include <SUIT_ViewManager.h>
36 #include <SUIT_ViewModel.h>
38 #include <SALOMEDSClient_SObject.hxx>
39 #include <SALOMEDSClient_Study.hxx>
41 #include <SALOME_Prs.h>
42 #include <SALOME_InteractiveObject.hxx>
46 #include <SALOME_Actor.h>
48 #include <OCCViewer_ViewModel.h>
49 #include <SVTK_ViewModel.h>
51 #include "GEOMImpl_Types.hxx"
55 #include <AIS_InteractiveObject.hxx>
56 #include <AIS_ListOfInteractive.hxx>
59 #include <vtkActorCollection.h>
61 GEOMGUI_Selection::GEOMGUI_Selection()
65 GEOMGUI_Selection::~GEOMGUI_Selection()
69 QtxValue GEOMGUI_Selection::globalParam( const QString& p ) const
71 if ( p == "isOCC" ) return QtxValue( activeViewType() == OCCViewer_Viewer::Type() );
72 if ( p == "selectionmode" ){
73 return QtxValue(selectionMode());
75 return LightApp_Selection::globalParam( p );
78 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
80 // if ( p == "isVisible" ) return QtxValue( isVisible( ind ) );
81 // parameter isVisible is calculated in base SalomeApp_Selection
84 return QtxValue( typeName( ind ) );
85 else if ( p == "displaymode" )
86 return QtxValue( displayMode( ind ) );
87 else if ( p == "isAutoColor" )
88 return QtxValue( isAutoColor( ind ) );
90 return LightApp_Selection::param( ind, p );
93 QString GEOMGUI_Selection::typeName( const int index ) const
95 if ( isComponent( index ) )
97 GEOM::GEOM_Object_var anObj = getObject( index );
98 if ( !CORBA::is_nil( anObj ) ) {
99 const int aGeomType = anObj->GetType();
100 if ( aGeomType == GEOM_GROUP )
108 bool GEOMGUI_Selection::isVisible( const int index ) const
110 GEOM::GEOM_Object_var obj = getObject( index );
111 SALOME_View* view = GEOM_Displayer::GetActiveView();
112 if ( !CORBA::is_nil( obj ) && view ) {
113 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
114 return view->isVisible( io );
119 bool GEOMGUI_Selection::isAutoColor( const int index ) const
121 GEOM::GEOM_Object_var obj = getObject( index );
122 if ( !CORBA::is_nil( obj ) )
123 return obj->GetAutoColor();
127 QString GEOMGUI_Selection::displayMode( const int index ) const
129 SALOME_View* view = GEOM_Displayer::GetActiveView();
130 QString viewType = activeViewType();
131 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
132 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
134 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
135 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
136 AIS_ListOfInteractive lst;
137 occPrs->GetObjects( lst );
138 if ( lst.Extent() ) {
139 Handle(AIS_InteractiveObject) io = lst.First();
140 if ( !io.IsNull() ) {
141 int dm = io->DisplayMode();
142 if ( dm == AIS_WireFrame )
144 else if ( dm == AIS_Shaded )
146 else { // return default display mode of AIS_InteractiveContext
147 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
148 )->activeWindow()->getViewManager()->getViewModel();
149 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
150 dm = ic->DisplayMode();
151 if ( dm == AIS_WireFrame )
153 else if ( dm == AIS_Shaded )
159 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
160 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
161 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
163 lst->InitTraversal();
164 vtkActor* actor = lst->GetNextActor();
166 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
168 int dm = salActor->getDisplayMode();
173 } // if ( salome actor )
175 } // if ( lst == vtkPrs->GetObjects() )
182 bool GEOMGUI_Selection::isComponent( const int index ) const
184 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
185 (SUIT_Session::session()->activeApplication()->activeStudy());
187 if ( appStudy && index >= 0 && index < count() ) {
188 _PTR(Study) study = appStudy->studyDS();
189 QString anEntry = entry( index );
191 if ( study && !anEntry.isNull() ) {
192 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
193 if ( aSO && aSO->GetFatherComponent() )
194 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
200 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
202 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
203 (SUIT_Session::session()->activeApplication()->activeStudy());
205 if (appStudy && index >= 0 && index < count()) {
206 _PTR(Study) study = appStudy->studyDS();
207 QString anEntry = entry(index);
209 if (study && !anEntry.isNull()) {
210 _PTR(SObject) aSO (study->FindObjectID(anEntry.latin1()));
212 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
213 return GEOM::GEOM_Object::_narrow(anObj);
217 return GEOM::GEOM_Object::_nil();
220 QString GEOMGUI_Selection::selectionMode() const
222 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
224 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
226 switch (aGeomGUI->getLocalSelectionMode())
228 case GEOM_POINT : return "VERTEX";
229 case GEOM_EDGE : return "EDGE";
230 case GEOM_WIRE : return "WIRE";
231 case GEOM_FACE : return "FACE";
232 case GEOM_SHELL : return "SHELL";
233 case GEOM_SOLID : return "SOLID";
234 case GEOM_COMPOUND : return "COMPOUND";
235 case GEOM_ALLOBJECTS : return "ALL";