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-2017 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.h>
32 #include <pcbnew_settings.h>
33 #include <pgm_base.h>
35 #include <kicad_string.h>
36 #include <kiface_i.h>
38 #include <footprint_wizard_frame.h>
39 
40 #if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
41 #include <python_scripting.h>
42 #else
43 // Dummy functions, actually defined in python_scripting.h when KICAD_SCRIPTING is enabled
44 static void pcbnewGetWizardsBackTrace( wxString& aText ) {}
45 static void pcbnewGetScriptsSearchPaths( wxString& aText ) {}
46 static void pcbnewGetUnloadableScriptNames( wxString& aText ) {}
47 #endif
48 
50 {
54 };
55 
56 
59 {
60  initLists();
61 
62  auto cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
63 
64  wxSize size;
65  size.x = cfg->m_FootprintWizardList.width;
66  size.y = cfg->m_FootprintWizardList.height;
67  SetSize( size );
68 
69  m_sdbSizerOK->SetDefault();
71 
72  Center();
73 }
74 
75 
77 {
78  if( !IsIconized() )
79  {
80  auto cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
81 
82  cfg->m_FootprintWizardList.width = GetSize().x;
83  cfg->m_FootprintWizardList.height = GetSize().y;
84  }
85 }
86 
87 
89 {
90  // Current wizard selection, empty or first
92 
94 
95  if( n_wizards )
97 
98  // Choose selection mode and insert the needed rows
99 
100  m_footprintGeneratorsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
101 
102  int curr_row_cnt = m_footprintGeneratorsGrid->GetNumberRows();
103 
104  if( curr_row_cnt )
105  m_footprintGeneratorsGrid->DeleteRows( 0, curr_row_cnt );
106 
107  if( n_wizards )
108  m_footprintGeneratorsGrid->InsertRows( 0, n_wizards );
109 
110  // Put all wizards in the list
111  for( int ii = 0; ii < n_wizards; ii++ )
112  {
113  wxString num = wxString::Format( "%d", ii+1 );
115  wxString name = wizard->GetName();
116  wxString description = wizard->GetDescription();
117  wxString image = wizard->GetImage();
118 
119  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_NUMBER, num );
120  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_NAME, name );
121  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_DESCR, description );
122 
123  }
124 
125  m_footprintGeneratorsGrid->AutoSizeColumns();
126 
127  // Auto-expand the description column
128  int width = m_footprintGeneratorsGrid->GetClientSize().GetWidth() -
129  m_footprintGeneratorsGrid->GetRowLabelSize() -
131 
132  if ( width > m_footprintGeneratorsGrid->GetColMinimalAcceptableWidth() )
133  m_footprintGeneratorsGrid->SetColSize( FP_GEN_ROW_DESCR, width );
134 
135  // Select the first row if it exists
136  m_footprintGeneratorsGrid->ClearSelection();
137 
138  if( m_footprintGeneratorsGrid->GetNumberRows() > 0 )
139  m_footprintGeneratorsGrid->SelectRow( 0, false );
140 
141  // Display info about scripts: Search paths
142  wxString message;
143  pcbnewGetScriptsSearchPaths( message );
144  m_tcSearchPaths->SetValue( message );
145  // Display info about scripts: unloadable scripts (due to syntax errors is python source)
147 
148  if( message.IsEmpty() )
149  {
150  m_tcNotLoaded->SetValue( _( "All footprint generator scripts were loaded" ) );
151  m_buttonShowTrace->Show( false );
152  }
153  else
154  m_tcNotLoaded->SetValue( message );
155 }
156 
157 
159 {
160 #if defined(KICAD_SCRIPTING)
161  FOOTPRINT_WIZARD_FRAME* fpw_frame = static_cast<FOOTPRINT_WIZARD_FRAME*>( GetParent() );
162  fpw_frame->PythonPluginsReload();
163 
164  initLists();
165 #endif
166 }
167 
168 
170 {
171  int click_row = event.GetRow();
173  m_footprintGeneratorsGrid->SelectRow( event.GetRow(), false );
174  // Move the grid cursor to the active line, mainly for aesthetic reasons:
175  m_footprintGeneratorsGrid->GoToCell( event.GetRow(), FP_GEN_ROW_NUMBER );
176 }
177 
178 
180 {
181  EndModal( wxID_OK );
182 }
183 
184 void DIALOG_FOOTPRINT_WIZARD_LIST::onShowTrace( wxCommandEvent& event )
185 {
186  wxString trace;
187  pcbnewGetWizardsBackTrace( trace );
188 
189  // Now display the filtered trace in our dialog
190  // (a simple wxMessageBox is really not suitable for long messages)
191  DIALOG_FOOTPRINT_WIZARD_LOG logWindow( this );
192  logWindow.m_Message->SetValue( trace );
193  logWindow.ShowModal();
194 }
195 
196 
198 {
199  return m_footprintWizard;
200 }
FOOTPRINT_WIZARD_FRAME.
FOOTPRINT_WIZARD * m_footprintWizard
The selected python script wizard.
Class DIALOG_FOOTPRINT_WIZARD_LIST_BASE.
void OnCellFpGeneratorDoubleClick(wxGridEvent &event) override
static FOOTPRINT_WIZARD * GetWizard(const wxString &aName)
Function GetWizard.
Class DIALOG_FOOTPRINT_WIZARD_LOG.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
static void pcbnewGetScriptsSearchPaths(wxString &aText)
void OnCellFpGeneratorClick(wxGridEvent &event) override
DIALOG_FOOTPRINT_WIZARD_LIST m_FootprintWizardList
static int GetWizardsCount()
Function GetWizardsCount.
#define NULL
virtual wxString GetDescription()=0
Function GetDescription.
void onUpdatePythonModulesClick(wxCommandEvent &event) override
static void pcbnewGetWizardsBackTrace(wxString &aText)
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any Do n...
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
Function GetImage.
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
#define _(s)
Definition: 3d_actions.cpp:33
virtual wxString GetName()=0
Function GetName.
static void pcbnewGetUnloadableScriptNames(wxString &aText)
FOOTPRINT_WIZARD This is the parent class from where any footprint wizard class must derive.