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 ) );
101 else if ( p == "compoundOfVertices" )
102 return QVariant( compoundOfVertices( ind ) );
104 return LightApp_Selection::parameter( ind, p );
107 // the method to skip temporary objects from selection (called from LightApp)
109 bool GEOMGUI_Selection::processOwner( const LightApp_DataOwner* theOwner)
111 return !theOwner->entry().contains("_");
114 QString GEOMGUI_Selection::typeName( const int index ) const
116 if ( isComponent( index ) )
118 GEOM::GEOM_Object_var anObj = getObject( index );
119 if ( !CORBA::is_nil( anObj ) ) {
120 const int aGeomType = anObj->GetType();
121 if ( aGeomType == GEOM_GROUP )
129 int GEOMGUI_Selection::typeId( const int index ) const
132 GEOM::GEOM_Object_var anObj = getObject( index );
133 if ( !CORBA::is_nil( anObj ) )
134 //aType = anObj->GetType();
135 aType = (int)anObj->GetShapeType();
139 bool GEOMGUI_Selection::isVisible( const int index ) const
141 GEOM::GEOM_Object_var obj = getObject( index );
142 SALOME_View* view = GEOM_Displayer::GetActiveView();
143 if ( !CORBA::is_nil( obj ) && view ) {
144 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).toLatin1().constData(), "GEOM", "TEMP_IO" );
145 return view->isVisible( io );
150 bool GEOMGUI_Selection::isAutoColor( const int index ) const
152 GEOM::GEOM_Object_var obj = getObject( index );
153 if ( !CORBA::is_nil( obj ) )
154 return obj->GetAutoColor();
158 QString GEOMGUI_Selection::displayMode( const int index ) const
160 SALOME_View* view = GEOM_Displayer::GetActiveView();
161 QString viewType = activeViewType();
162 if ( view /*fix for 9320==>*/&& ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
163 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
165 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
166 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
167 AIS_ListOfInteractive lst;
168 occPrs->GetObjects( lst );
169 if ( lst.Extent() ) {
170 Handle(AIS_InteractiveObject) io = lst.First();
171 if ( !io.IsNull() ) {
172 int dm = io->DisplayMode();
173 if ( dm == AIS_WireFrame )
175 else if ( dm == AIS_Shaded )
177 else { // return default display mode of AIS_InteractiveContext
178 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
179 )->activeWindow()->getViewManager()->getViewModel();
180 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
181 dm = ic->DisplayMode();
182 if ( dm == AIS_WireFrame )
184 else if ( dm == AIS_Shaded )
190 else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
191 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
192 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
194 lst->InitTraversal();
195 vtkActor* actor = lst->GetNextActor();
197 SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
199 int dm = salActor->getDisplayMode();
204 } // if ( salome actor )
206 } // if ( lst == vtkPrs->GetObjects() )
213 bool GEOMGUI_Selection::isVectorsMode( const int index ) const
216 SALOME_View* view = GEOM_Displayer::GetActiveView();
217 QString viewType = activeViewType();
218 if ( view && ( viewType == OCCViewer_Viewer::Type() || viewType == SVTK_Viewer::Type() ) ) {
219 SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1().constData() );
221 if ( viewType == OCCViewer_Viewer::Type() ) { // assuming OCC
222 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
223 AIS_ListOfInteractive lst;
224 occPrs->GetObjects( lst );
225 if ( lst.Extent() ) {
226 Handle(AIS_InteractiveObject) io = lst.First();
227 if ( !io.IsNull() ) {
228 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(io);
230 ret = aSh->isShowVectors();
233 } else if ( viewType == SVTK_Viewer::Type() ) { // assuming VTK
234 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
235 vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
237 lst->InitTraversal();
238 vtkActor* actor = lst->GetNextActor();
240 GEOM_Actor* aGeomActor = GEOM_Actor::SafeDownCast(actor);
242 ret = aGeomActor->GetVectorMode();
251 bool GEOMGUI_Selection::hasChildren( const _PTR(SObject)& obj )
255 _PTR(ChildIterator) it ( obj->GetStudy()->NewChildIterator( obj ) );
256 for ( ; it->More() && !ok; it->Next() ) {
257 _PTR(SObject) child = it->Value();
259 _PTR(SObject) refObj;
260 if ( child->ReferencedObject( refObj ) ) continue; // omit references
261 if ( child->GetName() != "" ) ok = true;
268 bool GEOMGUI_Selection::expandable( const _PTR(SObject)& obj )
271 _PTR(GenericAttribute) anAttr;
272 if ( obj && obj->FindAttribute( anAttr, "AttributeExpandable" ) ) {
273 _PTR(AttributeExpandable) aAttrExp = anAttr;
274 exp = aAttrExp->IsExpandable();
279 bool GEOMGUI_Selection::isCompoundOfVertices( GEOM::GEOM_Object_ptr obj )
282 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
283 (SUIT_Session::session()->activeApplication()->activeStudy());
284 if ( appStudy && !CORBA::is_nil( obj ) )
285 ret = obj->GetShapeType() == GEOM::COMPOUND && obj->GetMaxShapeType() == GEOM::VERTEX;
289 bool GEOMGUI_Selection::hasHiddenChildren( 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.isEmpty() ) {
300 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
301 OK = !expandable( aSO ) && hasChildren( aSO );
307 bool GEOMGUI_Selection::hasShownChildren( 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.isEmpty() ) {
318 _PTR(SObject) aSO( study->FindObjectID( anEntry.toStdString() ) );
319 OK = expandable( aSO ) && hasChildren( aSO );
325 bool GEOMGUI_Selection::compoundOfVertices( const int index ) const
327 return isCompoundOfVertices( getObject( index ) );
330 bool GEOMGUI_Selection::isComponent( 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() ) );
341 if ( aSO && aSO->GetFatherComponent() )
342 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
348 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
350 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
351 (SUIT_Session::session()->activeApplication()->activeStudy());
353 if (appStudy && index >= 0 && index < count()) {
354 _PTR(Study) study = appStudy->studyDS();
355 QString anEntry = entry(index);
357 if (study && !anEntry.isNull()) {
358 _PTR(SObject) aSO (study->FindObjectID(anEntry.toStdString()));
360 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSO);
361 return GEOM::GEOM_Object::_narrow(anObj);
365 return GEOM::GEOM_Object::_nil();
368 QString GEOMGUI_Selection::selectionMode() const
370 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
372 GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
374 switch (aGeomGUI->getLocalSelectionMode())
376 case GEOM_POINT : return "VERTEX";
377 case GEOM_EDGE : return "EDGE";
378 case GEOM_WIRE : return "WIRE";
379 case GEOM_FACE : return "FACE";
380 case GEOM_SHELL : return "SHELL";
381 case GEOM_SOLID : return "SOLID";
382 case GEOM_COMPOUND : return "COMPOUND";
383 case GEOM_ALLOBJECTS : return "ALL";