Salome HOME
Preferences for VISU module.
[modules/visu.git] / src / VISUGUI / VisuGUI_ScalarBarDlg.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_ScalarBarDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_ScalarBarDlg.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_FontWg.h"
34
35 #include "VISUConfig.hh"
36 #include "VISU_Convertor.hxx"
37
38 #include "VISU_ScalarMapPL.hxx"
39 #include "VISU_ScalarMap_i.hh"
40
41 #include "SalomeApp_Application.h"
42
43 #include "SUIT_MessageBox.h"
44 #include "SUIT_ResourceMgr.h"
45
46 #include <limits.h>
47 #include <qlayout.h>
48 #include <qvalidator.h>
49 #include <qcolordialog.h>
50
51 using namespace std;
52
53
54 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane (QWidget * parent, bool SetPref):
55   QVBox(parent)
56 {
57   myVerX = 0.01;  myVerY = 0.10;  myVerW = 0.10;  myVerH = 0.80;
58   myHorX = 0.20;  myHorY = 0.01;  myHorW = 0.60;  myHorH = 0.12;
59   Imin = 0.0; Imax = 0.0; /*Fmin = 0.0; Fmax = 0.0;*/ Rmin = 0.0; Rmax = 0.0;
60   myRangeMode = -1;
61
62   setSpacing(6);
63   //setMargin(11);
64
65   // Range ============================================================
66   RangeGroup = new QButtonGroup (tr("SCALAR_RANGE_GRP"), this, "RangeGroup");
67   RangeGroup->setColumnLayout(0, Qt::Vertical );
68   RangeGroup->layout()->setSpacing( 0 );
69   RangeGroup->layout()->setMargin( 0 );
70   QGridLayout* RangeGroupLayout = new QGridLayout( RangeGroup->layout() );
71   RangeGroupLayout->setAlignment( Qt::AlignTop );
72   RangeGroupLayout->setSpacing( 6 );
73   RangeGroupLayout->setMargin( 11 );
74
75   myModeLbl = new QLabel("Scalar Mode", RangeGroup);
76
77   myModeCombo = new QComboBox(RangeGroup);
78   myModeCombo->insertItem("Modulus");
79   myModeCombo->insertItem("Component 1");
80   myModeCombo->insertItem("Component 2");
81   myModeCombo->insertItem("Component 3");
82
83   CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), RangeGroup);
84   CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
85
86   RBFrange = new QRadioButton (tr("FIELD_RANGE_BTN"), RangeGroup, "RBFrange");
87   RBIrange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), RangeGroup, "RBIrange");
88   RBFrange->setChecked( true );
89
90   MinEdit = new QLineEdit( RangeGroup, "MinEdit" );
91   MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
92   MinEdit->setMinimumWidth( 70 );
93   MinEdit->setValidator( new QDoubleValidator(this) );
94   MinEdit->setText( "0.0" );
95   QLabel* MinLabel = new QLabel (tr("LBL_MIN"), RangeGroup, "MinLabel");
96   MinLabel->setBuddy(MinEdit);
97
98   MaxEdit = new QLineEdit( RangeGroup, "MaxEdit" );
99   MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
100   MaxEdit->setMinimumWidth( 70 );
101   MaxEdit->setValidator( new QDoubleValidator(this) );
102   MaxEdit->setText( "0.0" );
103   QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), RangeGroup, "MaxLabel");
104   MaxLabel->setBuddy(MaxEdit);
105
106   RangeGroupLayout->addWidget( myModeLbl, 0, 0 );
107   RangeGroupLayout->addMultiCellWidget( myModeCombo, 0, 0, 1, 3);
108   RangeGroupLayout->addMultiCellWidget( CBLog, 1, 1, 0, 3);
109   RangeGroupLayout->addMultiCellWidget( RBFrange, 2, 2, 0, 1);
110   RangeGroupLayout->addMultiCellWidget( RBIrange, 2, 2, 2, 3);
111   RangeGroupLayout->addWidget( MinLabel, 3, 0 );
112   RangeGroupLayout->addWidget( MinEdit,  3, 1 );
113   RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
114   RangeGroupLayout->addWidget( MaxEdit,  3, 3 );
115
116   //TopLayout->addWidget( RangeGroup );
117
118   // Colors and Labels ========================================================
119   QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this, "ColLabGroup");
120   ColLabGroup->setColumnLayout(0, Qt::Vertical );
121   ColLabGroup->layout()->setSpacing( 0 );
122   ColLabGroup->layout()->setMargin( 0 );
123   QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup->layout() );
124   ColLabGroupLayout->setAlignment( Qt::AlignTop );
125   ColLabGroupLayout->setSpacing( 6 );
126   ColLabGroupLayout->setMargin( 11 );
127
128   QLabel* ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup, "ColorLabel");
129   ColorSpin = new QSpinBox( 2, 256, 1, ColLabGroup );
130   ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131   ColorSpin->setMinimumWidth( 70 );
132   ColorSpin->setValue( 64 );
133
134   QLabel* LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup, "LabelLabel");
135   LabelSpin = new QSpinBox( 2, 65, 1, ColLabGroup );
136   LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
137   LabelSpin->setMinimumWidth( 70 );
138   LabelSpin->setValue( 5 );
139
140   ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
141   ColLabGroupLayout->addWidget( ColorSpin,  0, 1);
142   ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
143   ColLabGroupLayout->addWidget( LabelSpin,  0, 3);
144
145   //TopLayout->addWidget( ColLabGroup );
146
147   // Orientation ==========================================================
148   QButtonGroup* OrientGroup = new QButtonGroup (tr("ORIENTATION_GRP"), this, "OrientGroup");
149   OrientGroup->setColumnLayout(0, Qt::Vertical );
150   OrientGroup->layout()->setSpacing( 0 );
151   OrientGroup->layout()->setMargin( 0 );
152   QGridLayout* OrientGroupLayout = new QGridLayout( OrientGroup->layout() );
153   OrientGroupLayout->setAlignment( Qt::AlignTop );
154   OrientGroupLayout->setSpacing( 6 );
155   OrientGroupLayout->setMargin( 11 );
156
157   RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGroup, "RBvert");
158   RBvert->setChecked( true );
159   RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGroup, "RBhori");
160   OrientGroupLayout->addWidget( RBvert, 0, 0 );
161   OrientGroupLayout->addWidget( RBhori, 0, 1 );
162
163   //  TopLayout->addWidget( OrientGroup );
164
165   // Origin ===============================================================
166   QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this, "OriginGroup");
167   OriginGroup->setColumnLayout(0, Qt::Vertical );
168   OriginGroup->layout()->setSpacing( 0 );
169   OriginGroup->layout()->setMargin( 0 );
170   QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup->layout() );
171   OriginGroupLayout->setAlignment( Qt::AlignTop );
172   OriginGroupLayout->setSpacing( 6 );
173   OriginGroupLayout->setMargin( 11 );
174
175   QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup, "XLabel");
176   XSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
177   XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
178   XSpin->setMinimumWidth( 70 );
179   XSpin->setValue( 0.01 );
180
181   QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup, "YLabel");
182   YSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, OriginGroup );
183   YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
184   YSpin->setMinimumWidth( 70 );
185   YSpin->setValue( 0.01 );
186
187   OriginGroupLayout->addWidget( XLabel, 0, 0);
188   OriginGroupLayout->addWidget( XSpin,  0, 1);
189   OriginGroupLayout->addWidget( YLabel, 0, 2);
190   OriginGroupLayout->addWidget( YSpin,  0, 3);
191
192   //TopLayout->addWidget( OriginGroup );
193
194   // Dimensions =========================================================
195   QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this, "DimGroup");
196   DimGroup->setColumnLayout(0, Qt::Vertical );
197   DimGroup->layout()->setSpacing( 0 );
198   DimGroup->layout()->setMargin( 0 );
199   QGridLayout* DimGroupLayout = new QGridLayout( DimGroup->layout() );
200   DimGroupLayout->setAlignment( Qt::AlignTop );
201   DimGroupLayout->setSpacing( 6 );
202   DimGroupLayout->setMargin( 11 );
203
204   QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup, "WidthLabel");
205   WidthSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
206   WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
207   WidthSpin->setMinimumWidth( 70 );
208   WidthSpin->setValue( 0.1 );
209
210   QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup, "HeightLabel");
211   HeightSpin = new QtxDblSpinBox( 0.0, 1.0, 0.1, DimGroup );
212   HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
213   HeightSpin->setMinimumWidth( 70 );
214   HeightSpin->setValue( 0.8 );
215
216   DimGroupLayout->addWidget( WidthLabel, 0, 0);
217   DimGroupLayout->addWidget( WidthSpin,  0, 1);
218   DimGroupLayout->addWidget( HeightLabel, 0, 2);
219   DimGroupLayout->addWidget( HeightSpin,  0, 3);
220
221   //TopLayout->addWidget( DimGroup );
222
223   // Save check box ===========================================================
224   QHBox* aSaveBox = new QHBox(this);
225   if (!SetPref) {
226     CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), aSaveBox, "CBSave");
227     //TopLayout->addWidget(CBSave);
228   }
229   else {
230     CBSave = 0;
231   }
232   myTextBtn = new QPushButton("Text properties...", aSaveBox);
233   myTextDlg = new VisuGUI_TextPrefDlg(this);
234   myTextDlg->setTitleVisible(!SetPref);
235
236   // signals and slots connections ===========================================
237   connect( RangeGroup,   SIGNAL( clicked( int ) ), this, SLOT( changeRange( int ) ) );
238   connect( OrientGroup,  SIGNAL( clicked( int ) ), this, SLOT( changeDefaults( int ) ) );
239   connect( XSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
240   connect( YSpin,        SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
241   connect( myTextBtn,    SIGNAL( clicked() ), this, SLOT( onTextPref() ) );
242
243   changeRange( 0 );
244   changeDefaults( 0 );
245   myIsStoreTextProp = false;
246 }
247
248
249 /**
250  * Initializes dialog box values from resources
251  */
252 void VisuGUI_ScalarBarPane::initFromResources() {
253   int sbCol=64,sbLab=5,orient=0;
254   float sbX1=0.01,sbY1=0.1,sbW=0.1,sbH=0.8;
255   float sbVmin=0., sbVmax=0.;
256   bool sbRange=false;
257   QString aString;
258
259   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
260
261   int aScalarMode = aResourceMgr->integerValue("VISU", "scalar_bar_mode", 0);
262   myModeCombo->setCurrentItem(aScalarMode);
263
264   orient = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", orient);
265   if(orient != 0){
266     orient=1;
267     sbX1=0.2;
268     sbY1=0.01;
269     sbW=0.6;
270     sbH=0.12;
271   }
272   
273   QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
274
275   sbX1 = aResourceMgr->doubleValue("VISU", propertyName + "x", sbX1);
276   sbY1 = aResourceMgr->doubleValue("VISU", propertyName + "y", sbY1);
277
278   sbW = aResourceMgr->doubleValue("VISU", propertyName + "width", sbW);
279   sbH = aResourceMgr->doubleValue("VISU", propertyName + "height",sbH);
280   
281   sbCol = aResourceMgr->integerValue("VISU" ,"scalar_bar_num_colors", sbCol);
282   sbLab = aResourceMgr->integerValue("VISU", "scalar_bar_num_labels", sbLab);
283
284   int rangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0);
285   if (rangeType == 1) sbRange = true;
286   sbVmin = aResourceMgr->doubleValue("VISU", "scalar_range_min", sbVmin);
287   sbVmax = aResourceMgr->doubleValue("VISU", "scalar_range_max", sbVmax);
288
289   bool isLog = aResourceMgr->booleanValue("VISU", "scalar_bar_logarithmic", false);
290   setLogarithmic(isLog);
291   
292   if((sbX1 < 0.) || (sbY1 < 0.) ||
293      ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
294     if(orient == 0) {
295       sbX1=0.01;
296       sbY1=0.1;
297       sbW=0.1;
298       sbH=0.8;
299     } else {
300       sbX1=0.2;
301       sbY1=0.01;
302       sbW=0.6;
303       sbH=0.12;
304     }
305   }
306   if(sbCol < 2) sbCol=2;
307   if(sbCol > 64) sbCol=64;
308   if(sbLab < 2) sbLab=2;
309   if(sbLab > 65) sbLab=65;
310
311   if(sbVmin > sbVmax) {
312     sbVmin=0.;
313     sbVmax=0.;
314   }
315
316   setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
317   setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 0);
318   setScalarBarData( sbCol, sbLab );
319
320   // "Title"
321   bool isBold = false, isItalic = false, isShadow = false;
322   int aFontFamily = VTK_ARIAL;
323
324   if ( aResourceMgr->hasValue( "VISU", "scalar_bar_title_font" ) )
325     {
326       QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_title_font" );
327       
328       if ( f.family() == "Arial" )
329         aFontFamily = VTK_ARIAL;
330       else if ( f.family() == "Courier" )
331         aFontFamily = VTK_COURIER;
332       else if ( f.family() == "Times" )
333         aFontFamily = VTK_TIMES;
334       
335       isBold = f.bold();
336       isItalic = f.italic();
337       isShadow =  f.underline();
338     }
339   
340   QColor aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_title_color", QColor( 255, 255, 255 ) );
341   
342   myTextDlg->myTitleFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
343
344   // "Labels"
345   isBold = isItalic = isShadow = false;
346   aFontFamily = VTK_ARIAL;
347
348   if ( aResourceMgr->hasValue( "VISU", "scalar_bar_label_font" ) )
349     {
350       QFont f = aResourceMgr->fontValue( "VISU", "scalar_bar_label_font" );
351       
352       if ( f.family() == "Arial" )
353         aFontFamily = VTK_ARIAL;
354       else if ( f.family() == "Courier" )
355         aFontFamily = VTK_COURIER;
356       else if ( f.family() == "Times" )
357         aFontFamily = VTK_TIMES;
358       
359       isBold = f.bold();
360       isItalic = f.italic();
361       isShadow =  f.underline();
362     }
363   
364   aTextColor = aResourceMgr->colorValue( "VISU", "scalar_bar_label_color", QColor( 255, 255, 255 ) );
365   
366   myTextDlg->myLabelFont->SetData(aTextColor, aFontFamily, isBold, isItalic, isShadow);
367 }
368
369 /**
370  * Stores dialog values to resources
371  */
372 void VisuGUI_ScalarBarPane::storeToResources() {
373   int orient = (RBvert->isChecked())? 0 : 1;
374   float sbX1   = XSpin->value();
375   float sbY1   = YSpin->value();
376   float sbW    = WidthSpin->value();
377   float sbH    = HeightSpin->value();
378   int sbCol  = ColorSpin->value();
379   int sbLab  = LabelSpin->value();
380
381   if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
382     if(orient == 0) {
383       sbX1=0.01;
384       sbY1=0.1;
385       sbW=0.17;
386       sbH=0.8;
387     } else {
388       sbX1=0.2;
389       sbY1=0.01;
390       sbW=0.6;
391       sbH=0.12;
392     }
393   }
394
395   bool sbRange = RBIrange->isChecked();
396   float sbVmin = (float)(MinEdit->text().toDouble());
397   float sbVmax = (float)(MaxEdit->text().toDouble());
398
399   if(sbVmin > sbVmax) {
400     sbVmin=0.;
401     sbVmax=0.;
402   }
403
404   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
405
406   aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient);
407
408   QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
409
410   aResourceMgr->setValue("VISU", propertyName + "x", sbX1);
411   aResourceMgr->setValue("VISU", propertyName + "y", sbY1);
412   aResourceMgr->setValue("VISU", propertyName + "width", sbW);
413   aResourceMgr->setValue("VISU", propertyName + "height", sbH);
414
415   aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol);
416   aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab);
417
418   if(sbRange)
419     {
420       aResourceMgr->setValue("VISU", "scalar_range_type", 1);
421       aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin);
422       aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax);
423     }
424   else
425     aResourceMgr->setValue("VISU", "scalar_range_type", 0);
426   
427   aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic());
428  
429   ////
430
431   if (myIsStoreTextProp) {
432     // "Title"
433     QColor aTitleColor (255, 255, 255);
434     int aTitleFontFamily = VTK_ARIAL;
435     bool isTitleBold = false;
436     bool isTitleItalic = false;
437     bool isTitleShadow = false;
438
439     myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
440                                     isTitleBold, isTitleItalic, isTitleShadow);
441
442     QFont aTitleFont;
443     
444     aTitleFont.setBold(isTitleBold);
445     aTitleFont.setItalic(isTitleItalic);
446     aTitleFont.setUnderline(isTitleShadow);
447     
448     QString titleFontFamily;
449     switch (aTitleFontFamily) {
450     case VTK_ARIAL:
451       titleFontFamily = "Arial";
452       break;
453     case VTK_COURIER:
454       titleFontFamily = "Courier";
455       break;
456     case VTK_TIMES:
457       titleFontFamily = "Times";
458       break;
459     }
460     aTitleFont.setFamily(titleFontFamily);
461     
462     aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont);
463     
464     aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor);
465     
466     // "Label"
467     QColor aLabelColor (255, 255, 255);
468     int aLabelFontFamily = VTK_ARIAL;
469     bool isLabelBold = false;
470     bool isLabelItalic = false;
471     bool isLabelShadow = false;
472
473     myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
474                                     isLabelBold, isLabelItalic, isLabelShadow);
475
476
477     QFont aLabelFont;
478     
479     aLabelFont.setBold(isLabelBold);
480     aLabelFont.setItalic(isLabelItalic);
481     aLabelFont.setUnderline(isLabelShadow);
482
483     QString labelFontFamily;
484     switch (aLabelFontFamily) {
485     case VTK_ARIAL:
486       labelFontFamily = "Arial";
487       break;
488     case VTK_COURIER:
489       labelFontFamily = "Courier";
490       break;
491     case VTK_TIMES:
492       labelFontFamily = "Times";
493       break;
494     }
495
496     aLabelFont.setFamily(labelFontFamily);
497     
498     aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont);
499
500     aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor);
501   }
502 }
503
504 /**
505  * Initialise dialog box from presentation object
506  */
507 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
508   initFromResources();
509   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
510   setPosAndSize( thePrs->GetPosX(),
511                  thePrs->GetPosY(),
512                  thePrs->GetWidth(),
513                  thePrs->GetHeight(),
514                  thePrs->GetBarOrientation());
515   switch(thePrs->GetScaling()){
516   case VISU::LOGARITHMIC :
517     setLogarithmic(true);
518     break;
519   default:
520     setLogarithmic(false);
521   }
522   float aRange[2];
523   thePrs->GetScalarMapPL()->GetSourceRange(aRange);
524   Rmin = aRange[0]; Rmax = aRange[1];
525   setRange( thePrs->GetMin(), thePrs->GetMax(),
526             /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
527   setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
528   bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
529   myModeLbl->setEnabled(isScalarMode);
530   myModeCombo->setEnabled(isScalarMode);
531
532   // "Title"
533   myTextDlg->setTitleText(QString(thePrs->GetTitle()));
534
535   float R, G, B;
536   thePrs->GetTitleColor(&R, &G, &B);
537
538   myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
539                                   thePrs->GetTitFontType(),
540                                   thePrs->IsBoldTitle(),
541                                   thePrs->IsItalicTitle(),
542                                   thePrs->IsShadowTitle());
543
544   // "Labels"
545   thePrs->GetLabelColor(&R, &G, &B);
546
547   myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
548                                   thePrs->GetLblFontType(),
549                                   thePrs->IsBoldLabel(),
550                                   thePrs->IsItalicLabel(),
551                                   thePrs->IsShadowLabel());
552 }
553
554 /**
555  * Store values to presentation object
556  */
557 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
558   thePrs->SetScalarMode(myModeCombo->currentItem());
559   thePrs->SetPosition(XSpin->value(), YSpin->value());
560   thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
561   thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
562   if(isLogarithmic())
563     thePrs->SetScaling(VISU::LOGARITHMIC);
564   else
565     thePrs->SetScaling(VISU::LINEAR);
566
567   if (RBFrange->isChecked()) {
568     thePrs->SetSourceRange();
569   } else {
570     thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
571   }
572   thePrs->SetNbColors(ColorSpin->value());
573   thePrs->SetLabels(LabelSpin->value());
574
575   if (isToSave()) storeToResources();
576
577   if (myIsStoreTextProp) {
578     // "Title"
579     thePrs->SetTitle(myTextDlg->getTitleText().latin1());
580
581     QColor aTitColor (255, 255, 255);
582     int aTitleFontFamily = VTK_ARIAL;
583     bool isTitleBold = false;
584     bool isTitleItalic = false;
585     bool isTitleShadow = false;
586
587     myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
588                                     isTitleBold, isTitleItalic, isTitleShadow);
589
590     thePrs->SetBoldTitle(isTitleBold);
591     thePrs->SetItalicTitle(isTitleItalic);
592     thePrs->SetShadowTitle(isTitleShadow);
593     thePrs->SetTitFontType(aTitleFontFamily);
594     thePrs->SetTitleColor(aTitColor.red()/255.,
595                           aTitColor.green()/255.,
596                           aTitColor.blue()/255.);
597
598     // "Label"
599     QColor aLblColor (255, 255, 255);
600     int aLabelFontFamily = VTK_ARIAL;
601     bool isLabelBold = false;
602     bool isLabelItalic = false;
603     bool isLabelShadow = false;
604
605     myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
606                                     isLabelBold, isLabelItalic, isLabelShadow);
607
608     thePrs->SetBoldLabel(isLabelBold);
609     thePrs->SetItalicLabel(isLabelItalic);
610     thePrs->SetShadowLabel(isLabelShadow);
611     thePrs->SetLblFontType(aLabelFontFamily);
612     thePrs->SetLabelColor(aLblColor.red()/255.,
613                           aLblColor.green()/255.,
614                           aLblColor.blue()/255.);
615   }
616
617   return 1;
618 }
619
620 /*!
621   Called when orientation is changed
622 */
623 void VisuGUI_ScalarBarPane::changeDefaults( int )
624 {
625   if ( RBvert->isChecked() ) {
626     XSpin->setValue( myVerX );
627     YSpin->setValue( myVerY );
628     WidthSpin->setValue( myVerW );
629     HeightSpin->setValue( myVerH );
630   }
631   else {
632     XSpin->setValue( myHorX );
633     YSpin->setValue( myHorY );
634     WidthSpin->setValue( myHorW );
635     HeightSpin->setValue( myHorH );
636   }
637 }
638
639 /*!
640   Called when Range mode is changed
641 */
642 void VisuGUI_ScalarBarPane::changeRange( int )
643 {
644   int mode = -1;
645   if ( RBFrange->isChecked() )
646     mode = 0;
647   if ( RBIrange->isChecked() )
648     mode = 1;
649   if ( myRangeMode == mode )
650     return;
651   //MinSpin->setMaxValue( Fmin );
652   //MaxSpin->setMinValue( Fmax );
653   if ( RBFrange->isChecked() ) {
654     //MinLabel->setEnabled( false );
655     MinEdit->setEnabled( false );
656     //MaxLabel->setEnabled( false );
657     MaxEdit->setEnabled( false );
658     if ( mode != -1 ) {
659       Imin = MinEdit->text().toDouble();
660       Imax = MaxEdit->text().toDouble();
661     }
662     MinEdit->setText( QString::number( Rmin ) );
663     MaxEdit->setText( QString::number( Rmax ) );
664   }
665   else {
666     //MinLabel->setEnabled( true );
667     MinEdit->setEnabled( true );
668     //MaxLabel->setEnabled( true );
669     MaxEdit->setEnabled( true );
670     MinEdit->setText( QString::number( Imin ) );
671     MaxEdit->setText( QString::number( Imax ) );
672   }
673   myRangeMode = mode;
674 }
675
676 /*!
677   Called when X,Y position is changed
678 */
679 void VisuGUI_ScalarBarPane::XYChanged( double )
680 {
681   QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
682   if ( snd == XSpin ) {
683     WidthSpin->setMaxValue( 1.0 - XSpin->value() );
684   }
685   if ( snd == YSpin ) {
686     HeightSpin->setMaxValue( 1.0 - YSpin->value() );
687   }
688 }
689
690 /*!
691   Sets default values and range mode
692 */
693 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
694 {
695   Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
696   if ( RBIrange->isChecked() ) {
697     MinEdit->setText( QString::number( Imin ) );
698     MaxEdit->setText( QString::number( Imax ) );
699   }
700   else {
701     MinEdit->setText( QString::number( Rmin ) );
702     MaxEdit->setText( QString::number( Rmax ) );
703   }
704   myRangeMode = -1;
705   if( sbRange )
706     RBIrange->setChecked( true );
707   else
708     RBFrange->setChecked( true );
709   changeRange( 0 );
710 }
711
712 /*!
713   Sets size and position
714 */
715 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
716 {
717   if ( vert ) {
718     myVerX = x;
719     myVerY = y;
720     myVerW = w;
721     myVerH = h;
722     RBvert->setChecked( true );
723   }
724   else {
725     myHorX = x;
726     myHorY = y;
727     myHorW = w;
728     myHorH = h;
729     RBhori->setChecked( true );
730   }
731   changeDefaults( 0 );
732 }
733
734 /*!
735   Sets colors and labels number
736 */
737 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
738 {
739   ColorSpin->setValue( colors );
740   LabelSpin->setValue( labels );
741 }
742
743 /*!
744   Gets orientation
745 */
746 int  VisuGUI_ScalarBarPane::getOrientation()
747 {
748   if (RBvert->isChecked() )
749     return  1;
750   else
751     return 0;
752 }
753
754 /*!
755   Called when <OK> button is clicked, validates data and closes dialog
756 */
757 bool VisuGUI_ScalarBarPane::check()
758 {
759   double minVal = MinEdit->text().toDouble();
760   double maxVal = MaxEdit->text().toDouble();
761   if ( RBIrange->isChecked() ) {
762     if (minVal >= maxVal) {
763       SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
764                              tr("MSG_MINMAX_VALUES"),
765                              tr("BUT_OK"));
766       return false;
767     }
768   }
769   // check if logarithmic mode is on and check imposed range to not contain negative values
770   if ( CBLog->isChecked() ) {
771     if ( RBIrange->isChecked() ) {
772       if ( (minVal > 0) && (maxVal > 0) ) {
773         // nothing to do
774       }
775       else {
776         SUIT_MessageBox::warn1( this,
777                                 tr("WRN_VISU"),
778                                 tr("WRN_LOGARITHMIC_RANGE"),
779                                 tr("BUT_OK"));
780         return false;
781       }
782     }
783     else {
784       if ( Rmin > 0 && Rmax > 0 ) {
785         // nothing to do
786       }
787       else {
788         SUIT_MessageBox::warn1( this,
789                                 tr("WRN_VISU"),
790                                 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
791                                 tr("BUT_OK"));
792         RBIrange->setChecked(1);
793         changeRange(1);
794         //MinEdit->setText( QString::number( Rmin ) );
795         //MaxEdit->setText( QString::number( Rmax ) );
796         return false;
797       }
798     }
799   }
800   return true;
801 }
802
803 void VisuGUI_ScalarBarPane::onTextPref()
804 {
805   myIsStoreTextProp = myTextDlg->exec();
806 }
807
808
809 //#######################################################################################
810
811 /*!
812   Constructor
813 */
814 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
815     : QDialog(VISU::GetDesktop(theModule), 0, true,
816               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
817 {
818   setName("VisuGUI_ScalarBarDlg");
819   setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
820   setSizeGripEnabled(TRUE);
821
822   QVBoxLayout* TopLayout = new QVBoxLayout(this);
823   TopLayout->setSpacing(6);
824   TopLayout->setMargin(11);
825
826   myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
827   TopLayout->addWidget(myScalarPane);
828
829   // Common buttons ===========================================================
830   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
831   GroupButtons->setColumnLayout(0, Qt::Vertical );
832   GroupButtons->layout()->setSpacing( 0 );
833   GroupButtons->layout()->setMargin( 0 );
834   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
835   GroupButtonsLayout->setAlignment( Qt::AlignTop );
836   GroupButtonsLayout->setSpacing( 6 );
837   GroupButtonsLayout->setMargin( 11 );
838
839   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
840   buttonOk->setAutoDefault( TRUE );
841   buttonOk->setDefault( TRUE );
842   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
843   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
844
845   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
846   buttonCancel->setAutoDefault( TRUE );
847   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
848
849   TopLayout->addWidget( GroupButtons );
850
851   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
852   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
853 }
854
855 /*!
856   Called when <OK> button is clicked, validates data and closes dialog
857 */
858 void VisuGUI_ScalarBarDlg::accept()
859 {
860   if (myScalarPane->check()) QDialog::accept();
861 }
862
863
864 //#######################################################################################
865 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
866   : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
867 {
868   setName("VisuGUI_TextPrefDlg");
869   setCaption(tr("TIT_TEXT_PREF"));
870   setSizeGripEnabled(TRUE);
871
872   QVBoxLayout* TopLayout = new QVBoxLayout(this);
873   TopLayout->setSpacing(6);
874   TopLayout->setMargin(11);
875
876   // "Title" grp
877   QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
878
879   //   edit line
880   myTitleEdt = new QLineEdit (aTitleGrp);
881
882   //   font
883   QHBox* aHBox = new QHBox (aTitleGrp);
884   aHBox->setSpacing(5);
885   myTitleFont = new VisuGUI_FontWg (aHBox);
886
887   TopLayout->addWidget(aTitleGrp);
888
889   // "Labels" grp
890   QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
891
892   //   font
893   aHBox = new QHBox (aLabelsGrp);
894   aHBox->setSpacing(5);
895   myLabelFont = new VisuGUI_FontWg (aHBox);
896
897   TopLayout->addWidget(aLabelsGrp);
898
899   // Common buttons ===========================================================
900   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
901   GroupButtons->setColumnLayout(0, Qt::Vertical );
902   GroupButtons->layout()->setSpacing( 0 );
903   GroupButtons->layout()->setMargin( 0 );
904   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
905   GroupButtonsLayout->setAlignment( Qt::AlignTop );
906   GroupButtonsLayout->setSpacing( 6 );
907   GroupButtonsLayout->setMargin( 11 );
908
909   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
910   buttonOk->setAutoDefault( TRUE );
911   buttonOk->setDefault( TRUE );
912   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
913   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
914
915   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
916   buttonCancel->setAutoDefault( TRUE );
917   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
918
919   TopLayout->addWidget( GroupButtons );
920
921   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(accept()));
922   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
923 }