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
 Function GetName. More...
 
wxString GetImage () override
 Function GetImage. More...
 
wxString GetDescription () override
 Function GetDescription. More...
 
int GetNumParameterPages () override
 Function GetNumParameterPages. More...
 
wxString GetParameterPageName (int aPage) override
 Function GetParameterPageName. More...
 
wxArrayString GetParameterNames (int aPage) override
 Function GetParameterNames. More...
 
wxArrayString GetParameterTypes (int aPage) override
 Function GetParameterTypes. More...
 
wxArrayString GetParameterValues (int aPage) override
 Function GetParameterValues. More...
 
wxArrayString GetParameterErrors (int aPage) override
 Function GetParameterErrors. More...
 
wxString SetParameterValues (int aPage, wxArrayString &aValues) override
 Function SetParameterValues. More...
 
MODULEGetFootprint (wxString *aMessages) override
 Function GetModule This method builds the module itself and returns it to the caller function. More...
 
void * GetObject () override
 Function GetObject This method gets the pointer to the object from where this wizard constructs. More...
 
wxArrayString GetParameterHints (int aPage) override
 Function GetParameterHints. More...
 
wxArrayString GetParameterDesignators (int aPage=0) override
 Function GetParamaterDesignators. More...
 
void ResetParameters () override
 Function ResetParameters Reset all wizard parameters to default values. More...
 
void register_wizard ()
 Function register_wizard It's 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=NULL)
 
wxString CallRetStrMethod (const char *aMethod, PyObject *aArglist=NULL)
 
wxArrayString CallRetArrayStrMethod (const char *aMethod, PyObject *aArglist=NULL)
 

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 ( PyObject *  wizard)

Definition at line 36 of file pcbnew_footprint_wizards.cpp.

References m_PyWizard.

Referenced by PYTHON_FOOTPRINT_WIZARD_LIST::register_wizard().

37 {
38  PyLOCK lock;
39 
40  this->m_PyWizard = aWizard;
41  Py_XINCREF( aWizard );
42 }
PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD ( )

Definition at line 45 of file pcbnew_footprint_wizards.cpp.

References m_PyWizard.

46 {
47  PyLOCK lock;
48 
49  Py_XDECREF( this->m_PyWizard );
50 }

Member Function Documentation

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

Definition at line 53 of file pcbnew_footprint_wizards.cpp.

References Format(), m_PyWizard, and PyErrStringWithTraceback().

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

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

Definition at line 115 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), and PyArrayStringToWx().

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

117 {
118  wxArrayString ret;
119  wxString str_item;
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(
130  "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ),
131  1 );
132  return ret;
133  }
134 
135  ret = PyArrayStringToWx( result );
136 
137  Py_DECREF( result );
138  }
139 
140  return ret;
141 }
wxArrayString PyArrayStringToWx(PyObject *aArrayString)
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_FOOTPRINT_WIZARD::CallRetStrMethod ( const char *  aMethod,
PyObject *  aArglist = NULL 
)
private

Definition at line 95 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), and PyStringToWx().

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

96 {
97  wxString ret;
98  PyLOCK lock;
99 
100  PyObject* result = CallMethod( aMethod, aArglist );
101 
102  if( result == Py_None )
103  {
104  Py_DECREF( result );
105  return ret;
106  }
107 
108  ret = PyStringToWx( result );
109  Py_XDECREF( result );
110 
111  return ret;
112 }
wxString PyStringToWx(PyObject *aString)
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_FOOTPRINT_WIZARD::GetDescription ( )
overridevirtual

Function GetDescription.

Returns
a description of the footprint wizard

Implements FOOTPRINT_WIZARD.

Definition at line 160 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

161 {
162  PyLOCK lock;
163 
164  return CallRetStrMethod( "GetDescription" );
165 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
MODULE * PYTHON_FOOTPRINT_WIZARD::GetFootprint ( wxString *  aMessage)
overridevirtual

Function GetModule This method builds the module itself and returns it to the caller function.

Returns
PCB module built from the parameters given to the class
Parameters
aMessagea wxString to store messages (if any) generated by the footprint generator

Implements FOOTPRINT_WIZARD.

Definition at line 348 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), CallRetStrMethod(), mod, and PyModule_to_MODULE().

