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 )
TRACK* insertAid;
insertAid = ( (TRACK*) aBoardItem )->GetBestInsertPoint( this );
m_Track.Insert( (TRACK*) aBoardItem, insertAid );
aBoardItem->SetParent( this );
break;
case PCB_ZONE_T:
......
......@@ -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)
......
......@@ -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)
def SetStartEnd(self,start,end):
self.SetStart(start)
self.SetStart0(start)
self.SetEnd(end)
self.SetEnd0(end)
}
%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)
}
}
......@@ -32,54 +32,64 @@
%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
{
TEXTE_PCB* Cast_to_TEXTE_PCB() { return dynamic_cast<TEXTE_PCB*>(self); }
DIMENSION* Cast_to_DIMENSION() { return dynamic_cast<DIMENSION*>(self); }
MODULE* Cast_to_MODULE() { return dynamic_cast<MODULE*>(self); }
TEXTE_MODULE* Cast_to_TEXTE_MODULE() { return dynamic_cast<TEXTE_MODULE*>(self); }
DRAWSEGMENT* Cast_to_DRAWSEGMENT() { return dynamic_cast<DRAWSEGMENT*>(self); }
MARKER_PCB* Cast_to_MARKER_PCB() { return dynamic_cast<MARKER_PCB*>(self); }
BOARD* Cast_to_BOARD() { return dynamic_cast<BOARD*>(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); }
TRACK* Cast_to_TRACK() { return dynamic_cast<TRACK*>(self); }
ZONE_CONTAINER* Cast_to_ZONE_CONTAINER() { return dynamic_cast<ZONE_CONTAINER*>(self);}
VIA* Cast_to_VIA() { return dynamic_cast<VIA*>(self); }
TEXTE_PCB* Cast_to_TEXTE_PCB() { return dynamic_cast<TEXTE_PCB*>(self); }
DIMENSION* Cast_to_DIMENSION() { return dynamic_cast<DIMENSION*>(self); }
MODULE* Cast_to_MODULE() { return dynamic_cast<MODULE*>(self); }
TEXTE_MODULE* Cast_to_TEXTE_MODULE() { return dynamic_cast<TEXTE_MODULE*>(self); }
DRAWSEGMENT* Cast_to_DRAWSEGMENT() { return dynamic_cast<DRAWSEGMENT*>(self); }
MARKER_PCB* Cast_to_MARKER_PCB() { return dynamic_cast<MARKER_PCB*>(self); }
BOARD* Cast_to_BOARD() { return dynamic_cast<BOARD*>(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); }
TRACK* Cast_to_TRACK() { return dynamic_cast<TRACK*>(self); }
ZONE_CONTAINER* Cast_to_ZONE_CONTAINER() { return dynamic_cast<ZONE_CONTAINER*>(self);}
VIA* Cast_to_VIA() { return dynamic_cast<VIA*>(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()
}
}
......@@ -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(),
#!/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()
......@@ -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;
......
......@@ -155,7 +155,6 @@
%include <io_mgr.h>
%include <kicad_plugin.h>
%include "board.i"
%include "module.i"
%include "plugins.i"
......
......@@ -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()
......@@ -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()
......@@ -29,6 +29,7 @@
%include <std_vector.i>
%include <std_string.i>
%include <std_map.i>
/* ignore some constructors of EDA_ITEM that will make the build fail */
......@@ -56,19 +57,19 @@
%{
#include <cstddef>
#include <dlist.h>
#include <base_struct.h>
#include <common.h>
#include <wx_python_helpers.h>
#include <cstddef>
#include <vector>
#include <class_title_block.h>
#include <class_colors_design_settings.h>
#include <class_marker_base.h>
#include <dlist.h>
#include <base_struct.h>
#include <common.h>
#include <wx_python_helpers.h>
#include <cstddef>
#include <vector>
#include <class_title_block.h>
#include <class_colors_design_settings.h>
#include <class_marker_base.h>
#include <eda_text.h>
#include <convert_from_iu.h>
#include <convert_to_biu.h>
#include <convert_from_iu.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