]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_CacheDlg.cxx
Salome HOME
e4b5748f7a4d6cbb637b12cee1c10234185b64cc
[modules/visu.git] / src / VISUGUI / VisuGUI_CacheDlg.cxx
1 //  Copyright (C) 2007-2008  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 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_CacheDlg.cxx
24 //  Author : Oleg UVAROV
25 //  Module : VISU
26 //
27 #include "VisuGUI_CacheDlg.h"
28
29 #include "VisuGUI_Tools.h"
30
31 #include "VISU_PipeLine.hxx"
32
33 #include "SUIT_Desktop.h"
34 #include "SUIT_MessageBox.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_ResourceMgr.h"
37
38 #include "SalomeApp_Module.h"
39
40 #include "LightApp_Application.h"
41
42 #include "QtxDoubleSpinBox.h"
43
44 #include <QButtonGroup>
45 #include <QGroupBox>
46 #include <QLabel>
47 #include <QLayout>
48 #include <QLineEdit>
49 #include <QPushButton>
50 #include <QRadioButton>
51
52 using namespace std;
53
54 VisuGUI_CacheDlg::VisuGUI_CacheDlg( VISU::ColoredPrs3dCache_var theCache,
55                                     SalomeApp_Module* theModule )
56   : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
57     myCache( theCache )
58 {
59   setModal( true );
60   setWindowTitle( tr( "CACHE_TITLE" ) );
61   setAttribute( Qt::WA_DeleteOnClose );
62
63   QVBoxLayout* aTopLayout = new QVBoxLayout( this );
64   aTopLayout->setSpacing( 6 );
65   aTopLayout->setMargin( 6 );
66   //aTopLayout->setAutoAdd( true );
67
68   long aMb = 1024 * 1024;
69   bool isLimitedMemory = myCache->GetMemoryMode() == VISU::ColoredPrs3dCache::LIMITED;
70   double aLimitedMemory = myCache->GetLimitedMemory();
71   double aFreeMemory = (double)VISU_PipeLine::GetAvailableMemory( 8192 * aMb ) / (double)aMb;
72   double anUsedMemory = myCache->GetMemorySize();
73   double aLimitedMemoryMax = 
74 #ifdef WNT
75           max
76 #else
77           std::max
78 #endif
79           (anUsedMemory + aFreeMemory, aLimitedMemory);
80
81   // Settings
82   QButtonGroup* aMemoryGroup = new QButtonGroup(  this );
83   QGroupBox* aGB = new QGroupBox( tr( "MEMORY_MODE" ), this );
84   aTopLayout->addWidget( aGB );
85   QGridLayout* aGridLay = new QGridLayout( aGB );
86   //aMemoryGroup->setRadioButtonExclusive( true );
87
88   myLimitedMemoryButton = new QRadioButton( tr( "LIMITED_MEMORY" ), aGB );
89   myLimitedMemoryButton->setChecked( isLimitedMemory );
90   aGridLay->addWidget( myLimitedMemoryButton, 0, 0 );
91
92   myMimimalMemoryButton = new QRadioButton( tr( "MINIMAL_MEMORY" ), aGB );
93   myMimimalMemoryButton->setChecked( !isLimitedMemory );
94   aGridLay->addWidget( myMimimalMemoryButton, 1, 0 );
95
96   myLimitedMemory = new QtxDoubleSpinBox( 1.0, aLimitedMemoryMax, 10.0, aGB );
97   myLimitedMemory->setSuffix( " Mb" );
98   myLimitedMemory->setValue( aLimitedMemory );
99   myLimitedMemory->setEnabled( isLimitedMemory );
100   aGridLay->addWidget( myLimitedMemory, 0, 1 );
101   
102
103   connect( myLimitedMemoryButton, SIGNAL( toggled( bool ) ), myLimitedMemory, SLOT( setEnabled( bool ) ) );
104
105   // Current state
106   QGroupBox* aStateGroup = new QGroupBox( tr( "MEMORY STATE" ), this );
107   aTopLayout->addWidget( aStateGroup );
108   //aStateGroup->setColumnLayout( 0, Qt::Vertical );
109   //aStateGroup->layout()->setSpacing( 0 );
110   //aStateGroup->layout()->setMargin( 0 );
111
112   QGridLayout* aStateLayout = new QGridLayout( aStateGroup );
113   aStateLayout->setSpacing(6);
114   aStateLayout->setMargin(6);
115
116   QLabel* aUsedMemoryLabel = new QLabel( tr( "USED_BY_CACHE" ), aStateGroup );
117   myUsedMemory = new QLineEdit( aStateGroup );
118   myUsedMemory->setText( QString::number( anUsedMemory ) + " Mb" );
119   myUsedMemory->setReadOnly( true );
120   myUsedMemory->setEnabled( false );
121   QPalette aPal = myUsedMemory->palette();
122   aPal.setColor( myUsedMemory->foregroundRole(), Qt::black );
123   myUsedMemory->setPalette( aPal );
124   //myUsedMemory->setPaletteForegroundColor( Qt::black );
125
126   QLabel* aFreeMemoryLabel = new QLabel( tr( "FREE" ), aStateGroup );
127   myFreeMemory = new QLineEdit( aStateGroup );
128   myFreeMemory->setText( QString::number( aFreeMemory ) + " Mb" );
129   myFreeMemory->setReadOnly( true );
130   myFreeMemory->setEnabled( false );
131   aPal = myFreeMemory->palette();
132   aPal.setColor( myFreeMemory->foregroundRole(), Qt::black );
133   myFreeMemory->setPalette( aPal );
134   //myFreeMemory->setPaletteForegroundColor( Qt::black );
135
136   aStateLayout->addWidget( aUsedMemoryLabel, 0, 0 );
137   aStateLayout->addWidget( myUsedMemory, 0, 1 );
138   aStateLayout->addWidget( aFreeMemoryLabel, 1, 0 );
139   aStateLayout->addWidget( myFreeMemory, 1, 1 );
140
141   // Ok / Cancel
142   QGroupBox* GroupButtons = new QGroupBox( this );
143   aTopLayout->addWidget( GroupButtons );
144   //GroupButtons->setColumnLayout(0, Qt::Vertical );
145   //GroupButtons->layout()->setSpacing( 0 );
146   //GroupButtons->layout()->setMargin( 0 );
147   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
148   GroupButtonsLayout->setAlignment( Qt::AlignTop );
149   GroupButtonsLayout->setSpacing( 6 );
150   GroupButtonsLayout->setMargin( 11 );
151
152   QPushButton* buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
153   buttonOk->setAutoDefault( TRUE );
154   buttonOk->setDefault( TRUE );
155   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
156   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
157
158   QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
159   buttonCancel->setAutoDefault( TRUE );
160   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
161
162   QPushButton* buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
163   buttonHelp->setAutoDefault( TRUE );
164   GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
165
166   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
167   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
168   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
169 }
170
171 VisuGUI_CacheDlg::~VisuGUI_CacheDlg()
172 {
173 }
174
175 bool VisuGUI_CacheDlg::isLimitedMemory()
176 {
177   return myLimitedMemoryButton->isChecked();
178 }
179
180 double VisuGUI_CacheDlg::getLimitedMemory()
181 {
182   return myLimitedMemory->value();
183 }
184
185 void VisuGUI_CacheDlg::accept()
186 {
187   if( isLimitedMemory() )
188   {
189     myCache->SetMemoryMode( VISU::ColoredPrs3dCache::LIMITED );
190     myCache->SetLimitedMemory( (float)getLimitedMemory() );
191   }
192   else
193     myCache->SetMemoryMode( VISU::ColoredPrs3dCache::MINIMAL );
194
195
196   QDialog::accept();
197 }
198
199 void VisuGUI_CacheDlg::onHelp()
200 {
201   QString aHelpFileName;// = "types_of_gauss_points_presentations_page.html";
202   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
203   if (app)
204     app->onHelpContextModule(app->activeModule() ?
205                              app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
206   else {
207     SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
208                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
209                              arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
210                              tr("BUT_OK"));
211   }
212 }