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 private:
45 
46  void initDialog();
47 
48  void OnCheckEnableAnimation( wxCommandEvent& WXUNUSED( event ) ) override;
49  void OnLightsResetToDefaults( wxCommandEvent& event ) override;
50 
52  bool TransferDataFromWindow() override;
53 
55  bool TransferDataToWindow() override;
56 
58 };
59 
60 
61 void EDA_3D_VIEWER::Install3DViewOptionDialog( wxCommandEvent& event )
62 {
63  DIALOG_3D_VIEW_OPTIONS dlg( this );
64 
65  if( dlg.ShowModal() == wxID_OK )
66  {
67  NewDisplay( true );
68  }
69 }
70 
71 
73  DIALOG_3D_VIEW_OPTIONS_BASE( aParent ),
74  m_settings( aParent->GetAdapter() ),
75  m_canvas( aParent->GetCanvas() )
76 {
77  initDialog();
78 
79  m_sdbSizerOK->SetDefault();
80 
81  // Now all widgets have the size fixed, call FinishDialogSettings
83 }
84 
85 
87 {
89  m_bitmapBoardBody->SetBitmap( KiBitmap( ortho_xpm ) );
91  m_bitmap3DshapesTH->SetBitmap( KiBitmap( shape_3d_xpm ) );
92  m_bitmap3DshapesSMD->SetBitmap( KiBitmap( shape_3d_xpm ) );
94  m_bitmapBoundingBoxes->SetBitmap( KiBitmap( axis3d_xpm ) );
95  m_bitmapAreas->SetBitmap( KiBitmap( add_zone_xpm ) );
96  m_bitmapSilkscreen->SetBitmap( KiBitmap( text_xpm ) );
99  m_bitmapAdhesive->SetBitmap( KiBitmap( tools_xpm ) );
100  m_bitmapComments->SetBitmap( KiBitmap( editor_xpm ) );
101  m_bitmapECO->SetBitmap( KiBitmap( editor_xpm ) );
104 }
105 
107 {
108  m_staticAnimationSpeed->Enable( m_checkBoxEnableAnimation->GetValue() );
109  m_sliderAnimationSpeed->Enable( m_checkBoxEnableAnimation->GetValue() );
110 }
111 
113 {
117 
118  const std::vector<int> default_elevation =
119  {
120  67, 67, 67, 67, -67, -67, -67, -67,
121  };
122 
123  const std::vector<int> default_azimuth =
124  {
125  45, 135, 225, 315, 45, 135, 225, 315,
126  };
127 
128  for( size_t i = 0; i < m_settings.m_raytrace_lightSphericalCoords.size(); ++i )
129  {
131 
132  m_settings.m_raytrace_lightSphericalCoords[i].x = ( (float)default_elevation[i] + 90.0f ) / 180.0f;
133 
134  m_settings.m_raytrace_lightSphericalCoords[i].y = (float)default_azimuth[i] / 180.0f;
135  }
136 
138 }
139 
141 {
142  auto Transfer_color = [] ( const SFVEC3F& aSource, wxColourPickerCtrl *aTarget )
143  {
144  aTarget->SetColour( wxColour( aSource.r * 255,
145  aSource.g * 255,
146  aSource.b * 255, 255 ) );
147  };
148 
152 
157 
162 
163  m_spinCtrlLightElevation1->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[0].x * 180.0f - 90.0f ) );
164  m_spinCtrlLightElevation2->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[1].x * 180.0f - 90.0f ) );
165  m_spinCtrlLightElevation3->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[2].x * 180.0f - 90.0f ) );
166  m_spinCtrlLightElevation4->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[3].x * 180.0f - 90.0f ) );
167  m_spinCtrlLightElevation5->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[4].x * 180.0f - 90.0f ) );
168  m_spinCtrlLightElevation6->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[5].x * 180.0f - 90.0f ) );
169  m_spinCtrlLightElevation7->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[6].x * 180.0f - 90.0f ) );
170  m_spinCtrlLightElevation8->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[7].x * 180.0f - 90.0f ) );
171 
172  m_spinCtrlLightAzimuth1->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[0].y * 180.0f ) );
173  m_spinCtrlLightAzimuth2->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[1].y * 180.0f ) );
174  m_spinCtrlLightAzimuth3->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[2].y * 180.0f ) );
175  m_spinCtrlLightAzimuth4->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[3].y * 180.0f ) );
176  m_spinCtrlLightAzimuth5->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[4].y * 180.0f ) );
177  m_spinCtrlLightAzimuth6->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[5].y * 180.0f ) );
178  m_spinCtrlLightAzimuth7->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[6].y * 180.0f ) );
179  m_spinCtrlLightAzimuth8->SetValue( (int)( m_settings.m_raytrace_lightSphericalCoords[7].y * 180.0f ) );
180 }
181 
183 {
184  // Check/uncheck checkboxes
187  m_checkBoxAreas->SetValue( m_settings.GetFlag( FL_ZONE ) );
188 
192 
198  m_checkBoxECO->SetValue( m_settings.GetFlag( FL_ECO ) );
201 
202  // OpenGL options
209  m_choiceAntiAliasing->SetSelection( static_cast<int>( m_settings.AntiAliasingGet() ) );
210 
211  // Raytracing options
219 
223 
227 
230 
232 
233  // Camera Options
238 
240  m_spinCtrlRotationAngle->SetValue( ctrlTool->GetRotationIncrement() );
241 
242  return true;
243 }
244 
245 
247 {
248  // Set render mode
250 
251  // Set visibility of items
253  m_settings.SetFlag( FL_ZONE, m_checkBoxAreas->GetValue() );
256 
257  // Set 3D shapes visibility
261 
262  // Set Layer visibility
268  m_settings.SetFlag( FL_ECO, m_checkBoxECO->GetValue( ) );
269 
270  // OpenGL options
277  m_settings.AntiAliasingSet( static_cast<ANTIALIASING_MODE>( m_choiceAntiAliasing->GetSelection() ) );
278 
279  // Raytracing options
287 
291 
292  m_settings.m_raytrace_spread_shadows = static_cast<float>( m_spinCtrlDouble_SpreadFactor_Shadows->GetValue() ) / 100.0f;
293  m_settings.m_raytrace_spread_reflections = static_cast<float>( m_spinCtrlDouble_SpreadFactor_Reflections->GetValue() ) / 100.0f;
294  m_settings.m_raytrace_spread_refractions = static_cast<float>( m_spinCtrlDouble_SpreadFactor_Refractions->GetValue() ) / 100.0f;
295 
298 
299  auto Transfer_color = [] ( SFVEC3F& aTarget, wxColourPickerCtrl *aSource )
300  {
301  const wxColour color = aSource->GetColour();
302 
303  aTarget = SFVEC3F( color.Red() / 255.0f,
304  color.Green() / 255.0f,
305  color.Blue() / 255.0f );
306  };
307 
311 
320 
321  m_settings.m_raytrace_lightSphericalCoords[0].x = ( m_spinCtrlLightElevation1->GetValue() + 90.0f ) / 180.0f;
322  m_settings.m_raytrace_lightSphericalCoords[1].x = ( m_spinCtrlLightElevation2->GetValue() + 90.0f ) / 180.0f;
323  m_settings.m_raytrace_lightSphericalCoords[2].x = ( m_spinCtrlLightElevation3->GetValue() + 90.0f ) / 180.0f;
324  m_settings.m_raytrace_lightSphericalCoords[3].x = ( m_spinCtrlLightElevation4->GetValue() + 90.0f ) / 180.0f;
325  m_settings.m_raytrace_lightSphericalCoords[4].x = ( m_spinCtrlLightElevation5->GetValue() + 90.0f ) / 180.0f;
326  m_settings.m_raytrace_lightSphericalCoords[5].x = ( m_spinCtrlLightElevation6->GetValue() + 90.0f ) / 180.0f;
327  m_settings.m_raytrace_lightSphericalCoords[6].x = ( m_spinCtrlLightElevation7->GetValue() + 90.0f ) / 180.0f;
328  m_settings.m_raytrace_lightSphericalCoords[7].x = ( m_spinCtrlLightElevation8->GetValue() + 90.0f ) / 180.0f;
329 
338 
339  for( size_t i = 0; i < m_settings.m_raytrace_lightSphericalCoords.size(); ++i )
340  {
342  0.0f, 1.0f );
343 
345  0.0f, 2.0f );
346  }
347 
348  // Camera Options
351 
353  ctrlTool->SetRotationIncrement( m_spinCtrlRotationAngle->GetValue() );
354 
355  return true;
356 }
void AnimationEnabledSet(bool aAnimationEnabled)
AnimationEnabledSet - Enable or disable camera animation when switching to a pre-defined view.
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
std::vector< SFVEC3F > m_raytrace_lightColor
SFVEC3F m_raytrace_lightColorBottom
SFVEC3F m_raytrace_lightColorCamera
int m_raytrace_nrsamples_refractions
void Install3DViewOptionDialog(wxCommandEvent &event)
std::vector< SFVEC2F > m_raytrace_lightSphericalCoords
void OnLightsResetToDefaults(wxCommandEvent &event) override
const BITMAP_OPAQUE editor_xpm[1]
Definition: editor.cpp:83
float m_raytrace_spread_reflections
DIALOG_3D_VIEW_OPTIONS(EDA_3D_VIEWER *aParent)
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
SetFlag - 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:61
wxSpinCtrlDouble * m_spinCtrlDouble_SpreadFactor_Refractions
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_3D_VIEW_OPTIONS_BASE.
SFVEC3F m_raytrace_lightColorTop
const BITMAP_OPAQUE ortho_xpm[1]
Definition: ortho.cpp:55
const BITMAP_OPAQUE text_xpm[1]
Definition: text.cpp:27
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:47
wxColourPickerCtrl * m_colourPickerCameraLight
void MovingSpeedMultiplierSet(int aMovingSpeedMultiplier)
MovingSpeedMultiplierSet - Set the camera animation moving speed multiplier option.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
bool TransferDataToWindow() override
Automatically called after creating the dialog.
float m_raytrace_spread_shadows
int m_raytrace_nrsamples_shadows
void AntiAliasingSet(ANTIALIASING_MODE aAAmode)
AntiAliasingSet - set the current antialiasing mode value.
EDA_3D_CONTROLLER.
Definition: 3d_controller.h:39
bool AnimationEnabledGet() const
AnimationEnabledGet - Returns whether camera animation is enabled when switching to a pre-defined vie...
float m_raytrace_spread_refractions
double GetRotationIncrement()
Get the increment used by the RotateView actions.
Definition: 3d_controller.h:77
const BITMAP_OPAQUE shape_3d_xpm[1]
Definition: shape_3d.cpp:35
int m_raytrace_recursivelevel_reflections
const BITMAP_OPAQUE axis3d_xpm[1]
Definition: axis3d.cpp:91
const BITMAP_OPAQUE tools_xpm[1]
Definition: tools.cpp:113
const BITMAP_OPAQUE pads_mask_layers_xpm[1]
int MovingSpeedMultiplierGet() const
MovingSpeedMultiplierGet - Return the current camera animation moving speed multiplier option.
Declaration of the eda_3d_viewer class.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
const BITMAP_OPAQUE use_3D_copper_thickness_xpm[1]
ANTIALIASING_MODE AntiAliasingGet() const
GridGet - get the current antialiasing mode value.
const BITMAP_OPAQUE add_zone_xpm[1]
Definition: add_zone.cpp:74
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
Definition: eda_3d_viewer.h:65
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
int m_raytrace_recursivelevel_refractions
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
wxSpinCtrlDouble * m_spinCtrlDouble_SpreadFactor_Reflections
Class BOARD_ADAPTER Helper class to handle information needed to display 3D board.
Definition: board_adapter.h:68
wxColourPickerCtrl * m_colourPickerBottomLight
bool TransferDataFromWindow() override
Automatically called when clicking on the OK button.
void OnCheckEnableAnimation(wxCommandEvent &WXUNUSED(event)) override
wxSpinCtrlDouble * m_spinCtrlDouble_SpreadFactor_Shadows
int m_raytrace_nrsamples_reflections