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 : VVTK_PrimitiveBox.cxx
25 // Author : Oleg UVAROV
28 #include "VVTK_PrimitiveBox.h"
30 #include "VISU_OpenGLPointSpriteMapper.hxx"
32 #include "SUIT_ResourceMgr.h"
33 #include "SUIT_Session.h"
35 #include "QtxDblSpinBox.h"
36 #include "QtxIntSpinBox.h"
40 #include <qlineedit.h>
41 #include <qbuttongroup.h>
42 #include <qradiobutton.h>
43 #include <qpushbutton.h>
44 #include <qfiledialog.h>
50 VVTK_PrimitiveBox::VVTK_PrimitiveBox( QWidget* parent ) :
53 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
55 setTitle( tr( "PRIMITIVE_TITLE" ) );
56 setColumnLayout(0, Qt::Vertical );
57 layout()->setSpacing( 0 );
58 layout()->setMargin( 0 );
60 QGridLayout* aLayout = new QGridLayout( layout() );
61 aLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
62 aLayout->setSpacing(6);
63 aLayout->setMargin(11);
65 myPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
67 QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/";
68 myMainTexture = aRootDir + "sprite_texture.bmp";
69 myAlphaTexture = aRootDir + "sprite_alpha.bmp";
72 QButtonGroup* aPrimitiveTypeGroup = new QButtonGroup( 3, Qt::Horizontal, this, "PrimitiveTypeGroup" );
73 aPrimitiveTypeGroup->setMinimumWidth( 450 );
74 aPrimitiveTypeGroup->setRadioButtonExclusive( true );
75 aPrimitiveTypeGroup->setFrameStyle( QFrame::NoFrame );
76 aPrimitiveTypeGroup->layout()->setMargin( 0 );
78 myPointSpriteButton = new QRadioButton( tr( "POINT_SPRITE" ), aPrimitiveTypeGroup );
79 myOpenGLPointButton = new QRadioButton( tr( "OPENGL_POINT" ), aPrimitiveTypeGroup );
80 myGeomSphereButton = new QRadioButton( tr( "GEOMETRICAL_SPHERE" ), aPrimitiveTypeGroup );
82 aLayout->addMultiCellWidget( aPrimitiveTypeGroup, 0, 0, 0, 2 );
84 // Clamp ( Point Sprite & OpenGL Point )
85 myClampLabel = new QLabel( tr( "CLAMP" ), this );
86 myClampSpinBox = new QtxDblSpinBox( 1.0, 512.0, 1.0, this );
87 myClampSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89 aLayout->addWidget( myClampLabel, 1, 0 );
90 aLayout->addMultiCellWidget( myClampSpinBox, 1, 1, 1, 2 );
92 // Main Texture ( Point Sprite )
93 myMainTextureLabel = new QLabel( tr( "MAIN_TEXTURE" ), this );
94 myMainTextureLineEdit = new QLineEdit( this );
95 myMainTextureButton = new QPushButton( this );
96 myMainTextureButton->setAutoDefault( false );
97 myMainTextureButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
98 connect( myMainTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseMainTexture() ) );
100 aLayout->addWidget( myMainTextureLabel, 2, 0 );
101 aLayout->addWidget( myMainTextureLineEdit, 2, 1 );
102 aLayout->addWidget( myMainTextureButton, 2, 2 );
104 // Alpha Texture ( Point Sprite )
105 myAlphaTextureLabel = new QLabel( tr( "ALPHA_TEXTURE" ), this );
106 myAlphaTextureLineEdit = new QLineEdit( this );
107 myAlphaTextureButton = new QPushButton( this );
108 myAlphaTextureButton->setAutoDefault( false );
109 myAlphaTextureButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
110 connect( myAlphaTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseAlphaTexture() ) );
112 aLayout->addWidget( myAlphaTextureLabel, 3, 0 );
113 aLayout->addWidget( myAlphaTextureLineEdit, 3, 1 );
114 aLayout->addWidget( myAlphaTextureButton, 3, 2 );
116 // Alpha Threshold ( Point Sprite )
117 myAlphaThresholdLabel = new QLabel( tr( "ALPHA_THRESHOLD" ), this );
118 myAlphaThresholdSpinBox = new QtxDblSpinBox( 0.0, 1.0, 0.1, this );
119 myAlphaThresholdSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
121 aLayout->addWidget( myAlphaThresholdLabel, 4, 0 );
122 aLayout->addMultiCellWidget( myAlphaThresholdSpinBox, 4, 4, 1, 2 );
124 // Resolution ( Geometrical Sphere )
125 myResolutionLabel = new QLabel( tr( "RESOLUTION" ), this );
126 myResolutionSpinBox = new QtxIntSpinBox( 3, 100, 1, this );
127 myResolutionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
128 connect( myResolutionSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( onResolutionChanged( int ) ) );
130 aLayout->addWidget( myResolutionLabel, 1, 0 );
131 aLayout->addMultiCellWidget( myResolutionSpinBox, 1, 1, 1, 2 );
133 // Number of faces ( Geometrical Sphere )
134 myFaceNumberLabel = new QLabel( tr( "FACE_NUMBER" ), this );
135 myFaceNumberLineEdit = new QLineEdit( this );
136 myFaceNumberLineEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
137 myFaceNumberLineEdit->setEnabled( false );
138 //myFaceNumberLineEdit->setReadOnly( true );
140 aLayout->addWidget( myFaceNumberLabel, 2, 0 );
141 aLayout->addMultiCellWidget( myFaceNumberLineEdit, 2, 2, 1, 2 );
143 // Notification ( Geometrical Sphere )
144 myFaceLimitLabel = new QLabel( tr( "FACE_LIMIT" ), this );
145 myFaceLimitSpinBox = new QtxIntSpinBox( 10, 1000000, 10, this );
146 myFaceLimitSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
148 aLayout->addWidget( myFaceLimitLabel, 3, 0 );
149 aLayout->addMultiCellWidget( myFaceLimitSpinBox, 3, 3, 1, 2 );
151 connect( myPointSpriteButton, SIGNAL( clicked() ), this, SLOT( onTogglePointSprite() ) );
152 connect( myOpenGLPointButton, SIGNAL( clicked() ), this, SLOT( onToggleOpenGLPoint() ) );
153 connect( myGeomSphereButton, SIGNAL( clicked() ), this, SLOT( onToggleGeomSphere() ) );
156 void VVTK_PrimitiveBox::onTogglePointSprite()
158 myPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
160 myClampLabel->show();
161 myClampSpinBox->show();
163 myMainTextureLabel->show();
164 myMainTextureLineEdit->show();
165 myMainTextureButton->show();
167 myAlphaTextureLabel->show();
168 myAlphaTextureLineEdit->show();
169 myAlphaTextureButton->show();
171 myAlphaThresholdLabel->show();
172 myAlphaThresholdSpinBox->show();
174 myResolutionLabel->hide();
175 myResolutionSpinBox->hide();
177 myFaceNumberLabel->hide();
178 myFaceNumberLineEdit->hide();
180 myFaceLimitLabel->hide();
181 myFaceLimitSpinBox->hide();
184 void VVTK_PrimitiveBox::onToggleOpenGLPoint()
186 myPrimitiveType = VISU_OpenGLPointSpriteMapper::OpenGLPoint;
188 myClampLabel->show();
189 myClampSpinBox->show();
191 myMainTextureLabel->hide();
192 myMainTextureLineEdit->hide();
193 myMainTextureButton->hide();
195 myAlphaTextureLabel->hide();
196 myAlphaTextureLineEdit->hide();
197 myAlphaTextureButton->hide();
199 myAlphaThresholdLabel->hide();
200 myAlphaThresholdSpinBox->hide();
202 myResolutionLabel->hide();
203 myResolutionSpinBox->hide();
205 myFaceNumberLabel->hide();
206 myFaceNumberLineEdit->hide();
208 myFaceLimitLabel->hide();
209 myFaceLimitSpinBox->hide();
212 void VVTK_PrimitiveBox::onToggleGeomSphere()
214 myPrimitiveType = VISU_OpenGLPointSpriteMapper::GeomSphere;
216 myClampLabel->hide();
217 myClampSpinBox->hide();
219 myMainTextureLabel->hide();
220 myMainTextureLineEdit->hide();
221 myMainTextureButton->hide();
223 myAlphaTextureLabel->hide();
224 myAlphaTextureLineEdit->hide();
225 myAlphaTextureButton->hide();
227 myAlphaThresholdLabel->hide();
228 myAlphaThresholdSpinBox->hide();
230 myResolutionLabel->show();
231 myResolutionSpinBox->show();
233 myFaceNumberLabel->show();
234 myFaceNumberLineEdit->show();
236 myFaceLimitLabel->show();
237 myFaceLimitSpinBox->show();
240 void VVTK_PrimitiveBox::onResolutionChanged( int theResolution )
242 setFaceNumber( 2 * theResolution * ( theResolution - 2 ) );
245 void VVTK_PrimitiveBox::setPrimitiveType( int theType )
247 myPrimitiveType = theType;
249 switch( myPrimitiveType )
251 case VISU_OpenGLPointSpriteMapper::PointSprite :
252 myPointSpriteButton->setChecked( true );
253 onTogglePointSprite();
255 case VISU_OpenGLPointSpriteMapper::OpenGLPoint :
256 myOpenGLPointButton->setChecked( true );
257 onToggleOpenGLPoint();
259 case VISU_OpenGLPointSpriteMapper::GeomSphere :
260 myGeomSphereButton->setChecked( true );
261 onToggleGeomSphere();
267 float VVTK_PrimitiveBox::getClamp() const
269 return myClampSpinBox->value();
272 void VVTK_PrimitiveBox::setClamp( float theClamp )
274 myClampSpinBox->setValue( theClamp );
277 void VVTK_PrimitiveBox::setClampMaximum( float theClampMaximum )
279 myClampSpinBox->setMaxValue( theClampMaximum );
282 void VVTK_PrimitiveBox::setMainTexture( const QString& theMainTexture )
284 myMainTexture = theMainTexture;
285 myMainTextureLineEdit->setText( theMainTexture.section( '/', -1 ) );
288 void VVTK_PrimitiveBox::setAlphaTexture( const QString& theAlphaTexture )
290 myAlphaTexture = theAlphaTexture;
291 myAlphaTextureLineEdit->setText( theAlphaTexture.section( '/', -1 ) );
294 float VVTK_PrimitiveBox::getAlphaThreshold() const
296 return myAlphaThresholdSpinBox->value();
299 void VVTK_PrimitiveBox::setAlphaThreshold( float theAlphaThreshold )
301 myAlphaThresholdSpinBox->setValue( theAlphaThreshold );
304 int VVTK_PrimitiveBox::getResolution() const
306 return myResolutionSpinBox->value();
309 void VVTK_PrimitiveBox::setResolution( int theResolution )
311 myResolutionSpinBox->setValue( theResolution );
314 int VVTK_PrimitiveBox::getFaceNumber() const
316 int aResolution = getResolution();
317 return 2 * aResolution * ( aResolution - 2 );
318 //return myFaceNumberLineEdit->text().toInt();
321 void VVTK_PrimitiveBox::setFaceNumber( int theFaceNumber )
323 myFaceNumberLineEdit->setText( QString::number( theFaceNumber ) );
326 int VVTK_PrimitiveBox::getFaceLimit() const
328 return myFaceLimitSpinBox->value();
331 void VVTK_PrimitiveBox::setFaceLimit( int theFaceLimit )
333 myFaceLimitSpinBox->setValue( theFaceLimit );
336 void VVTK_PrimitiveBox::onBrowseMainTexture()
338 QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/";
339 QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this );
341 if( aFileName.isNull() )
344 myMainTexture = aFileName;
345 myMainTextureLineEdit->setText( aFileName.section( '/', -1 ) );
348 void VVTK_PrimitiveBox::onBrowseAlphaTexture()
350 QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/";
351 QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this );
353 if( aFileName.isNull() )
356 myAlphaTexture = aFileName;
357 myAlphaTextureLineEdit->setText( aFileName.section( '/', -1 ) );