Salome HOME
All modules must use SVTK package instead VTK
[modules/visu.git] / src / VISUGUI / VisuGUI_IsoSurfacesDlg.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_IsoSurfacesDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_IsoSurfacesDlg.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_Tools.h"
33
34 #include "SalomeApp_Application.h"
35
36 #include "SUIT_Desktop.h"
37 #include "SUIT_MessageBox.h"
38
39 #include <limits.h>
40
41 #include <qlayout.h>
42 #include <qvalidator.h>
43 #include <qtabwidget.h>
44
45 using namespace std;
46
47
48 VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent)
49      : QVBox(parent)
50 {
51   QFrame* TopGroup = new QFrame( this, "TopGroup" );
52   TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
53   TopGroup->setLineWidth(1);
54
55   QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
56   TopGroupLayout->setAlignment( Qt::AlignTop );
57   TopGroupLayout->setSpacing( 6 );
58   TopGroupLayout->setMargin( 11 );
59
60   QLabel* LabelNbr = new QLabel (tr("NB_SURFACES"), TopGroup, "LabelNbr");
61   TopGroupLayout->addWidget( LabelNbr, 0, 0 );
62   NbrIso = new QSpinBox( 1, 100, 1, TopGroup, "NbrIso" );
63   NbrIso->setValue( 1 );
64   TopGroupLayout->addWidget( NbrIso, 0, 1 );
65
66   QLabel* LabelMin = new QLabel (tr("MIN_VALUE"), TopGroup, "LabelMin");
67   TopGroupLayout->addWidget(LabelMin, 1, 0);
68   //MinIso = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
69   MinIso = new QLineEdit( TopGroup );
70   MinIso->setValidator( new QDoubleValidator(TopGroup) );
71   MinIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
72   MinIso->setMinimumSize( 70, 0 );
73   LabelMin->setBuddy(MinIso);
74   TopGroupLayout->addWidget( MinIso, 1, 1 );
75
76   QLabel* LabelMax = new QLabel (tr("MAX_VALUE"), TopGroup, "LabelMax");
77   TopGroupLayout->addWidget( LabelMax, 2, 0 );
78   //MaxIso = new QtxSpinBoxDbl( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
79   MaxIso = new QLineEdit( TopGroup );
80   MaxIso->setValidator( new QDoubleValidator(TopGroup) );
81   MaxIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
82   MaxIso->setMinimumSize( 70, 0 );
83   LabelMax->setBuddy(MaxIso);
84   TopGroupLayout->addWidget( MaxIso, 2, 1 );
85
86
87 //   CBUpdate = new QCheckBox ( tr( "Update scalar bar with these values" ), TopGroup);
88 //   CBUpdate->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
89 //   TopGroupLayout->addMultiCellWidget( CBUpdate, 4, 4, 0, 1);
90 //   CBUpdate->setChecked(false);
91   QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", TopGroup);
92   TopGroupLayout->addMultiCellWidget( aUpdateBtn, 3, 3, 0, 1);
93   connect( aUpdateBtn, SIGNAL( clicked() ), this, SLOT(onCBUpdate() ) );
94
95 //   CBLog = new QCheckBox ( tr( "Logarithmic scaling" ), TopGroup);
96 //   CBLog->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
97 //   TopGroupLayout->addMultiCellWidget( CBLog, 3, 3, 0, 1);
98 }
99
100 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
101 {
102   NbrIso->setValue(thePrs->GetNbSurfaces());
103   MinIso->setText(QString::number(thePrs->GetSubMin()));
104   MaxIso->setText(QString::number(thePrs->GetSubMax()));
105 //   switch(thePrs->GetScaling()){
106 //   case VISU::LOGARITHMIC :
107 //     CBLog->setChecked(true);
108 //     break;
109 //   default:
110 //     CBLog->setChecked(false);
111 //   }
112 }
113
114 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
115 {
116   thePrs->SetNbSurfaces(NbrIso->value());
117   thePrs->SetSubRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
118   return 1;
119 //   if (CBUpdate->isChecked())
120 //     {
121 //       thePrs->SetRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
122 //       if (CBLog->isChecked())
123 //      thePrs->SetScaling(VISU::LOGARITHMIC);
124 //       else
125 //      thePrs->SetScaling(VISU::LINEAR);
126 //    }
127 }
128
129 void VisuGUI_IsoSurfPane::onCBUpdate()
130 {
131   //  if (CBUpdate->isChecked()) {
132   myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
133     //  }
134 //     CBLog->setDisabled(false);
135 //   else CBLog->setDisabled(true);
136 }
137
138 bool VisuGUI_IsoSurfPane::check()
139 {
140   if (MinIso->text().toDouble() >= MaxIso->text().toDouble()) {
141     MESSAGE(tr("MSG_MINMAX_VALUES"));
142     SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
143                             tr("MSG_MINMAX_VALUES"),
144                             tr("BUT_OK"));
145     return false;
146   } // else if (/* CBUpdate->isChecked() && CBLog->isChecked() && */
147 //            (MinIso->text().toDouble() <=0 || MaxIso->text().toDouble() <=0) ) {
148 //     SUIT_MessageBox::warn1( this,
149 //                         tr("WRN_VISU"),
150 //                         tr("WRN_LOGARITHMIC_RANGE_ISOSURF"),
151 //                         tr("BUT_OK"));
152 //     return false;
153 //   }
154   return true;
155 }
156
157
158
159
160
161 /*!
162   Constructor
163 */
164 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
165      : QDialog(VISU::GetDesktop(theModule), "VisuGUI_IsoSurfacesDlg", true,
166                WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
167 {
168   setCaption(tr("DEFINE_ISOSURFACES"));
169   setSizeGripEnabled( TRUE );
170
171   QVBoxLayout* TopLayout = new QVBoxLayout(this);
172   TopLayout->setSpacing( 6 );
173   TopLayout->setMargin(11);
174
175   QTabWidget* aTabBox = new QTabWidget(this);
176   myIsoPane = new  VisuGUI_IsoSurfPane(this);
177   myIsoPane->setMargin( 5 );
178   aTabBox->addTab(myIsoPane, "Iso Surface");
179   myScalarPane = new VisuGUI_ScalarBarPane(this, false);
180   myIsoPane->setScalarBarPane(myScalarPane);
181   myScalarPane->setMargin( 5 );
182   aTabBox->addTab(myScalarPane, "Scalar Bar");
183
184   TopLayout->addWidget(aTabBox);
185
186   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
187   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
188   GroupButtons->setColumnLayout(0, Qt::Vertical );
189   GroupButtons->layout()->setSpacing( 0 );
190   GroupButtons->layout()->setMargin( 0 );
191   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
192   GroupButtonsLayout->setAlignment( Qt::AlignTop );
193   GroupButtonsLayout->setSpacing( 6 );
194   GroupButtonsLayout->setMargin( 11 );
195
196   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
197   buttonOk->setAutoDefault( TRUE );
198   buttonOk->setDefault( TRUE );
199   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
200   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
201   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
202   buttonCancel->setAutoDefault( TRUE );
203   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
204
205   TopLayout->addWidget(GroupButtons);
206
207   // signals and slots connections
208   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
209   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
210 }
211
212 void VisuGUI_IsoSurfacesDlg::accept()
213 {
214   if (myIsoPane->check() && myScalarPane->check())
215     QDialog::accept();
216 }