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

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

References CallMethod(), and PyArrayStringToWx().

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

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

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 )
103  {
104  const char* str_res = PyString_AsString( result );
105  ret = FROM_UTF8( str_res );
106  Py_DECREF( result );
107  }
108 
109  return ret;
110 }
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 158 of file pcbnew_footprint_wizards.cpp.

References CallRetStrMethod().

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

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

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

References CallRetStrMethod().

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

References CallRetStrMethod().

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

References CallMethod().

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

References m_PyWizard.

360 {
361  return (void*) m_PyWizard;
362 }
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 285 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

286 {
287  PyLOCK lock;
288 
289  PyObject* arglist = Py_BuildValue( "(i)", aPage );
290  wxArrayString ret = CallRetArrayStrMethod( "GetParameterDesignators", arglist );
291 
292  Py_DECREF( arglist );
293 
294  return ret;
295 }
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 261 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

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

References CallRetArrayStrMethod().

274 {
275  PyLOCK lock;
276 
277  PyObject* arglist = Py_BuildValue( "(i)", aPage );
278  wxArrayString ret = CallRetArrayStrMethod( "GetParameterHints", arglist );
279 
280  Py_DECREF( arglist );
281 
282  return ret;
283 }
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 209 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod(), and i.

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

References CallMethod(), and FROM_UTF8().

188 {
189  wxString ret;
190  PyLOCK lock;
191 
192  // Time to call the callback
193  PyObject* arglist = Py_BuildValue( "(i)", aPage );
194  PyObject* result = CallMethod( "GetParameterPageName", arglist );
195 
196  Py_DECREF( arglist );
197 
198  if( result )
199  {
200  const char* str_res = PyString_AsString( result );
201  ret = FROM_UTF8( str_res );
202  Py_DECREF( result );
203  }
204 
205  return ret;
206 }
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 234 of file pcbnew_footprint_wizards.cpp.

References CallRetArrayStrMethod().

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

References CallRetArrayStrMethod().

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

References CallMethod(), and PyModule_to_MODULE().

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

References CallRetStrMethod(), i, and str.

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