KiCad PCB EDA Suite
PYTHON_FOOTPRINT_WIZARD Class Reference

#include <pcbnew_footprint_wizards.h>

Inheritance diagram for PYTHON_FOOTPRINT_WIZARD:
FOOTPRINT_WIZARD

Public Member Functions

 PYTHON_FOOTPRINT_WIZARD (PyObject *wizard)
 
 ~PYTHON_FOOTPRINT_WIZARD ()
 
wxString GetName () override
 
wxString GetImage () override
 
wxString GetDescription () override
 
int GetNumParameterPages () override
 
wxString GetParameterPageName (int aPage) override
 
wxArrayString GetParameterNames (int aPage) override
 
wxArrayString GetParameterTypes (int aPage) override
 
wxArrayString GetParameterValues (int aPage) override
 
wxArrayString GetParameterErrors (int aPage) override
 
wxString SetParameterValues (int aPage, wxArrayString &aValues) override
 
FOOTPRINTGetFootprint (wxString *aMessages) override
 Build the footprint itself and returns it to the caller function. More...
 
void * GetObject () override
 Get the object from where this wizard constructs. More...
 
wxArrayString GetParameterHints (int aPage) override
 
wxArrayString GetParameterDesignators (int aPage=0) override
 
void ResetParameters () override
 Reset all wizard parameters to default values. More...
 
void register_wizard ()
 The standard method of a "FOOTPRINT_WIZARD" to register itself into the FOOTPRINT_WIZARD_LIST singleton manager. More...
 

Private Member Functions

PyObject * CallMethod (const char *aMethod, PyObject *aArglist=nullptr)
 
wxString CallRetStrMethod (const char *aMethod, PyObject *aArglist=nullptr)
 
wxArrayString CallRetArrayStrMethod (const char *aMethod, PyObject *aArglist=nullptr)
 

Private Attributes

PyObject * m_PyWizard
 

Detailed Description

Definition at line 41 of file pcbnew_footprint_wizards.h.

Constructor & Destructor Documentation

◆ PYTHON_FOOTPRINT_WIZARD()

PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD ( PyObject *  wizard)

Definition at line 37 of file pcbnew_footprint_wizards.cpp.

38{
39 PyLOCK lock;
40
41 m_PyWizard = aWizard;
42 Py_XINCREF( aWizard );
43}

References m_PyWizard.

◆ ~PYTHON_FOOTPRINT_WIZARD()

PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD ( )

Definition at line 46 of file pcbnew_footprint_wizards.cpp.

47{
48 PyLOCK lock;
49
50 Py_XDECREF( m_PyWizard );
51}

References m_PyWizard.

Member Function Documentation

◆ CallMethod()

PyObject * PYTHON_FOOTPRINT_WIZARD::CallMethod ( const char *  aMethod,
PyObject *  aArglist = nullptr 
)
private

Definition at line 54 of file pcbnew_footprint_wizards.cpp.

55{
56 PyLOCK lock;
57
58 PyErr_Clear();
59 // pFunc is a new reference to the desired method
60 PyObject* pFunc = PyObject_GetAttrString( m_PyWizard, aMethod );
61
62 if( pFunc && PyCallable_Check( pFunc ) )
63 {
64 PyObject* result = PyObject_CallObject( pFunc, aArglist );
65
66 if( PyErr_Occurred() )
67 {
68#if 1 // defined(DEBUG)
69 wxMessageBox( PyErrStringWithTraceback(),
70 _( "Exception on python footprint wizard code" ),
71 wxICON_ERROR | wxOK );
72#endif
73 }
74
75 if( result )
76 {
77 Py_XDECREF( pFunc );
78 return result;
79 }
80 }
81 else
82 {
83 wxString msg = wxString::Format(_( "Method '%s' not found, or not callable" ), aMethod );
84 wxMessageBox( msg, _( "Unknown Method" ), wxICON_ERROR | wxOK );
85 }
86
87 if( pFunc )
88 {
89 Py_XDECREF( pFunc );
90 }
91
92 return nullptr;
93}
#define _(s)
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

References _, Format(), and m_PyWizard.

