]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_VisuAsDlg.cxx
Salome HOME
NRI : merge from 1.2c
[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 #include "VisuGUI_VisuAsDlg.h"
30
31 #include "VISU_Actor.h"
32 #include "VISU_Prs3d_i.hh"
33
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "QAD_RightFrame.h"
37 #include "VTKViewer_ViewFrame.h"
38
39 #include <qlayout.h>
40
41 using namespace std;
42
43 /*!
44   Constructor
45 */
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 )
48 {
49   if ( !name )
50     setName( "VisuGUI_VisuAsDlg" );
51   setCaption( tr( "Visualize As" ) );
52   setSizeGripEnabled( TRUE );
53
54   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
55   TopLayout->setSpacing( 6 );
56   TopLayout->setMargin( 11 );
57
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 );
66
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 );
71   
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 );
77
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 );
83
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 );
93
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 );
102
103   // top layout
104   TopLayout->addWidget( TopGroup );
105   TopLayout->addWidget( GroupButtons );
106   
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() ) );
112
113   addType( tr( "All" ) );
114 }
115
116 /*!
117   Destructor
118 */
119 VisuGUI_VisuAsDlg::~VisuGUI_VisuAsDlg()
120 {
121 }
122
123 /*!
124   Adds type
125 */
126 void VisuGUI_VisuAsDlg::addType( QString type )
127 {
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() );
133 }
134
135 /*!
136   Called when user selects objects type from combo box
137 */
138 void VisuGUI_VisuAsDlg::RefreshListActors( const QString &VAType )
139 {
140   int test = 0;
141   if ( VAType == QString( "All" ) ) 
142     test = -1;
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;
153   else
154     return;
155   
156   ObjectsList->clear();
157   
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();
165       vtkActor *anActor;
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() );
171         }
172       }
173     }
174   }
175   updateButtonsState();
176 }
177
178 /*!
179   Checks if type of actor is valid according to test value [ static ]
180 */
181 bool VisuGUI_VisuAsDlg::ActorTypeIsValid( VISU_Actor* Actor, int test )
182 {
183   VISU::Prs3d_i* aPrs3d = Actor->GetPrs3d();
184   if(!aPrs3d) return false;
185   if(test == -1) {
186     switch(aPrs3d->GetType()){
187     case VISU::TSCALARMAP:
188     case VISU::TISOSURFACE:
189     case VISU::TDEFORMEDSHAPE:
190     case VISU::TCUTPLANES:
191     case VISU::TCUTLINES:
192     case VISU::TVECTORS:
193     case VISU::TSTREAMLINES:
194       return true;
195     default:
196       return false;
197     }
198   }else{
199     return aPrs3d->GetType() == test;
200   }
201 }
202
203 /*!
204   Gets object selected
205 */
206 QString VisuGUI_VisuAsDlg::getObject() 
207 {
208   for( int i = 0; i < ObjectsList->count(); i++ ) {
209     if ( ObjectsList->isSelected( i ) ) {
210       return ObjectsList->text( i );
211     }
212   }
213   return QString::null;
214 }
215
216 /*!
217   Called when selection changed
218 */
219 void VisuGUI_VisuAsDlg::updateButtonsState()
220 {
221   bool selected = false;
222   for( int i = 0; i < ObjectsList->count(); i++ ) {
223     if ( ObjectsList->isSelected( i ) ) {
224       selected = true;
225       break;
226     }
227   }
228   buttonOk->setEnabled( selected );
229 }
230
231
232
233
234