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 The 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
40/* Displays the name of the current opened library in the caption */
42{
43 wxString msg;
44
45 msg = _( "Footprint Wizard" );
46 msg << wxT( " [" );
47
48 if( !m_wizardName.IsEmpty() )
49 msg << m_wizardName;
50 else
51 msg += _( "no wizard selected" );
52
53 msg << wxT( "]" );
54
55 SetTitle( msg );
56}
57
58
60{
61 FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
62
63 if( !footprintWizard )
64 return;
65
67
68 // Delete the current footprint
70
71 // Creates the footprint
72 wxString msg;
73 FOOTPRINT* footprint = footprintWizard->GetFootprint( &msg );
75
76 if( footprint )
77 {
78 // Add the object to board
79 GetBoard()->Add( footprint, ADD_MODE::APPEND );
80 footprint->SetPosition( VECTOR2I( 0, 0 ) );
81 }
82
83 updateView();
84 GetCanvas()->Refresh();
85}
86
87
89{
90 m_buildMessageBox->SetValue( aMessage );
91}
92
93
95{
96 if( m_wizardName.Length() == 0 )
97 return nullptr;
98
100
101 if( !footprintWizard )
102 {
103 wxMessageBox( _( "Couldn't reload footprint wizard" ) );
104 return nullptr;
105 }
106
107 return footprintWizard;
108}
109
110
112{
114
115 if( footprintWizard && m_modal_ret_val )
116 {
117 wxString msg;
118 FOOTPRINT* footprint = footprintWizard->GetFootprint( &msg );
119 DisplayBuildMessage( msg );
120
121 return footprint;
122 }
123
124 return nullptr;
125}
126
127
129{
130 DIALOG_FOOTPRINT_WIZARD_LIST wizardSelector( this );
131
132 if( wizardSelector.ShowModal() != wxID_OK )
133 return;
134
135 FOOTPRINT_WIZARD* footprintWizard = wizardSelector.GetWizard();
136
137 if( footprintWizard )
138 {
139 m_wizardName = footprintWizard->GetName();
140 m_wizardDescription = footprintWizard->GetDescription();
141
142 footprintWizard->ResetParameters();
143 }
144 else
145 {
146 m_wizardName.Empty();
147 m_wizardDescription.Empty();
148 }
149
151 Zoom_Automatique( false );
155}
156
157
159{
161 updateView();
162}
163
165{
166 FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
167
168 if ( footprintWizard == nullptr )
169 return;
170
171 footprintWizard->ResetParameters();
172
173 // Reload
177}
178
179
181{
182 int page = m_pageList->GetSelection() - 1;
183
184 if( page < 0 )
185 page = 0;
186
187 m_pageList->SetSelection( page, true );
188
189 wxCommandEvent event;
190 ClickOnPageList( event );
191}
192
194{
195 int page = m_pageList->GetSelection() + 1;
196
197 if( (int)m_pageList->GetCount() <= page )
198 page = m_pageList->GetCount() - 1;
199
200 m_pageList->SetSelection( page, true );
201
202 wxCommandEvent event;
203 ClickOnPageList( event );
204}
205
206
207// This is a flag to avoid reentering of ParametersUpdated
208// that can happen in some cases
209static bool lock_update_prms = false;
210
211
213{
214 FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
215
216 if( !footprintWizard )
217 return;
218
219 if( m_parameterGridPage < 0 )
220 return;
221
222 if( lock_update_prms )
223 return;
224
225 wxArrayString prmValues = footprintWizard->GetParameterValues( m_parameterGridPage );
226 wxArrayString ptList = footprintWizard->GetParameterTypes( m_parameterGridPage );
227
228 bool has_changed = false;
229 int count = m_parameterGrid->GetNumberRows();
230
231 for( int prm_id = 0; prm_id < count; ++prm_id )
232 {
233 wxString value = m_parameterGrid->GetCellValue( prm_id, WIZ_COL_VALUE );
234
235 if( prmValues[prm_id] != value )
236 {
237 has_changed = true;
238 prmValues[prm_id] = value;
239 }
240 }
241
242 if( has_changed )
243 {
244 wxString res = footprintWizard->SetParameterValues( m_parameterGridPage, prmValues );
245
246 if( !res.IsEmpty() )
247 wxMessageBox( res );
248
251
252 // The python script can have modified some other parameters.
253 // So rebuild the current parameter list with new values, just in case.
254 //
255 // On wxWidgets 3.0.5, ReCreateParameterList() generates a EVT_GRID_CMD_CELL_CHANGED
256 // that call ParametersUpdated() and creating an infinite loop
257 // Note also it happens **only for languages using a comma** instead of a point
258 // for floating point separator
259 // It does not happen on wxWidgets 3.1.4
260 //
261 // So lock the next call.
262 lock_update_prms = true;
264 }
265
266 // unlock ParametersUpdated() now the update is finished
267 lock_update_prms = false;
268}
269
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:1060
void DeleteAllFootprints()
Remove all footprints from the deque and free the memory associated with them.
Definition: board.cpp:1474
int ShowModal() override
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 SelectCurrentWizard(wxCommandEvent &aDummy)
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 SelectFootprintWizard()
Show the list of footprint wizards available into the system.
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:2457
bool m_modal_ret_val
Definition: kiway_player.h:196
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:171
@ 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
VECTOR3I res
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695
Definition of file extensions used in Kicad.