Salome HOME
Update version to 3.2.0a1
[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
14 #include "VisuGUI_Tools.h"
15
16 #include "VISU_Actor.h"
17 #include "VISU_PipeLine.hxx"
18
19 #include "SalomeApp_Application.h"
20 #include "LightApp_SelectionMgr.h"
21
22 #include "SVTK_ViewWindow.h"
23 #include "SVTK_RenderWindowInteractor.h"
24
25 #include "SUIT_Desktop.h"
26 #include "SUIT_Session.h"
27 #include "SUIT_ViewWindow.h"
28
29 #include "SALOME_ListIteratorOfListIO.hxx"
30 #include "SALOME_ListIO.hxx"
31
32 #include "QtxDblSpinBox.h"
33
34 #include "utilities.h"
35
36 #include <qgroupbox.h>
37 #include <qlabel.h>
38 #include <qpushbutton.h>
39 #include <qlayout.h>
40
41 using namespace std;
42
43 /*!
44   Constructor
45 */
46 VisuGUI_NonIsometricDlg::VisuGUI_NonIsometricDlg (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("NonIsometricDlg");
51   setCaption(tr("DLG_TITLE"));
52   setSizeGripEnabled(TRUE);
53
54   SVTK_ViewWindow* aViewWnd = VISU::GetViewWindow();
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 (tr("LBL_X"), GroupBox, "TextLabelX");
69   m_sbXcoeff = new QtxDblSpinBox(-DBL_MAX, DBL_MAX, 0.1, GroupBox);
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->setMinimumWidth(80);
77   m_sbYcoeff->setValue(1.0);
78
79   // "Z" scaling
80   QLabel* TextLabelZ = new QLabel (tr("LBL_Z"), GroupBox, "TextLabelZ");
81   m_sbZcoeff = new QtxDblSpinBox(-DBL_MAX, DBL_MAX, 0.1, GroupBox);
82   m_sbZcoeff->setMinimumWidth(80);
83   m_sbZcoeff->setValue(1.0);
84
85   // Get initial values from the current VTK viewer
86   if (aViewWnd) {
87     double aScaleFactor[3];
88     aViewWnd->GetScale(aScaleFactor);
89     m_sbXcoeff -> setValue(aScaleFactor[0]);
90     m_sbYcoeff -> setValue(aScaleFactor[1]);
91     m_sbZcoeff -> setValue(aScaleFactor[2]);
92   }
93
94   // Create <Reset> button
95   m_bReset = new QPushButton(tr("&Reset"), GroupBox, "m_bReset");
96
97   // Layout widgets in the group box
98   glGroupBox->addWidget(TextLabelX, 0, 0);
99   glGroupBox->addWidget(m_sbXcoeff, 0, 1);
100   glGroupBox->addWidget(TextLabelY, 0, 2);
101   glGroupBox->addWidget(m_sbYcoeff, 0, 3);
102   glGroupBox->addWidget(TextLabelZ, 0, 4);
103   glGroupBox->addWidget(m_sbZcoeff, 0, 5);
104   glGroupBox->addWidget(m_bReset,   0, 6);
105
106   // OK, CANCEL, Apply button
107   QGroupBox* aWgt = new QGroupBox(this);
108   QHBoxLayout* aHBoxLayout = new QHBoxLayout(aWgt);
109   aHBoxLayout->setMargin(11);
110   aHBoxLayout->setSpacing(6);
111   // Create <OK> button
112   QPushButton* m_bOk = new QPushButton(tr("O&K"), aWgt, "m_bOk");
113   m_bOk->setDefault(TRUE);
114   m_bOk->setAutoDefault(TRUE);
115   // Create <Apply> button
116   QPushButton* m_bApply = new QPushButton(tr("&Apply"), aWgt, "m_bApply");
117   m_bApply->setAutoDefault(TRUE);
118   // Create <Cancel> button
119   QPushButton* m_bCancel = new QPushButton(tr("&Cancel"), aWgt, "m_bCancel");
120   m_bCancel->setAutoDefault(TRUE);
121
122   // Layout buttons
123   aHBoxLayout->addWidget(m_bOk);
124   aHBoxLayout->addWidget(m_bApply);
125   aHBoxLayout->addStretch();
126   aHBoxLayout->addWidget(m_bCancel);
127
128   // Layout top level widgets
129   layoutDlg->addWidget(GroupBox,0,0);
130   layoutDlg->addWidget(aWgt,1,0);
131
132   // signals and slots connections
133   connect(m_bCancel, SIGNAL(clicked()), this, SLOT(reject()));
134   connect(m_bOk,     SIGNAL(clicked()), this, SLOT(onClickOk()));
135   connect(m_bApply,  SIGNAL(clicked()), this, SLOT(onClickApply()));
136   connect(m_bReset,  SIGNAL(clicked()), this, SLOT(onClickReset()));
137
138   this->resize(100, this->sizeHint().height());
139 }
140
141 /*
142  *  Destroys the object and frees any allocated resources
143  */
144 VisuGUI_NonIsometricDlg::~VisuGUI_NonIsometricDlg()
145 {
146   // no need to delete child widgets, Qt does it all for us
147 }
148
149 void VisuGUI_NonIsometricDlg::onClickOk()
150 {
151   //apply changes
152   onClickApply();
153   //Close dialog
154   accept();
155 }
156
157 void VisuGUI_NonIsometricDlg::onClickApply()
158 {
159   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
160     (SUIT_Session::session()->activeApplication());
161   LightApp_SelectionMgr* mgr = anApp->selectionMgr();
162
163   SVTK_ViewWindow* vf = VISU::GetViewWindow();
164   if (!vf)
165     return;
166
167   double aScale[3] = {m_sbXcoeff->value(), m_sbYcoeff->value(), m_sbZcoeff->value()};
168   vf->SetScale(aScale);
169
170   SALOME_ListIO selected;
171   mgr->selectedObjects(selected);
172   SALOME_ListIteratorOfListIO Itinit(selected);
173
174   if (vf)
175     for (; Itinit.More(); Itinit.Next()) {
176       vf->highlight(Itinit.Value(), true);
177     }
178 }
179
180 void VisuGUI_NonIsometricDlg::onClickReset()
181 {
182   m_bReset->setFocus();
183   m_sbXcoeff->setValue(1.0);
184   m_sbYcoeff->setValue(1.0);
185   m_sbZcoeff->setValue(1.0);
186 }