Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[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 using namespace std;
13 #include "VisuGUI_NonIsometricDlg.h"
14
15 #include <qgroupbox.h>
16 #include <qlabel.h>
17 #include <qpushbutton.h>
18 #include <qlayout.h>
19 #include "QAD_SpinBoxDbl.h"
20 #include "QAD_Application.h"
21 #include "QAD_Desktop.h"
22 #include "QAD_StudyFrame.h"
23 #include "QAD_RightFrame.h"
24 #include "VTKViewer_ViewFrame.h"
25 #include "VISU_Actor.h"
26 #include "utilities.h"
27
28 #include "SALOME_Selection.h"
29 #include "SALOME_ListIteratorOfListIO.hxx"
30 #include "SALOME_ListIO.hxx"
31
32 /*!
33   Constructor
34 */
35 VisuGUI_NonIsometricDlg::VisuGUI_NonIsometricDlg( QWidget* parent, const char* name, bool modal, WFlags fl )
36     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
37 {
38
39   QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
40   VTKViewer_ViewFrame* aViewFrame =  dynamic_cast<VTKViewer_ViewFrame*>(sf->getRightFrame()->getViewFrame());
41
42   if ( !name )
43     setName( "NonIsometricDlg" );
44   setCaption( tr( "Scaling" ) );
45   setSizeGripEnabled( TRUE );
46   
47   // Create layout for this dialog
48   QGridLayout* layoutDlg = new QGridLayout( this );
49   layoutDlg->setSpacing(6);
50   layoutDlg->setMargin(11);
51   
52   // Create croup box with grid layout
53   QGroupBox* GroupBox = new QGroupBox( this, "GroupBox" );
54   QGridLayout* glGroupBox = new QGridLayout( GroupBox );
55   glGroupBox->setMargin(11);
56   glGroupBox->setSpacing(6);
57   
58   // "X" scaling
59   QLabel* TextLabelX = new QLabel( "X: ", GroupBox, "TextLabelX" );
60   m_sbXcoeff = new QAD_SpinBoxDbl( GroupBox, -DBL_MAX, DBL_MAX, 0.1 );
61 //m_sbXcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
62   m_sbXcoeff->setMinimumWidth( 80 );
63   m_sbXcoeff->setValue( 1.0 );
64   
65   // "Y" scaling
66   QLabel* TextLabelY = new QLabel( "Y", GroupBox, "TextLabelY" );
67   m_sbYcoeff = new QAD_SpinBoxDbl( GroupBox, -DBL_MAX, DBL_MAX, 0.1 );
68 //m_sbYcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
69   m_sbYcoeff->setMinimumWidth( 80 );
70   m_sbYcoeff->setValue( 1.0 );
71   
72   // "Z" scaling
73   QLabel* TextLabelZ = new QLabel( "Z", GroupBox, "TextLabelZ" );
74   m_sbZcoeff = new QAD_SpinBoxDbl( GroupBox, -DBL_MAX, DBL_MAX, 0.1 );
75 //m_sbZcoeff->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
76   m_sbZcoeff->setMinimumWidth( 80 );
77   m_sbZcoeff->setValue( 1.0 );
78
79   // Get initial values from the current VTK viewer
80   if ( aViewFrame ) {
81     double aScaleFactor[3];
82     aViewFrame->GetScale(aScaleFactor);
83     m_sbXcoeff -> setValue(aScaleFactor[0]);
84     m_sbYcoeff -> setValue(aScaleFactor[1]);
85     m_sbZcoeff -> setValue(aScaleFactor[2]);
86   }
87
88   // Create <Reset> button
89   m_bReset = new QPushButton( tr( "&Reset" ), GroupBox, "m_bReset" );
90
91   // Layout widgets in the group box
92   glGroupBox->addWidget( TextLabelX, 0, 0 );
93   glGroupBox->addWidget( m_sbXcoeff, 0, 1 );
94   glGroupBox->addWidget( TextLabelY, 0, 2 );
95   glGroupBox->addWidget( m_sbYcoeff, 0, 3 );
96   glGroupBox->addWidget( TextLabelZ, 0, 4 );
97   glGroupBox->addWidget( m_sbZcoeff, 0, 5 );
98   glGroupBox->addWidget( m_bReset,   0, 6 );
99   
100   // OK, CANCEL, Apply button
101   QGroupBox* aWgt = new QGroupBox( this );
102   QHBoxLayout* aHBoxLayout = new QHBoxLayout( aWgt );
103   aHBoxLayout->setMargin(11);
104   aHBoxLayout->setSpacing(6);
105   // Create <OK> button
106   QPushButton* m_bOk = new QPushButton( tr( "O&K" ), aWgt, "m_bOk" );
107   m_bOk->setDefault( TRUE );
108   m_bOk->setAutoDefault( TRUE );
109   // Create <Apply> button
110   QPushButton* m_bApply = new QPushButton( tr( "&Apply" ), aWgt, "m_bApply" );
111   m_bApply->setAutoDefault( TRUE );
112   // Create <Cancel> button
113   QPushButton* m_bCancel = new QPushButton( tr( "&Cancel" ), aWgt, "m_bCancel" );
114   m_bCancel->setAutoDefault( TRUE );
115
116   // Layout buttons
117   aHBoxLayout->addWidget( m_bOk );
118   aHBoxLayout->addWidget( m_bApply );
119   aHBoxLayout->addStretch();
120   aHBoxLayout->addWidget( m_bCancel );
121
122   // Layout top level widgets
123   layoutDlg->addWidget(GroupBox,0,0);
124   layoutDlg->addWidget(aWgt,1,0);
125
126   // signals and slots connections
127   connect( m_bCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
128   connect( m_bOk,     SIGNAL( clicked() ), this, SLOT( onClickOk( ) ) );
129   connect( m_bApply,  SIGNAL( clicked() ), this, SLOT( onClickApply( ) ) );
130   connect( m_bReset,  SIGNAL( clicked() ), this, SLOT( onClickReset( ) ) );
131   
132   this->resize( 100, this->sizeHint().height() );
133 }
134
135 /*  
136  *  Destroys the object and frees any allocated resources
137  */
138 VisuGUI_NonIsometricDlg::~VisuGUI_NonIsometricDlg()
139 {
140     // no need to delete child widgets, Qt does it all for us
141 }
142
143 void VisuGUI_NonIsometricDlg::onClickOk()
144 {
145   //apply changes
146   onClickApply();
147   //Close dialog
148   accept();
149 }
150
151 void VisuGUI_NonIsometricDlg::onClickApply(){
152   QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
153   SALOME_Selection* Sel = SALOME_Selection::Selection( sf->getStudy()->getSelection() );
154
155
156   if( VTKViewer_ViewFrame* vf =  dynamic_cast<VTKViewer_ViewFrame*>(sf->getRightFrame()->getViewFrame())){
157     double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
158     vf->SetScale(aScale);
159   }
160
161   SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
162   for (; Itinit.More(); Itinit.Next()) {
163     sf->getStudy()->highlight(Itinit.Value(), true);
164   }
165 }
166
167 void VisuGUI_NonIsometricDlg::onClickReset()
168 {
169   m_bReset->setFocus();
170   m_sbXcoeff->setValue( 1.0 );
171   m_sbYcoeff->setValue( 1.0 );
172   m_sbZcoeff->setValue( 1.0 );
173 }
174