349 {
350  PyLOCK lock;
351 
352  PyObject* result = CallMethod( "GetFootprint", NULL );
353 
354  if( aMessages )
355  *aMessages = CallRetStrMethod( "GetBuildMessages", NULL );
356 
357  if( !result )
358  return NULL;
359 
360  PyObject* obj = PyObject_GetAttrString( result, "this" );
361 
362  if( PyErr_Occurred() )
363  {
364  PyErr_Print();
365  PyErr_Clear();
366  }
367 
368  MODULE* mod = PyModule_to_MODULE( obj );
369 
370  return mod;
371 }
MODULE * PyModule_to_MODULE(PyObject *obj0)
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
#define mod(a, n)
Definition: greymap.cpp:24
wxString PYTHON_FOOTPRINT_WIZARD::GetImage ( )
overridevirtual

Function GetImage.

Returns
an svg image of the wizard to be rendered

Implements FOOTPRINT_WIZARD.

Definition at line 152 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

153 {
154  PyLOCK lock;
155 
156  return CallRetStrMethod( "GetImage" );
157 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_FOOTPRINT_WIZARD::GetName ( )
overridevirtual

Function GetName.

Returns
the name of the wizard

Implements FOOTPRINT_WIZARD.

Definition at line 144 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

145 {
146  PyLOCK lock;
147 
148  return CallRetStrMethod( "GetName" );
149 }
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
int PYTHON_FOOTPRINT_WIZARD::GetNumParameterPages ( )
overridevirtual

Function GetNumParameterPages.

Returns
the number of parameter pages that this wizard will show to the user

Implements FOOTPRINT_WIZARD.

Definition at line 168 of file pcbnew_footprint_wizards.cpp.

References CallMethod().

169 {
170  int ret = 0;
171  PyLOCK lock;
172 
173  // Time to call the callback
174  PyObject* result = CallMethod( "GetNumParameterPages", NULL );
175 
176  if( result )
177  {
178 #if PY_MAJOR_VERSION >= 3
179  if( !PyLong_Check( result ) )
180  return -1;
181 
182  ret = PyLong_AsLong( result );
183 #else
184  if( !PyInt_Check( result ) )
185  return -1;
186 
187  ret = PyInt_AsLong( result );
188 #endif
189  Py_DECREF( result );
190  }
191 
192  return ret;
193 }
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
void * PYTHON_FOOTPRINT_WIZARD::GetObject ( )
overridevirtual

Function GetObject This method gets the pointer to 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 374 of file pcbnew_footprint_wizards.cpp.

References m_PyWizard.

375 {
376  return (void*) m_PyWizard;
377 }
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterDesignators ( int  aPage = 0)
overridevirtual

Function GetParamaterDesignators.

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 296 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

297 {
298  PyLOCK lock;
299 
300  PyObject* arglist = Py_BuildValue( "(i)", aPage );
301  wxArrayString ret = CallRetArrayStrMethod( "GetParameterDesignators", arglist );
302 
303  Py_DECREF( arglist );
304 
305  return ret;
306 }
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors ( int  aPage)
overridevirtual

Function GetParameterErrors.

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 272 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

273 {
274  PyLOCK lock;
275 
276  PyObject* arglist = Py_BuildValue( "(i)", aPage );
277  wxArrayString ret = CallRetArrayStrMethod( "GetParameterErrors", arglist );
278 
279  Py_DECREF( arglist );
280 
281  return ret;
282 }
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterHints ( int  aPage)
overridevirtual

Function GetParameterHints.

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 284 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

285 {
286  PyLOCK lock;
287 
288  PyObject* arglist = Py_BuildValue( "(i)", aPage );
289  wxArrayString ret = CallRetArrayStrMethod( "GetParameterHints", arglist );
290 
291  Py_DECREF( arglist );
292 
293  return ret;
294 }
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames ( int  aPage)
overridevirtual

Function GetParameterNames.

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 220 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod(), and i.

221 {
222  wxArrayString ret;
223  PyLOCK lock;
224 
225  PyObject* arglist = Py_BuildValue( "(i)", aPage );
226 
227  ret = CallRetArrayStrMethod( "GetParameterNames", arglist );
228  Py_DECREF( arglist );
229 
230  for( unsigned i = 0; i < ret.GetCount(); i++ )
231  {
232  wxString rest;
233  wxString item = ret[i];
234 
235  if( item.StartsWith( wxT( "*" ), &rest ) )
236  {
237  ret[i] = rest;
238  }
239  }
240 
241  return ret;
242 }
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=NULL)
size_t i
Definition: json11.cpp:597
wxString PYTHON_FOOTPRINT_WIZARD::GetParameterPageName ( int  aPage)
overridevirtual

