1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_VisuAsDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_VisuAsDlg.h"
31 #include "VISU_Actor.h"
32 #include "VISU_Prs3d_i.hh"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_RightFrame.h"
37 #include "VTKViewer_ViewFrame.h"
46 VisuGUI_VisuAsDlg::VisuGUI_VisuAsDlg( QWidget* parent, const char* name, bool modal, WFlags fl)
47 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
50 setName( "VisuGUI_VisuAsDlg" );
51 setCaption( tr( "Visualize As" ) );
52 setSizeGripEnabled( TRUE );
54 QVBoxLayout* TopLayout = new QVBoxLayout( this );
55 TopLayout->setSpacing( 6 );
56 TopLayout->setMargin( 11 );
58 TopGroup = new QGroupBox( this, "TopGroup" );
59 TopGroup->setColumnLayout(0, Qt::Vertical );
60 TopGroup->layout()->setSpacing( 0 );
61 TopGroup->layout()->setMargin( 0 );
62 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
63 TopGroupLayout->setAlignment( Qt::AlignTop );
64 TopGroupLayout->setSpacing( 6 );
65 TopGroupLayout->setMargin( 11 );
67 TypeLabel = new QLabel( tr( "Type of Object:" ), TopGroup, "TypeLabel" );
68 TypeCombo = new QComboBox( FALSE, TopGroup, "TypeCombo" );
69 TypeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
70 TypeCombo->setMinimumSize( 150, 0 );
72 ObjectsLabel = new QLabel( tr( "List of Objects" ), TopGroup, "ObjectsLabel" );
73 ObjectsList = new QListBox( TopGroup, "ObjectsList" );
74 ObjectsList->setSelectionMode( QListBox::Single );
75 ObjectsList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
76 ObjectsList->setMinimumSize( 150, 80 );
78 TopGroupLayout->addWidget( TypeLabel, 0, 0 );
79 TopGroupLayout->addWidget( ObjectsLabel, 0, 1 );
80 TopGroupLayout->addWidget( TypeCombo, 1, 0 );
81 TopGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 0 );
82 TopGroupLayout->addMultiCellWidget( ObjectsList, 1, 2, 1, 1 );
84 // Common buttons ===========================================================
85 GroupButtons = new QGroupBox( this, "GroupButtons" );
86 GroupButtons->setColumnLayout(0, Qt::Vertical );
87 GroupButtons->layout()->setSpacing( 0 );
88 GroupButtons->layout()->setMargin( 0 );
89 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
90 GroupButtonsLayout->setAlignment( Qt::AlignTop );
91 GroupButtonsLayout->setSpacing( 6 );
92 GroupButtonsLayout->setMargin( 11 );
94 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
95 buttonOk->setAutoDefault( TRUE );
96 buttonOk->setDefault( TRUE );
97 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
98 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
99 buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
100 buttonCancel->setAutoDefault( TRUE );
101 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
104 TopLayout->addWidget( TopGroup );
105 TopLayout->addWidget( GroupButtons );
107 // signals and slots connections
108 connect( TypeCombo, SIGNAL( activated( const QString& ) ), this, SLOT( RefreshListActors( const QString& ) ) );
109 connect( ObjectsList, SIGNAL( selectionChanged() ), this, SLOT( updateButtonsState() ) );
110 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
111 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
113 addType( tr( "All" ) );
119 VisuGUI_VisuAsDlg::~VisuGUI_VisuAsDlg()
126 void VisuGUI_VisuAsDlg::addType( QString type )
128 int ind = TypeCombo->currentItem();
129 if ( TypeCombo->count() <= 0 ) ind = -1;
130 TypeCombo->insertItem( type );
131 if ( ind != TypeCombo->currentItem() )
132 RefreshListActors( TypeCombo->currentText() );
136 Called when user selects objects type from combo box
138 void VisuGUI_VisuAsDlg::RefreshListActors( const QString &VAType )
141 if ( VAType == QString( "All" ) )
143 else if ( VAType == QString( "Deformed Shape" ) )
144 test = VISU::TDEFORMEDSHAPE;
145 else if ( VAType == QString( "Vectors" ) )
146 test = VISU::TVECTORS;
147 else if ( VAType == QString( "Scalar Map" ) )
148 test = VISU::TSCALARMAP;
149 else if ( VAType == QString( "Iso-Surfaces" ) )
150 test = VISU::TISOSURFACE;
151 else if ( VAType == QString( "Cut Planes" ) )
152 test = VISU::TCUTPLANES;
156 ObjectsList->clear();
158 QAD_Study *myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
159 int nbSf = myActiveStudy->getStudyFramesCount();
160 for ( int i = 0; i < nbSf; i++ ) {
161 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
162 if ( sf->getTypeView() == VIEW_VTK ) {
163 vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
164 vtkActorCollection* ac = aRenderer->GetActors();
166 for( ac->InitTraversal(); ( anActor = ac->GetNextActor() ) != NULL; ) {
167 if ( anActor->IsA( "VISU_Actor" ) ) {
168 VISU_Actor* VISUActor = VISU_Actor::SafeDownCast( anActor );
169 if ( ActorTypeIsValid( VISUActor, test ) )
170 ObjectsList->insertItem( VISUActor->getName() );
175 updateButtonsState();
179 Checks if type of actor is valid according to test value [ static ]
181 bool VisuGUI_VisuAsDlg::ActorTypeIsValid( VISU_Actor* Actor, int test )
183 VISU::Prs3d_i* aPrs3d = Actor->GetPrs3d();
184 if(!aPrs3d) return false;
186 switch(aPrs3d->GetType()){
187 case VISU::TSCALARMAP:
188 case VISU::TISOSURFACE:
189 case VISU::TDEFORMEDSHAPE:
190 case VISU::TCUTPLANES:
191 case VISU::TCUTLINES:
193 case VISU::TSTREAMLINES:
199 return aPrs3d->GetType() == test;
206 QString VisuGUI_VisuAsDlg::getObject()
208 for( int i = 0; i < ObjectsList->count(); i++ ) {
209 if ( ObjectsList->isSelected( i ) ) {
210 return ObjectsList->text( i );
213 return QString::null;
217 Called when selection changed
219 void VisuGUI_VisuAsDlg::updateButtonsState()
221 bool selected = false;
222 for( int i = 0; i < ObjectsList->count(); i++ ) {
223 if ( ObjectsList->isSelected( i ) ) {
228 buttonOk->setEnabled( selected );