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_GaussPointsDlg.cxx
25 // Author : Oleg UVAROV
28 #include "VisuGUI_GaussPointsDlg.h"
30 #include "VISUConfig.hh"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_InputPane.h"
34 #include "VisuGUI_PrimitiveBox.h"
35 #include "VisuGUI_SizeBox.h"
37 #include "VISU_ColoredPrs3dFactory.hh"
38 #include "VISU_GaussPoints_i.hh"
39 #include "VISU_Prs3dUtils.hh"
40 #include "VISU_GaussPointsPL.hxx"
41 #include "VISU_OpenGLPointSpriteMapper.hxx"
42 #include "VISU_Convertor.hxx"
44 #include "LightApp_Application.h"
45 #include "SalomeApp_Module.h"
46 #include "SalomeApp_IntSpinBox.h"
47 #include <SalomeApp_DoubleSpinBox.h>
48 #include "LightApp_SelectionMgr.h"
49 #include "SUIT_Desktop.h"
50 #include "SUIT_ResourceMgr.h"
51 #include "SUIT_Session.h"
52 #include "SUIT_MessageBox.h"
53 #include "SVTK_FontWidget.h"
57 #include <QButtonGroup>
58 #include <QRadioButton>
59 #include <QFileDialog>
61 #include <QColorDialog>
65 #include <QPushButton>
68 #include <QToolButton>
72 #include <vtkPolyData.h>
73 #include <vtkDataSet.h>
74 #include <vtkSphereSource.h>
78 VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent):
81 myVerX = 0.01; myVerY = 0.10; myVerW = 0.08; myVerH = 0.80;
82 myHorX = 0.10; myHorY = 0.01; myHorW = 0.80; myHorH = 0.08;
83 myVerTS = myVerLS = myVerBW = myVerBH = 0;
84 myHorTS = myHorLS = myHorBW = myHorBH = 0;
85 Imin = 0.0; Imax = 0.0;
88 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
89 aMainLayout->setSpacing(6);
92 // Active bar ========================================================
93 QGroupBox* ActiveBarGroup = new QGroupBox (tr("ACTIVE_BAR_GRP"), this );
94 aMainLayout->addWidget(ActiveBarGroup);
95 //ActiveBarGroup->setColumnLayout(0, Qt::Vertical );
96 //ActiveBarGroup->layout()->setSpacing( 0 );
97 //ActiveBarGroup->layout()->setMargin( 0 );
98 QGridLayout* ActiveBarGroupLayout = new QGridLayout( ActiveBarGroup );
99 ActiveBarGroupLayout->setAlignment( Qt::AlignTop );
100 ActiveBarGroupLayout->setSpacing( 6 );
101 ActiveBarGroupLayout->setMargin( 11 );
103 QButtonGroup* BarTypeGroup = new QButtonGroup( ActiveBarGroup );
104 QGroupBox* aGB = new QGroupBox( ActiveBarGroup );
105 QVBoxLayout* aVBLay = new QVBoxLayout( aGB );
107 BarTypeGroup->setExclusive( true );
108 //aGB->setFrameStyle( QFrame::NoFrame );
109 aVBLay->setMargin( 0 );
111 myRBLocal = new QRadioButton( tr( "LOCAL" ), aGB );
112 myRBGlobal = new QRadioButton( tr( "GLOBAL" ), aGB );
113 aVBLay->addWidget( myRBLocal );
114 aVBLay->addWidget( myRBGlobal );
116 BarTypeGroup->addButton( myRBLocal );
117 BarTypeGroup->addButton( myRBGlobal );
119 myCBDisplayed = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup );
121 ActiveBarGroupLayout->addWidget( aGB, 0, 0, 2, 1 );
122 ActiveBarGroupLayout->addWidget( myCBDisplayed, 1, 1 );
124 // Range ============================================================
125 RangeGroup = new QButtonGroup ( this );
126 aGB = new QGroupBox( tr("SCALAR_RANGE_GRP"), this );
127 aMainLayout->addWidget(aGB);
129 QGridLayout* RangeGroupLayout = new QGridLayout( aGB );
130 RangeGroupLayout->setAlignment( Qt::AlignTop );
131 RangeGroupLayout->setSpacing( 6 );
132 RangeGroupLayout->setMargin( 11 );
134 myModeLbl = new QLabel("Scalar Mode", aGB);
136 myModeCombo = new QComboBox(aGB);
138 RBFieldRange = new QRadioButton (tr("FIELD_RANGE_BTN"), aGB);
139 RBImposedRange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), aGB);
140 RBFieldRange->setChecked( true );
141 RangeGroup->addButton( RBFieldRange );
142 RangeGroup->addButton( RBImposedRange );
144 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
145 int aPrecision = qAbs(aResourceMgr->integerValue( "VISU", "visual_data_precision", 0 ));
147 QDoubleValidator* dv = new QDoubleValidator(this);
148 dv->setDecimals(aPrecision);
150 MinEdit = new QLineEdit( aGB );
151 MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
152 MinEdit->setMinimumWidth( 70 );
153 MinEdit->setValidator( dv );
154 MinEdit->setText( "0.0" );
155 QLabel* MinLabel = new QLabel (tr("LBL_MIN"), aGB);
156 MinLabel->setBuddy(MinEdit);
158 MaxEdit = new QLineEdit( aGB );
159 MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
160 MaxEdit->setMinimumWidth( 70 );
161 MaxEdit->setValidator( dv );
162 MaxEdit->setText( "0.0" );
163 QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), aGB);
164 MaxLabel->setBuddy(MaxEdit);
166 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
167 RangeGroupLayout->addWidget( myModeCombo, 0, 1, 1, 3);
168 RangeGroupLayout->addWidget( RBFieldRange, 1, 0, 1, 2);
169 RangeGroupLayout->addWidget( RBImposedRange, 1, 2, 1, 2);
170 RangeGroupLayout->addWidget( MinLabel, 2, 0 );
171 RangeGroupLayout->addWidget( MinEdit, 2, 1 );
172 RangeGroupLayout->addWidget( MaxLabel, 2, 2 );
173 RangeGroupLayout->addWidget( MaxEdit, 2, 3 );
175 // Colors and Labels ========================================================
176 QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this );
177 aMainLayout->addWidget(ColLabGroup);
178 //ColLabGroup->setColumnLayout(0, Qt::Vertical );
179 //ColLabGroup->layout()->setSpacing( 0 );
180 //ColLabGroup->layout()->setMargin( 0 );
181 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup );
182 ColLabGroupLayout->setAlignment( Qt::AlignTop );
183 ColLabGroupLayout->setSpacing( 6 );
184 ColLabGroupLayout->setMargin( 11 );
186 QButtonGroup* TypeGroup = new QButtonGroup( ColLabGroup );
187 aGB = new QGroupBox ( ColLabGroup );
188 aVBLay = new QVBoxLayout( aGB );
189 TypeGroup->setExclusive( true );
190 //aGB->setFrameStyle( QFrame::NoFrame );
191 aVBLay->setMargin( 0 );
193 BicolorButton = new QRadioButton( tr( "BICOLOR" ), aGB );
194 aVBLay->addWidget( BicolorButton );
195 TypeGroup->addButton( BicolorButton );
196 RainbowButton = new QRadioButton( tr( "RAINBOW" ), aGB );
197 aVBLay->addWidget( RainbowButton );
198 TypeGroup->addButton( RainbowButton );
200 ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup );
201 ColorSpin = new SalomeApp_IntSpinBox( ColLabGroup );
202 ColorSpin->setAcceptNames( false );
203 ColorSpin->setMinimum( 2 );
204 ColorSpin->setMaximum( 256 );
205 ColorSpin->setSingleStep( 1 );
206 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
207 ColorSpin->setMinimumWidth( 70 );
208 ColorSpin->setValue( 64 );
210 LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup);
211 LabelSpin = new SalomeApp_IntSpinBox( ColLabGroup );
212 LabelSpin->setAcceptNames( false );
213 LabelSpin->setMinimum( 2 );
214 LabelSpin->setMaximum( 65 );
215 LabelSpin->setSingleStep( 1 );
216 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
217 LabelSpin->setMinimumWidth( 70 );
218 LabelSpin->setValue( 5 );
220 ColLabGroupLayout->addWidget( aGB, 0, 0, 2, 1);
221 ColLabGroupLayout->addWidget( ColorLabel, 1, 1);
222 ColLabGroupLayout->addWidget( ColorSpin, 1, 2);
223 ColLabGroupLayout->addWidget( LabelLabel, 1, 3);
224 ColLabGroupLayout->addWidget( LabelSpin, 1, 4);
226 //TopLayout->addWidget( ColLabGroup );
228 // Orientation ==========================================================
229 QButtonGroup* OrientGroup = new QButtonGroup ( this );
230 aGB = new QGroupBox( tr("ORIENTATION_GRP"), this );
231 aMainLayout->addWidget(aGB);
232 //OrientGroup->setColumnLayout(0, Qt::Vertical );
233 //OrientGroup->layout()->setSpacing( 0 );
234 //OrientGroup->layout()->setMargin( 0 );
235 QGridLayout* OrientGroupLayout = new QGridLayout( aGB );
236 OrientGroupLayout->setAlignment( Qt::AlignTop );
237 OrientGroupLayout->setSpacing( 6 );
238 OrientGroupLayout->setMargin( 11 );
240 RBvert = new QRadioButton (tr("VERTICAL_BTN"), aGB );
241 RBvert->setChecked( true );
242 OrientGroup->addButton( RBvert );
243 RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), aGB);
244 OrientGroup->addButton( RBhori
246 OrientGroupLayout->addWidget( RBvert, 0, 0 );
247 OrientGroupLayout->addWidget( RBhori, 0, 1 );
249 // TopLayout->addWidget( OrientGroup );
251 // Origin ===============================================================
252 QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this );
253 aMainLayout->addWidget( OriginGroup );
254 //OriginGroup->setColumnLayout(0, Qt::Vertical );
255 //OriginGroup->layout()->setSpacing( 0 );
256 //OriginGroup->layout()->setMargin( 0 );
257 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup );
258 OriginGroupLayout->setAlignment( Qt::AlignTop );
259 OriginGroupLayout->setSpacing( 6 );
260 OriginGroupLayout->setMargin( 11 );
262 QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup );
263 XSpin = new SalomeApp_DoubleSpinBox( OriginGroup );
264 VISU::initSpinBox( XSpin, 0.0, 1.0, 0.1, "parametric_precision" );
265 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
266 XSpin->setMinimumWidth( 70 );
267 XSpin->setValue( 0.01 );
269 QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup );
270 YSpin = new SalomeApp_DoubleSpinBox( OriginGroup );
271 VISU::initSpinBox( YSpin, 0.0, 1.0, 0.1, "parametric_precision" );
272 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
273 YSpin->setMinimumWidth( 70 );
274 YSpin->setValue( 0.01 );
276 OriginGroupLayout->addWidget( XLabel, 0, 0);
277 OriginGroupLayout->addWidget( XSpin, 0, 1);
278 OriginGroupLayout->addWidget( YLabel, 0, 2);
279 OriginGroupLayout->addWidget( YSpin, 0, 3);
281 //TopLayout->addWidget( OriginGroup );
283 // Dimensions =========================================================
284 QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this );
285 aMainLayout->addWidget( DimGroup );
286 //DimGroup->setColumnLayout(0, Qt::Vertical );
287 //DimGroup->layout()->setSpacing( 0 );
288 //DimGroup->layout()->setMargin( 0 );
289 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup );
290 DimGroupLayout->setAlignment( Qt::AlignTop );
291 DimGroupLayout->setSpacing( 6 );
292 DimGroupLayout->setMargin( 11 );
294 QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup );
295 WidthSpin = new SalomeApp_DoubleSpinBox( DimGroup );
296 VISU::initSpinBox( WidthSpin, 0.0, 1.0, 0.1, "parametric_precision" );
297 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
298 WidthSpin->setMinimumWidth( 70 );
299 WidthSpin->setValue( 0.1 );
301 QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup );
302 HeightSpin = new SalomeApp_DoubleSpinBox( DimGroup );
303 VISU::initSpinBox( HeightSpin, 0.0, 1.0, 0.1, "parametric_precision" );
304 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
305 HeightSpin->setMinimumWidth( 70 );
306 HeightSpin->setValue( 0.8 );
308 QLabel* SpacingLabel = new QLabel (tr("LBL_SPACING"), DimGroup );
309 SpacingSpin = new SalomeApp_DoubleSpinBox( DimGroup );
310 VISU::initSpinBox( SpacingSpin, 0.0, 1.0, 0.01, "parametric_precision" );
311 SpacingSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
312 SpacingSpin->setMinimumWidth( 70 );
313 SpacingSpin->setValue( 0.01 );
315 DimGroupLayout->addWidget( WidthLabel, 0, 0);
316 DimGroupLayout->addWidget( WidthSpin, 0, 1);
317 DimGroupLayout->addWidget( HeightLabel, 0, 2);
318 DimGroupLayout->addWidget( HeightSpin, 0, 3);
319 DimGroupLayout->addWidget( SpacingLabel, 0, 4);
320 DimGroupLayout->addWidget( SpacingSpin, 0, 5);
322 //TopLayout->addWidget( DimGroup );
324 QWidget* aSaveBox = new QWidget(this);
325 aMainLayout->addWidget( aSaveBox );
327 QHBoxLayout* aHBoxLay = new QHBoxLayout( aSaveBox );
329 myTextBtn = new QPushButton("Text properties...", aSaveBox);
330 aHBoxLay->addWidget( myTextBtn );
332 myBarBtn = new QPushButton("Bar properties...", aSaveBox);
333 aHBoxLay->addWidget( myBarBtn );
335 myTextDlg = new VisuGUI_TextPrefDlg(this);
336 aMainLayout->addWidget( myTextDlg );
337 myTextDlg->setTitleVisible(true);
339 myBarDlg = new VisuGUI_BarPrefDlg(this);
340 aMainLayout->addWidget( myBarDlg );
342 QGroupBox* CheckGroup = new QGroupBox("", this );
343 aMainLayout->addWidget( CheckGroup );
344 QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup );
346 myHideBar = new QCheckBox(tr("HIDE_SCALAR_BAR"), CheckGroup);
347 myHideBar->setChecked(false);
348 CheckGroupLayout->addWidget(myHideBar, 0, 0);
350 // signals and slots connections ===========================================
351 connect( RBFieldRange, SIGNAL( clicked() ), this, SLOT( fieldRangeClicked() ) );
352 connect( RBImposedRange,SIGNAL( clicked() ), this, SLOT( imposedRangeClicked() ) );
354 connect( myModeCombo, SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) );
356 connect( myRBLocal, SIGNAL( clicked() ), this, SLOT( onLocalScalarBar() ) );
357 connect( myRBGlobal, SIGNAL( clicked() ), this, SLOT( onGlobalScalarBar() ) );
359 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorLabel, SLOT( setEnabled( bool ) ) );
360 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorSpin, SLOT( setEnabled( bool ) ) );
361 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelLabel, SLOT( setEnabled( bool ) ) );
362 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelSpin, SLOT( setEnabled( bool ) ) );
363 connect( OrientGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( changeDefaults( int ) ) );
364 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
365 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
366 connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
367 connect( myBarBtn, SIGNAL( clicked() ), this, SLOT( onBarPref() ) );
370 myIsStoreTextProp = false;
373 bool VisuGUI_GaussScalarBarPane::UseFieldRange(bool theInit)
376 return !myPrsCopy->IsRangeFixed();
378 return RBFieldRange->isChecked() || !myPrsCopy->GetIsActiveLocalScalarBar();
382 void VisuGUI_GaussScalarBarPane::onGlobalScalarBar()
384 myPrsCopy->SetIsActiveLocalScalarBar(false);
385 myPrsCopy->SetSourceRange();
387 myCBDisplayed->setEnabled( false );
389 RBImposedRange->setEnabled( false );
390 RBFieldRange->setEnabled( false );
392 MinEdit->setEnabled( false );
393 MaxEdit->setEnabled( false );
395 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
396 int aPrecision = qAbs(aResourceMgr->integerValue("VISU", "visual_data_precision", 0));
398 MinEdit->setText(QString::number(myPrsCopy->GetMin(), 'g', aPrecision));
399 MaxEdit->setText(QString::number(myPrsCopy->GetMax(), 'g', aPrecision));
403 void VisuGUI_GaussScalarBarPane::onLocalScalarBar()
405 myPrsCopy->SetIsActiveLocalScalarBar(true);
406 if ( RBFieldRange->isChecked() )
407 myPrsCopy->SetSourceRange();
409 myPrsCopy->SetRange(myPrsCopy->GetMin(), myPrsCopy->GetMax());
411 myCBDisplayed->setEnabled( true );
413 RBImposedRange->setEnabled( true );
414 RBFieldRange->setEnabled( true );
416 MinEdit->setEnabled( RBImposedRange->isChecked() );
417 MaxEdit->setEnabled( RBImposedRange->isChecked() );
419 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
420 int aPrecision = qAbs(aResourceMgr->integerValue("VISU", "visual_data_precision", 0));
422 MinEdit->setText(QString::number(myPrsCopy->GetMin(), 'g', aPrecision));
423 MaxEdit->setText(QString::number(myPrsCopy->GetMax(), 'g', aPrecision));
428 Called when Range mode is changed to FieldRange
430 void VisuGUI_GaussScalarBarPane::fieldRangeClicked()
432 myPrsCopy->SetSourceRange();
434 RBFieldRange->setChecked( true );
435 RBImposedRange->setChecked( false );
437 MinEdit->setEnabled( false );
438 MaxEdit->setEnabled( false );
440 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
441 int aPrecision = qAbs(aResourceMgr->integerValue("VISU", "visual_data_precision", 0));
443 MinEdit->setText(QString::number(myPrsCopy->GetMin(), 'g', aPrecision));
444 MaxEdit->setText(QString::number(myPrsCopy->GetMax(), 'g', aPrecision));
449 Called when Range mode is changed to FieldRange
451 void VisuGUI_GaussScalarBarPane::imposedRangeClicked()
453 myPrsCopy->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
455 RBImposedRange->setChecked( true );
456 RBFieldRange->setChecked( false );
458 MinEdit->setEnabled( true );
459 MaxEdit->setEnabled( true );
464 Called when scalar mode is changed
466 void VisuGUI_GaussScalarBarPane::changeScalarMode( int theMode )
468 myPrsCopy->SetScalarMode( theMode );
469 if ( UseFieldRange() ) {
470 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
471 int aPrecision = qAbs(aResourceMgr->integerValue("VISU", "visual_data_precision", 0));
473 MinEdit->setText(QString::number(myPrsCopy->GetSourceMin(), 'g', aPrecision));
474 MaxEdit->setText(QString::number(myPrsCopy->GetSourceMax(), 'g', aPrecision));
479 * Initialise dialog box from presentation object
481 void VisuGUI_GaussScalarBarPane::initFromPrsObject(VISU::GaussPoints_i* thePrs,
486 myModeCombo->setCurrentIndex(thePrs->GetScalarMode());
488 bool activeLocal = thePrs->GetIsActiveLocalScalarBar();
490 RBImposedRange->setChecked( !UseFieldRange(theInit) );
491 RBFieldRange->setChecked( UseFieldRange(theInit) );
492 MinEdit->setEnabled( !UseFieldRange(theInit) );
493 MaxEdit->setEnabled( !UseFieldRange(theInit) );
495 RBImposedRange->setEnabled( false );
496 RBFieldRange->setEnabled( false );
497 MinEdit->setEnabled( false );
498 MaxEdit->setEnabled( false );
501 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
502 int aPrecision = qAbs(aResourceMgr->integerValue("VISU", "visual_data_precision", 0));
504 MinEdit->setText(QString::number(thePrs->GetMin(), 'g', aPrecision));
505 MaxEdit->setText(QString::number(thePrs->GetMax(), 'g', aPrecision));
507 setPosAndSize( thePrs->GetPosX(),
511 thePrs->GetBarOrientation());
513 if (RBvert->isChecked()) {
514 myVerTS = thePrs->GetTitleSize();
515 myVerLS = thePrs->GetLabelSize();
516 myVerBW = thePrs->GetBarWidth();
517 myVerBH = thePrs->GetBarHeight();
519 myHorTS = thePrs->GetTitleSize();
520 myHorLS = thePrs->GetLabelSize();
521 myHorBW = thePrs->GetBarWidth();
522 myHorBH = thePrs->GetBarHeight();
525 myBarDlg->setLabelsPrecision( VISU::ToPrecision( thePrs->GetLabelsFormat() ) );
526 myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
528 SpacingSpin->setValue(thePrs->GetSpacing());
530 myRBLocal->setChecked( activeLocal );
532 myRBGlobal->setChecked( !activeLocal );
533 myRBGlobal->setEnabled( thePrs->IsGlobalRangeDefined() );
534 if( !thePrs->IsGlobalRangeDefined() )
535 myRBLocal->setChecked( true );
537 myCBDisplayed->setEnabled( activeLocal );
538 myCBDisplayed->setChecked( thePrs->GetIsDispGlobalScalarBar() );
540 bool bicolor = thePrs->GetSpecificPL()->GetBicolor();
541 BicolorButton->setChecked( bicolor );
542 RainbowButton->setChecked( !bicolor );
543 ColorLabel->setEnabled( !bicolor );
544 ColorSpin->setEnabled( !bicolor );
545 LabelLabel->setEnabled( !bicolor );
546 LabelSpin->setEnabled( !bicolor );
548 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
550 // Update myModeCombo
551 int aNbComp = thePrs->GetField()->myNbComp;
552 bool isScalarMode = (aNbComp > 1);
553 myModeCombo->clear();
554 myModeCombo->addItem("<Modulus>");
555 VISU::PField aField = thePrs->GetField();
556 const VISU::TNames& aCompNames = aField->myCompNames;
557 const VISU::TNames& aUnitNames = aField->myUnitNames;
558 for(int i = 0; i < aNbComp; i++){
559 QString aComponent = QString(aCompNames[i].c_str()).simplified();
560 if(aComponent.isNull() || aComponent == "")
561 aComponent = "Component " + QString::number(i+1);
563 aComponent = "[" + QString::number(i+1) + "] " + aComponent;
565 QString anUnit = QString(aUnitNames[i].c_str()).simplified();
566 if(anUnit.isNull() || anUnit == "")
569 aComponent = aComponent + ", " + anUnit;
571 myModeCombo->addItem(aComponent);
574 myModeCombo->setCurrentIndex(thePrs->GetScalarMode());
576 myModeCombo->setCurrentIndex(1);
579 myModeLbl->setEnabled(isScalarMode);
580 myModeCombo->setEnabled(isScalarMode);
583 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
585 vtkFloatingPointType R, G, B;
586 thePrs->GetTitleColor(R, G, B);
588 int lp = VISU::ToPrecision( thePrs->GetLabelsFormat() );
589 myBarDlg->setLabelsPrecision( lp );
590 myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
592 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
593 thePrs->GetTitFontType(),
594 thePrs->IsBoldTitle(),
595 thePrs->IsItalicTitle(),
596 thePrs->IsShadowTitle());
599 thePrs->GetLabelColor(R, G, B);
601 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
602 thePrs->GetLblFontType(),
603 thePrs->IsBoldLabel(),
604 thePrs->IsItalicLabel(),
605 thePrs->IsShadowLabel());
607 myHideBar->setChecked(!thePrs->IsBarVisible());
611 * Store values to presentation object
613 int VisuGUI_GaussScalarBarPane::storeToPrsObject(VISU::GaussPoints_i* thePrs) {
614 thePrs->SetScalarMode(myModeCombo->currentIndex());
616 if (RBFieldRange->isChecked()) {
617 thePrs->SetSourceRange();
619 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
622 thePrs->SetSpacing(SpacingSpin->value());
623 thePrs->SetIsActiveLocalScalarBar(myRBLocal->isChecked());
624 thePrs->SetIsDispGlobalScalarBar(myCBDisplayed->isChecked());
625 thePrs->SetBiColor(BicolorButton->isChecked());
627 thePrs->SetPosition(XSpin->value(), YSpin->value());
628 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
629 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ColoredPrs3dBase::VERTICAL : VISU::ColoredPrs3dBase::HORIZONTAL);
630 thePrs->SetNbColors(ColorSpin->value());
631 thePrs->SetLabels(LabelSpin->value());
633 if(RBvert->isChecked()) {
634 thePrs->SetRatios(myVerTS, myVerLS, myVerBW, myVerBH);
636 thePrs->SetRatios(myHorTS, myHorLS, myHorBW, myHorBH);
639 std::string f = VISU::ToFormat( myBarDlg->getLabelsPrecision() );
640 thePrs->SetLabelsFormat( f.c_str() );
641 thePrs->SetUnitsVisible(myBarDlg->isUnitsVisible());
643 thePrs->SetBarVisible(!myHideBar->isChecked());
645 if (myIsStoreTextProp) {
647 thePrs->SetTitle(myTextDlg->getTitleText().toLatin1().data());
649 QColor aTitColor (255, 255, 255);
650 int aTitleFontFamily = VTK_ARIAL;
651 bool isTitleBold = false;
652 bool isTitleItalic = false;
653 bool isTitleShadow = false;
655 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
656 isTitleBold, isTitleItalic, isTitleShadow);
658 thePrs->SetBoldTitle(isTitleBold);
659 thePrs->SetItalicTitle(isTitleItalic);
660 thePrs->SetShadowTitle(isTitleShadow);
661 thePrs->SetTitFontType(aTitleFontFamily);
662 thePrs->SetTitleColor(aTitColor.red()/255.,
663 aTitColor.green()/255.,
664 aTitColor.blue()/255.);
667 QColor aLblColor (255, 255, 255);
668 int aLabelFontFamily = VTK_ARIAL;
669 bool isLabelBold = false;
670 bool isLabelItalic = false;
671 bool isLabelShadow = false;
673 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
674 isLabelBold, isLabelItalic, isLabelShadow);
676 thePrs->SetBoldLabel(isLabelBold);
677 thePrs->SetItalicLabel(isLabelItalic);
678 thePrs->SetShadowLabel(isLabelShadow);
679 thePrs->SetLblFontType(aLabelFontFamily);
680 thePrs->SetLabelColor(aLblColor.red()/255.,
681 aLblColor.green()/255.,
682 aLblColor.blue()/255.);
689 Called when orientation is changed
691 void VisuGUI_GaussScalarBarPane::changeDefaults( int )
693 if ( RBvert->isChecked() ) {
694 XSpin->setValue( myVerX );
695 YSpin->setValue( myVerY );
696 WidthSpin->setValue( myVerW );
697 HeightSpin->setValue( myVerH );
700 XSpin->setValue( myHorX );
701 YSpin->setValue( myHorY );
702 WidthSpin->setValue( myHorW );
703 HeightSpin->setValue( myHorH );
708 Called when X,Y position is changed
710 void VisuGUI_GaussScalarBarPane::XYChanged( double )
712 SalomeApp_DoubleSpinBox* snd = (SalomeApp_DoubleSpinBox*)sender();
713 if ( snd == XSpin ) {
714 WidthSpin->setMaximum( 1.0 - XSpin->value() );
716 if ( snd == YSpin ) {
717 HeightSpin->setMaximum( 1.0 - YSpin->value() );
722 Sets size and position
724 void VisuGUI_GaussScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
731 RBvert->setChecked( true );
738 RBhori->setChecked( true );
744 Sets colors and labels number
746 void VisuGUI_GaussScalarBarPane::setScalarBarData( int colors, int labels )
748 ColorSpin->setValue( colors );
749 LabelSpin->setValue( labels );
755 int VisuGUI_GaussScalarBarPane::getOrientation()
757 if (RBvert->isChecked() )
764 Sets and gets parameters
766 double VisuGUI_GaussScalarBarPane::getX() {
767 return XSpin->value();
770 double VisuGUI_GaussScalarBarPane::getY() {
771 return YSpin->value();
774 double VisuGUI_GaussScalarBarPane::getWidth() {
775 return WidthSpin->value();
778 double VisuGUI_GaussScalarBarPane::getHeight() {
779 return HeightSpin->value();
782 int VisuGUI_GaussScalarBarPane::getNbColors() {
783 return ColorSpin->value();
786 int VisuGUI_GaussScalarBarPane::getNbLabels() {
787 return LabelSpin->value();
790 void VisuGUI_GaussScalarBarPane::onTextPref()
792 myIsStoreTextProp = myTextDlg->exec();
795 void VisuGUI_GaussScalarBarPane::onBarPref()
797 if(RBvert->isChecked())
798 myBarDlg->setRatios(myVerTS, myVerLS, myVerBW, myVerBH);
800 myBarDlg->setRatios(myHorTS, myHorLS, myHorBW, myHorBH);
801 if(myBarDlg->exec()) {
802 if(RBvert->isChecked())
803 myBarDlg->getRatios(myVerTS, myVerLS, myVerBW, myVerBH);
805 myBarDlg->getRatios(myHorTS, myHorLS, myHorBW, myHorBH);
812 VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule):
814 VisuGUI_Prs3dDlg(theModule)
816 //setName("VisuGUI_GaussPointsDlg");
817 setWindowTitle(tr("DLG_PROP_TITLE"));
818 setSizeGripEnabled(TRUE);
820 QVBoxLayout* TopLayout = new QVBoxLayout(this);
821 TopLayout->setSpacing(6);
822 TopLayout->setMargin(11);
826 QButtonGroup* PrsGroup = new QButtonGroup( this );
827 QGroupBox* aGB = new QGroupBox( tr( "PRS_TITLE" ), this );
828 QHBoxLayout* aHBLay = new QHBoxLayout( aGB );
829 PrsGroup->setExclusive( true );
830 aHBLay->setMargin( 11 );
831 aHBLay->setSpacing(6);
833 myResultsButton = new QRadioButton( tr( "RESULTS" ), aGB );
834 myGeometryButton = new QRadioButton( tr( "GEOMETRY" ), aGB );
835 myDefShapeButton = new QRadioButton( tr( "DEFORMED_SHAPE" ), aGB );
836 aHBLay->addWidget( myResultsButton );
837 aHBLay->addWidget( myGeometryButton );
838 aHBLay->addWidget( myDefShapeButton );
840 PrsGroup->addButton( myResultsButton );
841 PrsGroup->addButton( myGeometryButton );
842 PrsGroup->addButton( myDefShapeButton );
845 myTabBox = new QTabWidget (this);
848 QWidget* aBox = new QWidget (this);
849 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
850 aVBLay->setMargin(11);
851 aVBLay->setSpacing(6);
854 myPrimitiveBox = new VisuGUI_PrimitiveBox( aBox );
855 aVBLay->addWidget( myPrimitiveBox );
858 mySizeBox = new VisuGUI_SizeBox( aBox );
859 aVBLay->addWidget( mySizeBox );
862 myDefShapeBox = new QGroupBox( tr( "DEFORMED_SHAPE_TITLE" ), aBox );
863 aVBLay->addWidget( myDefShapeBox );
864 //myDefShapeBox->setColumnLayout(0, Qt::Vertical );
865 //myDefShapeBox->layout()->setSpacing( 0 );
866 //myDefShapeBox->layout()->setMargin( 0 );
868 QGridLayout* aDefShapeLayout = new QGridLayout( myDefShapeBox );
869 aDefShapeLayout->setAlignment(Qt::AlignTop);
870 aDefShapeLayout->setSpacing(6);
871 aDefShapeLayout->setMargin(11);
873 QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox );
874 myScaleSpinBox = new SalomeApp_DoubleSpinBox( myDefShapeBox );
875 VISU::initSpinBox( myScaleSpinBox, 0.0, 10.0, 0.1, "visual_data_precision" );
877 aDefShapeLayout->addWidget( aScaleLabel, 0, 0 );
878 aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 );
881 myScalarPane = new VisuGUI_GaussScalarBarPane(this);
882 if ( myScalarPane->layout() )
883 myScalarPane->layout()->setMargin(5);
886 myInputPane = new VisuGUI_InputPane(VISU::TGAUSSPOINTS, theModule, this);
887 myInputPane->SetRestoreInitialSelection(false);
889 connect( myResultsButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleResults() ) );
890 connect( myResultsButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
891 connect( myGeometryButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleGeometry() ) );
892 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), this, SLOT( onToggleDefShape( bool ) ) );
893 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
895 myTabBox->addTab(aBox, tr("GAUSS_POINTS_TAB"));
896 myTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
897 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
899 // Common buttons ===========================================================
900 QGroupBox* GroupButtons = new QGroupBox( this );
901 //GroupButtons->setColumnLayout(0, Qt::Vertical );
902 //GroupButtons->layout()->setSpacing( 0 );
903 //GroupButtons->layout()->setMargin( 0 );
904 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
905 GroupButtonsLayout->setAlignment( Qt::AlignTop );
906 GroupButtonsLayout->setSpacing( 6 );
907 GroupButtonsLayout->setMargin( 11 );
909 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
910 buttonOk->setAutoDefault( TRUE );
911 buttonOk->setDefault( TRUE );
912 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
913 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
915 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons );
916 buttonCancel->setAutoDefault( TRUE );
917 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
919 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons );
920 buttonHelp->setAutoDefault( TRUE );
921 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
923 TopLayout->addWidget( aGB );
924 TopLayout->addWidget( myTabBox );
925 TopLayout->addWidget( GroupButtons );
927 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
928 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
929 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
932 VisuGUI_GaussPointsDlg::~VisuGUI_GaussPointsDlg()
935 void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
939 myPrsCopy = VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
941 myScalarPane->initFromPrsObject( myPrsCopy, theInit );
943 bool isDeformed = myPrsCopy->GetIsDeformed();
944 myScaleSpinBox->setValue( myPrsCopy->GetScaleFactor() );
945 myDefShapeButton->setChecked( isDeformed );
946 myDefShapeButton->setEnabled( myPrsCopy->GetField()->myNbComp > 1 );
947 onToggleDefShape( isDeformed );
949 bool isResults = myPrsCopy->GetIsColored();
950 myResultsButton->setChecked( isResults && !isDeformed );
951 myGeometryButton->setChecked( !isResults && !isDeformed );
953 myPrimitiveBox->setPrimitiveType( myPrsCopy->GetPrimitiveType() );
954 myPrimitiveBox->setClampMaximum( myPrsCopy->GetMaximumSupportedSize() );
955 myPrimitiveBox->setClamp( myPrsCopy->GetClamp() );
956 myPrimitiveBox->setMainTexture( myPrsCopy->GetQMainTexture() );
957 myPrimitiveBox->setAlphaTexture( myPrsCopy->GetQAlphaTexture() );
958 myPrimitiveBox->setAlphaThreshold( myPrsCopy->GetAlphaThreshold() );
959 myPrimitiveBox->setResolution( myPrsCopy->GetResolution() );
960 myPrimitiveBox->setFaceLimit( myPrsCopy->GetFaceLimit() );
962 mySizeBox->setType( isResults || isDeformed ? VisuGUI_SizeBox::Results : VisuGUI_SizeBox::Geometry );
963 mySizeBox->setGeomSize( myPrsCopy->GetGeomSize() );
964 mySizeBox->setMinSize( myPrsCopy->GetMinSize() );
965 mySizeBox->setMaxSize( myPrsCopy->GetMaxSize() );
966 mySizeBox->setMagnification( myPrsCopy->GetMagnification() );
967 mySizeBox->setIncrement( myPrsCopy->GetMagnificationIncrement() );
968 mySizeBox->setColor( myPrsCopy->GetQColor() );
970 //Disable Size controls if there are no OpenGL extensions
971 char* ext = (char*)glGetString( GL_EXTENSIONS );
972 if( strstr( ext, "GL_ARB_point_sprite" ) == NULL ||
973 strstr( ext, "GL_ARB_shader_objects" ) == NULL ||
974 strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL )
975 mySizeBox->enableSizeControls(false);
980 myInputPane->initFromPrsObject( myPrsCopy );
981 myTabBox->setCurrentIndex( 0 );
984 int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
986 if(!myInputPane->check())
989 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
990 anIsOk &= myScalarPane->storeToPrsObject( myPrsCopy );
992 myPrsCopy->SetIsDeformed( myDefShapeButton->isChecked() );
993 myPrsCopy->SetScaleFactor( myScaleSpinBox->value() );
995 int aPrimitiveType = myPrimitiveBox->getPrimitiveType();
996 myPrsCopy->SetPrimitiveType( VISU::GaussPoints::PrimitiveType( aPrimitiveType ) );
998 myPrsCopy->SetClamp( myPrimitiveBox->getClamp() );
1000 QString aMainTexture = myPrimitiveBox->getMainTexture();
1001 QString anAlphaTexture = myPrimitiveBox->getAlphaTexture();
1003 aMainTexture = aMainTexture.isNull() ? myPrsCopy->GetQMainTexture() : aMainTexture;
1004 anAlphaTexture = anAlphaTexture.isNull() ? myPrsCopy->GetQAlphaTexture() : anAlphaTexture;
1006 myPrsCopy->SetTextures( aMainTexture.toLatin1().data(), anAlphaTexture.toLatin1().data() );
1008 myPrsCopy->SetAlphaThreshold( myPrimitiveBox->getAlphaThreshold() );
1010 myPrsCopy->SetResolution( myPrimitiveBox->getResolution() );
1011 myPrsCopy->SetFaceLimit( myPrimitiveBox->getFaceLimit() );
1013 bool isColored = !myGeometryButton->isChecked();
1016 myPrsCopy->SetIsColored( true );
1017 myPrsCopy->SetMinSize( mySizeBox->getMinSize() );
1018 myPrsCopy->SetMaxSize( mySizeBox->getMaxSize() );
1022 myPrsCopy->SetIsColored( false );
1023 myPrsCopy->SetQColor( mySizeBox->getColor() );
1024 myPrsCopy->SetGeomSize( mySizeBox->getGeomSize() );
1027 myPrsCopy->SetMagnification( mySizeBox->getMagnification() );
1028 myPrsCopy->SetMagnificationIncrement( mySizeBox->getIncrement() );
1030 VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Copy(myPrsCopy, thePrs);
1032 //Set created Gauss points presentation selected,
1033 //Issue 0019874(EDF 746 VISU: Picking alphanumeric Gauss)
1035 SALOME_ListIO aListIO;
1036 //LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
1037 Handle(SALOME_InteractiveObject) anIO = thePrs->GetIO();
1038 if(anIO && anIO->hasEntry()) {
1039 aListIO.Append(anIO);
1040 VISU::UpdateObjBrowser(myModule,true);
1041 //IPAL20836 aSelectionMgr->setSelectedObjects(aListIO);
1044 myInputPane->SetRestoreInitialSelection(true);
1049 void VisuGUI_GaussPointsDlg::onToggleDefShape( bool on )
1051 if( on )//myDefShapeButton->isChecked() )
1053 myDefShapeBox->show();
1054 mySizeBox->setType( VisuGUI_SizeBox::Results );
1057 myDefShapeBox->hide();
1060 void VisuGUI_GaussPointsDlg::accept()
1062 if( (bool)myPrsCopy && myPrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere )
1064 int aNumberOfFaces = myPrimitiveBox->getFaceNumber();
1065 int aNumberOfPoints = myPrsCopy->GetSpecificPL()->GetInput()->GetNumberOfCells();
1067 if( aNumberOfFaces * aNumberOfPoints > myPrimitiveBox->getFaceLimit() )
1069 QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
1070 aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
1071 aWarning.append( "Can you please confirm that you want to continue anyway?" );
1072 if( SUIT_MessageBox::warning( this, tr( "Warning" ), aWarning, tr( "&OK" ), tr( "&Cancel" ) ) == 1 )
1077 float aMemory = 50.0 * 1024.0 * (float)aNumberOfFaces * (float)aNumberOfPoints;
1079 cout << aNumberOfFaces << endl;
1080 cout << aNumberOfPoints << endl;
1081 cout << aMemory << endl;
1083 vtkSphereSource* aSphere = vtkSphereSource::New();
1084 aSphere->SetThetaResolution( myPrimitiveBox->getResolution() );
1085 aSphere->SetPhiResolution( myPrimitiveBox->getResolution() );
1086 aSphere->GetOutput()->Update();
1087 aSphere->GetOutput()->GetActualMemorySize();
1089 aMemory = aSphere->GetOutput()->GetActualMemorySize() * 1024.0 * (float)aNumberOfPoints;
1091 if( VISU_PipeLine::CheckAvailableMemory( aMemory ) == 0 )
1093 SUIT_MessageBox::error1( this, "caption", "text", "ok" );
1099 //if( myScalarPane->check() )
1100 VisuGUI_Prs3dDlg::accept();
1103 QString VisuGUI_GaussPointsDlg::GetContextHelpFilePath()
1105 return "types_of_gauss_points_presentations_page.html";