Commit e6274f70 authored by jean-pierre charras's avatar jean-pierre charras

BOARD::Add(): fix an issue for tracks: parent not set (could be an issue only...

BOARD::Add(): fix an issue for tracks: parent not set (could be an issue only in python scripts, because the parent is set by the constructor)
*.i : fix coding style issues.
python method: add BOARD_ITEM Duplicate, which is a wrapper to Clone(). ( defined as Cast_to_BOARD_ITEM(selt.Clone()).Cast() )
update some .py examples.
parent 7c747c1a
...@@ -663,6 +663,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) ...@@ -663,6 +663,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl )
TRACK* insertAid; TRACK* insertAid;
insertAid = ( (TRACK*) aBoardItem )->GetBestInsertPoint( this ); insertAid = ( (TRACK*) aBoardItem )->GetBestInsertPoint( this );
m_Track.Insert( (TRACK*) aBoardItem, insertAid ); m_Track.Insert( (TRACK*) aBoardItem, insertAid );
aBoardItem->SetParent( this );
break; break;
case PCB_ZONE_T: case PCB_ZONE_T:
......
...@@ -804,7 +804,8 @@ void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src ) ...@@ -804,7 +804,8 @@ void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src )
SetTimeStamp( src->m_TimeStamp ); SetTimeStamp( src->m_TimeStamp );
m_Poly->RemoveAllContours(); m_Poly->RemoveAllContours();
m_Poly->Copy( src->m_Poly ); // copy outlines 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_ZoneClearance = src->m_ZoneClearance; // clearance value
m_ZoneMinThickness = src->m_ZoneMinThickness; m_ZoneMinThickness = src->m_ZoneMinThickness;
m_FillMode = src->m_FillMode; // Filling mode (segments/polygons) m_FillMode = src->m_FillMode; // Filling mode (segments/polygons)
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
def GetDrawings(self): return self.m_Drawings def GetDrawings(self): return self.m_Drawings
def GetTracks(self): return self.m_Track def GetTracks(self): return self.m_Track
def GetFullRatsnest(self): return self.m_FullRatsnest def GetFullRatsnest(self): return self.m_FullRatsnest
def GetZones(self): return self.m_ZoneDescriptorList
def Save(self,filename): def Save(self,filename):
return SaveBoard(filename,self,IO_MGR.KICAD) return SaveBoard(filename,self,IO_MGR.KICAD)
...@@ -47,8 +46,8 @@ ...@@ -47,8 +46,8 @@
# #
def Add(self,item): def Add(self,item):
item.thisown=0 item.thisown=0
self.AddNative(item) self.AddNative(item)
} }
} }
...@@ -75,44 +74,44 @@ ...@@ -75,44 +74,44 @@
%extend BOARD %extend BOARD
{ {
%pythoncode %pythoncode
{ {
def GetNetClasses(self): def GetNetClasses(self):
return self.GetDesignSettings().m_NetClasses return self.GetDesignSettings().m_NetClasses
def GetCurrentNetClassName(self): def GetCurrentNetClassName(self):
return self.GetDesignSettings().m_CurrentNetClassName return self.GetDesignSettings().m_CurrentNetClassName
def GetViasDimensionsList(self): def GetViasDimensionsList(self):
return self.GetDesignSettings().m_ViasDimensionsList return self.GetDesignSettings().m_ViasDimensionsList
def GetTrackWidthList(self): def GetTrackWidthList(self):
return self.GetDesignSettings().m_TrackWidthList return self.GetDesignSettings().m_TrackWidthList
} }
} }
%extend DRAWSEGMENT %extend DRAWSEGMENT
{ {
%pythoncode %pythoncode
{ {
def GetShapeStr(self): def GetShapeStr(self):
return self.ShowShape(self.GetShape()) return self.ShowShape(self.GetShape())
} }
} }
%extend BOARD_ITEM %extend BOARD_ITEM
{ {
%pythoncode %pythoncode
{ {
def SetPos(self,p): def SetPos(self,p):
self.SetPosition(p) self.SetPosition(p)
self.SetPos0(p) self.SetPos0(p)
def SetStartEnd(self,start,end): def SetStartEnd(self,start,end):
self.SetStart(start) self.SetStart(start)
self.SetStart0(start) self.SetStart0(start)
self.SetEnd(end) self.SetEnd(end)
self.SetEnd0(end) self.SetEnd0(end)
} }
} }
...@@ -32,54 +32,64 @@ ...@@ -32,54 +32,64 @@
%inline %inline
{ {
BOARD_ITEM* Cast_to_BOARD_ITEM(EDA_ITEM* base) { return dynamic_cast<BOARD_ITEM*>(base); } BOARD_ITEM* Cast_to_BOARD_ITEM(EDA_ITEM* base) { return dynamic_cast<BOARD_ITEM*>(base); }
} }
%extend BOARD_ITEM %extend BOARD_ITEM
{ {
TEXTE_PCB* Cast_to_TEXTE_PCB() { return dynamic_cast<TEXTE_PCB*>(self); } TEXTE_PCB* Cast_to_TEXTE_PCB() { return dynamic_cast<TEXTE_PCB*>(self); }
DIMENSION* Cast_to_DIMENSION() { return dynamic_cast<DIMENSION*>(self); } DIMENSION* Cast_to_DIMENSION() { return dynamic_cast<DIMENSION*>(self); }
MODULE* Cast_to_MODULE() { return dynamic_cast<MODULE*>(self); } MODULE* Cast_to_MODULE() { return dynamic_cast<MODULE*>(self); }
TEXTE_MODULE* Cast_to_TEXTE_MODULE() { return dynamic_cast<TEXTE_MODULE*>(self); } TEXTE_MODULE* Cast_to_TEXTE_MODULE() { return dynamic_cast<TEXTE_MODULE*>(self); }
DRAWSEGMENT* Cast_to_DRAWSEGMENT() { return dynamic_cast<DRAWSEGMENT*>(self); } DRAWSEGMENT* Cast_to_DRAWSEGMENT() { return dynamic_cast<DRAWSEGMENT*>(self); }
MARKER_PCB* Cast_to_MARKER_PCB() { return dynamic_cast<MARKER_PCB*>(self); } MARKER_PCB* Cast_to_MARKER_PCB() { return dynamic_cast<MARKER_PCB*>(self); }
BOARD* Cast_to_BOARD() { return dynamic_cast<BOARD*>(self); } BOARD* Cast_to_BOARD() { return dynamic_cast<BOARD*>(self); }
EDGE_MODULE* Cast_to_EDGE_MODULE() { return dynamic_cast<EDGE_MODULE*>(self); } EDGE_MODULE* Cast_to_EDGE_MODULE() { return dynamic_cast<EDGE_MODULE*>(self); }
D_PAD* Cast_to_D_PAD() { return dynamic_cast<D_PAD*>(self); } D_PAD* Cast_to_D_PAD() { return dynamic_cast<D_PAD*>(self); }
TRACK* Cast_to_TRACK() { return dynamic_cast<TRACK*>(self); } TRACK* Cast_to_TRACK() { return dynamic_cast<TRACK*>(self); }
ZONE_CONTAINER* Cast_to_ZONE_CONTAINER() { return dynamic_cast<ZONE_CONTAINER*>(self);} ZONE_CONTAINER* Cast_to_ZONE_CONTAINER() { return dynamic_cast<ZONE_CONTAINER*>(self);}
VIA* Cast_to_VIA() { return dynamic_cast<VIA*>(self); } VIA* Cast_to_VIA() { return dynamic_cast<VIA*>(self); }
%pythoncode %pythoncode
{ {
def Cast(self): def Cast(self):
ct = self.GetClass() ct = self.GetClass()
if ct=="PTEXT": if ct=="PTEXT":
return self.Cast_to_TEXTE_PCB() return self.Cast_to_TEXTE_PCB()
elif ct=="BOARD": elif ct=="BOARD":
return self.Cast_to_BOARD() return self.Cast_to_BOARD()
elif ct=="DIMENSION": elif ct=="DIMENSION":
return self.Cast_to_DIMENSION() return self.Cast_to_DIMENSION()
elif ct=="DRAWSEGMENT": elif ct=="DRAWSEGMENT":
return self.Cast_to_DRAWSEGMENT() return self.Cast_to_DRAWSEGMENT()
elif ct=="MGRAPHIC": elif ct=="MGRAPHIC":
return self.Cast_to_EDGE_MODULE() return self.Cast_to_EDGE_MODULE()
elif ct=="MODULE": elif ct=="MODULE":
return self.Cast_to_MODULE() return self.Cast_to_MODULE()
elif ct=="PAD": elif ct=="PAD":
return self.Cast_to_D_PAD() return self.Cast_to_D_PAD()
elif ct=="MTEXT": elif ct=="MTEXT":
return self.Cast_to_TEXTE_MODULE() return self.Cast_to_TEXTE_MODULE()
elif ct=="VIA": elif ct=="VIA":
return self.Cast_to_VIA() return self.Cast_to_VIA()
elif ct=="TRACK": elif ct=="TRACK":
return self.Cast_to_TRACK() return self.Cast_to_TRACK()
elif ct=="ZONE_CONTAINER": elif ct=="ZONE_CONTAINER":
return self.Cast_to_ZONE_CONTAINER() return self.Cast_to_ZONE_CONTAINER()
else: else:
return None return None
}
def Duplicate(self):
ct = self.GetClass()
if ct=="BOARD":
return None
else:
return Cast_to_BOARD_ITEM(self.Clone()).Cast()
}
} }
...@@ -14,40 +14,40 @@ FromUnits = FromMM ...@@ -14,40 +14,40 @@ FromUnits = FromMM
print "LISTING VIAS:" print "LISTING VIAS:"
for item in pcb.GetTracks(): for item in pcb.GetTracks():
if type(item) is VIA: if type(item) is VIA:
pos = item.GetPosition() pos = item.GetPosition()
drill = item.GetDrillValue() drill = item.GetDrillValue()
width = item.GetWidth() width = item.GetWidth()
print " * Via: %s - %f/%f "%(ToUnits(pos),ToUnits(drill),ToUnits(width)) print " * Via: %s - %f/%f "%(ToUnits(pos),ToUnits(drill),ToUnits(width))
elif type(item) is TRACK: elif type(item) is TRACK:
start = item.GetStart() start = item.GetStart()
end = item.GetEnd() end = item.GetEnd()
width = item.GetWidth() 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: else:
print "Unknown type %s" % type(item) print "Unknown type %s" % type(item)
print "" print ""
print "LIST DRAWINGS:" print "LIST DRAWINGS:"
for item in pcb.GetDrawings(): for item in pcb.GetDrawings():
if type(item) is TEXTE_PCB: if type(item) is TEXTE_PCB:
print "* Text: '%s' at %s"%(item.GetText(), item.GetPosition()) print "* Text: '%s' at %s"%(item.GetText(), item.GetPosition())
elif type(item) is DRAWSEGMENT: elif type(item) is DRAWSEGMENT:
print "* Drawing: %s"%item.GetShapeStr() # dir(item) print "* Drawing: %s"%item.GetShapeStr() # dir(item)
else: else:
print type(item) print type(item)
print "" print ""
print "LIST MODULES:" print "LIST MODULES:"
for module in pcb.GetModules(): 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 ""
print "Ratsnest cnt:",len(pcb.GetFullRatsnest()) print "Ratsnest cnt:",len(pcb.GetFullRatsnest())
...@@ -55,12 +55,12 @@ print "track w cnt:",len(pcb.GetTrackWidthList()) ...@@ -55,12 +55,12 @@ print "track w cnt:",len(pcb.GetTrackWidthList())
print "via s cnt:",len(pcb.GetViasDimensionsList()) print "via s cnt:",len(pcb.GetViasDimensionsList())
print "" print ""
print "LIST ZONES:" print "LIST ZONES:", pcb.GetAreaCount()
for idx in range(0, pcb.GetAreaCount()): for idx in range(0, pcb.GetAreaCount()):
zone=pcb.GetArea(idx) zone=pcb.GetArea(idx)
print "zone:", idx, "priority:", zone.GetPriority(), "netname", zone.GetNetname() print "zone:", idx, "priority:", zone.GetPriority(), "netname", zone.GetNetname()
print "" print ""
print "NetClasses:", pcb.GetNetClasses().GetCount() print "NetClasses:", pcb.GetNetClasses().GetCount(),
#!/usr/bin/env python #!/usr/bin/env python
from pcbnew import * from pcbnew import *
lst = FootprintEnumerate("/usr/share/kicad/modules/sockets.mod") lst = FootprintEnumerate("/usr/share/kicad/modules/sockets.mod")
for name in lst: for name in lst:
m = FootprintLoad("/usr/share/kicad/modules/sockets.mod",name) m = FootprintLoad("/usr/share/kicad/modules/sockets.mod",name)
print name,"->",m.GetLibRef(), m.GetReference() print name,"->",m.GetLibRef(), m.GetReference()
for p in m.Pads():
print "\t",p.GetPadName(),p.GetPosition(),p.GetPos0(), p.GetOffset() for p in m.Pads():
print "\t",p.GetPadName(),p.GetPosition(),p.GetPos0(), p.GetOffset()
...@@ -29,81 +29,79 @@ ...@@ -29,81 +29,79 @@
%extend MODULE %extend MODULE
{ {
%pythoncode %pythoncode
{ {
#def SaveToLibrary(self,filename): #def SaveToLibrary(self,filename):
# return SaveModuleToLibrary(filename,self) # return SaveModuleToLibrary(filename,self)
# #
# add function, clears the thisown to avoid python from deleting # add function, clears the thisown to avoid python from deleting
# the object in the garbage collector # the object in the garbage collector
# #
def Add(self,item): def Add(self,item):
itemC = item.Cast() itemC = item.Cast()
if type(itemC) is D_PAD: if type(itemC) is D_PAD:
item.thisown=0 item.thisown=0
self.Pads().PushBack(itemC) self.Pads().PushBack(itemC)
elif type(itemC) in [ TEXTE_PCB, DIMENSION, TEXTE_MODULE, DRAWSEGMENT,EDGE_MODULE]: elif type(itemC) in [ TEXTE_PCB, DIMENSION, TEXTE_MODULE, DRAWSEGMENT,EDGE_MODULE]:
item.thisown = 0 item.thisown = 0
self.GraphicalItems().PushBack(item) self.GraphicalItems().PushBack(item)
} }
} }
%pythoncode %pythoncode
{ {
def GetPluginForPath(lpath): def GetPluginForPath(lpath):
return IO_MGR.PluginFind(IO_MGR.LEGACY) return IO_MGR.PluginFind(IO_MGR.LEGACY)
def FootprintEnumerate(lpath): def FootprintEnumerate(lpath):
plug = GetPluginForPath(lpath) plug = GetPluginForPath(lpath)
return plug.FootprintEnumerate(lpath) return plug.FootprintEnumerate(lpath)
def FootprintLoad(lpath,name): def FootprintLoad(lpath,name):
plug = GetPluginForPath(lpath) plug = GetPluginForPath(lpath)
return plug.FootprintLoad(lpath,name) return plug.FootprintLoad(lpath,name)
def FootprintSave(lpath,module): def FootprintSave(lpath,module):
plug = GetPluginForPath(lpath) plug = GetPluginForPath(lpath)
return plug.FootprintSave(lpath,module) return plug.FootprintSave(lpath,module)
def FootprintDelete(lpath,name): def FootprintDelete(lpath,name):
plug = GetPluginForPath(lpath) plug = GetPluginForPath(lpath)
plug.FootprintDelete(lpath,name) plug.FootprintDelete(lpath,name)
def FootprintLibCreate(lpath): def FootprintLibCreate(lpath):
plug = GetPluginForPath(lpath) plug = GetPluginForPath(lpath)
plug.FootprintLibCreate(lpath) plug.FootprintLibCreate(lpath)
def FootprintLibDelete(lpath): def FootprintLibDelete(lpath):
plug = GetPluginForPath(lpath) plug = GetPluginForPath(lpath)
plug.FootprintLibDelete(lpath) plug.FootprintLibDelete(lpath)
def FootprintIsWritable(lpath): def FootprintIsWritable(lpath):
plug = GetPluginForPath(lpath) plug = GetPluginForPath(lpath)
plug.FootprintLibIsWritable(lpath) plug.FootprintLibIsWritable(lpath)
} }
%{ %{
MODULE *PyModule_to_MODULE(PyObject *obj0) MODULE *PyModule_to_MODULE(PyObject *obj0)
{ {
void *argp; void *argp;
int res1 = SWIG_ConvertPtr(obj0, &argp,SWIGTYPE_p_MODULE, 0 | 0 ); 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; return (MODULE*)argp;
fail: fail:
return NULL; return NULL;
......
...@@ -155,7 +155,6 @@ ...@@ -155,7 +155,6 @@
%include <io_mgr.h> %include <io_mgr.h>
%include <kicad_plugin.h> %include <kicad_plugin.h>
%include "board.i" %include "board.i"
%include "module.i" %include "module.i"
%include "plugins.i" %include "plugins.i"
......
...@@ -3,9 +3,9 @@ import pcbnew ...@@ -3,9 +3,9 @@ import pcbnew
pcb = pcbnew.GetBoard() pcb = pcbnew.GetBoard()
for m in pcb.GetModules(): for m in pcb.GetModules():
print m.GetPosition() print m.GetPosition()
for p in m.GetPads() for p in m.Pads():
print "p=>",p.GetPosition(),p.GetPadName() print "p=>",p.GetPosition(),p.GetPadName()
print p.GetPosition() print p.GetPosition()
...@@ -3,8 +3,6 @@ import pcbnew ...@@ -3,8 +3,6 @@ import pcbnew
pcb = pcbnew.GetBoard() pcb = pcbnew.GetBoard()
for m in pcb.GetModules(): for m in pcb.GetModules():
print m.GetReference(),"(",m.GetValue(),") at ", m.GetPosition() print m.GetReference(),"(",m.GetValue(),") at ", m.GetPosition()
for p in m.GetPads() for p in m.Pads():
print " pad",p.GetPadName(), "at",p.GetPosition() print " pad",p.GetPadName(), "at",p.GetPosition()
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
%include <std_vector.i> %include <std_vector.i>
%include <std_string.i> %include <std_string.i>
%include <std_map.i>
/* ignore some constructors of EDA_ITEM that will make the build fail */ /* ignore some constructors of EDA_ITEM that will make the build fail */
...@@ -56,19 +57,19 @@ ...@@ -56,19 +57,19 @@
%{ %{
#include <cstddef> #include <cstddef>
#include <dlist.h> #include <dlist.h>
#include <base_struct.h> #include <base_struct.h>
#include <common.h> #include <common.h>
#include <wx_python_helpers.h> #include <wx_python_helpers.h>
#include <cstddef> #include <cstddef>
#include <vector> #include <vector>
#include <class_title_block.h> #include <class_title_block.h>
#include <class_colors_design_settings.h> #include <class_colors_design_settings.h>
#include <class_marker_base.h> #include <class_marker_base.h>
#include <eda_text.h> #include <eda_text.h>
#include <convert_from_iu.h> #include <convert_from_iu.h>
#include <convert_to_biu.h> #include <convert_to_biu.h>
%} %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment