KiCad PCB EDA Suite
panel_3D_raytracing_options.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <bitmaps.h>
30 #include <tool/tool_manager.h>
31 
32 
34  wxWindow* aParent ) :
36  m_settings( aFrame->GetAdapter() ),
37  m_canvas( aFrame->GetCanvas() )
38 {
39 }
40 
41 
43 {
47 
48  const std::vector<int> default_elevation =
49  {
50  67, 67, 67, 67, -67, -67, -67, -67,
51  };
52 
53  const std::vector<int> default_azimuth =
54  {
55  45, 135, 225, 315, 45, 135, 225, 315,
56  };
57 
58  for( size_t i = 0; i < m_settings.m_RtLightSphericalCoords.size(); ++i )
59  {
60  m_settings.m_RtLightColor[i] = SFVEC3F( 0.168f );
61 
63  ( (float) default_elevation[i] + 90.0f ) / 180.0f;
64 
65  m_settings.m_RtLightSphericalCoords[i].y = (float) default_azimuth[i] / 180.0f;
66  }
67 
69 }
70 
71 
73 {
74  auto transfer_color = [] ( const SFVEC3F& aSource, COLOR_SWATCH *aTarget )
75  {
76  aTarget->SetSupportsOpacity( false );
77  aTarget->SetDefaultColor( KIGFX::COLOR4D( 0.5, 0.5, 0.5, 1.0 ) );
78  aTarget->SetSwatchColor( COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 ), false );
79  };
80 
84 
85  transfer_color( m_settings.m_RtLightColor[0], m_colourPickerLight1 );
86  transfer_color( m_settings.m_RtLightColor[1], m_colourPickerLight2 );
87  transfer_color( m_settings.m_RtLightColor[2], m_colourPickerLight3 );
88  transfer_color( m_settings.m_RtLightColor[3], m_colourPickerLight4 );
89 
90  transfer_color( m_settings.m_RtLightColor[4], m_colourPickerLight5 );
91  transfer_color( m_settings.m_RtLightColor[5], m_colourPickerLight6 );
92  transfer_color( m_settings.m_RtLightColor[6], m_colourPickerLight7 );
93  transfer_color( m_settings.m_RtLightColor[7], m_colourPickerLight8 );
94 
95  m_spinCtrlLightElevation1->SetValue(
96  (int)( m_settings.m_RtLightSphericalCoords[0].x * 180.0f - 90.0f ) );
97  m_spinCtrlLightElevation2->SetValue(
98  (int)( m_settings.m_RtLightSphericalCoords[1].x * 180.0f - 90.0f ) );
99  m_spinCtrlLightElevation3->SetValue(
100  (int)( m_settings.m_RtLightSphericalCoords[2].x * 180.0f - 90.0f ) );
101  m_spinCtrlLightElevation4->SetValue(
102  (int)( m_settings.m_RtLightSphericalCoords[3].x * 180.0f - 90.0f ) );
103  m_spinCtrlLightElevation5->SetValue(
104  (int)( m_settings.m_RtLightSphericalCoords[4].x * 180.0f - 90.0f ) );
105  m_spinCtrlLightElevation6->SetValue(
106  (int)( m_settings.m_RtLightSphericalCoords[5].x * 180.0f - 90.0f ) );
107  m_spinCtrlLightElevation7->SetValue(
108  (int)( m_settings.m_RtLightSphericalCoords[6].x * 180.0f - 90.0f ) );
109  m_spinCtrlLightElevation8->SetValue(
110  (int)( m_settings.m_RtLightSphericalCoords[7].x * 180.0f - 90.0f ) );
111 
112  m_spinCtrlLightAzimuth1->SetValue(
113  (int)( m_settings.m_RtLightSphericalCoords[0].y * 180.0f ) );
114  m_spinCtrlLightAzimuth2->SetValue(
115  (int)( m_settings.m_RtLightSphericalCoords[1].y * 180.0f ) );
116  m_spinCtrlLightAzimuth3->SetValue(
117  (int)( m_settings.m_RtLightSphericalCoords[2].y * 180.0f ) );
118  m_spinCtrlLightAzimuth4->SetValue(
119  (int)( m_settings.m_RtLightSphericalCoords[3].y * 180.0f ) );
120  m_spinCtrlLightAzimuth5->SetValue(
121  (int)( m_settings.m_RtLightSphericalCoords[4].y * 180.0f ) );
122  m_spinCtrlLightAzimuth6->SetValue(
123  (int)( m_settings.m_RtLightSphericalCoords[5].y * 180.0f ) );
124  m_spinCtrlLightAzimuth7->SetValue(
125  (int)( m_settings.m_RtLightSphericalCoords[6].y * 180.0f ) );
126  m_spinCtrlLightAzimuth8->SetValue(
127  (int)( m_settings.m_RtLightSphericalCoords[7].y * 180.0f ) );
128 }
129 
130 
132 {
146 
150 
156 
159 
161 
162  return true;
163 }
164 
165 
167 {
171  m_checkBoxRaytracing_addFloor->GetValue() );
179  m_checkBoxRaytracing_antiAliasing->GetValue() );
182 
186 
188  static_cast<float>( m_spinCtrlDouble_SpreadFactor_Shadows->GetValue() ) / 100.0f;
190  static_cast<float>( m_spinCtrlDouble_SpreadFactor_Reflections->GetValue() ) / 100.0f;
192  static_cast<float>( m_spinCtrlDouble_SpreadFactor_Refractions->GetValue() ) / 100.0f;
193 
196 
197  auto transfer_color = [] ( SFVEC3F& aTarget, COLOR_SWATCH *aSource )
198  {
199  const COLOR4D color = aSource->GetSwatchColor();
200 
201  aTarget = SFVEC3F( color.r, color.g, color.b );
202  };
203 
207 
208  transfer_color( m_settings.m_RtLightColor[0], m_colourPickerLight1 );
209  transfer_color( m_settings.m_RtLightColor[1], m_colourPickerLight2 );
210  transfer_color( m_settings.m_RtLightColor[2], m_colourPickerLight3 );
211  transfer_color( m_settings.m_RtLightColor[3], m_colourPickerLight4 );
212  transfer_color( m_settings.m_RtLightColor[4], m_colourPickerLight5 );
213  transfer_color( m_settings.m_RtLightColor[5], m_colourPickerLight6 );
214  transfer_color( m_settings.m_RtLightColor[6], m_colourPickerLight7 );
215  transfer_color( m_settings.m_RtLightColor[7], m_colourPickerLight8 );
216 
218  ( m_spinCtrlLightElevation1->GetValue() + 90.0f ) / 180.0f;
220  ( m_spinCtrlLightElevation2->GetValue() + 90.0f ) / 180.0f;
222  ( m_spinCtrlLightElevation3->GetValue() + 90.0f ) / 180.0f;
224  ( m_spinCtrlLightElevation4->GetValue() + 90.0f ) / 180.0f;
226  ( m_spinCtrlLightElevation5->GetValue() + 90.0f ) / 180.0f;
228  ( m_spinCtrlLightElevation6->GetValue() + 90.0f ) / 180.0f;
230  ( m_spinCtrlLightElevation7->GetValue() + 90.0f ) / 180.0f;
232  ( m_spinCtrlLightElevation8->GetValue() + 90.0f ) / 180.0f;
233 
234  m_settings.m_RtLightSphericalCoords[0].y = m_spinCtrlLightAzimuth1->GetValue() / 180.0f;
235  m_settings.m_RtLightSphericalCoords[1].y = m_spinCtrlLightAzimuth2->GetValue() / 180.0f;
236  m_settings.m_RtLightSphericalCoords[2].y = m_spinCtrlLightAzimuth3->GetValue() / 180.0f;
237  m_settings.m_RtLightSphericalCoords[3].y = m_spinCtrlLightAzimuth4->GetValue() / 180.0f;
238  m_settings.m_RtLightSphericalCoords[4].y = m_spinCtrlLightAzimuth5->GetValue() / 180.0f;
239  m_settings.m_RtLightSphericalCoords[5].y = m_spinCtrlLightAzimuth6->GetValue() / 180.0f;
240  m_settings.m_RtLightSphericalCoords[6].y = m_spinCtrlLightAzimuth7->GetValue() / 180.0f;
241  m_settings.m_RtLightSphericalCoords[7].y = m_spinCtrlLightAzimuth8->GetValue() / 180.0f;
242 
243  for( size_t i = 0; i < m_settings.m_RtLightSphericalCoords.size(); ++i )
244  {
246  glm::clamp( m_settings.m_RtLightSphericalCoords[i].x, 0.0f, 1.0f );
247 
249  glm::clamp( m_settings.m_RtLightSphericalCoords[i].y, 0.0f, 2.0f );
250  }
251 
252  return true;
253 }
bool GetFlag(DISPLAY3D_FLG aFlag) const
Get a configuration status of a flag.
int m_RtShadowSampleCount
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
Set the status of a flag.
int color
Definition: DXF_plotter.cpp:57
std::vector< SFVEC2F > m_RtLightSphericalCoords
void ResetPanel() override
Reset the contents of this panel.
float m_RtSpreadRefractions
SFVEC3F m_RtCameraLightColor
int m_RtRecursiveReflectionCount
float m_RtSpreadReflections
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
Class PANEL_3D_RAYTRACING_OPTIONS_BASE.
bool TransferDataFromWindow() override
Automatically called when clicking on the OK button.
SFVEC3F m_RtLightColorTop
int m_RtRecursiveRefractionCount
std::vector< SFVEC3F > m_RtLightColor
int m_RtRefractionSampleCount
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
bool TransferDataToWindow() override
Automatically called after creating the dialog.
A simple color swatch of the kind used to set layer colors.
Definition: color_swatch.h:56
SFVEC3F m_RtLightColorBottom
float m_RtSpreadShadows
int m_RtReflectionSampleCount
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
PANEL_3D_RAYTRACING_OPTIONS(EDA_3D_VIEWER_FRAME *aFrame, wxWindow *aParent)