Salome HOME
a90fccc59ec85da3aa7d7b6bd338cef4772f7d11
[modules/visu.git] / src / VISUGUI / VisuGUI_Table3dDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // VISU VISUGUI : GUI of VISU component
23 // File   : VisuGUI_Table3dDlg.cxx
24 // Author : Laurent CORNABE & Hubert ROLLAND
25 //
26 #include "VisuGUI_Table3dDlg.h"
27
28 #include "VisuGUI.h"
29 #include "VisuGUI_Tools.h"
30 #include "VisuGUI_ViewTools.h"
31 #include "VisuGUI_InputPane.h"
32
33 #include "VISU_ColoredPrs3dFactory.hh"
34 #include "VISU_ViewManager_i.hh"
35 #include "VISU_Prs3dUtils.hh"
36
37 #include <SVTK_ViewWindow.h>
38 #include <SALOME_Actor.h>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <LightApp_Application.h>
44 #include <SVTK_FontWidget.h>
45 #include <QtxDoubleSpinBox.h>
46
47 #include <QGridLayout>
48 #include <QHBoxLayout>
49 #include <QVBoxLayout>
50 #include <QTabWidget>
51 #include <QRadioButton>
52 #include <QSpinBox>
53 #include <QCheckBox>
54 #include <QLabel>
55 #include <QPushButton>
56 #include <QButtonGroup>
57 #include <QGroupBox>
58 #include <QLineEdit>
59
60 #define SURFACE_PRS_ID 0
61 #define CONTOUR_PRS_ID 1
62
63 //=======================================================================
64 //function : VisuGUI_Table3DPane
65 //purpose  :
66 //=======================================================================
67 VisuGUI_Table3DPane::VisuGUI_Table3DPane( QWidget* parent )
68   : QWidget( parent ),
69     myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>() ),
70     myPrs( 0 ),
71     myInitFromPrs( false )
72 {
73   QGridLayout* topLayout = new QGridLayout( this );
74   topLayout->setMargin( 11 );
75   topLayout->setSpacing( 6 );
76
77   // scale
78   QLabel* scaleLabel = new QLabel( tr( "SCALE" ), this );
79   ScaleSpn = new QtxDoubleSpinBox( -1.e6, 1.e6, 0.1, this );
80   // Presentation type
81   GBPrsTypeBox = new QGroupBox( tr( "PRESENTATION_TYPE" ), this );
82   GBPrsType = new QButtonGroup( GBPrsTypeBox );
83   QRadioButton* rb1 = new QRadioButton( tr( "SURFACE" ), GBPrsTypeBox );
84   QRadioButton* rb2 = new QRadioButton( tr( "CONTOUR" ), GBPrsTypeBox );
85   GBPrsType->addButton( rb1, SURFACE_PRS_ID );
86   GBPrsType->addButton( rb2, CONTOUR_PRS_ID );
87   QHBoxLayout* GBPrsTypeBoxLayout = new QHBoxLayout( GBPrsTypeBox );
88   GBPrsTypeBoxLayout->setMargin( 11 );
89   GBPrsTypeBoxLayout->setSpacing( 6 );
90   GBPrsTypeBoxLayout->addWidget( rb1 );
91   GBPrsTypeBoxLayout->addWidget( rb2 );
92   
93   // nb Contours
94   QLabel* nbContLabel = new QLabel( tr( "NUMBER_CONTOURS" ), this );
95   NbContoursSpn = new QSpinBox( this );
96   NbContoursSpn->setMinimum( 1 );
97   NbContoursSpn->setMaximum( 999 );
98   NbContoursSpn->setSingleStep( 1 );
99
100   topLayout->addWidget( scaleLabel,    0, 0 );
101   topLayout->addWidget( ScaleSpn,      0, 1 );
102   topLayout->addWidget( GBPrsTypeBox,  1, 0, 1, 2 );
103   topLayout->addWidget( nbContLabel,   2, 0 );
104   topLayout->addWidget( NbContoursSpn, 2, 1 );
105   topLayout->setRowStretch( 3, 5 );
106
107   // signals and slots connections
108
109   connect( GBPrsType, SIGNAL( buttonClicked( int ) ), this, SLOT( onPrsType( int ) ) );
110 }
111
112 //=======================================================================
113 //function : destructor
114 //purpose  :
115 //=======================================================================
116 VisuGUI_Table3DPane::~VisuGUI_Table3DPane()
117 {
118 }
119
120 //=======================================================================
121 //function : onPrsType
122 //purpose  :
123 //=======================================================================
124 void VisuGUI_Table3DPane::onPrsType( int id )
125 {
126   NbContoursSpn->setEnabled( id == CONTOUR_PRS_ID );
127 }
128
129 //=======================================================================
130 //function : storeToPrsObject
131 //purpose  :
132 //=======================================================================
133 int VisuGUI_Table3DPane::storeToPrsObject( VISU::PointMap3d_i* thePrs )
134 {
135   // scale
136   thePrs->SetScaleFactor( ScaleSpn->value() );
137
138   // prs type
139   thePrs->SetContourPrs( GBPrsType->checkedId() == CONTOUR_PRS_ID );
140
141   // nb contours
142   thePrs->SetNbOfContours( NbContoursSpn->value() );
143
144   return 1;
145 }
146
147 //=======================================================================
148 //function : GetPrs
149 //purpose  :
150 //=======================================================================
151 VISU::PointMap3d_i* VisuGUI_Table3DPane::GetPrs()
152 {
153   return myPrs;
154 }
155
156 //=======================================================================
157 //function : initFromPrsObject
158 //purpose  :
159 //=======================================================================
160 void VisuGUI_Table3DPane::initFromPrsObject( VISU::PointMap3d_i* thePrs )
161 {
162   myInitFromPrs = true;
163   myPrs = thePrs;
164
165   // scale
166   double aScale = thePrs->GetScaleFactor();
167   if (aScale<0)
168     aScale = 0;
169   ScaleSpn->setValue( aScale );
170
171   // prs type
172   int id = thePrs->GetIsContourPrs() ? CONTOUR_PRS_ID : SURFACE_PRS_ID;
173   GBPrsType->button( id )->setChecked( true );
174   onPrsType( id );
175
176   // nb contours
177   NbContoursSpn->setValue( thePrs->GetNbOfContours() );
178 }
179
180 //=======================================================================
181 //function : Table Scalar Bar
182 //purpose  :
183 //=======================================================================
184
185 VisuGUI_TableScalarBarPane::VisuGUI_TableScalarBarPane( QWidget* parent )
186   : QWidget( parent ), 
187     myBarPrs( 0 )
188 {
189   QGridLayout* topLayout = new QGridLayout( this );
190   topLayout->setSpacing( 6 );
191   topLayout->setMargin( 11 );
192
193   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
194   QString propertyName;
195   propertyName = QString( "scalar_bar_vertical_" );
196   myVerX  = aResourceMgr->doubleValue(  "VISU", propertyName + "x", 0. );
197   myVerY  = aResourceMgr->doubleValue(  "VISU", propertyName + "y", 0. );
198   myVerW  = aResourceMgr->doubleValue(  "VISU", propertyName + "width",  0. );
199   myVerH  = aResourceMgr->doubleValue(  "VISU", propertyName + "height", 0. );
200   myVerTS = aResourceMgr->integerValue( "VISU", propertyName + "title_size",  0 );
201   myVerLS = aResourceMgr->integerValue( "VISU", propertyName + "label_size",  0 );
202   myVerBW = aResourceMgr->integerValue( "VISU", propertyName + "bar_width",  0 );
203   myVerBH = aResourceMgr->integerValue( "VISU", propertyName + "bar_height", 0 );
204
205   propertyName = QString( "scalar_bar_horizontal_" );
206   myHorX  = aResourceMgr->doubleValue(  "VISU", propertyName + "x", 0. );
207   myHorY  = aResourceMgr->doubleValue(  "VISU", propertyName + "y", 0. );
208   myHorW  = aResourceMgr->doubleValue(  "VISU", propertyName + "width",  0. );
209   myHorH  = aResourceMgr->doubleValue(  "VISU", propertyName + "height", 0. );
210   myHorTS = aResourceMgr->integerValue( "VISU", propertyName + "title_size",  0 );
211   myHorLS = aResourceMgr->integerValue( "VISU", propertyName + "label_size",  0 );
212   myHorBW = aResourceMgr->integerValue( "VISU", propertyName + "bar_width",  0 );
213   myHorBH = aResourceMgr->integerValue( "VISU", propertyName + "bar_height", 0 );
214
215   // Range ============================================================
216   RangeGroup = new QGroupBox( tr( "SCALAR_RANGE_GRP" ), this );
217   QButtonGroup* RangeRB = new QButtonGroup( RangeGroup );
218   QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup );
219   RangeGroupLayout->setSpacing( 6 );
220   RangeGroupLayout->setMargin( 11 );
221
222   CBLog = new QCheckBox( tr( "LOGARITHMIC_SCALING" ), RangeGroup );
223
224   RBFrange = new QRadioButton( tr( "FIELD_RANGE_BTN" ),   RangeGroup );
225   RBIrange = new QRadioButton( tr( "IMPOSED_RANGE_BTN" ), RangeGroup );
226   RangeRB->addButton( RBFrange, 0 );
227   RangeRB->addButton( RBIrange, 1 );
228   RBFrange->setChecked( true );
229
230   MinEdit = new QLineEdit( RangeGroup );
231   MinEdit->setMinimumWidth( 70 );
232   MinEdit->setValidator( new QDoubleValidator( this ) );
233   MinEdit->setText( "0.0" );
234   QLabel* MinLabel = new QLabel( tr( "LBL_MIN" ), RangeGroup );
235   MinLabel->setBuddy( MinEdit );
236
237   MaxEdit = new QLineEdit( RangeGroup );
238   MaxEdit->setMinimumWidth( 70 );
239   MaxEdit->setValidator( new QDoubleValidator( this ) );
240   MaxEdit->setText( "0.0" );
241   QLabel* MaxLabel = new QLabel( tr( "LBL_MAX" ), RangeGroup );
242   MaxLabel->setBuddy( MaxEdit );
243
244   RangeGroupLayout->addWidget( CBLog,    1, 0, 1, 4 );
245   RangeGroupLayout->addWidget( RBFrange, 2, 0, 1, 2 );
246   RangeGroupLayout->addWidget( RBIrange, 2, 2, 1, 2 );
247   RangeGroupLayout->addWidget( MinLabel, 3, 0 );
248   RangeGroupLayout->addWidget( MinEdit,  3, 1 );
249   RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
250   RangeGroupLayout->addWidget( MaxEdit,  3, 3 );
251
252   // Colors and Labels ========================================================
253   QGroupBox* ColLabGroup = new QGroupBox( tr( "COLORS_LABELS_GRP" ), this );
254   QHBoxLayout* ColLabGroupLayout = new QHBoxLayout( ColLabGroup );
255   ColLabGroupLayout->setSpacing( 6 );
256   ColLabGroupLayout->setMargin( 11 );
257
258   QLabel* ColorLabel = new QLabel( tr( "LBL_NB_COLORS" ), ColLabGroup );
259   ColorSpin = new QSpinBox( ColLabGroup );
260   ColorSpin->setMinimum( 2 );
261   ColorSpin->setMaximum( 256 );
262   ColorSpin->setSingleStep( 1 );
263   ColorSpin->setMinimumWidth( 70 );
264   ColorSpin->setValue( 64 );
265
266   QLabel* LabelLabel = new QLabel( tr( "LBL_NB_LABELS" ), ColLabGroup );
267   LabelSpin = new QSpinBox( ColLabGroup );
268   LabelSpin->setMinimum( 2 );
269   LabelSpin->setMaximum( 65 );
270   LabelSpin->setSingleStep( 1 );
271   LabelSpin->setMinimumWidth( 70 );
272   LabelSpin->setValue( 5 );
273
274   ColLabGroupLayout->addWidget( ColorLabel );
275   ColLabGroupLayout->addWidget( ColorSpin );
276   ColLabGroupLayout->addWidget( LabelLabel );
277   ColLabGroupLayout->addWidget( LabelSpin );
278
279   // Orientation ==========================================================
280   QGroupBox* OrientGroup = new QGroupBox( tr( "ORIENTATION_GRP" ), this );
281   QButtonGroup* OrientRB = new QButtonGroup( OrientGroup );
282   QHBoxLayout* OrientGroupLayout = new QHBoxLayout( OrientGroup );
283   OrientGroupLayout->setSpacing( 6 );
284   OrientGroupLayout->setMargin( 11 );
285
286   RBvert = new QRadioButton( tr( "VERTICAL_BTN" ), OrientGroup );
287   RBhori = new QRadioButton( tr( "HORIZONTAL_BTN" ), OrientGroup );
288   OrientRB->addButton( RBvert, 0 );
289   OrientRB->addButton( RBhori, 1 );
290   RBvert->setChecked( true );
291   OrientGroupLayout->addWidget( RBvert );
292   OrientGroupLayout->addWidget( RBhori );
293
294   // Origin ===============================================================
295   QGroupBox* OriginGroup = new QGroupBox( tr( "ORIGIN_GRP" ), this );
296   QHBoxLayout* OriginGroupLayout = new QHBoxLayout( OriginGroup );
297   OriginGroupLayout->setSpacing( 6 );
298   OriginGroupLayout->setMargin( 11 );
299
300   QLabel* XLabel = new QLabel( tr( "LBL_X" ), OriginGroup );
301   XSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, OriginGroup );
302   XSpin->setMinimumWidth( 70 );
303   XSpin->setValue( 0.01 );
304
305   QLabel* YLabel = new QLabel( tr( "LBL_Y" ), OriginGroup );
306   YSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, OriginGroup );
307   YSpin->setMinimumWidth( 70 );
308   YSpin->setValue( 0.1 );
309
310   OriginGroupLayout->addWidget( XLabel );
311   OriginGroupLayout->addWidget( XSpin );
312   OriginGroupLayout->addWidget( YLabel );
313   OriginGroupLayout->addWidget( YSpin );
314
315   // Dimensions =========================================================
316   QGroupBox* DimGroup = new QGroupBox( tr( "DIMENSIONS_GRP" ), this );
317   QHBoxLayout* DimGroupLayout = new QHBoxLayout( DimGroup );
318   DimGroupLayout->setSpacing( 6 );
319   DimGroupLayout->setMargin( 11 );
320
321   QLabel* WidthLabel = new QLabel( tr( "LBL_WIDTH" ), DimGroup );
322   WidthSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, DimGroup );
323   WidthSpin->setMinimumWidth( 70 );
324   WidthSpin->setValue( 0.1 );
325
326   QLabel* HeightLabel = new QLabel( tr( "LBL_HEIGHT" ), DimGroup );
327   HeightSpin = new QtxDoubleSpinBox( 0.0, 1.0, 0.1, DimGroup );
328   HeightSpin->setMinimumWidth( 70 );
329   HeightSpin->setValue( 0.8 );
330
331   DimGroupLayout->addWidget( WidthLabel );
332   DimGroupLayout->addWidget( WidthSpin );
333   DimGroupLayout->addWidget( HeightLabel );
334   DimGroupLayout->addWidget( HeightSpin );
335
336   myTextBtn = new QPushButton( tr( "Text properties..." ), this );
337   myBarBtn  = new QPushButton( tr( "Bar properties..." ), this );
338
339   // main layout =========================================================
340
341   topLayout->addWidget( RangeGroup,  0, 0, 1, 2 );
342   topLayout->addWidget( ColLabGroup, 1, 0, 1, 2 );
343   topLayout->addWidget( OrientGroup, 2, 0, 1, 2 );
344   topLayout->addWidget( OriginGroup, 3, 0, 1, 2 );
345   topLayout->addWidget( DimGroup,    4, 0, 1, 2 );
346   topLayout->addWidget( myTextBtn,   5, 0 );
347   topLayout->addWidget( myBarBtn,    5, 1 );
348
349   // init ================================================================
350
351   myTextDlg = new VisuGUI_TextPrefDlg( this );
352   myTextDlg->setTitleVisible( true );
353   myBarDlg = new VisuGUI_BarPrefDlg( this );
354
355   if ( RBvert->isChecked() ) {
356     myBarDlg->setRatios( myVerTS, myVerLS, myVerBW, myVerBH );
357   } else {
358     myBarDlg->setRatios( myHorTS, myHorLS, myHorBW, myHorBH );
359   }
360
361   int lp = aResourceMgr->integerValue( "VISU", propertyName + "scalar_bar_label_precision", 3 );
362   myBarDlg->setLabelsPrecision( lp );
363
364   myBarDlg->setUnitsVisible( aResourceMgr->booleanValue( "VISU", propertyName + "display_units", true ) );
365
366   // signals and slots connections ===========================================
367   connect( RangeRB,      SIGNAL( buttonClicked( int ) ),   this, SLOT( changeRange( int ) ) );
368   connect( OrientRB,     SIGNAL( buttonClicked( int ) ),   this, SLOT( changeDefaults( int ) ) );
369   connect( XSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
370   connect( YSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
371   connect( myTextBtn,    SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
372   connect( myBarBtn,     SIGNAL( clicked() ), this, SLOT( onBarPref() ) );
373   changeDefaults( 0 );
374   myIsStoreTextProp = true;
375   myBusy = false;
376 }
377
378 //----------------------------------------------------------------------------
379
380 void VisuGUI_TableScalarBarPane::onBarPref()
381 {
382   if ( RBvert->isChecked() )
383     myBarDlg->setRatios( myVerTS, myVerLS, myVerBW, myVerBH );
384   else
385     myBarDlg->setRatios( myHorTS, myHorLS, myHorBW, myHorBH );
386   if ( myBarDlg->exec() ) {
387     if ( RBvert->isChecked() )
388       myBarDlg->getRatios( myVerTS, myVerLS, myVerBW, myVerBH );
389     else
390       myBarDlg->getRatios( myHorTS, myHorLS, myHorBW, myHorBH );
391   }
392 }
393
394 //----------------------------------------------------------------------------
395 /**
396  * Initialise dialog box from presentation object
397  */
398 void VisuGUI_TableScalarBarPane::initFromPrsObject( VISU::PointMap3d_i* thePrs )
399 {
400   myBarPrs = dynamic_cast<VISU::PointMap3d_i*>( thePrs );
401   
402   if ( !myBarPrs )
403     return;
404
405   switch ( myBarPrs->GetScaling() ) {
406   case VISU::LOGARITHMIC:
407     CBLog->setChecked( true );
408     break;
409   default:
410     CBLog->setChecked( false );
411   }
412
413   setRange( myBarPrs->GetMin(), myBarPrs->GetMax(), myBarPrs->IsRangeFixed() );
414
415   setScalarBarData( myBarPrs->GetNbColors(), myBarPrs->GetLabels() );
416
417   // "Title"
418   CORBA::String_var aTitle = myBarPrs->GetTitle();
419   myTextDlg->setTitleText( aTitle.in() );
420   myTitle = aTitle.in();
421
422   vtkFloatingPointType R, G, B;
423   myBarPrs->GetTitleColor( R, G, B );
424
425   setPosAndSize( myBarPrs->GetPosX(),
426                  myBarPrs->GetPosY(),
427                  myBarPrs->GetWidth(),
428                  myBarPrs->GetHeight(),
429                  myBarPrs->GetBarOrientation() );
430   
431   myVerTS = myBarPrs->GetTitleSize();
432   myVerLS = myBarPrs->GetLabelSize();
433   myVerBW = myBarPrs->GetBarWidth();
434   myVerBH = myBarPrs->GetBarHeight();
435   myBarDlg->setRatios( myVerTS, myVerLS, myVerBW, myVerBH );
436
437   myBarDlg->setLabelsPrecision( VISU::ToPrecision( myBarPrs->GetLabelsFormat() ) );
438   myBarDlg->setUnitsVisible( myBarPrs->IsUnitsVisible() );
439
440   myTextDlg->myTitleFont->SetData( QColor( (int)(R*255.), (int)(G*255.), (int)(B*255.) ),
441                                    myBarPrs->GetTitFontType(),
442                                    myBarPrs->IsBoldTitle(),
443                                    myBarPrs->IsItalicTitle(),
444                                    myBarPrs->IsShadowTitle() );
445
446   // "Labels"
447   myBarPrs->GetLabelColor( R, G, B );
448
449   myTextDlg->myLabelFont->SetData( QColor( (int)(R*255.), (int)(G*255.), (int)(B*255.) ),
450                                    myBarPrs->GetLblFontType(),
451                                    myBarPrs->IsBoldLabel(),
452                                    myBarPrs->IsItalicLabel(),
453                                    myBarPrs->IsShadowLabel() );
454 }
455
456 //----------------------------------------------------------------------------
457 /**
458  * Store values to presentation object
459  */
460 int VisuGUI_TableScalarBarPane::storeToPrsObject( VISU::PointMap3d_i* thePrs ) {
461   if( !myBarPrs )
462     return 0;
463
464   myBarPrs->SetPosition( XSpin->value(), YSpin->value() );
465   myBarPrs->SetSize( WidthSpin->value(), HeightSpin->value() );
466
467   if(RBvert->isChecked()) {
468     myBarPrs->SetRatios(myVerTS, myVerLS, myVerBW, myVerBH);
469   } else {
470     myBarPrs->SetRatios(myHorTS, myHorLS, myHorBW, myHorBH);
471   }
472
473   std::string f = VISU::ToFormat( myBarDlg->getLabelsPrecision() );
474   myBarPrs->SetLabelsFormat( f.c_str() );
475   myBarPrs->SetUnitsVisible( myBarDlg->isUnitsVisible() );
476
477   myBarPrs->SetBarOrientation( ( RBvert->isChecked() )? VISU::ColoredPrs3dBase::VERTICAL : VISU::ColoredPrs3dBase::HORIZONTAL );
478   if ( CBLog->isChecked() )
479     myBarPrs->SetScaling( VISU::LOGARITHMIC );
480   else
481     myBarPrs->SetScaling( VISU::LINEAR );
482
483   if ( RBFrange->isChecked() ) {
484     myBarPrs->SetSourceRange();
485   } else {
486     myBarPrs->SetRange( MinEdit->text().toDouble(), MaxEdit->text().toDouble() );
487   }
488   myBarPrs->SetNbColors( ColorSpin->value() );
489   myBarPrs->SetLabels( LabelSpin->value() );
490
491   if ( myIsStoreTextProp ) {
492     // "Title"
493     myBarPrs->SetTitle( myTextDlg->getTitleText().toLatin1().constData() );
494
495     QColor aTitColor( 255, 255, 255 );
496     int aTitleFontFamily = VTK_ARIAL;
497     bool isTitleBold = false;
498     bool isTitleItalic = false;
499     bool isTitleShadow = false;
500
501     myTextDlg->myTitleFont->GetData( aTitColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow );
502
503     myBarPrs->SetBoldTitle( isTitleBold );
504     myBarPrs->SetItalicTitle( isTitleItalic );
505     myBarPrs->SetShadowTitle( isTitleShadow );
506     myBarPrs->SetTitFontType( aTitleFontFamily );
507     myBarPrs->SetTitleColor( aTitColor.red()/255.,
508                              aTitColor.green()/255.,
509                              aTitColor.blue()/255. );
510
511     // "Label"
512     QColor aLblColor( 255, 255, 255 );
513     int aLabelFontFamily = VTK_ARIAL;
514     bool isLabelBold = false;
515     bool isLabelItalic = false;
516     bool isLabelShadow = false;
517
518     myTextDlg->myLabelFont->GetData( aLblColor, aLabelFontFamily, isLabelBold, isLabelItalic, isLabelShadow );
519
520     myBarPrs->SetBoldLabel( isLabelBold);
521     myBarPrs->SetItalicLabel( isLabelItalic );
522     myBarPrs->SetShadowLabel( isLabelShadow );
523     myBarPrs->SetLblFontType( aLabelFontFamily );
524     myBarPrs->SetLabelColor( aLblColor.red()/255.,
525                              aLblColor.green()/255.,
526                              aLblColor.blue()/255. );
527     //    myIsStoreTextProp = false;
528   }
529   return 1;
530 }
531
532 //----------------------------------------------------------------------------
533 /*!
534   Sets default values and range mode
535 */
536 void VisuGUI_TableScalarBarPane::setRange( double imin, double imax, bool sbRange )
537 {
538   MinEdit->setText( QString::number( imin ) );
539   MaxEdit->setText( QString::number( imax ) );
540
541   if ( sbRange )
542     RBIrange->setChecked( true );
543   else
544     RBFrange->setChecked( true );
545
546   changeRange( sbRange );
547 }
548
549 //----------------------------------------------------------------------------
550 /*!
551   Called when Range mode is changed
552 */
553 void VisuGUI_TableScalarBarPane::changeRange( int )
554 {
555   if ( RBFrange->isChecked() ) {
556     myBarPrs->SetSourceRange();
557     MinEdit->setEnabled( false );
558     MaxEdit->setEnabled( false );
559   } else {
560     myBarPrs->SetRange( myBarPrs->GetMin(), myBarPrs->GetMax() );
561     myBarPrs->SetRange( MinEdit->text().toDouble(), MaxEdit->text().toDouble() );
562     MinEdit->setEnabled( true );
563     MaxEdit->setEnabled( true );
564   }
565
566   MinEdit->setText( QString::number( myBarPrs->GetMin() ) );
567   MaxEdit->setText( QString::number( myBarPrs->GetMax() ) );
568 }
569
570 //----------------------------------------------------------------------------
571 /*!
572   Called when X,Y position is changed
573 */
574 void VisuGUI_TableScalarBarPane::XYChanged( double )
575 {
576   QtxDoubleSpinBox* snd = (QtxDoubleSpinBox*)sender();
577   if ( snd == XSpin ) {
578     WidthSpin->setMaximum( 1.0 - XSpin->value() );
579   }
580   if ( snd == YSpin ) {
581     HeightSpin->setMaximum( 1.0 - YSpin->value() );
582   }
583 }
584
585 //----------------------------------------------------------------------------
586 /*!
587   
588 */
589 void VisuGUI_TableScalarBarPane::changeScalarMode( int )
590 {
591 //do nothing
592 }
593
594 //----------------------------------------------------------------------------
595 /*!
596   Sets size and position
597 */
598 void VisuGUI_TableScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
599 {
600   if ( vert ) {
601     myVerX = x;
602     myVerY = y;
603     myVerW = w;
604     myVerH = h;
605     RBvert->setChecked( true );
606   }
607   else {
608     myHorX = x;
609     myHorY = y;
610     myHorW = w;
611     myHorH = h;
612     RBhori->setChecked( true );
613   }
614   changeDefaults( 0 );
615 }
616
617 //----------------------------------------------------------------------------
618 /*!
619   Sets colors and labels number
620 */
621 void VisuGUI_TableScalarBarPane::setScalarBarData( int colors, int labels )
622 {
623   ColorSpin->setValue( colors );
624   LabelSpin->setValue( labels );
625 }
626
627 //----------------------------------------------------------------------------
628 void VisuGUI_TableScalarBarPane::onTextPref()
629 {
630   myTextDlg->storeBeginValues();
631   myIsStoreTextProp = myTextDlg->exec() || myIsStoreTextProp;
632 }
633
634 //----------------------------------------------------------------------------
635 VisuGUI_TableScalarBarPane::~VisuGUI_TableScalarBarPane()
636 {
637 }
638
639 //----------------------------------------------------------------------------
640 /*!
641   Called when orientation is changed
642 */
643 void VisuGUI_TableScalarBarPane::changeDefaults( int )
644 {
645   if ( RBvert->isChecked() ) {
646     XSpin->setValue( myVerX );
647     YSpin->setValue( myVerY );
648     WidthSpin->setValue( myVerW );
649     HeightSpin->setValue( myVerH );
650   }
651   else {
652     XSpin->setValue( myHorX );
653     YSpin->setValue( myHorY );
654     WidthSpin->setValue( myHorW );
655     HeightSpin->setValue( myHorH );
656   }
657 }
658
659 //=======================================================================
660 //function : Check
661 //purpose  : Called when <OK> button is clicked, validates data and closes dialog
662 //=======================================================================
663 bool VisuGUI_TableScalarBarPane::check()
664 {
665   double minVal = MinEdit->text().toDouble();
666   double maxVal = MaxEdit->text().toDouble();
667   if ( RBIrange->isChecked() ) {
668     if (minVal >= maxVal) {
669       SUIT_MessageBox::warning( this,tr("WRN_VISU"),
670                                 tr("MSG_MINMAX_VALUES") );
671       return false;
672     }
673   }
674
675   // check if logarithmic mode is on and check imposed range to not contain negative values
676   if ( CBLog->isChecked() ) {
677     if ( minVal <= 0.0 || maxVal <= 0.0) {
678       if ( RBIrange->isChecked() ) {
679         SUIT_MessageBox::warning( this,
680                                   tr("WRN_VISU"),
681                                   tr("WRN_LOGARITHMIC_RANGE") );
682       } else {
683         if ( minVal == 0)
684           SUIT_MessageBox::warning( this,
685                                     tr("WRN_VISU"),
686                                     tr("WRN_LOGARITHMIC_RANGE") );
687         else
688           SUIT_MessageBox::warning( this,
689                                     tr("WRN_VISU"),
690                                     tr("WRN_LOGARITHMIC_FIELD_RANGE") );
691         RBIrange->setChecked(true);
692         changeRange(1);
693       }
694       return false;
695     }
696   }
697   return true;
698 }
699
700 //=======================================================================
701 //function : Constructor
702 //purpose  :
703 //=======================================================================
704 VisuGUI_Table3DDlg::VisuGUI_Table3DDlg ( SalomeApp_Module* theModule )
705   : QDialog ( VISU::GetDesktop( theModule ) )
706 {
707   setModal( false );
708   setWindowTitle( tr( "Point Map 3D Definition" ) );
709   setSizeGripEnabled( true );
710
711   QVBoxLayout* TopLayout = new QVBoxLayout( this );
712   TopLayout->setSpacing( 6 );
713   TopLayout->setMargin( 11 );
714
715   myTabBox = new QTabWidget( this );
716   myIsoPane = new VisuGUI_Table3DPane( this );
717   myScalarBarPane = new VisuGUI_TableScalarBarPane( this );
718
719   myTabBox->addTab( myIsoPane,       tr( "DLG_PREF_TITLE" ) );
720   myTabBox->addTab( myScalarBarPane, tr( "DLG_PROP_TITLE" ) );
721
722   QGroupBox* GroupButtons = new QGroupBox( this );
723   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
724   GroupButtonsLayout->setSpacing( 6 );
725   GroupButtonsLayout->setMargin( 11 );
726
727   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
728   buttonOk->setAutoDefault( true );
729   buttonOk->setDefault( true );
730   QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons );
731   buttonApply->setAutoDefault( true );
732   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons );
733   buttonCancel->setAutoDefault( true );
734   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ), GroupButtons );
735   buttonHelp->setAutoDefault( true );
736
737   GroupButtonsLayout->addWidget( buttonOk );
738   GroupButtonsLayout->addWidget( buttonApply );
739   GroupButtonsLayout->addSpacing( 10 );
740   GroupButtonsLayout->addStretch();
741   GroupButtonsLayout->addWidget( buttonCancel );
742   GroupButtonsLayout->addWidget( buttonHelp );
743
744   TopLayout->addWidget( myTabBox );
745   TopLayout->addWidget( GroupButtons );
746
747   // signals and slots connections
748   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
749   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
750   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
751   connect( buttonApply,  SIGNAL( clicked() ), this, SLOT( onApply() ) );
752 }
753
754 //=======================================================================
755 //function : Destructor
756 //purpose  :
757 //=======================================================================
758 VisuGUI_Table3DDlg::~VisuGUI_Table3DDlg()
759 {
760 }
761
762 //=======================================================================
763 //function : accept
764 //purpose  :
765 //=======================================================================
766 void VisuGUI_Table3DDlg::accept()
767 {
768   if (myScalarBarPane->check())
769     QDialog::accept();
770 }
771
772 //=======================================================================
773 //function : onApply
774 //purpose  :
775 //=======================================================================
776 void VisuGUI_Table3DDlg::onApply()
777 {
778   if (myScalarBarPane->check()) {
779     storeToPrsObject( myPrsCopy );
780     myPrsCopy->UpdateActors();
781   }
782 }
783
784 //=======================================================================
785 //function : onHelp
786 //purpose  :
787 //=======================================================================
788 void VisuGUI_Table3DDlg::onHelp()
789 {
790   QString aHelpFileName = "table_3d_page.html";
791   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
792   if (app) {
793     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
794     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
795   }
796   else {
797     QString platform;
798 #ifdef WIN32
799     platform = "winapplication";
800 #else
801     platform = "application";
802 #endif
803     SUIT_MessageBox::warning( this, QObject::tr("WRN_WARNING"),
804                               tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
805                               arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
806   }
807
808 }
809
810 //=======================================================================
811 //function : storeToPrsObject
812 //purpose  :
813 //=======================================================================
814 int VisuGUI_Table3DDlg::storeToPrsObject( VISU::PointMap3d_i* thePrs )
815 {
816   int anIsOk = myIsoPane->storeToPrsObject( thePrs );
817   anIsOk &= myScalarBarPane->storeToPrsObject( thePrs );
818
819   return anIsOk;
820 }
821
822 //=======================================================================
823 //function : initFromPrsObject
824 //purpose  :
825 //=======================================================================
826 void VisuGUI_Table3DDlg::initFromPrsObject( VISU::PointMap3d_i* thePrs )
827 {
828   myPrsCopy = thePrs;
829   myIsoPane->initFromPrsObject( thePrs );
830   myScalarBarPane->initFromPrsObject( thePrs );
831 }