45#include <wx/bmpbuttn.h>
47#include <wx/textdlg.h>
48#include <wx/checkbox.h>
59#define RR APPEARANCE_CONTROLS_3D::APPEARANCE_SETTING_3D
179 int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
180 m_pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
201 _(
"Use board stackup colors" ) );
205 [
this]( wxCommandEvent& aEvent )
215 _(
"Use PCB editor copper colors" ) );
218 "layers (realtime renderer only)" ) );
221 [
this]( wxCommandEvent& aEvent )
232 wxEXPAND | wxALL, 5 );
234 m_cbLayerPresets->SetToolTip( wxString::Format(
_(
"Save and restore color and visibility combinations.\n"
235 "Use %s+Tab to activate selector.\n"
236 "Successive Tabs while holding %s down will cycle through "
237 "presets in the popup." ),
241 m_cbViewports->SetToolTip( wxString::Format(
_(
"Save and restore camera position and zoom.\n"
242 "Use %s+Tab to activate selector.\n"
243 "Successive Tabs while holding %s down will cycle through "
244 "viewports in the popup." ),
280 menu.AppendSeparator();
290 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
292 auto setInnerCopperLayers =
305 switch( GetPopupMenuSelectionFromUser( menu ) )
310 setInnerCopperLayers(
true );
316 setInnerCopperLayers(
false );
320 setInnerCopperLayers(
true );
324 setInnerCopperLayers(
false );
331 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
343 if( wxBitmapButton* btn =
dynamic_cast<wxBitmapButton*
>( aEvent.GetEventObject() ) )
345 wxCommandEvent evt( wxEVT_BUTTON );
346 wxPostEvent( btn, evt );
398 if( child && child->GetWindow() )
410 const wxString& currentPreset =
m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
424 if(
m_presetMRU.Index( aPresetName ) != wxNOT_FOUND )
435 std::vector<VIEWPORT3D> ret;
438 ret.emplace_back( viewport );
448 for(
const VIEWPORT3D& viewport : aViewportList )
493 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
494 const std::map<int, COLOR4D>& colors =
m_frame->GetAdapter().GetLayerColors();
495 bool killFollow =
false;
496 bool doFastRefresh =
false;
521 visibleLayers.set( aLayer, isVisible );
543 visibleLayers.set( aLayer, isVisible );
552 doFastRefresh =
true;
553 visibleLayers.set( aLayer, isVisible );
557 visibleLayers.set( aLayer, isVisible );
568 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
569 m_frame->GetAdapter().SetLayerColors( colors );
571 const wxString& currentPreset =
m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
583 m_frame->GetCanvas()->Request_refresh();
594 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
595 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
597 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
599 int layer = aSwatch->GetId();
611 if( colors.count(
index ) )
612 colors[
index] = newColor;
614 if( setting->m_Ctl_color )
617 setting->m_Ctl_color->SetSwatchColor( newColor,
false );
623 colors[layer] = newColor;
626 m_frame->GetAdapter().SetLayerColors( colors );
628 const wxString& currentPreset =
m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
641 int swatchWidth =
m_windowLayers->ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
643 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
644 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
645 std::map<int, COLOR4D> defaultColors =
m_frame->GetAdapter().GetDefaultColors();
646 LSET enabled =
m_frame->GetBoard()->GetEnabledLayers();
655 const auto appendLayer =
656 [&](
const std::unique_ptr<APPEARANCE_SETTING_3D>& aSetting,
int aColorLayer )
658 wxBoxSizer* sizer =
new wxBoxSizer( wxHORIZONTAL );
659 int layer = aSetting->m_Id;
661 aSetting->m_Visible = visibleLayers.test( layer );
663 if( colors.count( aColorLayer ) )
668 swatch->SetToolTip(
_(
"Left double click or middle click to change color" ) );
679 "allow color editing." ),
680 10000, wxICON_INFORMATION );
683 sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 );
684 aSetting->m_Ctl_color = swatch;
686 swatch->Bind( COLOR_SWATCH_CHANGED,
687 [
this]( wxCommandEvent& event )
689 auto swatch =
static_cast<COLOR_SWATCH*
>(
event.GetEventObject() );
697 sizer->AddSpacer( swatchWidth );
700 sizer->AddSpacer( 5 );
702 wxString layerName = aSetting->GetLabel();
706 layerName =
m_frame->GetBoard()->GetLayerName( boardLayer );
708 wxStaticText* label =
new wxStaticText(
m_windowLayers, layer, layerName );
710 label->SetToolTip( aSetting->GetTooltip() );
714 sizer->AddSpacer( swatchWidth );
721 aSetting->m_Visible );
723 btn_visible->Bind( TOGGLE_CHANGED,
724 [
this]( wxCommandEvent& aEvent )
726 int id =
static_cast<wxWindow*
>( aEvent.GetEventObject() )->GetId();
727 bool isVisible = aEvent.GetInt();
734 tip.Printf(
_(
"Show or hide %s" ), aSetting->GetLabel().Lower() );
735 btn_visible->SetToolTip( tip );
737 aSetting->m_Ctl_visibility = btn_visible;
738 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
741 sizer->AddSpacer( 5 );
742 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL, 0 );
748 const auto appendInnerLayers =
760 wxString tooltip = wxString::Format(
_(
"Show %s" ), label );
763 std::make_unique<APPEARANCE_SETTING_3D>( label, layerId, tooltip ) );
771 m_layerSettings.emplace_back( std::make_unique<APPEARANCE_SETTING_3D>( s_setting ) );
772 std::unique_ptr<APPEARANCE_SETTING_3D>& setting =
m_layerSettings.back();
774 if( setting->m_Spacer )
781 appendLayer( setting, setting->m_Id );
785 appendLayer( setting, setting->m_Id );
802 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
803 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
805 for( std::unique_ptr<APPEARANCE_SETTING_3D>& setting :
m_layerSettings )
807 if( setting->m_Spacer )
810 if( setting->m_Ctl_visibility )
811 setting->m_Ctl_visibility->SetValue( visibleLayers.test( setting->m_Id ) );
813 if( setting->m_Ctl_color )
818 setting->m_Ctl_color->SetSwatchColor( colors[colorLayer],
false );
847 if( !
m_frame->GetAdapter().m_Cfg->m_LayerPresets.empty() )
864 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = wxEmptyString;
866 std::vector<LAYER_PRESET_3D>& presets =
m_frame->GetAdapter().m_Cfg->m_LayerPresets;
867 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
868 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
870 auto it = std::find_if(
871 presets.begin(), presets.end(),
874 if( aPreset.name.Lower() == _(
"legacy colors" ) && m_cbUseBoardStackupColors->GetValue() )
877 for( int layer = LAYER_3D_BOARD; layer < LAYER_3D_END; ++layer )
879 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
883 for(
int layer : { LAYER_FP_REFERENCES, LAYER_FP_VALUES, LAYER_FP_TEXT } )
885 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
891 auto it1 = aPreset.colors.find( layer );
892 auto it2 = colors.find( layer );
894 if( it1 != aPreset.colors.end() && it2 != colors.end() && *it1 != *it2 )
901 if( it != presets.end() )
903 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = it->name;
904 m_cbLayerPresets->SetStringSelection( it->name );
908 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 );
931 auto resetSelection =
941 else if(
index == 1 )
945 else if(
index == count - 2 )
947 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ),
_(
"Layer preset name:" ),
948 _(
"Save Layer Preset" ) );
950 if( dlg.ShowModal() != wxID_OK )
956 std::bitset<LAYER_3D_END> visibleLayers =
m_frame->GetAdapter().GetVisibleLayers();
957 std::map<int, COLOR4D> colors =
m_frame->GetAdapter().GetLayerColors();
959 name = dlg.GetValue();
963 if( !
IsOK( wxGetTopLevelParent(
this ),
_(
"Overwrite existing preset?" ) ) )
969 preset->layers = visibleLayers;
970 preset->colors = colors;
985 else if(
index == count - 1 )
987 wxArrayString headers;
988 std::vector<wxArrayString> items;
990 headers.Add(
_(
"Presets" ) );
995 item.Add( preset.
name );
996 items.emplace_back( item );
1012 return preset.name == name;
1061 if( preset->name.Lower() ==
_(
"legacy colors" ) )
1081 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
1082 m_cbViewports->Append( pair.first,
static_cast<void*
>( &pair.second ) );
1102 wxCHECK( viewport, );
1106 if( !viewport->
name.IsEmpty() )
1114 else if(
index == count - 2 )
1119 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ),
_(
"Viewport name:" ),
1120 _(
"Save Viewport" ),
name );
1122 if( dlg.ShowModal() != wxID_OK )
1132 name = dlg.GetValue();
1155 else if(
index == count - 1 )
1158 wxArrayString headers;
1159 std::vector<wxArrayString> items;
1161 headers.Add(
_(
"Viewports" ) );
1163 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
1166 item.Add( pair.first );
1167 items.emplace_back( item );
1178 if( idx != wxNOT_FOUND )
1209 wxCHECK( viewport, );
1211 if(
m_frame->GetCurrentCamera().GetViewMatrix() != viewport->
matrix )
1219 m_frame->GetCurrentCamera().SetViewMatrix( aViewport.
matrix );
1222 m_frame->GetCanvas()->Request_refresh();
1224 m_frame->GetCanvas()->RenderRaytracingRequest();
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
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
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 ApplyViewport(const wxString &aPresetName)
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 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 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
wxString name
A name for this layer set.