KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_wizard_frame_functions.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) 2012 Miguel Angel Ajo Pelayo, [email protected]
5 * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
6 * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <pcb_edit_frame.h>
27#include <board.h>
28#include <footprint.h>
29#include <pcbnew_id.h>
32#include <base_units.h>
33#include <widgets/wx_grid.h>
34#include <wx/listbox.h>
35#include <wx/msgdlg.h>
36#include <tool/tool_manager.h>
38
39
41{
42 wxString msg;
43 int page;
44
45 switch( event.GetId() )
46 {
48 page = m_pageList->GetSelection() + 1;
49
50 if( (int)m_pageList->GetCount() <= page )
51 page = m_pageList->GetCount() - 1;
52
53 m_pageList->SetSelection( page, true );
54 ClickOnPageList( event );
55 break;
56
58 page = m_pageList->GetSelection() - 1;
59
60 if( page < 0 )
61 page = 0;
62
63 m_pageList->SetSelection( page, true );
64 ClickOnPageList( event );
65 break;
66
67 default:
68 wxFAIL_MSG( wxString::Format( wxT( "FOOTPRINT_WIZARD_FRAME::Process_Special_Functions "
69 "error: id = %d" ),
70 event.GetId() ) );
71 break;
72 }
73}
74
75
76/* Displays the name of the current opened library in the caption */
78{
79 wxString msg;
80
81 msg = _( "Footprint Wizard" );
82 msg << wxT( " [" );
83
84 if( !m_wizardName.IsEmpty() )
85 msg << m_wizardName;
86 else
87 msg += _( "no wizard selected" );
88
89 msg << wxT( "]" );
90
91 SetTitle( msg );
92}
93
94
96{
97 FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
98
99 if( !footprintWizard )
100 return;
101
103
104 // Delete the current footprint
106
107 // Creates the footprint
108 wxString msg;
109 FOOTPRINT* footprint = footprintWizard->GetFootprint( &msg );
110 DisplayBuildMessage( msg );
111
112 if( footprint )
113 {
114 // Add the object to board
115 GetBoard()->Add( footprint, ADD_MODE::APPEND );
116 footprint->SetPosition( VECTOR2I( 0, 0 ) );
117 }
118
119 updateView();
120 GetCanvas()->Refresh();
121}
122
123
125{
126 m_buildMessageBox->SetValue( aMessage );
127}
128
129
131{
132 if( m_wizardName.Length() == 0 )
133 return nullptr;
134
136
137 if( !footprintWizard )
138 {
139 wxMessageBox( _( "Couldn't reload footprint wizard" ) );
140 return nullptr;
141 }
142
143 return footprintWizard;
144}
145
146
148{
150
151 if( footprintWizard && m_modal_ret_val )
152 {
153 wxString msg;
154 FOOTPRINT* footprint = footprintWizard->GetFootprint( &msg );
155 DisplayBuildMessage( msg );
156
157 return footprint;
158 }
159
160 return nullptr;
161}
162
163
165{
166 DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
167
168 if( wizardSelector.ShowModal() != wxID_OK )
169 return;
170
171 FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
172
173 if( footprintWizard )
174 {
175 m_wizardName = footprintWizard->GetName();
176 m_wizardDescription = footprintWizard->GetDescription();
177
178 footprintWizard->ResetParameters();
179 }
180 else
181 {
182 m_wizardName.Empty();
183 m_wizardDescription.Empty();
184 }
185
187 Zoom_Automatique( false );
191}
192
193
195{
197 updateView();
198}
199
200void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event )
201{
202 FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
203
204 if ( footprintWizard == nullptr )
205 return;
206
207 footprintWizard->ResetParameters();
208
209 // Reload
213}
214
215
216// This is a flag to avoid reentering of ParametersUpdated
217// that can happen in some cases
218static bool lock_update_prms = false;
219
220
222{
223 FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
224
225 if( !footprintWizard )
226 return;
227
228 if( m_parameterGridPage < 0 )
229 return;
230
231 if( lock_update_prms )
232 return;
233
234 wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
235 wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
236
237 bool has_changed = false;
238 int count = m_parameterGrid->GetNumberRows();
239
240 for( int prm_id = 0; prm_id < count; ++prm_id )
241 {
242 wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
243
244 if( prmValues[prm_id] != value )
245 {
246 has_changed = true;
247 prmValues[prm_id] = value;
248 }
249 }
250
251 if( has_changed )
252 {
253 wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
254
255 if( !res.IsEmpty() )
256 wxMessageBox( res );
257
260
261 // The python script can have modified some other parameters.
262 // So rebuild the current parameter list with new values, just in case.
263 //
264 // On wxWidgets 3.0.5, ReCreateParameterList() generates a EVT_GRID_CMD_CELL_CHANGED
265 // that call ParametersUpdated() and creating an infinite loop
266 // Note also it happens **only for languages using a comma** instead of a point
267 // for floating point separator
268 // It does not happen on wxWidgets 3.1.4
269 //
270 // So lock the next call.
271 lock_update_prms = true;
273 }
274
275 // unlock ParametersUpdated() now the update is finished
276 lock_update_prms = false;
277}
278
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:882
void DeleteAllFootprints()
Remove all footprints from the deque and free the memory associated with them.
Definition: board.cpp:1277
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
void ParametersUpdated(wxGridEvent &event)
Update the footprint python parameters values from the values in grid.
int m_parameterGridPage
the page currently displayed by m_parameterGrid it is most of time the m_pageList selection,...
wxListBox * m_pageList
The list of pages.
void ReCreateParameterList()
Create the list of parameters for the current page.
void DisplayWizardInfos()
Show all the details about the current wizard.
wxString m_wizardName
name of the current wizard
void updateView()
Rebuild the GAL view (reint tool manager, colors and drawings) must be run after any footprint change...
void ClickOnPageList(wxCommandEvent &event)
WX_GRID * m_parameterGrid
The list of parameters.
void DisplayBuildMessage(wxString &aMessage)
Display the message generated by the python build footprint script.
FOOTPRINT_WIZARD * GetMyWizard()
Reloads the wizard by name.
wxString m_wizardDescription
description of the wizard
void ReCreatePageList()
Create or recreate the list of parameter pages for the current wizard.
void RegenerateFootprint()
Regenerate the current footprint.
void Process_Special_Functions(wxCommandEvent &event)
void SelectFootprintWizard()
Show the list of footprint wizards available into the system.
void DefaultParameters(wxCommandEvent &event)
void SelectCurrentWizard(wxCommandEvent &event)
static FOOTPRINT_WIZARD * GetWizard(const wxString &aName)
The parent class from where any footprint wizard class must derive.
virtual wxString SetParameterValues(int aPage, wxArrayString &aValues)=0
virtual void ResetParameters()=0
Reset all wizard parameters to default values.
virtual wxArrayString GetParameterValues(int aPage)=0
virtual wxString GetName()=0
virtual wxArrayString GetParameterTypes(int aPage)=0
virtual wxString GetDescription()=0
virtual FOOTPRINT * GetFootprint(wxString *aMessage)=0
Build the footprint itself and returns it to the caller function.
void SetPosition(const VECTOR2I &aPos) override
Definition: footprint.cpp:2297
bool m_modal_ret_val
Definition: kiway_player.h:198
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:167
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
#define _(s)
@ WIZ_COL_VALUE
static bool lock_update_prms
@ ID_FOOTPRINT_WIZARD_PREVIOUS
Definition: pcbnew_id.h:109
@ ID_FOOTPRINT_WIZARD_NEXT
Definition: pcbnew_id.h:108
VECTOR3I res
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
Definition of file extensions used in Kicad.