Salome HOME
Improve english localization
[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   if (!name)
48     setName("NonIsometricDlg");
49   setCaption(tr("DLG_TITLE"));
50   setSizeGripEnabled(TRUE);
51   
52   SUIT_ViewWindow* sf = VisuGUI::application()->activeViewManager()->getActiveView();
53   VTKViewer_ViewWindow* aViewWnd =  dynamic_cast<VTKViewer_ViewWindow*>(sf);
54
55   // Create layout for this dialog
56   QGridLayout* layoutDlg = new QGridLayout( this );
57   layoutDlg->setSpacing(6);
58   layoutDlg->setMargin(11);
59   
60   // Create croup box with grid layout
61   QGroupBox* GroupBox = new QGroupBox( this, "GroupBox" );
62   QGridLayout* glGroupBox = new QGridLayout( GroupBox );
63   glGroupBox->setMargin(11);
64   glGroupBox->setSpacing(6);
65   
66   // "X" scaling
67   QLabel* TextLabelX = new QLabel (tr("LBL_X"), GroupBox, "TextLabelX");
68   m_sbXcoeff = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, GroupBox );
69 //m_sbXcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
70   m_sbXcoeff->setMinimumWidth( 80 );
71   m_sbXcoeff->setValue( 1.0 );
72   
73   // "Y" scaling
74   QLabel* TextLabelY = new QLabel (tr("LBL_Y"), GroupBox, "TextLabelY");
75   m_sbYcoeff = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, GroupBox );
76 //m_sbYcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
77   m_sbYcoeff->setMinimumWidth( 80 );
78   m_sbYcoeff->setValue( 1.0 );
79   
80   // "Z" scaling
81   QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), GroupBox, "TextLabelZ");
82   m_sbZcoeff = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, GroupBox );
83 //m_sbZcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
84   m_sbZcoeff->setMinimumWidth( 80 );
85   m_sbZcoeff->setValue( 1.0 );
86
87   // Get initial values from the current VTK viewer
88   if ( aViewWnd ) {
89     double aScaleFactor[3];
90     aViewWnd->GetScale(aScaleFactor);
91     m_sbXcoeff -> setValue(aScaleFactor[0]);
92     m_sbYcoeff -> setValue(aScaleFactor[1]);
93     m_sbZcoeff -> setValue(aScaleFactor[2]);
94   }
95
96   // Create <Reset> button
97   m_bReset = new QPushButton( tr( "&Reset" ), GroupBox, "m_bReset" );
98
99   // Layout widgets in the group box
100   glGroupBox->addWidget( TextLabelX, 0, 0 );
101   glGroupBox->addWidget( m_sbXcoeff, 0, 1 );
102   glGroupBox->addWidget( TextLabelY, 0, 2 );
103   glGroupBox->addWidget( m_sbYcoeff, 0, 3 );
104   glGroupBox->addWidget( TextLabelZ, 0, 4 );
105   glGroupBox->addWidget( m_sbZcoeff, 0, 5 );
106   glGroupBox->addWidget( m_bReset,   0, 6 );
107   
108   // OK, CANCEL, Apply button
109   QGroupBox* aWgt = new QGroupBox( this );
110   QHBoxLayout* aHBoxLayout = new QHBoxLayout( aWgt );
111   aHBoxLayout->setMargin(11);
112   aHBoxLayout->setSpacing(6);
113   // Create <OK> button
114   QPushButton* m_bOk = new QPushButton( tr( "O&K" ), aWgt, "m_bOk" );
115   m_bOk->setDefault( TRUE );
116   m_bOk->setAutoDefault( TRUE );
117   // Create <Apply> button
118   QPushButton* m_bApply = new QPushButton( tr( "&Apply" ), aWgt, "m_bApply" );
119   m_bApply->setAutoDefault( TRUE );
120   // Create <Cancel> button
121   QPushButton* m_bCancel = new QPushButton( tr( "&Cancel" ), aWgt, "m_bCancel" );
122   m_bCancel->setAutoDefault( TRUE );
123
124   // Layout buttons
125   aHBoxLayout->addWidget( m_bOk );
126   aHBoxLayout->addWidget( m_bApply );
127   aHBoxLayout->addStretch();
128   aHBoxLayout->addWidget( m_bCancel );
129
130   // Layout top level widgets
131   layoutDlg->addWidget(GroupBox,0,0);
132   layoutDlg->addWidget(aWgt,1,0);
133
134   // signals and slots connections
135   connect( m_bCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
136   connect( m_bOk,     SIGNAL( clicked() ), this, SLOT( onClickOk( ) ) );
137   connect( m_bApply,  SIGNAL( clicked() ), this, SLOT( onClickApply( ) ) );
138   connect( m_bReset,  SIGNAL( clicked() ), this, SLOT( onClickReset( ) ) );
139   
140   this->resize( 100, this->sizeHint().height() );
141 }
142
143 /*  
144  *  Destroys the object and frees any allocated resources
145  */
146 VisuGUI_NonIsometricDlg::~VisuGUI_NonIsometricDlg()
147 {
148     // no need to delete child widgets, Qt does it all for us
149 }
150
151 void VisuGUI_NonIsometricDlg::onClickOk()
152 {
153   //apply changes
154   onClickApply();
155   //Close dialog
156   accept();
157 }
158
159 void VisuGUI_NonIsometricDlg::onClickApply(){
160   SUIT_ViewWindow* sf = VisuGUI::application()->activeViewManager()->getActiveView();
161   SalomeApp_SelectionMgr* mgr = VisuGUI::application()->selectionMgr();
162
163
164   VTKViewer_ViewWindow* vf = dynamic_cast<VTKViewer_ViewWindow*>(sf);
165   if( !vf  )
166     return;
167     
168   double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
169   vf->SetScale(aScale);
170
171   SALOME_ListIO selected;
172   mgr->selectedObjects( selected );
173   SALOME_ListIteratorOfListIO Itinit( selected );
174   SVTK_RenderWindowInteractor* rw = dynamic_cast<SVTK_RenderWindowInteractor*>( vf->getRWInteractor() );
175
176   if( rw )
177     for (; Itinit.More(); Itinit.Next()) {
178       rw->highlight(Itinit.Value(), true);
179     }
180 }
181
182 void VisuGUI_NonIsometricDlg::onClickReset()
183 {
184   m_bReset->setFocus();
185   m_sbXcoeff->setValue( 1.0 );
186   m_sbYcoeff->setValue( 1.0 );
187   m_sbZcoeff->setValue( 1.0 );
188 }
189