1 // Copyright (C) 2007-2010 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
23 // File : GEOMGUI_Selection.cxx
24 // Author : Alexander SOLOVYOV, Open CASCADE S.A.S. (alexander.solovyov@opencascade.com)
26 #include "GEOMGUI_Selection.h"
28 #include "GeometryGUI.h"
29 #include "GEOM_Displayer.h"
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
34 #include "LightApp_DataOwner.h"
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_ViewWindow.h>
39 #include <SUIT_ViewManager.h>
41 #include <SALOME_Prs.h>
42 #include <SALOME_InteractiveObject.hxx>
46 #include <SALOME_Actor.h>
47 #include <GEOM_Actor.h>
49 #include <OCCViewer_ViewModel.h>
50 #include <SVTK_ViewModel.h>
52 #include <GEOMImpl_Types.hxx>
54 #include <GEOM_AISShape.hxx>
58 #include <AIS_InteractiveObject.hxx>
59 #include <AIS_ListOfInteractive.hxx>
62 #include <vtkActorCollection.h>
64 GEOMGUI_Selection::GEOMGUI_Selection()
65 : LightApp_Selection()
69 GEOMGUI_Selection::~GEOMGUI_Selection()
73 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
75 if ( p == "isOCC" ) return QVariant( activeViewType() == OCCViewer_Viewer::Type() );
76 if ( p == "selectionmode" ){
77 return QVariant(selectionMode());
79 return LightApp_Selection::parameter( p );
82 QVariant GEOMGUI_Selection::parameter( const int ind, const QString& p ) const
84 // if ( p == "isVisible" ) return QVariant( isVisible( ind ) );
85 // parameter isVisible is calculated in base SalomeApp_Selection
88 return QVariant( typeName( ind ) );
90 return QVariant( typeId( ind ) );
91 else if ( p == "displaymode" )
92 return QVariant( displayMode( ind ) );
93 else if ( p == "isAutoColor" )
94 return QVariant( isAutoColor( ind ) );
95 else if ( p == "isVectorsMode" )
96 return QVariant( isVectorsMode( ind ) );
97 else if ( p == "hasHiddenChildren" )
98 return QVariant( hasHiddenChildren( ind ) );
99 else if ( p == "hasShownChildren" )
100 return QVariant( hasShownChildren( ind ) );
102 return LightApp_Selection::parameter( ind, p );
105 // the method to skip temporary objects from selection (called from LightApp)
107 bool GEOMGUI_Selection::processOwner( const LightApp_DataOwner* theOwner)
109 return !theOwner->entry().contains("_");
112 QString GEOMGUI_Selection::typeName( const int index ) const
114 if ( isComponent( index ) )
116 GEOM::GEOM_Object_var anObj = getObject( index );
117 if ( !CORBA::is_nil( anObj ) ) {
118 const int aGeomType = anObj->GetType();
119 if ( aGeomType == GEOM_GROUP )
127 int GEOMGUI_Selection::typeId( const int index ) const
130 GEOM::GEOM_Object_var anObj = getObject( index );
131 if ( !CORBA::is_nil( anObj ) )
132 aType = anObj->GetType();
136 bool GEOMGUI_Selection::isVisible( const int index ) const
138 GEOM::GEOM_Object_var obj = getObject( index );
139 SALOME_View* view = GEOM_Displayer::GetActiveView();
140 if ( !CORBA::is_nil( obj ) && view ) {
141 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
142 return view->isVisible( io );
147 bool GEOMGUI_Selection::isAutoColor( const int index ) const
149 GEOM::GEOM_Object_var obj = getObject( index );
150 if ( !CORBA::is_nil( obj ) )
151 return obj->GetAutoColor();
155 QString GEOMGUI_Selection::displayMode( const int index ) const
157 SALOME_View* view = GEOM_Displayer::GetActiveView();
158 QString viewType = activeViewType();
159 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
160 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
162 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
163 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
164 AIS_ListOfInteractive lst;
165 occPrs->GetObjects( lst );
166 if ( lst.Extent() ) {
167 Handle(AIS_InteractiveObject) io = lst.First();
168 if ( !io.IsNull() ) {
169 int dm = io->DisplayMode();
170 if ( dm == AIS_WireFrame )
172 else if ( dm == AIS_Shaded )
174 else { // return default display mode of AIS_InteractiveContext
175 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
176 )->activeWindow()->getViewManager()->getViewModel();
177 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
178 dm = ic->DisplayMode();
179 if ( dm == AIS_WireFrame )
181 else if ( dm == AIS_Shaded )
187 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
188 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
189 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
191 lst->InitTraversal();
192 vtkActor* actor = lst->GetNextActor();
194 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
196 int dm = salActor->getDisplayMode();
201 } // if ( salome actor )
203 } // if ( lst == vtkPrs->GetObjects() )
210 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
213 SALOME_View* view = GEOM_Displayer::GetActiveView();
214 QString viewType = activeViewType();
215 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
216 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
218 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
219 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
220 AIS_ListOfInteractive lst;
221 occPrs->GetObjects( lst );
222 if ( lst.Extent() ) {
223 Handle(AIS_InteractiveObject) io = lst.First();
224 if ( !io.IsNull() ) {
225 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
227 ret = aSh->isShowVectors();
230 } else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
231 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
232 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
234 lst->InitTraversal();
235 vtkActor* actor = lst->GetNextActor();
237 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
239 ret = aGeomActor->GetVectorMode();
248 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
252 _PTR(ChildIterator) it ( obj->GetStudy()->NewChildIterator( obj ) );
253 for ( ; it->More() && !ok; it->Next() ) {
254 _PTR(SObject) child = it->Value();
256 _PTR(SObject) refObj;
257 if ( child->ReferencedObject( refObj ) ) continue; // omit references
258 if ( child->GetName() != "" ) ok = true;
265 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
268 _PTR(GenericAttribute) anAttr;
269 if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
270 _PTR(AttributeExpandable) aAttrExp = anAttr;
271 exp = aAttrExp->IsExpandable();
276 bool GEOMGUI_Selection::hasHiddenChildren( const int index ) const
279 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
280 (SUIT_Session::session()->activeApplication()->activeStudy());
282 if ( appStudy && index >= 0 && index < count() ) {
283 _PTR(Study) study = appStudy->studyDS();
284 QString anEntry = entry( index );
286 if ( study && !anEntry.isEmpty() ) {
287 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
288 OK = !expandable( aSO ) && hasChildren( aSO );
294 bool GEOMGUI_Selection::hasShownChildren( const int index ) const
297 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
298 (SUIT_Session::session()->activeApplication()->activeStudy());
300 if ( appStudy && index >= 0 && index < count() ) {
301 _PTR(Study) study = appStudy->studyDS();
302 QString anEntry = entry( index );
304 if ( study && !anEntry.isEmpty() ) {
305 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
306 OK = expandable( aSO ) && hasChildren( aSO );
312 bool GEOMGUI_Selection::isComponent( const int index ) const
314 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
315 (SUIT_Session::session()->activeApplication()->activeStudy());
317 if ( appStudy && index >= 0 && index < count() ) {
318 _PTR(Study) study = appStudy->studyDS();
319 QString anEntry = entry( index );
321 if ( study && !anEntry.isNull() ) {
322 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
323 if ( aSO && aSO->GetFatherComponent() )
324 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
330 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
332 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
333 (SUIT_Session::session()->activeApplication()->activeStudy());
335 if (appStudy && index >= 0 && index < count()) {
336 _PTR(Study) study = appStudy->studyDS();
337 QString anEntry = entry(index);
339 if (study && !anEntry.isNull()) {
340 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
342 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
343 return GEOM::GEOM_Object::_narrow(anObj);
347 return GEOM::GEOM_Object::_nil();
350 QString GEOMGUI_Selection::selectionMode() const
352 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
354 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
356 switch (aGeomGUI->getLocalSelectionMode())
358 case GEOM_POINT : return "VERTEX";
359 case GEOM_EDGE : return "EDGE";
360 case GEOM_WIRE : return "WIRE";
361 case GEOM_FACE : return "FACE";
362 case GEOM_SHELL : return "SHELL";
363 case GEOM_SOLID : return "SOLID";
364 case GEOM_COMPOUND : return "COMPOUND";
365 case GEOM_ALLOBJECTS : return "ALL";