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_RayTracingDlg.h"
22 #include "OCCViewer_ViewWindow.h"
23 #include "OCCViewer_ViewPort3d.h"
24 #include "OCCViewer_ViewFrame.h"
27 #include <SUIT_Session.h>
28 #include <QtxIntSpinBox.h>
32 #include <QVBoxLayout>
34 #include <QPushButton>
38 \class OCCViewer_RayTracingDlg
39 \brief Dialog allowing to assign parameters of ray tracing
44 \param view - parent widget
46 OCCViewer_RayTracingDlg::OCCViewer_RayTracingDlg( OCCViewer_ViewWindow* view )
49 // get current view frame (OCCViewer_ViewWindow->QFrame->OCCViewer_ViewFrame)
50 myViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( view->parent()->parent() );
51 myView3d = view->getViewPort()->getView();
52 setObjectName( "OCCViewer_RayTracingDlg" );
53 setWindowTitle( tr( "RAY_TRACING" ) );
56 setAttribute( Qt::WA_DeleteOnClose, true );
58 // Create layout for this dialog
59 QVBoxLayout* dlglayout = new QVBoxLayout( this );
60 dlglayout->setSpacing( 6 );
61 dlglayout->setMargin( 11 );
63 // Create "Ray tracing" group
65 myRayTracingGroup = new QGroupBox( tr( "RAY_TRACING" ) );
66 myRayTracingGroup->setCheckable( true );
68 QGridLayout* rayTracingLayout = new QGridLayout( myRayTracingGroup );
69 rayTracingLayout->setSpacing( 6 );
70 rayTracingLayout->setMargin( 11 );
72 myShadow = new QCheckBox( tr("SHADOW") );
73 myReflection = new QCheckBox( tr("REFLECTION") );
74 myAntialiasing = new QCheckBox( tr("ANTIALIASING") );
75 myTransparentShadow = new QCheckBox( tr("TRANSPARENT_SHADOW") );
76 QLabel* depthLabel = new QLabel( tr( "DEPTH" ) );
77 myDepth = new QtxIntSpinBox( 1, 10 );
79 rayTracingLayout->addWidget( depthLabel, 0, 0 );
80 rayTracingLayout->addWidget( myDepth, 0, 1 );
81 rayTracingLayout->addWidget( myReflection, 1, 0 );
82 rayTracingLayout->addWidget( myAntialiasing, 1, 1 );
83 rayTracingLayout->addWidget( myShadow, 2, 0 );
84 rayTracingLayout->addWidget( myTransparentShadow, 2, 1 );
86 // Create "Buttons" group
88 QGroupBox* groupButtons = new QGroupBox( this );
89 QHBoxLayout* groupButtonsLayout = new QHBoxLayout( groupButtons );
90 groupButtonsLayout->setSpacing( 6 );
91 groupButtonsLayout->setMargin( 11 );
93 QPushButton* buttonClose = new QPushButton( tr( "BUT_CLOSE" ) );
94 buttonClose->setDefault( true );
96 QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) );
98 groupButtonsLayout->addStretch();
99 groupButtonsLayout->addWidget( buttonClose );
100 groupButtonsLayout->addWidget( buttonHelp );
102 dlglayout->addWidget( myRayTracingGroup );
103 dlglayout->addWidget( groupButtons );
108 // Signals and slots connections
109 connect( myRayTracingGroup, SIGNAL( toggled(bool) ), this, SLOT( onRayTracing(bool) ) );
110 connect( myShadow, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) );
111 connect( myReflection, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) );
112 connect( myAntialiasing, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) );
113 connect( myTransparentShadow, SIGNAL( toggled(bool) ), this, SLOT( onValueChanged() ) );
114 connect( myDepth, SIGNAL( valueChanged(int) ), this, SLOT( onValueChanged() ) );
115 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( close() ) ) ;
116 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( ClickOnHelp() ) );
122 OCCViewer_RayTracingDlg::~OCCViewer_RayTracingDlg()
126 QString OCCViewer_RayTracingDlg::getName()
128 // return the name of object
129 return QString( "OCCViewer_RayTracingDlg" );
133 Initialization of initial values of widgets
135 void OCCViewer_RayTracingDlg::initParam()
137 Graphic3d_RenderingParams aParams = myView3d->RenderingParams();
138 myRayTracingGroup->setChecked( aParams.Method == Graphic3d_RM_RAYTRACING );
139 myDepth->setValue( aParams.RaytracingDepth );
140 myReflection->setChecked( aParams.IsReflectionEnabled );
141 myAntialiasing->setChecked( aParams.IsAntialiasingEnabled );
142 myShadow->setChecked( aParams.IsShadowEnabled );
143 myTransparentShadow->setChecked( aParams.IsTransparentShadowEnabled );
147 SLOT: called on value of ray tracing changed
149 void OCCViewer_RayTracingDlg::onValueChanged()
151 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
152 if ( OCCViewer_ViewWindow* aViewWindow = myViewFrame->getView(i) ) {
153 Handle(V3d_View) aView = aViewWindow->getViewPort()->getView();
154 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
155 aParams.IsShadowEnabled = myShadow->isChecked();
156 aParams.IsReflectionEnabled = myReflection->isChecked();
157 aParams.IsAntialiasingEnabled = myAntialiasing->isChecked();
158 aParams.IsTransparentShadowEnabled = myTransparentShadow->isChecked();
159 aParams.RaytracingDepth = myDepth->value();
166 SLOT on "Ray tracing" group click
168 void OCCViewer_RayTracingDlg::onRayTracing( bool theIsChecked )
170 for ( int i = OCCViewer_ViewFrame::BOTTOM_RIGHT; i <= OCCViewer_ViewFrame::TOP_RIGHT; i++ ) {
171 if ( OCCViewer_ViewWindow* aViewWindow = myViewFrame->getView(i) ) {
172 Handle(V3d_View) aView = aViewWindow->getViewPort()->getView();
173 Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
174 theIsChecked ? aParams.Method = Graphic3d_RM_RAYTRACING : aParams.Method = Graphic3d_RM_RASTERIZATION;
181 SLOT on help button click: opens a help page
183 void OCCViewer_RayTracingDlg::ClickOnHelp()
185 SUIT_Application* app = SUIT_Session::session()->activeApplication();
187 app->onHelpContextModule( "GUI", "occ_3d_viewer_page.html", "ray_tracing" );