40#include <wx/bmpbuttn.h>
42#include <wx/textdlg.h>
43#include <wx/checkbox.h>
45#include <../3d_rendering/opengl/render_3d_opengl.h>
49#define RR APPEARANCE_CONTROLS_3D::APPEARANCE_SETTING_3D
144 m_focusOwner( aFocusOwner ),
145 m_lastSelectedViewport( nullptr )
149 int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
150 m_pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
170 _(
"Use board stackup colors" ) );
174 [
this]( wxCommandEvent& aEvent )
184 _(
"Use PCB editor copper colors" ) );
187 "layers (realtime renderer only)" ) );
190 [
this]( wxCommandEvent& aEvent )
201 wxEXPAND | wxALL, 5 );
203 m_cbLayerPresets->SetToolTip( wxString::Format(
_(
"Save and restore color and visibility combinations.\n"
204 "Use %s+Tab to activate selector.\n"
205 "Successive Tabs while holding %s down will cycle through "
206 "presets in the popup." ),
210 m_cbViewports->SetToolTip( wxString::Format(
_(
"Save and restore camera position and zoom.\n"
211 "Use %s+Tab to activate selector.\n"
212 "Successive Tabs while holding %s down will cycle through "
213 "viewports in the popup." ),
248 if( wxBitmapButton* btn =
dynamic_cast<wxBitmapButton*
>( aEvent.GetEventObject() ) )
250 wxCommandEvent evt( wxEVT_BUTTON );
251 wxPostEvent( btn, evt );
303 if( child && child->GetWindow() )
329 if(
m_presetMRU.Index( aPresetName ) != wxNOT_FOUND )
340 std::vector<VIEWPORT3D> ret;
343 ret.emplace_back( viewport );
353 for(
const VIEWPORT3D& viewport : aViewportList )
400 bool killFollow =
false;
401 bool doFastRefresh =
false;
426 visibleLayers.set( aLayer, isVisible );
444 visibleLayers.set( aLayer, isVisible );
453 doFastRefresh =
true;
454 visibleLayers.set( aLayer, isVisible );
458 visibleLayers.set( aLayer, isVisible );
496 int layer = aSwatch->GetId();
499 colors[ layer ] = newColor;
505 const std::vector<int> copperIndices{
512 if( std::find( copperIndices.begin(), copperIndices.end(), layer ) != copperIndices.end() )
514 for(
int index : copperIndices )
516 if( layer != index && colors.count( index ) )
518 colors[index] = newColor;
546 int swatchWidth =
m_windowLayers->ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
560 [&](
const std::unique_ptr<APPEARANCE_SETTING_3D>& aSetting )
562 wxBoxSizer* sizer =
new wxBoxSizer( wxHORIZONTAL );
563 int layer = aSetting->m_Id;
565 aSetting->m_Visible = visibleLayers.test( layer );
567 if( colors.count( layer ) )
570 COLOR4D::WHITE, defaultColors[ layer ],
572 swatch->SetToolTip(
_(
"Left double click or middle click to change color" ) );
583 "allow color editing." ),
584 10000, wxICON_INFORMATION );
587 sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 );
588 aSetting->m_Ctl_color = swatch;
590 swatch->Bind( COLOR_SWATCH_CHANGED,
591 [
this]( wxCommandEvent& event )
593 auto swatch =
static_cast<COLOR_SWATCH*
>(
event.GetEventObject() );
601 sizer->AddSpacer( swatchWidth );
604 sizer->AddSpacer( 5 );
606 wxString layerName = aSetting->GetLabel();
612 wxStaticText* label =
new wxStaticText(
m_windowLayers, layer, layerName );
614 label->SetToolTip( aSetting->GetTooltip() );
618 sizer->AddSpacer( swatchWidth );
625 aSetting->m_Visible );
627 btn_visible->Bind( TOGGLE_CHANGED,
628 [
this]( wxCommandEvent& aEvent )
630 int id =
static_cast<wxWindow*
>( aEvent.GetEventObject() )->GetId();
631 bool isVisible = aEvent.GetInt();
638 tip.Printf(
_(
"Show or hide %s" ), aSetting->GetLabel().Lower() );
639 btn_visible->SetToolTip( tip );
641 aSetting->m_Ctl_visibility = btn_visible;
642 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
645 sizer->AddSpacer( 5 );
646 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL, 0 );
654 m_layerSettings.emplace_back( std::make_unique<APPEARANCE_SETTING_3D>( s_setting ) );
655 std::unique_ptr<APPEARANCE_SETTING_3D>& setting =
m_layerSettings.back();
657 if( setting->m_Spacer )
664 appendLayer( setting );
668 appendLayer( setting );
684 for( std::unique_ptr<APPEARANCE_SETTING_3D>& setting :
m_layerSettings )
686 if( setting->m_Spacer )
689 if( setting->m_Ctl_visibility )
690 setting->m_Ctl_visibility->SetValue( visibleLayers.test( setting->m_Id ) );
692 if( setting->m_Ctl_color )
694 setting->m_Ctl_color->SetSwatchColor( colors[ setting->m_Id ],
false );
742 auto it = std::find_if(
743 presets.begin(), presets.end(),
746 if( aPreset.name.Lower() == _(
"legacy colors" ) && m_cbUseBoardStackupColors->GetValue() )
749 for( int layer = LAYER_3D_BOARD; layer < LAYER_3D_END; ++layer )
751 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
755 for(
int layer : { LAYER_FP_REFERENCES, LAYER_FP_VALUES, LAYER_FP_TEXT } )
757 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
763 auto it1 = aPreset.colors.find( layer );
764 auto it2 = colors.find( layer );
766 if( it1 != aPreset.colors.end() && it2 != colors.end() && *it1 != *it2 )
773 if( it != presets.end() )
775 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = it->name;
776 m_cbLayerPresets->SetStringSelection( it->name );
780 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 );
803 auto resetSelection =
813 else if( index == 1 )
817 else if( index == count - 3 )
823 else if( index == count - 2 )
825 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ),
_(
"Layer preset name:" ),
826 _(
"Save Layer Preset" ) );
828 if( dlg.ShowModal() != wxID_OK )
837 name = dlg.GetValue();
841 if( !
IsOK( wxGetTopLevelParent(
this ),
_(
"Overwrite existing preset?" ) ) )
847 preset->layers = visibleLayers;
848 preset->colors = colors;
862 else if( index == count - 1 )
864 wxArrayString headers;
865 std::vector<wxArrayString> items;
867 headers.Add(
_(
"Presets" ) );
872 item.Add( preset.
name );
873 items.emplace_back( item );
889 return preset.name == name;
932 if( preset->name.Lower() ==
_(
"legacy colors" ) )
952 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
953 m_cbViewports->Append( pair.first,
static_cast<void*
>( &pair.second ) );
969 if( index >= 0 && index < count - 3 )
973 wxCHECK( viewport, );
977 if( !viewport->
name.IsEmpty() )
985 else if( index == count - 2 )
990 wxTextEntryDialog dlg( wxGetTopLevelParent(
this ),
_(
"Viewport name:" ),
991 _(
"Save Viewport" ),
name );
993 if( dlg.ShowModal() != wxID_OK )
1003 name = dlg.GetValue();
1026 else if( index == count - 1 )
1029 wxArrayString headers;
1030 std::vector<wxArrayString> items;
1032 headers.Add(
_(
"Viewports" ) );
1034 for( std::pair<const wxString, VIEWPORT3D>& pair :
m_viewports )
1037 item.Add( pair.first );
1038 items.emplace_back( item );
1049 if( idx != wxNOT_FOUND )
1076 if( index >= 0 && index < count - 3 )
1080 wxCHECK( viewport, );
static std::vector< int > inStackupColors
#define RR
Render Row abbreviation to reduce source width.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Container for an appearance setting (can control a layer class, object type, etc.)
Class APPEARANCE_CONTROLS_3D_BASE.
wxScrolledCanvas * m_windowLayers
wxBoxSizer * m_panelLayersSizer
wxChoice * m_cbLayerPresets
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()
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 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::map< int, COLOR4D > GetLayerColors() const
Build a color list which is used to store colors layers.
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 wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
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.
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
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
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.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
EDA_3D_CANVAS * GetCanvas()
CAMERA & GetCurrentCamera()
BOARD_ADAPTER & GetAdapter()
LAYER_PRESET_3D * FindPreset(const wxString &aName)
std::vector< LAYER_PRESET_3D > m_LayerPresets
WX_INFOBAR * GetInfoBar()
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 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)
@ LAYER_3D_SOLDERMASK_TOP
@ LAYER_3D_BOUNDING_BOXES
@ LAYER_3D_BACKGROUND_TOP
@ LAYER_3D_SOLDERMASK_BOTTOM
@ LAYER_3D_PLATED_BARRELS
@ 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).
PCB_LAYER_ID
A quick note on layer IDs:
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
const int c_IndicatorSizeDIP
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool use_board_editor_copper_colors
wxString name
A name for this layer set.