1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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
24 // File : VisuGUI_GaussPointsDlg.cxx
25 // Author : Oleg UVAROV
28 #include "VisuGUI_GaussPointsDlg.h"
30 #include "VISUConfig.hh"
32 #include "VisuGUI_Tools.h"
34 #include "VISU_GaussPoints_i.hh"
35 #include "VISU_GaussPointsPL.hxx"
36 #include "VISU_OpenGLPointSpriteMapper.hxx"
37 #include "VISU_Convertor.hxx"
39 #include "VVTK_PrimitiveBox.h"
40 #include "VVTK_SizeBox.h"
42 #include "LightApp_Application.h"
43 #include "SalomeApp_Module.h"
44 #include "SUIT_Desktop.h"
45 #include "SUIT_ResourceMgr.h"
46 #include "SUIT_Session.h"
47 #include "SUIT_MessageBox.h"
48 #include "SVTK_FontWidget.h"
51 #include <qtabwidget.h>
52 #include <qbuttongroup.h>
53 #include <qradiobutton.h>
54 #include <qfiledialog.h>
55 #include <qvalidator.h>
56 #include <qcolordialog.h>
58 #include <vtkPolyData.h>
59 #include <vtkDataSet.h>
60 #include <vtkSphereSource.h>
64 VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent, bool SetPref):
67 myVerX = 0.01; myVerY = 0.10; myVerW = 0.10; myVerH = 0.80;
68 myHorX = 0.20; myHorY = 0.01; myHorW = 0.60; myHorH = 0.12;
69 Imin = 0.0; Imax = 0.0;
75 // Active bar ========================================================
76 QGroupBox* ActiveBarGroup = new QGroupBox (tr("ACTIVE_BAR_GRP"), this, "ActiveBarGroup");
77 ActiveBarGroup->setColumnLayout(0, Qt::Vertical );
78 ActiveBarGroup->layout()->setSpacing( 0 );
79 ActiveBarGroup->layout()->setMargin( 0 );
80 QGridLayout* ActiveBarGroupLayout = new QGridLayout( ActiveBarGroup->layout() );
81 ActiveBarGroupLayout->setAlignment( Qt::AlignTop );
82 ActiveBarGroupLayout->setSpacing( 6 );
83 ActiveBarGroupLayout->setMargin( 11 );
85 QButtonGroup* BarTypeGroup = new QButtonGroup( 2, Qt::Vertical, ActiveBarGroup, "BarTypeGroup" );
86 BarTypeGroup->setRadioButtonExclusive( true );
87 BarTypeGroup->setFrameStyle( QFrame::NoFrame );
88 BarTypeGroup->layout()->setMargin( 0 );
90 myRBLocal = new QRadioButton( tr( "LOCAL" ), BarTypeGroup );
91 myRBGlobal = new QRadioButton( tr( "GLOBAL" ), BarTypeGroup );
93 myCBDisplayed = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup );
95 ActiveBarGroupLayout->addMultiCellWidget( BarTypeGroup, 0, 1, 0, 0 );
96 ActiveBarGroupLayout->addWidget( myCBDisplayed, 1, 1 );
98 // Range ============================================================
99 RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup");
100 RangeGroup->setColumnLayout(0, Qt::Vertical );
101 RangeGroup->layout()->setSpacing( 0 );
102 RangeGroup->layout()->setMargin( 0 );
103 QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
104 RangeGroupLayout->setAlignment( Qt::AlignTop );
105 RangeGroupLayout->setSpacing( 6 );
106 RangeGroupLayout->setMargin( 11 );
108 myModeLbl = new QLabel("Scalar Mode", RangeGroup);
110 myModeCombo = new QComboBox(RangeGroup);
112 RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
113 RangeGroupLayout->addWidget( myModeCombo, 0, 1 );
115 //TopLayout->addWidget( RangeGroup );
117 // Colors and Labels ========================================================
118 QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup");
119 ColLabGroup->setColumnLayout(0, Qt::Vertical );
120 ColLabGroup->layout()->setSpacing( 0 );
121 ColLabGroup->layout()->setMargin( 0 );
122 QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
123 ColLabGroupLayout->setAlignment( Qt::AlignTop );
124 ColLabGroupLayout->setSpacing( 6 );
125 ColLabGroupLayout->setMargin( 11 );
127 QButtonGroup* TypeGroup = new QButtonGroup( 2, Qt::Vertical, ColLabGroup, "TypeGroup" );
128 TypeGroup->setRadioButtonExclusive( true );
129 TypeGroup->setFrameStyle( QFrame::NoFrame );
130 TypeGroup->layout()->setMargin( 0 );
132 BicolorButton = new QRadioButton( tr( "BICOLOR" ), TypeGroup );
133 RainbowButton = new QRadioButton( tr( "RAINBOW" ), TypeGroup );
135 ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel");
136 ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
137 ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
138 ColorSpin->setMinimumWidth( 70 );
139 ColorSpin->setValue( 64 );
141 LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel");
142 LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
143 LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
144 LabelSpin->setMinimumWidth( 70 );
145 LabelSpin->setValue( 5 );
147 ColLabGroupLayout->addMultiCellWidget( TypeGroup, 0, 1, 0, 0);
148 ColLabGroupLayout->addWidget( ColorLabel, 1, 1);
149 ColLabGroupLayout->addWidget( ColorSpin, 1, 2);
150 ColLabGroupLayout->addWidget( LabelLabel, 1, 3);
151 ColLabGroupLayout->addWidget( LabelSpin, 1, 4);
153 //TopLayout->addWidget( ColLabGroup );
155 // Orientation ==========================================================
156 QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup");
157 OrientGroup->setColumnLayout(0, Qt::Vertical );
158 OrientGroup->layout()->setSpacing( 0 );
159 OrientGroup->layout()->setMargin( 0 );
160 QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
161 OrientGroupLayout->setAlignment( Qt::AlignTop );
162 OrientGroupLayout->setSpacing( 6 );
163 OrientGroupLayout->setMargin( 11 );
165 RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert");
166 RBvert->setChecked( true );
167 RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori");
168 OrientGroupLayout->addWidget( RBvert, 0, 0 );
169 OrientGroupLayout->addWidget( RBhori, 0, 1 );
171 // TopLayout->addWidget( OrientGroup );
173 // Origin ===============================================================
174 QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup");
175 OriginGroup->setColumnLayout(0, Qt::Vertical );
176 OriginGroup->layout()->setSpacing( 0 );
177 OriginGroup->layout()->setMargin( 0 );
178 QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
179 OriginGroupLayout->setAlignment( Qt::AlignTop );
180 OriginGroupLayout->setSpacing( 6 );
181 OriginGroupLayout->setMargin( 11 );
183 QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel");
184 XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
185 XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
186 XSpin->setMinimumWidth( 70 );
187 XSpin->setValue( 0.01 );
189 QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel");
190 YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
191 YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
192 YSpin->setMinimumWidth( 70 );
193 YSpin->setValue( 0.01 );
195 OriginGroupLayout->addWidget( XLabel, 0, 0);
196 OriginGroupLayout->addWidget( XSpin, 0, 1);
197 OriginGroupLayout->addWidget( YLabel, 0, 2);
198 OriginGroupLayout->addWidget( YSpin, 0, 3);
200 //TopLayout->addWidget( OriginGroup );
202 // Dimensions =========================================================
203 QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup");
204 DimGroup->setColumnLayout(0, Qt::Vertical );
205 DimGroup->layout()->setSpacing( 0 );
206 DimGroup->layout()->setMargin( 0 );
207 QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
208 DimGroupLayout->setAlignment( Qt::AlignTop );
209 DimGroupLayout->setSpacing( 6 );
210 DimGroupLayout->setMargin( 11 );
212 QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel");
213 WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
214 WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
215 WidthSpin->setMinimumWidth( 70 );
216 WidthSpin->setValue( 0.1 );
218 QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel");
219 HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
220 HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
221 HeightSpin->setMinimumWidth( 70 );
222 HeightSpin->setValue( 0.8 );
224 QLabel* SpacingLabel = new QLabel (tr("LBL_SPACING"), DimGroup, "SpacingLabel");
225 SpacingSpin = new QtxDblSpinBox( 0.0, 1.0, 0.01, DimGroup );
226 SpacingSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
227 SpacingSpin->setMinimumWidth( 70 );
228 SpacingSpin->setValue( 0.01 );
230 DimGroupLayout->addWidget( WidthLabel, 0, 0);
231 DimGroupLayout->addWidget( WidthSpin, 0, 1);
232 DimGroupLayout->addWidget( HeightLabel, 0, 2);
233 DimGroupLayout->addWidget( HeightSpin, 0, 3);
234 DimGroupLayout->addWidget( SpacingLabel, 0, 4);
235 DimGroupLayout->addWidget( SpacingSpin, 0, 5);
237 //TopLayout->addWidget( DimGroup );
239 // Save check box ===========================================================
240 QHBox* aSaveBox = new QHBox(this);
242 CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave");
243 //TopLayout->addWidget(CBSave);
248 myTextBtn = new QPushButton("Text properties...", aSaveBox);
249 myTextDlg = new VisuGUI_TextPrefDlg(this);
250 myTextDlg->setTitleVisible(!SetPref);
252 // signals and slots connections ===========================================
253 connect( myRBLocal, SIGNAL( toggled( bool ) ), myCBDisplayed, SLOT( setEnabled( bool ) ) );
254 connect( myRBGlobal, SIGNAL( clicked() ), this, SLOT( onSetDisplayGlobal() ) );
255 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorLabel, SLOT( setEnabled( bool ) ) );
256 connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorSpin, SLOT( setEnabled( bool ) ) );
257 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelLabel, SLOT( setEnabled( bool ) ) );
258 connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelSpin, SLOT( setEnabled( bool ) ) );
259 connect( OrientGroup, SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
260 connect( XSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
261 connect( YSpin, SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
262 connect( myTextBtn, SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
265 myIsStoreTextProp = false;
268 void VisuGUI_GaussScalarBarPane::onSetDisplayGlobal()
270 myCBDisplayed->setChecked( true );
275 * Initialise dialog box from presentation object
277 void VisuGUI_GaussScalarBarPane::initFromPrsObject(VISU::GaussPoints_i* thePrs) {
278 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
279 setPosAndSize( thePrs->GetPosX(),
283 thePrs->GetBarOrientation());
285 SpacingSpin->setValue(thePrs->GetSpacing());
287 bool activeLocal = thePrs->GetIsActiveLocalScalarBar();
288 myRBLocal->setChecked( activeLocal );
290 myRBGlobal->setChecked( !activeLocal );
291 myRBGlobal->setEnabled( thePrs->IsGlobalRangeDefined() );
292 if( !thePrs->IsGlobalRangeDefined() )
293 myRBLocal->setChecked( true );
295 myCBDisplayed->setEnabled( activeLocal );
296 myCBDisplayed->setChecked( thePrs->GetIsDispGlobalScalarBar() );
298 bool bicolor = thePrs->GetGaussPointsPL()->GetBicolor();
299 BicolorButton->setChecked( bicolor );
300 RainbowButton->setChecked( !bicolor );
301 ColorLabel->setEnabled( !bicolor );
302 ColorSpin->setEnabled( !bicolor );
303 LabelLabel->setEnabled( !bicolor );
304 LabelSpin->setEnabled( !bicolor );
306 setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
308 // Update myModeCombo
309 int aNbComp = thePrs->GetField()->myNbComp;
310 bool isScalarMode = (aNbComp > 1);
311 myModeCombo->clear();
312 myModeCombo->insertItem("<Modulus>");
313 const VISU::PField& aField = thePrs->GetField();
314 const VISU::TNames& aCompNames = aField->myCompNames;
315 const VISU::TNames& aUnitNames = aField->myUnitNames;
316 for(int i = 0; i < aNbComp; i++){
317 QString aComponent = QString(aCompNames[i].c_str()).simplifyWhiteSpace();
318 if(aComponent.isNull() || aComponent == "")
319 aComponent = "Component " + QString::number(i+1);
321 aComponent = "[" + QString::number(i+1) + "] " + aComponent;
323 QString anUnit = QString(aUnitNames[i].c_str()).simplifyWhiteSpace();
324 if(anUnit.isNull() || anUnit == "")
327 aComponent = aComponent + ", " + anUnit;
329 myModeCombo->insertItem(aComponent);
332 myModeCombo->setCurrentItem(thePrs->GetScalarMode());
334 myModeCombo->setCurrentItem(1);
337 myModeLbl->setEnabled(isScalarMode);
338 myModeCombo->setEnabled(isScalarMode);
341 myTextDlg->setTitleText(QString(thePrs->GetTitle()));
343 vtkFloatingPointType R, G, B;
344 thePrs->GetTitleColor(&R, &G, &B);
346 myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
347 thePrs->GetTitFontType(),
348 thePrs->IsBoldTitle(),
349 thePrs->IsItalicTitle(),
350 thePrs->IsShadowTitle());
353 thePrs->GetLabelColor(&R, &G, &B);
355 myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
356 thePrs->GetLblFontType(),
357 thePrs->IsBoldLabel(),
358 thePrs->IsItalicLabel(),
359 thePrs->IsShadowLabel());
363 * Store values to presentation object
365 int VisuGUI_GaussScalarBarPane::storeToPrsObject(VISU::GaussPoints_i* thePrs) {
366 thePrs->SetScalarMode(myModeCombo->currentItem());
367 thePrs->SetPosition(XSpin->value(), YSpin->value());
368 thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
369 thePrs->SetSpacing(SpacingSpin->value());
370 thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
371 thePrs->SetIsActiveLocalScalarBar(myRBLocal->isChecked());
372 thePrs->SetIsDispGlobalScalarBar(myCBDisplayed->isChecked());
373 thePrs->SetNbColors(ColorSpin->value());
374 thePrs->SetLabels(LabelSpin->value());
376 thePrs->GetGaussPointsPL()->SetBicolor(BicolorButton->isChecked());
378 //if (isToSave()) storeToResources();
380 if (myIsStoreTextProp) {
382 thePrs->SetTitle(myTextDlg->getTitleText().latin1());
384 QColor aTitColor (255, 255, 255);
385 int aTitleFontFamily = VTK_ARIAL;
386 bool isTitleBold = false;
387 bool isTitleItalic = false;
388 bool isTitleShadow = false;
390 myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
391 isTitleBold, isTitleItalic, isTitleShadow);
393 thePrs->SetBoldTitle(isTitleBold);
394 thePrs->SetItalicTitle(isTitleItalic);
395 thePrs->SetShadowTitle(isTitleShadow);
396 thePrs->SetTitFontType(aTitleFontFamily);
397 thePrs->SetTitleColor(aTitColor.red()/255.,
398 aTitColor.green()/255.,
399 aTitColor.blue()/255.);
402 QColor aLblColor (255, 255, 255);
403 int aLabelFontFamily = VTK_ARIAL;
404 bool isLabelBold = false;
405 bool isLabelItalic = false;
406 bool isLabelShadow = false;
408 myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
409 isLabelBold, isLabelItalic, isLabelShadow);
411 thePrs->SetBoldLabel(isLabelBold);
412 thePrs->SetItalicLabel(isLabelItalic);
413 thePrs->SetShadowLabel(isLabelShadow);
414 thePrs->SetLblFontType(aLabelFontFamily);
415 thePrs->SetLabelColor(aLblColor.red()/255.,
416 aLblColor.green()/255.,
417 aLblColor.blue()/255.);
424 Called when orientation is changed
426 void VisuGUI_GaussScalarBarPane::changeDefaults( int )
428 if ( RBvert->isChecked() ) {
429 XSpin->setValue( myVerX );
430 YSpin->setValue( myVerY );
431 WidthSpin->setValue( myVerW );
432 HeightSpin->setValue( myVerH );
435 XSpin->setValue( myHorX );
436 YSpin->setValue( myHorY );
437 WidthSpin->setValue( myHorW );
438 HeightSpin->setValue( myHorH );
443 Called when X,Y position is changed
445 void VisuGUI_GaussScalarBarPane::XYChanged( double )
447 QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
448 if ( snd == XSpin ) {
449 WidthSpin->setMaxValue( 1.0 - XSpin->value() );
451 if ( snd == YSpin ) {
452 HeightSpin->setMaxValue( 1.0 - YSpin->value() );
457 Sets size and position
459 void VisuGUI_GaussScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
466 RBvert->setChecked( true );
473 RBhori->setChecked( true );
479 Sets colors and labels number
481 void VisuGUI_GaussScalarBarPane::setScalarBarData( int colors, int labels )
483 ColorSpin->setValue( colors );
484 LabelSpin->setValue( labels );
490 int VisuGUI_GaussScalarBarPane::getOrientation()
492 if (RBvert->isChecked() )
499 void VisuGUI_GaussScalarBarPane::onTextPref()
501 myIsStoreTextProp = myTextDlg->exec();
508 VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule, bool SetPref):
509 QDialog(VISU::GetDesktop(theModule),
510 "VisuGUI_GaussPointsDlg", true,
511 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
514 setName("VisuGUI_ScalarBarDlg");
515 setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
516 setSizeGripEnabled(TRUE);
518 QVBoxLayout* TopLayout = new QVBoxLayout(this);
519 TopLayout->setSpacing(6);
520 TopLayout->setMargin(11);
524 QButtonGroup* PrsGroup = new QButtonGroup( 3, Qt::Horizontal, tr( "PRS_TITLE" ), this, "PrimitiveTypeGroup" );
525 PrsGroup->setRadioButtonExclusive( true );
526 PrsGroup->layout()->setMargin( 11 );
527 PrsGroup->layout()->setSpacing(6);
529 myResultsButton = new QRadioButton( tr( "RESULTS" ), PrsGroup );
530 myGeometryButton = new QRadioButton( tr( "GEOMETRY" ), PrsGroup );
531 myDefShapeButton = new QRadioButton( tr( "DEFORMED_SHAPE" ), PrsGroup );
533 QTabWidget* aTabBox = new QTabWidget (this);
536 QVBox* aBox = new QVBox (this);
541 myPrimitiveBox = new VVTK_PrimitiveBox( aBox );
544 mySizeBox = new VVTK_SizeBox( aBox );
547 myDefShapeBox = new QGroupBox( tr( "DEFORMED_SHAPE_TITLE" ), aBox );
548 myDefShapeBox->setColumnLayout(0, Qt::Vertical );
549 myDefShapeBox->layout()->setSpacing( 0 );
550 myDefShapeBox->layout()->setMargin( 0 );
552 QGridLayout* aDefShapeLayout = new QGridLayout( myDefShapeBox->layout() );
553 aDefShapeLayout->setAlignment(Qt::AlignTop);
554 aDefShapeLayout->setSpacing(6);
555 aDefShapeLayout->setMargin(11);
557 QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox );
558 myScaleSpinBox = new QtxDblSpinBox( 0.0, 10.0, 0.1, myDefShapeBox );
560 aDefShapeLayout->addWidget( aScaleLabel, 0, 0 );
561 aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 );
564 myScalarPane = new VisuGUI_GaussScalarBarPane(this, SetPref);
565 myScalarPane->setMargin(5);
568 connect( myResultsButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleResults() ) );
569 connect( myResultsButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
570 connect( myGeometryButton, SIGNAL( clicked() ), mySizeBox, SLOT( onToggleGeometry() ) );
571 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), this, SLOT( onToggleDefShape( bool ) ) );
572 connect( myDefShapeButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
574 aTabBox->addTab(aBox, tr("GAUSS_POINTS_TAB"));
575 aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
577 // Common buttons ===========================================================
578 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
579 GroupButtons->setColumnLayout(0, Qt::Vertical );
580 GroupButtons->layout()->setSpacing( 0 );
581 GroupButtons->layout()->setMargin( 0 );
582 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
583 GroupButtonsLayout->setAlignment( Qt::AlignTop );
584 GroupButtonsLayout->setSpacing( 6 );
585 GroupButtonsLayout->setMargin( 11 );
587 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
588 buttonOk->setAutoDefault( TRUE );
589 buttonOk->setDefault( TRUE );
590 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
591 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
593 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
594 buttonCancel->setAutoDefault( TRUE );
595 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
597 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
598 buttonHelp->setAutoDefault( TRUE );
599 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
601 TopLayout->addWidget( PrsGroup );
602 TopLayout->addWidget( aTabBox );
603 TopLayout->addWidget( GroupButtons );
605 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
606 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
607 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
610 void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::GaussPoints_i* thePrs )
612 bool isDeformed = thePrs->GetIsDeformed();
613 myScaleSpinBox->setValue( thePrs->GetScaleFactor() );
614 myDefShapeButton->setChecked( isDeformed );
615 myDefShapeButton->setEnabled( thePrs->GetField()->myNbComp > 1 );
616 onToggleDefShape( isDeformed );
618 bool isResults = thePrs->GetIsColored();
619 myResultsButton->setChecked( isResults && !isDeformed );
620 myGeometryButton->setChecked( !isResults && !isDeformed );
622 myPrimitiveBox->setPrimitiveType( thePrs->GetPrimitiveType() );
623 myPrimitiveBox->setClampMaximum( thePrs->GetMaximumSupportedSize() );
624 myPrimitiveBox->setClamp( thePrs->GetClamp() );
625 myPrimitiveBox->setMainTexture( thePrs->GetMainTexture() );
626 myPrimitiveBox->setAlphaTexture( thePrs->GetAlphaTexture() );
627 myPrimitiveBox->setAlphaThreshold( thePrs->GetAlphaThreshold() );
628 myPrimitiveBox->setResolution( thePrs->GetResolution() );
629 myPrimitiveBox->setFaceLimit( thePrs->GetFaceLimit() );
631 mySizeBox->setType( isResults || isDeformed ? VVTK_SizeBox::Results : VVTK_SizeBox::Geometry );
632 mySizeBox->setGeomSize( thePrs->GetGeomSize() );
633 mySizeBox->setMinSize( thePrs->GetMinSize() );
634 mySizeBox->setMaxSize( thePrs->GetMaxSize() );
635 mySizeBox->setMagnification( thePrs->GetMagnification() );
636 mySizeBox->setIncrement( thePrs->GetMagnificationIncrement() );
637 mySizeBox->setColor( thePrs->GetColor() );
639 myScalarPane->initFromPrsObject(thePrs);
644 int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::GaussPoints_i* thePrs )
646 thePrs->SetIsDeformed( myDefShapeButton->isChecked() );
647 thePrs->SetScaleFactor( myScaleSpinBox->value() );
649 thePrs->SetPrimitiveType( myPrimitiveBox->getPrimitiveType() );
651 thePrs->SetClamp( myPrimitiveBox->getClamp() );
653 QString aMainTexture = myPrimitiveBox->getMainTexture();
654 QString anAlphaTexture = myPrimitiveBox->getAlphaTexture();
656 aMainTexture = aMainTexture.isNull() ? thePrs->GetMainTexture() : aMainTexture;
657 anAlphaTexture = anAlphaTexture.isNull() ? thePrs->GetAlphaTexture() : anAlphaTexture;
659 thePrs->SetTextures( aMainTexture, anAlphaTexture );
661 thePrs->SetAlphaThreshold( myPrimitiveBox->getAlphaThreshold() );
663 thePrs->SetResolution( myPrimitiveBox->getResolution() );
664 thePrs->SetFaceLimit( myPrimitiveBox->getFaceLimit() );
666 bool isColored = !myGeometryButton->isChecked();
669 thePrs->SetIsColored( true );
670 thePrs->SetMinSize( mySizeBox->getMinSize() );
671 thePrs->SetMaxSize( mySizeBox->getMaxSize() );
675 thePrs->SetIsColored( false );
676 thePrs->SetColor( mySizeBox->getColor() );
677 thePrs->SetGeomSize( mySizeBox->getGeomSize() );
680 thePrs->SetMagnification( mySizeBox->getMagnification() );
681 thePrs->SetMagnificationIncrement( mySizeBox->getIncrement() );
683 return myScalarPane->storeToPrsObject(thePrs);
686 void VisuGUI_GaussPointsDlg::onToggleDefShape( bool on )
688 if( on )//myDefShapeButton->isChecked() )
690 myDefShapeBox->show();
691 mySizeBox->setType( VVTK_SizeBox::Results );
694 myDefShapeBox->hide();
697 void VisuGUI_GaussPointsDlg::accept()
699 if( myPrs && myPrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere )
701 int aNumberOfFaces = myPrimitiveBox->getFaceNumber();
702 int aNumberOfPoints = ( (vtkPolyData*)myPrs->GetGaussPointsPL()->GetInput() )->GetNumberOfCells();
704 if( aNumberOfFaces * aNumberOfPoints > myPrimitiveBox->getFaceLimit() )
706 QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
707 aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
708 aWarning.append( "Can you please confirm that you want to continue anyway?" );
709 if( SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning, tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 1 )
714 float aMemory = 50.0 * 1024.0 * (float)aNumberOfFaces * (float)aNumberOfPoints;
716 cout << aNumberOfFaces << endl;
717 cout << aNumberOfPoints << endl;
718 cout << aMemory << endl;
720 vtkSphereSource* aSphere = vtkSphereSource::New();
721 aSphere->SetThetaResolution( myPrimitiveBox->getResolution() );
722 aSphere->SetPhiResolution( myPrimitiveBox->getResolution() );
723 aSphere->GetOutput()->Update();
724 aSphere->GetOutput()->GetActualMemorySize();
726 aMemory = aSphere->GetOutput()->GetActualMemorySize() * 1024.0 * (float)aNumberOfPoints;
728 if( VISU_PipeLine::CheckAvailableMemory( aMemory ) == 0 )
730 SUIT_MessageBox::error1( this, "caption", "text", "ok" );
736 //if( myScalarPane->check() )
740 void VisuGUI_GaussPointsDlg::onHelp()
742 QString aHelpFileName = "types_of_gauss_points_presentations.htm";
743 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
745 app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
747 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
748 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
749 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
750 QObject::tr("BUT_OK"));