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