1 // Copyright (C) 2015-2016 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, or (at your option) any later version.
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
21 #include "OCCViewer_EnvTextureDlg.h"
22 #include "OCCViewer_ViewWindow.h"
23 #include "OCCViewer_ViewPort3d.h"
24 #include "OCCViewer_ViewFrame.h"
27 #include <SUIT_Session.h>
30 #include <Graphic3d_TextureEnv.hxx>
34 #include <QVBoxLayout>
35 #include <QPushButton>
37 #include <QFileDialog>
41 \class OCCViewer_EnvTextureDlg
42 \brief Dialog allowing to assign parameters of environment texture
47 \param view - parent widget
49 OCCViewer_EnvTextureDlg::OCCViewer_EnvTextureDlg( OCCViewer_ViewWindow* view )
53 // get current view frame (OCCViewer_ViewWindow->QFrame->OCCViewer_ViewFrame)
54 myViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( view->parent()->parent() );
55 myView3d = view->getViewPort()->getView();
57 setObjectName( "OCCViewer_EnvTextureDlg" );
58 setWindowTitle( tr( "ENV_TEXTURE" ) );
61 setAttribute( Qt::WA_DeleteOnClose, true );
63 // Create layout for this dialog
64 QVBoxLayout* dlglayout = new QVBoxLayout( this );
65 dlglayout->setSpacing( 6 );
66 dlglayout->setMargin( 11 );
68 // Create "Environment texture" group
70 myEnvTextureGroup = new QGroupBox( tr( "ENV_TEXTURE" ) );
71 myEnvTextureGroup->setCheckable( true );
73 QGridLayout* envTextureLayout = new QGridLayout( myEnvTextureGroup );
74 envTextureLayout->setSpacing( 6 );
75 envTextureLayout->setMargin( 11 );
77 myEnvTextureId = new QComboBox();
78 myEnvTextureId->addItem( tr( "ENV_CLOUDS" ) );
79 myEnvTextureId->addItem( tr( "ENV_CV" ) );
80 myEnvTextureId->addItem( tr( "ENV_MEDIT" ) );
81 myEnvTextureId->addItem( tr( "ENV_PEARL" ) );
82 myEnvTextureId->addItem( tr( "ENV_SKY1" ) );
83 myEnvTextureId->addItem( tr( "ENV_SKY2" ) );
84 myEnvTextureId->addItem( tr( "ENV_LINES" ) );
85 myEnvTextureId->addItem( tr( "ENV_ROAD" ) );
86 myEnvTextureId->addItem( tr( "ENV_CUSTOM" ) );
87 myEnvTextureId->setMinimumWidth( 300 );
89 myEnvTextureName = new QLineEdit();
90 myEnvTextureName->setVisible( false );
91 myFileButton = new QPushButton();
92 myFileButton->setText("...");
93 myFileButton->setVisible( false );
95 envTextureLayout->addWidget( myEnvTextureId, 0, 0, 1, 2 );
96 envTextureLayout->addWidget( myEnvTextureName, 1, 0 );
97 envTextureLayout->addWidget( myFileButton, 1, 1 );
99 // Create "Buttons" group
101 QGroupBox* groupButtons = new QGroupBox( this );
102 QHBoxLayout* groupButtonsLayout = new QHBoxLayout( groupButtons );
103 groupButtonsLayout->setSpacing( 6 );
104 groupButtonsLayout->setMargin( 11 );
106 QPushButton* buttonClose = new QPushButton( tr( "BUT_CLOSE" ) );
107 buttonClose->setDefault( true );
109 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) );
111 groupButtonsLayout->addStretch();
112 groupButtonsLayout->addWidget( buttonClose );
113 groupButtonsLayout->addWidget( buttonHelp );
115 dlglayout->addWidget( myEnvTextureGroup );
116 dlglayout->addWidget( groupButtons );
121 // Signals and slots connections
122 connect( myEnvTextureGroup, SIGNAL( toggled(bool) ), this, SLOT( onEnvTexture(bool) ) );
123 connect( myEnvTextureId, SIGNAL( currentIndexChanged(int) ), this, SLOT( onTextureChanged() ) );
124 connect( myFileButton, SIGNAL( clicked() ), this, SLOT( onFileSelectionClicked() ) );
125 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( close() ) );
126 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
132 OCCViewer_EnvTextureDlg::~OCCViewer_EnvTextureDlg()
136 QString OCCViewer_EnvTextureDlg::getName()
138 // return the name of object
139 return QString( "OCCViewer_EnvTextureDlg" );
143 Initialization of initial values of widgets
145 void OCCViewer_EnvTextureDlg::initParam()
147 Handle(Graphic3d_TextureEnv) aTexture = myView3d->TextureEnv();
148 bool anIsTexture = !aTexture.IsNull();
149 myEnvTextureGroup->setChecked( anIsTexture );
151 int aTextureId = myView3d->TextureEnv()->Name();
152 myEnvTextureId->setCurrentIndex( aTextureId );
153 if ( aTextureId == myEnvTextureId->count() - 1 ) {
154 TCollection_AsciiString aFileName;
155 aTexture->Path().SystemName( aFileName );
156 myEnvTextureName->setText( QString( aFileName.ToCString() ) );
157 myFileButton->setVisible( true );
158 myEnvTextureName->setVisible( true );
164 SLOT on "Environment texture" group click
166 void OCCViewer_EnvTextureDlg::onEnvTexture( bool theIsChecked )
171 Handle(Graphic3d_TextureEnv) aTexture;
172 #if OCC_VERSION_LARGE > 0x07000000
173 setEnvTexture( aTexture );
175 setEnvTexture( aTexture, V3d_TEX_ALL );
181 SLOT on when user changed the texture
183 void OCCViewer_EnvTextureDlg::onTextureChanged()
185 Handle(Graphic3d_TextureEnv) aTexture;
186 bool isCustom = myEnvTextureId->currentIndex() == myEnvTextureId->count()-1;
187 myEnvTextureName->setVisible( isCustom );
188 myFileButton->setVisible( isCustom );
190 if( myEnvTextureName->text().isEmpty() )
191 onFileSelectionClicked();
192 aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( myEnvTextureName->text().toStdString().c_str() ) );
195 myEnvTextureName->setText("");
196 Graphic3d_NameOfTextureEnv aStandardTexture;
197 QList<Graphic3d_NameOfTextureEnv> aTextures;
198 aTextures << Graphic3d_NOT_ENV_CLOUDS << Graphic3d_NOT_ENV_CV << Graphic3d_NOT_ENV_MEDIT
199 << Graphic3d_NOT_ENV_PEARL << Graphic3d_NOT_ENV_SKY1 << Graphic3d_NOT_ENV_SKY2
200 << Graphic3d_NOT_ENV_LINES << Graphic3d_NOT_ENV_ROAD;
201 aTexture = new Graphic3d_TextureEnv( aTextures.at( myEnvTextureId->currentIndex() ) );
203 #if OCC_VERSION_LARGE > 0x07000000
204 setEnvTexture( aTexture );
206 setEnvTexture( aTexture, V3d_TEX_ENVIRONMENT );
211 SLOT on file selection button click
213 void OCCViewer_EnvTextureDlg::onFileSelectionClicked()
215 QString selFile = QFileDialog::getOpenFileName( this,tr( "GEOM_SELECT_IMAGE" ),QString(), tr( "OCC_TEXTURE_FILES" ) );
216 if ( !selFile.isEmpty() ) {
217 myEnvTextureName->setText( selFile );
223 SLOT on help button click: opens a help page
225 void OCCViewer_EnvTextureDlg::ClickOnHelp()
227 SUIT_Application* app = SUIT_Session::session()->activeApplication();
229 app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "env_texture" );
233 Sets current texture environment for all view in the viewer
235 #if OCC_VERSION_LARGE > 0x07000000
236 void OCCViewer_EnvTextureDlg::setEnvTexture( Handle(Graphic3d_TextureEnv) theTexture)
238 void OCCViewer_EnvTextureDlg::setEnvTexture( Handle(Graphic3d_TextureEnv) theTexture, V3d_TypeOfSurfaceDetail theMode )
241 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
242 if ( OCCViewer_ViewWindow* aViewWindow = myViewFrame->getView(i) ) {
243 Handle(V3d_View) aView = aViewWindow->getViewPort()->getView();
244 aView->SetTextureEnv( theTexture );
245 #if OCC_VERSION_LARGE <= 0x07000000
246 aView->SetSurfaceDetail( theMode );