]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_IsoSurfacesDlg.cxx
Salome HOME
Bug IPAL21228 SIGSEGV on exit from Salome with active GaussPointsDlg
[modules/visu.git] / src / VISUGUI / VisuGUI_IsoSurfacesDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_IsoSurfacesDlg.cxx
24 //  Author : Laurent CORNABE & Hubert ROLLAND
25 //  Module : VISU
26 //  $Header$
27
28 #include "VisuGUI_IsoSurfacesDlg.h"
29
30 #include "VisuGUI.h"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_InputPane.h"
33
34 #include <VISU_ColoredPrs3dFactory.hh>
35
36 #include <LightApp_Application.h>
37
38 #include <QtxColorButton.h>
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>
47 #include <QValidator>
48 #include <QLabel>
49 #include <QGroupBox>
50 #include <QSpinBox>
51 #include <QPushButton>
52 #include <QCheckBox>
53 #include <QLineEdit>
54 #include <QTabWidget>
55 #include <QKeyEvent>
56 #include <QColorDialog>
57
58 using namespace std;
59
60 VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent,
61                                           VisuGUI_ScalarBarPane* theScalarPane)
62   : QWidget(parent),
63     myScalarPane(theScalarPane)
64 {
65   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
66   QFrame* TopGroup = new QFrame( this );
67   aMainLayout->addWidget( TopGroup );
68   
69   TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
70   TopGroup->setLineWidth(1);
71
72   QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
73   TopGroupLayout->setAlignment( Qt::AlignTop );
74   TopGroupLayout->setSpacing( 6 );
75   TopGroupLayout->setMargin( 11 );
76
77   QLabel* LabelNbr = new QLabel (tr("NB_SURFACES"), TopGroup);
78   TopGroupLayout->addWidget( LabelNbr, 0, 0 );
79   NbrIso = new QSpinBox( TopGroup );
80   NbrIso->setMaximum( 100 );
81   NbrIso->setMinimum( 1 );
82   NbrIso->setSingleStep( 1 );
83   NbrIso->setValue( 1 );
84   TopGroupLayout->addWidget( NbrIso, 0, 1 );
85
86   QLabel* LabelMin = new QLabel (tr("MIN_VALUE"), TopGroup );
87   TopGroupLayout->addWidget(LabelMin, 1, 0);
88   //MinIso = new QtxDoubleSpinBox( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
89   MinIso = new QLineEdit( TopGroup );
90   MinIso->setValidator( new QDoubleValidator(TopGroup) );
91   MinIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
92   MinIso->setMinimumSize( 70, 0 );
93   LabelMin->setBuddy(MinIso);
94   TopGroupLayout->addWidget( MinIso, 1, 1 );
95
96   QLabel* LabelMax = new QLabel (tr("MAX_VALUE"), TopGroup );
97   TopGroupLayout->addWidget( LabelMax, 2, 0 );
98   //MaxIso = new QtxSpinBoxDbl( -DBL_MAX, DBL_MAX, 0.1, TopGroup );
99   MaxIso = new QLineEdit( TopGroup );
100   MaxIso->setValidator( new QDoubleValidator(TopGroup) );
101   MaxIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
102   MaxIso->setMinimumSize( 70, 0 );
103   LabelMax->setBuddy(MaxIso);
104   TopGroupLayout->addWidget( MaxIso, 2, 1 );
105
106   myUseMagnitude = new QCheckBox(tr("MAGNITUDE_COLORING_CHK"), TopGroup);
107   myUseMagnitude->setChecked(true);
108   TopGroupLayout->addWidget( myUseMagnitude, 3, 0 );
109
110   mySelColor = new QtxColorButton( TopGroup );
111   mySelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
112   TopGroupLayout->addWidget( mySelColor, 3, 1 );
113   //connect( mySelColor, SIGNAL( clicked() ), this, SLOT( setColor() ) );
114   connect( myUseMagnitude, SIGNAL( toggled(bool) ), mySelColor, SLOT( setDisabled(bool) ) );
115
116   myUseLabels = new QCheckBox(tr("SHOW_VALUES_CHK"), TopGroup);
117   myUseLabels->setChecked(false);
118   TopGroupLayout->addWidget( myUseLabels, 4, 0 );
119   myNbLabels = new QSpinBox( TopGroup );
120   myNbLabels->setMinimum(1);
121   myNbLabels->setMaximum(100);
122   myNbLabels->setSingleStep(1);
123   myNbLabels->setEnabled(false);
124   TopGroupLayout->addWidget( myNbLabels, 4, 1 );
125   connect( myUseLabels, SIGNAL( toggled(bool) ), myNbLabels, SLOT( setEnabled(bool) ) );
126
127   QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", TopGroup);
128   TopGroupLayout->addWidget( aUpdateBtn, 5, 0, 1, 2);
129   connect( aUpdateBtn, SIGNAL( clicked() ), this, SLOT(onCBUpdate() ) );
130   mySelColor->setEnabled( !myUseMagnitude->isChecked() );
131 }
132
133 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
134 {
135   NbrIso->setValue(thePrs->GetNbSurfaces());
136   MinIso->setText(QString::number(thePrs->GetSubMin()));
137   MaxIso->setText(QString::number(thePrs->GetSubMax()));
138   myUseMagnitude->setChecked(thePrs->IsColored());
139   SALOMEDS::Color anOldColor = thePrs->GetColor();
140   QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
141   setColor(aColor);
142
143   myUseLabels->setChecked(thePrs->IsLabeled());
144   myNbLabels->setValue(thePrs->GetNbLabels());
145   mySelColor->setEnabled( !myUseMagnitude->isChecked() );
146 }
147
148 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
149 {
150   thePrs->SetNbSurfaces(NbrIso->value());
151   thePrs->SetSubRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
152   thePrs->ShowLabels(myUseLabels->isChecked(), myNbLabels->value());
153   thePrs->ShowColored(myUseMagnitude->isChecked());
154   if(!thePrs->IsColored()){
155     QColor aQColor = color();
156     SALOMEDS::Color aColor;
157     aColor.R = aQColor.red()/255.;
158     aColor.G = aQColor.green()/255.;
159     aColor.B = aQColor.blue()/255.;
160     thePrs->SetColor(aColor);
161   }
162   return 1;
163 }
164
165 void VisuGUI_IsoSurfPane::onCBUpdate()
166 {
167   myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
168 }
169
170 bool VisuGUI_IsoSurfPane::check()
171 {
172   if (MinIso->text().toDouble() >= MaxIso->text().toDouble()) {
173     MESSAGE(tr("MSG_MINMAX_VALUES").toLatin1().data());
174     SUIT_MessageBox::warning( this,tr("WRN_VISU"),
175                               tr("MSG_MINMAX_VALUES"),
176                               tr("BUT_OK"));
177     return false;
178   }
179   return true;
180 }
181
182 void VisuGUI_IsoSurfPane::setColor()
183 {
184   QColor cnew = QColorDialog::getColor( color(), this );
185   if ( cnew.isValid() )
186     setColor(cnew);
187 }
188
189 void VisuGUI_IsoSurfPane::setColor( const QColor& theColor)
190 {
191   /*  QPalette pal = mySelColor->palette();
192   pal.setColor(mySelColor->backgroundRole(), theColor);
193   mySelColor->setPalette(pal);*/
194   mySelColor->setColor( theColor );
195 }
196
197 QColor VisuGUI_IsoSurfPane::color() const
198 {
199   return mySelColor->color();
200 }
201
202
203 /*!
204   Constructor
205 */
206 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
207   : VisuGUI_ScalarBarBaseDlg(theModule)
208 {
209   setWindowTitle(tr("DEFINE_ISOSURFACES"));
210   setSizeGripEnabled( TRUE );
211
212   QVBoxLayout* TopLayout = new QVBoxLayout(this);
213   TopLayout->setSpacing( 6 );
214   TopLayout->setMargin(11);
215
216   myTabBox = new QTabWidget(this);
217   myIsoPane = new  VisuGUI_IsoSurfPane(this, GetScalarPane());
218   if ( myIsoPane->layout() )
219     myIsoPane->layout()->setMargin( 5 );
220   myTabBox->addTab(myIsoPane, "Iso Surface");
221   myInputPane = new VisuGUI_InputPane(VISU::TISOSURFACES, theModule, this);
222   myTabBox->addTab(GetScalarPane(), "Scalar Bar");
223   myTabBox->addTab(myInputPane, "Input");
224
225   TopLayout->addWidget(myTabBox);
226
227   QGroupBox* GroupButtons = new QGroupBox( this );
228   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
229   //GroupButtons->setColumnLayout(0, Qt::Vertical );
230   //GroupButtons->layout()->setSpacing( 0 );
231   //GroupButtons->layout()->setMargin( 0 );
232   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
233   GroupButtonsLayout->setAlignment( Qt::AlignTop );
234   GroupButtonsLayout->setSpacing( 6 );
235   GroupButtonsLayout->setMargin( 11 );
236
237   QPushButton* buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
238   buttonOk->setAutoDefault( TRUE );
239   buttonOk->setDefault( TRUE );
240   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
241   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
242   QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
243   buttonCancel->setAutoDefault( TRUE );
244   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
245   QPushButton* buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
246   buttonHelp->setAutoDefault( TRUE );
247   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
248
249   TopLayout->addWidget(GroupButtons);
250
251   // signals and slots connections
252   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
253   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
254   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
255 }
256
257 VisuGUI_IsoSurfacesDlg::~VisuGUI_IsoSurfacesDlg()
258 {}
259
260 void VisuGUI_IsoSurfacesDlg::accept()
261 {
262   if ( myIsoPane->check() )
263     VisuGUI_ScalarBarBaseDlg::accept();
264 }
265
266 void VisuGUI_IsoSurfacesDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
267                                                 bool theInit )
268 {
269   if( theInit )
270     myPrsCopy = VISU::TSameAsFactory<VISU::TISOSURFACES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
271
272   VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
273
274   myIsoPane->initFromPrsObject(myPrsCopy);
275
276   if( !theInit )
277     return;
278
279   myInputPane->initFromPrsObject( myPrsCopy );
280   myTabBox->setCurrentIndex( 0 );
281 }
282
283 int VisuGUI_IsoSurfacesDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
284 {
285   if(!myInputPane->check() || !GetScalarPane()->check())
286     return 0;
287   
288   int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
289   anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
290   anIsOk &= myIsoPane->storeToPrsObject( myPrsCopy );
291
292   VISU::TSameAsFactory<VISU::TISOSURFACES>().Copy(myPrsCopy, thePrs);
293
294   return anIsOk;
295 }
296
297 QString VisuGUI_IsoSurfacesDlg::GetContextHelpFilePath()
298 {
299   return "iso_surfaces_page.html";
300 }