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