From 9398eb9767736d6891c71acc10616b77a5a2c9f2 Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo <miguelangel@nbee.es> Date: Mon, 19 Mar 2012 09:36:38 +0100 Subject: [PATCH] std::vector and std::string items DLIST iterator code, now we can do: for module in pcb.m_Modules: print module.GetReference() instead of: module = pcb.m_Modules while module: print module.GetReference() module = module.Next() or even: module_list = list(pcb.m_Modules) --- pcbnew/scripting/pcbnew.i | 11 ++++++----- scripting/kicad.i | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/pcbnew/scripting/pcbnew.i b/pcbnew/scripting/pcbnew.i index d778bf7e3d..c74d00fdc6 100644 --- a/pcbnew/scripting/pcbnew.i +++ b/pcbnew/scripting/pcbnew.i @@ -180,9 +180,10 @@ BOARD *GetBoard(); %template(TRACK_List) DLIST<TRACK>; %template(PAD_List) DLIST<D_PAD>; -/* TODO: -the std::* compilatio is broken with some swig + gcc combinations - * see kicad.i for more information. - * %template(MARKER_Vector) std::vector<MARKER_PCB*>; - * %template(ZONE_CONTAINER_Vector) std::vector<ZONE_CONTAINER*>; - */ + + +%template(MARKER_Vector) std::vector<MARKER_PCB*>; +%template(ZONE_CONTAINER_Vector) std::vector<ZONE_CONTAINER*>; +%template(VIA_DIMENSION_Vector) std::vector<VIA_DIMENSION>; + diff --git a/scripting/kicad.i b/scripting/kicad.i index 5bd5dd11f7..b2c9809c69 100644 --- a/scripting/kicad.i +++ b/scripting/kicad.i @@ -30,10 +30,12 @@ /* OFF NOW, it triggers an error with GCC 4.6 and swig-2.0.4 or trunk.. http://sourceforge.net/tracker/index.php?func=detail&aid=3391906&group_id=1645&atid=101645 +*/ + %include <std_vector.i> %include <std_string.i> -*/ + %nodefaultctor EDA_ITEM; @@ -48,6 +50,7 @@ %ignore GetCommandOptions; %{ + #include <cstddef> #include <dlist.h> #include <base_struct.h> #include <common.h> @@ -63,7 +66,6 @@ /* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */ %include <wx.i> - %include <dlist.h> %include <base_struct.h> %include <common.h> @@ -71,9 +73,34 @@ %include <class_colors_design_settings.h> -/* -namespace std +%extend DLIST { - %template(intVector) vector<int>; + %pythoncode + { + class DLISTIter: + def __init__(self,aList): + self.last = aList + + def next(self): + if self.last is None: + raise StopIteration + else: + ret = None + + # first item in list has "Get" as a DLIST + try: + ret = self.last.Get() + except: + ret = self.last #next items just not.. + + self.last = self.last.Next() + return ret + + def __iter__(self): + return self.DLISTIter(self) + + } } -*/ +%template(intVector) std::vector<int>; + +