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 "LightApp_DataOwner.h"
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ViewWindow.h>
38 #include <SUIT_ViewManager.h>
40 #include <SALOME_Prs.h>
41 #include <SALOME_InteractiveObject.hxx>
45 #include <SALOME_Actor.h>
46 #include <GEOM_Actor.h>
48 #include <OCCViewer_ViewModel.h>
49 #include <SVTK_ViewModel.h>
51 #include <GEOMImpl_Types.hxx>
53 #include <GEOM_AISShape.hxx>
57 #include <AIS_InteractiveObject.hxx>
58 #include <AIS_ListOfInteractive.hxx>
61 #include <vtkActorCollection.h>
63 GEOMGUI_Selection::GEOMGUI_Selection()
64 : LightApp_Selection()
68 GEOMGUI_Selection::~GEOMGUI_Selection()
72 QVariant GEOMGUI_Selection::parameter( const QString& p ) const
74 if ( p == "isOCC" ) return QVariant( activeViewType() == OCCViewer_Viewer::Type() );
75 if ( p == "selectionmode" ){
76 return QVariant(selectionMode());
78 return LightApp_Selection::parameter( p );
81 QVariant GEOMGUI_Selection::parameter( const int ind, const QString& p ) const
83 // if ( p == "isVisible" ) return QVariant( isVisible( ind ) );
84 // parameter isVisible is calculated in base SalomeApp_Selection
87 return QVariant( typeName( ind ) );
89 return QVariant( typeId( ind ) );
90 else if ( p == "displaymode" )
91 return QVariant( displayMode( ind ) );
92 else if ( p == "isAutoColor" )
93 return QVariant( isAutoColor( ind ) );
94 else if ( p == "isVectorsMode" )
95 return QVariant( isVectorsMode( ind ) );
96 else if ( p == "hasHiddenChildren" )
97 return QVariant( hasHiddenChildren( ind ) );
98 else if ( p == "hasShownChildren" )
99 return QVariant( hasShownChildren( ind ) );
101 return LightApp_Selection::parameter( ind, p );
104 // the method to skip temporary objects from selection (called from LightApp)
106 bool GEOMGUI_Selection::processOwner( const LightApp_DataOwner* theOwner)
108 return !theOwner->entry().contains("_");
111 QString GEOMGUI_Selection::typeName( const int index ) const
113 if ( isComponent( index ) )
115 GEOM::GEOM_Object_var anObj = getObject( index );
116 if ( !CORBA::is_nil( anObj ) ) {
117 const int aGeomType = anObj->GetType();
118 if ( aGeomType == GEOM_GROUP )
126 int GEOMGUI_Selection::typeId( const int index ) const
129 GEOM::GEOM_Object_var anObj = getObject( index );
130 if ( !CORBA::is_nil( anObj ) )
131 aType = anObj->GetType();
135 bool GEOMGUI_Selection::isVisible( const int index ) const
137 GEOM::GEOM_Object_var obj = getObject( index );
138 SALOME_View* view = GEOM_Displayer::GetActiveView();
139 if ( !CORBA::is_nil( obj ) && view ) {
140 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
141 return view->isVisible( io );
146 bool GEOMGUI_Selection::isAutoColor( const int index ) const
148 GEOM::GEOM_Object_var obj = getObject( index );
149 if ( !CORBA::is_nil( obj ) )
150 return obj->GetAutoColor();
154 QString GEOMGUI_Selection::displayMode( const int index ) const
156 SALOME_View* view = GEOM_Displayer::GetActiveView();
157 QString viewType = activeViewType();
158 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
159 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
161 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
162 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
163 AIS_ListOfInteractive lst;
164 occPrs->GetObjects( lst );
165 if ( lst.Extent() ) {
166 Handle(AIS_InteractiveObject) io = lst.First();
167 if ( !io.IsNull() ) {
168 int dm = io->DisplayMode();
169 if ( dm == AIS_WireFrame )
171 else if ( dm == AIS_Shaded )
173 else { // return default display mode of AIS_InteractiveContext
174 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
175 )->activeWindow()->getViewManager()->getViewModel();
176 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
177 dm = ic->DisplayMode();
178 if ( dm == AIS_WireFrame )
180 else if ( dm == AIS_Shaded )
186 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
187 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
188 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
190 lst->InitTraversal();
191 vtkActor* actor = lst->GetNextActor();
193 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
195 int dm = salActor->getDisplayMode();
200 } // if ( salome actor )
202 } // if ( lst == vtkPrs->GetObjects() )
209 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
212 SALOME_View* view = GEOM_Displayer::GetActiveView();
213 QString viewType = activeViewType();
214 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
215 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
217 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
218 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
219 AIS_ListOfInteractive lst;
220 occPrs->GetObjects( lst );
221 if ( lst.Extent() ) {
222 Handle(AIS_InteractiveObject) io = lst.First();
223 if ( !io.IsNull() ) {
224 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
226 ret = aSh->isShowVectors();
229 } else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
230 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
231 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
233 lst->InitTraversal();
234 vtkActor* actor = lst->GetNextActor();
236 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
238 ret = aGeomActor->GetVectorMode();
247 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
251 _PTR(ChildIterator) it ( obj->GetStudy()->NewChildIterator( obj ) );
252 for ( ; it->More() && !ok; it->Next() ) {
253 _PTR(SObject) child = it->Value();
255 _PTR(SObject) refObj;
256 if ( child->ReferencedObject( refObj ) ) continue; // omit references
257 if ( child->GetName() != "" ) ok = true;
264 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
267 _PTR(GenericAttribute) anAttr;
268 if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
269 _PTR(AttributeExpandable) aAttrExp = anAttr;
270 exp = aAttrExp->IsExpandable();
275 bool GEOMGUI_Selection::hasHiddenChildren( const int index ) const
278 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
279 (SUIT_Session::session()->activeApplication()->activeStudy());
281 if ( appStudy && index >= 0 && index < count() ) {
282 _PTR(Study) study = appStudy->studyDS();
283 QString anEntry = entry( index );
285 if ( study && !anEntry.isEmpty() ) {
286 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
287 OK = !expandable( aSO ) && hasChildren( aSO );
293 bool GEOMGUI_Selection::hasShownChildren( const int index ) const
296 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
297 (SUIT_Session::session()->activeApplication()->activeStudy());
299 if ( appStudy && index >= 0 && index < count() ) {
300 _PTR(Study) study = appStudy->studyDS();
301 QString anEntry = entry( index );
303 if ( study && !anEntry.isEmpty() ) {
304 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
305 OK = expandable( aSO ) && hasChildren( aSO );
311 bool GEOMGUI_Selection::isComponent( const int index ) const
313 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
314 (SUIT_Session::session()->activeApplication()->activeStudy());
316 if ( appStudy && index >= 0 && index < count() ) {
317 _PTR(Study) study = appStudy->studyDS();
318 QString anEntry = entry( index );
320 if ( study && !anEntry.isNull() ) {
321 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
322 if ( aSO && aSO->GetFatherComponent() )
323 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
329 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
331 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
332 (SUIT_Session::session()->activeApplication()->activeStudy());
334 if (appStudy && index >= 0 && index < count()) {
335 _PTR(Study) study = appStudy->studyDS();
336 QString anEntry = entry(index);
338 if (study && !anEntry.isNull()) {
339 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
341 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
342 return GEOM::GEOM_Object::_narrow(anObj);
346 return GEOM::GEOM_Object::_nil();
349 QString GEOMGUI_Selection::selectionMode() const
351 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
353 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
355 switch (aGeomGUI->getLocalSelectionMode())
357 case GEOM_POINT : return "VERTEX";
358 case GEOM_EDGE : return "EDGE";
359 case GEOM_WIRE : return "WIRE";
360 case GEOM_FACE : return "FACE";
361 case GEOM_SHELL : return "SHELL";
362 case GEOM_SOLID : return "SOLID";
363 case GEOM_COMPOUND : return "COMPOUND";
364 case GEOM_ALLOBJECTS : return "ALL";