Function GetParameterPageName.

Parameters
aPageis the page we want the name of
Returns
a string with the page name

Implements FOOTPRINT_WIZARD.

Definition at line 196 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), and PyStringToWx().

197 {
198  wxString ret;
199  PyLOCK lock;
200 
201  // Time to call the callback
202  PyObject* arglist = Py_BuildValue( "(i)", aPage );
203  PyObject* result = CallMethod( "GetParameterPageName", arglist );
204 
205  Py_DECREF( arglist );
206 
207  if( result == Py_None )
208  {
209  Py_DECREF( result );
210  return ret;
211  }
212 
213  ret = PyStringToWx( result );
214  Py_XDECREF( result );
215 
216  return ret;
217 }
wxString PyStringToWx(PyObject *aString)
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes ( int  aPage)
overridevirtual

Function GetParameterTypes.

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 245 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

246 {
247  wxArrayString ret;
248  PyLOCK lock;
249 
250  PyObject* arglist = Py_BuildValue( "(i)", aPage );
251 
252  ret = CallRetArrayStrMethod( "GetParameterTypes", arglist );
253  Py_DECREF( arglist );
254 
255  return ret;
256 }
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=NULL)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues ( int  aPage)
overridevirtual

Function GetParameterValues.

Parameters
aPageis the page we want the parameter values of
Returns
an array of parameter values

Implements FOOTPRINT_WIZARD.

Definition at line 259 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

260 {
261  PyLOCK lock;
262 
263  PyObject* arglist = Py_BuildValue( "(i)", aPage );
264  wxArrayString ret = CallRetArrayStrMethod( "GetParameterValues", arglist );
265 
266  Py_DECREF( arglist );
267 
268  return ret;
269 }
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=NULL)
void FOOTPRINT_WIZARD::register_wizard ( )
inherited

Function register_wizard It's 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.

References FOOTPRINT_WIZARD_LIST::m_FootprintWizards, and FOOTPRINT_WIZARD_LIST::register_wizard().

Referenced by FOOTPRINT_WIZARD::FOOTPRINT_WIZARD(), and PYTHON_FOOTPRINT_WIZARD_LIST::register_wizard().

40 {
42 }
static void register_wizard(FOOTPRINT_WIZARD *aWizard)
Function register_wizard A footprint wizard calls this static method when it wants to register itself...
void PYTHON_FOOTPRINT_WIZARD::ResetParameters ( )
overridevirtual

Function ResetParameters Reset all wizard parameters to default values.

Implements FOOTPRINT_WIZARD.

Definition at line 336 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), and PyModule_to_MODULE().

337 {
338  PyLOCK lock;
339 
340  CallMethod( "ResetWizard", NULL );
341 }
PyObject * CallMethod(const char *aMethod, PyObject *aArglist=NULL)
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues ( int  aPage,
wxArrayString &  aValues 
)
overridevirtual

Function SetParameterValues.

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 308 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod(), i, and str.

309 {
310  int len = aValues.size();
311 
312  PyLOCK lock;
313 
314  PyObject* py_list = PyList_New( len );
315 
316  for( int i = 0; i < len; i++ )
317  {
318  wxString& str = aValues[i];
319 #if PY_MAJOR_VERSION >= 3
320  PyObject* py_str = PyUnicode_FromString( (const char*) str.mb_str() );
321 #else
322  PyObject* py_str = PyString_FromString( (const char*) str.mb_str() );
323 #endif
324  PyList_SetItem( py_list, i, py_str );
325  }
326 
327  PyObject* arglist;
328 
329  arglist = Py_BuildValue( "(i,O)", aPage, py_list );
330  wxString res = CallRetStrMethod( "SetParameterValues", arglist );
331  Py_DECREF( arglist );
332 
333  return res;
334 }
const string & str
Definition: json11.cpp:596
wxString CallRetStrMethod(const char *aMethod, PyObject *aArglist=NULL)
size_t i
Definition: json11.cpp:597

Member Data Documentation

PyObject* PYTHON_FOOTPRINT_WIZARD::m_PyWizard
private

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