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_WIZARDS 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 37 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.

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 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  wxT( "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  printf( "method not found, or not callable: %s\n", aMethod );
83  }
84 
85  if( pFunc )
86  {
87  Py_XDECREF( pFunc );
88  }
89 
90  return NULL;
91 }
wxString PyErrStringWithTraceback()
wxArrayString PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod ( const char *  aMethod,
PyObject *  aArglist = NULL 
)
private

Definition at line 112 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), and PyArrayStringToWx().

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

114 {
115  wxArrayString ret;
116  wxString str_item;
117  PyLOCK lock;
118 
119  PyObject* result = CallMethod( aMethod, aArglist );
120 
121  if( result )
122  {
123  if( !PyList_Check( result ) )
124  {
125  Py_DECREF( result );
126  ret.Add( wxT(
127  "PYTHON_FOOTPRINT_WIZARD::CallRetArrayStrMethod, result is not a list" ),
128  1 );
129  return ret;
130  }
131 
132  ret = PyArrayStringToWx( result );
133 
134  Py_DECREF( result );
135  }
136 
137  return ret;
138 }
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 94 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), and FROM_UTF8().

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

95 {
96  wxString ret;
97  PyLOCK lock;
98 
99  PyObject* result = CallMethod( aMethod, aArglist );
100 
101  if( result )
102  {
103  const char* str_res = PyString_AsString( result );
104  ret = FROM_UTF8( str_res );
105  Py_DECREF( result );
106  }
107 
108  return ret;
109 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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 157 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

158 {
159  PyLOCK lock;
160 
161  return CallRetStrMethod( "GetDescription" );
162 }
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 332 of file pcbnew_footprint_wizards.cpp.

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

333 {
334  PyLOCK lock;
335 
336  PyObject* result = CallMethod( "GetFootprint", NULL );
337 
338  if( aMessages )
339  *aMessages = CallRetStrMethod( "GetBuildMessages", NULL );
340 
341  if( !result )
342  return NULL;
343 
344  PyObject* obj = PyObject_GetAttrString( result, "this" );
345 
346  if( PyErr_Occurred() )
347  {
348  PyErr_Print();
349  PyErr_Clear();
350  }
351 
352  MODULE* mod = PyModule_to_MODULE( obj );
353 
354  return mod;
355 }
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 149 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

150 {
151  PyLOCK lock;
152 
153  return CallRetStrMethod( "GetImage" );
154 }
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 141 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

142 {
143  PyLOCK lock;
144 
145  return CallRetStrMethod( "GetName" );
146 }
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 165 of file pcbnew_footprint_wizards.cpp.

References CallMethod().

166 {
167  int ret = 0;
168  PyLOCK lock;
169 
170  // Time to call the callback
171  PyObject* result = CallMethod( "GetNumParameterPages", NULL );
172 
173  if( result )
174  {
175  if( !PyInt_Check( result ) )
176  return -1;
177 
178  ret = PyInt_AsLong( result );
179  Py_DECREF( result );
180  }
181 
182  return ret;
183 }
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 358 of file pcbnew_footprint_wizards.cpp.

References m_PyWizard.

359 {
360  return (void*) m_PyWizard;
361 }
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 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( "GetParameterDesignators", arglist );
290 
291  Py_DECREF( arglist );
292 
293  return ret;
294 }
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 260 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

261 {
262  PyLOCK lock;
263 
264  PyObject* arglist = Py_BuildValue( "(i)", aPage );
265  wxArrayString ret = CallRetArrayStrMethod( "GetParameterErrors", arglist );
266 
267  Py_DECREF( arglist );
268 
269  return ret;
270 }
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 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( "GetParameterHints", arglist );
278 
279  Py_DECREF( arglist );
280 
281  return ret;
282 }
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 208 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

209 {
210  wxArrayString ret;
211  PyLOCK lock;
212 
213  PyObject* arglist = Py_BuildValue( "(i)", aPage );
214 
215  ret = CallRetArrayStrMethod( "GetParameterNames", arglist );
216  Py_DECREF( arglist );
217 
218  for( unsigned i = 0; i < ret.GetCount(); i++ )
219  {
220  wxString rest;
221  wxString item = ret[i];
222 
223  if( item.StartsWith( wxT( "*" ), &rest ) )
224  {
225  ret[i] = rest;
226  }
227  }
228 
229  return ret;
230 }
wxArrayString CallRetArrayStrMethod(const char *aMethod, PyObject *aArglist=NULL)
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 186 of file pcbnew_footprint_wizards.cpp.

References CallMethod(), and FROM_UTF8().

187 {
188  wxString ret;
189  PyLOCK lock;
190 
191  // Time to call the callback
192  PyObject* arglist = Py_BuildValue( "(i)", aPage );
193  PyObject* result = CallMethod( "GetParameterPageName", arglist );
194 
195  Py_DECREF( arglist );
196 
197  if( result )
198  {
199  const char* str_res = PyString_AsString( result );
200  ret = FROM_UTF8( str_res );
201  Py_DECREF( result );
202  }
203 
204  return ret;
205 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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 233 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

234 {
235  wxArrayString ret;
236  PyLOCK lock;
237 
238  PyObject* arglist = Py_BuildValue( "(i)", aPage );
239 
240  ret = CallRetArrayStrMethod( "GetParameterTypes", arglist );
241  Py_DECREF( arglist );
242 
243  return ret;
244 }
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 247 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

248 {
249  PyLOCK lock;
250 
251  PyObject* arglist = Py_BuildValue( "(i)", aPage );
252  wxArrayString ret = CallRetArrayStrMethod( "GetParameterValues", arglist );
253 
254  Py_DECREF( arglist );
255 
256  return ret;
257 }
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_WIZARDS singleton manager.

Definition at line 39 of file class_footprint_wizard.cpp.

References FOOTPRINT_WIZARDS::register_wizard().

Referenced by PYTHON_FOOTPRINT_WIZARDS::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 320 of file pcbnew_footprint_wizards.cpp.

References CallMethod().

321 {
322  PyLOCK lock;
323 
324  CallMethod( "ResetWizard", NULL );
325 }
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 296 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

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

Member Data Documentation

PyObject* PYTHON_FOOTPRINT_WIZARD::m_PyWizard
private

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