1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_CacheDlg.cxx
25 // Author : Oleg UVAROV
28 #include "VisuGUI_CacheDlg.h"
30 #include "VisuGUI_Tools.h"
32 #include "VISU_PipeLine.hxx"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_MessageBox.h"
36 #include "SUIT_Session.h"
37 #include "SUIT_ResourceMgr.h"
39 #include "SalomeApp_Module.h"
40 #include <SalomeApp_DoubleSpinBox.h>
42 #include "LightApp_Application.h"
44 #include <QButtonGroup>
49 #include <QPushButton>
50 #include <QRadioButton>
54 VisuGUI_CacheDlg::VisuGUI_CacheDlg( VISU::ColoredPrs3dCache_var theCache,
55 SalomeApp_Module* theModule )
56 : QDialog( VISU::GetDesktop( theModule ), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
60 setWindowTitle( tr( "CACHE_TITLE" ) );
61 setAttribute( Qt::WA_DeleteOnClose );
63 QVBoxLayout* aTopLayout = new QVBoxLayout( this );
64 aTopLayout->setSpacing( 6 );
65 aTopLayout->setMargin( 6 );
66 //aTopLayout->setAutoAdd( true );
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 =
79 (anUsedMemory + aFreeMemory, aLimitedMemory);
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 );
88 myLimitedMemoryButton = new QRadioButton( tr( "LIMITED_MEMORY" ), aGB );
89 myLimitedMemoryButton->setChecked( isLimitedMemory );
90 aGridLay->addWidget( myLimitedMemoryButton, 0, 0 );
92 myMimimalMemoryButton = new QRadioButton( tr( "MINIMAL_MEMORY" ), aGB );
93 myMimimalMemoryButton->setChecked( !isLimitedMemory );
94 aGridLay->addWidget( myMimimalMemoryButton, 1, 0 );
96 myLimitedMemory = new SalomeApp_DoubleSpinBox( aGB );
97 VISU::initSpinBox( myLimitedMemory, 1.0, aLimitedMemoryMax, 10.0, "memory_precision" );
98 myLimitedMemory->setSuffix( " Mb" );
99 myLimitedMemory->setValue( aLimitedMemory );
100 myLimitedMemory->setEnabled( isLimitedMemory );
101 aGridLay->addWidget( myLimitedMemory, 0, 1 );
104 connect( myLimitedMemoryButton, SIGNAL( toggled( bool ) ), myLimitedMemory, SLOT( setEnabled( bool ) ) );
107 QGroupBox* aStateGroup = new QGroupBox( tr( "MEMORY STATE" ), this );
108 aTopLayout->addWidget( aStateGroup );
109 //aStateGroup->setColumnLayout( 0, Qt::Vertical );
110 //aStateGroup->layout()->setSpacing( 0 );
111 //aStateGroup->layout()->setMargin( 0 );
113 QGridLayout* aStateLayout = new QGridLayout( aStateGroup );
114 aStateLayout->setSpacing(6);
115 aStateLayout->setMargin(6);
117 QLabel* aUsedMemoryLabel = new QLabel( tr( "USED_BY_CACHE" ), aStateGroup );
118 myUsedMemory = new QLineEdit( aStateGroup );
119 myUsedMemory->setText( QString::number( anUsedMemory ) + " Mb" );
120 myUsedMemory->setReadOnly( true );
121 myUsedMemory->setEnabled( false );
122 QPalette aPal = myUsedMemory->palette();
123 aPal.setColor( myUsedMemory->foregroundRole(), Qt::black );
124 myUsedMemory->setPalette( aPal );
125 //myUsedMemory->setPaletteForegroundColor( Qt::black );
127 QLabel* aFreeMemoryLabel = new QLabel( tr( "FREE" ), aStateGroup );
128 myFreeMemory = new QLineEdit( aStateGroup );
129 myFreeMemory->setText( QString::number( aFreeMemory ) + " Mb" );
130 myFreeMemory->setReadOnly( true );
131 myFreeMemory->setEnabled( false );
132 aPal = myFreeMemory->palette();
133 aPal.setColor( myFreeMemory->foregroundRole(), Qt::black );
134 myFreeMemory->setPalette( aPal );
135 //myFreeMemory->setPaletteForegroundColor( Qt::black );
137 aStateLayout->addWidget( aUsedMemoryLabel, 0, 0 );
138 aStateLayout->addWidget( myUsedMemory, 0, 1 );
139 aStateLayout->addWidget( aFreeMemoryLabel, 1, 0 );
140 aStateLayout->addWidget( myFreeMemory, 1, 1 );
143 QGroupBox* GroupButtons = new QGroupBox( this );
144 aTopLayout->addWidget( GroupButtons );
145 //GroupButtons->setColumnLayout(0, Qt::Vertical );
146 //GroupButtons->layout()->setSpacing( 0 );
147 //GroupButtons->layout()->setMargin( 0 );
148 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
149 GroupButtonsLayout->setAlignment( Qt::AlignTop );
150 GroupButtonsLayout->setSpacing( 6 );
151 GroupButtonsLayout->setMargin( 11 );
153 QPushButton* buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
154 buttonOk->setAutoDefault( TRUE );
155 buttonOk->setDefault( TRUE );
156 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
157 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
159 QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
160 buttonCancel->setAutoDefault( TRUE );
161 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
163 QPushButton* buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
164 buttonHelp->setAutoDefault( TRUE );
165 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
167 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
168 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
169 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
172 VisuGUI_CacheDlg::~VisuGUI_CacheDlg()
176 bool VisuGUI_CacheDlg::isLimitedMemory()
178 return myLimitedMemoryButton->isChecked();
181 double VisuGUI_CacheDlg::getLimitedMemory()
183 return myLimitedMemory->value();
186 void VisuGUI_CacheDlg::accept()
188 if( isLimitedMemory() )
190 myCache->SetMemoryMode( VISU::ColoredPrs3dCache::LIMITED );
191 myCache->SetLimitedMemory( (float)getLimitedMemory() );
194 myCache->SetMemoryMode( VISU::ColoredPrs3dCache::MINIMAL );
200 void VisuGUI_CacheDlg::onHelp()
202 QString aHelpFileName;// = "types_of_gauss_points_presentations_page.html";
203 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
205 app->onHelpContextModule(app->activeModule() ?
206 app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
208 SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
209 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
210 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),