Salome HOME
7492c7f570bf6ccec2dfaaa7dd4c49cb7fb9dcdb
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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
34 #include "VISU_GaussPoints_i.hh"
35 #include "VISU_GaussPointsPL.hxx"
36 #include "VISU_OpenGLPointSpriteMapper.hxx"
37 #include "VISU_Convertor.hxx"
38
39 #include "VVTK_PrimitiveBox.h"
40 #include "VVTK_SizeBox.h"
41
42 #include "SalomeApp_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"
49
50 #include <qlayout.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>
57
58 #include <vtkPolyData.h>
59 #include <vtkDataSet.h>
60 #include <vtkSphereSource.h>
61
62 using namespace std;
63
64 VisuGUI_GaussScalarBarPane::VisuGUI_GaussScalarBarPane (QWidget * parent, bool SetPref):
65   QVBox(parent)
66 {
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;
70   myRangeMode = -1;
71
72   setSpacing(6);
73   //setMargin(11);
74
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 );
84
85   QButtonGroup* BarTypeGroup = new QButtonGroup( 2, Qt::Vertical, ActiveBarGroup, "BarTypeGroup" );
86   BarTypeGroup->setRadioButtonExclusive( true );
87   BarTypeGroup->setFrameStyle( QFrame::NoFrame );
88   BarTypeGroup->layout()->setMargin( 0 );
89
90   myRBLocal = new QRadioButton( tr( "LOCAL" ), BarTypeGroup );
91   myRBGlobal = new QRadioButton( tr( "GLOBAL" ), BarTypeGroup );
92
93   myCBDisplayed = new QCheckBox( tr( "DISPLAYED" ), ActiveBarGroup );
94
95   ActiveBarGroupLayout->addMultiCellWidget( BarTypeGroup, 0, 1, 0, 0 );
96   ActiveBarGroupLayout->addWidget( myCBDisplayed, 1, 1 );
97
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 );
107
108   myModeLbl = new QLabel("Scalar Mode", RangeGroup);
109
110   myModeCombo = new QComboBox(RangeGroup);
111
112   RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
113   RangeGroupLayout->addWidget( myModeCombo, 0, 1 );
114
115   //TopLayout->addWidget( RangeGroup );
116
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 );
126
127   QButtonGroup* TypeGroup = new QButtonGroup( 2, Qt::Vertical, ColLabGroup, "TypeGroup" );
128   TypeGroup->setRadioButtonExclusive( true );
129   TypeGroup->setFrameStyle( QFrame::NoFrame );
130   TypeGroup->layout()->setMargin( 0 );
131
132   BicolorButton = new QRadioButton( tr( "BICOLOR" ), TypeGroup );
133   RainbowButton = new QRadioButton( tr( "RAINBOW" ), TypeGroup );
134
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 );
140
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 );
146
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);
152
153   //TopLayout->addWidget( ColLabGroup );
154
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 );
164
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 );
170
171   //  TopLayout->addWidget( OrientGroup );
172
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 );
182
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 );
188
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 );
194
195   OriginGroupLayout->addWidget( XLabel, 0, 0);
196   OriginGroupLayout->addWidget( XSpin,  0, 1);
197   OriginGroupLayout->addWidget( YLabel, 0, 2);
198   OriginGroupLayout->addWidget( YSpin,  0, 3);
199
200   //TopLayout->addWidget( OriginGroup );
201
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 );
211
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 );
217
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 );
223
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 );
229
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);
236
237   //TopLayout->addWidget( DimGroup );
238
239   // Save check box ===========================================================
240   QHBox* aSaveBox = new QHBox(this);
241   if (!SetPref) {
242     CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave");
243     //TopLayout->addWidget(CBSave);
244   }
245   else {
246     CBSave = 0;
247   }
248   myTextBtn = new QPushButton("Text properties...", aSaveBox);
249   myTextDlg = new VisuGUI_TextPrefDlg(this);
250   myTextDlg->setTitleVisible(!SetPref);
251
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() ) );
263
264   changeDefaults( 0 );
265   myIsStoreTextProp = false;
266 }
267
268 void VisuGUI_GaussScalarBarPane::onSetDisplayGlobal()
269 {
270   myCBDisplayed->setChecked( true );
271 }
272
273
274 /**
275  * Initialise dialog box from presentation object
276  */
277 void VisuGUI_GaussScalarBarPane::initFromPrsObject(VISU::GaussPoints_i* thePrs) {
278   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
279   setPosAndSize( thePrs->GetPosX(),
280                  thePrs->GetPosY(),
281                  thePrs->GetWidth(),
282                  thePrs->GetHeight(),
283                  thePrs->GetBarOrientation());
284
285   SpacingSpin->setValue(thePrs->GetSpacing());
286
287   bool activeLocal = thePrs->GetIsActiveLocalScalarBar();
288   myRBLocal->setChecked( activeLocal );
289
290   myRBGlobal->setChecked( !activeLocal );
291   myRBGlobal->setEnabled( thePrs->IsGlobalRangeDefined() );
292   if( !thePrs->IsGlobalRangeDefined() )
293     myRBLocal->setChecked( true );
294
295   myCBDisplayed->setEnabled( activeLocal );
296   myCBDisplayed->setChecked( thePrs->GetIsDispGlobalScalarBar() );
297
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 );
305
306   setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
307
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]).simplifyWhiteSpace();
318     if(aComponent.isNull() || aComponent == "")
319       aComponent = "Component " + QString::number(i+1);
320     else
321       aComponent = "[" + QString::number(i+1) + "] " + aComponent;
322
323     QString anUnit = QString(aUnitNames[i]).simplifyWhiteSpace();
324     if(anUnit.isNull() || anUnit == "")
325       anUnit = "-";
326     
327     aComponent = aComponent + ", " + anUnit;
328
329     myModeCombo->insertItem(aComponent);
330   }
331   //
332   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
333   if (aNbComp==1){
334     myModeCombo->setCurrentItem(1);
335   }
336   //
337   myModeLbl->setEnabled(isScalarMode);
338   myModeCombo->setEnabled(isScalarMode);
339
340   // "Title"
341   myTextDlg->setTitleText(QString(thePrs->GetTitle()));
342
343   float R, G, B;
344   thePrs->GetTitleColor(&R, &G, &B);
345
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());
351
352   // "Labels"
353   thePrs->GetLabelColor(&R, &G, &B);
354
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());
360 }
361
362 /**
363  * Store values to presentation object
364  */
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());
375
376   thePrs->GetGaussPointsPL()->SetBicolor(BicolorButton->isChecked());
377
378   //if (isToSave()) storeToResources();
379
380   if (myIsStoreTextProp) {
381     // "Title"
382     thePrs->SetTitle(myTextDlg->getTitleText().latin1());
383
384     QColor aTitColor (255, 255, 255);
385     int aTitleFontFamily = VTK_ARIAL;
386     bool isTitleBold = false;
387     bool isTitleItalic = false;
388     bool isTitleShadow = false;
389
390     myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
391                                     isTitleBold, isTitleItalic, isTitleShadow);
392
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.);
400
401     // "Label"
402     QColor aLblColor (255, 255, 255);
403     int aLabelFontFamily = VTK_ARIAL;
404     bool isLabelBold = false;
405     bool isLabelItalic = false;
406     bool isLabelShadow = false;
407
408     myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
409                                     isLabelBold, isLabelItalic, isLabelShadow);
410
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.);
418   }
419
420   return 1;
421 }
422
423 /*!
424   Called when orientation is changed
425 */
426 void VisuGUI_GaussScalarBarPane::changeDefaults( int )
427 {
428   if ( RBvert->isChecked() ) {
429     XSpin->setValue( myVerX );
430     YSpin->setValue( myVerY );
431     WidthSpin->setValue( myVerW );
432     HeightSpin->setValue( myVerH );
433   }
434   else {
435     XSpin->setValue( myHorX );
436     YSpin->setValue( myHorY );
437     WidthSpin->setValue( myHorW );
438     HeightSpin->setValue( myHorH );
439   }
440 }
441
442 /*!
443   Called when X,Y position is changed
444 */
445 void VisuGUI_GaussScalarBarPane::XYChanged( double )
446 {
447   QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
448   if ( snd == XSpin ) {
449     WidthSpin->setMaxValue( 1.0 - XSpin->value() );
450   }
451   if ( snd == YSpin ) {
452     HeightSpin->setMaxValue( 1.0 - YSpin->value() );
453   }
454 }
455
456 /*!
457   Sets size and position
458 */
459 void VisuGUI_GaussScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
460 {
461   if ( vert ) {
462     myVerX = x;
463     myVerY = y;
464     myVerW = w;
465     myVerH = h;
466     RBvert->setChecked( true );
467   }
468   else {
469     myHorX = x;
470     myHorY = y;
471     myHorW = w;
472     myHorH = h;
473     RBhori->setChecked( true );
474   }
475   changeDefaults( 0 );
476 }
477
478 /*!
479   Sets colors and labels number
480 */
481 void VisuGUI_GaussScalarBarPane::setScalarBarData( int colors, int labels )
482 {
483   ColorSpin->setValue( colors );
484   LabelSpin->setValue( labels );
485 }
486
487 /*!
488   Gets orientation
489 */
490 int  VisuGUI_GaussScalarBarPane::getOrientation()
491 {
492   if (RBvert->isChecked() )
493     return  1;
494   else
495     return 0;
496 }
497
498
499 void VisuGUI_GaussScalarBarPane::onTextPref()
500 {
501   myIsStoreTextProp = myTextDlg->exec();
502 }
503
504
505 /*!
506  * Constructor
507  */
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),
512   myPrs(NULL)
513 {
514   setName("VisuGUI_ScalarBarDlg");
515   setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
516   setSizeGripEnabled(TRUE);
517
518   QVBoxLayout* TopLayout = new QVBoxLayout(this);
519   TopLayout->setSpacing(6);
520   TopLayout->setMargin(11);
521
522
523   // Presentation
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);
528
529   myResultsButton = new QRadioButton( tr( "RESULTS" ), PrsGroup );
530   myGeometryButton = new QRadioButton( tr( "GEOMETRY" ), PrsGroup );
531   myDefShapeButton = new QRadioButton( tr( "DEFORMED_SHAPE" ), PrsGroup );
532
533   QTabWidget* aTabBox = new QTabWidget (this);
534
535   // Gauss points pane
536   QVBox* aBox = new QVBox (this);
537   aBox->setMargin(11);
538   aBox->setSpacing(6);
539
540   // Primitive
541   myPrimitiveBox = new VVTK_PrimitiveBox( aBox );
542
543   // Size
544   mySizeBox = new VVTK_SizeBox( aBox );
545
546   // Deformed Shape
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 );
551
552   QGridLayout* aDefShapeLayout = new QGridLayout( myDefShapeBox->layout() );
553   aDefShapeLayout->setAlignment(Qt::AlignTop);
554   aDefShapeLayout->setSpacing(6);
555   aDefShapeLayout->setMargin(11);
556
557   QLabel* aScaleLabel = new QLabel( tr( "SCALE_FACTOR" ), myDefShapeBox );
558   myScaleSpinBox = new QtxDblSpinBox( 0.0, 10.0, 0.1, myDefShapeBox );
559
560   aDefShapeLayout->addWidget( aScaleLabel, 0, 0 );
561   aDefShapeLayout->addWidget( myScaleSpinBox, 0, 1 );
562
563   // Scalar Bar pane
564   myScalarPane = new VisuGUI_GaussScalarBarPane(this, SetPref);
565   myScalarPane->setMargin(5);
566
567
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 ) ) );
573
574   aTabBox->addTab(aBox, tr("GAUSS_POINTS_TAB"));
575   aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
576
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 );
586
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 );
592
593   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
594   buttonCancel->setAutoDefault( TRUE );
595   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
596
597   TopLayout->addWidget( PrsGroup );
598   TopLayout->addWidget( aTabBox );
599   TopLayout->addWidget( GroupButtons );
600
601   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
602   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
603 }
604
605 void VisuGUI_GaussPointsDlg::initFromPrsObject( VISU::GaussPoints_i* thePrs )
606 {
607   bool isDeformed = thePrs->GetIsDeformed();
608   myScaleSpinBox->setValue( thePrs->GetScaleFactor() );
609   myDefShapeButton->setChecked( isDeformed );
610   myDefShapeButton->setEnabled( thePrs->GetField()->myNbComp > 1 );
611   onToggleDefShape( isDeformed );
612
613   bool isResults = thePrs->GetIsColored();
614   myResultsButton->setChecked( isResults && !isDeformed );
615   myGeometryButton->setChecked( !isResults && !isDeformed );
616
617   myPrimitiveBox->setPrimitiveType( thePrs->GetPrimitiveType() );
618   myPrimitiveBox->setClampMaximum( thePrs->GetMaximumSupportedSize() );
619   myPrimitiveBox->setClamp( thePrs->GetClamp() );
620   myPrimitiveBox->setMainTexture( thePrs->GetMainTexture() );
621   myPrimitiveBox->setAlphaTexture( thePrs->GetAlphaTexture() );
622   myPrimitiveBox->setAlphaThreshold( thePrs->GetAlphaThreshold() );
623   myPrimitiveBox->setResolution( thePrs->GetResolution() );
624   myPrimitiveBox->setFaceLimit( thePrs->GetFaceLimit() );
625
626   mySizeBox->setType( isResults || isDeformed ? VVTK_SizeBox::Results : VVTK_SizeBox::Geometry );
627   mySizeBox->setGeomSize( thePrs->GetGeomSize() );
628   mySizeBox->setMinSize( thePrs->GetMinSize() );
629   mySizeBox->setMaxSize( thePrs->GetMaxSize() );
630   mySizeBox->setMagnification( thePrs->GetMagnification() );
631   mySizeBox->setIncrement( thePrs->GetMagnificationIncrement() );
632   mySizeBox->setColor( thePrs->GetColor() );
633
634   myScalarPane->initFromPrsObject(thePrs);
635
636   myPrs = thePrs;
637 }
638
639 int VisuGUI_GaussPointsDlg::storeToPrsObject( VISU::GaussPoints_i* thePrs )
640 {
641   thePrs->SetIsDeformed( myDefShapeButton->isChecked() );
642   thePrs->SetScaleFactor( myScaleSpinBox->value() );
643
644   thePrs->SetPrimitiveType( myPrimitiveBox->getPrimitiveType() );
645
646   thePrs->SetClamp( myPrimitiveBox->getClamp() );
647
648   QString aMainTexture = myPrimitiveBox->getMainTexture();
649   QString anAlphaTexture = myPrimitiveBox->getAlphaTexture();
650
651   aMainTexture = aMainTexture.isNull() ? thePrs->GetMainTexture() : aMainTexture;
652   anAlphaTexture = anAlphaTexture.isNull() ? thePrs->GetAlphaTexture() : anAlphaTexture;
653   
654   thePrs->SetTextures( aMainTexture, anAlphaTexture );
655
656   thePrs->SetAlphaThreshold( myPrimitiveBox->getAlphaThreshold() );
657
658   thePrs->SetResolution( myPrimitiveBox->getResolution() );
659   thePrs->SetFaceLimit( myPrimitiveBox->getFaceLimit() );
660
661   bool isColored = !myGeometryButton->isChecked();
662   if( isColored )
663   {
664     thePrs->SetIsColored( true );
665     thePrs->SetMinSize( mySizeBox->getMinSize() );
666     thePrs->SetMaxSize( mySizeBox->getMaxSize() );
667   }
668   else
669   {
670     thePrs->SetIsColored( false );
671     thePrs->SetColor( mySizeBox->getColor() );
672     thePrs->SetGeomSize( mySizeBox->getGeomSize() );
673   }
674
675   thePrs->SetMagnification( mySizeBox->getMagnification() );
676   thePrs->SetMagnificationIncrement( mySizeBox->getIncrement() );
677
678   return myScalarPane->storeToPrsObject(thePrs);
679 }
680
681 void VisuGUI_GaussPointsDlg::onToggleDefShape( bool on )
682 {
683   if( on )//myDefShapeButton->isChecked() )
684   {
685     myDefShapeBox->show();
686     mySizeBox->setType( VVTK_SizeBox::Results );
687   }
688   else
689     myDefShapeBox->hide();
690 }
691
692 void VisuGUI_GaussPointsDlg::accept()
693 {
694   if( myPrs && myPrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere )
695   {
696     int aNumberOfFaces = myPrimitiveBox->getFaceNumber();
697     int aNumberOfPoints = ( (vtkPolyData*)myPrs->GetGaussPointsPL()->GetInput() )->GetNumberOfCells();
698
699     if( aNumberOfFaces * aNumberOfPoints > myPrimitiveBox->getFaceLimit() )
700     {
701       QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
702       aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
703       aWarning.append( "Can you please confirm that you want to continue anyway?" );
704       if( SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning, tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 1 )
705         return;
706     }
707
708     /*
709     float aMemory = 50.0 * 1024.0 * (float)aNumberOfFaces * (float)aNumberOfPoints;
710
711     cout << aNumberOfFaces << endl;
712     cout << aNumberOfPoints << endl;
713     cout << aMemory << endl;
714
715     vtkSphereSource* aSphere = vtkSphereSource::New();
716     aSphere->SetThetaResolution( myPrimitiveBox->getResolution() );
717     aSphere->SetPhiResolution( myPrimitiveBox->getResolution() );
718     aSphere->GetOutput()->Update();
719     aSphere->GetOutput()->GetActualMemorySize();
720
721     aMemory = aSphere->GetOutput()->GetActualMemorySize() * 1024.0 * (float)aNumberOfPoints;
722
723     if( VISU_PipeLine::CheckAvailableMemory( aMemory ) == 0 )
724     {
725       SUIT_MessageBox::error1( this, "caption", "text", "ok" );
726       return 0;
727     }
728     */
729   }
730
731   //if( myScalarPane->check() )
732   QDialog::accept();
733 }