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