]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_GaussPointsDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_GaussPointsDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VisuGUI_GaussPointsDlg.cxx
25 //  Author : Oleg UVAROV
26 //  Module : VISU
27
28 #include "VisuGUI_GaussPointsDlg.h"
29
30 #include "VISUConfig.hh"
31
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_InputPane.h"
34
35 #include "VISU_ColoredPrs3dFactory.hh"
36 #include "VISU_GaussPoints_i.hh"
37 #include "VISU_GaussPointsPL.hxx"
38 #include "VISU_OpenGLPointSpriteMapper.hxx"
39 #include "VISU_Convertor.hxx"
40
41 #include "VVTK_PrimitiveBox.h"
42 #include "VVTK_SizeBox.h"
43
44 #include "LightApp_Application.h"
45 #include "SalomeApp_Module.h"
46 #include "SUIT_Desktop.h"
47 #include "SUIT_ResourceMgr.h"
48 #include "SUIT_Session.h"
49 #include "SUIT_MessageBox.h"
50 #include "SVTK_FontWidget.h"
51
52 #include "QtxDblSpinBox.h"
53
54 #include <qlayout.h>
55 #include <qtabwidget.h>
56 #include <qbuttongroup.h>
57 #include <qradiobutton.h>
58 #include <qfiledialog.h>
59 #include <qvalidator.h>
60 #include <qcolordialog.h>
61 #include <qgroupbox.h>
62 #include <qcheckbox.h>
63 #include <qlabel.h>
64 #include <qpushbutton.h>
65 #include <qlineedit.h>
66 #include <qspinbox.h>
67 #include <qcombobox.h>
68 #include <qtoolbutton.h>
69 #include <qtabwidget.h>
70
71 #include <vtkPolyData.h>
72 #include <vtkDataSet.h>
73 #include <vtkSphereSource.h>
74
75 using namespace std;
76
77 VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent):
78   QVBox(parent)
79 {
80   myVerX = 0.01;  myVerY = 0.10;  myVerW = 0.10;  myVerH = 0.80;
81   myHorX = 0.20;  myHorY = 0.01;  myHorW = 0.60;  myHorH = 0.12;
82   myVerTW = myVerTH = myVerLW = myVerLH = myVerBW = myVerBH = 0;
83   myHorTW = myHorTH = myHorLW = myHorLH = myHorBW = myHorBH = 0;
84   Imin = 0.0; Imax = 0.0;
85   myRangeMode = -1;
86
87   setSpacing(6);
88   //setMargin(11);
89
90   // Active bar ========================================================
91   QGroupBox* ActiveBarGroup = new QGroupBox (tr("ACTIVE_BAR_GRP"), this, "ActiveBarGroup");
92   ActiveBarGroup->setColumnLayout(0, Qt::Vertical );
93   ActiveBarGroup->layout()->setSpacing( 0 );
94   ActiveBarGroup->layout()->setMargin( 0 );
95   QGridLayout* ActiveBarGroupLayout = new QGridLayout( ActiveBarGroup->layout() );
96   ActiveBarGroupLayout->setAlignment( Qt::AlignTop );
97   ActiveBarGroupLayout->setSpacing( 6 );
98   ActiveBarGroupLayout->setMargin( 11 );
99
100   QButtonGroup* BarTypeGroup = new QButtonGroup( 2, Qt::Vertical, ActiveBarGroup, "BarTypeGroup" );
101   BarTypeGroup->setRadioButtonExclusive( true );
102   BarTypeGroup->setFrameStyle( QFrame::NoFrame );
103   BarTypeGroup->layout()->setMargin( 0 );
104
105   myRBLocal = new QRadioButton( tr( "LOCAL" ), BarTypeGroup );
106   myRBGlobal = new QRadioButton( tr( "GLOBAL" ), BarTypeGroup );
107
108   myCBDisplayed = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup );
109
110   ActiveBarGroupLayout->addMultiCellWidget( BarTypeGroup, 0, 1, 0, 0 );
111   ActiveBarGroupLayout->addWidget( myCBDisplayed, 1, 1 );
112
113   // Range ============================================================
114   RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup");
115   RangeGroup->setColumnLayout(0, Qt::Vertical );
116   RangeGroup->layout()->setSpacing( 0 );
117   RangeGroup->layout()->setMargin( 0 );
118   QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
119   RangeGroupLayout->setAlignment( Qt::AlignTop );
120   RangeGroupLayout->setSpacing( 6 );
121   RangeGroupLayout->setMargin( 11 );
122
123   myModeLbl = new QLabel("Scalar Mode", RangeGroup);
124
125   myModeCombo = new QComboBox(RangeGroup);
126
127   RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
128   RangeGroupLayout->addWidget( myModeCombo, 0, 1 );
129
130   RBFieldRange = new QRadioButton (tr("FIELD_RANGE_BTN"), RangeGroup, "RBFieldRange");
131   RBImposedRange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), RangeGroup, "RBImposedRange");
132   RBFieldRange->setChecked( true );
133
134   MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
135   MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
136   MinEdit->setMinimumWidth( 70 );
137   MinEdit->setValidator( new QDoubleValidator(this) );
138   MinEdit->setText( "0.0" );
139   QLabel* MinLabel = new QLabel (tr("LBL_MIN"), RangeGroup, "MinLabel");
140   MinLabel->setBuddy(MinEdit);
141
142   MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
143   MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
144   MaxEdit->setMinimumWidth( 70 );
145   MaxEdit->setValidator( new QDoubleValidator(this) );
146   MaxEdit->setText( "0.0" );
147   QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), RangeGroup, "MaxLabel");
148   MaxLabel->setBuddy(MaxEdit);
149
150   RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
151   RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
152   RangeGroupLayout->addMultiCellWidget( RBFieldRange, 1, 1, 0, 1);
153   RangeGroupLayout->addMultiCellWidget( RBImposedRange, 1, 1, 2, 3);
154   RangeGroupLayout->addWidget( MinLabel, 2, 0 );
155   RangeGroupLayout->addWidget( MinEdit,  2, 1 );
156   RangeGroupLayout->addWidget( MaxLabel, 2, 2 );
157   RangeGroupLayout->addWidget( MaxEdit,  2, 3 );
158
159   // Colors and Labels ========================================================
160   QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup");
161   ColLabGroup->setColumnLayout(0, Qt::Vertical );
162   ColLabGroup->layout()->setSpacing( 0 );
163   ColLabGroup->layout()->setMargin( 0 );
164   QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
165   ColLabGroupLayout->setAlignment( Qt::AlignTop );
166   ColLabGroupLayout->setSpacing( 6 );
167   ColLabGroupLayout->setMargin( 11 );
168
169   QButtonGroup* TypeGroup = new QButtonGroup( 2, Qt::Vertical, ColLabGroup, "TypeGroup" );
170   TypeGroup->setRadioButtonExclusive( true );
171   TypeGroup->setFrameStyle( QFrame::NoFrame );
172   TypeGroup->layout()->setMargin( 0 );
173
174   BicolorButton = new QRadioButton( tr( "BICOLOR" ), TypeGroup );
175   RainbowButton = new QRadioButton( tr( "RAINBOW" ), TypeGroup );
176
177   ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel");
178   ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
179   ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180   ColorSpin->setMinimumWidth( 70 );
181   ColorSpin->setValue( 64 );
182
183   LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel");
184   LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
185   LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
186   LabelSpin->setMinimumWidth( 70 );
187   LabelSpin->setValue( 5 );
188
189   ColLabGroupLayout->addMultiCellWidget( TypeGroup, 0, 1, 0, 0);
190   ColLabGroupLayout->addWidget( ColorLabel, 1, 1);
191   ColLabGroupLayout->addWidget( ColorSpin,  1, 2);
192   ColLabGroupLayout->addWidget( LabelLabel, 1, 3);
193   ColLabGroupLayout->addWidget( LabelSpin,  1, 4);
194
195   //TopLayout->addWidget( ColLabGroup );
196
197   // Orientation ==========================================================
198   QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup");
199   OrientGroup->setColumnLayout(0, Qt::Vertical );
200   OrientGroup->layout()->setSpacing( 0 );
201   OrientGroup->layout()->setMargin( 0 );
202   QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
203   OrientGroupLayout->setAlignment( Qt::AlignTop );
204   OrientGroupLayout->setSpacing( 6 );
205   OrientGroupLayout->setMargin( 11 );
206
207   RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert");
208   RBvert->setChecked( true );
209   RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori");
210   OrientGroupLayout->addWidget( RBvert, 0, 0 );
211   OrientGroupLayout->addWidget( RBhori, 0, 1 );
212
213   //  TopLayout->addWidget( OrientGroup );
214
215   // Origin ===============================================================
216   QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup");
217   OriginGroup->setColumnLayout(0, Qt::Vertical );
218   OriginGroup->layout()->setSpacing( 0 );
219   OriginGroup->layout()->setMargin( 0 );
220   QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
221   OriginGroupLayout->setAlignment( Qt::AlignTop );
222   OriginGroupLayout->setSpacing( 6 );
223   OriginGroupLayout->setMargin( 11 );
224
225   QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel");
226   XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
227   XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
228   XSpin->setMinimumWidth( 70 );
229   XSpin->setValue( 0.01 );
230
231   QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel");
232   YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
233   YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
234   YSpin->setMinimumWidth( 70 );
235   YSpin->setValue( 0.01 );
236
237   OriginGroupLayout->addWidget( XLabel, 0, 0);
238   OriginGroupLayout->addWidget( XSpin,  0, 1);
239   OriginGroupLayout->addWidget( YLabel, 0, 2);
240   OriginGroupLayout->addWidget( YSpin,  0, 3);
241
242   //TopLayout->addWidget( OriginGroup );
243
244   // Dimensions =========================================================
245   QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup");
246   DimGroup->setColumnLayout(0, Qt::Vertical );
247   DimGroup->layout()->setSpacing( 0 );
248   DimGroup->layout()->setMargin( 0 );
249   QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
250   DimGroupLayout->setAlignment( Qt::AlignTop );
251   DimGroupLayout->setSpacing( 6 );
252   DimGroupLayout->setMargin( 11 );
253
254   QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel");
255   WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
256   WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
257   WidthSpin->setMinimumWidth( 70 );
258   WidthSpin->setValue( 0.1 );
259
260   QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel");
261   HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
262   HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
263   HeightSpin->setMinimumWidth( 70 );
264   HeightSpin->setValue( 0.8 );
265
266   QLabel* SpacingLabel = new QLabel (tr("LBL_SPACING"), DimGroup, "SpacingLabel");
267   SpacingSpin = new QtxDblSpinBox( 0.0, 1.0, 0.01, DimGroup );
268   SpacingSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
269   SpacingSpin->setMinimumWidth( 70 );
270   SpacingSpin->setValue( 0.01 );
271
272   DimGroupLayout->addWidget( WidthLabel, 0, 0);
273   DimGroupLayout->addWidget( WidthSpin,  0, 1);
274   DimGroupLayout->addWidget( HeightLabel, 0, 2);
275   DimGroupLayout->addWidget( HeightSpin,  0, 3);
276   DimGroupLayout->addWidget( SpacingLabel, 0, 4);
277   DimGroupLayout->addWidget( SpacingSpin,  0, 5);
278
279   //TopLayout->addWidget( DimGroup );
280
281   QHBox* aSaveBox = new QHBox(this);
282   myTextBtn = new QPushButton("Text properties...", aSaveBox);
283   myBarBtn = new QPushButton("Bar properties...", aSaveBox);
284   myTextDlg = new VisuGUI_TextPrefDlg(this);
285   myTextDlg->setTitleVisible(true);
286   myBarDlg = new VisuGUI_BarPrefDlg(this);
287
288   // signals and slots connections ===========================================
289   connect( RBFieldRange,    SIGNAL( clicked() ), this, SLOT( fieldRangeClicked() ) );
290   connect( RBImposedRange,    SIGNAL( clicked() ), this, SLOT( imposedRangeClicked() ) );
291
292   connect( myModeCombo,   SIGNAL( activated( int ) ), this, SLOT( changeScalarMode( int ) ) );
293
294   connect( myRBLocal,     SIGNAL( clicked() ), this, SLOT( onLocalScalarBar() ) );
295   connect( myRBGlobal,    SIGNAL( clicked() ), this, SLOT( onGlobalScalarBar() ) );
296
297   connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorLabel, SLOT( setEnabled( bool ) ) );
298   connect( RainbowButton, SIGNAL( toggled( bool ) ), ColorSpin, SLOT( setEnabled( bool ) ) );
299   connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelLabel, SLOT( setEnabled( bool ) ) );
300   connect( RainbowButton, SIGNAL( toggled( bool ) ), LabelSpin, SLOT( setEnabled( bool ) ) );
301   connect( OrientGroup,   SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
302   connect( XSpin,         SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
303   connect( YSpin,         SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
304   connect( myTextBtn,     SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
305   connect( myBarBtn,      SIGNAL( clicked() ), this, SLOT( onBarPref() ) );
306
307   changeDefaults( 0 );
308   myIsStoreTextProp = false;
309 }
310
311 bool VisuGUI_GaussScalarBarPane::UseFieldRange(bool theInit)
312 {
313   if ( theInit )
314     return !myPrsCopy->IsRangeFixed();
315
316   return RBFieldRange->isChecked() || !myPrsCopy->GetIsActiveLocalScalarBar();
317 }
318
319
320 void VisuGUI_GaussScalarBarPane::onGlobalScalarBar()
321 {
322   myPrsCopy->SetIsActiveLocalScalarBar(false);
323   myPrsCopy->SetSourceRange();
324
325   myCBDisplayed->setEnabled( false );
326
327   RBImposedRange->setEnabled( false );
328   RBFieldRange->setEnabled( false );
329
330   MinEdit->setEnabled( false );
331   MaxEdit->setEnabled( false );
332
333   MinEdit->setText( QString::number( myPrsCopy->GetMin() ) );
334   MaxEdit->setText( QString::number( myPrsCopy->GetMax() ) );
335 }
336
337
338 void VisuGUI_GaussScalarBarPane::onLocalScalarBar()
339 {
340   myPrsCopy->SetIsActiveLocalScalarBar(true);
341   if ( RBFieldRange->isChecked() )
342     myPrsCopy->SetSourceRange();
343   else
344     myPrsCopy->SetRange(myPrsCopy->GetMin(), myPrsCopy->GetMax());
345
346   myCBDisplayed->setEnabled( true );
347
348   RBImposedRange->setEnabled( true );
349   RBFieldRange->setEnabled( true );
350
351   MinEdit->setEnabled( RBImposedRange->isChecked() );
352   MaxEdit->setEnabled( RBImposedRange->isChecked() );
353
354   MinEdit->setText( QString::number( myPrsCopy->GetMin() ) );
355   MaxEdit->setText( QString::number( myPrsCopy->GetMax() ) );
356 }
357
358
359 /*!
360   Called when Range mode is changed to FieldRange
361 */
362 void VisuGUI_GaussScalarBarPane::fieldRangeClicked()
363 {
364   myPrsCopy->SetSourceRange();
365
366   RBFieldRange->setChecked( true );
367   RBImposedRange->setChecked( false );
368
369   MinEdit->setEnabled( false );
370   MaxEdit->setEnabled( false );
371
372   MinEdit->setText( QString::number( myPrsCopy->GetMin() ) );
373   MaxEdit->setText( QString::number( myPrsCopy->GetMax() ) );
374 }
375
376
377 /*!
378   Called when Range mode is changed to FieldRange
379 */
380 void VisuGUI_GaussScalarBarPane::imposedRangeClicked()
381 {
382   myPrsCopy->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
383
384   RBImposedRange->setChecked( true );
385   RBFieldRange->setChecked( false );
386
387   MinEdit->setEnabled( true );
388   MaxEdit->setEnabled( true );
389 }
390
391
392 /*!
393   Called when scalar mode is changed
394 */
395 void VisuGUI_GaussScalarBarPane::changeScalarMode( int theMode )
396 {
397   myPrsCopy->SetScalarMode( theMode );
398   if ( UseFieldRange() ) {
399     MinEdit->setText( QString::number( myPrsCopy->GetSourceMin() ) );
400     MaxEdit->setText( QString::number( myPrsCopy->GetSourceMax() ) );
401   }
402 }
403
404 /**
405  * Initialise dialog box from presentation object
406  */
407 void VisuGUI_GaussScalarBarPane::initFromPrsObject(VISU::GaussPoints_i* thePrs,
408                                                    bool theInit ) 
409 {
410   myPrsCopy = thePrs;
411
412   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
413
414   bool activeLocal = thePrs->GetIsActiveLocalScalarBar();
415   if ( activeLocal ) {
416     RBImposedRange->setChecked( !UseFieldRange(theInit) );
417     RBFieldRange->setChecked( UseFieldRange(theInit) );
418     MinEdit->setEnabled( !UseFieldRange(theInit) );
419     MaxEdit->setEnabled( !UseFieldRange(theInit) );
420   } else {
421     RBImposedRange->setEnabled( false );
422     RBFieldRange->setEnabled( false );
423     MinEdit->setEnabled( false );
424     MaxEdit->setEnabled( false );
425   }
426
427   MinEdit->setText( QString::number( thePrs->GetMin() ) );
428   MaxEdit->setText( QString::number( thePrs->GetMax() ) );
429
430   setPosAndSize( thePrs->GetPosX(),
431                  thePrs->GetPosY(),
432                  thePrs->GetWidth(),
433                  thePrs->GetHeight(),
434                  thePrs->GetBarOrientation());
435
436   if(RBvert->isChecked()) {
437     myVerTW = thePrs->GetTitleWidth();
438     myVerTH = thePrs->GetTitleHeight();
439     myVerLW = thePrs->GetLabelWidth();
440     myVerLH = thePrs->GetLabelHeight();
441     myVerBW = thePrs->GetBarWidth();
442     myVerBH = thePrs->GetBarHeight();
443   } else {
444     myHorTW = thePrs->GetTitleWidth();
445     myHorTH = thePrs->GetTitleHeight();
446     myHorLW = thePrs->GetLabelWidth();
447     myHorLH = thePrs->GetLabelHeight();
448     myHorBW = thePrs->GetBarWidth();
449     myHorBH = thePrs->GetBarHeight();
450   }
451
452   myBarDlg->setLabelsFormat(thePrs->GetLabelsFormat());
453   myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
454
455   SpacingSpin->setValue(thePrs->GetSpacing());
456
457   myRBLocal->setChecked( activeLocal );
458
459   myRBGlobal->setChecked( !activeLocal );
460   myRBGlobal->setEnabled( thePrs->IsGlobalRangeDefined() );
461   if( !thePrs->IsGlobalRangeDefined() )
462     myRBLocal->setChecked( true );
463
464   myCBDisplayed->setEnabled( activeLocal );
465   myCBDisplayed->setChecked( thePrs->GetIsDispGlobalScalarBar() );
466
467   bool bicolor = thePrs->GetSpecificPL()->GetBicolor();
468   BicolorButton->setChecked( bicolor );
469   RainbowButton->setChecked( !bicolor );
470   ColorLabel->setEnabled( !bicolor );
471   ColorSpin->setEnabled( !bicolor );
472   LabelLabel->setEnabled( !bicolor );
473   LabelSpin->setEnabled( !bicolor );
474
475   setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
476
477   // Update myModeCombo
478   int aNbComp = thePrs->GetField()->myNbComp;
479   bool isScalarMode = (aNbComp > 1);
480   myModeCombo->clear();
481   myModeCombo->insertItem("<Modulus>");
482   VISU::PField aField = thePrs->GetField();
483   const VISU::TNames& aCompNames = aField->myCompNames;
484   const VISU::TNames& aUnitNames = aField->myUnitNames;
485   for(int i = 0; i < aNbComp; i++){
486     QString aComponent = QString(aCompNames[i].c_str()).simplifyWhiteSpace();
487     if(aComponent.isNull() || aComponent == "")
488       aComponent = "Component " + QString::number(i+1);
489     else
490       aComponent = "[" + QString::number(i+1) + "] " + aComponent;
491
492     QString anUnit = QString(aUnitNames[i].c_str()).simplifyWhiteSpace();
493     if(anUnit.isNull() || anUnit == "")
494       anUnit = "-";
495     
496     aComponent = aComponent + ", " + anUnit;
497
498     myModeCombo->insertItem(aComponent);
499   }
500   //
501   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
502   if (aNbComp==1){
503     myModeCombo->setCurrentItem(1);
504   }
505   //
506   myModeLbl->setEnabled(isScalarMode);
507   myModeCombo->setEnabled(isScalarMode);
508
509   // "Title"
510   myTextDlg->setTitleText(QString(thePrs->GetTitle()));
511
512   vtkFloatingPointType R, G, B;
513   thePrs->GetTitleColor(&R, &G, &B);
514
515   myBarDlg->setLabelsFormat(thePrs->GetLabelsFormat());
516   myBarDlg->setUnitsVisible(thePrs->IsUnitsVisible());
517
518   myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
519                                   thePrs->GetTitFontType(),
520                                   thePrs->IsBoldTitle(),
521                                   thePrs->IsItalicTitle(),
522                                   thePrs->IsShadowTitle());
523
524   // "Labels"
525   thePrs->GetLabelColor(&R, &G, &B);
526
527   myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
528                                   thePrs->GetLblFontType(),
529                                   thePrs->IsBoldLabel(),
530                                   thePrs->IsItalicLabel(),
531                                   thePrs->IsShadowLabel());
532 }
533
534 /**
535  * Store values to presentation object
536  */
537 int VisuGUI_GaussScalarBarPane::storeToPrsObject(VISU::GaussPoints_i* thePrs) {
538   thePrs->SetScalarMode(myModeCombo->currentItem());
539
540   if (RBFieldRange->isChecked()) {
541     thePrs->SetSourceRange();
542   } else {
543     thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
544   }
545
546   thePrs->SetSpacing(SpacingSpin->value());
547   thePrs->SetIsActiveLocalScalarBar(myRBLocal->isChecked());
548   thePrs->SetIsDispGlobalScalarBar(myCBDisplayed->isChecked());
549   thePrs->SetBiColor(BicolorButton->isChecked());
550
551   thePrs->SetPosition(XSpin->value(), YSpin->value());
552   thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
553   thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ColoredPrs3d::VERTICAL : VISU::ColoredPrs3d::HORIZONTAL);
554   thePrs->SetNbColors(ColorSpin->value());
555   thePrs->SetLabels(LabelSpin->value());
556
557   if(RBvert->isChecked()) {
558     thePrs->SetRatios(myVerTW, myVerTH, myVerLW, myVerLH, myVerBW, myVerBH);
559   } else {
560     thePrs->SetRatios(myHorTW, myHorTH, myHorLW, myHorLH, myHorBW, myHorBH);
561   }
562
563   thePrs->SetLabelsFormat(myBarDlg->getLabelsFormat());
564   thePrs->SetUnitsVisible(myBarDlg->isUnitsVisible());
565
566   if (myIsStoreTextProp) {
567     // "Title"
568     thePrs->SetTitle(myTextDlg->getTitleText().latin1());
569
570     QColor aTitColor (255, 255, 255);
571     int aTitleFontFamily = VTK_ARIAL;
572     bool isTitleBold = false;
573     bool isTitleItalic = false;
574     bool isTitleShadow = false;
575
576     myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
577                                     isTitleBold, isTitleItalic, isTitleShadow);
578
579     thePrs->SetBoldTitle(isTitleBold);
580     thePrs->SetItalicTitle(isTitleItalic);
581     thePrs->SetShadowTitle(isTitleShadow);
582     thePrs->SetTitFontType(aTitleFontFamily);
583     thePrs->SetTitleColor(aTitColor.red()/255.,
584                           aTitColor.green()/255.,
585                           aTitColor.blue()/255.);
586
587     // "Label"
588     QColor aLblColor (255, 255, 255);
589     int aLabelFontFamily = VTK_ARIAL;
590     bool isLabelBold = false;
591     bool isLabelItalic = false;
592     bool isLabelShadow = false;
593
594     myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
595                                     isLabelBold, isLabelItalic, isLabelShadow);
596
597     thePrs->SetBoldLabel(isLabelBold);
598     thePrs->SetItalicLabel(isLabelItalic);
599     thePrs->SetShadowLabel(isLabelShadow);
600     thePrs->SetLblFontType(aLabelFontFamily);
601     thePrs->SetLabelColor(aLblColor.red()/255.,
602                           aLblColor.green()/255.,
603                           aLblColor.blue()/255.);
604   }
605
606   return 1;
607 }
608
609 /*!
610   Called when orientation is changed
611 */
612 void VisuGUI_GaussScalarBarPane::changeDefaults( int )
613 {
614   if ( RBvert->isChecked() ) {
615     XSpin->setValue( myVerX );
616     YSpin->setValue( myVerY );
617     WidthSpin->setValue( myVerW );
618     HeightSpin->setValue( myVerH );
619   }
620   else {
621     XSpin->setValue( myHorX );
622     YSpin->setValue( myHorY );
623     WidthSpin->setValue( myHorW );
624     HeightSpin->setValue( myHorH );
625   }
626 }
627
628 /*!
629   Called when X,Y position is changed
630 */
631 void VisuGUI_GaussScalarBarPane::XYChanged( double )
632 {
633   QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
634   if ( snd == XSpin ) {
635     WidthSpin->setMaxValue( 1.0 - XSpin->value() );
636   }
637   if ( snd == YSpin ) {
638     HeightSpin->setMaxValue( 1.0 - YSpin->value() );
639   }
640 }
641
642 /*!
643   Sets size and position
644 */
645 void VisuGUI_GaussScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
646 {
647   if ( vert ) {
648     myVerX = x;
649     myVerY = y;
650     myVerW = w;
651     myVerH = h;
652     RBvert->setChecked( true );
653   }
654   else {
655     myHorX = x;
656     myHorY = y;
657     myHorW = w;
658     myHorH = h;
659     RBhori->setChecked( true );
660   }
661   changeDefaults( 0 );
662 }
663
664 /*!
665   Sets colors and labels number
666 */
667 void VisuGUI_GaussScalarBarPane::setScalarBarData( int colors, int labels )
668 {
669   ColorSpin->setValue( colors );
670   LabelSpin->setValue( labels );
671 }
672
673 /*!
674   Gets orientation
675 */
676 int VisuGUI_GaussScalarBarPane::getOrientation()
677 {
678   if (RBvert->isChecked() )
679     return  1;
680   else
681     return 0;
682 }
683
684 /*!
685   Sets and gets parameters
686 */
687 double VisuGUI_GaussScalarBarPane::getX() {
688   return XSpin->value();
689 }
690
691 double VisuGUI_GaussScalarBarPane::getY() {
692   return YSpin->value();
693 }
694
695 double VisuGUI_GaussScalarBarPane::getWidth() {
696   return WidthSpin->value();
697 }
698
699 double VisuGUI_GaussScalarBarPane::getHeight() {
700   return HeightSpin->value();
701 }
702
703 int VisuGUI_GaussScalarBarPane::getNbColors() {
704   return ColorSpin->value();
705 }
706
707 int VisuGUI_GaussScalarBarPane::getNbLabels() {
708   return LabelSpin->value();
709 }
710
711 void VisuGUI_GaussScalarBarPane::onTextPref()
712 {
713   myIsStoreTextProp = myTextDlg->exec();
714 }
715
716 void VisuGUI_GaussScalarBarPane::onBarPref()
717 {
718   if(RBvert->isChecked())
719     myBarDlg->setRatios(myVerTW, myVerTH, myVerLW, myVerLH, myVerBW, myVerBH);
720   else
721     myBarDlg->setRatios(myHorTW, myHorTH, myHorLW, myHorLH, myHorBW, myHorBH);
722   if(myBarDlg->exec()) {
723     if(RBvert->isChecked())
724       myBarDlg->getRatios(myVerTW, myVerTH, myVerLW, myVerLH, myVerBW, myVerBH);
725     else
726       myBarDlg->getRatios(myHorTW, myHorTH, myHorLW, myHorLH, myHorBW, myHorBH);
727   }
728 }
729
730 /*!
731  * Constructor
732  */
733 VisuGUI_GaussPointsDlg::VisuGUI_GaussPointsDlg(SalomeApp_Module* theModule):
734   VisuGUI_Prs3dDlg(theModule)
735 {
736   setName("VisuGUI_GaussPointsDlg");
737   setCaption(tr("DLG_PROP_TITLE"));
738   setSizeGripEnabled(TRUE);
739
740   QVBoxLayout* TopLayout = new QVBoxLayout(this);
741   TopLayout->setSpacing(6);
742   TopLayout->setMargin(11);
743
744
745   // Presentation
746   QButtonGroup* PrsGroup = new QButtonGroup( 3, Qt::Horizontal, tr( "PRS_TITLE" ), this, "PrimitiveTypeGroup" );
747   PrsGroup->setRadioButtonExclusive( true );
748   PrsGroup->layout()->setMargin( 11 );
749   PrsGroup->layout()->setSpacing(6);
750
751   myResultsButton = new QRadioButton( tr( "RESULTS" ), PrsGroup );
752   myGeometryButton = new QRadioButton( tr( "GEOMETRY" ), PrsGroup );
753   myDefShapeButton = new QRadioButton( tr( "DEFORMED_SHAPE" ), PrsGroup );
754
755   myTabBox = new QTabWidget (this);
756
757   // Gauss points pane
758   QVBox* aBox = new QVBox (this);
759   aBox->setMargin(11);
760   aBox->setSpacing(6);
761
762   // Primitive
763   myPrimitiveBox = new VVTK_PrimitiveBox( aBox );
764
765   // Size
766   mySizeBox = new VVTK_SizeBox( aBox );
767
768   // Deformed Shape
769   myDefShapeBox = new QGroupBox( tr( "DEFORMED_SHAPE_TITLE" ), aBox );
770   myDefShapeBox->setColumnLayout(0, Qt::Vertical );
771   myDefShapeBox->layout()->setSpacing( 0 );
772   myDefShapeBox->layout()->setMargin( 0 );
773
774   QGridLayout* aDefShapeLayout = new QGridLayout( myDefShapeBox->layout() );
775   aDefShapeLayout->setAlignment(Qt::AlignTop);
776   aDefShapeLayout->setSpacing(6);
777   aDefShapeLayout->setMargin(11);
778
779   QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox );
780   myScaleSpinBox = new QtxDblSpinBox( 0.0, 10.0, 0.1, myDefShapeBox );
781
782   aDefShapeLayout->addWidget( aScaleLabel, 0, 0 );
783   aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 );
784
785   // Scalar Bar pane
786   myScalarPane = new VisuGUI_GaussScalarBarPane(this);
787   myScalarPane->setMargin(5);
788
789   // Input pane
790   myInputPane = new VisuGUI_InputPane(VISU::TGAUSSPOINTS, theModule, this);
791
792   connect( myResultsButton,  SIGNAL( clicked() ),       mySizeBox,    SLOT( onToggleResults() ) );
793   connect( myResultsButton,  SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
794   connect( myGeometryButton, SIGNAL( clicked() ),       mySizeBox,    SLOT( onToggleGeometry() ) );
795   connect( myDefShapeButton, SIGNAL( toggled( bool ) ), this,         SLOT( onToggleDefShape( bool ) ) );
796   connect( myDefShapeButton, SIGNAL( toggled( bool ) ), myScalarPane, SLOT( setEnabled( bool ) ) );
797
798   myTabBox->addTab(aBox, tr("GAUSS_POINTS_TAB"));
799   myTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
800   myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
801
802   // Common buttons ===========================================================
803   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
804   GroupButtons->setColumnLayout(0, Qt::Vertical );
805   GroupButtons->layout()->setSpacing( 0 );
806   GroupButtons->layout()->setMargin( 0 );
807   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
808   GroupButtonsLayout->setAlignment( Qt::AlignTop );
809   GroupButtonsLayout->setSpacing( 6 );
810   GroupButtonsLayout->setMargin( 11 );
811
812   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
813   buttonOk->setAutoDefault( TRUE );
814   buttonOk->setDefault( TRUE );
815   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
816   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
817
818   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
819   buttonCancel->setAutoDefault( TRUE );
820   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
821
822   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
823   buttonHelp->setAutoDefault( TRUE );
824   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
825
826   TopLayout->addWidget( PrsGroup );
827   TopLayout->addWidget( myTabBox );
828   TopLayout->addWidget( GroupButtons );
829
830   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
831   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
832   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
833 }
834
835 VisuGUI_GaussPointsDlg::~VisuGUI_GaussPointsDlg()
836 {}
837
838 void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
839                                                 bool theInit )
840 {
841   if( theInit )
842     myPrsCopy = VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
843
844   myScalarPane->initFromPrsObject( myPrsCopy, theInit );
845
846   bool isDeformed = myPrsCopy->GetIsDeformed();
847   myScaleSpinBox->setValue( myPrsCopy->GetScaleFactor() );
848   myDefShapeButton->setChecked( isDeformed );
849   myDefShapeButton->setEnabled( myPrsCopy->GetField()->myNbComp > 1 );
850   onToggleDefShape( isDeformed );
851
852   bool isResults = myPrsCopy->GetIsColored();
853   myResultsButton->setChecked( isResults && !isDeformed );
854   myGeometryButton->setChecked( !isResults && !isDeformed );
855
856   myPrimitiveBox->setPrimitiveType( myPrsCopy->GetPrimitiveType() );
857   myPrimitiveBox->setClampMaximum( myPrsCopy->GetMaximumSupportedSize() );
858   myPrimitiveBox->setClamp( myPrsCopy->GetClamp() );
859   myPrimitiveBox->setMainTexture( myPrsCopy->GetQMainTexture() );
860   myPrimitiveBox->setAlphaTexture( myPrsCopy->GetQAlphaTexture() );
861   myPrimitiveBox->setAlphaThreshold( myPrsCopy->GetAlphaThreshold() );
862   myPrimitiveBox->setResolution( myPrsCopy->GetResolution() );
863   myPrimitiveBox->setFaceLimit( myPrsCopy->GetFaceLimit() );
864
865   mySizeBox->setType( isResults || isDeformed ? VVTK_SizeBox::Results : VVTK_SizeBox::Geometry );
866   mySizeBox->setGeomSize( myPrsCopy->GetGeomSize() );
867   mySizeBox->setMinSize( myPrsCopy->GetMinSize() );
868   mySizeBox->setMaxSize( myPrsCopy->GetMaxSize() );
869   mySizeBox->setMagnification( myPrsCopy->GetMagnification() );
870   mySizeBox->setIncrement( myPrsCopy->GetMagnificationIncrement() );
871   mySizeBox->setColor( myPrsCopy->GetQColor() );
872
873   if( !theInit )
874     return;
875
876   myInputPane->initFromPrsObject( myPrsCopy );
877   myTabBox->setCurrentPage( 0 );
878 }
879
880 int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
881 {
882   if(!myInputPane->check())
883     return 0;
884
885   int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
886   anIsOk &= myScalarPane->storeToPrsObject( myPrsCopy );
887
888   myPrsCopy->SetIsDeformed( myDefShapeButton->isChecked() );
889   myPrsCopy->SetScaleFactor( myScaleSpinBox->value() );
890
891   int aPrimitiveType = myPrimitiveBox->getPrimitiveType();
892   myPrsCopy->SetPrimitiveType( VISU::GaussPoints::PrimitiveType( aPrimitiveType )  );
893
894   myPrsCopy->SetClamp( myPrimitiveBox->getClamp() );
895
896   QString aMainTexture = myPrimitiveBox->getMainTexture();
897   QString anAlphaTexture = myPrimitiveBox->getAlphaTexture();
898
899   aMainTexture = aMainTexture.isNull() ? myPrsCopy->GetQMainTexture() : aMainTexture;
900   anAlphaTexture = anAlphaTexture.isNull() ? myPrsCopy->GetQAlphaTexture() : anAlphaTexture;
901   
902   myPrsCopy->SetTextures( aMainTexture, anAlphaTexture );
903
904   myPrsCopy->SetAlphaThreshold( myPrimitiveBox->getAlphaThreshold() );
905
906   myPrsCopy->SetResolution( myPrimitiveBox->getResolution() );
907   myPrsCopy->SetFaceLimit( myPrimitiveBox->getFaceLimit() );
908
909   bool isColored = !myGeometryButton->isChecked();
910   if( isColored )
911   {
912     myPrsCopy->SetIsColored( true );
913     myPrsCopy->SetMinSize( mySizeBox->getMinSize() );
914     myPrsCopy->SetMaxSize( mySizeBox->getMaxSize() );
915   }
916   else
917   {
918     myPrsCopy->SetIsColored( false );
919     myPrsCopy->SetQColor( mySizeBox->getColor() );
920     myPrsCopy->SetGeomSize( mySizeBox->getGeomSize() );
921   }
922
923   myPrsCopy->SetMagnification( mySizeBox->getMagnification() );
924   myPrsCopy->SetMagnificationIncrement( mySizeBox->getIncrement() );
925
926   VISU::TSameAsFactory<VISU::TGAUSSPOINTS>().Copy(myPrsCopy, thePrs);
927
928   return anIsOk;
929 }
930
931 void VisuGUI_GaussPointsDlg::onToggleDefShape( bool on )
932 {
933   if( on )//myDefShapeButton->isChecked() )
934   {
935     myDefShapeBox->show();
936     mySizeBox->setType( VVTK_SizeBox::Results );
937   }
938   else
939     myDefShapeBox->hide();
940 }
941
942 void VisuGUI_GaussPointsDlg::accept()
943 {
944   if( (bool)myPrsCopy && myPrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere )
945   {
946     int aNumberOfFaces = myPrimitiveBox->getFaceNumber();
947     int aNumberOfPoints = myPrsCopy->GetSpecificPL()->GetInput()->GetNumberOfCells();
948
949     if( aNumberOfFaces * aNumberOfPoints > myPrimitiveBox->getFaceLimit() )
950     {
951       QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
952       aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
953       aWarning.append( "Can you please confirm that you want to continue anyway?" );
954       if( SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning, tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 1 )
955         return;
956     }
957
958     /*
959     float aMemory = 50.0 * 1024.0 * (float)aNumberOfFaces * (float)aNumberOfPoints;
960
961     cout << aNumberOfFaces << endl;
962     cout << aNumberOfPoints << endl;
963     cout << aMemory << endl;
964
965     vtkSphereSource* aSphere = vtkSphereSource::New();
966     aSphere->SetThetaResolution( myPrimitiveBox->getResolution() );
967     aSphere->SetPhiResolution( myPrimitiveBox->getResolution() );
968     aSphere->GetOutput()->Update();
969     aSphere->GetOutput()->GetActualMemorySize();
970
971     aMemory = aSphere->GetOutput()->GetActualMemorySize() * 1024.0 * (float)aNumberOfPoints;
972
973     if( VISU_PipeLine::CheckAvailableMemory( aMemory ) == 0 )
974     {
975       SUIT_MessageBox::error1( this, "caption", "text", "ok" );
976       return 0;
977     }
978     */
979   }
980
981   //if( myScalarPane->check() )
982   VisuGUI_Prs3dDlg::accept();
983 }
984
985 QString VisuGUI_GaussPointsDlg::GetContextHelpFilePath()
986 {
987   return "types_of_gauss_points_presentations_page.html";
988 }