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