diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 201de6ff6d..b8db13989a 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -663,6 +663,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) TRACK* insertAid; insertAid = ( (TRACK*) aBoardItem )->GetBestInsertPoint( this ); m_Track.Insert( (TRACK*) aBoardItem, insertAid ); + aBoardItem->SetParent( this ); break; case PCB_ZONE_T: diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 104dd19e72..8401e99282 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -804,7 +804,8 @@ void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src ) SetTimeStamp( src->m_TimeStamp ); m_Poly->RemoveAllContours(); m_Poly->Copy( src->m_Poly ); // copy outlines - m_CornerSelection = -1; // For corner moving, corner index to drag, or -1 if no selection + m_CornerSelection = -1; // For corner moving, corner index to drag, + // or -1 if no selection m_ZoneClearance = src->m_ZoneClearance; // clearance value m_ZoneMinThickness = src->m_ZoneMinThickness; m_FillMode = src->m_FillMode; // Filling mode (segments/polygons) diff --git a/pcbnew/scripting/board.i b/pcbnew/scripting/board.i index 095a285bc0..65d0cb1990 100644 --- a/pcbnew/scripting/board.i +++ b/pcbnew/scripting/board.i @@ -36,7 +36,6 @@ def GetDrawings(self): return self.m_Drawings def GetTracks(self): return self.m_Track def GetFullRatsnest(self): return self.m_FullRatsnest - def GetZones(self): return self.m_ZoneDescriptorList def Save(self,filename): return SaveBoard(filename,self,IO_MGR.KICAD) @@ -47,8 +46,8 @@ # def Add(self,item): - item.thisown=0 - self.AddNative(item) + item.thisown=0 + self.AddNative(item) } } @@ -75,44 +74,44 @@ %extend BOARD { - %pythoncode - { - def GetNetClasses(self): - return self.GetDesignSettings().m_NetClasses + %pythoncode + { + def GetNetClasses(self): + return self.GetDesignSettings().m_NetClasses - def GetCurrentNetClassName(self): - return self.GetDesignSettings().m_CurrentNetClassName + def GetCurrentNetClassName(self): + return self.GetDesignSettings().m_CurrentNetClassName - def GetViasDimensionsList(self): - return self.GetDesignSettings().m_ViasDimensionsList + def GetViasDimensionsList(self): + return self.GetDesignSettings().m_ViasDimensionsList - def GetTrackWidthList(self): - return self.GetDesignSettings().m_TrackWidthList - } + def GetTrackWidthList(self): + return self.GetDesignSettings().m_TrackWidthList + } } %extend DRAWSEGMENT { - %pythoncode - { - def GetShapeStr(self): - return self.ShowShape(self.GetShape()) - } + %pythoncode + { + def GetShapeStr(self): + return self.ShowShape(self.GetShape()) + } } %extend BOARD_ITEM { - %pythoncode - { - def SetPos(self,p): - self.SetPosition(p) - self.SetPos0(p) + %pythoncode + { + def SetPos(self,p): + self.SetPosition(p) + self.SetPos0(p) - def SetStartEnd(self,start,end): - self.SetStart(start) - self.SetStart0(start) - self.SetEnd(end) - self.SetEnd0(end) - } + def SetStartEnd(self,start,end): + self.SetStart(start) + self.SetStart0(start) + self.SetEnd(end) + self.SetEnd0(end) + } } diff --git a/pcbnew/scripting/board_item.i b/pcbnew/scripting/board_item.i index 07384e2e6e..42a421de04 100644 --- a/pcbnew/scripting/board_item.i +++ b/pcbnew/scripting/board_item.i @@ -32,54 +32,64 @@ %inline { - BOARD_ITEM* Cast_to_BOARD_ITEM(EDA_ITEM* base) { return dynamic_cast(base); } + BOARD_ITEM* Cast_to_BOARD_ITEM(EDA_ITEM* base) { return dynamic_cast(base); } } %extend BOARD_ITEM { - TEXTE_PCB* Cast_to_TEXTE_PCB() { return dynamic_cast(self); } - DIMENSION* Cast_to_DIMENSION() { return dynamic_cast(self); } - MODULE* Cast_to_MODULE() { return dynamic_cast(self); } - TEXTE_MODULE* Cast_to_TEXTE_MODULE() { return dynamic_cast(self); } - DRAWSEGMENT* Cast_to_DRAWSEGMENT() { return dynamic_cast(self); } - MARKER_PCB* Cast_to_MARKER_PCB() { return dynamic_cast(self); } - BOARD* Cast_to_BOARD() { return dynamic_cast(self); } - EDGE_MODULE* Cast_to_EDGE_MODULE() { return dynamic_cast(self); } - D_PAD* Cast_to_D_PAD() { return dynamic_cast(self); } - TRACK* Cast_to_TRACK() { return dynamic_cast(self); } - ZONE_CONTAINER* Cast_to_ZONE_CONTAINER() { return dynamic_cast(self);} - VIA* Cast_to_VIA() { return dynamic_cast(self); } + TEXTE_PCB* Cast_to_TEXTE_PCB() { return dynamic_cast(self); } + DIMENSION* Cast_to_DIMENSION() { return dynamic_cast(self); } + MODULE* Cast_to_MODULE() { return dynamic_cast(self); } + TEXTE_MODULE* Cast_to_TEXTE_MODULE() { return dynamic_cast(self); } + DRAWSEGMENT* Cast_to_DRAWSEGMENT() { return dynamic_cast(self); } + MARKER_PCB* Cast_to_MARKER_PCB() { return dynamic_cast(self); } + BOARD* Cast_to_BOARD() { return dynamic_cast(self); } + EDGE_MODULE* Cast_to_EDGE_MODULE() { return dynamic_cast(self); } + D_PAD* Cast_to_D_PAD() { return dynamic_cast(self); } + TRACK* Cast_to_TRACK() { return dynamic_cast(self); } + ZONE_CONTAINER* Cast_to_ZONE_CONTAINER() { return dynamic_cast(self);} + VIA* Cast_to_VIA() { return dynamic_cast(self); } - %pythoncode - { + %pythoncode + { def Cast(self): - ct = self.GetClass() + ct = self.GetClass() - if ct=="PTEXT": - return self.Cast_to_TEXTE_PCB() - elif ct=="BOARD": - return self.Cast_to_BOARD() - elif ct=="DIMENSION": - return self.Cast_to_DIMENSION() - elif ct=="DRAWSEGMENT": - return self.Cast_to_DRAWSEGMENT() - elif ct=="MGRAPHIC": - return self.Cast_to_EDGE_MODULE() - elif ct=="MODULE": - return self.Cast_to_MODULE() - elif ct=="PAD": - return self.Cast_to_D_PAD() - elif ct=="MTEXT": - return self.Cast_to_TEXTE_MODULE() - elif ct=="VIA": - return self.Cast_to_VIA() - elif ct=="TRACK": - return self.Cast_to_TRACK() - elif ct=="ZONE_CONTAINER": - return self.Cast_to_ZONE_CONTAINER() - else: - return None - } + if ct=="PTEXT": + return self.Cast_to_TEXTE_PCB() + elif ct=="BOARD": + return self.Cast_to_BOARD() + elif ct=="DIMENSION": + return self.Cast_to_DIMENSION() + elif ct=="DRAWSEGMENT": + return self.Cast_to_DRAWSEGMENT() + elif ct=="MGRAPHIC": + return self.Cast_to_EDGE_MODULE() + elif ct=="MODULE": + return self.Cast_to_MODULE() + elif ct=="PAD": + return self.Cast_to_D_PAD() + elif ct=="MTEXT": + return self.Cast_to_TEXTE_MODULE() + elif ct=="VIA": + return self.Cast_to_VIA() + elif ct=="TRACK": + return self.Cast_to_TRACK() + elif ct=="ZONE_CONTAINER": + return self.Cast_to_ZONE_CONTAINER() + else: + return None + + + def Duplicate(self): + + ct = self.GetClass() + + if ct=="BOARD": + return None + else: + return Cast_to_BOARD_ITEM(self.Clone()).Cast() + } } diff --git a/pcbnew/scripting/examples/listPcb.py b/pcbnew/scripting/examples/listPcb.py index c1904ad7a6..60ed093741 100755 --- a/pcbnew/scripting/examples/listPcb.py +++ b/pcbnew/scripting/examples/listPcb.py @@ -14,40 +14,40 @@ FromUnits = FromMM print "LISTING VIAS:" for item in pcb.GetTracks(): - if type(item) is VIA: + if type(item) is VIA: - pos = item.GetPosition() - drill = item.GetDrillValue() - width = item.GetWidth() - print " * Via: %s - %f/%f "%(ToUnits(pos),ToUnits(drill),ToUnits(width)) + pos = item.GetPosition() + drill = item.GetDrillValue() + width = item.GetWidth() + print " * Via: %s - %f/%f "%(ToUnits(pos),ToUnits(drill),ToUnits(width)) - elif type(item) is TRACK: + elif type(item) is TRACK: - start = item.GetStart() - end = item.GetEnd() - width = item.GetWidth() + start = item.GetStart() + end = item.GetEnd() + width = item.GetWidth() - print " * Track: %s to %s, width %f" % (ToUnits(start),ToUnits(end),ToUnits(width)) + print " * Track: %s to %s, width %f" % (ToUnits(start),ToUnits(end),ToUnits(width)) - else: - print "Unknown type %s" % type(item) + else: + print "Unknown type %s" % type(item) print "" print "LIST DRAWINGS:" for item in pcb.GetDrawings(): - if type(item) is TEXTE_PCB: - print "* Text: '%s' at %s"%(item.GetText(), item.GetPosition()) - elif type(item) is DRAWSEGMENT: - print "* Drawing: %s"%item.GetShapeStr() # dir(item) - else: - print type(item) + if type(item) is TEXTE_PCB: + print "* Text: '%s' at %s"%(item.GetText(), item.GetPosition()) + elif type(item) is DRAWSEGMENT: + print "* Drawing: %s"%item.GetShapeStr() # dir(item) + else: + print type(item) print "" print "LIST MODULES:" for module in pcb.GetModules(): - print "* Module: %s at %s"%(module.GetReference(),ToUnits(module.GetPosition())) + print "* Module: %s at %s"%(module.GetReference(),ToUnits(module.GetPosition())) print "" print "Ratsnest cnt:",len(pcb.GetFullRatsnest()) @@ -55,12 +55,12 @@ print "track w cnt:",len(pcb.GetTrackWidthList()) print "via s cnt:",len(pcb.GetViasDimensionsList()) print "" -print "LIST ZONES:" +print "LIST ZONES:", pcb.GetAreaCount() for idx in range(0, pcb.GetAreaCount()): zone=pcb.GetArea(idx) print "zone:", idx, "priority:", zone.GetPriority(), "netname", zone.GetNetname() print "" -print "NetClasses:", pcb.GetNetClasses().GetCount() +print "NetClasses:", pcb.GetNetClasses().GetCount(), diff --git a/pcbnew/scripting/examples/listPcbLibrary.py b/pcbnew/scripting/examples/listPcbLibrary.py index 928b3e0191..8262c17497 100755 --- a/pcbnew/scripting/examples/listPcbLibrary.py +++ b/pcbnew/scripting/examples/listPcbLibrary.py @@ -1,9 +1,12 @@ #!/usr/bin/env python from pcbnew import * + lst = FootprintEnumerate("/usr/share/kicad/modules/sockets.mod") + for name in lst: - m = FootprintLoad("/usr/share/kicad/modules/sockets.mod",name) - print name,"->",m.GetLibRef(), m.GetReference() - for p in m.Pads(): - print "\t",p.GetPadName(),p.GetPosition(),p.GetPos0(), p.GetOffset() - + m = FootprintLoad("/usr/share/kicad/modules/sockets.mod",name) + print name,"->",m.GetLibRef(), m.GetReference() + + for p in m.Pads(): + print "\t",p.GetPadName(),p.GetPosition(),p.GetPos0(), p.GetOffset() + diff --git a/pcbnew/scripting/module.i b/pcbnew/scripting/module.i index 54369486aa..95a42ccfca 100644 --- a/pcbnew/scripting/module.i +++ b/pcbnew/scripting/module.i @@ -29,81 +29,79 @@ %extend MODULE -{ +{ %pythoncode { - + #def SaveToLibrary(self,filename): # return SaveModuleToLibrary(filename,self) - + # # add function, clears the thisown to avoid python from deleting # the object in the garbage collector # - - def Add(self,item): - - itemC = item.Cast() - - if type(itemC) is D_PAD: - item.thisown=0 - self.Pads().PushBack(itemC) - elif type(itemC) in [ TEXTE_PCB, DIMENSION, TEXTE_MODULE, DRAWSEGMENT,EDGE_MODULE]: - item.thisown = 0 - self.GraphicalItems().PushBack(item) + + def Add(self,item): + + itemC = item.Cast() + + if type(itemC) is D_PAD: + item.thisown=0 + self.Pads().PushBack(itemC) + elif type(itemC) in [ TEXTE_PCB, DIMENSION, TEXTE_MODULE, DRAWSEGMENT,EDGE_MODULE]: + item.thisown = 0 + self.GraphicalItems().PushBack(item) } - + } -%pythoncode +%pythoncode { - -def GetPluginForPath(lpath): + + def GetPluginForPath(lpath): return IO_MGR.PluginFind(IO_MGR.LEGACY) - -def FootprintEnumerate(lpath): + + def FootprintEnumerate(lpath): plug = GetPluginForPath(lpath) return plug.FootprintEnumerate(lpath) - -def FootprintLoad(lpath,name): + + def FootprintLoad(lpath,name): plug = GetPluginForPath(lpath) return plug.FootprintLoad(lpath,name) - -def FootprintSave(lpath,module): - plug = GetPluginForPath(lpath) + + def FootprintSave(lpath,module): + plug = GetPluginForPath(lpath) return plug.FootprintSave(lpath,module) - -def FootprintDelete(lpath,name): + + def FootprintDelete(lpath,name): plug = GetPluginForPath(lpath) plug.FootprintDelete(lpath,name) - -def FootprintLibCreate(lpath): + + def FootprintLibCreate(lpath): plug = GetPluginForPath(lpath) plug.FootprintLibCreate(lpath) - -def FootprintLibDelete(lpath): + + def FootprintLibDelete(lpath): plug = GetPluginForPath(lpath) plug.FootprintLibDelete(lpath) - -def FootprintIsWritable(lpath): + + def FootprintIsWritable(lpath): plug = GetPluginForPath(lpath) plug.FootprintLibIsWritable(lpath) - - } %{ - MODULE *PyModule_to_MODULE(PyObject *obj0) + MODULE *PyModule_to_MODULE(PyObject *obj0) { void *argp; int res1 = SWIG_ConvertPtr(obj0, &argp,SWIGTYPE_p_MODULE, 0 | 0 ); - if (!SWIG_IsOK(res1)) + if (!SWIG_IsOK(res1)) { - SWIG_exception_fail(SWIG_ArgError(res1), "Converting object to MODULE*"); + SWIG_exception_fail(SWIG_ArgError(res1), "Converting object to MODULE*"); } - + return (MODULE*)argp; - + fail: return NULL; diff --git a/pcbnew/scripting/pcbnew.i b/pcbnew/scripting/pcbnew.i index 376028711b..6c50e1b3f1 100644 --- a/pcbnew/scripting/pcbnew.i +++ b/pcbnew/scripting/pcbnew.i @@ -155,7 +155,6 @@ %include %include - %include "board.i" %include "module.i" %include "plugins.i" diff --git a/pcbnew/scripting/tests/test1.py b/pcbnew/scripting/tests/test1.py index b507e33090..b1f7cffbf9 100644 --- a/pcbnew/scripting/tests/test1.py +++ b/pcbnew/scripting/tests/test1.py @@ -3,9 +3,9 @@ import pcbnew pcb = pcbnew.GetBoard() for m in pcb.GetModules(): - print m.GetPosition() - for p in m.GetPads() - print "p=>",p.GetPosition(),p.GetPadName() - print p.GetPosition() + print m.GetPosition() + for p in m.Pads(): + print "p=>",p.GetPosition(),p.GetPadName() + print p.GetPosition() diff --git a/pcbnew/scripting/tests/test2.py b/pcbnew/scripting/tests/test2.py index e14028c3dd..e925f88256 100644 --- a/pcbnew/scripting/tests/test2.py +++ b/pcbnew/scripting/tests/test2.py @@ -3,8 +3,6 @@ import pcbnew pcb = pcbnew.GetBoard() for m in pcb.GetModules(): - print m.GetReference(),"(",m.GetValue(),") at ", m.GetPosition() - for p in m.GetPads() - print " pad",p.GetPadName(), "at",p.GetPosition() - - + print m.GetReference(),"(",m.GetValue(),") at ", m.GetPosition() + for p in m.Pads(): + print " pad",p.GetPadName(), "at",p.GetPosition() diff --git a/scripting/kicad.i b/scripting/kicad.i index 59a1afcbab..c522b040e3 100644 --- a/scripting/kicad.i +++ b/scripting/kicad.i @@ -29,6 +29,7 @@ %include %include +%include /* ignore some constructors of EDA_ITEM that will make the build fail */ @@ -56,19 +57,19 @@ %{ #include - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include - #include - #include - #include + #include + #include + #include #include - #include - #include + #include + #include %}