Salome HOME
Update copyright information
[modules/visu.git] / src / VISUGUI / VisuGUI_Prs3dDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU VISUGUI : GUI of VISU component
24 //  File   : VisuGUI_Prs3dDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //
28 #include "VisuGUI_Prs3dDlg.h"
29
30 #include "VisuGUI.h"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_ViewTools.h"
33 #include "VisuGUI_InputPane.h"
34
35 #include "SVTK_ViewWindow.h"
36 #include "SVTK_FontWidget.h"
37
38 #include "VISUConfig.hh"
39 #include "VISU_Convertor.hxx"
40 #include "VISU_MeshValue.hxx"
41 #include "VISU_Structures_impl.hxx"
42 #include "VISU_ScalarMapPL.hxx"
43 #include "VISU_ScalarBarActor.hxx"
44 #include "VISU_ScalarMapAct.h"
45 #include "VISU_ScalarMap_i.hh"
46 #include "VISU_Result_i.hh"
47 #include "VISU_Prs3dUtils.hh"
48
49 #include <SalomeApp_IntSpinBox.h>
50 #include <SalomeApp_DoubleSpinBox.h>
51 #include "LightApp_Application.h"
52
53 #include "SUIT_Session.h"
54 #include "SUIT_MessageBox.h"
55 #include "SUIT_ResourceMgr.h"
56 #include "SUIT_Desktop.h"
57
58 #include <QCheckBox>
59 #include <QLineEdit>
60 #include <QRadioButton>
61 #include <QButtonGroup>
62 #include <QGroupBox>
63 #include <QLabel>
64 #include <QPushButton>
65 #include <QComboBox>
66 #include <QToolButton>
67 #include <QLayout>
68 #include <QValidator>
69 #include <QColorDialog>
70 #include <QTabWidget>
71 #include <QKeyEvent>
72 #include <QGridLayout>
73
74 #include <vtkTextProperty.h>
75
76 #include <limits>
77
78 //-----------------------------------------------------------------------
79 // Text Preferences Dialog
80 //-----------------------------------------------------------------------
81 /*!
82   Constructor
83 */
84 VisuGUI_TextPrefDlg::VisuGUI_TextPrefDlg (QWidget* parent)
85   : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
86 {
87   setModal( true );
88   setWindowTitle(tr("TIT_TEXT_PREF"));
89   setSizeGripEnabled(TRUE);
90
91   QVBoxLayout* aMainLay = new QVBoxLayout(this);
92   aMainLay->setSpacing(6);
93   aMainLay->setMargin(11);
94
95   // "Title" grp
96   QGroupBox* aTitleGrp = new QGroupBox ( tr("LBL_TITLE"), this);
97   QVBoxLayout* aVBLay = new QVBoxLayout( aTitleGrp );
98
99   //   edit line
100   myTitleEdt = new QLineEdit (aTitleGrp);
101   aVBLay->addWidget( myTitleEdt);
102
103   //   font
104   QWidget* aHBox = new QWidget (aTitleGrp);
105   aVBLay->addWidget( aHBox );
106
107   QHBoxLayout* aHBLay = new QHBoxLayout( aHBox );
108   aHBLay->setSpacing(5);
109
110   myTitleFont = new SVTK_FontWidget (aHBox);
111   myTitleFont->Initialize();
112   aHBLay->addWidget( myTitleFont );
113
114   aMainLay->addWidget(aTitleGrp);
115
116   // "Labels" grp
117   QGroupBox* aLabelsGrp = new QGroupBox (tr("LBL_LABELS"), this);
118   aVBLay = new QVBoxLayout( aLabelsGrp );
119
120   //   font
121   aHBox = new QWidget (aLabelsGrp);
122   aVBLay->addWidget( aHBox );
123
124   aHBLay = new QHBoxLayout( aHBox );
125   aHBLay->setSpacing(5);
126
127   myLabelFont = new SVTK_FontWidget (aHBox);
128   myLabelFont->Initialize();
129   aHBLay->addWidget( myLabelFont );
130
131   aMainLay->addWidget(aLabelsGrp);
132
133   // Common buttons ===========================================================
134   QGroupBox* GroupButtons = new QGroupBox( this );
135   //GroupButtons->setColumnLayout(0, Qt::Vertical );
136   //GroupButtons->layout()->setSpacing( 0 );
137   //GroupButtons->layout()->setMargin( 0 );
138   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
139   GroupButtonsLayout->setAlignment( Qt::AlignTop );
140   GroupButtonsLayout->setSpacing( 6 );
141   GroupButtonsLayout->setMargin( 11 );
142
143   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
144   buttonOk->setAutoDefault( TRUE );
145   buttonOk->setDefault( TRUE );
146   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
147   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
148
149   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons );
150   buttonCancel->setAutoDefault( TRUE );
151   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
152
153   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons );
154   buttonHelp->setAutoDefault( TRUE );
155   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
156
157   aMainLay->addWidget( GroupButtons );
158
159   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(accept()));
160   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
161   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
162 }
163
164
165 //----------------------------------------------------------------------------
166 QString VisuGUI_TextPrefDlg::getTitleText()
167 {
168   return myTitleEdt->text();
169 }
170
171
172 //----------------------------------------------------------------------------
173 void VisuGUI_TextPrefDlg::setTitleText( const QString& theText )
174 {
175   myTitleEdt->setText(theText);
176 }
177
178
179 //----------------------------------------------------------------------------
180 void VisuGUI_TextPrefDlg::setTitleVisible(bool isVisible)
181 {
182   if(isVisible)
183     myTitleEdt->show();
184   else
185     myTitleEdt->hide();
186 }
187
188
189 //----------------------------------------------------------------------------
190 void VisuGUI_TextPrefDlg::onHelp()
191 {
192   QString aHelpFileName = "scalar_map_page.html";
193   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
194   if (app) {
195     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
196     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
197   }
198   else {
199     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
200                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
201                              arg(app->resourceMgr()->stringValue("ExternalBrowser",
202                                                                  "application")).arg(aHelpFileName),
203                              QObject::tr("BUT_OK"));
204   }
205 }
206
207
208 //----------------------------------------------------------------------------
209 void VisuGUI_TextPrefDlg::storeBeginValues()
210 {
211   myTitle = myTitleEdt->text();
212   myTitleFont->GetData(myColors[0], myComboVals[0], myCheckVals[0], myCheckVals[1], myCheckVals[2]);
213   myLabelFont->GetData(myColors[1], myComboVals[1], myCheckVals[3], myCheckVals[4], myCheckVals[5]);
214 }
215
216
217 //----------------------------------------------------------------------------
218 /*!
219   Called when <Cancel> button is clicked, restore begin values
220 */
221 void VisuGUI_TextPrefDlg::reject()
222 {
223   myTitleEdt->setText(myTitle);
224   myTitleFont->SetData(myColors[0], myComboVals[0], myCheckVals[0], myCheckVals[1], myCheckVals[2]);
225   myLabelFont->SetData(myColors[1], myComboVals[1], myCheckVals[3], myCheckVals[4], myCheckVals[5]);
226
227   QDialog::reject();
228 }
229
230
231 //----------------------------------------------------------------------------
232 /*!
233   Called when <Ok> button is clicked, store begin values
234 */
235 void VisuGUI_TextPrefDlg::accept()
236 {
237   storeBeginValues();
238
239   QDialog::accept();
240 }
241
242
243 //----------------------------------------------------------------------------
244 /*!
245   Provides help on F1 button click
246 */
247 void VisuGUI_TextPrefDlg::keyPressEvent( QKeyEvent* e )
248 {
249   QDialog::keyPressEvent( e );
250   if ( e->isAccepted() )
251     return;
252
253   if ( e->key() == Qt::Key_F1 )
254     {
255       e->accept();
256       onHelp();
257     }
258 }
259
260 //-----------------------------------------------------------------------
261 // Scalar Bar Preferences Dialog
262 //-----------------------------------------------------------------------
263 /*!
264   Constructor
265 */
266 VisuGUI_BarPrefDlg::VisuGUI_BarPrefDlg( QWidget* parent )
267   : QDialog( parent ),
268     myOrientation( 1 )
269 {
270   setModal( true );
271   setWindowTitle( tr( "TIT_BAR_PREF" ) );
272   setSizeGripEnabled( true );
273
274   QString propertyName = QString( "scalar_bar_vertical_" );
275
276   myTitleSize = myLabelSize = myBarWidth = myBarHeight = 0;
277   myUnits = true;
278   myPrecision = 3;
279
280   QVBoxLayout* aMainLay = new QVBoxLayout( this );
281   aMainLay->setSpacing( 5 );
282   aMainLay->setMargin( 5 );
283
284   // dimensions
285
286   QGroupBox* aDimGrp = new QGroupBox( this );
287   QGridLayout* aDimGrpLay = new QGridLayout( aDimGrp );
288   aDimGrpLay->setSpacing( 5 );
289   aDimGrpLay->setMargin( 5 );
290
291   myTitleSizeSpin = new SalomeApp_IntSpinBox( aDimGrp );
292   myTitleSizeSpin->setAcceptNames( false );
293   myTitleSizeSpin->setRange( 0, 100 );
294   myTitleSizeSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
295   myTitleSizeSpin->setMinimumWidth( 70 );
296   myTitleSizeSpin->setValue( 0 );
297   myTitleSizeSpin->setSpecialValueText( tr( "AUTO" ) );
298   QLabel* aTitleSizeLbl = new QLabel( tr( "LBL_TITLE_W" ), aDimGrp );
299
300   myLabelSizeSpin = new SalomeApp_IntSpinBox( aDimGrp );
301   myLabelSizeSpin->setAcceptNames( false );
302   myLabelSizeSpin->setRange( 0, 100 );
303   myLabelSizeSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
304   myLabelSizeSpin->setMinimumWidth( 70 );
305   myLabelSizeSpin->setValue( 0 );
306   myLabelSizeSpin->setSpecialValueText( tr( "AUTO" ) );
307   QLabel* aLabelSizeLbl = new QLabel( tr( "LBL_LABEL_W" ), aDimGrp );
308
309   myBarWidthSpin = new SalomeApp_IntSpinBox( aDimGrp );
310   myBarWidthSpin->setAcceptNames( false );
311   myBarWidthSpin->setRange( 0, 100 );
312   myBarWidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
313   myBarWidthSpin->setMinimumWidth( 70 );
314   myBarWidthSpin->setValue( 0 );
315   myBarWidthSpin->setSpecialValueText( tr( "AUTO" ) );
316   QLabel* aBarWidthLbl = new QLabel( tr( "LBL_BAR_W" ), aDimGrp );
317
318   myBarHeightSpin = new SalomeApp_IntSpinBox( aDimGrp );
319   myBarHeightSpin->setAcceptNames( false );
320   myBarHeightSpin->setRange( 0, 100 );
321   myBarHeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
322   myBarHeightSpin->setMinimumWidth( 70 );
323   myBarHeightSpin->setValue( 0 );
324   myBarHeightSpin->setSpecialValueText( tr( "AUTO" ) );
325   QLabel* aBarHeightLbl = new QLabel( tr( "LBL_BAR_H" ), aDimGrp );
326
327   // format and units
328
329   QLabel* aPrecLbl = new QLabel( tr( "PRECISION" ), aDimGrp );
330   myPrecisionSpin = new SalomeApp_IntSpinBox( aDimGrp );
331   myPrecisionSpin->setAcceptNames( false );
332   myPrecisionSpin->setRange( 1, 100 );
333
334   myUnitsChk = new QCheckBox( tr( "LBL_SHOW_UNITS" ), aDimGrp );
335
336   // layout
337
338   aDimGrpLay->addWidget( aTitleSizeLbl,  0, 0 );
339   aDimGrpLay->addWidget( myTitleSizeSpin,   0, 1 );
340   aDimGrpLay->addWidget( aLabelSizeLbl,  0, 2 );
341   aDimGrpLay->addWidget( myLabelSizeSpin,   0, 3 );
342   aDimGrpLay->addWidget( aBarWidthLbl,   1, 0 );
343   aDimGrpLay->addWidget( myBarWidthSpin,    1, 1 );
344   aDimGrpLay->addWidget( aBarHeightLbl,  1, 2 );
345   aDimGrpLay->addWidget( myBarHeightSpin,   1, 3 );
346   aDimGrpLay->addWidget( aPrecLbl, 2, 0 );
347   aDimGrpLay->addWidget( myPrecisionSpin, 2, 1 );
348   aDimGrpLay->addWidget( myUnitsChk, 2, 2, 1, 2 );
349
350   aMainLay->addWidget( aDimGrp );
351
352   // Common buttons ===========================================================
353
354   QGroupBox* GroupButtons = new QGroupBox( this );
355   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
356   GroupButtonsLayout->setAlignment( Qt::AlignTop );
357   GroupButtonsLayout->setSpacing( 6 );
358   GroupButtonsLayout->setMargin( 11 );
359
360   QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons );
361   buttonOk->setAutoDefault( true );
362   buttonOk->setDefault( true );
363
364   QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons );
365   buttonCancel->setAutoDefault( true );
366
367   QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons );
368   buttonHelp->setAutoDefault( true );
369
370   GroupButtonsLayout->addWidget( buttonOk );
371   GroupButtonsLayout->addSpacing( 5 );
372   GroupButtonsLayout->addStretch();
373   GroupButtonsLayout->addWidget( buttonCancel );
374   GroupButtonsLayout->addWidget( buttonHelp );
375
376   aMainLay->addWidget( GroupButtons );
377
378   connect( buttonOk,        SIGNAL( clicked() ),           this, SLOT( accept() ) );
379   connect( buttonCancel,    SIGNAL( clicked() ),           this, SLOT( reject() ) );
380   connect( buttonHelp,      SIGNAL( clicked() ),           this, SLOT( onHelp() ) );
381   connect( myTitleSizeSpin,  SIGNAL( valueChanged( int ) ), this, SIGNAL( updatePreview() ) );
382   connect( myLabelSizeSpin,  SIGNAL( valueChanged( int ) ), this, SIGNAL( updatePreview() ) );
383   connect( myBarWidthSpin,    SIGNAL( valueChanged( int ) ), this, SIGNAL( updatePreview() ) );
384   connect( myBarHeightSpin,   SIGNAL( valueChanged( int ) ), this, SIGNAL( updatePreview() ) );
385   connect( myUnitsChk,         SIGNAL( toggled( bool ) ),     this, SIGNAL( updatePreview() ) );
386   connect( myPrecisionSpin,  SIGNAL( valueChanged( int ) ), this, SIGNAL( updatePreview() ) );
387 }
388
389
390 //----------------------------------------------------------------------------
391 void VisuGUI_BarPrefDlg::setRatios( int titleRatioSize, int labelRatioWidth,
392                                     int barRatioWidth, int barRatioHeight )
393 {
394   myTitleSizeSpin->setValue( myTitleSize = titleRatioSize );
395   myLabelSizeSpin->setValue( myLabelSize = labelRatioWidth );
396   myBarWidthSpin->setValue( myBarWidth = barRatioWidth );
397   myBarHeightSpin->setValue( myBarHeight = barRatioHeight );
398 }
399
400
401 //----------------------------------------------------------------------------
402 void VisuGUI_BarPrefDlg::getRatios( int& titleRatioSize, int& labelRatioWidth,
403                                     int& barRatioWidth, int& barRatioHeight )
404 {
405   titleRatioSize  = myTitleSizeSpin->value();
406   labelRatioWidth  = myLabelSizeSpin->value();
407   barRatioWidth    = myBarWidthSpin->value();
408   barRatioHeight   = myBarHeightSpin->value();
409 }
410
411
412 //----------------------------------------------------------------------------
413 void VisuGUI_BarPrefDlg::setLabelsPrecision( const int p )
414 {
415   myPrecisionSpin->setValue( p );
416 }
417
418 //----------------------------------------------------------------------------
419 int VisuGUI_BarPrefDlg::getLabelsPrecision() const
420 {
421   return myPrecisionSpin->value();
422 }
423
424 //----------------------------------------------------------------------------
425 void VisuGUI_BarPrefDlg::setOrientation( const int ori )
426 {
427   myOrientation = ori;
428 }
429
430 //----------------------------------------------------------------------------
431
432 int VisuGUI_BarPrefDlg::getOrientation() const
433 {
434   return myOrientation;
435 }
436
437 //----------------------------------------------------------------------------
438 void VisuGUI_BarPrefDlg::onHelp()
439 {
440   QString aHelpFileName = "scalar_map_page.html";
441   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
442   if (app) {
443     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
444     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
445   }
446   else {
447     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
448                               tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
449                               arg( app->resourceMgr()->stringValue( "ExternalBrowser",
450                                                                     "application" ) ).
451                               arg( aHelpFileName ) );
452   }
453 }
454
455
456 //----------------------------------------------------------------------------
457 void VisuGUI_BarPrefDlg::setUnitsVisible(bool isVisible)
458 {
459   myUnitsChk->setChecked( myUnits = isVisible );
460 }
461
462
463 //----------------------------------------------------------------------------
464 bool VisuGUI_BarPrefDlg::isUnitsVisible()
465 {
466   return myUnitsChk->isChecked();
467 }
468
469
470 //----------------------------------------------------------------------------
471 /*!
472   Called when <Cancel> button is clicked, restore begin values
473 */
474 void VisuGUI_BarPrefDlg::reject()
475 {
476   myTitleSizeSpin->setValue( myTitleSize );
477   myLabelSizeSpin->setValue( myLabelSize );
478   myBarWidthSpin->setValue( myBarWidth );
479   myBarHeightSpin->setValue( myBarHeight );
480   myUnitsChk->setChecked( myUnits );
481   myPrecisionSpin->setValue( myPrecision );
482   QDialog::reject();
483 }
484
485
486 //----------------------------------------------------------------------------
487 /*!
488   Called when <Ok> button is clicked, store begin values
489 */
490 void VisuGUI_BarPrefDlg::accept()
491 {
492   QString dVal;
493   int aBWH = myOrientation == 1 ? myBarWidthSpin->value() : myBarHeightSpin->value();
494   if( ( myLabelSizeSpin->value()+ aBWH ) > 100 )
495   {
496     SUIT_MessageBox::warning( this, tr( "WRN_VISU" ), tr( "MSG_BIG_SCALE" ) );
497     return;
498   }
499
500   if ( myTitleSizeSpin->value() > 100 )
501   {
502     SUIT_MessageBox::warning( this, tr( "WRN_VISU" ), tr( "MSG_BIG_SCALE_TLT" ) );
503     return;
504   }
505
506   myTitleSize = myTitleSizeSpin->value();
507   myLabelSize = myLabelSizeSpin->value();
508   myBarWidth = myBarWidthSpin->value();
509   myBarHeight = myBarHeightSpin->value();
510   myUnits = myUnitsChk->isChecked();
511   myPrecision = myPrecisionSpin->value();
512   QDialog::accept();
513 }
514
515
516 //----------------------------------------------------------------------------
517 /*!
518   Provides help on F1 button click
519 */
520 void VisuGUI_BarPrefDlg::keyPressEvent( QKeyEvent* e )
521 {
522   QDialog::keyPressEvent( e );
523   if ( e->isAccepted() )
524     return;
525
526   if ( e->key() == Qt::Key_F1 ) {
527     e->accept();
528     onHelp();
529   }
530 }
531
532
533 //-----------------------------------------------------------------------
534 // Scalar Bar Pane
535 //-----------------------------------------------------------------------
536
537 /*!
538   Constructor
539 */
540 VisuGUI_ScalarBarPane::VisuGUI_ScalarBarPane( QWidget* parent, bool theIsDisplayGaussMetric, bool thePreview )
541   : QWidget( parent ),
542     myPreviewActor( 0 ),
543     myScalarMap( 0 ),
544     myScalarMapPL( 0 ),
545     myIsDisplayGaussMetric( theIsDisplayGaussMetric )
546 {
547   QVBoxLayout* aMainLayout = new QVBoxLayout( this );
548   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
549   QString propertyName;
550   propertyName = QString("scalar_bar_vertical_");
551   myVerX = aResourceMgr->doubleValue("VISU", propertyName + "x", 0.);
552   myVerY = aResourceMgr->doubleValue("VISU", propertyName + "y", 0.);
553   myVerW = aResourceMgr->doubleValue("VISU", propertyName + "width", 0.);
554   myVerH = aResourceMgr->doubleValue("VISU", propertyName + "height",0.);
555   myVerTS = aResourceMgr->integerValue("VISU", propertyName + "title_size", 0);
556   myVerLS = aResourceMgr->integerValue("VISU", propertyName + "label_size", 0);
557   myVerBW = aResourceMgr->integerValue("VISU", propertyName + "bar_width", 0);
558   myVerBH = aResourceMgr->integerValue("VISU", propertyName + "bar_height",0);
559
560   propertyName = QString("scalar_bar_horizontal_");
561   myHorX  = aResourceMgr->doubleValue("VISU", propertyName + "x", 0.);
562   myHorY  = aResourceMgr->doubleValue("VISU", propertyName + "y", 0.);
563   myHorW  = aResourceMgr->doubleValue("VISU", propertyName + "width", 0.);
564   myHorH  = aResourceMgr->doubleValue("VISU", propertyName + "height",0.);
565   myHorTS = aResourceMgr->integerValue("VISU", propertyName + "title_size", 0);
566   myHorLS = aResourceMgr->integerValue("VISU", propertyName + "label_size", 0);
567   myHorBW = aResourceMgr->integerValue("VISU", propertyName + "bar_width", 0);
568   myHorBH = aResourceMgr->integerValue("VISU", propertyName + "bar_height",0);
569
570   //aMainLayout->setSpacing(6);
571
572   // Range ============================================================
573   RangeGroup = new QButtonGroup ( this );
574   QGroupBox* aGB = new QGroupBox( tr("SCALAR_RANGE_GRP"),this  );
575   aMainLayout->addWidget( aGB );
576   QGridLayout* RangeGroupLayout = new QGridLayout( aGB );
577   RangeGroupLayout->setAlignment( Qt::AlignTop );
578   //RangeGroupLayout->setSpacing( 6 );
579   //RangeGroupLayout->setMargin( 11 );
580
581   myModeLbl = new QLabel("Scalar Mode", aGB);
582
583   myModeCombo = new QComboBox(aGB);
584
585   CBLog = new QCheckBox (tr("LOGARITHMIC_SCALING"), aGB);
586   CBLog->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
587
588   myGaussMetricLabel = new QLabel( tr("VISU_GAUSS_METRIC"), aGB );
589   myGaussMetric = new QComboBox( aGB );
590   myGaussMetric->addItem( tr("VISU_GAUSS_METRIC_AVERAGE") );
591   myGaussMetric->addItem( tr("VISU_GAUSS_METRIC_MINIMUM") );
592   myGaussMetric->addItem( tr("VISU_GAUSS_METRIC_MAXIMUM") );
593   myGaussMetric->setToolTip( tr("VISU_GAUSS_METRIC_TOOLTIP") );
594
595   if( !myIsDisplayGaussMetric ) {
596     myGaussMetricLabel->hide();
597     myGaussMetric->hide();
598   }
599
600   RBFrange = new QRadioButton (tr("FIELD_RANGE_BTN"), aGB);
601   RBIrange = new QRadioButton (tr("IMPOSED_RANGE_BTN"), aGB);
602   RangeGroup->addButton( RBFrange, 0 );
603   RangeGroup->addButton( RBIrange, 1 );
604   RBFrange->setChecked( true );
605
606   int aPrecision = qAbs( aResourceMgr->integerValue( "VISU", "visual_data_precision", 0 ) );
607   QDoubleValidator* dv = new QDoubleValidator(this);
608   dv->setDecimals(aPrecision);
609
610   MinEdit = new QLineEdit( aGB );
611   MinEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
612   //MinEdit->setMinimumWidth( 70 );
613   MinEdit->setValidator( dv );
614   MinEdit->setText( "0.0" );
615   QLabel* MinLabel = new QLabel (tr("LBL_MIN"), aGB);
616   MinLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
617   MinLabel->setBuddy(MinEdit);
618
619   MaxEdit = new QLineEdit( aGB );
620   MaxEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
621   //MaxEdit->setMinimumWidth( 70 );
622   MaxEdit->setValidator( dv );
623   MaxEdit->setText( "0.0" );
624   QLabel* MaxLabel = new QLabel (tr("LBL_MAX"), aGB);
625   MaxLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
626   MaxLabel->setBuddy(MaxEdit);
627
628   RangeGroupLayout->addWidget( myModeLbl, 0, 0, 1, 1 );
629   RangeGroupLayout->addWidget( myModeCombo, 0, 1, 1, 2);
630   RangeGroupLayout->addWidget( CBLog, 0, 3, 1, 1);
631   RangeGroupLayout->addWidget( myGaussMetricLabel, 1, 0, 1, 1);
632   RangeGroupLayout->addWidget( myGaussMetric, 1, 1, 1, 3);
633   RangeGroupLayout->addWidget( RBFrange, 2, 0, 1, 2);
634   RangeGroupLayout->addWidget( RBIrange, 2, 2, 1, 2);
635   RangeGroupLayout->addWidget( MinLabel, 3, 0 );
636   RangeGroupLayout->addWidget( MinEdit,  3, 1 );
637   RangeGroupLayout->addWidget( MaxLabel, 3, 2 );
638   RangeGroupLayout->addWidget( MaxEdit,  3, 3 );
639
640   // Colors and Labels ========================================================
641   QGroupBox* ColLabGroup = new QGroupBox (tr("COLORS_LABELS_GRP"), this);
642   aMainLayout->addWidget( ColLabGroup );
643   QGridLayout* ColLabGroupLayout = new QGridLayout( ColLabGroup );
644   ColLabGroupLayout->setAlignment( Qt::AlignTop );
645   //ColLabGroupLayout->setSpacing( 6 );
646   //ColLabGroupLayout->setMargin( 11 );
647
648   QLabel* ColorLabel = new QLabel (tr("LBL_NB_COLORS"), ColLabGroup);
649   ColorSpin = new SalomeApp_IntSpinBox( ColLabGroup );
650   ColorSpin->setAcceptNames( false );
651   ColorSpin->setMinimum( 2 );
652   ColorSpin->setMaximum( 256 );
653   ColorSpin->setSingleStep( 1 );
654   ColorSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
655   //ColorSpin->setMinimumWidth( 70 );
656   ColorSpin->setValue( 64 );
657
658   QLabel* LabelLabel = new QLabel (tr("LBL_NB_LABELS"), ColLabGroup);
659   LabelSpin = new SalomeApp_IntSpinBox( ColLabGroup );
660   LabelSpin->setAcceptNames( false );
661   LabelSpin->setMinimum( 2 );
662   LabelSpin->setMaximum( 65 );
663   LabelSpin->setSingleStep( 1 );
664
665   LabelSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
666   //LabelSpin->setMinimumWidth( 70 );
667   LabelSpin->setValue( 5 );
668
669   ColLabGroupLayout->addWidget( ColorLabel, 0, 0);
670   ColLabGroupLayout->addWidget( ColorSpin,  0, 1);
671   ColLabGroupLayout->addWidget( LabelLabel, 0, 2);
672   ColLabGroupLayout->addWidget( LabelSpin,  0, 3);
673
674   // Orientation ==========================================================
675   QButtonGroup* OrientGroup = new QButtonGroup ( this );
676   QGroupBox* OrientGB = new QGroupBox( tr("ORIENTATION_GRP"),this );
677   aMainLayout->addWidget( OrientGB );
678   QGridLayout* OrientGroupLayout = new QGridLayout( OrientGB );
679   OrientGroupLayout->setAlignment( Qt::AlignTop );
680   //OrientGroupLayout->setSpacing( 6 );
681   //OrientGroupLayout->setMargin( 11 );
682
683   RBvert = new QRadioButton (tr("VERTICAL_BTN"), OrientGB);
684   RBvert->setChecked( true );
685   RBhori = new QRadioButton (tr("HORIZONTAL_BTN"), OrientGB);
686   OrientGroup->addButton( RBvert );
687   OrientGroup->addButton( RBhori );
688   OrientGroupLayout->addWidget( RBvert, 0, 0 );
689   OrientGroupLayout->addWidget( RBhori, 0, 1 );
690
691   // Origin ===============================================================
692   QGroupBox* OriginGroup = new QGroupBox (tr("ORIGIN_GRP"), this);
693   aMainLayout->addWidget( OriginGroup );
694   QGridLayout* OriginGroupLayout = new QGridLayout( OriginGroup );
695   OriginGroupLayout->setAlignment( Qt::AlignTop );
696   //OriginGroupLayout->setSpacing( 6 );
697   //OriginGroupLayout->setMargin( 11 );
698
699   QLabel* XLabel = new QLabel (tr("LBL_X"), OriginGroup);
700   XSpin = new SalomeApp_DoubleSpinBox( OriginGroup );
701   VISU::initSpinBox( XSpin, 0.0, +1.0, .1, "parametric_precision" );
702   XSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
703   //XSpin->setMinimumWidth( 70 );
704   XSpin->setValue( 0.01 );
705
706   QLabel* YLabel = new QLabel (tr("LBL_Y"), OriginGroup);
707   YSpin = new SalomeApp_DoubleSpinBox( OriginGroup );
708   VISU::initSpinBox( YSpin, 0.0, +1.0, .1, "parametric_precision" );  
709   YSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
710   //YSpin->setMinimumWidth( 70 );
711   YSpin->setValue( 0.1 );
712
713   OriginGroupLayout->addWidget( XLabel, 0, 0);
714   OriginGroupLayout->addWidget( XSpin,  0, 1);
715   OriginGroupLayout->addWidget( YLabel, 0, 2);
716   OriginGroupLayout->addWidget( YSpin,  0, 3);
717
718   // Dimensions =========================================================
719   QGroupBox* DimGroup = new QGroupBox (tr("DIMENSIONS_GRP"), this );
720   aMainLayout->addWidget( DimGroup );
721   QGridLayout* DimGroupLayout = new QGridLayout( DimGroup );
722   DimGroupLayout->setAlignment( Qt::AlignTop );
723   //DimGroupLayout->setSpacing( 6 );
724   //DimGroupLayout->setMargin( 11 );
725
726   QLabel* WidthLabel = new QLabel (tr("LBL_WIDTH"), DimGroup);
727   WidthSpin = new SalomeApp_DoubleSpinBox( DimGroup );
728   VISU::initSpinBox( WidthSpin, 0.0, +1.0, .1, "parametric_precision" );    
729   WidthSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
730   //WidthSpin->setMinimumWidth( 70 );
731   WidthSpin->setValue( 0.1 );
732
733   QLabel* HeightLabel = new QLabel (tr("LBL_HEIGHT"), DimGroup);
734   HeightSpin = new SalomeApp_DoubleSpinBox( DimGroup );
735   VISU::initSpinBox( HeightSpin, 0.0, +1.0, .1, "parametric_precision" );
736   HeightSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
737   //HeightSpin->setMinimumWidth( 70 );
738   HeightSpin->setValue( 0.8 );
739
740   DimGroupLayout->addWidget( WidthLabel, 0, 0);
741   DimGroupLayout->addWidget( WidthSpin,  0, 1);
742   DimGroupLayout->addWidget( HeightLabel, 0, 2);
743   DimGroupLayout->addWidget( HeightSpin,  0, 3);
744
745   // Save check box ===========================================================
746   QWidget* aSaveBox = new QWidget(this);
747   aMainLayout->addWidget( aSaveBox );
748   QHBoxLayout* aVBLay = new QHBoxLayout( aSaveBox );
749   aVBLay->addWidget( myTextBtn = new QPushButton("Text properties...", aSaveBox) );
750   aVBLay->addWidget( myBarBtn  = new QPushButton("Bar properties...",  aSaveBox) );
751
752   aMainLayout->addWidget( myTextDlg = new VisuGUI_TextPrefDlg(this) );
753   myTextDlg->setTitleVisible(!thePreview);
754   myBarDlg = new VisuGUI_BarPrefDlg(this);
755
756   QGroupBox* CheckGroup = new QGroupBox("", this );
757   aMainLayout->addWidget( CheckGroup );
758   //QHBoxLayout* CheckGroupLayout = new QHBoxLayout( CheckGroup );
759   QGridLayout* CheckGroupLayout = new QGridLayout( CheckGroup );
760
761   myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), CheckGroup);
762   myPreviewCheck->setChecked(false);
763   CheckGroupLayout->addWidget(myPreviewCheck, 0, 0);
764
765   myHideBar = new QCheckBox(tr("HIDE_SCALAR_BAR"), CheckGroup);
766   myHideBar->setChecked(false);
767   CheckGroupLayout->addWidget(myHideBar, 0, 1);
768
769 // RKV : Begin
770   CBDistr = new QCheckBox (tr("SHOW_DISTRIBUTION"), CheckGroup);
771   CheckGroupLayout->addWidget(CBDistr, 1, 0);
772 // RKV : End
773   if (!thePreview) {
774     CBSave = new QCheckBox (tr("SAVE_DEFAULT_CHK"), CheckGroup);
775     CheckGroupLayout->addWidget( CBSave, 1, 1 );
776   }
777   else {
778     CBSave = 0;
779     myPreviewCheck->hide();
780     CheckGroup->hide();
781   }
782
783   if(RBvert->isChecked()) {
784     myBarDlg->setRatios(myVerTS, myVerLS, myVerBW, myVerBH);
785   } else {
786     myBarDlg->setRatios(myHorTS, myHorLS, myHorBW, myHorBH);
787   }
788
789   int lp = aResourceMgr->integerValue( "VISU", propertyName + "scalar_bar_label_precision", 3 );
790   myBarDlg->setLabelsPrecision( lp );
791
792   myBarDlg->setUnitsVisible(aResourceMgr->booleanValue("VISU", propertyName + "display_units", true));
793
794   // signals and slots connections ===========================================
795   connect( RBFrange,   SIGNAL( toggled( bool ) ), this, SLOT( onFieldRange( bool ) ) );
796   connect( RBIrange,   SIGNAL( toggled( bool ) ), this, SLOT( onImposedRange( bool ) ) );
797
798   connect( myModeCombo,    SIGNAL( activated( int ) ),       this, SLOT( changeScalarMode( int ) ) );
799   connect( myGaussMetric,  SIGNAL( activated( int ) ),       this, SLOT( changeGaussMetric( int ) ) );
800   connect( OrientGroup,    SIGNAL( buttonClicked( int ) ),   this, SLOT( changeDefaults( int ) ) );
801   connect( XSpin,          SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
802   connect( YSpin,          SIGNAL( valueChanged( double ) ), this, SLOT( XYChanged( double ) ) );
803   connect( myTextBtn,      SIGNAL( clicked() ),              this, SLOT( onTextPref() ) );
804   connect( myBarBtn,       SIGNAL( clicked() ),              this, SLOT( onBarPref() ) );
805   connect( myPreviewCheck, SIGNAL( toggled( bool )),         this, SLOT( onPreviewCheck( bool ) ) );
806
807   connect( CBDistr,        SIGNAL( toggled( bool ) ),        this, SLOT( onShowDistribution( bool ) )); // RKV
808
809   connect( ColorSpin,      SIGNAL( valueChanged( int ) ),    this, SLOT( updatePreview() ));
810   connect( LabelSpin,      SIGNAL( valueChanged( int ) ),    this, SLOT( updatePreview() ));
811   connect( WidthSpin,      SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
812   connect( HeightSpin,     SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ));
813   connect( CBLog,          SIGNAL( toggled( bool ) ),        this, SLOT( updatePreview() ));
814   connect( myBarDlg,       SIGNAL( updatePreview() ),        this, SLOT( updatePreview() ));
815   changeDefaults( 0 );
816   myIsStoreTextProp = false;
817   myBusy = false;
818 }
819
820 /**
821  * Stores dialog values to resources
822  */
823 void VisuGUI_ScalarBarPane::storeToResources() {
824   int orient = (RBvert->isChecked())? 0 : 1;
825   float sbX1   = XSpin->value();
826   float sbY1   = YSpin->value();
827   float sbW    = WidthSpin->value();
828   float sbH    = HeightSpin->value();
829   int sbCol  = ColorSpin->value();
830   int sbLab  = LabelSpin->value();
831
832   if((sbX1 < 0.) || (sbY1 < 0.) || ((sbX1+sbW) > 1.) || ((sbY1+sbH) > 1.)) {
833     if(orient == 0) {
834       sbX1=0.01;
835       sbY1=0.1;
836       sbW=0.1;
837       sbH=0.8;
838     } else {
839       sbX1=0.1;
840       sbY1=0.01;
841       sbW=0.8;
842       sbH=0.08;
843     }
844   }
845
846   bool sbRange = RBIrange->isChecked();
847   float sbVmin = (float)(MinEdit->text().toDouble());
848   float sbVmax = (float)(MaxEdit->text().toDouble());
849
850   if(sbVmin > sbVmax) {
851     sbVmin=0.;
852     sbVmax=0.;
853   }
854
855   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
856
857   aResourceMgr->setValue("VISU", "scalar_bar_orientation", orient);
858
859   QString propertyName = QString( "scalar_bar_%1_" ).arg( orient == 0 ? "vertical" : "horizontal" );
860
861   aResourceMgr->setValue("VISU", propertyName + "x", sbX1);
862   aResourceMgr->setValue("VISU", propertyName + "y", sbY1);
863   aResourceMgr->setValue("VISU", propertyName + "width", sbW);
864   aResourceMgr->setValue("VISU", propertyName + "height", sbH);
865
866   aResourceMgr->setValue("VISU", "scalar_bar_num_colors", sbCol);
867   aResourceMgr->setValue("VISU", "scalar_bar_num_labels", sbLab);
868
869   if(sbRange)
870     {
871       aResourceMgr->setValue("VISU", "scalar_range_type", 1);
872       aResourceMgr->setValue("VISU", "scalar_range_min" ,sbVmin);
873       aResourceMgr->setValue("VISU", "scalar_range_max" ,sbVmax);
874     }
875   else
876     aResourceMgr->setValue("VISU", "scalar_range_type", 0);
877
878   aResourceMgr->setValue("VISU", "scalar_bar_logarithmic", isLogarithmic());
879   aResourceMgr->setValue("VISU", "scalar_bar_show_distribution", isShowDistribution()); // RKV
880
881   ////
882
883   if (myIsStoreTextProp) {
884     // "Title"
885     QColor aTitleColor (255, 255, 255);
886     int aTitleFontFamily = VTK_ARIAL;
887     bool isTitleBold = false;
888     bool isTitleItalic = false;
889     bool isTitleShadow = false;
890
891     myTextDlg->myTitleFont->GetData(aTitleColor, aTitleFontFamily,
892                                     isTitleBold, isTitleItalic, isTitleShadow);
893
894     QFont aTitleFont;
895
896     aTitleFont.setBold(isTitleBold);
897     aTitleFont.setItalic(isTitleItalic);
898     aTitleFont.setOverline(isTitleShadow);
899
900     QString titleFontFamily;
901     switch (aTitleFontFamily) {
902     case VTK_ARIAL:
903       titleFontFamily = "Arial";
904       break;
905     case VTK_COURIER:
906       titleFontFamily = "Courier";
907       break;
908     case VTK_TIMES:
909       titleFontFamily = "Times";
910       break;
911     }
912     aTitleFont.setFamily(titleFontFamily);
913
914     aResourceMgr->setValue("VISU", "scalar_bar_title_font", aTitleFont);
915
916     aResourceMgr->setValue("VISU", "scalar_bar_title_color", aTitleColor);
917
918     // "Label"
919     QColor aLabelColor (255, 255, 255);
920     int aLabelFontFamily = VTK_ARIAL;
921     bool isLabelBold = false;
922     bool isLabelItalic = false;
923     bool isLabelShadow = false;
924
925     myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
926                                     isLabelBold, isLabelItalic, isLabelShadow);
927
928
929     QFont aLabelFont;
930
931     aLabelFont.setBold(isLabelBold);
932     aLabelFont.setItalic(isLabelItalic);
933     aLabelFont.setOverline(isLabelShadow);
934
935     QString labelFontFamily;
936     switch (aLabelFontFamily) {
937     case VTK_ARIAL:
938       labelFontFamily = "Arial";
939       break;
940     case VTK_COURIER:
941       labelFontFamily = "Courier";
942       break;
943     case VTK_TIMES:
944       labelFontFamily = "Times";
945       break;
946     }
947
948     aLabelFont.setFamily(labelFontFamily);
949
950     aResourceMgr->setValue("VISU", "scalar_bar_label_font", aLabelFont);
951
952     aResourceMgr->setValue("VISU", "scalar_bar_label_color", aLabelColor);
953   }
954 }
955
956 //----------------------------------------------------------------------------
957 VisuGUI_ScalarBarPane::~VisuGUI_ScalarBarPane()
958 {
959   deleteScalarBar();
960   if (SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
961     aViewWindow->Repaint();
962 }
963
964 //----------------------------------------------------------------------------
965 /**
966  * Initialise dialog box from presentation object
967  */
968 void VisuGUI_ScalarBarPane::initFromPrsObject(VISU::ColoredPrs3d_i* thePrs)
969 {
970   myScalarMap = dynamic_cast<VISU::ScalarMap_i*>(thePrs);
971
972   if( !myScalarMap )
973     return;
974
975   switch(myScalarMap->GetScaling()){
976   case VISU::LOGARITHMIC :
977     setLogarithmic(true);
978     break;
979   default:
980     setLogarithmic(false);
981   }
982
983   // Update myModeCombo
984   const VISU::PField& aField = myScalarMap->GetScalarField();
985   const VISU::TNames& aCompNames = aField->myCompNames;
986   const VISU::TNames& aUnitNames = aField->myUnitNames;
987   int aNbComp = aField->myNbComp;
988   bool isScalarMode = (aNbComp > 1);
989   myModeCombo->clear();
990   myModeCombo->addItem("<Modulus>");
991   for(int i = 0; i < aNbComp; i++){
992     QString aComponent = QString(aCompNames[i].c_str()).simplified();
993     if(aComponent.isNull() || aComponent == "")
994       aComponent = "Component " + QString::number(i+1);
995     else
996       aComponent = "[" + QString::number(i+1) + "] " + aComponent;
997
998     QString anUnit = QString(aUnitNames[i].c_str()).simplified();
999     if(anUnit.isNull() || anUnit == "")
1000       anUnit = "-";
1001
1002     aComponent = aComponent + ", " + anUnit;
1003
1004     myModeCombo->addItem(aComponent);
1005   }
1006
1007   myModeCombo->setCurrentIndex(myScalarMap->GetScalarMode());
1008   if ( aNbComp == 1 )
1009     myModeCombo->setCurrentIndex(1);
1010
1011   myModeLbl->setEnabled(isScalarMode);
1012   myModeCombo->setEnabled(isScalarMode);
1013
1014   // Gauss Metric option should be visible only if at least one
1015   // of mesh values on geometry is based on multiple gauss points
1016   bool isEnableGaussMetric = false;
1017   if( myIsDisplayGaussMetric ) {
1018     const VISU::TValField& aValField = aField->myValField;
1019     VISU::TValField::const_iterator anIter = aValField.find(myScalarMap->GetScalarTimeStampNumber());
1020     if ( anIter != aValField.end() ) {
1021       VISU::PValForTime aValForTime = anIter->second;
1022       if( aValForTime && aValForTime->GetMaxNbGauss() > 1 )
1023         isEnableGaussMetric = true;
1024     }
1025   }
1026
1027   myGaussMetricLabel->setEnabled(isEnableGaussMetric);
1028   myGaussMetric->setEnabled(isEnableGaussMetric);
1029   if( isEnableGaussMetric )
1030     myGaussMetric->setCurrentIndex((int)myScalarMap->GetGaussMetric());
1031
1032   setRange( myScalarMap->GetMin(), myScalarMap->GetMax(), myScalarMap->IsRangeFixed() );
1033
1034   setScalarBarData( myScalarMap->GetNbColors(), myScalarMap->GetLabels() );
1035   setShowDistribution( myScalarMap->GetIsDistributionVisible() );
1036
1037   // "Title"
1038   CORBA::String_var aTitle = myScalarMap->GetTitle();
1039   myTextDlg->setTitleText(aTitle.in());
1040   myTitle = aTitle.in();
1041
1042   setPosAndSize( myScalarMap->GetPosX(),
1043                  myScalarMap->GetPosY(),
1044                  myScalarMap->GetWidth(),
1045                  myScalarMap->GetHeight(),
1046                  myScalarMap->GetBarOrientation());
1047
1048   if(RBvert->isChecked()) {
1049     myVerTS = myScalarMap->GetTitleSize();
1050     myVerLS = myScalarMap->GetLabelSize();
1051     myVerBW = myScalarMap->GetBarWidth();
1052     myVerBH = myScalarMap->GetBarHeight();
1053     myBarDlg->setRatios(myVerTS, myVerLS, myVerBW, myVerBH);
1054   } else {
1055     myHorTS = myScalarMap->GetTitleSize();
1056     myHorLS = myScalarMap->GetLabelSize();
1057     myHorBW = myScalarMap->GetBarWidth();
1058     myHorBH = myScalarMap->GetBarHeight();
1059     myBarDlg->setRatios(myHorTS, myHorLS, myHorBW, myHorBH);
1060   }
1061
1062   myBarDlg->setLabelsPrecision( VISU::ToPrecision( myScalarMap->GetLabelsFormat() ) );
1063   myBarDlg->setUnitsVisible(myScalarMap->IsUnitsVisible());
1064
1065   vtkFloatingPointType R, G, B;
1066   myScalarMap->GetTitleColor(R, G, B);
1067
1068   QColor aTextColor = QColor((int)(R*255.), (int)(G*255.), (int)(B*255.));
1069
1070   myTextDlg->myTitleFont->SetData(aTextColor,
1071                                   myScalarMap->GetTitFontType(),
1072                                   myScalarMap->IsBoldTitle(),
1073                                   myScalarMap->IsItalicTitle(),
1074                                   myScalarMap->IsShadowTitle());
1075
1076   // "Labels"
1077   myScalarMap->GetLabelColor(R, G, B);
1078
1079   QColor aLabelColor = QColor((int)(R*255.), (int)(G*255.), (int)(B*255.));
1080
1081   myTextDlg->myLabelFont->SetData(aLabelColor,
1082                                   myScalarMap->GetLblFontType(),
1083                                   myScalarMap->IsBoldLabel(),
1084                                   myScalarMap->IsItalicLabel(),
1085                                   myScalarMap->IsShadowLabel());
1086
1087   myHideBar->setChecked(!myScalarMap->IsBarVisible());
1088
1089   // Draw Preview
1090   if (myPreviewCheck->isChecked()) {
1091     createScalarBar();
1092     updatePreview();
1093   }
1094
1095 }
1096
1097
1098 //----------------------------------------------------------------------------
1099 /*! Slot update preview of scalar bar, if preview is checked
1100  */
1101 void VisuGUI_ScalarBarPane::updatePreview()
1102 {
1103   if (myPreviewCheck->isChecked()) {
1104     if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
1105       deleteScalarBar();
1106       createScalarBar();
1107       vf->Repaint();
1108     }
1109   }
1110 }
1111
1112 //----------------------------------------------------------------------------
1113 /*! Creating preview scalar bar
1114  */
1115 void VisuGUI_ScalarBarPane::createScalarBar()
1116 {
1117   if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
1118   if (myPreviewActor != 0) return;
1119   if (myScalarMap == NULL) return;
1120
1121   if (!check()) return;
1122   myScalarMapPL = VISU_ScalarMapPL::New();
1123   if(myScalarMap->GetSpecificPL())
1124     myScalarMapPL->ShallowCopy(myScalarMap->GetSpecificPL(), true);
1125
1126   if ( myBusy ) return;
1127
1128   myBusy = true;
1129
1130   int sbCol,sbLab;
1131   sbCol = getNbColors();
1132   sbLab = getNbLabels();
1133   if(sbCol < 2) sbCol=2;
1134   if(sbCol > 64) sbCol=64;
1135   if(sbLab < 2) sbLab=2;
1136   if(sbLab > 65) sbLab=65;
1137   myPreviewActor = VISU_ScalarMapAct::New();
1138   VISU_ScalarBarActor* aScalarBarActor = myPreviewActor->GetScalarBar();
1139   myPreviewActor->GetScalarBar()->VisibilityOn();
1140   myPreviewActor->PickableOff();
1141   //myPreviewActor->SetBarVisibility(!myHideBar->isChecked());
1142
1143   myScalarMapPL->SetScalarMode(myModeCombo->currentIndex());
1144   if(isLogarithmic())
1145     myScalarMapPL->SetScaling(VISU::LOGARITHMIC);
1146   else
1147     myScalarMapPL->SetScaling(VISU::LINEAR);
1148
1149   if( myGaussMetric->isVisible() )
1150     myScalarMapPL->SetGaussMetric((VISU::TGaussMetric)myGaussMetric->currentIndex());
1151
1152   if ( RBFrange->isChecked() ) {
1153     myScalarMapPL->SetSourceRange();
1154   } else {
1155     vtkFloatingPointType aRange[2];
1156     aRange[0] = (vtkFloatingPointType)MinEdit->text().toDouble();
1157     aRange[1] = (vtkFloatingPointType)MaxEdit->text().toDouble();
1158     myScalarMapPL->SetScalarRange( aRange );
1159   }
1160
1161   myScalarMapPL->SetNbColors(sbCol);
1162   myScalarMapPL->Update();
1163
1164   aScalarBarActor->SetLookupTable(myScalarMapPL->GetBarTable());
1165   aScalarBarActor->SetDistribution( myScalarMapPL->GetDistribution() );
1166   aScalarBarActor->SetDistributionVisibility( isShowDistribution() );
1167
1168   if (!myTextDlg->getTitleText().isEmpty()) {
1169     VISU::PValForTime aValForTime;
1170     const VISU::PField& aField = myScalarMap->GetScalarField();
1171     const VISU::TValField& aValField = aField->myValField;
1172     VISU::TValField::const_iterator anIter = aValField.find(myScalarMap->GetScalarTimeStampNumber());
1173     if (anIter != aValField.end())
1174       aValForTime = anIter->second;
1175
1176     if (aValForTime) {
1177       std::stringstream aStream;
1178       const VISU::TTime& aTime = aValForTime->myTime;
1179       aStream<< myTextDlg->getTitleText().toLatin1().data() <<" ";
1180       if(myBarDlg->isUnitsVisible())
1181         aStream<<VISU_Convertor::GenerateName(aTime)<<std::ends;
1182       else {
1183         QString aName;
1184         aName.sprintf("%g", aTime.first);
1185         aStream << aName.toLatin1().data() << std::ends;
1186       }
1187       std::string aScalarBarTitle = aStream.str();
1188       aScalarBarActor->SetTitle(aScalarBarTitle.c_str());
1189     } else {
1190       aScalarBarActor->SetTitle(myTextDlg->getTitleText().toLatin1().data());
1191     }
1192   }
1193   else
1194     aScalarBarActor->SetTitle(myTitle.c_str());
1195   aScalarBarActor->SetOrientation(getOrientation());
1196   aScalarBarActor->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
1197   aScalarBarActor->GetPositionCoordinate()->SetValue(getX(),getY());
1198   aScalarBarActor->SetWidth(getWidth());
1199   aScalarBarActor->SetHeight(getHeight());
1200   aScalarBarActor->SetNumberOfLabels(sbLab);
1201   aScalarBarActor->SetMaximumNumberOfColors(sbCol);
1202
1203   // title text property
1204   QColor aTitleColor;
1205   int aTitleFontFamily;
1206   bool isTitleBold;
1207   bool isTitleItalic;
1208   bool isTitleShadow;
1209   myTextDlg->myTitleFont->GetData(aTitleColor,aTitleFontFamily,
1210                                   isTitleBold,isTitleItalic,isTitleShadow);
1211   vtkTextProperty* aTitleProp = aScalarBarActor->GetTitleTextProperty();
1212   aTitleProp->SetFontFamily(aTitleFontFamily);
1213   aTitleProp->SetColor(vtkFloatingPointType(aTitleColor.red())/255.,
1214                        vtkFloatingPointType(aTitleColor.green())/255.,
1215                        vtkFloatingPointType(aTitleColor.blue())/255.);
1216   (isTitleBold)? aTitleProp->BoldOn() : aTitleProp->BoldOff();
1217   (isTitleItalic)? aTitleProp->ItalicOn() : aTitleProp->ItalicOff();
1218   (isTitleShadow)? aTitleProp->ShadowOn() : aTitleProp->ShadowOff();
1219
1220   // label text property
1221   QColor aLabelColor;
1222   int aLabelFontFamily;
1223   bool isLabelBold;
1224   bool isLabelItalic;
1225   bool isLabelShadow;
1226   myTextDlg->myLabelFont->GetData(aLabelColor, aLabelFontFamily,
1227                                   isLabelBold, isLabelItalic, isLabelShadow);
1228   vtkTextProperty* aLabelProp = aScalarBarActor->GetLabelTextProperty();
1229   aLabelProp->SetFontFamily(aLabelFontFamily);
1230   aLabelProp->SetColor(vtkFloatingPointType(aLabelColor.red())/255.,
1231                        vtkFloatingPointType(aLabelColor.green())/255.,
1232                        vtkFloatingPointType(aLabelColor.blue())/255.);
1233   (isLabelBold)? aLabelProp->BoldOn() : aLabelProp->BoldOff();
1234   (isLabelItalic)? aLabelProp->ItalicOn() : aLabelProp->ItalicOff();
1235   (isLabelShadow)? aLabelProp->ShadowOn() : aLabelProp->ShadowOff();
1236
1237   int VerTS, VerLS, VerBW, VerBH;
1238   myBarDlg->getRatios(VerTS, VerLS, VerBW, VerBH);
1239   aScalarBarActor->SetRatios(VerTS, VerLS, VerBW, VerBH);
1240
1241   std::string f = VISU::ToFormat( myBarDlg->getLabelsPrecision() );
1242   aScalarBarActor->SetLabelFormat( f.c_str() );
1243
1244   aScalarBarActor->Modified();
1245
1246   VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
1247
1248   myBusy = false;
1249 }
1250
1251
1252 //----------------------------------------------------------------------------
1253 /*! Deleting preview scalar bar
1254  */
1255 void VisuGUI_ScalarBarPane::deleteScalarBar()
1256 {
1257   if ( myBusy ) return;
1258
1259   if (myPreviewActor == 0) return;
1260   vtkRenderer* aRend       = myPreviewActor->GetRenderer();
1261   vtkRenderWindow* aWnd = aRend->GetRenderWindow();
1262   if(aRend && aWnd)
1263     myPreviewActor->RemoveFromRender(aRend);
1264   myPreviewActor->GetScalarBar()->VisibilityOff();
1265   myPreviewActor->Delete();
1266   myPreviewActor = 0;
1267
1268   if (myScalarMapPL){
1269     myScalarMapPL->Delete();
1270     myScalarMapPL = 0;
1271   }
1272 }
1273
1274
1275 //----------------------------------------------------------------------------
1276 /**
1277  * Store values to presentation object
1278  */
1279 int VisuGUI_ScalarBarPane::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs) {
1280   if( !myScalarMap )
1281     return 0;
1282
1283   myScalarMap->SetScalarMode(myModeCombo->currentIndex());
1284   if( myGaussMetric->isVisible() )
1285     myScalarMap->SetGaussMetric((VISU::GaussMetric)myGaussMetric->currentIndex());
1286   myScalarMap->SetPosition(XSpin->value(), YSpin->value());
1287   myScalarMap->SetSize(WidthSpin->value(), HeightSpin->value());
1288   if(RBvert->isChecked()) {
1289     myScalarMap->SetRatios(myVerTS, myVerLS, myVerBW, myVerBH);
1290   } else {
1291     myScalarMap->SetRatios(myHorTS, myHorLS, myHorBW, myHorBH);
1292   }
1293
1294   std::string f = VISU::ToFormat( myBarDlg->getLabelsPrecision() );
1295   myScalarMap->SetLabelsFormat( f.c_str() );
1296   myScalarMap->SetUnitsVisible(myBarDlg->isUnitsVisible());
1297
1298   myScalarMap->SetBarOrientation((RBvert->isChecked())? VISU::ColoredPrs3dBase::VERTICAL : VISU::ColoredPrs3dBase::HORIZONTAL);
1299   if(isLogarithmic())
1300     myScalarMap->SetScaling(VISU::LOGARITHMIC);
1301   else
1302     myScalarMap->SetScaling(VISU::LINEAR);
1303
1304   if ( RBFrange->isChecked() ) {
1305     myScalarMap->SetSourceRange();
1306   } else {
1307     myScalarMap->SetRange( MinEdit->text().toDouble(), MaxEdit->text().toDouble() );
1308   }
1309   myScalarMap->SetNbColors(ColorSpin->value());
1310   myScalarMap->SetLabels(LabelSpin->value());
1311   myScalarMap->SetIsDistributionVisible(isShowDistribution()); // RKV
1312
1313   myScalarMap->SetBarVisible(!myHideBar->isChecked());
1314
1315   if (isToSave()) storeToResources();
1316
1317   if (myIsStoreTextProp) {
1318     // "Title"
1319     myScalarMap->SetTitle(myTextDlg->getTitleText().toLatin1().data());
1320
1321     QColor aTitColor (255, 255, 255);
1322     int aTitleFontFamily = VTK_ARIAL;
1323     bool isTitleBold = false;
1324     bool isTitleItalic = false;
1325     bool isTitleShadow = false;
1326
1327     myTextDlg->myTitleFont->GetData(aTitColor, aTitleFontFamily,
1328                                     isTitleBold, isTitleItalic, isTitleShadow);
1329
1330     myScalarMap->SetBoldTitle(isTitleBold);
1331     myScalarMap->SetItalicTitle(isTitleItalic);
1332     myScalarMap->SetShadowTitle(isTitleShadow);
1333     myScalarMap->SetTitFontType(aTitleFontFamily);
1334     myScalarMap->SetTitleColor(aTitColor.red()/255.,
1335                           aTitColor.green()/255.,
1336                           aTitColor.blue()/255.);
1337
1338     // "Label"
1339     QColor aLblColor (255, 255, 255);
1340     int aLabelFontFamily = VTK_ARIAL;
1341     bool isLabelBold = false;
1342     bool isLabelItalic = false;
1343     bool isLabelShadow = false;
1344
1345     myTextDlg->myLabelFont->GetData(aLblColor, aLabelFontFamily,
1346                                     isLabelBold, isLabelItalic, isLabelShadow);
1347
1348     myScalarMap->SetBoldLabel(isLabelBold);
1349     myScalarMap->SetItalicLabel(isLabelItalic);
1350     myScalarMap->SetShadowLabel(isLabelShadow);
1351     myScalarMap->SetLblFontType(aLabelFontFamily);
1352     myScalarMap->SetLabelColor(aLblColor.red()/255.,
1353                                aLblColor.green()/255.,
1354                                aLblColor.blue()/255.);
1355     myIsStoreTextProp = false;
1356   }
1357
1358   return 1;
1359 }
1360
1361
1362 //----------------------------------------------------------------------------
1363 /*!
1364   Called when orientation is changed
1365 */
1366 void VisuGUI_ScalarBarPane::changeDefaults( int )
1367 {
1368   if ( RBvert->isChecked() ) {
1369     XSpin->setValue( myVerX );
1370     YSpin->setValue( myVerY );
1371     WidthSpin->setValue( myVerW );
1372     HeightSpin->setValue( myVerH );
1373   }
1374   else {
1375     XSpin->setValue( myHorX );
1376     YSpin->setValue( myHorY );
1377     WidthSpin->setValue( myHorW );
1378     HeightSpin->setValue( myHorH );
1379   }
1380   updatePreview();
1381 }
1382
1383
1384 //----------------------------------------------------------------------------
1385 /*!
1386   Called when Range mode is changed
1387 */
1388 void VisuGUI_ScalarBarPane::onFieldRange( bool isOn )
1389 {
1390   if (isOn) {
1391     myScalarMap->SetSourceRange();
1392     MinEdit->setEnabled( false );
1393     MaxEdit->setEnabled( false );
1394     changeScalarMode(myModeCombo->currentIndex());
1395   }
1396 }
1397
1398 void VisuGUI_ScalarBarPane::onImposedRange( bool isOn )
1399 {
1400   if (isOn) {
1401     myScalarMap->SetRange( myScalarMap->GetSourceMin(), myScalarMap->GetSourceMax() );
1402     MinEdit->setEnabled( true );
1403     MaxEdit->setEnabled( true );
1404     changeScalarMode(myModeCombo->currentIndex());
1405   }
1406 }
1407
1408 void VisuGUI_ScalarBarPane::onShowDistribution( bool isOn )
1409 {
1410   myScalarMap->SetIsDistributionVisible(isOn);
1411   updatePreview();
1412 }
1413
1414 void VisuGUI_ScalarBarPane::changeRange( int )
1415 {
1416   if ( RBFrange->isChecked() ) {
1417     myScalarMap->SetSourceRange();
1418     MinEdit->setEnabled( false );
1419     MaxEdit->setEnabled( false );
1420   } else {
1421     myScalarMap->SetRange( myScalarMap->GetSourceMin(), myScalarMap->GetSourceMax() );
1422     MinEdit->setEnabled( true );
1423     MaxEdit->setEnabled( true );
1424   }
1425
1426   changeScalarMode(myModeCombo->currentIndex());
1427 }
1428
1429
1430 //----------------------------------------------------------------------------
1431 /*!
1432   Called when X,Y position is changed
1433 */
1434 void VisuGUI_ScalarBarPane::XYChanged( double )
1435 {
1436   SalomeApp_DoubleSpinBox* snd = (SalomeApp_DoubleSpinBox*)sender();
1437   if ( snd == XSpin ) {
1438     WidthSpin->setMaximum( 1.0 - XSpin->value() );
1439   }
1440   if ( snd == YSpin ) {
1441     HeightSpin->setMaximum( 1.0 - YSpin->value() );
1442   }
1443   updatePreview();
1444 }
1445
1446
1447 //----------------------------------------------------------------------------
1448 /*!
1449   Called when scalar mode is changed
1450 */
1451 void VisuGUI_ScalarBarPane::changeScalarMode( int theMode )
1452 {
1453   myScalarMap->SetScalarMode(theMode);
1454
1455   if ( RBFrange->isChecked() ) {
1456     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
1457     int aPrecision = qAbs( aResourceMgr->integerValue("VISU", "visual_data_precision", 0) );
1458
1459     MinEdit->setText(QString::number(myScalarMap->GetSourceMin(), 'g', aPrecision));
1460     MaxEdit->setText(QString::number(myScalarMap->GetSourceMax(), 'g', aPrecision));
1461   }
1462
1463   updatePreview();
1464 }
1465
1466
1467 //----------------------------------------------------------------------------
1468 /*!
1469   Called when scalar mode is changed
1470 */
1471 void VisuGUI_ScalarBarPane::changeGaussMetric( int theGaussMetric )
1472 {
1473   myScalarMap->SetGaussMetric((VISU::GaussMetric)theGaussMetric);
1474
1475   if ( RBFrange->isChecked() ) {
1476     SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
1477     int aPrecision = qAbs( aResourceMgr->integerValue("VISU", "visual_data_precision", 0) );
1478
1479     MinEdit->setText(QString::number(myScalarMap->GetSourceMin(), 'g', aPrecision));
1480     MaxEdit->setText(QString::number(myScalarMap->GetSourceMax(), 'g', aPrecision));
1481   }
1482
1483   updatePreview();
1484 }
1485
1486
1487 //----------------------------------------------------------------------------
1488 /*!
1489   Sets default values and range mode
1490 */
1491 void VisuGUI_ScalarBarPane::setRange( double imin, double imax, bool sbRange )
1492 {
1493   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
1494   int aPrecision = qAbs( aResourceMgr->integerValue("VISU", "visual_data_precision", 0) );
1495
1496   MinEdit->setText(QString::number(imin, 'g', aPrecision+1)); // VSR +1 is for 'g' format
1497   MaxEdit->setText(QString::number(imax, 'g', aPrecision+1)); // VSR +1 is for 'g' format
1498
1499   if( sbRange )
1500     RBIrange->setChecked( true );
1501   else
1502     RBFrange->setChecked( true );
1503
1504   changeRange( sbRange );
1505 }
1506
1507
1508 //----------------------------------------------------------------------------
1509 /*!
1510   Sets and gets parameters
1511 */
1512 bool VisuGUI_ScalarBarPane::isIRange() {
1513   return RBIrange->isChecked();
1514 }
1515
1516
1517 //----------------------------------------------------------------------------
1518 double VisuGUI_ScalarBarPane::getMin() {
1519   return MinEdit->text().toDouble();
1520 }
1521
1522
1523 //----------------------------------------------------------------------------
1524 double VisuGUI_ScalarBarPane::getMax() {
1525   return MaxEdit->text().toDouble();
1526 }
1527
1528
1529 //----------------------------------------------------------------------------
1530 double VisuGUI_ScalarBarPane::getX() {
1531   return XSpin->value();
1532 }
1533
1534
1535 //----------------------------------------------------------------------------
1536 double VisuGUI_ScalarBarPane::getY() {
1537   return YSpin->value();
1538 }
1539
1540
1541 //----------------------------------------------------------------------------
1542 double VisuGUI_ScalarBarPane::getWidth() {
1543   return WidthSpin->value();
1544 }
1545
1546
1547 //----------------------------------------------------------------------------
1548 double VisuGUI_ScalarBarPane::getHeight() {
1549   return HeightSpin->value();
1550 }
1551
1552
1553 //----------------------------------------------------------------------------
1554 int VisuGUI_ScalarBarPane::getNbColors() {
1555   return ColorSpin->value();
1556 }
1557
1558
1559 //----------------------------------------------------------------------------
1560 int VisuGUI_ScalarBarPane::getNbLabels() {
1561   return LabelSpin->value();
1562 }
1563
1564
1565 //----------------------------------------------------------------------------
1566 bool VisuGUI_ScalarBarPane::isLogarithmic() {
1567   return CBLog->isChecked();
1568 }
1569
1570
1571 //----------------------------------------------------------------------------
1572 void VisuGUI_ScalarBarPane::setLogarithmic( bool on ) {
1573   CBLog->setChecked( on );
1574 }
1575
1576 //----------------------------------------------------------------------------
1577 bool VisuGUI_ScalarBarPane::isShowDistribution() {
1578   return CBDistr->isChecked();
1579 }
1580
1581
1582 //----------------------------------------------------------------------------
1583 void VisuGUI_ScalarBarPane::setShowDistribution( bool on ) {
1584   CBDistr->setChecked( on );
1585 }
1586
1587 // RKV : End
1588 //----------------------------------------------------------------------------
1589 bool VisuGUI_ScalarBarPane::isToSave() {
1590   return CBSave ? CBSave->isChecked() : false;
1591 }
1592
1593 //----------------------------------------------------------------------------
1594 /*!
1595   Sets size and position
1596 */
1597 void VisuGUI_ScalarBarPane::setPosAndSize( double x, double y, double w, double h, bool vert )
1598 {
1599   if ( vert ) {
1600     myVerX = x;
1601     myVerY = y;
1602     myVerW = w;
1603     myVerH = h;
1604     RBvert->setChecked( true );
1605   }
1606   else {
1607     myHorX = x;
1608     myHorY = y;
1609     myHorW = w;
1610     myHorH = h;
1611     RBhori->setChecked( true );
1612   }
1613   changeDefaults( 0 );
1614 }
1615
1616
1617 //----------------------------------------------------------------------------
1618 /*!
1619   Sets colors and labels number
1620 */
1621 void VisuGUI_ScalarBarPane::setScalarBarData( int colors, int labels )
1622 {
1623   ColorSpin->setValue( colors );
1624   LabelSpin->setValue( labels );
1625 }
1626
1627
1628 //----------------------------------------------------------------------------
1629 /*!
1630   Gets orientation
1631 */
1632 int  VisuGUI_ScalarBarPane::getOrientation()
1633 {
1634   if (RBvert->isChecked() )
1635     return  1;
1636   else
1637     return 0;
1638 }
1639
1640
1641 //----------------------------------------------------------------------------
1642 /*!
1643   Called when <OK> button is clicked, validates data and closes dialog
1644 */
1645 bool VisuGUI_ScalarBarPane::check()
1646 {
1647   double minVal = MinEdit->text().toDouble();
1648   double maxVal = MaxEdit->text().toDouble();
1649   if ( RBIrange->isChecked() ) {
1650     if (minVal >= maxVal) {
1651       SUIT_MessageBox::warning( this,tr("WRN_VISU"),
1652                              tr("MSG_MINMAX_VALUES"),
1653                              tr("BUT_OK"));
1654       return false;
1655     }
1656   }
1657
1658   // check if logarithmic mode is on and check imposed range to not contain negative values
1659   if ( CBLog->isChecked() ) {
1660     if ( minVal <= 0.0 || maxVal <= 0.0 ) {
1661       if ( RBIrange->isChecked() ) {
1662         SUIT_MessageBox::warning( this,
1663                                   tr("WRN_VISU"),
1664                                   tr("WRN_LOGARITHMIC_RANGE"),
1665                                   tr("BUT_OK"));
1666       } else {
1667         if ( minVal == 0 || maxVal == 0 )
1668           SUIT_MessageBox::warning( this,
1669                                   tr("WRN_VISU"),
1670                                   tr("WRN_LOGARITHMIC_RANGE"),
1671                                   tr("BUT_OK"));
1672         else
1673           SUIT_MessageBox::warning( this,
1674                                     tr("WRN_VISU"),
1675                                     tr("WRN_LOGARITHMIC_FIELD_RANGE"),
1676                                     tr("BUT_OK"));
1677         RBIrange->setChecked(true);
1678         changeRange(1);
1679       }
1680       return false;
1681     }
1682   }
1683   return true;
1684 }
1685
1686
1687 //----------------------------------------------------------------------------
1688 void VisuGUI_ScalarBarPane::onTextPref()
1689 {
1690   myTextDlg->storeBeginValues();
1691   myIsStoreTextProp = myTextDlg->exec() || myIsStoreTextProp;
1692   updatePreview();
1693 }
1694
1695
1696 //----------------------------------------------------------------------------
1697 void VisuGUI_ScalarBarPane::onBarPref()
1698 {
1699   if(RBvert->isChecked())
1700     myBarDlg->setRatios(myVerTS, myVerLS, myVerBW, myVerBH);
1701   else
1702     myBarDlg->setRatios(myHorTS, myHorLS, myHorBW, myHorBH);
1703   myBarDlg->setOrientation( getOrientation() );
1704   if(myBarDlg->exec()) {
1705     if(RBvert->isChecked())
1706       myBarDlg->getRatios(myVerTS, myVerLS, myVerBW, myVerBH);
1707     else
1708       myBarDlg->getRatios(myHorTS, myHorLS, myHorBW, myHorBH);
1709     updatePreview();
1710   }
1711 }
1712
1713
1714 //----------------------------------------------------------------------------
1715 void VisuGUI_ScalarBarPane::onPreviewCheck (bool thePreview)
1716 {
1717   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
1718     if (thePreview) {
1719       createScalarBar();
1720     } else {
1721       deleteScalarBar();
1722     }
1723     vf->Repaint();
1724   }
1725 }
1726
1727 VisuGUI_Prs3dDlg::VisuGUI_Prs3dDlg( SalomeApp_Module* theModule )
1728   : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint )
1729 {
1730 }
1731
1732 //----------------------------------------------------------------------------
1733 /*!
1734   Called when <Help> button is clicked, shows the corresponding help page in defined browser
1735 */
1736 void VisuGUI_Prs3dDlg::onHelp()
1737 {
1738   QString aHelpFileName = GetContextHelpFilePath();
1739   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1740   if (app) {
1741     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
1742     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
1743   }
1744   else {
1745     SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ),
1746                               tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
1747                               arg( app->resourceMgr()->stringValue( "ExternalBrowser",
1748                                                                    "application" ) ).
1749                               arg( aHelpFileName ) );
1750   }
1751 }
1752
1753
1754 //----------------------------------------------------------------------------
1755 void VisuGUI_Prs3dDlg::keyPressEvent( QKeyEvent* e )
1756 {
1757   QDialog::keyPressEvent( e );
1758   if ( e->isAccepted() )
1759     return;
1760
1761   if ( e->key() == Qt::Key_F1 ) {
1762     e->accept();
1763     onHelp();
1764   }
1765 }
1766
1767 //----------------------------------------------------------------------------
1768 VisuGUI_ScalarBarBaseDlg::VisuGUI_ScalarBarBaseDlg( SalomeApp_Module* theModule, bool theIsDisplayGaussMetric, bool thePreview ) :
1769   VisuGUI_Prs3dDlg( theModule )
1770 {
1771   myScalarPane = new VisuGUI_ScalarBarPane(this, theIsDisplayGaussMetric, thePreview);
1772   myScalarPane->layout()->setMargin( 5 );
1773 }
1774
1775
1776 VisuGUI_ScalarBarBaseDlg::~VisuGUI_ScalarBarBaseDlg()
1777 {
1778 }
1779
1780
1781 //----------------------------------------------------------------------------
1782 void VisuGUI_ScalarBarBaseDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
1783                                                   bool theInit )
1784 {
1785   myScalarPane->initFromPrsObject( thePrs );
1786 }
1787
1788
1789 //----------------------------------------------------------------------------
1790 /*!
1791   Called when <OK> button is clicked, validates data and closes dialog
1792 */
1793 void VisuGUI_ScalarBarBaseDlg::accept()
1794 {
1795   if (GetScalarPane()->check())
1796     VisuGUI_Prs3dDlg::accept();
1797 }
1798
1799
1800 //----------------------------------------------------------------------------
1801 /*!
1802   Called when <Cancel> button is clicked, remove preview and closes dialog
1803 */
1804 void VisuGUI_ScalarBarBaseDlg::reject()
1805 {
1806   VisuGUI_Prs3dDlg::reject();
1807 }
1808
1809 //----------------------------------------------------------------------------
1810 VisuGUI_ScalarBarPane* VisuGUI_ScalarBarBaseDlg::GetScalarPane()
1811 {
1812   return myScalarPane;
1813 }
1814
1815
1816 //----------------------------------------------------------------------------