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#include <wx/intl.h>
33
34
35class BITMAP_TOGGLE;
36class COLOR_SWATCH;
40
41using KIGFX::COLOR4D;
42
43
45{
46public:
47
52 {
53 public:
54 int m_Id;
57
60
61 APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const wxString& aTooltip ) :
62 m_Id( aId ),
63 m_Visible( true ),
64 m_Spacer( false ),
65 m_Ctl_visibility( nullptr ),
66 m_Ctl_color( nullptr ),
67 m_tooltip( aTooltip ),
68 m_label( aLabel )
69 {
70 }
71
72 APPEARANCE_SETTING_3D( const wxString& aLabel, int aId, const TOOL_ACTION& aAction ) :
73 m_Id( aId ),
74 m_Visible( true ),
75 m_Spacer( false ),
76 m_Ctl_visibility( nullptr ),
77 m_Ctl_color( nullptr ),
78 m_label( aLabel ),
79 m_action( &aAction )
80 {
81 }
82
84 m_Id( -1 ),
85 m_Visible( false ),
86 m_Spacer( true ),
87 m_Ctl_visibility( nullptr ),
88 m_Ctl_color( nullptr )
89 {
90 }
91
92 wxString GetTooltip() const
93 {
94 if( m_tooltip.has_value() )
95 return wxGetTranslation( m_tooltip.value() );
96 else if( m_action.has_value() )
97 return m_action.value()->GetTooltip( true );
98 else
99 return wxEmptyString;
100 }
101
102 wxString GetLabel() const
103 {
104 return wxGetTranslation( m_label );
105 }
106
107 private:
108 wxString m_label;
109
110 std::optional<wxString> m_tooltip;
111 std::optional<const TOOL_ACTION*> m_action;
112 };
113
114 APPEARANCE_CONTROLS_3D( EDA_3D_VIEWER_FRAME* aParent, wxWindow* aFocusOwner );
116
117 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
118 // will only land us in trouble.
121
122 wxSize GetBestSize() const;
123 void OnDarkModeToggle();
124 void OnLayerVisibilityChanged( int aLayer, bool isVisible );
125
127
128 void UpdateLayerCtls();
129
130 void ApplyLayerPreset( const wxString& aPresetName );
131
132 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
133
135 std::vector<VIEWPORT3D> GetUserViewports() const;
136
138 void SetUserViewports( std::vector<VIEWPORT3D>& aPresetList );
139
140 void ApplyViewport( const wxString& aPresetName );
141
142 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
143
144protected:
145 void OnSetFocus( wxFocusEvent& aEvent ) override;
146 void OnSize( wxSizeEvent& aEvent ) override;
147
148 void OnLayerContextMenu( wxContextMenuEvent& aEvent );
149 void OnLanguageChanged( wxCommandEvent& aEvent );
150
151private:
152 void rebuildControls();
153
154 void rebuildLayers();
155
156 void rebuildLayerPresetsWidget( bool aReset );
157
159
161
162 void onColorSwatchChanged( COLOR_SWATCH* aSwatch );
163
164 void updateLayerPresetWidget( const wxString& aName );
165
166 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
167
168 void doApplyLayerPreset( const wxString& aPresetName );
169
170 void onViewportChanged( wxCommandEvent& aEvent ) override;
171 void onUpdateViewportsCb( wxUpdateUIEvent& aEvent ) override;
172
173 void doApplyViewport( const VIEWPORT3D& aViewport );
174
175 void passOnFocus();
176
177private:
178 static const APPEARANCE_SETTING_3D s_layerSettings[];
179
181 wxWindow* m_focusOwner;
182
183 std::vector<std::unique_ptr<APPEARANCE_SETTING_3D>> m_layerSettings;
184 std::map<int, APPEARANCE_SETTING_3D*> m_layerSettingsMap;
185
186 wxArrayString m_presetMRU;
187
188 std::map<wxString, VIEWPORT3D> m_viewports;
190 wxArrayString m_viewportMRU;
191
193 wxBoxSizer* m_envOuterSizer;
199};
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 ApplyViewport(const wxString &aPresetName)
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 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 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.