1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_IsoSurfacesDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_IsoSurfacesDlg.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_InputPane.h"
35 #include <VISU_ColoredPrs3dFactory.hh>
37 #include <LightApp_Application.h>
39 #include <SalomeApp_IntSpinBox.h>
41 #include <QtxColorButton.h>
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_ResourceMgr.h>
53 #include <QPushButton>
58 #include <QColorDialog>
59 #include <QButtonGroup>
60 #include <QRadioButton>
62 VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent,
63 VisuGUI_ScalarBarPane* theScalarPane)
65 myScalarPane(theScalarPane)
67 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
68 QFrame* TopGroup = new QFrame( this );
69 aMainLayout->addWidget( TopGroup );
71 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
72 TopGroup->setLineWidth(1);
74 QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
75 TopGroupLayout->setAlignment( Qt::AlignTop );
76 TopGroupLayout->setSpacing( 6 );
77 TopGroupLayout->setMargin( 11 );
79 QGroupBox* aRangeBox = new QGroupBox( tr( "RANGE" ), this );
80 QRadioButton* aUseScalarBarRange = new QRadioButton( tr( "USE_SCALAR_BAR_RANGE" ), aRangeBox );
81 QRadioButton* aUseCustomRange = new QRadioButton( tr( "USE_CUSTOM_RANGE" ), aRangeBox );
83 myRangeGrp = new QButtonGroup( aRangeBox );
84 myRangeGrp->addButton( aUseScalarBarRange, ScalarBarRange );
85 myRangeGrp->addButton( aUseCustomRange, CustomRange );
86 aUseScalarBarRange->setChecked( true );
88 connect( myRangeGrp, SIGNAL( buttonClicked( int ) ), this, SLOT( onRangeButtonClicked( int ) ) );
90 QLabel* LabelMin = new QLabel( tr( "MIN_VALUE" ), aRangeBox );
91 MinIso = new QLineEdit( aRangeBox );
92 MinIso->setValidator( new QDoubleValidator( aRangeBox ) );
93 MinIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
94 MinIso->setMinimumSize( 70, 0 );
95 LabelMin->setBuddy( MinIso );
97 QLabel* LabelMax = new QLabel( tr( "MAX_VALUE" ), aRangeBox );
98 MaxIso = new QLineEdit( aRangeBox );
99 MaxIso->setValidator( new QDoubleValidator( aRangeBox ) );
100 MaxIso->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
101 MaxIso->setMinimumSize( 70, 0 );
102 LabelMax->setBuddy( MaxIso );
104 QPushButton* aUpdateBtn = new QPushButton( "Update scalar bar range with these values", aRangeBox );
105 aUpdateBtn->setEnabled( false );
106 connect( aUpdateBtn, SIGNAL( clicked() ), this, SLOT(onCBUpdate() ) );
107 connect( aUseCustomRange, SIGNAL( toggled( bool ) ), aUpdateBtn, SLOT( setEnabled( bool ) ) );
109 QGridLayout* aRangeLayout = new QGridLayout( aRangeBox );
110 aRangeLayout->setSpacing( 6 );
111 aRangeLayout->setMargin( 11 );
112 aRangeLayout->addWidget( aUseScalarBarRange, 0, 0 );
113 aRangeLayout->addWidget( aUseCustomRange, 0, 1 );
114 aRangeLayout->addWidget( LabelMin, 1, 0 );
115 aRangeLayout->addWidget( MinIso, 1, 1 );
116 aRangeLayout->addWidget( LabelMax, 2, 0 );
117 aRangeLayout->addWidget( MaxIso, 2, 1 );
118 aRangeLayout->addWidget( aUpdateBtn, 3, 0, 1, 2 );
120 TopGroupLayout->addWidget( aRangeBox, 0, 0, 1, 2 );
122 QLabel* LabelNbr = new QLabel (tr("NB_SURFACES"), TopGroup);
123 TopGroupLayout->addWidget( LabelNbr, 1, 0 );
124 NbrIso = new SalomeApp_IntSpinBox( TopGroup );
125 NbrIso->setAcceptNames( false );
126 NbrIso->setMaximum( 100 );
127 NbrIso->setMinimum( 1 );
128 NbrIso->setSingleStep( 1 );
129 NbrIso->setValue( 1 );
130 TopGroupLayout->addWidget( NbrIso, 1, 1 );
132 myUseMagnitude = new QCheckBox(tr("MAGNITUDE_COLORING_CHK"), TopGroup);
133 myUseMagnitude->setChecked(true);
134 TopGroupLayout->addWidget( myUseMagnitude, 2, 0 );
136 mySelColor = new QtxColorButton( TopGroup );
137 mySelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
138 TopGroupLayout->addWidget( mySelColor, 2, 1 );
139 //connect( mySelColor, SIGNAL( clicked() ), this, SLOT( setColor() ) );
140 connect( myUseMagnitude, SIGNAL( toggled(bool) ), mySelColor, SLOT( setDisabled(bool) ) );
142 myUseLabels = new QCheckBox(tr("SHOW_VALUES_CHK"), TopGroup);
143 myUseLabels->setChecked(false);
144 TopGroupLayout->addWidget( myUseLabels, 3, 0 );
145 myNbLabels = new SalomeApp_IntSpinBox( TopGroup );
146 myNbLabels->setAcceptNames( false );
147 myNbLabels->setMinimum(1);
148 myNbLabels->setMaximum(100);
149 myNbLabels->setSingleStep(1);
150 myNbLabels->setEnabled(false);
151 TopGroupLayout->addWidget( myNbLabels, 3, 1 );
152 connect( myUseLabels, SIGNAL( toggled(bool) ), myNbLabels, SLOT( setEnabled(bool) ) );
154 mySelColor->setEnabled( !myUseMagnitude->isChecked() );
157 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
159 NbrIso->setValue(thePrs->GetNbSurfaces());
160 MinIso->setText(QString::number(thePrs->GetSubMin()));
161 MaxIso->setText(QString::number(thePrs->GetSubMax()));
163 int anId = thePrs->IsSubRangeFixed() ? ScalarBarRange : CustomRange;
164 bool anIsSubRangeFixed = thePrs->IsSubRangeFixed();
165 myRangeGrp->button( anId )->setChecked( true );
166 onRangeButtonClicked( anId );
168 myUseMagnitude->setChecked(thePrs->IsColored());
169 SALOMEDS::Color anOldColor = thePrs->GetColor();
170 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
173 myUseLabels->setChecked(thePrs->IsLabeled());
174 myNbLabels->setValue(thePrs->GetNbLabels());
175 mySelColor->setEnabled( !myUseMagnitude->isChecked() );
178 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
180 thePrs->SetNbSurfaces(NbrIso->value());
182 if( myRangeGrp->checkedId() == ScalarBarRange )
184 thePrs->SetSubRange( myScalarPane->getMin(), myScalarPane->getMax() );
185 thePrs->SetSubRangeFixed( true );
189 thePrs->SetSubRange( MinIso->text().toDouble(), MaxIso->text().toDouble() );
190 thePrs->SetSubRangeFixed( false );
193 thePrs->ShowLabels(myUseLabels->isChecked(), myNbLabels->value());
194 thePrs->ShowColored(myUseMagnitude->isChecked());
195 if(!thePrs->IsColored()){
196 QColor aQColor = color();
197 SALOMEDS::Color aColor;
198 aColor.R = aQColor.red()/255.;
199 aColor.G = aQColor.green()/255.;
200 aColor.B = aQColor.blue()/255.;
201 thePrs->SetColor(aColor);
206 void VisuGUI_IsoSurfPane::onRangeButtonClicked( int theId )
208 bool isCustomRange = theId == 1;
209 MinIso->setEnabled( isCustomRange );
210 MaxIso->setEnabled( isCustomRange );
213 void VisuGUI_IsoSurfPane::onCBUpdate()
215 myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
218 bool VisuGUI_IsoSurfPane::check()
220 if (MinIso->text().toDouble() >= MaxIso->text().toDouble()) {
221 MESSAGE(tr("MSG_MINMAX_VALUES").toLatin1().data());
222 SUIT_MessageBox::warning( this,tr("WRN_VISU"),
223 tr("MSG_MINMAX_VALUES"),
230 void VisuGUI_IsoSurfPane::setColor()
232 QColor cnew = QColorDialog::getColor( color(), this );
233 if ( cnew.isValid() )
237 void VisuGUI_IsoSurfPane::setColor( const QColor& theColor)
239 /* QPalette pal = mySelColor->palette();
240 pal.setColor(mySelColor->backgroundRole(), theColor);
241 mySelColor->setPalette(pal);*/
242 mySelColor->setColor( theColor );
245 QColor VisuGUI_IsoSurfPane::color() const
247 return mySelColor->color();
254 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
255 : VisuGUI_ScalarBarBaseDlg(theModule)
257 setWindowTitle(tr("DEFINE_ISOSURFACES"));
258 setSizeGripEnabled( TRUE );
260 QVBoxLayout* TopLayout = new QVBoxLayout(this);
261 TopLayout->setSpacing( 6 );
262 TopLayout->setMargin(11);
264 myTabBox = new QTabWidget(this);
265 myIsoPane = new VisuGUI_IsoSurfPane(this, GetScalarPane());
266 if ( myIsoPane->layout() )
267 myIsoPane->layout()->setMargin( 5 );
268 myTabBox->addTab(myIsoPane, "Iso Surface");
269 myInputPane = new VisuGUI_InputPane(VISU::TISOSURFACES, theModule, this);
270 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
271 myTabBox->addTab(myInputPane, "Input");
273 TopLayout->addWidget(myTabBox);
275 QGroupBox* GroupButtons = new QGroupBox( this );
276 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
277 //GroupButtons->setColumnLayout(0, Qt::Vertical );
278 //GroupButtons->layout()->setSpacing( 0 );
279 //GroupButtons->layout()->setMargin( 0 );
280 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
281 GroupButtonsLayout->setAlignment( Qt::AlignTop );
282 GroupButtonsLayout->setSpacing( 6 );
283 GroupButtonsLayout->setMargin( 11 );
285 QPushButton* buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
286 buttonOk->setAutoDefault( TRUE );
287 buttonOk->setDefault( TRUE );
288 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
289 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
290 QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
291 buttonCancel->setAutoDefault( TRUE );
292 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
293 QPushButton* buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
294 buttonHelp->setAutoDefault( TRUE );
295 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
297 TopLayout->addWidget(GroupButtons);
299 // signals and slots connections
300 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
301 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
302 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
305 VisuGUI_IsoSurfacesDlg::~VisuGUI_IsoSurfacesDlg()
308 void VisuGUI_IsoSurfacesDlg::accept()
310 if ( myIsoPane->check() )
311 VisuGUI_ScalarBarBaseDlg::accept();
314 void VisuGUI_IsoSurfacesDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
318 myPrsCopy = VISU::TSameAsFactory<VISU::TISOSURFACES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
320 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
322 myIsoPane->initFromPrsObject(myPrsCopy);
327 myInputPane->initFromPrsObject( myPrsCopy );
328 myTabBox->setCurrentIndex( 0 );
331 int VisuGUI_IsoSurfacesDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
333 if(!myInputPane->check() || !GetScalarPane()->check())
336 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
337 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
338 anIsOk &= myIsoPane->storeToPrsObject( myPrsCopy );
340 VISU::TSameAsFactory<VISU::TISOSURFACES>().Copy(myPrsCopy, thePrs);
345 QString VisuGUI_IsoSurfacesDlg::GetContextHelpFilePath()
347 return "iso_surfaces_page.html";