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
30 #include "VisuGUI_VisuAsDlg.h"
31 #include "VISU_PrsObject_i.hh"
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_RightFrame.h"
35 #include "VTKViewer_ViewFrame.h"
41 VisuGUI_VisuAsDlg::VisuGUI_VisuAsDlg( QWidget* parent, const char* name, bool modal, WFlags fl)
42 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
45 setName( "VisuGUI_VisuAsDlg" );
46 setCaption( tr( "Visualize As" ) );
47 setSizeGripEnabled( TRUE );
49 QVBoxLayout* TopLayout = new QVBoxLayout( this );
50 TopLayout->setSpacing( 6 );
51 TopLayout->setMargin( 11 );
53 TopGroup = new QGroupBox( this, "TopGroup" );
54 TopGroup->setColumnLayout(0, Qt::Vertical );
55 TopGroup->layout()->setSpacing( 0 );
56 TopGroup->layout()->setMargin( 0 );
57 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
58 TopGroupLayout->setAlignment( Qt::AlignTop );
59 TopGroupLayout->setSpacing( 6 );
60 TopGroupLayout->setMargin( 11 );
62 TypeLabel = new QLabel( tr( "Type of Object:" ), TopGroup, "TypeLabel" );
63 TypeCombo = new QComboBox( FALSE, TopGroup, "TypeCombo" );
64 TypeCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
65 TypeCombo->setMinimumSize( 150, 0 );
67 ObjectsLabel = new QLabel( tr( "List of Objects" ), TopGroup, "ObjectsLabel" );
68 ObjectsList = new QListBox( TopGroup, "ObjectsList" );
69 ObjectsList->setSelectionMode( QListBox::Single );
70 ObjectsList->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
71 ObjectsList->setMinimumSize( 150, 80 );
73 TopGroupLayout->addWidget( TypeLabel, 0, 0 );
74 TopGroupLayout->addWidget( ObjectsLabel, 0, 1 );
75 TopGroupLayout->addWidget( TypeCombo, 1, 0 );
76 TopGroupLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 0 );
77 TopGroupLayout->addMultiCellWidget( ObjectsList, 1, 2, 1, 1 );
79 // Common buttons ===========================================================
80 GroupButtons = new QGroupBox( this, "GroupButtons" );
81 GroupButtons->setColumnLayout(0, Qt::Vertical );
82 GroupButtons->layout()->setSpacing( 0 );
83 GroupButtons->layout()->setMargin( 0 );
84 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
85 GroupButtonsLayout->setAlignment( Qt::AlignTop );
86 GroupButtonsLayout->setSpacing( 6 );
87 GroupButtonsLayout->setMargin( 11 );
89 buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
90 buttonOk->setAutoDefault( TRUE );
91 buttonOk->setDefault( TRUE );
92 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
93 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
94 buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
95 buttonCancel->setAutoDefault( TRUE );
96 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
99 TopLayout->addWidget( TopGroup );
100 TopLayout->addWidget( GroupButtons );
102 // signals and slots connections
103 connect( TypeCombo, SIGNAL( activated( const QString& ) ), this, SLOT( RefreshListActors( const QString& ) ) );
104 connect( ObjectsList, SIGNAL( selectionChanged() ), this, SLOT( updateButtonsState() ) );
105 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
106 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
108 addType( tr( "All" ) );
114 VisuGUI_VisuAsDlg::~VisuGUI_VisuAsDlg()
121 void VisuGUI_VisuAsDlg::addType( QString type )
123 int ind = TypeCombo->currentItem();
124 if ( TypeCombo->count() <= 0 ) ind = -1;
125 TypeCombo->insertItem( type );
126 if ( ind != TypeCombo->currentItem() )
127 RefreshListActors( TypeCombo->currentText() );
131 Called when user selects objects type from combo box
133 void VisuGUI_VisuAsDlg::RefreshListActors( const QString &VAType )
136 if ( VAType == QString( "All" ) )
138 else if ( VAType == QString( "Deformed Shape" ) )
139 test = VISU::TDEFORMEDSHAPE;
140 else if ( VAType == QString( "Vectors" ) )
141 test = VISU::TVECTORS;
142 else if ( VAType == QString( "Scalar Map" ) )
143 test = VISU::TSCALARMAP;
144 else if ( VAType == QString( "Iso-Surfaces" ) )
145 test = VISU::TISOSURFACE;
146 else if ( VAType == QString( "Cut Planes" ) )
147 test = VISU::TCUTPLANES;
151 ObjectsList->clear();
153 QAD_Study *myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
154 int nbSf = myActiveStudy->getStudyFramesCount();
155 for ( int i = 0; i < nbSf; i++ ) {
156 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
157 if ( sf->getTypeView() == VIEW_VTK ) {
158 vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
159 vtkActorCollection* ac = aRenderer->GetActors();
161 for( ac->InitTraversal(); ( anActor = ac->GetNextActor() ) != NULL; ) {
162 if ( anActor->IsA( "VISU_Actor" ) ) {
163 VISU_Actor* VISUActor = VISU_Actor::SafeDownCast( anActor );
164 if ( ActorTypeIsValid( VISUActor, test ) )
165 ObjectsList->insertItem( VISUActor->getName() );
170 updateButtonsState();
174 Checks if type of actor is valid according to test value [ static ]
176 bool VisuGUI_VisuAsDlg::ActorTypeIsValid( VISU_Actor* Actor, int test )
178 VISU::Prs3d_i* aPrs3d = Actor->getPrs3d();
179 if(!aPrs3d) return false;
181 switch(aPrs3d->GetType()){
182 case VISU::TSCALARMAP:
183 case VISU::TISOSURFACE:
184 case VISU::TDEFORMEDSHAPE:
185 case VISU::TCUTPLANES:
186 case VISU::TCUTLINES:
188 case VISU::TSTREAMLINES:
194 return aPrs3d->GetType() == test;
201 QString VisuGUI_VisuAsDlg::getObject()
203 for( int i = 0; i < ObjectsList->count(); i++ ) {
204 if ( ObjectsList->isSelected( i ) ) {
205 return ObjectsList->text( i );
208 return QString::null;
212 Called when selection changed
214 void VisuGUI_VisuAsDlg::updateButtonsState()
216 bool selected = false;
217 for( int i = 0; i < ObjectsList->count(); i++ ) {
218 if ( ObjectsList->isSelected( i ) ) {
223 buttonOk->setEnabled( selected );