1 // Copyright (C) 2007-2008 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
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_IsoSurfacesDlg.cxx
24 // Author : Laurent CORNABE & Hubert ROLLAND
28 #include "VisuGUI_IsoSurfacesDlg.h"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_InputPane.h"
34 #include <VISU_ColoredPrs3dFactory.hh>
36 #include <LightApp_Application.h>
38 #include <QtxColorButton.h>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
51 #include <QPushButton>
56 #include <QColorDialog>
57 #include <QButtonGroup>
58 #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 QSpinBox( TopGroup );
125 NbrIso->setMaximum( 100 );
126 NbrIso->setMinimum( 1 );
127 NbrIso->setSingleStep( 1 );
128 NbrIso->setValue( 1 );
129 TopGroupLayout->addWidget( NbrIso, 1, 1 );
131 myUseMagnitude = new QCheckBox(tr("MAGNITUDE_COLORING_CHK"), TopGroup);
132 myUseMagnitude->setChecked(true);
133 TopGroupLayout->addWidget( myUseMagnitude, 2, 0 );
135 mySelColor = new QtxColorButton( TopGroup );
136 mySelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
137 TopGroupLayout->addWidget( mySelColor, 2, 1 );
138 //connect( mySelColor, SIGNAL( clicked() ), this, SLOT( setColor() ) );
139 connect( myUseMagnitude, SIGNAL( toggled(bool) ), mySelColor, SLOT( setDisabled(bool) ) );
141 myUseLabels = new QCheckBox(tr("SHOW_VALUES_CHK"), TopGroup);
142 myUseLabels->setChecked(false);
143 TopGroupLayout->addWidget( myUseLabels, 3, 0 );
144 myNbLabels = new QSpinBox( TopGroup );
145 myNbLabels->setMinimum(1);
146 myNbLabels->setMaximum(100);
147 myNbLabels->setSingleStep(1);
148 myNbLabels->setEnabled(false);
149 TopGroupLayout->addWidget( myNbLabels, 3, 1 );
150 connect( myUseLabels, SIGNAL( toggled(bool) ), myNbLabels, SLOT( setEnabled(bool) ) );
152 mySelColor->setEnabled( !myUseMagnitude->isChecked() );
155 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
157 NbrIso->setValue(thePrs->GetNbSurfaces());
158 MinIso->setText(QString::number(thePrs->GetSubMin()));
159 MaxIso->setText(QString::number(thePrs->GetSubMax()));
161 int anId = thePrs->IsSubRangeFixed() ? ScalarBarRange : CustomRange;
162 bool anIsSubRangeFixed = thePrs->IsSubRangeFixed();
163 myRangeGrp->button( anId )->setChecked( true );
164 onRangeButtonClicked( anId );
166 myUseMagnitude->setChecked(thePrs->IsColored());
167 SALOMEDS::Color anOldColor = thePrs->GetColor();
168 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
171 myUseLabels->setChecked(thePrs->IsLabeled());
172 myNbLabels->setValue(thePrs->GetNbLabels());
173 mySelColor->setEnabled( !myUseMagnitude->isChecked() );
176 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
178 thePrs->SetNbSurfaces(NbrIso->value());
180 if( myRangeGrp->checkedId() == ScalarBarRange )
182 thePrs->SetSubRange( myScalarPane->getMin(), myScalarPane->getMax() );
183 thePrs->SetSubRangeFixed( true );
187 thePrs->SetSubRange( MinIso->text().toDouble(), MaxIso->text().toDouble() );
188 thePrs->SetSubRangeFixed( false );
191 thePrs->ShowLabels(myUseLabels->isChecked(), myNbLabels->value());
192 thePrs->ShowColored(myUseMagnitude->isChecked());
193 if(!thePrs->IsColored()){
194 QColor aQColor = color();
195 SALOMEDS::Color aColor;
196 aColor.R = aQColor.red()/255.;
197 aColor.G = aQColor.green()/255.;
198 aColor.B = aQColor.blue()/255.;
199 thePrs->SetColor(aColor);
204 void VisuGUI_IsoSurfPane::onRangeButtonClicked( int theId )
206 bool isCustomRange = theId == 1;
207 MinIso->setEnabled( isCustomRange );
208 MaxIso->setEnabled( isCustomRange );
211 void VisuGUI_IsoSurfPane::onCBUpdate()
213 myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
216 bool VisuGUI_IsoSurfPane::check()
218 if (MinIso->text().toDouble() >= MaxIso->text().toDouble()) {
219 MESSAGE(tr("MSG_MINMAX_VALUES").toLatin1().data());
220 SUIT_MessageBox::warning( this,tr("WRN_VISU"),
221 tr("MSG_MINMAX_VALUES"),
228 void VisuGUI_IsoSurfPane::setColor()
230 QColor cnew = QColorDialog::getColor( color(), this );
231 if ( cnew.isValid() )
235 void VisuGUI_IsoSurfPane::setColor( const QColor& theColor)
237 /* QPalette pal = mySelColor->palette();
238 pal.setColor(mySelColor->backgroundRole(), theColor);
239 mySelColor->setPalette(pal);*/
240 mySelColor->setColor( theColor );
243 QColor VisuGUI_IsoSurfPane::color() const
245 return mySelColor->color();
252 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
253 : VisuGUI_ScalarBarBaseDlg(theModule)
255 setWindowTitle(tr("DEFINE_ISOSURFACES"));
256 setSizeGripEnabled( TRUE );
258 QVBoxLayout* TopLayout = new QVBoxLayout(this);
259 TopLayout->setSpacing( 6 );
260 TopLayout->setMargin(11);
262 myTabBox = new QTabWidget(this);
263 myIsoPane = new VisuGUI_IsoSurfPane(this, GetScalarPane());
264 if ( myIsoPane->layout() )
265 myIsoPane->layout()->setMargin( 5 );
266 myTabBox->addTab(myIsoPane, "Iso Surface");
267 myInputPane = new VisuGUI_InputPane(VISU::TISOSURFACES, theModule, this);
268 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
269 myTabBox->addTab(myInputPane, "Input");
271 TopLayout->addWidget(myTabBox);
273 QGroupBox* GroupButtons = new QGroupBox( this );
274 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
275 //GroupButtons->setColumnLayout(0, Qt::Vertical );
276 //GroupButtons->layout()->setSpacing( 0 );
277 //GroupButtons->layout()->setMargin( 0 );
278 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
279 GroupButtonsLayout->setAlignment( Qt::AlignTop );
280 GroupButtonsLayout->setSpacing( 6 );
281 GroupButtonsLayout->setMargin( 11 );
283 QPushButton* buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
284 buttonOk->setAutoDefault( TRUE );
285 buttonOk->setDefault( TRUE );
286 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
287 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
288 QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
289 buttonCancel->setAutoDefault( TRUE );
290 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
291 QPushButton* buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
292 buttonHelp->setAutoDefault( TRUE );
293 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
295 TopLayout->addWidget(GroupButtons);
297 // signals and slots connections
298 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
299 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
300 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
303 VisuGUI_IsoSurfacesDlg::~VisuGUI_IsoSurfacesDlg()
306 void VisuGUI_IsoSurfacesDlg::accept()
308 if ( myIsoPane->check() )
309 VisuGUI_ScalarBarBaseDlg::accept();
312 void VisuGUI_IsoSurfacesDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
316 myPrsCopy = VISU::TSameAsFactory<VISU::TISOSURFACES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
318 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
320 myIsoPane->initFromPrsObject(myPrsCopy);
325 myInputPane->initFromPrsObject( myPrsCopy );
326 myTabBox->setCurrentIndex( 0 );
329 int VisuGUI_IsoSurfacesDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
331 if(!myInputPane->check() || !GetScalarPane()->check())
334 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
335 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
336 anIsOk &= myIsoPane->storeToPrsObject( myPrsCopy );
338 VISU::TSameAsFactory<VISU::TISOSURFACES>().Copy(myPrsCopy, thePrs);
343 QString VisuGUI_IsoSurfacesDlg::GetContextHelpFilePath()
345 return "iso_surfaces_page.html";