1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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
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"
38 #include "SalomeApp_Module.h"
40 #include "LightApp_Application.h"
42 #include "QtxDblSpinBox.h"
44 #include <qbuttongroup.h>
45 #include <qgroupbox.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qradiobutton.h>
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 ),
60 setCaption( tr( "CACHE_TITLE" ) );
62 QVBoxLayout* aTopLayout = new QVBoxLayout( this );
63 aTopLayout->setSpacing( 6 );
64 aTopLayout->setMargin( 6 );
65 aTopLayout->setAutoAdd( true );
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 =
78 (anUsedMemory + aFreeMemory, aLimitedMemory);
81 QButtonGroup* aMemoryGroup = new QButtonGroup( 2, Qt::Vertical, tr( "MEMORY_MODE" ), this );
82 aMemoryGroup->setRadioButtonExclusive( true );
84 myLimitedMemoryButton = new QRadioButton( tr( "LIMITED_MEMORY" ), aMemoryGroup );
85 myLimitedMemoryButton->setChecked( isLimitedMemory );
87 myMimimalMemoryButton = new QRadioButton( tr( "MINIMAL_MEMORY" ), aMemoryGroup );
88 myMimimalMemoryButton->setChecked( !isLimitedMemory );
90 myLimitedMemory = new QtxDblSpinBox( 1.0, aLimitedMemoryMax, 10.0, aMemoryGroup );
91 myLimitedMemory->setSuffix( " Mb" );
92 myLimitedMemory->setValue( aLimitedMemory );
93 myLimitedMemory->setEnabled( isLimitedMemory );
95 connect( myLimitedMemoryButton, SIGNAL( toggled( bool ) ), myLimitedMemory, SLOT( setEnabled( bool ) ) );
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 );
103 QGridLayout* aStateLayout = new QGridLayout( aStateGroup->layout(), 2, 2 );
104 aStateLayout->setSpacing(6);
105 aStateLayout->setMargin(6);
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 );
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 );
121 aStateLayout->addWidget( aUsedMemoryLabel, 0, 0 );
122 aStateLayout->addWidget( myUsedMemory, 0, 1 );
123 aStateLayout->addWidget( aFreeMemoryLabel, 1, 0 );
124 aStateLayout->addWidget( myFreeMemory, 1, 1 );
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 );
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 );
142 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
143 buttonCancel->setAutoDefault( TRUE );
144 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
146 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
147 buttonHelp->setAutoDefault( TRUE );
148 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
150 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
151 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
152 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
155 VisuGUI_CacheDlg::~VisuGUI_CacheDlg()
159 bool VisuGUI_CacheDlg::isLimitedMemory()
161 return myLimitedMemoryButton->isChecked();
164 double VisuGUI_CacheDlg::getLimitedMemory()
166 return myLimitedMemory->value();
169 void VisuGUI_CacheDlg::accept()
171 if( isLimitedMemory() )
173 myCache->SetMemoryMode( VISU::ColoredPrs3dCache::LIMITED );
174 myCache->SetLimitedMemory( (float)getLimitedMemory() );
177 myCache->SetMemoryMode( VISU::ColoredPrs3dCache::MINIMAL );
183 void VisuGUI_CacheDlg::onHelp()
185 QString aHelpFileName;// = "types_of_gauss_points_presentations_page.html";
186 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
188 app->onHelpContextModule(app->activeModule() ?
189 app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
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"));