Salome HOME
SMH: 3.0.0 preparation - merged and adopted version (POLYWORK+HEAD)
[modules/visu.git] / src / VISUGUI / VisuGUI_NonIsometricDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SALOMEGUI_NonIsometricDlg.cxx
8 //  Author : Vasily Rusyaev 
9 //  Module : VISU
10 //  $Header$ 
11
12 #include "VisuGUI_NonIsometricDlg.h"
13 #include "VisuGUI_Selection.h"
14 #include "VisuGUI.h"
15 #include "VISU_Actor.h"
16 #include "VISU_PipeLine.hxx"
17
18 #include "QtxDblSpinBox.h"
19
20 #include "SalomeApp_Application.h"
21 #include "SalomeApp_SelectionMgr.h"
22
23 #include "SVTK_RenderWindowInteractor.h"
24
25 #include "SUIT_Desktop.h"
26 #include "SUIT_ViewWindow.h"
27 #include "VTKViewer_ViewWindow.h"
28 #include "utilities.h"
29
30 #include "SALOME_Selection.h"
31 #include "SALOME_ListIteratorOfListIO.hxx"
32 #include "SALOME_ListIO.hxx"
33
34 #include <qgroupbox.h>
35 #include <qlabel.h>
36 #include <qpushbutton.h>
37 #include <qlayout.h>
38
39 using namespace std;
40
41 /*!
42   Constructor
43 */
44 VisuGUI_NonIsometricDlg::VisuGUI_NonIsometricDlg( QWidget* parent, const char* name, bool modal, WFlags fl )
45     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
46 {
47
48   SUIT_ViewWindow* sf = VisuGUI::application()->activeViewManager()->getActiveView();
49   VTKViewer_ViewWindow* aViewWnd =  dynamic_cast<VTKViewer_ViewWindow*>(sf);
50
51   if ( !name )
52     setName( "NonIsometricDlg" );
53   setCaption( tr( "Scaling" ) );
54   setSizeGripEnabled( TRUE );
55   
56   // Create layout for this dialog
57   QGridLayout* layoutDlg = new QGridLayout( this );
58   layoutDlg->setSpacing(6);
59   layoutDlg->setMargin(11);
60   
61   // Create croup box with grid layout
62   QGroupBox* GroupBox = new QGroupBox( this, "GroupBox" );
63   QGridLayout* glGroupBox = new QGridLayout( GroupBox );
64   glGroupBox->setMargin(11);
65   glGroupBox->setSpacing(6);
66   
67   // "X" scaling
68   QLabel* TextLabelX = new QLabel( "X: ", GroupBox, "TextLabelX" );
69   m_sbXcoeff = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, GroupBox );
70 //m_sbXcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
71   m_sbXcoeff->setMinimumWidth( 80 );
72   m_sbXcoeff->setValue( 1.0 );
73   
74   // "Y" scaling
75   QLabel* TextLabelY = new QLabel( "Y", GroupBox, "TextLabelY" );
76   m_sbYcoeff = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, GroupBox );
77 //m_sbYcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
78   m_sbYcoeff->setMinimumWidth( 80 );
79   m_sbYcoeff->setValue( 1.0 );
80   
81   // "Z" scaling
82   QLabel* TextLabelZ = new QLabel( "Z", GroupBox, "TextLabelZ" );
83   m_sbZcoeff = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, GroupBox );
84 //m_sbZcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
85   m_sbZcoeff->setMinimumWidth( 80 );
86   m_sbZcoeff->setValue( 1.0 );
87
88   // Get initial values from the current VTK viewer
89   if ( aViewWnd ) {
90     double aScaleFactor[3];
91     aViewWnd->GetScale(aScaleFactor);
92     m_sbXcoeff -> setValue(aScaleFactor[0]);
93     m_sbYcoeff -> setValue(aScaleFactor[1]);
94     m_sbZcoeff -> setValue(aScaleFactor[2]);
95   }
96
97   // Create <Reset> button
98   m_bReset = new QPushButton( tr( "&Reset" ), GroupBox, "m_bReset" );
99
100   // Layout widgets in the group box
101   glGroupBox->addWidget( TextLabelX, 0, 0 );
102   glGroupBox->addWidget( m_sbXcoeff, 0, 1 );
103   glGroupBox->addWidget( TextLabelY, 0, 2 );
104   glGroupBox->addWidget( m_sbYcoeff, 0, 3 );
105   glGroupBox->addWidget( TextLabelZ, 0, 4 );
106   glGroupBox->addWidget( m_sbZcoeff, 0, 5 );
107   glGroupBox->addWidget( m_bReset,   0, 6 );
108   
109   // OK, CANCEL, Apply button
110   QGroupBox* aWgt = new QGroupBox( this );
111   QHBoxLayout* aHBoxLayout = new QHBoxLayout( aWgt );
112   aHBoxLayout->setMargin(11);
113   aHBoxLayout->setSpacing(6);
114   // Create <OK> button
115   QPushButton* m_bOk = new QPushButton( tr( "O&K" ), aWgt, "m_bOk" );
116   m_bOk->setDefault( TRUE );
117   m_bOk->setAutoDefault( TRUE );
118   // Create <Apply> button
119   QPushButton* m_bApply = new QPushButton( tr( "&Apply" ), aWgt, "m_bApply" );
120   m_bApply->setAutoDefault( TRUE );
121   // Create <Cancel> button
122   QPushButton* m_bCancel = new QPushButton( tr( "&Cancel" ), aWgt, "m_bCancel" );
123   m_bCancel->setAutoDefault( TRUE );
124
125   // Layout buttons
126   aHBoxLayout->addWidget( m_bOk );
127   aHBoxLayout->addWidget( m_bApply );
128   aHBoxLayout->addStretch();
129   aHBoxLayout->addWidget( m_bCancel );
130
131   // Layout top level widgets
132   layoutDlg->addWidget(GroupBox,0,0);
133   layoutDlg->addWidget(aWgt,1,0);
134
135   // signals and slots connections
136   connect( m_bCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
137   connect( m_bOk,     SIGNAL( clicked() ), this, SLOT( onClickOk( ) ) );
138   connect( m_bApply,  SIGNAL( clicked() ), this, SLOT( onClickApply( ) ) );
139   connect( m_bReset,  SIGNAL( clicked() ), this, SLOT( onClickReset( ) ) );
140   
141   this->resize( 100, this->sizeHint().height() );
142 }
143
144 /*  
145  *  Destroys the object and frees any allocated resources
146  */
147 VisuGUI_NonIsometricDlg::~VisuGUI_NonIsometricDlg()
148 {
149     // no need to delete child widgets, Qt does it all for us
150 }
151
152 void VisuGUI_NonIsometricDlg::onClickOk()
153 {
154   //apply changes
155   onClickApply();
156   //Close dialog
157   accept();
158 }
159
160 void VisuGUI_NonIsometricDlg::onClickApply(){
161   SUIT_ViewWindow* sf = VisuGUI::application()->activeViewManager()->getActiveView();
162   SalomeApp_SelectionMgr* mgr = VisuGUI::application()->selectionMgr();
163
164
165   VTKViewer_ViewWindow* vf = dynamic_cast<VTKViewer_ViewWindow*>(sf);
166   if( !vf  )
167     return;
168     
169   double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
170   vf->SetScale(aScale);
171
172   SALOME_ListIO selected;
173   mgr->selectedObjects( selected );
174   SALOME_ListIteratorOfListIO Itinit( selected );
175   SVTK_RenderWindowInteractor* rw = dynamic_cast<SVTK_RenderWindowInteractor*>( vf->getRWInteractor() );
176
177   if( rw )
178     for (; Itinit.More(); Itinit.Next()) {
179       rw->highlight(Itinit.Value(), true);
180     }
181 }
182
183 void VisuGUI_NonIsometricDlg::onClickReset()
184 {
185   m_bReset->setFocus();
186   m_sbXcoeff->setValue( 1.0 );
187   m_sbYcoeff->setValue( 1.0 );
188   m_sbZcoeff->setValue( 1.0 );
189 }
190