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 <kiface_i.h>
34 #include <footprint_wizard_frame.h>
35 
36 #if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
37 #include <python_scripting.h>
38 #else
39 // Dummy functions, actually defined in python_scripting.h when KICAD_SCRIPTING is enabled
40 static void pcbnewGetWizardsBackTrace( wxString& aText ) {}
41 static void pcbnewGetScriptsSearchPaths( wxString& aText ) {}
42 static void pcbnewGetUnloadableScriptNames( wxString& aText ) {}
43 #endif
44 
46 {
50 };
51 
52 #define FPWIZARTDLIST_HEIGHT_KEY wxT( "FpWizardListHeight" )
53 #define FPWIZARTDLIST_WIDTH_KEY wxT( "FpWizardListWidth" )
54 
57 {
59  initLists();
60 
61  if( m_config )
62  {
63  wxSize size;
64  m_config->Read( FPWIZARTDLIST_WIDTH_KEY, &size.x, -1 );
65  m_config->Read( FPWIZARTDLIST_HEIGHT_KEY, &size.y, -1 );
66  SetSize( size );
67  }
68 
69  m_sdbSizerOK->SetDefault();
71 
72  Center();
73 }
74 
75 
77 {
78  if( m_config && !IsIconized() )
79  {
80  m_config->Write( FPWIZARTDLIST_WIDTH_KEY, GetSize().x );
81  m_config->Write( FPWIZARTDLIST_HEIGHT_KEY, GetSize().y );
82  }
83 }
84 
85 
87 {
88  // Current wizard selection, empty or first
89  m_footprintWizard = NULL;
90 
92 
93  if( n_wizards )
95 
96  // Choose selection mode and insert the needed rows
97 
98  m_footprintGeneratorsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
99 
100  int curr_row_cnt = m_footprintGeneratorsGrid->GetNumberRows();
101 
102  if( curr_row_cnt )
103  m_footprintGeneratorsGrid->DeleteRows( 0, curr_row_cnt );
104 
105  if( n_wizards )
106  m_footprintGeneratorsGrid->InsertRows( 0, n_wizards );
107 
108  // Put all wizards in the list
109  for( int ii = 0; ii < n_wizards; ii++ )
110  {
111  wxString num = wxString::Format( "%d", ii+1 );
113  wxString name = wizard->GetName();
114  wxString description = wizard->GetDescription();
115  wxString image = wizard->GetImage();
116 
117  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_NUMBER, num );
118  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_NAME, name );
119  m_footprintGeneratorsGrid->SetCellValue( ii, FP_GEN_ROW_DESCR, description );
120 
121  }
122 
123  m_footprintGeneratorsGrid->AutoSizeColumns();
124 
125  // Auto-expand the description column
126  int width = m_footprintGeneratorsGrid->GetClientSize().GetWidth() -
127  m_footprintGeneratorsGrid->GetRowLabelSize() -
129 
130  if ( width > m_footprintGeneratorsGrid->GetColMinimalAcceptableWidth() )
131  m_footprintGeneratorsGrid->SetColSize( FP_GEN_ROW_DESCR, width );
132 
133  // Select the first row if it exists
134  m_footprintGeneratorsGrid->ClearSelection();
135 
136  if( m_footprintGeneratorsGrid->GetNumberRows() > 0 )
137  m_footprintGeneratorsGrid->SelectRow( 0, false );
138 
139  // Display info about scripts: Search paths
140  wxString message;
141  pcbnewGetScriptsSearchPaths( message );
142  m_tcSearchPaths->SetValue( message );
143  // Display info about scripts: unloadable scripts (due to syntax errors is python source)
145 
146  if( message.IsEmpty() )
147  {
148  m_tcNotLoaded->SetValue( _( "All footprint generator scripts were loaded" ) );
149  m_buttonShowTrace->Show( false );
150  }
151  else
152  m_tcNotLoaded->SetValue( message );
153 }
154 
155 
157 {
158 #if defined(KICAD_SCRIPTING)
159  FOOTPRINT_WIZARD_FRAME* fpw_frame = static_cast<FOOTPRINT_WIZARD_FRAME*>( GetParent() );
160  fpw_frame->PythonPluginsReload();
161 
162  initLists();
163 #endif
164 }
165 
166 
168 {
169  int click_row = event.GetRow();
171  m_footprintGeneratorsGrid->SelectRow( event.GetRow(), false );
172  // Move the grid cursor to the active line, mainly for aesthetic reasons:
173  m_footprintGeneratorsGrid->GoToCell( event.GetRow(), FP_GEN_ROW_NUMBER );
174 }
175 
176 
178 {
179  EndModal( wxID_OK );
180 }
181 
182 void DIALOG_FOOTPRINT_WIZARD_LIST::onShowTrace( wxCommandEvent& event )
183 {
184  wxString trace;
186 
187  // Filter message before displaying them
188  // a trace starts by "Traceback" and is followed by 2 useless lines
189  // for our purpose
190  wxArrayString traces;
191  wxStringSplit( trace, traces, '\n' );
192 
193  // Build the filtered message (remove useless lines)
194  trace.Clear();
195 
196  for( unsigned ii = 0; ii < traces.Count(); ++ii )
197  {
198  if( traces[ii].Contains( "Traceback" ) )
199  {
200  ii += 2; // Skip this line and next lines which are related to pcbnew.py module
201 
202  if( !trace.IsEmpty() ) // Add separator for the next trace block
203  trace << "\n**********************************\n";
204  }
205  else
206  trace += traces[ii] + "\n";
207  }
208 
209  // Now display the filtered trace in our dialog
210  // (a simple wxMessageBox is really not suitable for long messages)
211  DIALOG_FOOTPRINT_WIZARD_LOG logWindow( this );
212  logWindow.m_Message->SetValue( trace );
213  logWindow.ShowModal();
214 }
215 
216 
218 {
219  return m_footprintWizard;
220 }
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: common.cpp:188
Class FOOTPRINT_WIZARD_FRAME.
FOOTPRINT_WIZARD * m_footprintWizard
The selected python script wizard.
Class DIALOG_FOOTPRINT_WIZARD_LIST_BASE.
long trace
Definition: solve.cpp:232
void OnCellFpGeneratorDoubleClick(wxGridEvent &event) override
static FOOTPRINT_WIZARD * GetWizard(const wxString &aName)
Function GetWizard.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_FOOTPRINT_WIZARD_LOG.
static void pcbnewGetScriptsSearchPaths(wxString &aText)
void OnCellFpGeneratorClick(wxGridEvent &event) override
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
static int GetWizardsCount()
Function GetWizardsCount.
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
virtual wxString GetImage()=0
Function GetImage.
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual wxString GetName()=0
Function GetName.
#define FPWIZARTDLIST_WIDTH_KEY
#define FPWIZARTDLIST_HEIGHT_KEY
static void pcbnewGetUnloadableScriptNames(wxString &aText)
Class FOOTPRINT_WIZARD This is the parent class from where any footprint wizard class must derive.