Referenced by CallRetArrayStrMethod(), CallRetStrMethod(), GetFootprint(), GetNumParameterPages(), GetParameterPageName(), and ResetParameters().

◆ CallRetArrayStrMethod()

wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod ( const char *  aMethod,
PyObject *  aArglist = nullptr 
)
private

Definition at line 116 of file pcbnew_footprint_wizards.cpp.

118{
119 wxArrayString ret;
120 PyLOCK lock;
121
122 PyObject* result = CallMethod( aMethod, aArglist );
123
124 if( result )
125 {
126 if( !PyList_Check( result ) )
127 {
128 Py_DECREF( result );
129 ret.Add( wxT( "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ),
130 1 );
131 return ret;
132 }
133
134 ret = PyArrayStringToWx( result );
135
136 Py_DECREF( result );
137 }
138
139 return ret;
140}
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=nullptr)

References CallMethod().

Referenced by GetParameterDesignators(), GetParameterErrors(), GetParameterHints(), GetParameterNames(), GetParameterTypes(), and GetParameterValues().

◆ CallRetStrMethod()

wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod ( const char *  aMethod,
PyObject *  aArglist = nullptr 
)
private

Definition at line 96 of file pcbnew_footprint_wizards.cpp.

97{
98 wxString ret;
99 PyLOCK lock;
100
101 PyObject* result = CallMethod( aMethod, aArglist );
102
103 if( result == Py_None )
104 {
105 Py_DECREF( result );
106 return ret;
107 }
108
109 ret = PyStringToWx( result );
110 Py_XDECREF( result );
111
112 return ret;
113}

References CallMethod().

Referenced by GetDescription(), GetFootprint(), GetImage(), GetName(), and SetParameterValues().

◆ GetDescription()

wxString PYTHON_FOOTPRINT_WIZARD::GetDescription ( )
overridevirtual
Returns
a description of the footprint wizard.

Implements FOOTPRINT_WIZARD.

Definition at line 159 of file pcbnew_footprint_wizards.cpp.

160{
161 PyLOCK lock;
162
163 return CallRetStrMethod( "GetDescription" );
164}
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=nullptr)

References CallRetStrMethod().

◆ GetFootprint()

FOOTPRINT * PYTHON_FOOTPRINT_WIZARD::GetFootprint ( wxString *  aMessage)
overridevirtual

Build the footprint itself and returns it to the caller function.

Parameters
aMessageis storage for messages (if any) generated by the footprint generator.
Returns
a footprint built from the parameters given to the class.

Implements FOOTPRINT_WIZARD.

Definition at line 336 of file pcbnew_footprint_wizards.cpp.

337{
338 PyLOCK lock;
339
340 PyObject* result = CallMethod( "GetFootprint", nullptr );
341
342 if( aMessages )
343 *aMessages = CallRetStrMethod( "GetBuildMessages", nullptr );
344
345 if( !result )
346 return nullptr;
347
348 PyObject* obj = PyObject_GetAttrString( result, "this" );
349
350 if( PyErr_Occurred() )
351 {
352 PyErr_Print();
353 PyErr_Clear();
354 }
355
356 FOOTPRINT* footprint = PyFootprint_to_FOOTPRINT( obj );
357
358 return footprint;
359}
FOOTPRINT * PyFootprint_to_FOOTPRINT(PyObject *obj0)

References CallMethod(), CallRetStrMethod(), and PyFootprint_to_FOOTPRINT().

◆ GetImage()

wxString PYTHON_FOOTPRINT_WIZARD::GetImage ( )
overridevirtual
Returns
an svg image of the wizard to be rendered.

Implements FOOTPRINT_WIZARD.

Definition at line 151 of file pcbnew_footprint_wizards.cpp.

152{
153 PyLOCK lock;
154
155 return CallRetStrMethod( "GetImage" );
156}

References CallRetStrMethod().

◆ GetName()

wxString PYTHON_FOOTPRINT_WIZARD::GetName ( )
overridevirtual
Returns
the name of the wizard.

Implements FOOTPRINT_WIZARD.

Definition at line 143 of file pcbnew_footprint_wizards.cpp.

144{
145 PyLOCK lock;
146
147 return CallRetStrMethod( "GetName" );
148}

References CallRetStrMethod().

