KiCad PCB EDA Suite
Loading...
Searching...
No Matches
appearance_controls_3D.h
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) 2023 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <vector>
24
25#include <wx/event.h>
26
27#include <gal/color4d.h>
28#include <layer_ids.h>
31#include <tool/tool_action.h>
32
33
34class BITMAP_TOGGLE;
35class COLOR_SWATCH;
39
40using KIGFX::COLOR4D;
41
42
44{
45public:
46
51 {
52 public:
53 int m_Id;
56
59
60 APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const wxString& aTooltip ) :
61 m_Id( aId ),
62 m_Visible( true ),
63 m_Spacer( false ),
64 m_Ctl_visibility( nullptr ),
65 m_Ctl_color( nullptr ),
66 m_tooltip( aTooltip ),
67 m_label( aLabel )
68 {
69 }
70
71 APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const TOOL_ACTION& aAction ) :
72 m_Id( aId ),
73 m_Visible( true ),
74 m_Spacer( false ),
75 m_Ctl_visibility( nullptr ),
76 m_Ctl_color( nullptr ),
77 m_label( aLabel ),
78 m_action( &aAction )
79 {
80 }
81
83 m_Id( -1 ),
84 m_Visible( false ),
85 m_Spacer( true ),
86 m_Ctl_visibility( nullptr ),
87 m_Ctl_color( nullptr )
88 {
89 }
90
91 wxString GetTooltip() const
92 {
93 if( m_tooltip.has_value() )
94 return wxGetTranslation( m_tooltip.value() );
95 else if( m_action.has_value() )
96 return m_action.value()->GetTooltip( true );
97 else
98 return wxEmptyString;
99 }
100
101 wxString GetLabel() const
102 {
103 return wxGetTranslation( m_label );
104 }
105
106 private:
107 wxString m_label;
108
109 std::optional<wxString> m_tooltip;
110 std::optional<const TOOL_ACTION*> m_action;
111 };
112
113 APPEARANCE_CONTROLS_3D( EDA_3D_VIEWER_FRAME* aParent, wxWindow* aFocusOwner );
115
116 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
117 // will only land us in trouble.
120
121 wxSize GetBestSize() const;
122 void OnDarkModeToggle();
123 void OnLayerVisibilityChanged( int aLayer, bool isVisible );
124
126
127 void UpdateLayerCtls();
128
129 void ApplyLayerPreset( const wxString& aPresetName );
130
131 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
132
134 std::vector<VIEWPORT3D> GetUserViewports() const;
135
137 void SetUserViewports( std::vector<VIEWPORT3D>& aPresetList );
138
139 void ApplyViewport( const wxString& aPresetName );
140
141 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
142
143protected:
144 void OnSetFocus( wxFocusEvent& aEvent ) override;
145 void OnSize( wxSizeEvent& aEvent ) override;
146
147 void OnLayerContextMenu( wxContextMenuEvent& aEvent );
148 void OnLayerScaleChange( wxSpinDoubleEvent& aEvent ) override;
149 void OnResetLayerSpacing( wxCommandEvent& aEvent ) override;
150 void OnRedrawTriggerTimer( wxTimerEvent& aEvent );
151 void OnLanguageChanged( wxCommandEvent& aEvent );
152
153private:
154 void applyLayerSpacing();
155
156 void rebuildControls();
157
158 void rebuildLayers();
159
160 void rebuildLayerPresetsWidget( bool aReset );
161
163
165
166 void onColorSwatchChanged( COLOR_SWATCH* aSwatch );
167
168 void updateLayerPresetWidget( const wxString& aName );
169
170 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
171
172 void doApplyLayerPreset( const wxString& aPresetName );
173
174 void onViewportChanged( wxCommandEvent& aEvent ) override;
175 void onUpdateViewportsCb( wxUpdateUIEvent& aEvent ) override;
176
177 void doApplyViewport( const VIEWPORT3D& aViewport );
178
179 void passOnFocus();
180
181private:
182 static const APPEARANCE_SETTING_3D s_layerSettings[];
183
185 wxWindow* m_focusOwner;
186
187 std::vector<std::unique_ptr<APPEARANCE_SETTING_3D>> m_layerSettings;
188 std::map<int, APPEARANCE_SETTING_3D*> m_layerSettingsMap;
189
190 wxArrayString m_presetMRU;
191
192 std::map<wxString, VIEWPORT3D> m_viewports;
194 wxArrayString m_viewportMRU;
195
197 wxBoxSizer* m_envOuterSizer;
205};
APPEARANCE_SETTING_3D(const wxString &aLabel, int aId, const TOOL_ACTION &aAction)
std::optional< const TOOL_ACTION * > m_action
APPEARANCE_SETTING_3D(const wxString &aLabel, int aId, const wxString &aTooltip)
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)
void OnLanguageChanged(wxCommandEvent &aEvent)
GRID_BITMAP_TOGGLE_RENDERER * m_toggleGridRenderer
void onLayerPresetChanged(wxCommandEvent &aEvent) override
void updateLayerPresetWidget(const wxString &aName)
std::vector< VIEWPORT3D > GetUserViewports() const
Return a list of viewports created by the user.
void OnRedrawTriggerTimer(wxTimerEvent &aEvent)
void ApplyViewport(const wxString &aPresetName)
wxTimer m_redrawTriggerTimer
A timer used to rate-limit redraws when UI controls change.
void rebuildLayerPresetsWidget(bool aReset)
void onColorSwatchChanged(COLOR_SWATCH *aSwatch)
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
const wxArrayString & GetViewportsMRU()
APPEARANCE_CONTROLS_3D & operator=(const APPEARANCE_CONTROLS_3D &)=delete
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
APPEARANCE_CONTROLS_3D(const APPEARANCE_CONTROLS_3D &)=delete
void ApplyLayerPreset(const wxString &aPresetName)
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.
const wxArrayString & GetLayerPresetsMRU()
A checkbox control except with custom bitmaps for the checked and unchecked states.
A simple color swatch of the kind used to set layer colors.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Icon provider for the "standard" row indicators, for example in layer selection lists.
Represent a single user action.