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 ) );
87 return QVariant( typeId( ind ) );
88 else if ( p == "displaymode" )
89 return QVariant( displayMode( ind ) );
90 else if ( p == "isAutoColor" )
91 return QVariant( isAutoColor( ind ) );
92 else if ( p == "isVectorsMode" )
93 return QVariant( isVectorsMode( ind ) );
94 else if ( p == "hasHiddenChildren" )
95 return QVariant( hasHiddenChildren( ind ) );
96 else if ( p == "hasShownChildren" )
97 return QVariant( hasShownChildren( ind ) );
99 return LightApp_Selection::parameter( ind, p );
102 QString GEOMGUI_Selection::typeName( const int index ) const
104 if ( isComponent( index ) )
106 GEOM::GEOM_Object_var anObj = getObject( index );
107 if ( !CORBA::is_nil( anObj ) ) {
108 const int aGeomType = anObj->GetType();
109 if ( aGeomType == GEOM_GROUP )
117 int GEOMGUI_Selection::typeId( const int index ) const
120 GEOM::GEOM_Object_var anObj = getObject( index );
121 if ( !CORBA::is_nil( anObj ) )
122 aType = anObj->GetType();
126 bool GEOMGUI_Selection::isVisible( const int index ) const
128 GEOM::GEOM_Object_var obj = getObject( index );
129 SALOME_View* view = GEOM_Displayer::GetActiveView();
130 if ( !CORBA::is_nil( obj ) && view ) {
131 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
132 return view->isVisible( io );
137 bool GEOMGUI_Selection::isAutoColor( const int index ) const
139 GEOM::GEOM_Object_var obj = getObject( index );
140 if ( !CORBA::is_nil( obj ) )
141 return obj->GetAutoColor();
145 QString GEOMGUI_Selection::displayMode( const int index ) const
147 SALOME_View* view = GEOM_Displayer::GetActiveView();
148 QString viewType = activeViewType();
149 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
150 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
152 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
153 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
154 AIS_ListOfInteractive lst;
155 occPrs->GetObjects( lst );
156 if ( lst.Extent() ) {
157 Handle(AIS_InteractiveObject) io = lst.First();
158 if ( !io.IsNull() ) {
159 int dm = io->DisplayMode();
160 if ( dm == AIS_WireFrame )
162 else if ( dm == AIS_Shaded )
164 else { // return default display mode of AIS_InteractiveContext
165 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
166 )->activeWindow()->getViewManager()->getViewModel();
167 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
168 dm = ic->DisplayMode();
169 if ( dm == AIS_WireFrame )
171 else if ( dm == AIS_Shaded )
177 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
178 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
179 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
181 lst->InitTraversal();
182 vtkActor* actor = lst->GetNextActor();
184 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
186 int dm = salActor->getDisplayMode();
191 } // if ( salome actor )
193 } // if ( lst == vtkPrs->GetObjects() )
200 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
203 SALOME_View* view = GEOM_Displayer::GetActiveView();
204 QString viewType = activeViewType();
205 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
206 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
208 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
209 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
210 AIS_ListOfInteractive lst;
211 occPrs->GetObjects( lst );
212 if ( lst.Extent() ) {
213 Handle(AIS_InteractiveObject) io = lst.First();
214 if ( !io.IsNull() ) {
215 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
217 ret = aSh->isShowVectors();
220 } else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
221 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
222 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
224 lst->InitTraversal();
225 vtkActor* actor = lst->GetNextActor();
227 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
229 ret = aGeomActor->GetVectorMode();
238 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
242 _PTR(ChildIterator) it ( obj->GetStudy()->NewChildIterator( obj ) );
243 for ( ; it->More() && !ok; it->Next() ) {
244 _PTR(SObject) child = it->Value();
246 _PTR(SObject) refObj;
247 if ( child->ReferencedObject( refObj ) ) continue; // omit references
248 if ( child->GetName() != "" ) ok = true;
255 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
258 _PTR(GenericAttribute) anAttr;
259 if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
260 _PTR(AttributeExpandable) aAttrExp = anAttr;
261 exp = aAttrExp->IsExpandable();
266 bool GEOMGUI_Selection::hasHiddenChildren( const int index ) const
269 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
270 (SUIT_Session::session()->activeApplication()->activeStudy());
272 if ( appStudy && index >= 0 && index < count() ) {
273 _PTR(Study) study = appStudy->studyDS();
274 QString anEntry = entry( index );
276 if ( study && !anEntry.isEmpty() ) {
277 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
278 OK = !expandable( aSO ) && hasChildren( aSO );
284 bool GEOMGUI_Selection::hasShownChildren( const int index ) const
287 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
288 (SUIT_Session::session()->activeApplication()->activeStudy());
290 if ( appStudy && index >= 0 && index < count() ) {
291 _PTR(Study) study = appStudy->studyDS();
292 QString anEntry = entry( index );
294 if ( study && !anEntry.isEmpty() ) {
295 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
296 OK = expandable( aSO ) && hasChildren( aSO );
302 bool GEOMGUI_Selection::isComponent( const int index ) const
304 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
305 (SUIT_Session::session()->activeApplication()->activeStudy());
307 if ( appStudy && index >= 0 && index < count() ) {
308 _PTR(Study) study = appStudy->studyDS();
309 QString anEntry = entry( index );
311 if ( study && !anEntry.isNull() ) {
312 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
313 if ( aSO && aSO->GetFatherComponent() )
314 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
320 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
322 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
323 (SUIT_Session::session()->activeApplication()->activeStudy());
325 if (appStudy && index >= 0 && index < count()) {
326 _PTR(Study) study = appStudy->studyDS();
327 QString anEntry = entry(index);
329 if (study && !anEntry.isNull()) {
330 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
332 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
333 return GEOM::GEOM_Object::_narrow(anObj);
337 return GEOM::GEOM_Object::_nil();
340 QString GEOMGUI_Selection::selectionMode() const
342 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
344 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
346 switch (aGeomGUI->getLocalSelectionMode())
348 case GEOM_POINT : return "VERTEX";
349 case GEOM_EDGE : return "EDGE";
350 case GEOM_WIRE : return "WIRE";
351 case GEOM_FACE : return "FACE";
352 case GEOM_SHELL : return "SHELL";
353 case GEOM_SOLID : return "SOLID";
354 case GEOM_COMPOUND : return "COMPOUND";
355 case GEOM_ALLOBJECTS : return "ALL";