45#include <wx/bmpbuttn.h>
47#include <wx/textdlg.h>
48#include <wx/checkbox.h>
62#define RR APPEARANCE_CONTROLS_3D::APPEARANCE_SETTING_3D
182 int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
183 m_pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
204 _(
"Use board stackup colors" ) );
208 [
this]( wxCommandEvent& aEvent )
218 _(
"Use PCB editor copper colors" ) );
221 "layers (realtime renderer only)" ) );
224 [
this]( wxCommandEvent& aEvent )
235 wxEXPAND | wxALL, 5 );
237 m_cbLayerPresets->SetToolTip( wxString::Format(
_(
"Save and restore color and visibility combinations.\n"
238 "Use %s+Tab to activate selector.\n"
239 "Successive Tabs while holding %s down will cycle through "
240 "presets in the popup." ),
244 m_cbViewports->SetToolTip( wxString::Format(
_(
"Save and restore camera position and zoom.\n"
245 "Use %s+Tab to activate selector.\n"
246 "Successive Tabs while holding %s down will cycle through "
247 "viewports in the popup." ),
291 menu.AppendSeparator();
301 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
303 auto setInnerCopperLayers =
316 switch( GetPopupMenuSelectionFromUser( menu ) )
321 setInnerCopperLayers(
true );
327 setInnerCopperLayers(
false );
331 setInnerCopperLayers(
true );
335 setInnerCopperLayers(
false );
342 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
384 if( wxBitmapButton* btn =
dynamic_cast<wxBitmapButton*
>( aEvent.GetEventObject() ) )
386 wxCommandEvent evt( wxEVT_BUTTON );
387 wxPostEvent( btn, evt );
439 if( child && child->GetWindow() )
454 const wxString& currentPreset =
m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
468 if(
m_presetMRU.Index( aPresetName ) != wxNOT_FOUND )
479 std::vector<VIEWPORT3D> ret;
482 ret.emplace_back( viewport );
493 for(
const VIEWPORT3D& viewport : aViewportList )
539 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
540 const std::map<int, COLOR4D>& colors =
m_frame->GetAdapter().GetLayerColors();
541 bool killFollow =
false;
542 bool doFastRefresh =
false;
567 visibleLayers.set( aLayer, isVisible );
589 visibleLayers.set( aLayer, isVisible );
598 doFastRefresh =
true;
599 visibleLayers.set( aLayer, isVisible );
603 visibleLayers.set( aLayer, isVisible );
614 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
615 m_frame->GetAdapter().SetLayerColors( colors );
617 const wxString& currentPreset =
m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
629 m_frame->GetCanvas()->Request_refresh();
640 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
641 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
643 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
645 int layer = aSwatch->GetId();
657 if( colors.count(
index ) )
658 colors[
index] = newColor;
660 if( setting->m_Ctl_color )
663 setting->m_Ctl_color->SetSwatchColor( newColor,
false );
669 colors[layer] = newColor;
672 m_frame->GetAdapter().SetLayerColors( colors );
674 const wxString& currentPreset =
m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
687 int swatchWidth =
m_windowLayers->ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
689 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
690 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
691 std::map<int, COLOR4D> defaultColors =
m_frame->GetAdapter().GetDefaultColors();
692 LSET enabled =
m_frame->GetBoard()->GetEnabledLayers();
701 const auto appendLayer =
702 [&](
const std::unique_ptr<APPEARANCE_SETTING_3D>& aSetting,
int aColorLayer )
704 wxBoxSizer* sizer =
new wxBoxSizer( wxHORIZONTAL );
705 int layer = aSetting->m_Id;
707 aSetting->m_Visible = visibleLayers.test( layer );
709 if( colors.count( aColorLayer ) )
714 swatch->SetToolTip(
_(
"Left double click or middle click to change color" ) );
725 "allow color editing." ),
726 10000, wxICON_INFORMATION );
729 sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 );
730 aSetting->m_Ctl_color = swatch;
732 swatch->Bind( COLOR_SWATCH_CHANGED,
733 [
this]( wxCommandEvent& event )
735 auto swatch =
static_cast<COLOR_SWATCH*
>(
event.GetEventObject() );
743 sizer->AddSpacer( swatchWidth );
746 sizer->AddSpacer( 5 );
748 wxString layerName = aSetting->GetLabel();
752 layerName =
m_frame->GetBoard()->GetLayerName( boardLayer );
754 wxStaticText* label =
new wxStaticText(
m_windowLayers, layer, layerName );
756 label->SetToolTip( aSetting->GetTooltip() );
760 sizer->AddSpacer( swatchWidth );
767 aSetting->m_Visible );
769 btn_visible->Bind( TOGGLE_CHANGED,
770 [
this]( wxCommandEvent& aEvent )
772 int id =
static_cast<wxWindow*
>( aEvent.GetEventObject() )->GetId();
773 bool isVisible = aEvent.GetInt();
780 tip.Printf(
_(
"Show or hide %s" ), aSetting->GetLabel().Lower() );
781 btn_visible->SetToolTip( tip );
783 aSetting->m_Ctl_visibility = btn_visible;
784 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
787 sizer->AddSpacer( 5 );
788 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL, 0 );
794 const auto appendInnerLayers =
806 wxString tooltip = wxString::Format(
_(
"Show %s" ), label );
809 std::make_unique<APPEARANCE_SETTING_3D>( label, layerId, tooltip ) );
817 m_layerSettings.emplace_back( std::make_unique<APPEARANCE_SETTING_3D>( s_setting ) );
818 std::unique_ptr<APPEARANCE_SETTING_3D>& setting =
m_layerSettings.back();
820 if( setting->m_Spacer )
827 appendLayer( setting, setting->m_Id );
831 appendLayer( setting, setting->m_Id );
848 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
849 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
851 for( std::unique_ptr<APPEARANCE_SETTING_3D>& setting :
m_layerSettings )
853 if( setting->m_Spacer )
856 if( setting->m_Ctl_visibility )
857 setting->m_Ctl_visibility->SetValue( visibleLayers.test( setting->m_Id ) );
859 if( setting->m_Ctl_color )
864 setting->m_Ctl_color->SetSwatchColor( colors[colorLayer],
false );
893 if( !
m_frame->GetAdapter().m_Cfg->m_LayerPresets.empty() )
910 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = wxEmptyString;
912 std::vector<LAYER_PRESET_3D>& presets =
m_frame->GetAdapter().m_Cfg->m_LayerPresets;
913 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
914 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
916 auto it = std::find_if(
917 presets.begin(), presets.end(),
920 if( aPreset.name.Lower() == _(
"legacy colors" ) && m_cbUseBoardStackupColors->GetValue() )
923 for( int layer = LAYER_3D_BOARD; layer < LAYER_3D_END; ++layer )
925 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
929 for(
int layer : { LAYER_FP_REFERENCES, LAYER_FP_VALUES, LAYER_FP_TEXT } )
931 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
937 auto it1 = aPreset.colors.find( layer );
938 auto it2 = colors.find( layer );
940 if( it1 != aPreset.colors.end() && it2 != colors.end() && *it1 != *it2 )
947 if( it != presets.end() )
949 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = it->name;
950 m_cbLayerPresets->SetStringSelection( it->name );
954 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 );
977 auto resetSelection =
987 else if(
index == 1 )
991 else if(
index == count - 2 )
993 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ),
_(
"Layer preset name:" ),
994 _(
"Save Layer Preset" ) );
996 if( dlg.ShowModal() != wxID_OK )
1002 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
1003 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
1005 name = dlg.GetValue();
1009 if( !
IsOK( wxGetTopLevelParent(
this ),
_(
"Overwrite existing preset?" ) ) )
1015 preset->layers = visibleLayers;
1016 preset->colors = colors;
1031 else if(
index == count - 1 )
1033 wxArrayString headers;
1034 std::vector<wxArrayString> items;
1036 headers.Add(
_(
"Presets" ) );
1041 item.Add( preset.
name );
1042 items.emplace_back( item );
1058 return preset.name == name;
1107 if( preset->name.Lower() ==
_(
"legacy colors" ) )
1127 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
1128 m_cbViewports->Append( pair.first,
static_cast<void*
>( &pair.second ) );
1148 wxCHECK( viewport, );
1152 if( !viewport->
name.IsEmpty() )
1160 else if(
index == count - 2 )
1165 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ),
_(
"Viewport name:" ),
1166 _(
"Save Viewport" ),
name );
1168 if( dlg.ShowModal() != wxID_OK )
1178 name = dlg.GetValue();
1201 else if(
index == count - 1 )
1204 wxArrayString headers;
1205 std::vector<wxArrayString> items;
1207 headers.Add(
_(
"Viewports" ) );
1209 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
1212 item.Add( pair.first );
1213 items.emplace_back( item );
1224 if( idx != wxNOT_FOUND )
1255 wxCHECK( viewport, );
1257 if(
m_frame->GetCurrentCamera().GetViewMatrix() != viewport->
matrix )
1265 m_frame->GetCurrentCamera().SetViewMatrix( aViewport.
matrix );
1268 m_frame->GetCanvas()->Request_refresh();
1270 m_frame->GetCanvas()->RenderRaytracingRequest();
static constexpr int REBUILD_DELAY_MS
Debounce delay for rebuilding the 3D view after control changes.
static bool isCopperLayer3D(int aLayer)
#define RR
Render Row abbreviation to reduce source width.
static constexpr int ID_HIDE_ALL_COPPER_LAYERS
static bool isStackupColorLayer3D(int aLayer)
static constexpr int ID_SHOW_ALL_COPPER_LAYERS
static constexpr int ID_HIDE_ALL_INNER_LAYERS
static constexpr int ID_SHOW_ALL_INNER_LAYERS
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Container for an appearance setting (can control a layer class, object type, etc.)
wxScrolledCanvas * m_windowLayers
wxSpinCtrlDouble * m_layerScaleCtrl
wxBoxSizer * m_panelLayersSizer
wxChoice * m_cbLayerPresets
APPEARANCE_CONTROLS_3D_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxBoxSizer * m_sizerOuter
wxStaticText * m_presetsLabel
wxBitmapButton * m_btnResetLayerScale
wxStaticText * m_viewportsLabel
void OnLanguageChanged(wxCommandEvent &aEvent)
void CommonSettingsChanged()
VIEWPORT3D * m_lastSelectedViewport
wxArrayString m_viewportMRU
~APPEARANCE_CONTROLS_3D()
GRID_BITMAP_TOGGLE_RENDERER * m_toggleGridRenderer
wxCheckBox * m_cbUseBoardStackupColors
void onLayerPresetChanged(wxCommandEvent &aEvent) override
wxArrayString m_presetMRU
void updateLayerPresetWidget(const wxString &aName)
wxSize GetBestSize() const
std::vector< VIEWPORT3D > GetUserViewports() const
Return a list of viewports created by the user.
wxColour m_layerPanelColour
void OnRedrawTriggerTimer(wxTimerEvent &aEvent)
void ApplyViewport(const wxString &aPresetName)
wxTimer m_redrawTriggerTimer
A timer used to rate-limit redraws when UI controls change.
void syncLayerPresetSelection()
void rebuildLayerPresetsWidget(bool aReset)
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 wxString &aPresetName)
EDA_3D_VIEWER_FRAME * m_frame
void onUpdateViewportsCb(wxUpdateUIEvent &aEvent) override
void OnSetFocus(wxFocusEvent &aEvent) override
void OnResetLayerSpacing(wxCommandEvent &aEvent) override
void OnLayerVisibilityChanged(int aLayer, bool isVisible)
void OnLayerContextMenu(wxContextMenuEvent &aEvent)
void OnSize(wxSizeEvent &aEvent) override
void doApplyViewport(const VIEWPORT3D &aViewport)
std::map< wxString, VIEWPORT3D > m_viewports
wxCheckBox * m_cbUseBoardEditorCopperColors
wxBoxSizer * m_layersOuterSizer
void ApplyLayerPreset(const wxString &aPresetName)
void rebuildViewportsWidget()
void onViewportChanged(wxCommandEvent &aEvent) override
void OnLayerScaleChange(wxSpinDoubleEvent &aEvent) override
void SetUserViewports(std::vector< VIEWPORT3D > &aPresetList)
Update the current viewports from those saved in the project file.
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::bitset< LAYER_3D_END > GetVisibleLayers() const
void SetLayerColors(const std::map< int, COLOR4D > &aColors)
EDA_3D_VIEWER_SETTINGS * m_Cfg
Information pertinent to a Pcbnew printed circuit board.
int GetCopperLayerCount() const
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
static const COLOR4D WHITE
A simple color swatch of the kind used to set layer colors.
KIGFX::COLOR4D GetSwatchColor() const
void SetReadOnlyCallback(std::function< void()> aCallback)
Register a handler for when the user tries to interact with a read-only swatch.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetScaleFactor() const override
Get the DPI scale from all known sources in order:
static TOOL_ACTION showNavigator
static TOOL_ACTION showNotInPosFile
static TOOL_ACTION showTHT
static TOOL_ACTION showDNP
static TOOL_ACTION showSMD
static TOOL_ACTION showVirtual
static TOOL_ACTION showBBoxes
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
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.
LSET is a set of PCB_LAYER_IDs.
Object to render the board using openGL.
void RebuildHitTestAsync()
Rebuild the raytracing hit-test scene in the background after a visibility change.
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
A modified version of the wxInfoBar class that allows us to:
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
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.
PCB_LAYER_ID Map3DLayerToPCBLayer(int aLayer)
int MapPCBLayerTo3DLayer(PCB_LAYER_ID aLayer)
@ LAYER_3D_COPPER_INNER_30
@ LAYER_3D_SOLDERMASK_TOP
@ LAYER_3D_BOUNDING_BOXES
@ LAYER_3D_BACKGROUND_TOP
@ LAYER_3D_SOLDERMASK_BOTTOM
@ LAYER_3D_PLATED_BARRELS
@ LAYER_3D_COPPER_INNER_1
@ 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).
bool IsInnerCopperLayer(int aLayerId)
Test whether a layer is an inner (In1_Cu to In30_Cu) copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
const int c_IndicatorSizeDIP
static bool isCopper(const PNS::ITEM *aItem)
bool use_board_editor_copper_colors
float board_layer_thickness_scale
wxString name
A name for this layer set.