◆ GetNumParameterPages()

int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages ( )
overridevirtual
Returns
the number of parameter pages that this wizard will show to the user.

Implements FOOTPRINT_WIZARD.

Definition at line 167 of file pcbnew_footprint_wizards.cpp.

168{
169 int ret = 0;
170 PyLOCK lock;
171
172 // Time to call the callback
173 PyObject* result = CallMethod( "GetNumParameterPages", nullptr );
174
175 if( result )
176 {
177 if( !PyLong_Check( result ) )
178 return -1;
179
180 ret = PyLong_AsLong( result );
181 Py_DECREF( result );
182 }
183
184 return ret;
185}

References CallMethod().

◆ GetObject()

void * PYTHON_FOOTPRINT_WIZARD::GetObject ( )
overridevirtual

Get the object from where this wizard constructs.

Returns
it's a void pointer as it could be a PyObject or any other.

Implements FOOTPRINT_WIZARD.

Definition at line 362 of file pcbnew_footprint_wizards.cpp.

363{
364 return (void*) m_PyWizard;
365}

References m_PyWizard.

◆ GetParameterDesignators()

wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterDesignators ( int  aPage = 0)
overridevirtual
Parameters
aPageis the page we want to know the designators of.
Returns
an array of designators (blank strings for no designators.

Implements FOOTPRINT_WIZARD.

Definition at line 288 of file pcbnew_footprint_wizards.cpp.

289{
290 PyLOCK lock;
291
292 PyObject* arglist = Py_BuildValue( "(i)", aPage );
293 wxArrayString ret = CallRetArrayStrMethod( "GetParameterDesignators", arglist );
294
295 Py_DECREF( arglist );
296
297 return ret;
298}
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=nullptr)

References CallRetArrayStrMethod().

◆ GetParameterErrors()

wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors ( int  aPage)
overridevirtual
Parameters
aPageis the page we want to know the errors of.
Returns
an array of errors (if any) for the parameters, empty strings for OK parameters.

Implements FOOTPRINT_WIZARD.

Definition at line 264 of file pcbnew_footprint_wizards.cpp.

265{
266 PyLOCK lock;
267
268 PyObject* arglist = Py_BuildValue( "(i)", aPage );
269 wxArrayString ret = CallRetArrayStrMethod( "GetParameterErrors", arglist );
270
271 Py_DECREF( arglist );
272
273 return ret;
274}

References CallRetArrayStrMethod().

◆ GetParameterHints()

wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterHints ( int  aPage)
overridevirtual
Parameters
aPageis the page we want to know the hints of.
Returns
an array of hints (if any) for the parameters, empty string for no hints.

Implements FOOTPRINT_WIZARD.

Definition at line 276 of file pcbnew_footprint_wizards.cpp.

277{
278 PyLOCK lock;
279
280 PyObject* arglist = Py_BuildValue( "(i)", aPage );
281 wxArrayString ret = CallRetArrayStrMethod( "GetParameterHints", arglist );
282
283 Py_DECREF( arglist );
284
285 return ret;
286}

References CallRetArrayStrMethod().

◆ GetParameterNames()

wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames ( int  aPage)
overridevirtual
Parameters
aPageis the page we want the parameter names of.
Returns
an array string with the parameter names on a certain page.

Implements FOOTPRINT_WIZARD.

Definition at line 212 of file pcbnew_footprint_wizards.cpp.

213{
214 wxArrayString ret;
215 PyLOCK lock;
216
217 PyObject* arglist = Py_BuildValue( "(i)", aPage );
218
219 ret = CallRetArrayStrMethod( "GetParameterNames", arglist );
220 Py_DECREF( arglist );
221
222 for( unsigned i = 0; i < ret.GetCount(); i++ )
223 {
224 wxString rest;
225 wxString item = ret[i];
226
227 if( item.StartsWith( wxT( "*" ), &rest ) )
228 {
229 ret[i] = rest;
230 }
231 }
232
233 return ret;
234}

References CallRetArrayStrMethod().

◆ GetParameterPageName()

wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName ( int  aPage)
overridevirtual
Parameters
aPageis the page we want the name of.
Returns
a string with the page name.

Implements FOOTPRINT_WIZARD.

