41#include <wx/bmpbuttn.h>
43#include <wx/textdlg.h>
45#include <../3d_rendering/opengl/render_3d_opengl.h>
48#define RR APPEARANCE_CONTROLS_3D::APPEARANCE_SETTING_3D
87 wxWindow* aFocusOwner ) :
90 m_focusOwner( aFocusOwner ),
91 m_lastSelectedViewport( nullptr )
96 int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
97 m_pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
115 m_cbLayerPresets->SetToolTip( wxString::Format(
_(
"Save and restore color and visibility "
117 "Use %s+Tab to activate selector.\n"
118 "Successive Tabs while holding %s down will "
119 "cycle through presets in the popup." ),
123 m_cbViewports->SetToolTip( wxString::Format(
_(
"Save and restore camera position and zoom.\n"
124 "Use %s+Tab to activate selector.\n"
125 "Successive Tabs while holding %s down will "
126 "cycle through viewports in the popup." ),
130 if( screenHeight <= 900 && m_pointSize >= indicatorSize )
136 KiBitmap( BITMAPS::visibility_off ) );
158 if( wxBitmapButton* btn =
dynamic_cast<wxBitmapButton*
>( aEvent.GetEventObject() ) )
160 wxCommandEvent evt( wxEVT_BUTTON );
161 wxPostEvent( btn, evt );
203 if( child && child->GetWindow() )
229 if(
m_presetMRU.Index( aPresetName ) != wxNOT_FOUND )
240 std::vector<VIEWPORT3D> ret;
243 ret.emplace_back( viewport );
253 for(
const VIEWPORT3D& viewport : aViewportList )
300 bool killFollow =
false;
301 bool doFastRefresh =
false;
326 visibleLayers.set( aLayer, isVisible );
343 visibleLayers.set( aLayer, isVisible );
352 doFastRefresh =
true;
353 visibleLayers.set( aLayer, isVisible );
357 visibleLayers.set( aLayer, isVisible );
393 int layer = aSwatch->GetId();
396 colors[ layer ] = newColor;
413 int swatchWidth =
m_windowLayers->ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
426 [&](
const std::unique_ptr<APPEARANCE_SETTING_3D>& aSetting )
428 wxBoxSizer* sizer =
new wxBoxSizer( wxHORIZONTAL );
429 int layer = aSetting->m_Id;
431 aSetting->m_Visible = visibleLayers.test( layer );
433 if( colors.count( layer ) )
436 COLOR4D::WHITE, defaultColors[ layer ],
438 swatch->SetToolTip(
_(
"Left double click or middle click to change color" ) );
440 sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 );
441 aSetting->m_Ctl_color = swatch;
443 swatch->Bind( COLOR_SWATCH_CHANGED,
444 [
this]( wxCommandEvent& event )
446 auto swatch =
static_cast<COLOR_SWATCH*
>(
event.GetEventObject() );
454 sizer->AddSpacer( swatchWidth );
457 sizer->AddSpacer( 5 );
459 wxStaticText* label =
new wxStaticText(
m_windowLayers, layer, aSetting->GetLabel() );
461 label->SetToolTip( aSetting->GetTooltip() );
465 sizer->AddSpacer( swatchWidth );
471 KiBitmap( BITMAPS::visibility_off ),
472 aSetting->m_Visible );
474 btn_visible->Bind( TOGGLE_CHANGED,
475 [
this]( wxCommandEvent& aEvent )
477 int id =
static_cast<wxWindow*
>( aEvent.GetEventObject() )->GetId();
478 bool isVisible = aEvent.GetInt();
485 tip.Printf(
_(
"Show or hide %s" ), aSetting->GetLabel().Lower() );
486 btn_visible->SetToolTip( tip );
488 aSetting->m_Ctl_visibility = btn_visible;
489 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
492 sizer->AddSpacer( 5 );
493 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL, 0 );
501 m_layerSettings.emplace_back( std::make_unique<APPEARANCE_SETTING_3D>( s_setting ) );
502 std::unique_ptr<APPEARANCE_SETTING_3D>& setting =
m_layerSettings.back();
504 if( setting->m_Spacer )
507 appendLayer( setting );
521 for( std::unique_ptr<APPEARANCE_SETTING_3D>& setting :
m_layerSettings )
523 if( setting->m_Spacer )
526 if( setting->m_Ctl_visibility )
527 setting->m_Ctl_visibility->SetValue( visibleLayers.test( setting->m_Id ) );
529 if( setting->m_Ctl_color )
530 setting->m_Ctl_color->SetSwatchColor( colors[ setting->m_Id ],
false );
566 auto it = std::find_if( presets.begin(), presets.end(),
569 for( int layer = LAYER_3D_BOARD; layer < LAYER_3D_END; ++layer )
571 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
575 for(
int layer : { LAYER_FP_REFERENCES, LAYER_FP_VALUES, LAYER_FP_TEXT } )
577 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
583 if( aPreset.colors.at( layer ) != colors.at( layer ) )
590 if( it != presets.end() )
592 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = it->name;
593 m_cbLayerPresets->SetStringSelection( it->name );
597 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 );
620 auto resetSelection =
633 else if( index == 1 )
640 else if( index == count - 3 )
646 else if( index == count - 2 )
648 wxTextEntryDialog dlg(
this,
_(
"Layer preset name:" ),
_(
"Save Layer Preset" ) );
650 if( dlg.ShowModal() != wxID_OK )
659 name = dlg.GetValue();
663 if( !
IsOK(
this,
_(
"Overwrite existing preset?" ) ) )
669 preset->layers = visibleLayers;
670 preset->colors = colors;
684 else if( index == count - 1 )
686 wxArrayString headers;
687 std::vector<wxArrayString> items;
689 headers.Add(
_(
"Presets" ) );
694 item.Add( preset.
name );
695 items.emplace_back( item );
701 if( dlg.ShowModal() == wxID_OK )
711 return preset.name == name;
759 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
760 m_cbViewports->Append( pair.first,
static_cast<void*
>( &pair.second ) );
776 if( index >= 0 && index < count - 3 )
780 wxCHECK( viewport, );
784 if( !viewport->
name.IsEmpty() )
790 else if( index == count - 2 )
795 wxTextEntryDialog dlg(
this,
_(
"Viewport name:" ),
_(
"Save Viewport" ),
name );
797 if( dlg.ShowModal() != wxID_OK )
807 name = dlg.GetValue();
828 else if( index == count - 1 )
831 wxArrayString headers;
832 std::vector<wxArrayString> items;
834 headers.Add(
_(
"Viewports" ) );
836 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
839 item.Add( pair.first );
840 items.emplace_back( item );
846 if( dlg.ShowModal() == wxID_OK )
851 if( idx != wxNOT_FOUND )
876 if( index >= 0 && index < count - 3 )
880 wxCHECK( viewport, );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Container for an appearance setting (can control a layer class, object type, etc.)
Class APPEARANCE_CONTROLS_3D_BASE.
wxScrolledCanvas * m_windowLayers
wxChoice * m_cbLayerPresets
wxBoxSizer * m_sizerOuter
wxStaticText * m_presetsLabel
wxStaticText * m_viewportsLabel
void CommonSettingsChanged()
VIEWPORT3D * m_lastSelectedViewport
wxArrayString m_viewportMRU
~APPEARANCE_CONTROLS_3D()
GRID_BITMAP_TOGGLE_RENDERER * m_toggleGridRenderer
void onLayerPresetChanged(wxCommandEvent &aEvent) override
wxArrayString m_presetMRU
void updateLayerPresetWidget(const wxString &aName)
wxSize GetBestSize() const
std::vector< VIEWPORT3D > GetUserViewports() const
Update the current viewports from those saved in the project file.
wxColour m_layerPanelColour
void ApplyViewport(const wxString &aPresetName)
void syncLayerPresetSelection()
void rebuildLayerPresetsWidget()
void onColorSwatchChanged(COLOR_SWATCH *aSwatch)
wxBoxSizer * m_envOuterSizer
APPEARANCE_CONTROLS_3D(EDA_3D_VIEWER_FRAME *aParent, wxWindow *aFocusOwner)
std::vector< std::unique_ptr< APPEARANCE_SETTING_3D > > m_layerSettings
std::map< int, APPEARANCE_SETTING_3D * > m_layerSettingsMap
static const APPEARANCE_SETTING_3D s_layerSettings[]
Template for object appearance settings.
void doApplyLayerPreset(const LAYER_PRESET_3D &aPreset)
EDA_3D_VIEWER_FRAME * m_frame
void onUpdateViewportsCb(wxUpdateUIEvent &aEvent) override
void OnSetFocus(wxFocusEvent &aEvent) override
void OnLayerVisibilityChanged(int aLayer, bool isVisible)
void OnSize(wxSizeEvent &aEvent) override
void doApplyViewport(const VIEWPORT3D &aViewport)
std::map< wxString, VIEWPORT3D > m_viewports
wxBoxSizer * m_layersOuterSizer
void ApplyLayerPreset(const wxString &aPresetName)
void rebuildViewportsWidget()
void onViewportChanged(wxCommandEvent &aEvent) override
void SetUserViewports(std::vector< VIEWPORT3D > &aPresetList)
A checkbox control except with custom bitmaps for the checked and unchecked states.
Helper class to handle information needed to display 3D board.
void SetVisibleLayers(const std::bitset< LAYER_3D_END > &aLayers)
std::map< int, COLOR4D > GetLayerColors() const
std::bitset< LAYER_3D_END > GetVisibleLayers() const
void SetLayerColors(const std::map< int, COLOR4D > &aColors)
EDA_3D_VIEWER_SETTINGS * m_Cfg
std::map< int, COLOR4D > GetDefaultColors() const
const glm::mat4 & GetViewMatrix() const
void SetViewMatrix(glm::mat4 aViewMatrix)
Set the affine matrix to be applied to a transformation camera.
A simple color swatch of the kind used to set layer colors.
KIGFX::COLOR4D GetSwatchColor() const
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetContentScaleFactor() const override
Get the content scale factor, which may be different from the scale factor on some platforms.
double GetScaleFactor() const override
Get the DPI scale from all known sources in order:
static TOOL_ACTION showNotInPosFile
static TOOL_ACTION showTHT
static TOOL_ACTION showDNP
static TOOL_ACTION showSMD
static TOOL_ACTION showVirtual
static TOOL_ACTION showBBoxes
static TOOL_ACTION showAxis
RENDER_3D_BASE * GetCurrentRender() const
void RenderRaytracingRequest()
Request to render the current view in Raytracing mode.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
BOARD_ADAPTER & GetAdapter() override
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
CAMERA & GetCurrentCamera() override
EDA_3D_CANVAS * GetCanvas()
LAYER_PRESET_3D * FindPreset(const wxString &aName)
std::vector< LAYER_PRESET_3D > m_LayerPresets
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
void SetListLabel(const wxString &aLabel)
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
A color representation with 4 components: red, green, blue, alpha.
Object to render the board using openGL.
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
This file is part of the common library.
Declaration of the eda_3d_viewer class.
#define FOLLOW_PLOT_SETTINGS
#define VIEWPORT_SWITCH_KEY
#define PRESET_SWITCH_KEY
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
@ LAYER_3D_SOLDERMASK_TOP
@ LAYER_3D_BOUNDING_BOXES
@ LAYER_3D_BACKGROUND_TOP
@ LAYER_3D_SOLDERMASK_BOTTOM
@ LAYER_3D_SILKSCREEN_TOP
@ LAYER_3D_VIRTUAL_MODELS
@ LAYER_3D_MODELS_MARKED_DNP
@ LAYER_3D_OFF_BOARD_SILK
@ LAYER_3D_MODELS_NOT_IN_POS
@ LAYER_3D_BACKGROUND_BOTTOM
@ LAYER_3D_SILKSCREEN_BOTTOM
@ LAYER_FP_REFERENCES
show footprints references (when texts are visible)
@ LAYER_FP_VALUES
show footprints values (when texts are visible)
wxFont GetInfoFont(wxWindow *aWindow)
void delete_if(_Container &__c, _Function &&__f)
Deletes all values from __c for which __f returns true.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString name
A name for this layer set.
std::bitset< LAYER_3D_END > layers
std::map< int, KIGFX::COLOR4D > colors