Salome HOME
Fix for the "0051899: curves are not shown in opened study" issue.
[modules/visu.git] / src / VISUGUI / VisuGUI_ScalarBarDlg.cxx
1 // Copyright (C) 2007-2013  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_ScalarBarDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28 //
29 #include "VisuGUI_ScalarBarDlg.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_ViewTools.h"
34 #include "VisuGUI_InputPane.h"
35
36 #include "SVTK_ViewWindow.h"
37
38 #include "VISUConfig.hh"
39 #include "VISU_Convertor.hxx"
40
41 #include "VISU_ScalarMapPL.hxx"
42 #include "VISU_ScalarMap_i.hh"
43 #include "VISU_ScalarMapAct.h"
44
45 #include "VISU_Result_i.hh"
46 #include "VISU_ColoredPrs3dFactory.hh"
47
48 #include "LightApp_Application.h"
49
50 #include "SUIT_Session.h"
51 #include "SUIT_MessageBox.h"
52 #include "SUIT_ResourceMgr.h"
53
54 #include <limits.h>
55
56 #include <QLayout>
57 #include <QValidator>
58 #include <QColorDialog>
59 #include <QTabWidget>
60 #include <QPushButton>
61 #include <QGridLayout>
62 #include <QKeyEvent>
63
64 #include <vtkTextProperty.h>
65
66 using namespace std;
67
68 /*!
69   Constructor
70 */
71 VisuGUI_ScalarBarDlg::VisuGUI_ScalarBarDlg (SalomeApp_Module* theModule)
72   : VisuGUI_ScalarBarBaseDlg(theModule, true)
73 {
74   setWindowTitle(tr("DLG_PROP_TITLE"));
75   setSizeGripEnabled(TRUE);
76
77   QVBoxLayout* TopLayout = new QVBoxLayout(this);
78   TopLayout->setSpacing(6);
79   TopLayout->setMargin(11);
80
81   myTabBox = new QTabWidget(this);
82   myInputPane = new VisuGUI_InputPane(VISU::TSCALARMAP, theModule, this);
83   myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
84   myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
85
86   TopLayout->addWidget(myTabBox);
87
88   // Common buttons ===========================================================
89   QGroupBox* GroupButtons = new QGroupBox( this );
90   //GroupButtons->setColumnLayout(0, Qt::Vertical );
91   //GroupButtons->layout()->setSpacing( 0 );
92   //GroupButtons->layout()->setMargin( 0 );
93   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
94   GroupButtonsLayout->setAlignment( Qt::AlignTop );
95   GroupButtonsLayout->setSpacing( 6 );
96   GroupButtonsLayout->setMargin( 11 );
97
98   QPushButton* buttonOk = new QPushButton( tr("BUT_OK"), GroupButtons );
99   buttonOk->setAutoDefault( TRUE );
100   buttonOk->setDefault( TRUE );
101   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
102   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
103
104   QPushButton* buttonCancel = new QPushButton( tr("BUT_CANCEL") , GroupButtons );
105   buttonCancel->setAutoDefault( TRUE );
106   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
107
108   QPushButton* buttonHelp = new QPushButton( tr("BUT_HELP") , GroupButtons );
109   buttonHelp->setAutoDefault( TRUE );
110   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
111
112   TopLayout->addWidget( GroupButtons );
113
114   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
115   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
116   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
117 }
118
119 VisuGUI_ScalarBarDlg::~VisuGUI_ScalarBarDlg()
120 {}
121
122 /*!
123   Called when <Help> button is clicked, shows the corresponding help page in defined browser
124 */
125 QString VisuGUI_ScalarBarDlg::GetContextHelpFilePath()
126 {
127   return "scalar_map_page.html";
128 }
129
130 /*!
131   Initialize dialog from the presentation
132 */
133 void VisuGUI_ScalarBarDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
134                                               bool theInit )
135 {
136   if( theInit )
137     myPrsCopy = VISU::TSameAsFactory<VISU::TSCALARMAP>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
138
139   VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
140
141   if( !theInit )
142     return;
143
144   myInputPane->initFromPrsObject( myPrsCopy );
145   myTabBox->setCurrentIndex( 0 );
146 }
147
148 /*!
149   Store dialog to the presentation
150 */
151 int VisuGUI_ScalarBarDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
152 {
153   if (!myInputPane->check() || !GetScalarPane()->check())
154     return 0;
155   
156   int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
157   anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
158
159   VISU::TSameAsFactory<VISU::TSCALARMAP>().Copy(myPrsCopy, thePrs);
160
161   return anIsOk;
162 }