]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_VisuAsDlg.cxx
Salome HOME
NRI : Merge from V1_2.
[modules/visu.git] / src / VISUGUI / VisuGUI_VisuAsDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VisuGUI_VisuAsDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND 
26 //  Module : VISU
27 //  $Header$
28
29 using namespace std;
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"
36 #include <qlayout.h>
37
38 /*!
39   Constructor
40 */
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 )
43 {
44   if ( !name )
45     setName( "VisuGUI_VisuAsDlg" );
46   setCaption( tr( "Visualize As" ) );
47   setSizeGripEnabled( TRUE );
48
49   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
50   TopLayout->setSpacing( 6 );
51   TopLayout->setMargin( 11 );
52
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 );
61
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 );
66   
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 );
72
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 );
78
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 );
88
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 );
97
98   // top layout
99   TopLayout->addWidget( TopGroup );
100   TopLayout->addWidget( GroupButtons );
101   
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() ) );
107
108   addType( tr( "All" ) );
109 }
110
111 /*!
112   Destructor
113 */
114 VisuGUI_VisuAsDlg::~VisuGUI_VisuAsDlg()
115 {
116 }
117
118 /*!
119   Adds type
120 */
121 void VisuGUI_VisuAsDlg::addType( QString type )
122 {
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() );
128 }
129
130 /*!
131   Called when user selects objects type from combo box
132 */
133 void VisuGUI_VisuAsDlg::RefreshListActors( const QString &VAType )
134 {
135   int test = 0;
136   if ( VAType == QString( "All" ) ) 
137     test = -1;
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;
148   else
149     return;
150   
151   ObjectsList->clear();
152   
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();
160       vtkActor *anActor;
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() );
166         }
167       }
168     }
169   }
170   updateButtonsState();
171 }
172
173 /*!
174   Checks if type of actor is valid according to test value [ static ]
175 */
176 bool VisuGUI_VisuAsDlg::ActorTypeIsValid( VISU_Actor* Actor, int test )
177 {
178   VISU::Prs3d_i* aPrs3d = Actor->getPrs3d();
179   if(!aPrs3d) return false;
180   if(test == -1) {
181     switch(aPrs3d->GetType()){
182     case VISU::TSCALARMAP:
183     case VISU::TISOSURFACE:
184     case VISU::TDEFORMEDSHAPE:
185     case VISU::TCUTPLANES:
186     case VISU::TCUTLINES:
187     case VISU::TVECTORS:
188     case VISU::TSTREAMLINES:
189       return true;
190     default:
191       return false;
192     }
193   }else{
194     return aPrs3d->GetType() == test;
195   }
196 }
197
198 /*!
199   Gets object selected
200 */
201 QString VisuGUI_VisuAsDlg::getObject() 
202 {
203   for( int i = 0; i < ObjectsList->count(); i++ ) {
204     if ( ObjectsList->isSelected( i ) ) {
205       return ObjectsList->text( i );
206     }
207   }
208   return QString::null;
209 }
210
211 /*!
212   Called when selection changed
213 */
214 void VisuGUI_VisuAsDlg::updateButtonsState()
215 {
216   bool selected = false;
217   for( int i = 0; i < ObjectsList->count(); i++ ) {
218     if ( ObjectsList->isSelected( i ) ) {
219       selected = true;
220       break;
221     }
222   }
223   buttonOk->setEnabled( selected );
224 }
225
226
227
228
229