KiCad PCB EDA Suite
dialog_footprint_wizard_list.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-2014 Miguel Angel Ajo <miguelangel@nbee.es>
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU 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, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #include <wx/grid.h>
30 
31 #include <pcbnew_settings.h>
32 #include <pgm_base.h>
34 #include <kicad_string.h>
35 #include <kiface_i.h>
37 #include <footprint_wizard_frame.h>
38 
40 
41 
43 {
47 };
48 
49 
52 {
53  initLists();
54 
55  auto cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
56 
57  wxSize size;
58  size.x = cfg->m_FootprintWizardList.width;
59  size.y = cfg->m_FootprintWizardList.height;
60  SetSize( size );
61 
62  m_sdbSizerOK->SetDefault();
64 
65  Center();
66 }
67 
68 
70 {
71  if( !IsIconized() )
72  {
73  auto cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
74 
75  cfg->m_FootprintWizardList.width = GetSize().x;
76  cfg->m_FootprintWizardList.height = GetSize().y;
77  }
78 }
79 
80 
82 {
83  // Current wizard selection, empty or first
85 
87 
88  if( n_wizards )
90 
91  // Choose selection mode and insert the needed rows
92 
93  m_footprintGeneratorsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
94 
95  int curr_row_cnt = m_footprintGeneratorsGrid->GetNumberRows();
96 
97  if( curr_row_cnt )
98  m_footprintGeneratorsGrid->DeleteRows( 0, curr_row_cnt );
99 
100  if( n_wizards )
101  m_footprintGeneratorsGrid->InsertRows( 0, n_wizards );
102 
103  // Put all wizards in the list
104  for( int ii = 0; ii < n_wizards; ii++ )
105  {
106  wxString num = wxString::Format( "%d", ii+1 );
108  wxString name = wizard->GetName();
109  wxString description = wizard->GetDescription();
110  wxString image = wizard->GetImage();
111 
112  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_NUMBER, num );
113  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_NAME, name );
114  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_DESCR, description );
115 
116  }
117 
118  m_footprintGeneratorsGrid->AutoSizeColumns();
119 
120  // Auto-expand the description column
121  int width = m_footprintGeneratorsGrid->GetClientSize().GetWidth() -
122  m_footprintGeneratorsGrid->GetRowLabelSize() -
124 
125  if ( width > m_footprintGeneratorsGrid->GetColMinimalAcceptableWidth() )
126  m_footprintGeneratorsGrid->SetColSize( FP_GEN_ROW_DESCR, width );
127 
128  // Select the first row if it exists
129  m_footprintGeneratorsGrid->ClearSelection();
130 
131  if( m_footprintGeneratorsGrid->GetNumberRows() > 0 )
132  m_footprintGeneratorsGrid->SelectRow( 0, false );
133 
134  // Display info about scripts: Search paths
135  wxString message;
136  pcbnewGetScriptsSearchPaths( message );
137  m_tcSearchPaths->SetValue( message );
138 
139  // Display info about scripts: unloadable scripts (due to syntax errors is python source).
141 
142  if( message.IsEmpty() )
143  {
144  m_tcNotLoaded->SetValue( _( "All footprint generator scripts were loaded" ) );
145  m_buttonShowTrace->Show( false );
146  }
147  else
148  m_tcNotLoaded->SetValue( message );
149 }
150 
151 
153 {
154  FOOTPRINT_WIZARD_FRAME* fpw_frame = static_cast<FOOTPRINT_WIZARD_FRAME*>( GetParent() );
155  fpw_frame->PythonPluginsReload();
156 
157  initLists();
158 }
159 
160 
162 {
163  int click_row = event.GetRow();
165  m_footprintGeneratorsGrid->SelectRow( event.GetRow(), false );
166 
167  // Move the grid cursor to the active line, mainly for aesthetic reasons:
168  m_footprintGeneratorsGrid->GoToCell( event.GetRow(), FP_GEN_ROW_NUMBER );
169 }
170 
171 
173 {
174  wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
175 }
176 
177 
178 void DIALOG_FOOTPRINT_WIZARD_LIST::onShowTrace( wxCommandEvent& event )
179 {
180  wxString trace;
181  pcbnewGetWizardsBackTrace( trace );
182 
183  // Now display the filtered trace in our dialog
184  // (a simple wxMessageBox is really not suitable for long messages)
185  DIALOG_FOOTPRINT_WIZARD_LOG logWindow( this );
186  logWindow.m_Message->SetValue( trace );
187  logWindow.ShowModal();
188 }
189 
190 
192 {
193  return m_footprintWizard;
194 }
FOOTPRINT_WIZARD * m_footprintWizard
The selected python script wizard.
Class DIALOG_FOOTPRINT_WIZARD_LIST_BASE.
void pcbnewGetUnloadableScriptNames(wxString &aNames)
Collect the list of python scripts which could not be loaded.
void OnCellFpGeneratorDoubleClick(wxGridEvent &event) override
static FOOTPRINT_WIZARD * GetWizard(const wxString &aName)
Class DIALOG_FOOTPRINT_WIZARD_LOG.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
void OnCellFpGeneratorClick(wxGridEvent &event) override
DIALOG_FOOTPRINT_WIZARD_LIST m_FootprintWizardList
void pcbnewGetWizardsBackTrace(wxString &aTrace)
Return the backtrace of errors (if any) when wizard python scripts are loaded.
#define NULL
virtual wxString GetDescription()=0
void onUpdatePythonModulesClick(wxCommandEvent &event) override
#define _(s)
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any.
void onShowTrace(wxCommandEvent &event) override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
virtual wxString GetImage()=0
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
see class PGM_BASE
const char * name
Definition: DXF_plotter.cpp:59
virtual wxString GetName()=0
void pcbnewGetScriptsSearchPaths(wxString &aNames)
Collect the list of paths where python scripts are searched.
The parent class from where any footprint wizard class must derive.