Salome HOME
9a4eab8581aec210814aa9089443235f271a19b1
[modules/gui.git] / src / OCCViewer / OCCViewer_RayTracingDlg.cxx
1 // Copyright (C) 2015-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "OCCViewer_RayTracingDlg.h"
22 #include "OCCViewer_ViewWindow.h"
23 #include "OCCViewer_ViewPort3d.h"
24 #include "OCCViewer_ViewFrame.h"
25
26 // GUI includes
27 #include <SUIT_Session.h>
28 #include <QtxIntSpinBox.h>
29
30 // QT Includes
31 #include <QGroupBox>
32 #include <QVBoxLayout>
33 #include <QLabel>
34 #include <QPushButton>
35 #include <QCheckBox>
36
37 /*!
38   \class OCCViewer_RayTracingDlg
39   \brief Dialog allowing to assign parameters of ray tracing
40 */
41
42 /*!
43   \brief Constructor
44   \param view - parent widget
45 */
46 OCCViewer_RayTracingDlg::OCCViewer_RayTracingDlg( OCCViewer_ViewWindow* view )
47   :QDialog( view )
48 {
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" ) );
54   setModal( false );
55
56   setAttribute( Qt::WA_DeleteOnClose, true );
57
58   // Create layout for this dialog
59   QVBoxLayout* dlglayout = new QVBoxLayout( this );
60   dlglayout->setSpacing( 6 );
61   dlglayout->setMargin( 11 );
62
63   // Create "Ray tracing" group
64
65   myRayTracingGroup = new QGroupBox( tr( "RAY_TRACING" ) );
66   myRayTracingGroup->setCheckable( true );
67   
68   QGridLayout* rayTracingLayout = new QGridLayout( myRayTracingGroup );
69   rayTracingLayout->setSpacing( 6 );
70   rayTracingLayout->setMargin( 11 );
71
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 );
78
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 );
85
86   // Create "Buttons" group
87
88   QGroupBox* groupButtons = new QGroupBox( this );
89   QHBoxLayout* groupButtonsLayout = new QHBoxLayout( groupButtons );
90   groupButtonsLayout->setSpacing( 6 );
91   groupButtonsLayout->setMargin( 11 );
92
93   QPushButton* buttonClose = new QPushButton( tr( "BUT_CLOSE" ) );
94   buttonClose->setDefault( true );
95
96   QPushButton* buttonHelp = new QPushButton( tr( "GEOM_BUT_HELP" ) );
97
98   groupButtonsLayout->addStretch();
99   groupButtonsLayout->addWidget( buttonClose );
100   groupButtonsLayout->addWidget( buttonHelp );
101
102   dlglayout->addWidget( myRayTracingGroup );
103   dlglayout->addWidget( groupButtons );
104
105   // Initializations
106   initParam();
107
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() ) );
117 }
118
119 /*!
120   \brief Destructor
121 */
122 OCCViewer_RayTracingDlg::~OCCViewer_RayTracingDlg()
123 {
124 }
125
126 QString OCCViewer_RayTracingDlg::getName()
127 {
128   // return the name of object
129   return QString( "OCCViewer_RayTracingDlg" );
130 }
131
132 /*!
133   Initialization of initial values of widgets
134 */
135 void OCCViewer_RayTracingDlg::initParam()
136 {
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 );
144 }
145
146 /*!
147   SLOT: called on value of ray tracing changed
148 */
149 void OCCViewer_RayTracingDlg::onValueChanged()
150 {
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();
160       aView->Redraw();
161     }
162   }
163 }
164
165 /*!
166   SLOT on "Ray tracing" group click
167 */
168 void OCCViewer_RayTracingDlg::onRayTracing( bool theIsChecked )
169 {
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;
175       aView->Redraw();
176     }
177   }
178 }
179
180 /*!
181   SLOT on help button click: opens a help page
182 */
183 void OCCViewer_RayTracingDlg::ClickOnHelp()
184 {
185   SUIT_Application* app = SUIT_Session::session()->activeApplication();
186   if ( app )
187     app->onHelpContextModule( "GUI", "occ_3d_viewer.html", "ray-tracing" );
188 }