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