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>
60 VisuGUI_IsoSurfPane::VisuGUI_IsoSurfPane (QWidget* parent,
61 VisuGUI_ScalarBarPane* theScalarPane)
63 myScalarPane(theScalarPane)
65 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
66 QFrame* TopGroup = new QFrame( this );
67 aMainLayout->addWidget( TopGroup );
69 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
70 TopGroup->setLineWidth(1);
72 QGridLayout* TopGroupLayout = new QGridLayout(TopGroup);
73 TopGroupLayout->setAlignment( Qt::AlignTop );
74 TopGroupLayout->setSpacing( 6 );
75 TopGroupLayout->setMargin( 11 );
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 );
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 );
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 );
106 myUseMagnitude = new QCheckBox(tr("MAGNITUDE_COLORING_CHK"), TopGroup);
107 myUseMagnitude->setChecked(true);
108 TopGroupLayout->addWidget( myUseMagnitude, 3, 0 );
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) ) );
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) ) );
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() );
133 void VisuGUI_IsoSurfPane::initFromPrsObject (VISU::IsoSurfaces_i* thePrs)
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));
143 myUseLabels->setChecked(thePrs->IsLabeled());
144 myNbLabels->setValue(thePrs->GetNbLabels());
145 mySelColor->setEnabled( !myUseMagnitude->isChecked() );
148 int VisuGUI_IsoSurfPane::storeToPrsObject (VISU::IsoSurfaces_i* thePrs)
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);
165 void VisuGUI_IsoSurfPane::onCBUpdate()
167 myScalarPane->setRange(MinIso->text().toDouble(), MaxIso->text().toDouble(), true);
170 bool VisuGUI_IsoSurfPane::check()
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"),
182 void VisuGUI_IsoSurfPane::setColor()
184 QColor cnew = QColorDialog::getColor( color(), this );
185 if ( cnew.isValid() )
189 void VisuGUI_IsoSurfPane::setColor( const QColor& theColor)
191 /* QPalette pal = mySelColor->palette();
192 pal.setColor(mySelColor->backgroundRole(), theColor);
193 mySelColor->setPalette(pal);*/
194 mySelColor->setColor( theColor );
197 QColor VisuGUI_IsoSurfPane::color() const
199 return mySelColor->color();
206 VisuGUI_IsoSurfacesDlg::VisuGUI_IsoSurfacesDlg (SalomeApp_Module* theModule)
207 : VisuGUI_ScalarBarBaseDlg(theModule)
209 setWindowTitle(tr("DEFINE_ISOSURFACES"));
210 setSizeGripEnabled( TRUE );
212 QVBoxLayout* TopLayout = new QVBoxLayout(this);
213 TopLayout->setSpacing( 6 );
214 TopLayout->setMargin(11);
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");
225 TopLayout->addWidget(myTabBox);
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 );
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 );
249 TopLayout->addWidget(GroupButtons);
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() ) );
257 VisuGUI_IsoSurfacesDlg::~VisuGUI_IsoSurfacesDlg()
260 void VisuGUI_IsoSurfacesDlg::accept()
262 if ( myIsoPane->check() )
263 VisuGUI_ScalarBarBaseDlg::accept();
266 void VisuGUI_IsoSurfacesDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
270 myPrsCopy = VISU::TSameAsFactory<VISU::TISOSURFACES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
272 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
274 myIsoPane->initFromPrsObject(myPrsCopy);
279 myInputPane->initFromPrsObject( myPrsCopy );
280 myTabBox->setCurrentIndex( 0 );
283 int VisuGUI_IsoSurfacesDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
285 if(!myInputPane->check() || !GetScalarPane()->check())
288 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
289 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
290 anIsOk &= myIsoPane->storeToPrsObject( myPrsCopy );
292 VISU::TSameAsFactory<VISU::TISOSURFACES>().Copy(myPrsCopy, thePrs);
297 QString VisuGUI_IsoSurfacesDlg::GetContextHelpFilePath()
299 return "iso_surfaces_page.html";