Salome HOME
IPAL9285,9292,9314
[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=1;
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   orient = aResourceMgr->integerValue("Visu:SBOrientation",orient);
262   if(orient != 1){
263     orient=0;
264     sbX1=0.2;
265     sbY1=0.01;
266     sbW=0.6;
267     sbH=0.12;
268   }
269
270   sbX1 = aResourceMgr->doubleValue("Visu:SBXorigin",sbX1);
271   sbY1 = aResourceMgr->doubleValue("Visu:SBYorigin",sbY1);
272
273   sbW = aResourceMgr->doubleValue("Visu:SBWidth",sbW);
274   sbH = aResourceMgr->doubleValue("Visu:SBHeight",sbH);
275
276   sbCol = aResourceMgr->integerValue("Visu:SBNumberOfColors",sbCol);
277   sbLab = aResourceMgr->integerValue("Visu:SBNumberOfLabels",sbLab);
278   sbRange = aResourceMgr->booleanValue("Visu:SBImposeRange",sbRange);
279   sbVmin = aResourceMgr->doubleValue("Visu:SBMinimumValue",sbVmin);
280   sbVmax = aResourceMgr->doubleValue("Visu:SBMaximumValue",sbVmax);
281
282   QString aScaling = aResourceMgr->stringValue("Visu:SBMaximumValue","LINEAR");
283   if(aScaling.compare("LOGARITHMIC") == 0)
284     setLogarithmic(true);
285   else
286     setLogarithmic(false);
287
288   if((sbX1 < 0.) || (sbY1 < 0.) ||
289      ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
290     if(orient == 1) {
291       sbX1=0.01;
292       sbY1=0.1;
293       sbW=0.1;
294       sbH=0.8;
295     } else {
296       sbX1=0.2;
297       sbY1=0.01;
298       sbW=0.6;
299       sbH=0.12;
300     }
301   }
302   if(sbCol < 2) sbCol=2;
303   if(sbCol > 64) sbCol=64;
304   if(sbLab < 2) sbLab=2;
305   if(sbLab > 65) sbLab=65;
306
307   if(sbVmin > sbVmax) {
308     sbVmin=0.;
309     sbVmax=0.;
310   }
311
312   setRange( sbVmin, sbVmax, /*0.0, 0.0,*/ sbRange );
313   setPosAndSize( sbX1, sbY1, sbW, sbH, orient == 1);
314   setScalarBarData( sbCol, sbLab );
315
316   // "Title"
317   aString = aResourceMgr->stringValue("Visu:IsBoldTitle","true");
318   bool isBold = (aString.compare("true") == 0);
319   aString = aResourceMgr->stringValue("Visu:IsItalicTitle","true");
320   bool isItalic = (aString.compare("true") == 0);
321   aString = aResourceMgr->stringValue("Visu:IsShadowTitle","true");
322   bool isShadow = (aString.compare("true") == 0);
323
324   int aFontType = aResourceMgr->integerValue("Visu:TitFontType",0);
325   int aFontFamily = VTK_ARIAL;
326   switch (aFontType) {
327   case 0:
328     aFontFamily = VTK_ARIAL; break;
329   case 1:
330     aFontFamily = VTK_COURIER; break;
331   case 2:
332     aFontFamily = VTK_TIMES; break;
333   }
334
335   float R = aResourceMgr->doubleValue("Visu:TitleColorR",1.0);
336   if (R > 1) R = 1;
337   if (R < 0) R = 0;
338
339   float G = aResourceMgr->doubleValue("Visu:TitleColorG",1.0);
340   if (G > 1) G = 1;
341   if (G < 0) G = 0;
342
343   float B = aResourceMgr->doubleValue("Visu:TitleColorB",1.0);
344   if (B > 1) B = 1;
345   if (B < 0) B = 0;
346
347   myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
348                                   aFontFamily,
349                                   isBold, isItalic, isShadow);
350
351   // "Labels"
352   aString = aResourceMgr->stringValue("Visu:IsBoldLabel","true");
353   isBold = (aString.compare("true") == 0);
354   aString = aResourceMgr->stringValue("Visu:IsItalicLabel","true");
355   isItalic = (aString.compare("true") == 0);
356   aString = aResourceMgr->stringValue("Visu:IsShadowLabel","true");
357   isShadow = (aString.compare("true") == 0);
358
359   aFontType = aResourceMgr->integerValue("Visu:LblFontType",0);
360   aFontFamily = VTK_ARIAL;
361   switch (aFontType) {
362   case 0:
363     aFontFamily = VTK_ARIAL; break;
364   case 1:
365     aFontFamily = VTK_COURIER; break;
366   case 2:
367     aFontFamily = VTK_TIMES; break;
368   }
369
370   R = aResourceMgr->doubleValue("Visu:LabelColorR",1.0);
371   if (R > 1) R = 1;
372   if (R < 0) R = 0;
373
374   G = aResourceMgr->doubleValue("Visu:LabelColorG",1.0);
375   if (G > 1) G = 1;
376   if (G < 0) G = 0;
377
378   B = aResourceMgr->doubleValue("Visu:LabelColorB",1.0);
379   if (B > 1) B = 1;
380   if (B < 0) B = 0;
381
382   myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
383                                   aFontFamily,
384                                   isBold, isItalic, isShadow);
385 }
386
387 /**
388  * Stores dialog values to resources
389  */
390 void VisuGUI_ScalarBarPane::storeToResources() {
391   int orient = (RBvert->isChecked())? 1 : 0;
392   float sbX1   = XSpin->value();
393   float sbY1   = YSpin->value();
394   float sbW    = WidthSpin->value();
395   float sbH    = HeightSpin->value();
396   int sbCol  = ColorSpin->value();
397   int sbLab  = LabelSpin->value();
398
399   if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
400     if(orient == 1) {
401       sbX1=0.01;
402       sbY1=0.1;
403       sbW=0.17;
404       sbH=0.8;
405     } else {
406       sbX1=0.2;
407       sbY1=0.01;
408       sbW=0.6;
409       sbH=0.12;
410     }
411   }
412
413   bool sbRange = RBIrange->isChecked();
414   float sbVmin = (float)(MinEdit->text().toDouble());
415   float sbVmax = (float)(MaxEdit->text().toDouble());
416
417   if(sbVmin > sbVmax) {
418     sbVmin=0.;
419     sbVmax=0.;
420   }
421
422   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
423
424   aResourceMgr->setValue("Visu:SBOrientation",orient);
425   aResourceMgr->setValue("Visu:SBXorigin",sbX1);
426   aResourceMgr->setValue("Visu:SBYorigin",sbY1);
427   aResourceMgr->setValue("Visu:SBWidth",sbW);
428   aResourceMgr->setValue("Visu:SBHeight",sbH);
429   aResourceMgr->setValue("Visu:SBNumberOfColors",sbCol);
430   aResourceMgr->setValue("Visu:SBNumberOfLabels",sbLab);
431   if(sbRange)
432     aResourceMgr->setValue("Visu:SBImposeRange", "true");
433   else
434     aResourceMgr->setValue("Visu:SBImposeRange", "false");
435   aResourceMgr->setValue("Visu:SBMinimumValue",sbVmin);
436   aResourceMgr->setValue("Visu:SBMaximumValue",sbVmax);
437   if(isLogarithmic())
438     aResourceMgr->setValue("Visu:SBScaling", "LOGARITHMIC");
439   else
440     aResourceMgr->setValue("Visu:SBScaling", "LINEAR");
441
442   ////
443
444   if (myIsStoreTextProp) {
445     // "Title"
446     QColor aTitleColor (255, 255, 255);
447     int aTitleFontFamily = VTK_ARIAL;
448     bool isTitleBold = false;
449     bool isTitleItalic = false;
450     bool isTitleShadow = false;
451
452     myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
453                                     isTitleBold, isTitleItalic, isTitleShadow);
454
455     if (isTitleBold)
456       aResourceMgr->setValue("Visu:IsBoldTitle","true");
457     else
458       aResourceMgr->setValue("Visu:IsBoldTitle","false");
459
460     if (isTitleItalic)
461       aResourceMgr->setValue("Visu:IsItalicTitle","true");
462     else
463       aResourceMgr->setValue("Visu:IsItalicTitle","false");
464
465     if (isTitleShadow)
466       aResourceMgr->setValue("Visu:IsShadowTitle","true");
467     else
468       aResourceMgr->setValue("Visu:IsShadowTitle","false");
469
470     switch (aTitleFontFamily) {
471     case VTK_ARIAL:
472       aResourceMgr->setValue("Visu:TitFontType",0);
473       break;
474     case VTK_COURIER:
475       aResourceMgr->setValue("Visu:TitFontType",1);
476       break;
477     case VTK_TIMES:
478       aResourceMgr->setValue("Visu:TitFontType",2);
479       break;
480     }
481     aResourceMgr->setValue("Visu:TitleColorR", aTitleColor.red()/255.);
482     aResourceMgr->setValue("Visu:TitleColorG", aTitleColor.green()/255.);
483     aResourceMgr->setValue("Visu:TitleColorB", aTitleColor.blue()/255.);
484
485     // "Label"
486     QColor aLabelColor (255, 255, 255);
487     int aLabelFontFamily = VTK_ARIAL;
488     bool isLabelBold = false;
489     bool isLabelItalic = false;
490     bool isLabelShadow = false;
491
492     myTextDlg->myTitleFont->GetData(aLabelColor, aLabelFontFamily,
493                                     isLabelBold, isLabelItalic, isLabelShadow);
494
495     if (isLabelBold)
496       aResourceMgr->setValue("Visu:IsBoldLabel","true");
497     else
498       aResourceMgr->setValue("Visu:IsBoldLabel","false");
499
500     if (isLabelItalic)
501       aResourceMgr->setValue("Visu:IsItalicLabel","true");
502     else
503       aResourceMgr->setValue("Visu:IsItalicLabel","false");
504
505     if (isLabelShadow)
506       aResourceMgr->setValue("Visu:IsShadowLabel","true");
507     else
508       aResourceMgr->setValue("Visu:IsShadowLabel","false");
509
510     switch (aLabelFontFamily) {
511     case VTK_ARIAL:
512       aResourceMgr->setValue("Visu:LblFontType",0);
513       break;
514     case VTK_COURIER:
515       aResourceMgr->setValue("Visu:LblFontType",1);
516       break;
517     case VTK_TIMES:
518       aResourceMgr->setValue("Visu:LblFontType",2);
519       break;
520     }
521     aResourceMgr->setValue("Visu:LabelColorR", aLabelColor.red()/255.);
522     aResourceMgr->setValue("Visu:LabelColorG", aLabelColor.green()/255.);
523     aResourceMgr->setValue("Visu:LabelColorB", aLabelColor.blue()/255.);
524   }
525 }
526
527 /**
528  * Initialise dialog box from presentation object
529  */
530 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ScalarMap_i* thePrs) {
531   initFromResources();
532   myModeCombo->setCurrentItem(thePrs->GetScalarMode());
533   setPosAndSize( thePrs->GetPosX(),
534                  thePrs->GetPosY(),
535                  thePrs->GetWidth(),
536                  thePrs->GetHeight(),
537                  thePrs->GetBarOrientation());
538   switch(thePrs->GetScaling()){
539   case VISU::LOGARITHMIC :
540     setLogarithmic(true);
541     break;
542   default:
543     setLogarithmic(false);
544   }
545   float aRange[2];
546   thePrs->GetScalarMapPL()->GetSourceRange(aRange);
547   Rmin = aRange[0]; Rmax = aRange[1];
548   setRange( thePrs->GetMin(), thePrs->GetMax(),
549             /*0.0, 0.0,*/ thePrs->IsRangeFixed() );
550   setScalarBarData( thePrs->GetNbColors(), thePrs->GetLabels() );
551   bool isScalarMode = (thePrs->GetField()->myNbComp > 1);
552   myModeLbl->setEnabled(isScalarMode);
553   myModeCombo->setEnabled(isScalarMode);
554
555   // "Title"
556   myTextDlg->setTitleText(QString(thePrs->GetTitle()));
557
558   float R, G, B;
559   thePrs->GetTitleColor(&R, &G, &B);
560
561   myTextDlg->myTitleFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
562                                   thePrs->GetTitFontType(),
563                                   thePrs->IsBoldTitle(),
564                                   thePrs->IsItalicTitle(),
565                                   thePrs->IsShadowTitle());
566
567   // "Labels"
568   thePrs->GetLabelColor(&R, &G, &B);
569
570   myTextDlg->myLabelFont->SetData(QColor((int)(R*255.), (int)(G*255.), (int)(B*255.)),
571                                   thePrs->GetLblFontType(),
572                                   thePrs->IsBoldLabel(),
573                                   thePrs->IsItalicLabel(),
574                                   thePrs->IsShadowLabel());
575 }
576
577 /**
578  * Store values to presentation object
579  */
580 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ScalarMap_i* thePrs) {
581   thePrs->SetScalarMode(myModeCombo->currentItem());
582   thePrs->SetPosition(XSpin->value(), YSpin->value());
583   thePrs->SetSize(WidthSpin->value(), HeightSpin->value());
584   thePrs->SetBarOrientation((RBvert->isChecked())? VISU::ScalarMap::VERTICAL : VISU::ScalarMap::HORIZONTAL);
585   if(isLogarithmic())
586     thePrs->SetScaling(VISU::LOGARITHMIC);
587   else
588     thePrs->SetScaling(VISU::LINEAR);
589
590   if (RBFrange->isChecked()) {
591     thePrs->SetSourceRange();
592   } else {
593     thePrs->SetRange(MinEdit->text().toDouble(), MaxEdit->text().toDouble());
594   }
595   thePrs->SetNbColors(ColorSpin->value());
596   thePrs->SetLabels(LabelSpin->value());
597
598   if (isToSave()) storeToResources();
599
600   if (myIsStoreTextProp) {
601     // "Title"
602     thePrs->SetTitle(myTextDlg->getTitleText().latin1());
603
604     QColor aTitColor (255, 255, 255);
605     int aTitleFontFamily = VTK_ARIAL;
606     bool isTitleBold = false;
607     bool isTitleItalic = false;
608     bool isTitleShadow = false;
609
610     myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
611                                     isTitleBold, isTitleItalic, isTitleShadow);
612
613     thePrs->SetBoldTitle(isTitleBold);
614     thePrs->SetItalicTitle(isTitleItalic);
615     thePrs->SetShadowTitle(isTitleShadow);
616     thePrs->SetTitFontType(aTitleFontFamily);
617     thePrs->SetTitleColor(aTitColor.red()/255.,
618                           aTitColor.green()/255.,
619                           aTitColor.blue()/255.);
620
621     // "Label"
622     QColor aLblColor (255, 255, 255);
623     int aLabelFontFamily = VTK_ARIAL;
624     bool isLabelBold = false;
625     bool isLabelItalic = false;
626     bool isLabelShadow = false;
627
628     myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
629                                     isLabelBold, isLabelItalic, isLabelShadow);
630
631     thePrs->SetBoldLabel(isLabelBold);
632     thePrs->SetItalicLabel(isLabelItalic);
633     thePrs->SetShadowLabel(isLabelShadow);
634     thePrs->SetLblFontType(aLabelFontFamily);
635     thePrs->SetLabelColor(aLblColor.red()/255.,
636                           aLblColor.green()/255.,
637                           aLblColor.blue()/255.);
638   }
639
640   return 1;
641 }
642
643 /*!
644   Called when orientation is changed
645 */
646 void VisuGUI_ScalarBarPane::changeDefaults( int )
647 {
648   if ( RBvert->isChecked() ) {
649     XSpin->setValue( myVerX );
650     YSpin->setValue( myVerY );
651     WidthSpin->setValue( myVerW );
652     HeightSpin->setValue( myVerH );
653   }
654   else {
655     XSpin->setValue( myHorX );
656     YSpin->setValue( myHorY );
657     WidthSpin->setValue( myHorW );
658     HeightSpin->setValue( myHorH );
659   }
660 }
661
662 /*!
663   Called when Range mode is changed
664 */
665 void VisuGUI_ScalarBarPane::changeRange( int )
666 {
667   int mode = -1;
668   if ( RBFrange->isChecked() )
669     mode = 0;
670   if ( RBIrange->isChecked() )
671     mode = 1;
672   if ( myRangeMode == mode )
673     return;
674   //MinSpin->setMaxValue( Fmin );
675   //MaxSpin->setMinValue( Fmax );
676   if ( RBFrange->isChecked() ) {
677     //MinLabel->setEnabled( false );
678     MinEdit->setEnabled( false );
679     //MaxLabel->setEnabled( false );
680     MaxEdit->setEnabled( false );
681     if ( mode != -1 ) {
682       Imin = MinEdit->text().toDouble();
683       Imax = MaxEdit->text().toDouble();
684     }
685     MinEdit->setText( QString::number( Rmin ) );
686     MaxEdit->setText( QString::number( Rmax ) );
687   }
688   else {
689     //MinLabel->setEnabled( true );
690     MinEdit->setEnabled( true );
691     //MaxLabel->setEnabled( true );
692     MaxEdit->setEnabled( true );
693     MinEdit->setText( QString::number( Imin ) );
694     MaxEdit->setText( QString::number( Imax ) );
695   }
696   myRangeMode = mode;
697 }
698
699 /*!
700   Called when X,Y position is changed
701 */
702 void VisuGUI_ScalarBarPane::XYChanged( double )
703 {
704   QtxDblSpinBox* snd = (QtxDblSpinBox*)sender();
705   if ( snd == XSpin ) {
706     WidthSpin->setMaxValue( 1.0 - XSpin->value() );
707   }
708   if ( snd == YSpin ) {
709     HeightSpin->setMaxValue( 1.0 - YSpin->value() );
710   }
711 }
712
713 /*!
714   Sets default values and range mode
715 */
716 void VisuGUI_ScalarBarPane::setRange( double imin, double imax/*, double fmin, double fmax*/, bool sbRange )
717 {
718   Imin = imin; Imax = imax;// Fmin = fmin; Fmax = fmax;
719   if ( RBIrange->isChecked() ) {
720     MinEdit->setText( QString::number( Imin ) );
721     MaxEdit->setText( QString::number( Imax ) );
722   }
723   else {
724     MinEdit->setText( QString::number( Rmin ) );
725     MaxEdit->setText( QString::number( Rmax ) );
726   }
727   myRangeMode = -1;
728   if( sbRange )
729     RBIrange->setChecked( true );
730   else
731     RBFrange->setChecked( true );
732   changeRange( 0 );
733 }
734
735 /*!
736   Sets size and position
737 */
738 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
739 {
740   if ( vert ) {
741     myVerX = x;
742     myVerY = y;
743     myVerW = w;
744     myVerH = h;
745     RBvert->setChecked( true );
746   }
747   else {
748     myHorX = x;
749     myHorY = y;
750     myHorW = w;
751     myHorH = h;
752     RBhori->setChecked( true );
753   }
754   changeDefaults( 0 );
755 }
756
757 /*!
758   Sets colors and labels number
759 */
760 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
761 {
762   ColorSpin->setValue( colors );
763   LabelSpin->setValue( labels );
764 }
765
766 /*!
767   Gets orientation
768 */
769 int  VisuGUI_ScalarBarPane::getOrientation()
770 {
771   if (RBvert->isChecked() )
772     return  1;
773   else
774     return 0;
775 }
776
777 /*!
778   Called when <OK> button is clicked, validates data and closes dialog
779 */
780 bool VisuGUI_ScalarBarPane::check()
781 {
782   double minVal = MinEdit->text().toDouble();
783   double maxVal = MaxEdit->text().toDouble();
784   if ( RBIrange->isChecked() ) {
785     if (minVal >= maxVal) {
786       SUIT_MessageBox::warn1( this,tr("WRN_VISU"),
787                              tr("MSG_MINMAX_VALUES"),
788                              tr("BUT_OK"));
789       return false;
790     }
791   }
792   // check if logarithmic mode is on and check imposed range to not contain negative values
793   if ( CBLog->isChecked() ) {
794     if ( RBIrange->isChecked() ) {
795       if ( (minVal > 0) && (maxVal > 0) ) {
796         // nothing to do
797       }
798       else {
799         SUIT_MessageBox::warn1( this,
800                                 tr("WRN_VISU"),
801                                 tr("WRN_LOGARITHMIC_RANGE"),
802                                 tr("BUT_OK"));
803         return false;
804       }
805     }
806     else {
807       if ( Rmin > 0 && Rmax > 0 ) {
808         // nothing to do
809       }
810       else {
811         SUIT_MessageBox::warn1( this,
812                                 tr("WRN_VISU"),
813                                 tr("WRN_LOGARITHMIC_FIELD_RANGE"),
814                                 tr("BUT_OK"));
815         RBIrange->setChecked(1);
816         changeRange(1);
817         //MinEdit->setText( QString::number( Rmin ) );
818         //MaxEdit->setText( QString::number( Rmax ) );
819         return false;
820       }
821     }
822   }
823   return true;
824 }
825
826 void VisuGUI_ScalarBarPane::onTextPref()
827 {
828   myIsStoreTextProp = myTextDlg->exec();
829 }
830
831
832 //#######################################################################################
833
834 /*!
835   Constructor
836 */
837 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule, bool SetPref)
838     : QDialog(VISU::GetDesktop(theModule), 0, true,
839               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
840 {
841   setName("VisuGUI_ScalarBarDlg");
842   setCaption(SetPref ? tr("DLG_PREF_TITLE") : tr("DLG_PROP_TITLE"));
843   setSizeGripEnabled(TRUE);
844
845   QVBoxLayout* TopLayout = new QVBoxLayout(this);
846   TopLayout->setSpacing(6);
847   TopLayout->setMargin(11);
848
849   myScalarPane = new VisuGUI_ScalarBarPane(this, SetPref);
850   TopLayout->addWidget(myScalarPane);
851
852   // Common buttons ===========================================================
853   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
854   GroupButtons->setColumnLayout(0, Qt::Vertical );
855   GroupButtons->layout()->setSpacing( 0 );
856   GroupButtons->layout()->setMargin( 0 );
857   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
858   GroupButtonsLayout->setAlignment( Qt::AlignTop );
859   GroupButtonsLayout->setSpacing( 6 );
860   GroupButtonsLayout->setMargin( 11 );
861
862   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
863   buttonOk->setAutoDefault( TRUE );
864   buttonOk->setDefault( TRUE );
865   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
866   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
867
868   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
869   buttonCancel->setAutoDefault( TRUE );
870   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
871
872   TopLayout->addWidget( GroupButtons );
873
874   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
875   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
876 }
877
878 /*!
879   Called when <OK> button is clicked, validates data and closes dialog
880 */
881 void VisuGUI_ScalarBarDlg::accept()
882 {
883   if (myScalarPane->check()) QDialog::accept();
884 }
885
886
887 //#######################################################################################
888 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
889   : QDialog(parent, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
890 {
891   setName("VisuGUI_TextPrefDlg");
892   setCaption(tr("TIT_TEXT_PREF"));
893   setSizeGripEnabled(TRUE);
894
895   QVBoxLayout* TopLayout = new QVBoxLayout(this);
896   TopLayout->setSpacing(6);
897   TopLayout->setMargin(11);
898
899   // "Title" grp
900   QGroupBox* aTitleGrp = new QGroupBox (2, Qt::Vertical, tr("LBL_TITLE"), this);
901
902   //   edit line
903   myTitleEdt = new QLineEdit (aTitleGrp);
904
905   //   font
906   QHBox* aHBox = new QHBox (aTitleGrp);
907   aHBox->setSpacing(5);
908   myTitleFont = new VisuGUI_FontWg (aHBox);
909
910   TopLayout->addWidget(aTitleGrp);
911
912   // "Labels" grp
913   QGroupBox* aLabelsGrp = new QGroupBox (1, Qt::Vertical, tr("LBL_LABELS"), this);
914
915   //   font
916   aHBox = new QHBox (aLabelsGrp);
917   aHBox->setSpacing(5);
918   myLabelFont = new VisuGUI_FontWg (aHBox);
919
920   TopLayout->addWidget(aLabelsGrp);
921
922   // Common buttons ===========================================================
923   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
924   GroupButtons->setColumnLayout(0, Qt::Vertical );
925   GroupButtons->layout()->setSpacing( 0 );
926   GroupButtons->layout()->setMargin( 0 );
927   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
928   GroupButtonsLayout->setAlignment( Qt::AlignTop );
929   GroupButtonsLayout->setSpacing( 6 );
930   GroupButtonsLayout->setMargin( 11 );
931
932   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
933   buttonOk->setAutoDefault( TRUE );
934   buttonOk->setDefault( TRUE );
935   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
936   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
937
938   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
939   buttonCancel->setAutoDefault( TRUE );
940   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
941
942   TopLayout->addWidget( GroupButtons );
943
944   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(accept()));
945   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
946 }