Fix pcbnew drawings api

Add some basic tests
This commit is contained in:
qu1ck 2020-10-09 01:41:11 -07:00 committed by Ian McInerney
parent c40483d18a
commit e784743284
2 changed files with 36 additions and 11 deletions

View File

@ -134,10 +134,10 @@ static PCB_TARGET* Cast_to_PCB_TARGET( BOARD_ITEM* );
return Cast_to_CENTER_DIMENSION(self)
elif ct=="ORTHOGONAL_DIMENSION":
return Cast_to_ORTHOGONAL_DIMENSION(self)
elif ct=="DRAWSEGMENT":
elif ct=="PCB_SHAPE":
return Cast_to_PCB_SHAPE(self)
elif ct=="MGRAPHIC":
return Cast_to_FP_GRAPHIC(self)
return Cast_to_FP_SHAPE(self)
elif ct=="MODULE":
return Cast_to_MODULE(self)
elif ct=="PCB_GROUP":

View File

@ -40,6 +40,31 @@ class TestPCBLoad(unittest.TestCase):
def test_pcb_netcount(self):
self.assertEqual(self.pcb.GetNetCount(),51)
def test_pcb_shapes(self):
drawings = list(self.pcb.GetDrawings())
edge_cuts = [d for d in drawings if d.GetLayer() == pcbnew.Edge_Cuts]
coordinates = [[list(edge.GetStart()), list(edge.GetEnd())] for edge in edge_cuts]
expected_coordinates = [
[[88265000, 51816000], [188595000, 51816000]],
[[88265000, 131826000], [88265000, 51816000]],
[[188595000, 51816000], [188595000, 131826000]],
[[188595000, 131826000], [88265000, 131826000]]
]
self.assertEqual(sorted(coordinates), sorted(expected_coordinates))
def test_pcb_text(self):
drawings = list(self.pcb.GetDrawings())
text = [d for d in drawings if d.GetClass() == "PTEXT"]
self.verify_text(text[0], 173355000, 68453000, pcbnew.F_Cu,
u'Actionneur\nPiezo New Amp\nV02')
self.verify_text(text[1], 176149000, 64643000, pcbnew.B_Cu,
u'Actionneur\nPiezo New Amp\nV02')
def verify_text(self, text, x, y, layer, s):
self.assertEquals(list(text.GetPosition()), [x, y])
self.assertEquals(text.GetLayer(), layer)
self.assertEquals(text.GetText(), s)
#def test_interactive(self):
# code.interact(local=locals())