]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_IsoSurfacesDlg.cxx
Salome HOME
DCQ : Merge with Ecole Ete a6.
[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 "VISU_IsoSurfaces_i.hh"
31
32 #include "QAD_Application.h"
33 #include "QAD_Desktop.h"
34 #include "QAD_MessageBox.h"
35
36 #include <limits.h>
37
38 #include <qlayout.h>
39 #include <qvalidator.h>
40 #include <qtabwidget.h>
41
42
43 using namespace std;
44
45
46 VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane(QWidget* parent) 
47   : QVBox(parent)
48 {
49   QFrame* TopGroup = new QFrame( this, "TopGroup" );
50   TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
51   TopGroup->setLineWidth(1);
52
53   QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
54   TopGroupLayout->setAlignment( Qt::AlignTop );
55   TopGroupLayout->setSpacing( 6 );
56   TopGroupLayout->setMargin( 11 );
57
58   QLabel* LabelNbr = new QLabel( tr( "Number of surfaces:" ), TopGroup, "LabelNbr" );
59   TopGroupLayout->addWidget( LabelNbr, 0, 0 );
60   NbrIso = new QSpinBox( 1, 100, 1, TopGroup, "NbrIso" );
61   NbrIso->setValue( 1 );
62   TopGroupLayout->addWidget( NbrIso, 0, 1 );
63
64   QLabel* LabelMin = new QLabel( tr( "Minimum value:" ), TopGroup, "LabelMin" );
65   TopGroupLayout->addWidget( LabelMin, 1, 0 );
66   //MinIso = new QAD_SpinBoxDbl( TopGroup, -DBL_MAX, DBL_MAX, 0.1 );
67   MinIso = new QLineEdit( TopGroup );
68   MinIso->setValidator( new QDoubleValidator(TopGroup) );  
69   MinIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
70   MinIso->setMinimumSize( 70, 0 );
71   LabelMin->setBuddy(MinIso);
72   TopGroupLayout->addWidget( MinIso, 1, 1 );
73
74   QLabel* LabelMax = new QLabel( tr( "Maximum value:" ), TopGroup, "LabelMax" );
75   TopGroupLayout->addWidget( LabelMax, 2, 0 );
76   //MaxIso = new QAD_SpinBoxDbl( TopGroup, -DBL_MAX, DBL_MAX, 0.1);
77   MaxIso = new QLineEdit( TopGroup );
78   MaxIso->setValidator( new QDoubleValidator(TopGroup) );
79   MaxIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
80   MaxIso->setMinimumSize( 70, 0 );
81   LabelMax->setBuddy(MaxIso);
82   TopGroupLayout->addWidget( MaxIso, 2, 1 );
83   
84   
85 //   CBUpdate = new QCheckBox ( tr( "Update scalar bar with these values" ), TopGroup);
86 //   CBUpdate->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
87 //   TopGroupLayout->addMultiCellWidget( CBUpdate, 4, 4, 0, 1);
88 //   CBUpdate->setChecked(false);
89   QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", TopGroup);
90   TopGroupLayout->addMultiCellWidget( aUpdateBtn, 3, 3, 0, 1);
91   connect( aUpdateBtn, SIGNAL( clicked() ), this, SLOT(onCBUpdate() ) );   
92   
93 //   CBLog = new QCheckBox ( tr( "Logarithmic scaling" ), TopGroup);
94 //   CBLog->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
95 //   TopGroupLayout->addMultiCellWidget( CBLog, 3, 3, 0, 1);
96   
97 }
98
99
100
101 void VisuGUI_IsoSurfPane::initFromPrsObject(VISU::IsoSurfaces_i* thePrs) {
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   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
138 bool VisuGUI_IsoSurfPane::check() {
139   if (MinIso->text().toDouble() >= MaxIso->text().toDouble()) {
140     MESSAGE(tr("MSG_MINMAX_VALUES"));
141     QAD_MessageBox::warn1( this,tr("VISU_WARNING"),
142                            tr("MSG_MINMAX_VALUES"),
143                            tr("VISU_BUT_OK"));
144     return false;
145   } // else if (/* CBUpdate->isChecked() && CBLog->isChecked() && */
146 //            (MinIso->text().toDouble() <=0 || MaxIso->text().toDouble() <=0) ) {
147 //     QAD_MessageBox::warn1( this,
148 //                         tr("VISU_WARNING"),
149 //                         tr("WRN_LOGARITHMIC_RANGE_ISOSURF"),
150 //                         tr("VISU_BUT_OK"));
151 //     return false;
152 //   }
153   return true;
154 }
155
156
157
158
159
160 /*!
161   Constructor
162 */
163 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg()
164   : QDialog( QAD_Application::getDesktop(), "VisuGUI_IsoSurfacesDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
165 {
166   setCaption( tr( "Iso Surfaces Definition" ) );
167   setSizeGripEnabled( TRUE );
168   
169   QVBoxLayout* TopLayout = new QVBoxLayout(this);
170   TopLayout->setSpacing( 6 );
171   TopLayout->setMargin(11);
172  
173   QTabWidget* aTabBox = new QTabWidget(this);
174   myIsoPane = new  VisuGUI_IsoSurfPane(this);
175   myIsoPane->setMargin( 5 );
176   aTabBox->addTab(myIsoPane, "Iso Surface");
177   myScalarPane = new VisuGUI_ScalarBarPane(this, false);
178   myIsoPane->setScalarBarPane(myScalarPane);
179   myScalarPane->setMargin( 5 );
180   aTabBox->addTab(myScalarPane, "Scalar Bar");
181
182   TopLayout->addWidget(aTabBox);
183   
184   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
185   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
186   GroupButtons->setColumnLayout(0, Qt::Vertical );
187   GroupButtons->layout()->setSpacing( 0 );
188   GroupButtons->layout()->setMargin( 0 );
189   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
190   GroupButtonsLayout->setAlignment( Qt::AlignTop );
191   GroupButtonsLayout->setSpacing( 6 );
192   GroupButtonsLayout->setMargin( 11 );
193   
194   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
195   buttonOk->setAutoDefault( TRUE );
196   buttonOk->setDefault( TRUE );
197   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
198   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
199   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
200   buttonCancel->setAutoDefault( TRUE );
201   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
202   
203   TopLayout->addWidget(GroupButtons);
204   
205   // signals and slots connections
206   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
207   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
208 }
209
210 void VisuGUI_IsoSurfacesDlg::accept() {
211   if (myIsoPane->check() && myScalarPane->check())  QDialog::accept();
212 }
213