KiCad PCB EDA Suite
dialog_3D_view_option.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-2020 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 
33 {
34 public:
35  explicit DIALOG_3D_VIEW_OPTIONS( EDA_3D_VIEWER* aParent );
36 
38  {
39  return static_cast<EDA_3D_VIEWER*>( DIALOG_SHIM::GetParent() );
40  }
41 
42  void OnCheckEnableAnimation( wxCommandEvent& WXUNUSED( event ) ) override;
43  void OnLightsResetToDefaults( wxCommandEvent& event ) override;
44 
46  bool TransferDataFromWindow() override;
47 
49  bool TransferDataToWindow() override;
50 
52 
53 private:
56 };
57 
58 
59 void EDA_3D_VIEWER::Install3DViewOptionDialog( wxCommandEvent& event )
60 {
61  DIALOG_3D_VIEW_OPTIONS dlg( this );
62 
63  if( dlg.ShowModal() == wxID_OK )
64  {
65  NewDisplay( true );
66  }
67 }
68 
69 
71  DIALOG_3D_VIEW_OPTIONS_BASE( aParent ),
72  m_settings( aParent->GetAdapter() ),
73  m_canvas( aParent->GetCanvas() )
74 {
75  m_sdbSizerOK->SetDefault();
76 
77  // Now all widgets have the size fixed, call FinishDialogSettings
79 }
80 
81 
83 {
86 }
87 
88 
90 {
94 
95  const std::vector<int> default_elevation =
96  {
97  67, 67, 67, 67, -67, -67, -67, -67,
98  };
99 
100  const std::vector<int> default_azimuth =
101  {
102  45, 135, 225, 315, 45, 135, 225, 315,
103  };
104 
105  for( size_t i = 0; i < m_settings.m_RtLightSphericalCoords.size(); ++i )
106  {
107  m_settings.m_RtLightColor[i] = SFVEC3F( 0.168f );
108 
110  ( (float) default_elevation[i] + 90.0f ) / 180.0f;
111 
112  m_settings.m_RtLightSphericalCoords[i].y = (float) default_azimuth[i] / 180.0f;
113  }
114 
116 }
117 
118 
120 {
121  auto Transfer_color = [] ( const SFVEC3F& aSource, wxColourPickerCtrl *aTarget )
122  {
123  aTarget->SetColour( wxColour( aSource.r * 255, aSource.g * 255, aSource.b * 255, 255 ) );
124  };
125 
129 
130  Transfer_color( m_settings.m_RtLightColor[0], m_colourPickerLight1 );
131  Transfer_color( m_settings.m_RtLightColor[1], m_colourPickerLight2 );
132  Transfer_color( m_settings.m_RtLightColor[2], m_colourPickerLight3 );
133  Transfer_color( m_settings.m_RtLightColor[3], m_colourPickerLight4 );
134 
135  Transfer_color( m_settings.m_RtLightColor[4], m_colourPickerLight5 );
136  Transfer_color( m_settings.m_RtLightColor[5], m_colourPickerLight6 );
137  Transfer_color( m_settings.m_RtLightColor[6], m_colourPickerLight7 );
138  Transfer_color( m_settings.m_RtLightColor[7], m_colourPickerLight8 );
139 
141 
142  m_spinCtrlLightElevation1->SetValue(
143  (int)( m_settings.m_RtLightSphericalCoords[0].x * 180.0f - 90.0f ) );
144  m_spinCtrlLightElevation2->SetValue(
145  (int)( m_settings.m_RtLightSphericalCoords[1].x * 180.0f - 90.0f ) );
146  m_spinCtrlLightElevation3->SetValue(
147  (int)( m_settings.m_RtLightSphericalCoords[2].x * 180.0f - 90.0f ) );
148  m_spinCtrlLightElevation4->SetValue(
149  (int)( m_settings.m_RtLightSphericalCoords[3].x * 180.0f - 90.0f ) );
150  m_spinCtrlLightElevation5->SetValue(
151  (int)( m_settings.m_RtLightSphericalCoords[4].x * 180.0f - 90.0f ) );
152  m_spinCtrlLightElevation6->SetValue(
153  (int)( m_settings.m_RtLightSphericalCoords[5].x * 180.0f - 90.0f ) );
154  m_spinCtrlLightElevation7->SetValue(
155  (int)( m_settings.m_RtLightSphericalCoords[6].x * 180.0f - 90.0f ) );
156  m_spinCtrlLightElevation8->SetValue(
157  (int)( m_settings.m_RtLightSphericalCoords[7].x * 180.0f - 90.0f ) );
158 
159  m_spinCtrlLightAzimuth1->SetValue(
160  (int)( m_settings.m_RtLightSphericalCoords[0].y * 180.0f ) );
161  m_spinCtrlLightAzimuth2->SetValue(
162  (int)( m_settings.m_RtLightSphericalCoords[1].y * 180.0f ) );
163  m_spinCtrlLightAzimuth3->SetValue(
164  (int)( m_settings.m_RtLightSphericalCoords[2].y * 180.0f ) );
165  m_spinCtrlLightAzimuth4->SetValue(
166  (int)( m_settings.m_RtLightSphericalCoords[3].y * 180.0f ) );
167  m_spinCtrlLightAzimuth5->SetValue(
168  (int)( m_settings.m_RtLightSphericalCoords[4].y * 180.0f ) );
169  m_spinCtrlLightAzimuth6->SetValue(
170  (int)( m_settings.m_RtLightSphericalCoords[5].y * 180.0f ) );
171  m_spinCtrlLightAzimuth7->SetValue(
172  (int)( m_settings.m_RtLightSphericalCoords[6].y * 180.0f ) );
173  m_spinCtrlLightAzimuth8->SetValue(
174  (int)( m_settings.m_RtLightSphericalCoords[7].y * 180.0f ) );
175 }
176 
177 
179 {
180  // Check/uncheck checkboxes
183  m_checkBoxAreas->SetValue( m_settings.GetFlag( FL_ZONE ) );
184 
188 
194  m_checkBoxECO->SetValue( m_settings.GetFlag( FL_ECO ) );
199 
200  // OpenGL options
206  m_checkBoxDisableMoveVias->SetValue(
208  m_checkBoxDisableMoveHoles->SetValue(
210  m_choiceAntiAliasing->SetSelection( static_cast<int>( m_settings.GetAntiAliasingMode() ) );
211 
212  // Raytracing options
226 
230 
236 
239 
241 
242  // Camera Options
247 
249  m_spinCtrlRotationAngle->SetValue( ctrlTool->GetRotationIncrement() );
250 
251  return true;
252 }
253 
254 
256 {
257  // Set render mode
259 
260  // Set visibility of items
262  m_settings.SetFlag( FL_ZONE, m_checkBoxAreas->GetValue() );
267 
268  // Set 3D shapes visibility
272 
273  // Set Layer visibility
279  m_settings.SetFlag( FL_ECO, m_checkBoxECO->GetValue( ) );
280 
281  // OpenGL options
286  m_checkBoxDisableMoveThickness->GetValue() );
288  m_checkBoxDisableMoveVias->GetValue() );
290  m_checkBoxDisableMoveHoles->GetValue() );
292  static_cast<ANTIALIASING_MODE>( m_choiceAntiAliasing->GetSelection() ) );
293 
294  // Raytracing options
298  m_checkBoxRaytracing_addFloor->GetValue() );
306  m_checkBoxRaytracing_antiAliasing->GetValue() );
309 
313 
315  static_cast<float>( m_spinCtrlDouble_SpreadFactor_Shadows->GetValue() ) / 100.0f;
317  static_cast<float>( m_spinCtrlDouble_SpreadFactor_Reflections->GetValue() ) / 100.0f;
319  static_cast<float>( m_spinCtrlDouble_SpreadFactor_Refractions->GetValue() ) / 100.0f;
320 
323 
324  auto Transfer_color = [] ( SFVEC3F& aTarget, wxColourPickerCtrl *aSource )
325  {
326  const wxColour color = aSource->GetColour();
327 
328  aTarget = SFVEC3F( color.Red() / 255.0f, color.Green() / 255.0f, color.Blue() / 255.0f );
329  };
330 
334 
335  Transfer_color( m_settings.m_RtLightColor[0], m_colourPickerLight1 );
336  Transfer_color( m_settings.m_RtLightColor[1], m_colourPickerLight2 );
337  Transfer_color( m_settings.m_RtLightColor[2], m_colourPickerLight3 );
338  Transfer_color( m_settings.m_RtLightColor[3], m_colourPickerLight4 );
339  Transfer_color( m_settings.m_RtLightColor[4], m_colourPickerLight5 );
340  Transfer_color( m_settings.m_RtLightColor[5], m_colourPickerLight6 );
341  Transfer_color( m_settings.m_RtLightColor[6], m_colourPickerLight7 );
342  Transfer_color( m_settings.m_RtLightColor[7], m_colourPickerLight8 );
343 
345 
347  ( m_spinCtrlLightElevation1->GetValue() + 90.0f ) / 180.0f;
349  ( m_spinCtrlLightElevation2->GetValue() + 90.0f ) / 180.0f;
351  ( m_spinCtrlLightElevation3->GetValue() + 90.0f ) / 180.0f;
353  ( m_spinCtrlLightElevation4->GetValue() + 90.0f ) / 180.0f;
355  ( m_spinCtrlLightElevation5->GetValue() + 90.0f ) / 180.0f;
357  ( m_spinCtrlLightElevation6->GetValue() + 90.0f ) / 180.0f;
359  ( m_spinCtrlLightElevation7->GetValue() + 90.0f ) / 180.0f;
361  ( m_spinCtrlLightElevation8->GetValue() + 90.0f ) / 180.0f;
362 
363  m_settings.m_RtLightSphericalCoords[0].y = m_spinCtrlLightAzimuth1->GetValue() / 180.0f;
364  m_settings.m_RtLightSphericalCoords[1].y = m_spinCtrlLightAzimuth2->GetValue() / 180.0f;
365  m_settings.m_RtLightSphericalCoords[2].y = m_spinCtrlLightAzimuth3->GetValue() / 180.0f;
366  m_settings.m_RtLightSphericalCoords[3].y = m_spinCtrlLightAzimuth4->GetValue() / 180.0f;
367  m_settings.m_RtLightSphericalCoords[4].y = m_spinCtrlLightAzimuth5->GetValue() / 180.0f;
368  m_settings.m_RtLightSphericalCoords[5].y = m_spinCtrlLightAzimuth6->GetValue() / 180.0f;
369  m_settings.m_RtLightSphericalCoords[6].y = m_spinCtrlLightAzimuth7->GetValue() / 180.0f;
370  m_settings.m_RtLightSphericalCoords[7].y = m_spinCtrlLightAzimuth8->GetValue() / 180.0f;
371 
372  for( size_t i = 0; i < m_settings.m_RtLightSphericalCoords.size(); ++i )
373  {
375  glm::clamp( m_settings.m_RtLightSphericalCoords[i].x, 0.0f, 1.0f );
376 
378  glm::clamp( m_settings.m_RtLightSphericalCoords[i].y, 0.0f, 2.0f );
379  }
380 
381  // Camera Options
384 
386  ctrlTool->SetRotationIncrement( m_spinCtrlRotationAngle->GetValue() );
387 
388  return true;
389 }
void AnimationEnabledSet(bool aAnimationEnabled)
Enable or disable camera animation when switching to a pre-defined view.
bool GetFlag(DISPLAY3D_FLG aFlag) const
Get a configuration status of a flag.
int m_RtShadowSampleCount
void Install3DViewOptionDialog(wxCommandEvent &event)
void OnLightsResetToDefaults(wxCommandEvent &event) override
void SetAntiAliasingMode(ANTIALIASING_MODE aAAmode)
Set the current antialiasing mode value.
DIALOG_3D_VIEW_OPTIONS(EDA_3D_VIEWER *aParent)
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
Set the status of a flag.
void SetRotationIncrement(double aRotIncrement)
Set the increment used by the RotateView actions.
Definition: 3d_controller.h:67
int color
Definition: DXF_plotter.cpp:60
wxSpinCtrlDouble * m_spinCtrlDouble_SpreadFactor_Refractions
Class DIALOG_3D_VIEW_OPTIONS_BASE.
wxColourPickerCtrl * m_colourPickerSelection
std::vector< SFVEC2F > m_RtLightSphericalCoords
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:48
wxColourPickerCtrl * m_colourPickerCameraLight
float m_RtSpreadRefractions
SFVEC3F m_RtCameraLightColor
void MovingSpeedMultiplierSet(int aMovingSpeedMultiplier)
Set the camera animation moving speed multiplier option.
bool TransferDataToWindow() override
Automatically called after creating the dialog.
int m_RtRecursiveReflectionCount
float m_RtSpreadReflections
EDA_3D_CONTROLLER.
Definition: 3d_controller.h:39
SFVEC3F m_RtLightColorTop
bool AnimationEnabledGet() const
Return whether camera animation is enabled when switching to a pre-defined view.
double GetRotationIncrement()
Get the increment used by the RotateView actions.
Definition: 3d_controller.h:77
int m_RtRecursiveRefractionCount
std::vector< SFVEC3F > m_RtLightColor
int m_RtRefractionSampleCount
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int MovingSpeedMultiplierGet() const
Return the current camera animation moving speed multiplier option.
Declaration of the eda_3d_viewer class.
ANTIALIASING_MODE GetAntiAliasingMode() const
Get the current antialiasing mode value.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_OpenGlSelectionColor
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
Definition: eda_3d_viewer.h:66
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
SFVEC3F m_RtLightColorBottom
float m_RtSpreadShadows
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
wxSpinCtrlDouble * m_spinCtrlDouble_SpreadFactor_Reflections
Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:67
wxColourPickerCtrl * m_colourPickerBottomLight
int m_RtReflectionSampleCount
bool TransferDataFromWindow() override
Automatically called when clicking on the OK button.
void OnCheckEnableAnimation(wxCommandEvent &WXUNUSED(event)) override
wxSpinCtrlDouble * m_spinCtrlDouble_SpreadFactor_Shadows