1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : VisuGUI_IsoSurfacesDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_IsoSurfacesDlg.h"
32 #include "VisuGUI_Tools.h"
34 #include "LightApp_Application.h"
36 #include "SUIT_Desktop.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_MessageBox.h"
39 #include "SUIT_ResourceMgr.h"
44 #include <qvalidator.h>
45 #include <qtabwidget.h>
50 VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent)
53 QFrame* TopGroup = new QFrame( this, "TopGroup" );
54 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
55 TopGroup->setLineWidth(1);
57 QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
58 TopGroupLayout->setAlignment( Qt::AlignTop );
59 TopGroupLayout->setSpacing( 6 );
60 TopGroupLayout->setMargin( 11 );
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 );
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 );
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 );
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() ) );
97 // CBLog = new QCheckBox ( tr( "Logarithmic scaling" ), TopGroup);
98 // CBLog->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed) );
99 // TopGroupLayout->addMultiCellWidget( CBLog, 3, 3, 0, 1);
102 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
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);
112 // CBLog->setChecked(false);
116 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
118 thePrs->SetNbSurfaces(NbrIso->value());
119 thePrs->SetSubRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
121 // if (CBUpdate->isChecked())
123 // thePrs->SetRange(MinIso->text().toDouble(), MaxIso->text().toDouble());
124 // if (CBLog->isChecked())
125 // thePrs->SetScaling(VISU::LOGARITHMIC);
127 // thePrs->SetScaling(VISU::LINEAR);
131 void VisuGUI_IsoSurfPane::onCBUpdate()
133 // if (CBUpdate->isChecked()) {
134 myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
136 // CBLog->setDisabled(false);
137 // else CBLog->setDisabled(true);
140 bool VisuGUI_IsoSurfPane::check()
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"),
148 } // else if (/* CBUpdate->isChecked() && CBLog->isChecked() && */
149 // (MinIso->text().toDouble() <=0 || MaxIso->text().toDouble() <=0) ) {
150 // SUIT_MessageBox::warn1( this,
152 // tr("WRN_LOGARITHMIC_RANGE_ISOSURF"),
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)
170 setCaption(tr("DEFINE_ISOSURFACES"));
171 setSizeGripEnabled( TRUE );
173 QVBoxLayout* TopLayout = new QVBoxLayout(this);
174 TopLayout->setSpacing( 6 );
175 TopLayout->setMargin(11);
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");
186 TopLayout->addWidget(aTabBox);
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 );
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 );
210 TopLayout->addWidget(GroupButtons);
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() ) );
218 void VisuGUI_IsoSurfacesDlg::accept()
220 if (myIsoPane->check() && myScalarPane->check())
222 myScalarPane->deletePreview();
227 void VisuGUI_IsoSurfacesDlg::reject()
229 myScalarPane->deletePreview();
233 void VisuGUI_IsoSurfacesDlg::onHelp()
235 QString aHelpFileName = "/files/iso_surfaces_presentation.htm";
236 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
238 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
239 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
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"));