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 MinEdit = new QLineEdit( aGB );
146 MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
147 MinEdit->setMinimumWidth( 70 );
148 MinEdit->setValidator( new QDoubleValidator(this) );
149 MinEdit->setText( "0.0" );
150 QLabel* MinLabel = new QLabel (tr("LBL_MIN"), aGB);
151 MinLabel->setBuddy(MinEdit);
153 MaxEdit = new QLineEdit( aGB );
154 MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
155 MaxEdit->setMinimumWidth( 70 );
156 MaxEdit->setValidator( new QDoubleValidator(this) );
157 MaxEdit->setText( "0.0" );
158 QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), aGB);
159 MaxLabel->setBuddy(MaxEdit);
161 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
162 RangeGroupLayout->addWidget( myModeCombo, 0, 1, 1, 3);
163 RangeGroupLayout->addWidget( RBFieldRange, 1, 0, 1, 2);
164 RangeGroupLayout->addWidget( RBImposedRange, 1, 2, 1, 2);
165 RangeGroupLayout->addWidget( MinLabel, 2, 0 );
166 RangeGroupLayout->addWidget( MinEdit, 2, 1 );
167 RangeGroupLayout->addWidget( MaxLabel, 2, 2 );
168 RangeGroupLayout->addWidget( MaxEdit, 2, 3 );
170 // Colors and Labels ========================================================
171 QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this );
172 aMainLayout->addWidget(ColLabGroup);
173 //ColLabGroup->setColumnLayout(0, Qt::Vertical );
174 //ColLabGroup->layout()->setSpacing( 0 );
175 //ColLabGroup->layout()->setMargin( 0 );
176 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup );
177 ColLabGroupLayout->setAlignment( Qt::AlignTop );
178 ColLabGroupLayout->setSpacing( 6 );
179 ColLabGroupLayout->setMargin( 11 );
181 QButtonGroup* TypeGroup = new QButtonGroup( ColLabGroup );
182 aGB = new QGroupBox ( ColLabGroup );
183 aVBLay = new QVBoxLayout( aGB );
184 TypeGroup->setExclusive( true );
185 //aGB->setFrameStyle( QFrame::NoFrame );
186 aVBLay->setMargin( 0 );
188 BicolorButton = new QRadioButton( tr( "BICOLOR" ), aGB );
189 aVBLay->addWidget( BicolorButton );
190 TypeGroup->addButton( BicolorButton );
191 RainbowButton = new QRadioButton( tr( "RAINBOW" ), aGB );
192 aVBLay->addWidget( RainbowButton );
193 TypeGroup->addButton( RainbowButton );
195 ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup );
196 ColorSpin = new QSpinBox( ColLabGroup );
197 ColorSpin->setMinimum( 2 );
198 ColorSpin->setMaximum( 256 );
199 ColorSpin->setSingleStep( 1 );
200 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
201 ColorSpin->setMinimumWidth( 70 );
202 ColorSpin->setValue( 64 );
204 LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup);
205 LabelSpin = new QSpinBox( ColLabGroup );
206 LabelSpin->setMinimum( 2 );
207 LabelSpin->setMaximum( 65 );
208 LabelSpin->setSingleStep( 1 );
209 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
210 LabelSpin->setMinimumWidth( 70 );
211 LabelSpin->setValue( 5 );
213 ColLabGroupLayout->addWidget( aGB, 0, 0, 2, 1);
214 ColLabGroupLayout->addWidget( ColorLabel, 1, 1);
215 ColLabGroupLayout->addWidget( ColorSpin, 1, 2);
216 ColLabGroupLayout->addWidget( LabelLabel, 1, 3);
217 ColLabGroupLayout->addWidget( LabelSpin, 1, 4);
219 //TopLayout->addWidget( ColLabGroup );
221 // Orientation ==========================================================
222 QButtonGroup* OrientGroup = new QButtonGroup ( this );
223 aGB = new QGroupBox( tr("ORIENTATION_GRP"), this );
224 aMainLayout->addWidget(aGB);
225 //OrientGroup->setColumnLayout(0, Qt::Vertical );
226 //OrientGroup->layout()->setSpacing( 0 );
227 //OrientGroup->layout()->setMargin( 0 );
228 QGridLayout* OrientGroupLayout = new QGridLayout( aGB );
229 OrientGroupLayout->setAlignment( Qt::AlignTop );
230 OrientGroupLayout->setSpacing( 6 );
231 OrientGroupLayout->setMargin( 11 );
233 RBvert = new QRadioButton (tr("VERTICAL_BTN"), aGB );
234 RBvert->setChecked( true );
235 OrientGroup->addButton( RBvert );
236 RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), aGB);
237 OrientGroup->addButton( RBhori
239 OrientGroupLayout->addWidget( RBvert, 0, 0 );
240 OrientGroupLayout->addWidget( RBhori, 0, 1 );
242 // TopLayout->addWidget( OrientGroup );
244 // Origin ===============================================================
245 QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this );
246 aMainLayout->addWidget( OriginGroup );
247 //OriginGroup->setColumnLayout(0, Qt::Vertical );
248 //OriginGroup->layout()->setSpacing( 0 );
249 //OriginGroup->layout()->setMargin( 0 );
250 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup );
251 OriginGroupLayout->setAlignment( Qt::AlignTop );
252 OriginGroupLayout->setSpacing( 6 );
253 OriginGroupLayout->setMargin( 11 );
255 QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup );
256 XSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, OriginGroup );
257 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
258 XSpin->setMinimumWidth( 70 );
259 XSpin->setValue( 0.01 );
261 QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup );
262 YSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, OriginGroup );
263 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
264 YSpin->setMinimumWidth( 70 );
265 YSpin->setValue( 0.01 );
267 OriginGroupLayout->addWidget( XLabel, 0, 0);
268 OriginGroupLayout->addWidget( XSpin, 0, 1);
269 OriginGroupLayout->addWidget( YLabel, 0, 2);
270 OriginGroupLayout->addWidget( YSpin, 0, 3);
272 //TopLayout->addWidget( OriginGroup );
274 // Dimensions =========================================================
275 QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this );
276 aMainLayout->addWidget( DimGroup );
277 //DimGroup->setColumnLayout(0, Qt::Vertical );
278 //DimGroup->layout()->setSpacing( 0 );
279 //DimGroup->layout()->setMargin( 0 );
280 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup );
281 DimGroupLayout->setAlignment( Qt::AlignTop );
282 DimGroupLayout->setSpacing( 6 );
283 DimGroupLayout->setMargin( 11 );
285 QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup );
286 WidthSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, DimGroup );
287 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
288 WidthSpin->setMinimumWidth( 70 );
289 WidthSpin->setValue( 0.1 );
291 QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup );
292 HeightSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, DimGroup );
293 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
294 HeightSpin->setMinimumWidth( 70 );
295 HeightSpin->setValue( 0.8 );
297 QLabel* SpacingLabel = new QLabel (tr("LBL_SPACING"), DimGroup );
298 SpacingSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.01, DimGroup );
299 SpacingSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
300 SpacingSpin->setMinimumWidth( 70 );
301 SpacingSpin->setValue( 0.01 );
303 DimGroupLayout->addWidget( WidthLabel, 0, 0);
304 DimGroupLayout->addWidget( WidthSpin, 0, 1);
305 DimGroupLayout->addWidget( HeightLabel, 0, 2);
306 DimGroupLayout->addWidget( HeightSpin, 0, 3);
307 DimGroupLayout->addWidget( SpacingLabel, 0, 4);
308 DimGroupLayout->addWidget( SpacingSpin, 0, 5);
310 //TopLayout->addWidget( DimGroup );
312 QWidget* aSaveBox = new QWidget(this);
313 aMainLayout->addWidget( aSaveBox );
315 QHBoxLayout* aHBoxLay = new QHBoxLayout( aSaveBox );
317 myTextBtn = new QPushButton("Text properties...", aSaveBox);
318 aHBoxLay->addWidget( myTextBtn );
320 myBarBtn = new QPushButton("Bar properties...", aSaveBox);
321 aHBoxLay->addWidget( myBarBtn );
323 myTextDlg = new VisuGUI_TextPrefDlg(this);
324 aMainLayout->addWidget( myTextDlg );
325 myTextDlg->setTitleVisible(true);
327 myBarDlg = new VisuGUI_BarPrefDlg(this);
328 aMainLayout->addWidget( myBarDlg );
330 QGroupBox* CheckGroup = new QGroupBox("", this );
331 aMainLayout->addWidget( CheckGroup );
332 QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup );
334 myHideBar = new QCheckBox(tr("HIDE_SCALAR_BAR"), CheckGroup);
335 myHideBar->setChecked(false);
336 CheckGroupLayout->addWidget(myHideBar, 0, 0);
338 // signals and slots connections ===========================================
339 connect( RBFieldRange, SIGNAL( clicked() ), this, SLOT( fieldRangeClicked() ) );
340 connect( RBImposedRange,SIGNAL( clicked() ), this, SLOT( imposedRangeClicked() ) );
342 connect( myModeCombo, SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) );
344 connect( myRBLocal, SIGNAL( clicked() ), this, SLOT( onLocalScalarBar() ) );
345 connect( myRBGlobal, SIGNAL( clicked() ), this, SLOT( onGlobalScalarBar() ) );
347 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorLabel, SLOT( setEnabled( bool ) ) );
348 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorSpin, SLOT( setEnabled( bool ) ) );
349 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelLabel, SLOT( setEnabled( bool ) ) );
350 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelSpin, SLOT( setEnabled( bool ) ) );
351 connect( OrientGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( changeDefaults( int ) ) );
352 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
353 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
354 connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
355 connect( myBarBtn, SIGNAL( clicked() ), this, SLOT( onBarPref() ) );
358 myIsStoreTextProp = false;
361 bool VisuGUI_GaussScalarBarPane::UseFieldRange(bool theInit)
364 return !myPrsCopy->IsRangeFixed();
366 return RBFieldRange->isChecked() || !myPrsCopy->GetIsActiveLocalScalarBar();
370 void VisuGUI_GaussScalarBarPane::onGlobalScalarBar()
372 myPrsCopy->SetIsActiveLocalScalarBar(false);
373 myPrsCopy->SetSourceRange();
375 myCBDisplayed->setEnabled( false );
377 RBImposedRange->setEnabled( false );
378 RBFieldRange->setEnabled( false );
380 MinEdit->setEnabled( false );
381 MaxEdit->setEnabled( false );
383 MinEdit->setText( QString::number( myPrsCopy->GetMin() ) );
384 MaxEdit->setText( QString::number( myPrsCopy->GetMax() ) );
388 void VisuGUI_GaussScalarBarPane::onLocalScalarBar()
390 myPrsCopy->SetIsActiveLocalScalarBar(true);
391 if ( RBFieldRange->isChecked() )
392 myPrsCopy->SetSourceRange();
394 myPrsCopy->SetRange(myPrsCopy->GetMin(), myPrsCopy->GetMax());
396 myCBDisplayed->setEnabled( true );
398 RBImposedRange->setEnabled( true );
399 RBFieldRange->setEnabled( true );
401 MinEdit->setEnabled( RBImposedRange->isChecked() );
402 MaxEdit->setEnabled( RBImposedRange->isChecked() );
404 MinEdit->setText( QString::number( myPrsCopy->GetMin() ) );
405 MaxEdit->setText( QString::number( myPrsCopy->GetMax() ) );
410 Called when Range mode is changed to FieldRange
412 void VisuGUI_GaussScalarBarPane::fieldRangeClicked()
414 myPrsCopy->SetSourceRange();
416 RBFieldRange->setChecked( true );
417 RBImposedRange->setChecked( false );
419 MinEdit->setEnabled( false );
420 MaxEdit->setEnabled( false );
422 MinEdit->setText( QString::number( myPrsCopy->GetMin() ) );
423 MaxEdit->setText( QString::number( myPrsCopy->GetMax() ) );
428 Called when Range mode is changed to FieldRange
430 void VisuGUI_GaussScalarBarPane::imposedRangeClicked()
432 myPrsCopy->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
434 RBImposedRange->setChecked( true );
435 RBFieldRange->setChecked( false );
437 MinEdit->setEnabled( true );
438 MaxEdit->setEnabled( true );
443 Called when scalar mode is changed
445 void VisuGUI_GaussScalarBarPane::changeScalarMode( int theMode )
447 myPrsCopy->SetScalarMode( theMode );
448 if ( UseFieldRange() ) {
449 MinEdit->setText( QString::number( myPrsCopy->GetSourceMin() ) );
450 MaxEdit->setText( QString::number( myPrsCopy->GetSourceMax() ) );
455 * Initialise dialog box from presentation object
457 void VisuGUI_GaussScalarBarPane::initFromPrsObject(VISU::GaussPoints_i* thePrs,
462 myModeCombo->setCurrentIndex(thePrs->GetScalarMode());
464 bool activeLocal = thePrs->GetIsActiveLocalScalarBar();
466 RBImposedRange->setChecked( !UseFieldRange(theInit) );
467 RBFieldRange->setChecked( UseFieldRange(theInit) );
468 MinEdit->setEnabled( !UseFieldRange(theInit) );
469 MaxEdit->setEnabled( !UseFieldRange(theInit) );
471 RBImposedRange->setEnabled( false );
472 RBFieldRange->setEnabled( false );
473 MinEdit->setEnabled( false );
474 MaxEdit->setEnabled( false );
477 MinEdit->setText( QString::number( thePrs->GetMin() ) );
478 MaxEdit->setText( QString::number( thePrs->GetMax() ) );
480 setPosAndSize( thePrs->GetPosX(),
484 thePrs->GetBarOrientation());
486 if(RBvert->isChecked()) {
487 myVerTS = thePrs->GetTitleSize();
488 myVerLS = thePrs->GetLabelSize();
489 myVerBW = thePrs->GetBarWidth();
490 myVerBH = thePrs->GetBarHeight();
492 myHorTS = thePrs->GetTitleSize();
493 myHorLS = thePrs->GetLabelSize();
494 myHorBW = thePrs->GetBarWidth();
495 myHorBH = thePrs->GetBarHeight();
498 myBarDlg->setLabelsPrecision( VISU::ToPrecision( thePrs->GetLabelsFormat() ) );
499 myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
501 SpacingSpin->setValue(thePrs->GetSpacing());
503 myRBLocal->setChecked( activeLocal );
505 myRBGlobal->setChecked( !activeLocal );
506 myRBGlobal->setEnabled( thePrs->IsGlobalRangeDefined() );
507 if( !thePrs->IsGlobalRangeDefined() )
508 myRBLocal->setChecked( true );
510 myCBDisplayed->setEnabled( activeLocal );
511 myCBDisplayed->setChecked( thePrs->GetIsDispGlobalScalarBar() );
513 bool bicolor = thePrs->GetSpecificPL()->GetBicolor();
514 BicolorButton->setChecked( bicolor );
515 RainbowButton->setChecked( !bicolor );
516 ColorLabel->setEnabled( !bicolor );
517 ColorSpin->setEnabled( !bicolor );
518 LabelLabel->setEnabled( !bicolor );
519 LabelSpin->setEnabled( !bicolor );
521 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
523 // Update myModeCombo
524 int aNbComp = thePrs->GetField()->myNbComp;
525 bool isScalarMode = (aNbComp > 1);
526 myModeCombo->clear();
527 myModeCombo->addItem("<Modulus>");
528 VISU::PField aField = thePrs->GetField();
529 const VISU::TNames& aCompNames = aField->myCompNames;
530 const VISU::TNames& aUnitNames = aField->myUnitNames;
531 for(int i = 0; i < aNbComp; i++){
532 QString aComponent = QString(aCompNames[i].c_str()).simplified();
533 if(aComponent.isNull() || aComponent == "")
534 aComponent = "Component " + QString::number(i+1);
536 aComponent = "[" + QString::number(i+1) + "] " + aComponent;
538 QString anUnit = QString(aUnitNames[i].c_str()).simplified();
539 if(anUnit.isNull() || anUnit == "")
542 aComponent = aComponent + ", " + anUnit;
544 myModeCombo->addItem(aComponent);
547 myModeCombo->setCurrentIndex(thePrs->GetScalarMode());
549 myModeCombo->setCurrentIndex(1);
552 myModeLbl->setEnabled(isScalarMode);
553 myModeCombo->setEnabled(isScalarMode);
556 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
558 vtkFloatingPointType R, G, B;
559 thePrs->GetTitleColor(R, G, B);
561 int lp = VISU::ToPrecision( thePrs->GetLabelsFormat() );
562 myBarDlg->setLabelsPrecision( lp );
563 myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
565 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
566 thePrs->GetTitFontType(),
567 thePrs->IsBoldTitle(),
568 thePrs->IsItalicTitle(),
569 thePrs->IsShadowTitle());
572 thePrs->GetLabelColor(R, G, B);
574 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
575 thePrs->GetLblFontType(),
576 thePrs->IsBoldLabel(),
577 thePrs->IsItalicLabel(),
578 thePrs->IsShadowLabel());
580 myHideBar->setChecked(!thePrs->IsBarVisible());
584 * Store values to presentation object
586 int VisuGUI_GaussScalarBarPane::storeToPrsObject(VISU::GaussPoints_i* thePrs) {
587 thePrs->SetScalarMode(myModeCombo->currentIndex());
589 if (RBFieldRange->isChecked()) {
590 thePrs->SetSourceRange();
592 thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
595 thePrs->SetSpacing(SpacingSpin->value());
596 thePrs->SetIsActiveLocalScalarBar(myRBLocal->isChecked());
597 thePrs->SetIsDispGlobalScalarBar(myCBDisplayed->isChecked());
598 thePrs->SetBiColor(BicolorButton->isChecked());
600 thePrs->SetPosition(XSpin->value(), YSpin->value());
601 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
602 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ColoredPrs3dBase::VERTICAL : VISU::ColoredPrs3dBase::HORIZONTAL);
603 thePrs->SetNbColors(ColorSpin->value());
604 thePrs->SetLabels(LabelSpin->value());
606 if(RBvert->isChecked()) {
607 thePrs->SetRatios(myVerTS, myVerLS, myVerBW, myVerBH);
609 thePrs->SetRatios(myHorTS, myHorLS, myHorBW, myHorBH);
612 std::string f = VISU::ToFormat( myBarDlg->getLabelsPrecision() );
613 thePrs->SetLabelsFormat( f.c_str() );
614 thePrs->SetUnitsVisible(myBarDlg->isUnitsVisible());
616 thePrs->SetBarVisible(!myHideBar->isChecked());
618 if (myIsStoreTextProp) {
620 thePrs->SetTitle(myTextDlg->getTitleText().toLatin1().data());
622 QColor aTitColor (255, 255, 255);
623 int aTitleFontFamily = VTK_ARIAL;
624 bool isTitleBold = false;
625 bool isTitleItalic = false;
626 bool isTitleShadow = false;
628 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
629 isTitleBold, isTitleItalic, isTitleShadow);
631 thePrs->SetBoldTitle(isTitleBold);
632 thePrs->SetItalicTitle(isTitleItalic);
633 thePrs->SetShadowTitle(isTitleShadow);
634 thePrs->SetTitFontType(aTitleFontFamily);
635 thePrs->SetTitleColor(aTitColor.red()/255.,
636 aTitColor.green()/255.,
637 aTitColor.blue()/255.);
640 QColor aLblColor (255, 255, 255);
641 int aLabelFontFamily = VTK_ARIAL;
642 bool isLabelBold = false;
643 bool isLabelItalic = false;
644 bool isLabelShadow = false;
646 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
647 isLabelBold, isLabelItalic, isLabelShadow);
649 thePrs->SetBoldLabel(isLabelBold);
650 thePrs->SetItalicLabel(isLabelItalic);
651 thePrs->SetShadowLabel(isLabelShadow);
652 thePrs->SetLblFontType(aLabelFontFamily);
653 thePrs->SetLabelColor(aLblColor.red()/255.,
654 aLblColor.green()/255.,
655 aLblColor.blue()/255.);
662 Called when orientation is changed
664 void VisuGUI_GaussScalarBarPane::changeDefaults( int )
666 if ( RBvert->isChecked() ) {
667 XSpin->setValue( myVerX );
668 YSpin->setValue( myVerY );
669 WidthSpin->setValue( myVerW );
670 HeightSpin->setValue( myVerH );
673 XSpin->setValue( myHorX );
674 YSpin->setValue( myHorY );
675 WidthSpin->setValue( myHorW );
676 HeightSpin->setValue( myHorH );
681 Called when X,Y position is changed
683 void VisuGUI_GaussScalarBarPane::XYChanged( double )
685 QtxDoubleSpinBox* snd = (QtxDoubleSpinBox*)sender();
686 if ( snd == XSpin ) {
687 WidthSpin->setMaximum( 1.0 - XSpin->value() );
689 if ( snd == YSpin ) {
690 HeightSpin->setMaximum( 1.0 - YSpin->value() );
695 Sets size and position
697 void VisuGUI_GaussScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
704 RBvert->setChecked( true );
711 RBhori->setChecked( true );
717 Sets colors and labels number
719 void VisuGUI_GaussScalarBarPane::setScalarBarData( int colors, int labels )
721 ColorSpin->setValue( colors );
722 LabelSpin->setValue( labels );
728 int VisuGUI_GaussScalarBarPane::getOrientation()
730 if (RBvert->isChecked() )
737 Sets and gets parameters
739 double VisuGUI_GaussScalarBarPane::getX() {
740 return XSpin->value();
743 double VisuGUI_GaussScalarBarPane::getY() {
744 return YSpin->value();
747 double VisuGUI_GaussScalarBarPane::getWidth() {
748 return WidthSpin->value();
751 double VisuGUI_GaussScalarBarPane::getHeight() {
752 return HeightSpin->value();
755 int VisuGUI_GaussScalarBarPane::getNbColors() {
756 return ColorSpin->value();
759 int VisuGUI_GaussScalarBarPane::getNbLabels() {
760 return LabelSpin->value();
763 void VisuGUI_GaussScalarBarPane::onTextPref()
765 myIsStoreTextProp = myTextDlg->exec();
768 void VisuGUI_GaussScalarBarPane::onBarPref()
770 if(RBvert->isChecked())
771 myBarDlg->setRatios(myVerTS, myVerLS, myVerBW, myVerBH);
773 myBarDlg->setRatios(myHorTS, myHorLS, myHorBW, myHorBH);
774 if(myBarDlg->exec()) {
775 if(RBvert->isChecked())
776 myBarDlg->getRatios(myVerTS, myVerLS, myVerBW, myVerBH);
778 myBarDlg->getRatios(myHorTS, myHorLS, myHorBW, myHorBH);
785 VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule):
787 VisuGUI_Prs3dDlg(theModule)
789 //setName("VisuGUI_GaussPointsDlg");
790 setWindowTitle(tr("DLG_PROP_TITLE"));
791 setSizeGripEnabled(TRUE);
793 QVBoxLayout* TopLayout = new QVBoxLayout(this);
794 TopLayout->setSpacing(6);
795 TopLayout->setMargin(11);
799 QButtonGroup* PrsGroup = new QButtonGroup( this );
800 QGroupBox* aGB = new QGroupBox( tr( "PRS_TITLE" ), this );
801 QHBoxLayout* aHBLay = new QHBoxLayout( aGB );
802 PrsGroup->setExclusive( true );
803 aHBLay->setMargin( 11 );
804 aHBLay->setSpacing(6);
806 myResultsButton = new QRadioButton( tr( "RESULTS" ), aGB );
807 myGeometryButton = new QRadioButton( tr( "GEOMETRY" ), aGB );
808 myDefShapeButton = new QRadioButton( tr( "DEFORMED_SHAPE" ), aGB );
809 aHBLay->addWidget( myResultsButton );
810 aHBLay->addWidget( myGeometryButton );
811 aHBLay->addWidget( myDefShapeButton );
813 PrsGroup->addButton( myResultsButton );
814 PrsGroup->addButton( myGeometryButton );
815 PrsGroup->addButton( myDefShapeButton );
818 myTabBox = new QTabWidget (this);
821 QWidget* aBox = new QWidget (this);
822 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
823 aVBLay->setMargin(11);
824 aVBLay->setSpacing(6);
827 myPrimitiveBox = new VVTK_PrimitiveBox( aBox );
828 aVBLay->addWidget( myPrimitiveBox );
831 mySizeBox = new VVTK_SizeBox( aBox );
832 aVBLay->addWidget( mySizeBox );
835 myDefShapeBox = new QGroupBox( tr( "DEFORMED_SHAPE_TITLE" ), aBox );
836 aVBLay->addWidget( myDefShapeBox );
837 //myDefShapeBox->setColumnLayout(0, Qt::Vertical );
838 //myDefShapeBox->layout()->setSpacing( 0 );
839 //myDefShapeBox->layout()->setMargin( 0 );
841 QGridLayout* aDefShapeLayout = new QGridLayout( myDefShapeBox );
842 aDefShapeLayout->setAlignment(Qt::AlignTop);
843 aDefShapeLayout->setSpacing(6);
844 aDefShapeLayout->setMargin(11);
846 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
847 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
849 QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox );
850 myScaleSpinBox = new QtxDoubleSpinBox( 0.0, 10.0, 0.1, aPrecision*(-1), 32, myDefShapeBox );
852 aDefShapeLayout->addWidget( aScaleLabel, 0, 0 );
853 aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 );
856 myScalarPane = new VisuGUI_GaussScalarBarPane(this);
857 if ( myScalarPane->layout() )
858 myScalarPane->layout()->setMargin(5);
861 myInputPane = new VisuGUI_InputPane(VISU::TGAUSSPOINTS, theModule, this);
862 myInputPane->SetRestoreInitialSelection(false);
864 connect( myResultsButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleResults() ) );
865 connect( myResultsButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
866 connect( myGeometryButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleGeometry() ) );
867 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), this, SLOT( onToggleDefShape( bool ) ) );
868 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
870 myTabBox->addTab(aBox, tr("GAUSS_POINTS_TAB"));
871 myTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
872 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
874 // Common buttons ===========================================================
875 QGroupBox* GroupButtons = new QGroupBox( this );
876 //GroupButtons->setColumnLayout(0, Qt::Vertical );
877 //GroupButtons->layout()->setSpacing( 0 );
878 //GroupButtons->layout()->setMargin( 0 );
879 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
880 GroupButtonsLayout->setAlignment( Qt::AlignTop );
881 GroupButtonsLayout->setSpacing( 6 );
882 GroupButtonsLayout->setMargin( 11 );
884 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
885 buttonOk->setAutoDefault( TRUE );
886 buttonOk->setDefault( TRUE );
887 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
888 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
890 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons );
891 buttonCancel->setAutoDefault( TRUE );
892 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
894 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons );
895 buttonHelp->setAutoDefault( TRUE );
896 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
898 TopLayout->addWidget( aGB );
899 TopLayout->addWidget( myTabBox );
900 TopLayout->addWidget( GroupButtons );
902 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
903 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
904 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
907 VisuGUI_GaussPointsDlg::~VisuGUI_GaussPointsDlg()
910 void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
914 myPrsCopy = VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
916 myScalarPane->initFromPrsObject( myPrsCopy, theInit );
918 bool isDeformed = myPrsCopy->GetIsDeformed();
919 myScaleSpinBox->setValue( myPrsCopy->GetScaleFactor() );
920 myDefShapeButton->setChecked( isDeformed );
921 myDefShapeButton->setEnabled( myPrsCopy->GetField()->myNbComp > 1 );
922 onToggleDefShape( isDeformed );
924 bool isResults = myPrsCopy->GetIsColored();
925 myResultsButton->setChecked( isResults && !isDeformed );
926 myGeometryButton->setChecked( !isResults && !isDeformed );
928 myPrimitiveBox->setPrimitiveType( myPrsCopy->GetPrimitiveType() );
929 myPrimitiveBox->setClampMaximum( myPrsCopy->GetMaximumSupportedSize() );
930 myPrimitiveBox->setClamp( myPrsCopy->GetClamp() );
931 myPrimitiveBox->setMainTexture( myPrsCopy->GetQMainTexture() );
932 myPrimitiveBox->setAlphaTexture( myPrsCopy->GetQAlphaTexture() );
933 myPrimitiveBox->setAlphaThreshold( myPrsCopy->GetAlphaThreshold() );
934 myPrimitiveBox->setResolution( myPrsCopy->GetResolution() );
935 myPrimitiveBox->setFaceLimit( myPrsCopy->GetFaceLimit() );
937 mySizeBox->setType( isResults || isDeformed ? VVTK_SizeBox::Results : VVTK_SizeBox::Geometry );
938 mySizeBox->setGeomSize( myPrsCopy->GetGeomSize() );
939 mySizeBox->setMinSize( myPrsCopy->GetMinSize() );
940 mySizeBox->setMaxSize( myPrsCopy->GetMaxSize() );
941 mySizeBox->setMagnification( myPrsCopy->GetMagnification() );
942 mySizeBox->setIncrement( myPrsCopy->GetMagnificationIncrement() );
943 mySizeBox->setColor( myPrsCopy->GetQColor() );
945 //Disable Size controls if there are no OpenGL extensions
946 char* ext = (char*)glGetString( GL_EXTENSIONS );
947 if( strstr( ext, "GL_ARB_point_sprite" ) == NULL ||
948 strstr( ext, "GL_ARB_shader_objects" ) == NULL ||
949 strstr( ext, "GL_ARB_vertex_buffer_object" ) == NULL )
950 mySizeBox->enableSizeControls(false);
955 myInputPane->initFromPrsObject( myPrsCopy );
956 myTabBox->setCurrentIndex( 0 );
959 int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
961 if(!myInputPane->check())
964 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
965 anIsOk &= myScalarPane->storeToPrsObject( myPrsCopy );
967 myPrsCopy->SetIsDeformed( myDefShapeButton->isChecked() );
968 myPrsCopy->SetScaleFactor( myScaleSpinBox->value() );
970 int aPrimitiveType = myPrimitiveBox->getPrimitiveType();
971 myPrsCopy->SetPrimitiveType( VISU::GaussPoints::PrimitiveType( aPrimitiveType ) );
973 myPrsCopy->SetClamp( myPrimitiveBox->getClamp() );
975 QString aMainTexture = myPrimitiveBox->getMainTexture();
976 QString anAlphaTexture = myPrimitiveBox->getAlphaTexture();
978 aMainTexture = aMainTexture.isNull() ? myPrsCopy->GetQMainTexture() : aMainTexture;
979 anAlphaTexture = anAlphaTexture.isNull() ? myPrsCopy->GetQAlphaTexture() : anAlphaTexture;
981 myPrsCopy->SetTextures( aMainTexture.toLatin1().data(), anAlphaTexture.toLatin1().data() );
983 myPrsCopy->SetAlphaThreshold( myPrimitiveBox->getAlphaThreshold() );
985 myPrsCopy->SetResolution( myPrimitiveBox->getResolution() );
986 myPrsCopy->SetFaceLimit( myPrimitiveBox->getFaceLimit() );
988 bool isColored = !myGeometryButton->isChecked();
991 myPrsCopy->SetIsColored( true );
992 myPrsCopy->SetMinSize( mySizeBox->getMinSize() );
993 myPrsCopy->SetMaxSize( mySizeBox->getMaxSize() );
997 myPrsCopy->SetIsColored( false );
998 myPrsCopy->SetQColor( mySizeBox->getColor() );
999 myPrsCopy->SetGeomSize( mySizeBox->getGeomSize() );
1002 myPrsCopy->SetMagnification( mySizeBox->getMagnification() );
1003 myPrsCopy->SetMagnificationIncrement( mySizeBox->getIncrement() );
1005 VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Copy(myPrsCopy, thePrs);
1007 //Set created Gauss points presentation selected,
1008 //Issue 0019874(EDF 746 VISU: Picking alphanumeric Gauss)
1010 SALOME_ListIO aListIO;
1011 // LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
1012 Handle(SALOME_InteractiveObject) anIO = thePrs->GetIO();
1013 if(anIO && anIO->hasEntry()) {
1014 aListIO.Append(anIO);
1015 VISU::UpdateObjBrowser(myModule,true);
1016 //IPAL20836 aSelectionMgr->setSelectedObjects(aListIO);
1019 myInputPane->SetRestoreInitialSelection(true);
1024 void VisuGUI_GaussPointsDlg::onToggleDefShape( bool on )
1026 if( on )//myDefShapeButton->isChecked() )
1028 myDefShapeBox->show();
1029 mySizeBox->setType( VVTK_SizeBox::Results );
1032 myDefShapeBox->hide();
1035 void VisuGUI_GaussPointsDlg::accept()
1037 if( (bool)myPrsCopy && myPrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere )
1039 int aNumberOfFaces = myPrimitiveBox->getFaceNumber();
1040 int aNumberOfPoints = myPrsCopy->GetSpecificPL()->GetInput()->GetNumberOfCells();
1042 if( aNumberOfFaces * aNumberOfPoints > myPrimitiveBox->getFaceLimit() )
1044 QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
1045 aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
1046 aWarning.append( "Can you please confirm that you want to continue anyway?" );
1047 if( SUIT_MessageBox::warning( this, tr( "Warning" ), aWarning, tr( "&OK" ), tr( "&Cancel" ) ) == 1 )
1052 float aMemory = 50.0 * 1024.0 * (float)aNumberOfFaces * (float)aNumberOfPoints;
1054 cout << aNumberOfFaces << endl;
1055 cout << aNumberOfPoints << endl;
1056 cout << aMemory << endl;
1058 vtkSphereSource* aSphere = vtkSphereSource::New();
1059 aSphere->SetThetaResolution( myPrimitiveBox->getResolution() );
1060 aSphere->SetPhiResolution( myPrimitiveBox->getResolution() );
1061 aSphere->GetOutput()->Update();
1062 aSphere->GetOutput()->GetActualMemorySize();
1064 aMemory = aSphere->GetOutput()->GetActualMemorySize() * 1024.0 * (float)aNumberOfPoints;
1066 if( VISU_PipeLine::CheckAvailableMemory( aMemory ) == 0 )
1068 SUIT_MessageBox::error1( this, "caption", "text", "ok" );
1074 //if( myScalarPane->check() )
1075 VisuGUI_Prs3dDlg::accept();
1078 QString VisuGUI_GaussPointsDlg::GetContextHelpFilePath()
1080 return "types_of_gauss_points_presentations_page.html";