KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_wizard_properties_panel.cpp
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) 2026 Jon Evans <[email protected]>
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 along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <ranges>
22
24
25#include <footprint_wizard.h>
29#include <widgets/ui_common.h>
30
31#include <wx/stattext.h>
32
33
35 FOOTPRINT_WIZARD_FRAME* aFrame ) :
36 PROPERTIES_PANEL( aParent, aFrame ),
37 m_frame( aFrame ),
38 m_wizard( nullptr ),
39 m_unitEditorInstance( nullptr ),
40 m_checkboxEditorInstance( nullptr ),
41 m_ratioEditorInstance( nullptr )
42{
43 // AUI panel caption is enough
44 m_caption->Hide();
45
46 wxASSERT( wxPGGlobalVars );
47
48 wxString editorKey = PG_UNIT_EDITOR::BuildEditorName( m_frame );
49 auto it = wxPGGlobalVars->m_mapEditorClasses.find( editorKey );
50
51 if( it != wxPGGlobalVars->m_mapEditorClasses.end() )
52 {
53 m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( it->second );
54 m_unitEditorInstance->UpdateFrame( m_frame );
55 }
56 else
57 {
58 PG_UNIT_EDITOR* new_editor = new PG_UNIT_EDITOR( m_frame );
59 m_unitEditorInstance = static_cast<PG_UNIT_EDITOR*>( wxPropertyGrid::RegisterEditorClass( new_editor ) );
60 }
61
62 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_CHECKBOX_EDITOR::EDITOR_NAME );
63
64 if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
65 {
66 PG_CHECKBOX_EDITOR* cbEditor = new PG_CHECKBOX_EDITOR();
67 m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( wxPropertyGrid::RegisterEditorClass( cbEditor ) );
68 }
69 else
70 {
71 m_checkboxEditorInstance = static_cast<PG_CHECKBOX_EDITOR*>( it->second );
72 }
73
74 it = wxPGGlobalVars->m_mapEditorClasses.find( PG_RATIO_EDITOR::EDITOR_NAME );
75
76 if( it == wxPGGlobalVars->m_mapEditorClasses.end() )
77 {
78 PG_RATIO_EDITOR* ratioEditor = new PG_RATIO_EDITOR();
79 m_ratioEditorInstance = static_cast<PG_RATIO_EDITOR*>( wxPropertyGrid::RegisterEditorClass( ratioEditor ) );
80 }
81 else
82 {
83 m_ratioEditorInstance = static_cast<PG_RATIO_EDITOR*>( it->second );
84 }
85}
86
87
93
94
98
99
101{
102 SUPPRESS_GRID_CHANGED_EVENTS raii( this );
103
104 if( m_grid->IsEditorFocused() )
105 m_grid->CommitChangesFromEditor();
106
107 m_grid->Clear();
108
109 if( !aWizard )
110 return;
111
112 std::map<kiapi::common::types::WizardParameterCategory, std::vector<WIZARD_PARAMETER*>> params;
113
114 for( const std::unique_ptr<WIZARD_PARAMETER>& param : aWizard->Info().parameters )
115 params[param->category].emplace_back( param.get() );
116
117 for( kiapi::common::types::WizardParameterCategory category : params | std::views::keys )
118 {
119 auto groupItem = new wxPropertyCategory( WIZARD_PARAMETER::ParameterCategoryName( category ) );
120 m_grid->Append( groupItem );
121
122 for( WIZARD_PARAMETER* param : params[category] )
123 {
124 if( wxPGProperty* prop = createPGProperty( param ) )
125 m_grid->Append( prop );
126 }
127 }
128
130}
131
132
134{
135 wxPGProperty* ret = nullptr;
136
137 switch( aParam->type )
138 {
139 case kiapi::common::types::WPDT_DISTANCE:
140 ret = new PGPROPERTY_SIZE( m_frame );
141 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( m_frame ) );
142 break;
143
144 case kiapi::common::types::WPDT_AREA:
145 ret = new PGPROPERTY_AREA( m_frame );
146 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( m_frame ) );
147 break;
148
149 case kiapi::common::types::WPDT_VOLUME:
150 wxASSERT_MSG( false, "Volume properties are not currently implemented" );
151 break;
152
153 case kiapi::common::types::WPDT_TIME:
154 ret = new wxFloatProperty();
155 break;
156
157 case kiapi::common::types::WPDT_ANGLE:
158 ret = new PGPROPERTY_ANGLE();;
159 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( m_frame ) );
160 break;
161
162 case kiapi::common::types::WPDT_STRING:
163 ret = new PGPROPERTY_STRING();
164 break;
165
166 case kiapi::common::types::WPDT_INTEGER:
167 ret = new wxIntProperty();
168 break;
169
170 case kiapi::common::types::WPDT_REAL:
171 ret = new wxFloatProperty();
172 break;
173
174 case kiapi::common::types::WPDT_BOOL:
175 ret = new PGPROPERTY_BOOL();
176 break;
177
178 // TODO(JE) consider supporting enum properties
179
180 case kiapi::common::types::WPDT_UNKNOWN:
181 default:
182 break;
183 }
184
185 if( ret )
186 {
187 ret->SetLabel( wxGetTranslation( aParam->name ) );
188 ret->SetName( aParam->identifier );
189 ret->SetHelpString( wxGetTranslation( aParam->description ) );
190 ret->SetClientData( aParam );
191
192 if( auto ip = dynamic_cast<const WIZARD_INT_PARAMETER*>( aParam ) )
193 ret->SetValue( ip->value );
194 else if( auto rp = dynamic_cast<const WIZARD_REAL_PARAMETER*>( aParam ) )
195 ret->SetValue( rp->value );
196 else if( auto bp = dynamic_cast<const WIZARD_BOOL_PARAMETER*>( aParam ) )
197 ret->SetValue( bp->value );
198 else if( auto sp = dynamic_cast<const WIZARD_STRING_PARAMETER*>( aParam ) )
199 ret->SetValue( sp->value );
200 }
201
202 return ret;
203}
204
205
207{
208 return static_cast<WIZARD_PARAMETER*>( aEvent.GetProperty()->GetClientData() );
209}
210
211
212void FOOTPRINT_WIZARD_PROPERTIES_PANEL::valueChanged( wxPropertyGridEvent& aEvent )
213{
214 WIZARD_PARAMETER* param = getParamFromEvent( aEvent );
215 wxCHECK( param, /* void */ );
216
217 wxAny newValue = aEvent.GetPropertyValue();
218
219 if( WIZARD_INT_PARAMETER* ip = dynamic_cast<WIZARD_INT_PARAMETER*>( param ) )
220 {
221 ip->value = newValue.As<int>();
222 }
223 else if( WIZARD_REAL_PARAMETER* rp = dynamic_cast<WIZARD_REAL_PARAMETER*>( param ) )
224 {
225 rp->value = newValue.As<double>();
226 }
227 else if( WIZARD_BOOL_PARAMETER* bp = dynamic_cast<WIZARD_BOOL_PARAMETER*>( param ) )
228 {
229 bp->value = newValue.As<bool>();
230 }
231 else if( WIZARD_STRING_PARAMETER* sp = dynamic_cast<WIZARD_STRING_PARAMETER*>( param ) )
232 {
233 sp->value = newValue.As<wxString>();
234 }
235
236 m_frame->OnWizardParametersChanged();
237}
FOOTPRINT_WIZARD_PROPERTIES_PANEL(wxWindow *aParent, FOOTPRINT_WIZARD_FRAME *aFrame)
void valueChanged(wxPropertyGridEvent &aEvent) override
wxPGProperty * createPGProperty(const PROPERTY_BASE *aProperty) const override
static WIZARD_PARAMETER * getParamFromEvent(const wxPropertyGridEvent &aEvent)
WIZARD_INFO & Info()
A wxEnumProperty that displays a color next to the enum value.
static const wxString EDITOR_NAME
Definition pg_editors.h:75
static const wxString EDITOR_NAME
Definition pg_editors.h:117
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
PROPERTIES_PANEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame)
wxPropertyGrid * m_grid
wxStaticText * m_caption
kiapi::common::types::WizardParameterDataType type
static wxString ParameterCategoryName(kiapi::common::types::WizardParameterCategory aCategory)
APIIMPORT wxPGGlobalVarsClass * wxPGGlobalVars
std::vector< std::unique_ptr< WIZARD_PARAMETER > > parameters
Functions to provide common constants and other functions to assist in making a consistent UI.