1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU VISUGUI : GUI of VISU component
21 // File : VisuGUI_PrimitiveBox.cxx
22 // Author : Oleg UVAROV
25 #include "VisuGUI_PrimitiveBox.h"
26 #include "VisuGUI_Tools.h"
28 #include <VISU_OpenGLPointSpriteMapper.hxx>
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
33 #include <SalomeApp_DoubleSpinBox.h>
34 #include <SalomeApp_IntSpinBox.h>
39 #include <QButtonGroup>
40 #include <QRadioButton>
41 #include <QPushButton>
42 #include <QFileDialog>
48 VisuGUI_PrimitiveBox::VisuGUI_PrimitiveBox( QWidget* parent ) :
51 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
53 setTitle( tr( "PRIMITIVE_TITLE" ) );
54 //setColumnLayout(0, Qt::Vertical );
55 //layout()->setSpacing( 0 );
56 //layout()->setMargin( 0 );
58 QGridLayout* aLayout = new QGridLayout( this );
59 aLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
60 aLayout->setSpacing(6);
61 aLayout->setMargin(11);
63 myPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
65 QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/";
66 myMainTexture = aRootDir + "sprite_texture.bmp";
67 myAlphaTexture = aRootDir + "sprite_alpha.bmp";
70 QGroupBox* aPrimitiveTypeGroup = new QGroupBox( this );
71 aPrimitiveTypeGroup->setMinimumWidth( 450 );
72 QHBoxLayout* aPrimLayout = new QHBoxLayout( aPrimitiveTypeGroup );
73 aPrimLayout->setMargin( 0 );
75 //QButtonGroup* aPrimitiveTypeGroup = new QButtonGroup( 3, Qt::Horizontal, this, "PrimitiveTypeGroup" );
76 //aPrimitiveTypeGroup->setMinimumWidth( 450 );
77 //aPrimitiveTypeGroup->setRadioButtonExclusive( true );
78 //aPrimitiveTypeGroup->setFrameStyle( QFrame::NoFrame );
79 //aPrimitiveTypeGroup->layout()->setMargin( 0 );
81 myPointSpriteButton = new QRadioButton( tr( "POINT_SPRITE" ), aPrimitiveTypeGroup );
82 myOpenGLPointButton = new QRadioButton( tr( "OPENGL_POINT" ), aPrimitiveTypeGroup );
83 myGeomSphereButton = new QRadioButton( tr( "GEOMETRICAL_SPHERE" ), aPrimitiveTypeGroup );
85 aPrimLayout->addWidget( myPointSpriteButton );
86 aPrimLayout->addWidget( myOpenGLPointButton );
87 aPrimLayout->addWidget( myGeomSphereButton );
89 aLayout->addWidget( aPrimitiveTypeGroup, 0, 0, 1, 2 );
91 // Clamp ( Point Sprite & OpenGL Point )
92 myClampLabel = new QLabel( tr( "CLAMP" ), this );
93 myClampSpinBox = new SalomeApp_DoubleSpinBox( this );
94 VISU::initSpinBox( myClampSpinBox, 1.0, 512.0, 1.0, "parametric_precision" );
95 myClampSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
97 aLayout->addWidget( myClampLabel, 1, 0 );
98 aLayout->addWidget( myClampSpinBox, 1, 1, 1, 2 );
100 // Main Texture ( Point Sprite )
101 myMainTextureLabel = new QLabel( tr( "MAIN_TEXTURE" ), this );
102 myMainTextureLineEdit = new QLineEdit( this );
103 myMainTextureButton = new QPushButton( this );
104 myMainTextureButton->setAutoDefault( false );
105 myMainTextureButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
106 connect( myMainTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseMainTexture() ) );
108 aLayout->addWidget( myMainTextureLabel, 2, 0 );
109 aLayout->addWidget( myMainTextureLineEdit, 2, 1 );
110 aLayout->addWidget( myMainTextureButton, 2, 2 );
112 // Alpha Texture ( Point Sprite )
113 myAlphaTextureLabel = new QLabel( tr( "ALPHA_TEXTURE" ), this );
114 myAlphaTextureLineEdit = new QLineEdit( this );
115 myAlphaTextureButton = new QPushButton( this );
116 myAlphaTextureButton->setAutoDefault( false );
117 myAlphaTextureButton->setIcon( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
118 connect( myAlphaTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseAlphaTexture() ) );
120 aLayout->addWidget( myAlphaTextureLabel, 3, 0 );
121 aLayout->addWidget( myAlphaTextureLineEdit, 3, 1 );
122 aLayout->addWidget( myAlphaTextureButton, 3, 2 );
124 // Alpha Threshold ( Point Sprite )
125 myAlphaThresholdLabel = new QLabel( tr( "ALPHA_THRESHOLD" ), this );
126 myAlphaThresholdSpinBox = new SalomeApp_DoubleSpinBox( this );
127 VISU::initSpinBox( myAlphaThresholdSpinBox, 0.0, 1.0, 0.1, "parametric_precision" );
128 myAlphaThresholdSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
130 aLayout->addWidget( myAlphaThresholdLabel, 4, 0 );
131 aLayout->addWidget( myAlphaThresholdSpinBox, 4, 1, 1, 2 );
133 // Resolution ( Geometrical Sphere )
134 myResolutionLabel = new QLabel( tr( "RESOLUTION" ), this );
135 myResolutionSpinBox = new SalomeApp_IntSpinBox( this );
136 VISU::initSpinBox( myResolutionSpinBox, 3, 100, 1 );
137 myResolutionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
138 connect( myResolutionSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onResolutionChanged( int ) ) );
140 aLayout->addWidget( myResolutionLabel, 5, 0 );
141 aLayout->addWidget( myResolutionSpinBox, 5, 1, 1, 2 );
143 // Number of faces ( Geometrical Sphere )
144 myFaceNumberLabel = new QLabel( tr( "FACE_NUMBER" ), this );
145 myFaceNumberLineEdit = new QLineEdit( this );
146 myFaceNumberLineEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
147 myFaceNumberLineEdit->setEnabled( false );
148 //myFaceNumberLineEdit->setReadOnly( true );
150 aLayout->addWidget( myFaceNumberLabel, 6, 0 );
151 aLayout->addWidget( myFaceNumberLineEdit, 6, 1, 1, 2 );
153 // Notification ( Geometrical Sphere )
154 myFaceLimitLabel = new QLabel( tr( "FACE_LIMIT" ), this );
155 myFaceLimitSpinBox = new SalomeApp_IntSpinBox( this );
156 VISU::initSpinBox( myFaceLimitSpinBox, 10, 1000000, 10 );
157 myFaceLimitSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
159 aLayout->addWidget( myFaceLimitLabel, 7, 0 );
160 aLayout->addWidget( myFaceLimitSpinBox, 7, 1, 1, 2 );
162 connect( myPointSpriteButton, SIGNAL( clicked() ), this, SLOT( onTogglePointSprite() ) );
163 connect( myOpenGLPointButton, SIGNAL( clicked() ), this, SLOT( onToggleOpenGLPoint() ) );
164 connect( myGeomSphereButton, SIGNAL( clicked() ), this, SLOT( onToggleGeomSphere() ) );
167 void VisuGUI_PrimitiveBox::onTogglePointSprite()
169 myPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
171 myClampLabel->show();
172 myClampSpinBox->show();
174 myMainTextureLabel->show();
175 myMainTextureLineEdit->show();
176 myMainTextureButton->show();
178 myAlphaTextureLabel->show();
179 myAlphaTextureLineEdit->show();
180 myAlphaTextureButton->show();
182 myAlphaThresholdLabel->show();
183 myAlphaThresholdSpinBox->show();
185 myResolutionLabel->hide();
186 myResolutionSpinBox->hide();
188 myFaceNumberLabel->hide();
189 myFaceNumberLineEdit->hide();
191 myFaceLimitLabel->hide();
192 myFaceLimitSpinBox->hide();
195 void VisuGUI_PrimitiveBox::onToggleOpenGLPoint()
197 myPrimitiveType = VISU_OpenGLPointSpriteMapper::OpenGLPoint;
199 myClampLabel->show();
200 myClampSpinBox->show();
202 myMainTextureLabel->hide();
203 myMainTextureLineEdit->hide();
204 myMainTextureButton->hide();
206 myAlphaTextureLabel->hide();
207 myAlphaTextureLineEdit->hide();
208 myAlphaTextureButton->hide();
210 myAlphaThresholdLabel->hide();
211 myAlphaThresholdSpinBox->hide();
213 myResolutionLabel->hide();
214 myResolutionSpinBox->hide();
216 myFaceNumberLabel->hide();
217 myFaceNumberLineEdit->hide();
219 myFaceLimitLabel->hide();
220 myFaceLimitSpinBox->hide();
223 void VisuGUI_PrimitiveBox::onToggleGeomSphere()
225 myPrimitiveType = VISU_OpenGLPointSpriteMapper::GeomSphere;
227 myClampLabel->hide();
228 myClampSpinBox->hide();
230 myMainTextureLabel->hide();
231 myMainTextureLineEdit->hide();
232 myMainTextureButton->hide();
234 myAlphaTextureLabel->hide();
235 myAlphaTextureLineEdit->hide();
236 myAlphaTextureButton->hide();
238 myAlphaThresholdLabel->hide();
239 myAlphaThresholdSpinBox->hide();
241 myResolutionLabel->show();
242 myResolutionSpinBox->show();
244 myFaceNumberLabel->show();
245 myFaceNumberLineEdit->show();
247 myFaceLimitLabel->show();
248 myFaceLimitSpinBox->show();
251 void VisuGUI_PrimitiveBox::onResolutionChanged( int theResolution )
253 setFaceNumber( 2 * theResolution * ( theResolution - 2 ) );
256 void VisuGUI_PrimitiveBox::setPrimitiveType( int theType )
258 myPrimitiveType = theType;
260 switch( myPrimitiveType )
262 case VISU_OpenGLPointSpriteMapper::PointSprite :
263 myPointSpriteButton->setChecked( true );
264 onTogglePointSprite();
266 case VISU_OpenGLPointSpriteMapper::OpenGLPoint :
267 myOpenGLPointButton->setChecked( true );
268 onToggleOpenGLPoint();
270 case VISU_OpenGLPointSpriteMapper::GeomSphere :
271 myGeomSphereButton->setChecked( true );
272 onToggleGeomSphere();
278 float VisuGUI_PrimitiveBox::getClamp() const
280 return myClampSpinBox->value();
283 void VisuGUI_PrimitiveBox::setClamp( float theClamp )
285 myClampSpinBox->setValue( theClamp );
288 void VisuGUI_PrimitiveBox::setClampMaximum( float theClampMaximum )
290 myClampSpinBox->setMaximum( theClampMaximum );
293 void VisuGUI_PrimitiveBox::setMainTexture( const QString& theMainTexture )
295 myMainTexture = theMainTexture;
296 myMainTextureLineEdit->setText( theMainTexture.section( '/', -1 ) );
299 void VisuGUI_PrimitiveBox::setAlphaTexture( const QString& theAlphaTexture )
301 myAlphaTexture = theAlphaTexture;
302 myAlphaTextureLineEdit->setText( theAlphaTexture.section( '/', -1 ) );
305 float VisuGUI_PrimitiveBox::getAlphaThreshold() const
307 return myAlphaThresholdSpinBox->value();
310 void VisuGUI_PrimitiveBox::setAlphaThreshold( float theAlphaThreshold )
312 myAlphaThresholdSpinBox->setValue( theAlphaThreshold );
315 int VisuGUI_PrimitiveBox::getResolution() const
317 return myResolutionSpinBox->value();
320 void VisuGUI_PrimitiveBox::setResolution( int theResolution )
322 myResolutionSpinBox->setValue( theResolution );
325 int VisuGUI_PrimitiveBox::getFaceNumber() const
327 int aResolution = getResolution();
328 return 2 * aResolution * ( aResolution - 2 );
329 //return myFaceNumberLineEdit->text().toInt();
332 void VisuGUI_PrimitiveBox::setFaceNumber( int theFaceNumber )
334 myFaceNumberLineEdit->setText( QString::number( theFaceNumber ) );
337 int VisuGUI_PrimitiveBox::getFaceLimit() const
339 return myFaceLimitSpinBox->value();
342 void VisuGUI_PrimitiveBox::setFaceLimit( int theFaceLimit )
344 myFaceLimitSpinBox->setValue( theFaceLimit );
347 void VisuGUI_PrimitiveBox::onBrowseMainTexture()
349 QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/";
350 QString aFileName = QFileDialog::getOpenFileName( this,
353 "Bitmap (*.bmp *.jpg *.png)" );
355 if( aFileName.isNull() )
358 myMainTexture = aFileName;
359 myMainTextureLineEdit->setText( aFileName.section( '/', -1 ) );
362 void VisuGUI_PrimitiveBox::onBrowseAlphaTexture()
364 QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/";
365 QString aFileName = QFileDialog::getOpenFileName( this,
368 "Bitmap (*.bmp *.jpg *.png)" );
370 if( aFileName.isNull() )
373 myAlphaTexture = aFileName;
374 myAlphaTextureLineEdit->setText( aFileName.section( '/', -1 ) );