]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_IsoSurfacesDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 #include "VisuGUI_InputPane.h"
34
35 #include "VISU_ColoredPrs3dFactory.hh"
36
37 #include "LightApp_Application.h"
38
39 #include "SUIT_Desktop.h"
40 #include "SUIT_Session.h"
41 #include "SUIT_MessageBox.h"
42 #include "SUIT_ResourceMgr.h"
43
44 #include <limits.h>
45
46 #include <qlayout.h>
47 #include <qvalidator.h>
48 #include <qtabwidget.h>
49
50 using namespace std;
51
52
53 VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent,
54                                           VisuGUI_ScalarBarPane* theScalarPane)
55   : QVBox(parent),
56     myScalarPane(theScalarPane)
57 {
58   QFrame* TopGroup = new QFrame( this, "TopGroup" );
59   TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
60   TopGroup->setLineWidth(1);
61
62   QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
63   TopGroupLayout->setAlignment( Qt::AlignTop );
64   TopGroupLayout->setSpacing( 6 );
65   TopGroupLayout->setMargin( 11 );
66
67   QLabel* LabelNbr = new QLabel (tr("NB_SURFACES"), TopGroup, "LabelNbr");
68   TopGroupLayout->addWidget( LabelNbr, 0, 0 );
69   NbrIso = new QSpinBox( 1, 100, 1, TopGroup, "NbrIso" );
70   NbrIso->setValue( 1 );
71   TopGroupLayout->addWidget( NbrIso, 0, 1 );
72
73   QLabel* LabelMin = new QLabel (tr("MIN_VALUE"), TopGroup, "LabelMin");
74   TopGroupLayout->addWidget(LabelMin, 1, 0);
75   //MinIso = new QtxDblSpinBox( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
76   MinIso = new QLineEdit( TopGroup );
77   MinIso->setValidator( new QDoubleValidator(TopGroup) );
78   MinIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
79   MinIso->setMinimumSize( 70, 0 );
80   LabelMin->setBuddy(MinIso);
81   TopGroupLayout->addWidget( MinIso, 1, 1 );
82
83   QLabel* LabelMax = new QLabel (tr("MAX_VALUE"), TopGroup, "LabelMax");
84   TopGroupLayout->addWidget( LabelMax, 2, 0 );
85   //MaxIso = new QtxSpinBoxDbl( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
86   MaxIso = new QLineEdit( TopGroup );
87   MaxIso->setValidator( new QDoubleValidator(TopGroup) );
88   MaxIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89   MaxIso->setMinimumSize( 70, 0 );
90   LabelMax->setBuddy(MaxIso);
91   TopGroupLayout->addWidget( MaxIso, 2, 1 );
92
93   QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", TopGroup);
94   TopGroupLayout->addMultiCellWidget( aUpdateBtn, 3, 3, 0, 1);
95   connect( aUpdateBtn, SIGNAL( clicked() ), this, SLOT(onCBUpdate() ) );
96 }
97
98 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
99 {
100   NbrIso->setValue(thePrs->GetNbSurfaces());
101   MinIso->setText(QString::number(thePrs->GetSubMin()));
102   MaxIso->setText(QString::number(thePrs->GetSubMax()));
103 }
104
105 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
106 {
107   thePrs->SetNbSurfaces(NbrIso->value());
108   thePrs->SetSubRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
109   return 1;
110 }
111
112 void VisuGUI_IsoSurfPane::onCBUpdate()
113 {
114   myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
115 }
116
117 bool VisuGUI_IsoSurfPane::check()
118 {
119   if (MinIso->text().toDouble() >= MaxIso->text().toDouble()) {
120     MESSAGE(tr("MSG_MINMAX_VALUES"));
121     SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
122                             tr("MSG_MINMAX_VALUES"),
123                             tr("BUT_OK"));
124     return false;
125   }
126   return true;
127 }
128
129
130
131
132
133 /*!
134   Constructor
135 */
136 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
137   : VisuGUI_ScalarBarBaseDlg(theModule)
138 {
139   setCaption(tr("DEFINE_ISOSURFACES"));
140   setSizeGripEnabled( TRUE );
141
142   QVBoxLayout* TopLayout = new QVBoxLayout(this);
143   TopLayout->setSpacing( 6 );
144   TopLayout->setMargin(11);
145
146   myTabBox = new QTabWidget(this);
147   myIsoPane = new  VisuGUI_IsoSurfPane(this, GetScalarPane());
148   myIsoPane->setMargin( 5 );
149   myTabBox->addTab(myIsoPane, "Iso Surface");
150   myInputPane = new VisuGUI_InputPane(VISU::TISOSURFACES, theModule, this);
151   myTabBox->addTab(GetScalarPane(), "Scalar Bar");
152   myTabBox->addTab(myInputPane, "Input");
153
154   TopLayout->addWidget(myTabBox);
155
156   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
157   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
158   GroupButtons->setColumnLayout(0, Qt::Vertical );
159   GroupButtons->layout()->setSpacing( 0 );
160   GroupButtons->layout()->setMargin( 0 );
161   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
162   GroupButtonsLayout->setAlignment( Qt::AlignTop );
163   GroupButtonsLayout->setSpacing( 6 );
164   GroupButtonsLayout->setMargin( 11 );
165
166   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
167   buttonOk->setAutoDefault( TRUE );
168   buttonOk->setDefault( TRUE );
169   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
170   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
171   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
172   buttonCancel->setAutoDefault( TRUE );
173   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
174   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
175   buttonHelp->setAutoDefault( TRUE );
176   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
177
178   TopLayout->addWidget(GroupButtons);
179
180   // signals and slots connections
181   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
182   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
183   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
184 }
185
186 VisuGUI_IsoSurfacesDlg::~VisuGUI_IsoSurfacesDlg()
187 {}
188
189 void VisuGUI_IsoSurfacesDlg::accept()
190 {
191   if ( myIsoPane->check() )
192     VisuGUI_ScalarBarBaseDlg::accept();
193 }
194
195 void VisuGUI_IsoSurfacesDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
196                                                 bool theInit )
197 {
198   if( theInit )
199     myPrsCopy = VISU::TSameAsFactory<VISU::TISOSURFACES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
200
201   VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
202
203   myIsoPane->initFromPrsObject(myPrsCopy);
204
205   if( !theInit )
206     return;
207
208   myInputPane->initFromPrsObject( myPrsCopy );
209   myTabBox->setCurrentPage( 0 );
210 }
211
212 int VisuGUI_IsoSurfacesDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
213 {
214   if(!myInputPane->check() || !GetScalarPane()->check())
215     return 0;
216
217   int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
218   anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
219   anIsOk &= myIsoPane->storeToPrsObject( myPrsCopy );
220
221   VISU::TSameAsFactory<VISU::TISOSURFACES>().Copy(myPrsCopy, thePrs);
222
223   return anIsOk;
224 }
225
226 QString VisuGUI_IsoSurfacesDlg::GetContextHelpFilePath()
227 {
228   return "iso_surfaces_page.html";
229 }