Salome HOME
Example of a c++ component with engine from Salome tutorial
[samples/atomsolv.git] / src / ATOMSOLVGUI / ATOMSOLVGUI_Selection.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include "ATOMSOLVGUI_Selection.h"
23
24 #include <LightApp_DataOwner.h>
25 #include <LightApp_Displayer.h>
26 #include <SalomeApp_Study.h>
27
28 #include <OCCViewer_ViewModel.h>
29
30 #include <SUIT_Session.h>
31 #include <SUIT_ViewWindow.h>
32 #include <SUIT_ViewManager.h>
33 #include <SUIT_ViewModel.h>
34
35 #include <SALOMEDSClient_SObject.hxx>
36 #include <SALOMEDSClient_Study.hxx>
37
38 #include <SALOME_Prs.h>
39 #include <SALOME_InteractiveObject.hxx>
40
41 #include <SVTK_Prs.h>
42 #include <SALOME_Actor.h>
43
44 #include <SVTK_ViewModel.h>
45
46
47 // VTK Includes
48 #include <vtkActorCollection.h>
49
50 ATOMSOLVGUI_Selection::ATOMSOLVGUI_Selection()
51 {
52 }
53
54 ATOMSOLVGUI_Selection::~ATOMSOLVGUI_Selection()
55 {
56 }
57
58 QVariant ATOMSOLVGUI_Selection::parameter( const int ind, const QString& p ) const
59 {
60   if ( p == "displaymode" )
61     return QVariant( displayMode( ind ) );
62   
63   return LightApp_Selection::parameter( ind, p );
64 }
65
66 QString ATOMSOLVGUI_Selection::displayMode( const int index ) const
67 {
68   SALOME_View* view = LightApp_Displayer::GetActiveView();
69   QString viewType = activeViewType();
70   if ( view && viewType == SVTK_Viewer::Type() ) {
71     if ( SALOME_Prs* prs = view->CreatePrs( entry( index ).toLatin1() ) ) {
72       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
73       vtkActorCollection* lst = vtkPrs ? vtkPrs->GetObjects() : 0;
74       if ( lst ) {
75         lst->InitTraversal();
76         vtkActor* actor = lst->GetNextActor();
77         if ( actor ) {
78           SALOME_Actor* salActor = dynamic_cast<SALOME_Actor*>( actor );
79           if ( salActor ) {
80             int dm = salActor->GetRepresentation();
81             if ( dm == 0 )
82               return "Points";
83             else if ( dm == 1 )
84               return "Wireframe";
85             else if ( dm == 2 )
86               return "Surface";
87           } // if ( salome actor )
88         } // if ( actor )
89       } // if ( lst == vtkPrs->GetObjects() )
90     }
91   }
92   return "Undefined";
93 }
94