1 // Copyright (C) 2007-2008 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
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_CacheDlg.cxx
24 // Author : Oleg UVAROV
27 #include "VisuGUI_CacheDlg.h"
29 #include "VisuGUI_Tools.h"
31 #include "VISU_PipeLine.hxx"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_MessageBox.h"
35 #include "SUIT_Session.h"
36 #include "SUIT_ResourceMgr.h"
38 #include "SalomeApp_Module.h"
40 #include "LightApp_Application.h"
42 #include "QtxDoubleSpinBox.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 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 );
103 connect( myLimitedMemoryButton, SIGNAL( toggled( bool ) ), myLimitedMemory, SLOT( setEnabled( bool ) ) );
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 );
112 QGridLayout* aStateLayout = new QGridLayout( aStateGroup );
113 aStateLayout->setSpacing(6);
114 aStateLayout->setMargin(6);
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 );
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 );
136 aStateLayout->addWidget( aUsedMemoryLabel, 0, 0 );
137 aStateLayout->addWidget( myUsedMemory, 0, 1 );
138 aStateLayout->addWidget( aFreeMemoryLabel, 1, 0 );
139 aStateLayout->addWidget( myFreeMemory, 1, 1 );
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 );
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 );
158 QPushButton* buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
159 buttonCancel->setAutoDefault( TRUE );
160 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
162 QPushButton* buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
163 buttonHelp->setAutoDefault( TRUE );
164 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
166 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
167 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
168 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
171 VisuGUI_CacheDlg::~VisuGUI_CacheDlg()
175 bool VisuGUI_CacheDlg::isLimitedMemory()
177 return myLimitedMemoryButton->isChecked();
180 double VisuGUI_CacheDlg::getLimitedMemory()
182 return myLimitedMemory->value();
185 void VisuGUI_CacheDlg::accept()
187 if( isLimitedMemory() )
189 myCache->SetMemoryMode( VISU::ColoredPrs3dCache::LIMITED );
190 myCache->SetLimitedMemory( (float)getLimitedMemory() );
193 myCache->SetMemoryMode( VISU::ColoredPrs3dCache::MINIMAL );
199 void VisuGUI_CacheDlg::onHelp()
201 QString aHelpFileName;// = "types_of_gauss_points_presentations_page.html";
202 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
204 app->onHelpContextModule(app->activeModule() ?
205 app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
207 SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
208 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
209 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),