Salome HOME
NRI : Correction 1.1a version.
[modules/visu.git] / src / VISUGUI / VisuGUI_VisuAsDlg.cxx
1 using namespace std;
2 //  File      : VisuGUI_VisuAsDlg.cxx
3 //  Created   : Wed Aug 01 10:23:06 2001
4 //  Author    : Laurent CORNABE & Hubert ROLLAND 
5 //  Project   : SALOME
6 //  Module    : VISUGUI
7 //  Copyright : PRINCIPIA
8 //  $Header$
9
10 #include "VisuGUI_VisuAsDlg.h"
11 #include "QAD_Application.h"
12 #include "QAD_Desktop.h"
13 #include "QAD_RightFrame.h"
14 #include "VTKViewer_ViewFrame.h"
15 #include <qlayout.h>
16
17 /*!
18   Constructor
19 */
20 VisuGUI_VisuAsDlg::VisuGUI_VisuAsDlg( QWidget* parent,  const char* name, bool modal, WFlags fl)
21     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
22 {
23   if ( !name )
24     setName( "VisuGUI_VisuAsDlg" );
25   setCaption( tr( "Visualize As" ) );
26   setSizeGripEnabled( TRUE );
27
28   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
29   TopLayout->setSpacing( 6 );
30   TopLayout->setMargin( 11 );
31
32   TopGroup = new QGroupBox( this, "TopGroup" );
33   TopGroup->setColumnLayout(0, Qt::Vertical );
34   TopGroup->layout()->setSpacing( 0 );
35   TopGroup->layout()->setMargin( 0 );
36   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
37   TopGroupLayout->setAlignment( Qt::AlignTop );
38   TopGroupLayout->setSpacing( 6 );
39   TopGroupLayout->setMargin( 11 );
40
41   TypeLabel = new QLabel( tr( "Type of Object:" ), TopGroup, "TypeLabel" );
42   TypeCombo = new QComboBox( FALSE, TopGroup, "TypeCombo" );
43   TypeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
44   TypeCombo->setMinimumSize( 150, 0 );
45   
46   ObjectsLabel = new QLabel( tr( "List of Objects" ), TopGroup, "ObjectsLabel" );
47   ObjectsList = new QListBox( TopGroup, "ObjectsList" );
48   ObjectsList->setSelectionMode( QListBox::Single );
49   ObjectsList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
50   ObjectsList->setMinimumSize( 150, 80 );
51
52   TopGroupLayout->addWidget( TypeLabel,    0, 0 );
53   TopGroupLayout->addWidget( ObjectsLabel, 0, 1 );
54   TopGroupLayout->addWidget( TypeCombo,    1, 0 );
55   TopGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 0 );
56   TopGroupLayout->addMultiCellWidget( ObjectsList,  1, 2, 1, 1 );
57
58   // Common buttons ===========================================================
59   GroupButtons = new QGroupBox( this, "GroupButtons" );
60   GroupButtons->setColumnLayout(0, Qt::Vertical );
61   GroupButtons->layout()->setSpacing( 0 );
62   GroupButtons->layout()->setMargin( 0 );
63   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
64   GroupButtonsLayout->setAlignment( Qt::AlignTop );
65   GroupButtonsLayout->setSpacing( 6 );
66   GroupButtonsLayout->setMargin( 11 );
67
68   buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
69   buttonOk->setAutoDefault( TRUE );
70   buttonOk->setDefault( TRUE );
71   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
72   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
73   buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
74   buttonCancel->setAutoDefault( TRUE );
75   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
76
77   // top layout
78   TopLayout->addWidget( TopGroup );
79   TopLayout->addWidget( GroupButtons );
80   
81   // signals and slots connections
82   connect( TypeCombo,    SIGNAL( activated( const QString& ) ), this, SLOT( RefreshListActors( const QString& ) ) );
83   connect( ObjectsList,  SIGNAL( selectionChanged() ),          this, SLOT( updateButtonsState() ) );
84   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
85   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
86
87   addType( tr( "All" ) );
88 }
89
90 /*!
91   Destructor
92 */
93 VisuGUI_VisuAsDlg::~VisuGUI_VisuAsDlg()
94 {
95 }
96
97 /*!
98   Adds type
99 */
100 void VisuGUI_VisuAsDlg::addType( QString type )
101 {
102   int ind = TypeCombo->currentItem();
103   if ( TypeCombo->count() <= 0 ) ind = -1;
104   TypeCombo->insertItem( type );
105   if ( ind != TypeCombo->currentItem() )
106     RefreshListActors( TypeCombo->currentText() );
107 }
108
109 /*!
110   Called when user selects objects type from combo box
111 */
112 void VisuGUI_VisuAsDlg::RefreshListActors( const QString &VAType )
113 {
114   int test = 0;
115   if ( VAType == QString( "All" ) ) 
116     test = -1;
117   else if ( VAType == QString( "Deformed Shape" ) )
118     test = VisuActorType_DeformedShape;
119   else if ( VAType == QString( "Vectors" ) )
120     test = VisuActorType_Vectors;
121   else if ( VAType == QString( "Scalar Map" ) )
122     test = VisuActorType_ScalarMap;
123   else if ( VAType == QString( "Iso-Surfaces" ) )
124     test = VisuActorType_IsoSurfaces;
125   else if ( VAType == QString( "Cut Planes" ) )
126     test = VisuActorType_CutPlanes;
127   else
128     return;
129   
130   ObjectsList->clear();
131   
132   QAD_Study *myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
133   int nbSf = myActiveStudy->getStudyFramesCount();
134   for ( int i = 0; i < nbSf; i++ ) {
135     QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
136     if ( sf->getTypeView() == VIEW_VTK ) {
137       vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
138       vtkActorCollection* ac = aRenderer->GetActors();
139       vtkActor *anActor;
140       for( ac->InitTraversal(); ( anActor = ac->GetNextActor() ) != NULL; ) {
141         if ( anActor->IsA( "VISU_Actor" ) ) {
142           VISU_Actor* VISUActor = VISU_Actor::SafeDownCast( anActor );
143           if ( ActorTypeIsValid( VISUActor, test ) )
144             ObjectsList->insertItem( VISUActor->getName() );
145         }
146       }
147     }
148   }
149   updateButtonsState();
150 }
151
152 /*!
153   Checks if type of actor is valid according to test value [ static ]
154 */
155 bool VisuGUI_VisuAsDlg::ActorTypeIsValid( VISU_Actor* Actor, int test )
156 {
157   if( test == -1 ) {
158     if( Actor->VisuActorType < VisuActorType_DeformedShape || 
159         Actor->VisuActorType > VisuActorType_CutPlanes )
160       return false;
161     else
162       return true;
163   }
164   else {
165     if( test < VisuActorType_DeformedShape ||
166         test > VisuActorType_CutPlanes )
167       return false;
168     else {
169       if( Actor->VisuActorType == test)
170         return true;
171       else
172         return false;
173     }
174   }
175 }
176
177 /*!
178   Gets object selected
179 */
180 QString VisuGUI_VisuAsDlg::getObject() 
181 {
182   for( int i = 0; i < ObjectsList->count(); i++ ) {
183     if ( ObjectsList->isSelected( i ) ) {
184       return ObjectsList->text( i );
185     }
186   }
187   return QString::null;
188 }
189
190 /*!
191   Called when selection changed
192 */
193 void VisuGUI_VisuAsDlg::updateButtonsState()
194 {
195   bool selected = false;
196   for( int i = 0; i < ObjectsList->count(); i++ ) {
197     if ( ObjectsList->isSelected( i ) ) {
198       selected = true;
199       break;
200     }
201   }
202   buttonOk->setEnabled( selected );
203 }
204
205
206
207
208