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 // File : GEOMGUI_Selection.cxx
23 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S. (alexander.solovyov@opencascade.com)
25 #include "GEOMGUI_Selection.h"
27 #include "GeometryGUI.h"
28 #include "GEOM_Displayer.h"
30 #include <SalomeApp_Application.h>
31 #include <SalomeApp_Study.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
38 #include <SALOME_Prs.h>
39 #include <SALOME_InteractiveObject.hxx>
43 #include <SALOME_Actor.h>
44 #include <GEOM_Actor.h>
46 #include <OCCViewer_ViewModel.h>
47 #include <SVTK_ViewModel.h>
49 #include <GEOMImpl_Types.hxx>
51 #include <GEOM_AISShape.hxx>
55 #include <AIS_InteractiveObject.hxx>
56 #include <AIS_ListOfInteractive.hxx>
59 #include <vtkActorCollection.h>
61 GEOMGUI_Selection::GEOMGUI_Selection()
62 : LightApp_Selection()
66 GEOMGUI_Selection::~GEOMGUI_Selection()
70 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
72 if ( p == "isOCC" ) return QVariant( activeViewType() == OCCViewer_Viewer::Type() );
73 if ( p == "selectionmode" ){
74 return QVariant(selectionMode());
76 return LightApp_Selection::parameter( p );
79 QVariant GEOMGUI_Selection::parameter( const int ind, const QString& p ) const
81 // if ( p == "isVisible" ) return QVariant( isVisible( ind ) );
82 // parameter isVisible is calculated in base SalomeApp_Selection
85 return QVariant( typeName( ind ) );
86 else if ( p == "displaymode" )
87 return QVariant( displayMode( ind ) );
88 else if ( p == "isAutoColor" )
89 return QVariant( isAutoColor( ind ) );
90 else if ( p == "isVectorsMode" )
91 return QVariant( isVectorsMode( ind ) );
92 else if ( p == "hasHiddenChildren" )
93 return QVariant( hasHiddenChildren( ind ) );
94 else if ( p == "hasShownChildren" )
95 return QVariant( hasShownChildren( ind ) );
97 return LightApp_Selection::parameter( ind, p );
100 QString GEOMGUI_Selection::typeName( const int index ) const
102 if ( isComponent( index ) )
104 GEOM::GEOM_Object_var anObj = getObject( index );
105 if ( !CORBA::is_nil( anObj ) ) {
106 const int aGeomType = anObj->GetType();
107 if ( aGeomType == GEOM_GROUP )
115 bool GEOMGUI_Selection::isVisible( const int index ) const
117 GEOM::GEOM_Object_var obj = getObject( index );
118 SALOME_View* view = GEOM_Displayer::GetActiveView();
119 if ( !CORBA::is_nil( obj ) && view ) {
120 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
121 return view->isVisible( io );
126 bool GEOMGUI_Selection::isAutoColor( const int index ) const
128 GEOM::GEOM_Object_var obj = getObject( index );
129 if ( !CORBA::is_nil( obj ) )
130 return obj->GetAutoColor();
134 QString GEOMGUI_Selection::displayMode( const int index ) const
136 SALOME_View* view = GEOM_Displayer::GetActiveView();
137 QString viewType = activeViewType();
138 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
139 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
141 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
142 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
143 AIS_ListOfInteractive lst;
144 occPrs->GetObjects( lst );
145 if ( lst.Extent() ) {
146 Handle(AIS_InteractiveObject) io = lst.First();
147 if ( !io.IsNull() ) {
148 int dm = io->DisplayMode();
149 if ( dm == AIS_WireFrame )
151 else if ( dm == AIS_Shaded )
153 else { // return default display mode of AIS_InteractiveContext
154 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
155 )->activeWindow()->getViewManager()->getViewModel();
156 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
157 dm = ic->DisplayMode();
158 if ( dm == AIS_WireFrame )
160 else if ( dm == AIS_Shaded )
166 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
167 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
168 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
170 lst->InitTraversal();
171 vtkActor* actor = lst->GetNextActor();
173 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
175 int dm = salActor->getDisplayMode();
180 } // if ( salome actor )
182 } // if ( lst == vtkPrs->GetObjects() )
189 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
192 SALOME_View* view = GEOM_Displayer::GetActiveView();
193 QString viewType = activeViewType();
194 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
195 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
197 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
198 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
199 AIS_ListOfInteractive lst;
200 occPrs->GetObjects( lst );
201 if ( lst.Extent() ) {
202 Handle(AIS_InteractiveObject) io = lst.First();
203 if ( !io.IsNull() ) {
204 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
205 ret = aSh->isShowVectors();
208 } else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
209 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
210 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
212 lst->InitTraversal();
213 vtkActor* actor = lst->GetNextActor();
215 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
217 ret = aGeomActor->GetVectorMode();
226 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
230 _PTR(ChildIterator) it ( obj->GetStudy()->NewChildIterator( obj ) );
231 for ( ; it->More() && !ok; it->Next() ) {
232 _PTR(SObject) child = it->Value();
234 _PTR(SObject) refObj;
235 if ( child->ReferencedObject( refObj ) ) continue; // omit references
236 if ( child->GetName() != "" ) ok = true;
243 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
246 _PTR(GenericAttribute) anAttr;
247 if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
248 _PTR(AttributeExpandable) aAttrExp = anAttr;
249 exp = aAttrExp->IsExpandable();
254 bool GEOMGUI_Selection::hasHiddenChildren( const int index ) const
257 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
258 (SUIT_Session::session()->activeApplication()->activeStudy());
260 if ( appStudy && index >= 0 && index < count() ) {
261 _PTR(Study) study = appStudy->studyDS();
262 QString anEntry = entry( index );
264 if ( study && !anEntry.isEmpty() ) {
265 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
266 OK = !expandable( aSO ) && hasChildren( aSO );
272 bool GEOMGUI_Selection::hasShownChildren( const int index ) const
275 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
276 (SUIT_Session::session()->activeApplication()->activeStudy());
278 if ( appStudy && index >= 0 && index < count() ) {
279 _PTR(Study) study = appStudy->studyDS();
280 QString anEntry = entry( index );
282 if ( study && !anEntry.isEmpty() ) {
283 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
284 OK = expandable( aSO ) && hasChildren( aSO );
290 bool GEOMGUI_Selection::isComponent( const int index ) const
292 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
293 (SUIT_Session::session()->activeApplication()->activeStudy());
295 if ( appStudy && index >= 0 && index < count() ) {
296 _PTR(Study) study = appStudy->studyDS();
297 QString anEntry = entry( index );
299 if ( study && !anEntry.isNull() ) {
300 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
301 if ( aSO && aSO->GetFatherComponent() )
302 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
308 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
310 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
311 (SUIT_Session::session()->activeApplication()->activeStudy());
313 if (appStudy && index >= 0 && index < count()) {
314 _PTR(Study) study = appStudy->studyDS();
315 QString anEntry = entry(index);
317 if (study && !anEntry.isNull()) {
318 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
320 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
321 return GEOM::GEOM_Object::_narrow(anObj);
325 return GEOM::GEOM_Object::_nil();
328 QString GEOMGUI_Selection::selectionMode() const
330 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
332 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
334 switch (aGeomGUI->getLocalSelectionMode())
336 case GEOM_POINT : return "VERTEX";
337 case GEOM_EDGE : return "EDGE";
338 case GEOM_WIRE : return "WIRE";
339 case GEOM_FACE : return "FACE";
340 case GEOM_SHELL : return "SHELL";
341 case GEOM_SOLID : return "SOLID";
342 case GEOM_COMPOUND : return "COMPOUND";
343 case GEOM_ALLOBJECTS : return "ALL";