Definition at line 188 of file pcbnew_footprint_wizards.cpp.

189{
190 wxString ret;
191 PyLOCK lock;
192
193 // Time to call the callback
194 PyObject* arglist = Py_BuildValue( "(i)", aPage );
195 PyObject* result = CallMethod( "GetParameterPageName", arglist );
196
197 Py_DECREF( arglist );
198
199 if( result == Py_None )
200 {
201 Py_DECREF( result );
202 return ret;
203 }
204
205 ret = PyStringToWx( result );
206 Py_XDECREF( result );
207
208 return ret;
209}

References CallMethod().

◆ GetParameterTypes()

wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes ( int  aPage)
overridevirtual
Parameters
aPageis the page we want the parameter types of.
Returns
an array string with the parameter types on a certain page "IU" for internal units, "UNITS" for units (0,1,2,3...,N).

Implements FOOTPRINT_WIZARD.

Definition at line 237 of file pcbnew_footprint_wizards.cpp.

238{
239 wxArrayString ret;
240 PyLOCK lock;
241
242 PyObject* arglist = Py_BuildValue( "(i)", aPage );
243
244 ret = CallRetArrayStrMethod( "GetParameterTypes", arglist );
245 Py_DECREF( arglist );
246
247 return ret;
248}

References CallRetArrayStrMethod().

◆ GetParameterValues()

wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues ( int  aPage)
overridevirtual
Parameters
aPageis the page we want the parameter values of.
Returns
an array of parameter values.

Implements FOOTPRINT_WIZARD.

Definition at line 251 of file pcbnew_footprint_wizards.cpp.

252{
253 PyLOCK lock;
254
255 PyObject* arglist = Py_BuildValue( "(i)", aPage );
256 wxArrayString ret = CallRetArrayStrMethod( "GetParameterValues", arglist );
257
258 Py_DECREF( arglist );
259
260 return ret;
261}

References CallRetArrayStrMethod().

◆ register_wizard()

void FOOTPRINT_WIZARD::register_wizard ( )
inherited

The standard method of a "FOOTPRINT_WIZARD" to register itself into the FOOTPRINT_WIZARD_LIST singleton manager.

Definition at line 39 of file footprint_wizard.cpp.

40{
42}
static void register_wizard(FOOTPRINT_WIZARD *aWizard)
A footprint wizard calls this static method when it wants to register itself into the system wizards.

References FOOTPRINT_WIZARD_LIST::register_wizard().

Referenced by PYTHON_FOOTPRINT_WIZARD_LIST::register_wizard().

◆ ResetParameters()

void PYTHON_FOOTPRINT_WIZARD::ResetParameters ( )
overridevirtual

Reset all wizard parameters to default values.

Implements FOOTPRINT_WIZARD.

Definition at line 324 of file pcbnew_footprint_wizards.cpp.

325{
326 PyLOCK lock;
327
328 CallMethod( "ResetWizard", nullptr );
329}

References CallMethod().

◆ SetParameterValues()

wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues ( int  aPage,
wxArrayString &  aValues 
)
overridevirtual
Parameters
aPageis the page we want to set the parameters in.
aValuesare the values we want to set into the parameters.
Returns
an array of parameter values.

Implements FOOTPRINT_WIZARD.

Definition at line 300 of file pcbnew_footprint_wizards.cpp.

301{
302 int len = aValues.size();
303
304 PyLOCK lock;
305
306 PyObject* py_list = PyList_New( len );
307
308 for( int i = 0; i < len; i++ )
309 {
310 wxString& str = aValues[i];
311 PyObject* py_str = PyUnicode_FromString( (const char*) str.mb_str() );
312 PyList_SetItem( py_list, i, py_str );
313 }
314
315 PyObject* arglist;
316
317 arglist = Py_BuildValue( "(i,O)", aPage, py_list );
318 wxString res = CallRetStrMethod( "SetParameterValues", arglist );
319 Py_DECREF( arglist );
320
321 return res;
322}

References CallRetStrMethod().

Member Data Documentation

◆ m_PyWizard

PyObject* PYTHON_FOOTPRINT_WIZARD::m_PyWizard
private

The documentation for this class was generated from the following files: