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_GaussPointsDlg.cxx
24 // Author : Oleg UVAROV
27 #include "VisuGUI_GaussPointsDlg.h"
29 #include "VISUConfig.hh"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_InputPane.h"
34 #include "VISU_ColoredPrs3dFactory.hh"
35 #include "VISU_GaussPoints_i.hh"
36 #include "VISU_Prs3dUtils.hh"
37 #include "VISU_GaussPointsPL.hxx"
38 #include "VISU_OpenGLPointSpriteMapper.hxx"
39 #include "VISU_Convertor.hxx"
41 #include "VVTK_PrimitiveBox.h"
42 #include "VVTK_SizeBox.h"
44 #include "LightApp_Application.h"
45 #include "SalomeApp_Module.h"
46 #include "LightApp_SelectionMgr.h"
47 #include "SUIT_Desktop.h"
48 #include "SUIT_ResourceMgr.h"
49 #include "SUIT_Session.h"
50 #include "SUIT_MessageBox.h"
51 #include "SVTK_FontWidget.h"
53 #include "QtxDoubleSpinBox.h"
57 #include <QButtonGroup>
58 #include <QRadioButton>
59 #include <QFileDialog>
61 #include <QColorDialog>
65 #include <QPushButton>
69 #include <QToolButton>
73 #include <vtkPolyData.h>
74 #include <vtkDataSet.h>
75 #include <vtkSphereSource.h>
79 VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent):
82 myVerX = 0.01; myVerY = 0.10; myVerW = 0.08; myVerH = 0.80;
83 myHorX = 0.10; myHorY = 0.01; myHorW = 0.80; myHorH = 0.08;
84 myVerTS = myVerLS = myVerBW = myVerBH = 0;
85 myHorTS = myHorLS = myHorBW = myHorBH = 0;
86 Imin = 0.0; Imax = 0.0;
89 QVBoxLayout* aMainLayout = new QVBoxLayout( this );
90 aMainLayout->setSpacing(6);
93 // Active bar ========================================================
94 QGroupBox* ActiveBarGroup = new QGroupBox (tr("ACTIVE_BAR_GRP"), this );
95 aMainLayout->addWidget(ActiveBarGroup);
96 //ActiveBarGroup->setColumnLayout(0, Qt::Vertical );
97 //ActiveBarGroup->layout()->setSpacing( 0 );
98 //ActiveBarGroup->layout()->setMargin( 0 );
99 QGridLayout* ActiveBarGroupLayout = new QGridLayout( ActiveBarGroup );
100 ActiveBarGroupLayout->setAlignment( Qt::AlignTop );
101 ActiveBarGroupLayout->setSpacing( 6 );
102 ActiveBarGroupLayout->setMargin( 11 );
104 QButtonGroup* BarTypeGroup = new QButtonGroup( ActiveBarGroup );
105 QGroupBox* aGB = new QGroupBox( ActiveBarGroup );
106 QVBoxLayout* aVBLay = new QVBoxLayout( aGB );
108 BarTypeGroup->setExclusive( true );
109 //aGB->setFrameStyle( QFrame::NoFrame );
110 aVBLay->setMargin( 0 );
112 myRBLocal = new QRadioButton( tr( "LOCAL" ), aGB );
113 myRBGlobal = new QRadioButton( tr( "GLOBAL" ), aGB );
114 aVBLay->addWidget( myRBLocal );
115 aVBLay->addWidget( myRBGlobal );
117 BarTypeGroup->addButton( myRBLocal );
118 BarTypeGroup->addButton( myRBGlobal );
120 myCBDisplayed = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup );
122 ActiveBarGroupLayout->addWidget( aGB, 0, 0, 2, 1 );
123 ActiveBarGroupLayout->addWidget( myCBDisplayed, 1, 1 );
125 // Range ============================================================
126 RangeGroup = new QButtonGroup ( this );
127 aGB = new QGroupBox( tr("SCALAR_RANGE_GRP"), this );
128 aMainLayout->addWidget(aGB);
130 QGridLayout* RangeGroupLayout = new QGridLayout( aGB );
131 RangeGroupLayout->setAlignment( Qt::AlignTop );
132 RangeGroupLayout->setSpacing( 6 );
133 RangeGroupLayout->setMargin( 11 );
135 myModeLbl = new QLabel("Scalar Mode", aGB);
137 myModeCombo = new QComboBox(aGB);
139 RBFieldRange = new QRadioButton (tr("FIELD_RANGE_BTN"), aGB);
140 RBImposedRange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), aGB);
141 RBFieldRange->setChecked( true );
142 RangeGroup->addButton( RBFieldRange );
143 RangeGroup->addButton( RBImposedRange );
145 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
146 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
148 QDoubleValidator* dv = new QDoubleValidator(this);
149 dv->setDecimals(aPrecision);
151 MinEdit = new QLineEdit( aGB );
152 MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
153 MinEdit->setMinimumWidth( 70 );
154 MinEdit->setValidator( dv );
155 MinEdit->setText( "0.0" );
156 QLabel* MinLabel = new QLabel (tr("LBL_MIN"), aGB);
157 MinLabel->setBuddy(MinEdit);
159 MaxEdit = new QLineEdit( aGB );
160 MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
161 MaxEdit->setMinimumWidth( 70 );
162 MaxEdit->setValidator( dv );
163 MaxEdit->setText( "0.0" );
164 QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), aGB);
165 MaxLabel->setBuddy(MaxEdit);
167 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
168 RangeGroupLayout->addWidget( myModeCombo, 0, 1, 1, 3);
169 RangeGroupLayout->addWidget( RBFieldRange, 1, 0, 1, 2);
170 RangeGroupLayout->addWidget( RBImposedRange, 1, 2, 1, 2);
171 RangeGroupLayout->addWidget( MinLabel, 2, 0 );
172 RangeGroupLayout->addWidget( MinEdit, 2, 1 );
173 RangeGroupLayout->addWidget( MaxLabel, 2, 2 );
174 RangeGroupLayout->addWidget( MaxEdit, 2, 3 );
176 // Colors and Labels ========================================================
177 QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this );
178 aMainLayout->addWidget(ColLabGroup);
179 //ColLabGroup->setColumnLayout(0, Qt::Vertical );
180 //ColLabGroup->layout()->setSpacing( 0 );
181 //ColLabGroup->layout()->setMargin( 0 );
182 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup );
183 ColLabGroupLayout->setAlignment( Qt::AlignTop );
184 ColLabGroupLayout->setSpacing( 6 );
185 ColLabGroupLayout->setMargin( 11 );
187 QButtonGroup* TypeGroup = new QButtonGroup( ColLabGroup );
188 aGB = new QGroupBox ( ColLabGroup );
189 aVBLay = new QVBoxLayout( aGB );
190 TypeGroup->setExclusive( true );
191 //aGB->setFrameStyle( QFrame::NoFrame );
192 aVBLay->setMargin( 0 );
194 BicolorButton = new QRadioButton( tr( "BICOLOR" ), aGB );
195 aVBLay->addWidget( BicolorButton );
196 TypeGroup->addButton( BicolorButton );
197 RainbowButton = new QRadioButton( tr( "RAINBOW" ), aGB );
198 aVBLay->addWidget( RainbowButton );
199 TypeGroup->addButton( RainbowButton );
201 ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup );
202 ColorSpin = new QSpinBox( ColLabGroup );
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 QSpinBox( ColLabGroup );
212 LabelSpin->setMinimum( 2 );
213 LabelSpin->setMaximum( 65 );
214 LabelSpin->setSingleStep( 1 );
215 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
216 LabelSpin->setMinimumWidth( 70 );
217 LabelSpin->setValue( 5 );
219 ColLabGroupLayout->addWidget( aGB, 0, 0, 2, 1);
220 ColLabGroupLayout->addWidget( ColorLabel, 1, 1);
221 ColLabGroupLayout->addWidget( ColorSpin, 1, 2);
222 ColLabGroupLayout->addWidget( LabelLabel, 1, 3);
223 ColLabGroupLayout->addWidget( LabelSpin, 1, 4);
225 //TopLayout->addWidget( ColLabGroup );
227 // Orientation ==========================================================
228 QButtonGroup* OrientGroup = new QButtonGroup ( this );
229 aGB = new QGroupBox( tr("ORIENTATION_GRP"), this );
230 aMainLayout->addWidget(aGB);
231 //OrientGroup->setColumnLayout(0, Qt::Vertical );
232 //OrientGroup->layout()->setSpacing( 0 );
233 //OrientGroup->layout()->setMargin( 0 );
234 QGridLayout* OrientGroupLayout = new QGridLayout( aGB );
235 OrientGroupLayout->setAlignment( Qt::AlignTop );
236 OrientGroupLayout->setSpacing( 6 );
237 OrientGroupLayout->setMargin( 11 );
239 RBvert = new QRadioButton (tr("VERTICAL_BTN"), aGB );
240 RBvert->setChecked( true );
241 OrientGroup->addButton( RBvert );
242 RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), aGB);
243 OrientGroup->addButton( RBhori
245 OrientGroupLayout->addWidget( RBvert, 0, 0 );
246 OrientGroupLayout->addWidget( RBhori, 0, 1 );
248 // TopLayout->addWidget( OrientGroup );
250 // Origin ===============================================================
251 QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this );
252 aMainLayout->addWidget( OriginGroup );
253 //OriginGroup->setColumnLayout(0, Qt::Vertical );
254 //OriginGroup->layout()->setSpacing( 0 );
255 //OriginGroup->layout()->setMargin( 0 );
256 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup );
257 OriginGroupLayout->setAlignment( Qt::AlignTop );
258 OriginGroupLayout->setSpacing( 6 );
259 OriginGroupLayout->setMargin( 11 );
261 QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup );
262 XSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, OriginGroup );
263 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
264 XSpin->setMinimumWidth( 70 );
265 XSpin->setValue( 0.01 );
267 QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup );
268 YSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, OriginGroup );
269 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
270 YSpin->setMinimumWidth( 70 );
271 YSpin->setValue( 0.01 );
273 OriginGroupLayout->addWidget( XLabel, 0, 0);
274 OriginGroupLayout->addWidget( XSpin, 0, 1);
275 OriginGroupLayout->addWidget( YLabel, 0, 2);
276 OriginGroupLayout->addWidget( YSpin, 0, 3);
278 //TopLayout->addWidget( OriginGroup );
280 // Dimensions =========================================================
281 QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this );
282 aMainLayout->addWidget( DimGroup );
283 //DimGroup->setColumnLayout(0, Qt::Vertical );
284 //DimGroup->layout()->setSpacing( 0 );
285 //DimGroup->layout()->setMargin( 0 );
286 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup );
287 DimGroupLayout->setAlignment( Qt::AlignTop );
288 DimGroupLayout->setSpacing( 6 );
289 DimGroupLayout->setMargin( 11 );
291 QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup );
292 WidthSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, DimGroup );
293 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
294 WidthSpin->setMinimumWidth( 70 );
295 WidthSpin->setValue( 0.1 );
297 QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup );
298 HeightSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, DimGroup );
299 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
300 HeightSpin->setMinimumWidth( 70 );
301 HeightSpin->setValue( 0.8 );
303 QLabel* SpacingLabel = new QLabel (tr("LBL_SPACING"), DimGroup );
304 SpacingSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.01, DimGroup );
305 SpacingSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
306 SpacingSpin->setMinimumWidth( 70 );
307 SpacingSpin->setValue( 0.01 );
309 DimGroupLayout->addWidget( WidthLabel, 0, 0);
310 DimGroupLayout->addWidget( WidthSpin, 0, 1);
311 DimGroupLayout->addWidget( HeightLabel, 0, 2);
312 DimGroupLayout->addWidget( HeightSpin, 0, 3);
313 DimGroupLayout->addWidget( SpacingLabel, 0, 4);
314 DimGroupLayout->addWidget( SpacingSpin, 0, 5);
316 //TopLayout->addWidget( DimGroup );
318 QWidget* aSaveBox = new QWidget(this);
319 aMainLayout->addWidget( aSaveBox );
321 QHBoxLayout* aHBoxLay = new QHBoxLayout( aSaveBox );
323 myTextBtn = new QPushButton("Text properties...", aSaveBox);
324 aHBoxLay->addWidget( myTextBtn );
326 myBarBtn = new QPushButton("Bar properties...", aSaveBox);
327 aHBoxLay->addWidget( myBarBtn );
329 myTextDlg = new VisuGUI_TextPrefDlg(this);
330 aMainLayout->addWidget( myTextDlg );
331 myTextDlg->setTitleVisible(true);
333 myBarDlg = new VisuGUI_BarPrefDlg(this);
334 aMainLayout->addWidget( myBarDlg );
336 QGroupBox* CheckGroup = new QGroupBox("", this );
337 aMainLayout->addWidget( CheckGroup );
338 QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup );
340 myHideBar = new QCheckBox(tr("HIDE_SCALAR_BAR"), CheckGroup);
341 myHideBar->setChecked(false);
342 CheckGroupLayout->addWidget(myHideBar, 0, 0);
344 // signals and slots connections ===========================================
345 connect( RBFieldRange, SIGNAL( clicked() ), this, SLOT( fieldRangeClicked() ) );
346 connect( RBImposedRange,SIGNAL( clicked() ), this, SLOT( imposedRangeClicked() ) );
348 connect( myModeCombo, SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) );
350 connect( myRBLocal, SIGNAL( clicked() ), this, SLOT( onLocalScalarBar() ) );
351 connect( myRBGlobal, SIGNAL( clicked() ), this, SLOT( onGlobalScalarBar() ) );
353 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorLabel, SLOT( setEnabled( bool ) ) );
354 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorSpin, SLOT( setEnabled( bool ) ) );
355 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelLabel, SLOT( setEnabled( bool ) ) );
356 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelSpin, SLOT( setEnabled( bool ) ) );
357 connect( OrientGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( changeDefaults( int ) ) );
358 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
359 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
360 connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
361 connect( myBarBtn, SIGNAL( clicked() ), this, SLOT( onBarPref() ) );
364 myIsStoreTextProp = false;
367 bool VisuGUI_GaussScalarBarPane::UseFieldRange(bool theInit)
370 return !myPrsCopy->IsRangeFixed();
372 return RBFieldRange->isChecked() || !myPrsCopy->GetIsActiveLocalScalarBar();
376 void VisuGUI_GaussScalarBarPane::onGlobalScalarBar()
378 myPrsCopy->SetIsActiveLocalScalarBar(false);
379 myPrsCopy->SetSourceRange();
381 myCBDisplayed->setEnabled( false );
383 RBImposedRange->setEnabled( false );
384 RBFieldRange->setEnabled( false );
386 MinEdit->setEnabled( false );
387 MaxEdit->setEnabled( false );
389 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
390 int aPrecision = aResourceMgr->integerValue("VISU", "floating_point_precision", 0);
392 MinEdit->setText(QString::number(myPrsCopy->GetMin(), 'g', aPrecision));
393 MaxEdit->setText(QString::number(myPrsCopy->GetMax(), 'g', aPrecision));
397 void VisuGUI_GaussScalarBarPane::onLocalScalarBar()
399 myPrsCopy->SetIsActiveLocalScalarBar(true);
400 if ( RBFieldRange->isChecked() )
401 myPrsCopy->SetSourceRange();
403 myPrsCopy->SetRange(myPrsCopy->GetMin(), myPrsCopy->GetMax());
405 myCBDisplayed->setEnabled( true );
407 RBImposedRange->setEnabled( true );
408 RBFieldRange->setEnabled( true );
410 MinEdit->setEnabled( RBImposedRange->isChecked() );
411 MaxEdit->setEnabled( RBImposedRange->isChecked() );
413 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
414 int aPrecision = aResourceMgr->integerValue("VISU", "floating_point_precision", 0);
416 MinEdit->setText(QString::number(myPrsCopy->GetMin(), 'g', aPrecision));
417 MaxEdit->setText(QString::number(myPrsCopy->GetMax(), 'g', aPrecision));
422 Called when Range mode is changed to FieldRange
424 void VisuGUI_GaussScalarBarPane::fieldRangeClicked()
426 myPrsCopy->SetSourceRange();
428 RBFieldRange->setChecked( true );
429 RBImposedRange->setChecked( false );
431 MinEdit->setEnabled( false );
432 MaxEdit->setEnabled( false );
434 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
435 int aPrecision = aResourceMgr->integerValue("VISU", "floating_point_precision", 0);
437 MinEdit->setText(QString::number(myPrsCopy->GetMin(), 'g', aPrecision));
438 MaxEdit->setText(QString::number(myPrsCopy->GetMax(), 'g', aPrecision));
443 Called when Range mode is changed to FieldRange
445 void VisuGUI_GaussScalarBarPane::imposedRangeClicked()
447 myPrsCopy->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
449 RBImposedRange->setChecked( true );
450 RBFieldRange->setChecked( false );
452 MinEdit->setEnabled( true );
453 MaxEdit->setEnabled( true );
458 Called when scalar mode is changed
460 void VisuGUI_GaussScalarBarPane::changeScalarMode( int theMode )
462 myPrsCopy->SetScalarMode( theMode );
463 if ( UseFieldRange() ) {
464 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
465 int aPrecision = aResourceMgr->integerValue("VISU", "floating_point_precision", 0);
467 MinEdit->setText(QString::number(myPrsCopy->GetSourceMin(), 'g', aPrecision));
468 MaxEdit->setText(QString::number(myPrsCopy->GetSourceMax(), 'g', aPrecision));
473 * Initialise dialog box from presentation object
475 void VisuGUI_GaussScalarBarPane::initFromPrsObject(VISU::GaussPoints_i* thePrs,
480 myModeCombo->setCurrentIndex(thePrs->GetScalarMode());
482 bool activeLocal = thePrs->GetIsActiveLocalScalarBar();
484 RBImposedRange->setChecked( !UseFieldRange(theInit) );
485 RBFieldRange->setChecked( UseFieldRange(theInit) );
486 MinEdit->setEnabled( !UseFieldRange(theInit) );
487 MaxEdit->setEnabled( !UseFieldRange(theInit) );
489 RBImposedRange->setEnabled( false );
490 RBFieldRange->setEnabled( false );
491 MinEdit->setEnabled( false );
492 MaxEdit->setEnabled( false );
495 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
496 int aPrecision = aResourceMgr->integerValue("VISU", "floating_point_precision", 0);
498 MinEdit->setText(QString::number(thePrs->GetMin(), 'g', aPrecision));
499 MaxEdit->setText(QString::number(thePrs->GetMax(), 'g', aPrecision));
501 setPosAndSize( thePrs->GetPosX(),
505 thePrs->GetBarOrientation());
507 if (RBvert->isChecked()) {
508 myVerTS = thePrs->GetTitleSize();
509 myVerLS = thePrs->GetLabelSize();
510 myVerBW = thePrs->GetBarWidth();
511 myVerBH = thePrs->GetBarHeight();
513 myHorTS = thePrs->GetTitleSize();
514 myHorLS = thePrs->GetLabelSize();
515 myHorBW = thePrs->GetBarWidth();
516 myHorBH = thePrs->GetBarHeight();
519 myBarDlg->setLabelsPrecision( VISU::ToPrecision( thePrs->GetLabelsFormat() ) );
520 myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
522 SpacingSpin->setValue(thePrs->GetSpacing());
524 myRBLocal->setChecked( activeLocal );
526 myRBGlobal->setChecked( !activeLocal );
527 myRBGlobal->setEnabled( thePrs->IsGlobalRangeDefined() );
528 if( !thePrs->IsGlobalRangeDefined() )
529 myRBLocal->setChecked( true );
531 myCBDisplayed->setEnabled( activeLocal );
532 myCBDisplayed->setChecked( thePrs->GetIsDispGlobalScalarBar() );
534 bool bicolor = thePrs->GetSpecificPL()->GetBicolor();
535 BicolorButton->setChecked( bicolor );
536 RainbowButton->setChecked( !bicolor );
537 ColorLabel->setEnabled( !bicolor );
538 ColorSpin->setEnabled( !bicolor );
539 LabelLabel->setEnabled( !bicolor );
540 LabelSpin->setEnabled( !bicolor );
542 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
544 // Update myModeCombo
545 int aNbComp = thePrs->GetField()->myNbComp;
546 bool isScalarMode = (aNbComp > 1);
547 myModeCombo->clear();
548 myModeCombo->addItem("<Modulus>");
549 VISU::PField aField = thePrs->GetField();
550 const VISU::TNames& aCompNames = aField->myCompNames;
551 const VISU::TNames& aUnitNames = aField->myUnitNames;
552 for(int i = 0; i < aNbComp; i++){
553 QString aComponent = QString(aCompNames[i].c_str()).simplified();
554 if(aComponent.isNull() || aComponent == "")
555 aComponent = "Component " + QString::number(i+1);
557 aComponent = "[" + QString::number(i+1) + "] " + aComponent;
559 QString anUnit = QString(aUnitNames[i].c_str()).simplified();
560 if(anUnit.isNull() || anUnit == "")
563 aComponent = aComponent + ", " + anUnit;
565 myModeCombo->addItem(aComponent);
568 myModeCombo->setCurrentIndex(thePrs->GetScalarMode());
570 myModeCombo->setCurrentIndex(1);
573 myModeLbl->setEnabled(isScalarMode);
574 myModeCombo->setEnabled(isScalarMode);
577 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
579 vtkFloatingPointType R, G, B;
580 thePrs->GetTitleColor(R, G, B);
582 int lp = VISU::ToPrecision( thePrs->GetLabelsFormat() );
583 myBarDlg->setLabelsPrecision( lp );
584 myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
586 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
587 thePrs->GetTitFontType(),
588 thePrs->IsBoldTitle(),
589 thePrs->IsItalicTitle(),
590 thePrs->IsShadowTitle());
593 thePrs->GetLabelColor(R, G, B);
595 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
596 thePrs->GetLblFontType(),
597 thePrs->IsBoldLabel(),
598 thePrs->IsItalicLabel(),
599 thePrs->IsShadowLabel());
601 myHideBar->setChecked(!thePrs->IsBarVisible());
605 * Store values to presentation object
607 int VisuGUI_GaussScalarBarPane::storeToPrsObject(VISU::GaussPoints_i* thePrs) {
608 thePrs->SetScalarMode(myModeCombo->currentIndex());
610 if (RBFieldRange->isChecked()) {
611 thePrs->SetSourceRange();
613 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
616 thePrs->SetSpacing(SpacingSpin->value());
617 thePrs->SetIsActiveLocalScalarBar(myRBLocal->isChecked());
618 thePrs->SetIsDispGlobalScalarBar(myCBDisplayed->isChecked());
619 thePrs->SetBiColor(BicolorButton->isChecked());
621 thePrs->SetPosition(XSpin->value(), YSpin->value());
622 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
623 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ColoredPrs3dBase::VERTICAL : VISU::ColoredPrs3dBase::HORIZONTAL);
624 thePrs->SetNbColors(ColorSpin->value());
625 thePrs->SetLabels(LabelSpin->value());
627 if(RBvert->isChecked()) {
628 thePrs->SetRatios(myVerTS, myVerLS, myVerBW, myVerBH);
630 thePrs->SetRatios(myHorTS, myHorLS, myHorBW, myHorBH);
633 std::string f = VISU::ToFormat( myBarDlg->getLabelsPrecision() );
634 thePrs->SetLabelsFormat( f.c_str() );
635 thePrs->SetUnitsVisible(myBarDlg->isUnitsVisible());
637 thePrs->SetBarVisible(!myHideBar->isChecked());
639 if (myIsStoreTextProp) {
641 thePrs->SetTitle(myTextDlg->getTitleText().toLatin1().data());
643 QColor aTitColor (255, 255, 255);
644 int aTitleFontFamily = VTK_ARIAL;
645 bool isTitleBold = false;
646 bool isTitleItalic = false;
647 bool isTitleShadow = false;
649 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
650 isTitleBold, isTitleItalic, isTitleShadow);
652 thePrs->SetBoldTitle(isTitleBold);
653 thePrs->SetItalicTitle(isTitleItalic);
654 thePrs->SetShadowTitle(isTitleShadow);
655 thePrs->SetTitFontType(aTitleFontFamily);
656 thePrs->SetTitleColor(aTitColor.red()/255.,
657 aTitColor.green()/255.,
658 aTitColor.blue()/255.);
661 QColor aLblColor (255, 255, 255);
662 int aLabelFontFamily = VTK_ARIAL;
663 bool isLabelBold = false;
664 bool isLabelItalic = false;
665 bool isLabelShadow = false;
667 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
668 isLabelBold, isLabelItalic, isLabelShadow);
670 thePrs->SetBoldLabel(isLabelBold);
671 thePrs->SetItalicLabel(isLabelItalic);
672 thePrs->SetShadowLabel(isLabelShadow);
673 thePrs->SetLblFontType(aLabelFontFamily);
674 thePrs->SetLabelColor(aLblColor.red()/255.,
675 aLblColor.green()/255.,
676 aLblColor.blue()/255.);
683 Called when orientation is changed
685 void VisuGUI_GaussScalarBarPane::changeDefaults( int )
687 if ( RBvert->isChecked() ) {
688 XSpin->setValue( myVerX );
689 YSpin->setValue( myVerY );
690 WidthSpin->setValue( myVerW );
691 HeightSpin->setValue( myVerH );
694 XSpin->setValue( myHorX );
695 YSpin->setValue( myHorY );
696 WidthSpin->setValue( myHorW );
697 HeightSpin->setValue( myHorH );
702 Called when X,Y position is changed
704 void VisuGUI_GaussScalarBarPane::XYChanged( double )
706 QtxDoubleSpinBox* snd = (QtxDoubleSpinBox*)sender();
707 if ( snd == XSpin ) {
708 WidthSpin->setMaximum( 1.0 - XSpin->value() );
710 if ( snd == YSpin ) {
711 HeightSpin->setMaximum( 1.0 - YSpin->value() );
716 Sets size and position
718 void VisuGUI_GaussScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
725 RBvert->setChecked( true );
732 RBhori->setChecked( true );
738 Sets colors and labels number
740 void VisuGUI_GaussScalarBarPane::setScalarBarData( int colors, int labels )
742 ColorSpin->setValue( colors );
743 LabelSpin->setValue( labels );
749 int VisuGUI_GaussScalarBarPane::getOrientation()
751 if (RBvert->isChecked() )
758 Sets and gets parameters
760 double VisuGUI_GaussScalarBarPane::getX() {
761 return XSpin->value();
764 double VisuGUI_GaussScalarBarPane::getY() {
765 return YSpin->value();
768 double VisuGUI_GaussScalarBarPane::getWidth() {
769 return WidthSpin->value();
772 double VisuGUI_GaussScalarBarPane::getHeight() {
773 return HeightSpin->value();
776 int VisuGUI_GaussScalarBarPane::getNbColors() {
777 return ColorSpin->value();
780 int VisuGUI_GaussScalarBarPane::getNbLabels() {
781 return LabelSpin->value();
784 void VisuGUI_GaussScalarBarPane::onTextPref()
786 myIsStoreTextProp = myTextDlg->exec();
789 void VisuGUI_GaussScalarBarPane::onBarPref()
791 if(RBvert->isChecked())
792 myBarDlg->setRatios(myVerTS, myVerLS, myVerBW, myVerBH);
794 myBarDlg->setRatios(myHorTS, myHorLS, myHorBW, myHorBH);
795 if(myBarDlg->exec()) {
796 if(RBvert->isChecked())
797 myBarDlg->getRatios(myVerTS, myVerLS, myVerBW, myVerBH);
799 myBarDlg->getRatios(myHorTS, myHorLS, myHorBW, myHorBH);
806 VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule):
808 VisuGUI_Prs3dDlg(theModule)
810 //setName("VisuGUI_GaussPointsDlg");
811 setWindowTitle(tr("DLG_PROP_TITLE"));
812 setSizeGripEnabled(TRUE);
814 QVBoxLayout* TopLayout = new QVBoxLayout(this);
815 TopLayout->setSpacing(6);
816 TopLayout->setMargin(11);
820 QButtonGroup* PrsGroup = new QButtonGroup( this );
821 QGroupBox* aGB = new QGroupBox( tr( "PRS_TITLE" ), this );
822 QHBoxLayout* aHBLay = new QHBoxLayout( aGB );
823 PrsGroup->setExclusive( true );
824 aHBLay->setMargin( 11 );
825 aHBLay->setSpacing(6);
827 myResultsButton = new QRadioButton( tr( "RESULTS" ), aGB );
828 myGeometryButton = new QRadioButton( tr( "GEOMETRY" ), aGB );
829 myDefShapeButton = new QRadioButton( tr( "DEFORMED_SHAPE" ), aGB );
830 aHBLay->addWidget( myResultsButton );
831 aHBLay->addWidget( myGeometryButton );
832 aHBLay->addWidget( myDefShapeButton );
834 PrsGroup->addButton( myResultsButton );
835 PrsGroup->addButton( myGeometryButton );
836 PrsGroup->addButton( myDefShapeButton );
839 myTabBox = new QTabWidget (this);
842 QWidget* aBox = new QWidget (this);
843 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
844 aVBLay->setMargin(11);
845 aVBLay->setSpacing(6);
848 myPrimitiveBox = new VVTK_PrimitiveBox( aBox );
849 aVBLay->addWidget( myPrimitiveBox );
852 mySizeBox = new VVTK_SizeBox( aBox );
853 aVBLay->addWidget( mySizeBox );
856 myDefShapeBox = new QGroupBox( tr( "DEFORMED_SHAPE_TITLE" ), aBox );
857 aVBLay->addWidget( myDefShapeBox );
858 //myDefShapeBox->setColumnLayout(0, Qt::Vertical );
859 //myDefShapeBox->layout()->setSpacing( 0 );
860 //myDefShapeBox->layout()->setMargin( 0 );
862 QGridLayout* aDefShapeLayout = new QGridLayout( myDefShapeBox );
863 aDefShapeLayout->setAlignment(Qt::AlignTop);
864 aDefShapeLayout->setSpacing(6);
865 aDefShapeLayout->setMargin(11);
867 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
868 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
870 QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox );
871 myScaleSpinBox = new QtxDoubleSpinBox( 0.0, 10.0, 0.1, aPrecision*(-1), 32, myDefShapeBox );
873 aDefShapeLayout->addWidget( aScaleLabel, 0, 0 );
874 aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 );
877 myScalarPane = new VisuGUI_GaussScalarBarPane(this);
878 if ( myScalarPane->layout() )
879 myScalarPane->layout()->setMargin(5);
882 myInputPane = new VisuGUI_InputPane(VISU::TGAUSSPOINTS, theModule, this);
883 myInputPane->SetRestoreInitialSelection(false);
885 connect( myResultsButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleResults() ) );
886 connect( myResultsButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
887 connect( myGeometryButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleGeometry() ) );
888 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), this, SLOT( onToggleDefShape( bool ) ) );
889 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
891 myTabBox->addTab(aBox, tr("GAUSS_POINTS_TAB"));
892 myTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
893 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
895 // Common buttons ===========================================================
896 QGroupBox* GroupButtons = new QGroupBox( this );
897 //GroupButtons->setColumnLayout(0, Qt::Vertical );
898 //GroupButtons->layout()->setSpacing( 0 );
899 //GroupButtons->layout()->setMargin( 0 );
900 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
901 GroupButtonsLayout->setAlignment( Qt::AlignTop );
902 GroupButtonsLayout->setSpacing( 6 );
903 GroupButtonsLayout->setMargin( 11 );
905 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
906 buttonOk->setAutoDefault( TRUE );
907 buttonOk->setDefault( TRUE );
908 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
909 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
911 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons );
912 buttonCancel->setAutoDefault( TRUE );
913 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
915 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons );
916 buttonHelp->setAutoDefault( TRUE );
917 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
919 TopLayout->addWidget( aGB );
920 TopLayout->addWidget( myTabBox );
921 TopLayout->addWidget( GroupButtons );
923 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
924 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
925 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
928 VisuGUI_GaussPointsDlg::~VisuGUI_GaussPointsDlg()
931 void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
935 myPrsCopy = VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
937 myScalarPane->initFromPrsObject( myPrsCopy, theInit );
939 bool isDeformed = myPrsCopy->GetIsDeformed();
940 myScaleSpinBox->setValue( myPrsCopy->GetScaleFactor() );
941 myDefShapeButton->setChecked( isDeformed );
942 myDefShapeButton->setEnabled( myPrsCopy->GetField()->myNbComp > 1 );
943 onToggleDefShape( isDeformed );
945 bool isResults = myPrsCopy->GetIsColored();
946 myResultsButton->setChecked( isResults && !isDeformed );
947 myGeometryButton->setChecked( !isResults && !isDeformed );
949 myPrimitiveBox->setPrimitiveType( myPrsCopy->GetPrimitiveType() );
950 myPrimitiveBox->setClampMaximum( myPrsCopy->GetMaximumSupportedSize() );
951 myPrimitiveBox->setClamp( myPrsCopy->GetClamp() );
952 myPrimitiveBox->setMainTexture( myPrsCopy->GetQMainTexture() );
953 myPrimitiveBox->setAlphaTexture( myPrsCopy->GetQAlphaTexture() );
954 myPrimitiveBox->setAlphaThreshold( myPrsCopy->GetAlphaThreshold() );
955 myPrimitiveBox->setResolution( myPrsCopy->GetResolution() );
956 myPrimitiveBox->setFaceLimit( myPrsCopy->GetFaceLimit() );
958 mySizeBox->setType( isResults || isDeformed ? VVTK_SizeBox::Results : VVTK_SizeBox::Geometry );
959 mySizeBox->setGeomSize( myPrsCopy->GetGeomSize() );
960 mySizeBox->setMinSize( myPrsCopy->GetMinSize() );
961 mySizeBox->setMaxSize( myPrsCopy->GetMaxSize() );
962 mySizeBox->setMagnification( myPrsCopy->GetMagnification() );
963 mySizeBox->setIncrement( myPrsCopy->GetMagnificationIncrement() );
964 mySizeBox->setColor( myPrsCopy->GetQColor() );
966 //Disable Size controls if there are no OpenGL extensions
967 char* ext = (char*)glGetString( GL_EXTENSIONS );
968 if( strstr( ext, "GL_ARB_point_sprite" ) == NULL ||
969 strstr( ext, "GL_ARB_shader_objects" ) == NULL ||
970 strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL )
971 mySizeBox->enableSizeControls(false);
976 myInputPane->initFromPrsObject( myPrsCopy );
977 myTabBox->setCurrentIndex( 0 );
980 int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
982 if(!myInputPane->check())
985 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
986 anIsOk &= myScalarPane->storeToPrsObject( myPrsCopy );
988 myPrsCopy->SetIsDeformed( myDefShapeButton->isChecked() );
989 myPrsCopy->SetScaleFactor( myScaleSpinBox->value() );
991 int aPrimitiveType = myPrimitiveBox->getPrimitiveType();
992 myPrsCopy->SetPrimitiveType( VISU::GaussPoints::PrimitiveType( aPrimitiveType ) );
994 myPrsCopy->SetClamp( myPrimitiveBox->getClamp() );
996 QString aMainTexture = myPrimitiveBox->getMainTexture();
997 QString anAlphaTexture = myPrimitiveBox->getAlphaTexture();
999 aMainTexture = aMainTexture.isNull() ? myPrsCopy->GetQMainTexture() : aMainTexture;
1000 anAlphaTexture = anAlphaTexture.isNull() ? myPrsCopy->GetQAlphaTexture() : anAlphaTexture;
1002 myPrsCopy->SetTextures( aMainTexture.toLatin1().data(), anAlphaTexture.toLatin1().data() );
1004 myPrsCopy->SetAlphaThreshold( myPrimitiveBox->getAlphaThreshold() );
1006 myPrsCopy->SetResolution( myPrimitiveBox->getResolution() );
1007 myPrsCopy->SetFaceLimit( myPrimitiveBox->getFaceLimit() );
1009 bool isColored = !myGeometryButton->isChecked();
1012 myPrsCopy->SetIsColored( true );
1013 myPrsCopy->SetMinSize( mySizeBox->getMinSize() );
1014 myPrsCopy->SetMaxSize( mySizeBox->getMaxSize() );
1018 myPrsCopy->SetIsColored( false );
1019 myPrsCopy->SetQColor( mySizeBox->getColor() );
1020 myPrsCopy->SetGeomSize( mySizeBox->getGeomSize() );
1023 myPrsCopy->SetMagnification( mySizeBox->getMagnification() );
1024 myPrsCopy->SetMagnificationIncrement( mySizeBox->getIncrement() );
1026 VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Copy(myPrsCopy, thePrs);
1028 //Set created Gauss points presentation selected,
1029 //Issue 0019874(EDF 746 VISU: Picking alphanumeric Gauss)
1031 SALOME_ListIO aListIO;
1032 //LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
1033 Handle(SALOME_InteractiveObject) anIO = thePrs->GetIO();
1034 if(anIO && anIO->hasEntry()) {
1035 aListIO.Append(anIO);
1036 VISU::UpdateObjBrowser(myModule,true);
1037 //IPAL20836 aSelectionMgr->setSelectedObjects(aListIO);
1040 myInputPane->SetRestoreInitialSelection(true);
1045 void VisuGUI_GaussPointsDlg::onToggleDefShape( bool on )
1047 if( on )//myDefShapeButton->isChecked() )
1049 myDefShapeBox->show();
1050 mySizeBox->setType( VVTK_SizeBox::Results );
1053 myDefShapeBox->hide();
1056 void VisuGUI_GaussPointsDlg::accept()
1058 if( (bool)myPrsCopy && myPrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere )
1060 int aNumberOfFaces = myPrimitiveBox->getFaceNumber();
1061 int aNumberOfPoints = myPrsCopy->GetSpecificPL()->GetInput()->GetNumberOfCells();
1063 if( aNumberOfFaces * aNumberOfPoints > myPrimitiveBox->getFaceLimit() )
1065 QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
1066 aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
1067 aWarning.append( "Can you please confirm that you want to continue anyway?" );
1068 if( SUIT_MessageBox::warning( this, tr( "Warning" ), aWarning, tr( "&OK" ), tr( "&Cancel" ) ) == 1 )
1073 float aMemory = 50.0 * 1024.0 * (float)aNumberOfFaces * (float)aNumberOfPoints;
1075 cout << aNumberOfFaces << endl;
1076 cout << aNumberOfPoints << endl;
1077 cout << aMemory << endl;
1079 vtkSphereSource* aSphere = vtkSphereSource::New();
1080 aSphere->SetThetaResolution( myPrimitiveBox->getResolution() );
1081 aSphere->SetPhiResolution( myPrimitiveBox->getResolution() );
1082 aSphere->GetOutput()->Update();
1083 aSphere->GetOutput()->GetActualMemorySize();
1085 aMemory = aSphere->GetOutput()->GetActualMemorySize() * 1024.0 * (float)aNumberOfPoints;
1087 if( VISU_PipeLine::CheckAvailableMemory( aMemory ) == 0 )
1089 SUIT_MessageBox::error1( this, "caption", "text", "ok" );
1095 //if( myScalarPane->check() )
1096 VisuGUI_Prs3dDlg::accept();
1099 QString VisuGUI_GaussPointsDlg::GetContextHelpFilePath()
1101 return "types_of_gauss_points_presentations_page.html";