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