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