Skip to content

Commit

Permalink
use proper information for center of text and center of footprint whe…
Browse files Browse the repository at this point in the history
…n positioning footprint text.

Fixes #35
  • Loading branch information
MitjaNemec committed Jan 24, 2023
1 parent 0941beb commit fcf7038
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion action_replicate_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def on_ok(self, event):
self.hl_items = []
pcbnew.Refresh()

self.logger.exception("Fatal error when running Replicate layoue plugin")
self.logger.exception("Fatal error when running Replicate layout plugin")
e_dlg = ErrorDialog(self)
e_dlg.ShowModal()
e_dlg.Destroy()
Expand Down
17 changes: 8 additions & 9 deletions replicate_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(self, board, src_anchor_fp_ref, update_func=update_progress):
self.src_anchor_fp_group = self.src_anchor_fp.fp.GetParentGroup().GetName()
else:
self.src_anchor_fp_group = None
# TODO check if there is any other footprint fit same ID as anchor footprint
# TODO check if there is any other footprint with same ID as anchor footprint

def parse_schematic_files(self, filename, dict_of_sheets):
with open(filename, encoding='utf-8') as f:
Expand Down Expand Up @@ -792,9 +792,10 @@ def replicate_footprints(self):

# convert to tuple of integers
new_pos = [int(x) for x in new_pos]
dst_fp_pos = pcbnew.wxPoint(*new_pos)
# place current footprint - only if current footprint is not also the anchor
if dst_fp.ref != dst_anchor_fp.ref:
dst_fp.fp.SetPosition(pcbnew.wxPoint(*new_pos))
dst_fp.fp.SetPosition(dst_fp_pos)

if dst_fp.fp.IsFlipped() != src_fp_flipped:
dst_fp.fp.Flip(dst_fp.fp.GetPosition(), False)
Expand All @@ -817,12 +818,12 @@ def replicate_footprints(self):
delta_angle = dst_anchor_fp_angle + src_anchor_fp_angle
dst_fp_rel_pos_rot = rotate_around_center([-src_fp_rel_pos[0], src_fp_rel_pos[1]],
-delta_angle)
dst_fp_rel_pos = dst_anchor_fp_position + pcbnew.wxPoint(dst_fp_rel_pos_rot[0],
dst_fp_rel_pos_rot[1])
dst_fp_pos = dst_anchor_fp_position + pcbnew.wxPoint(dst_fp_rel_pos_rot[0],
dst_fp_rel_pos_rot[1])
# also need to change the angle
dst_fp.fp.SetPosition(dst_fp_rel_pos)
dst_fp.fp.SetPosition(dst_fp_pos)
src_fp_flipped_orientation = flipped_angle(src_fp_orientation)
flipped_delta = flipped_angle(src_anchor_fp_angle)-dst_anchor_fp_angle
flipped_delta = flipped_angle(src_anchor_fp_angle) - dst_anchor_fp_angle
new_orientation = src_fp_flipped_orientation - flipped_delta
dst_fp.fp.SetOrientationDegrees(new_orientation)

Expand All @@ -848,11 +849,9 @@ def replicate_footprints(self):
for src_text in src_fp_text_items:
txt_index = src_fp_text_items.index(src_text)
src_txt_pos = src_text.GetPosition()
src_txt_rel_pos = src_txt_pos - src_fp.fp.GetBoundingBox(False, False).Centre()
src_txt_rel_pos = src_txt_pos - src_fp_pos
src_txt_orientation = src_text.GetTextAngle()
delta_angle = dst_fp_orientation - src_fp_orientation

dst_fp_pos = dst_fp.fp.GetBoundingBox(False, False).Centre()
dst_text = dst_fp_text_items[txt_index]

dst_text.SetLayer(src_text.GetLayer())
Expand Down
24 changes: 5 additions & 19 deletions test_replicate_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,15 @@ def test_file(in_filename, test_filename, src_anchor_fp_reference, level, sheets
return compare_boards(out_filename, test_filename)


@unittest.SkipTest
class myamigo_issue(unittest.TestCase):
def setUp(self):
os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "myamigo_issue"))

def test_inner(self):
logger.info("Testing text placement")
input_filename = 'V5_V6_Replicator_Test.kicad_pcb'
test_filename = input_filename.split('.')[0] + "_ref_inner" + ".kicad_pcb"
err = test_file(input_filename, test_filename, 'R1', level=0, sheets=(0, 1),
containing=False, remove=True, by_group=True)
# self.assertEqual(err, 0, "inner levels failed")


@unittest.SkipTest
class manotam_issue(unittest.TestCase):
class myamigo_35(unittest.TestCase):
def setUp(self):
os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "manotam_issue"))
os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "myamigo_35"))

def test_inner(self):
logger.info("Testing text placement")
input_filename = 'Test.kicad_pcb'
input_filename = 'Replicate_Text_Error.kicad_pcb'
test_filename = input_filename.split('.')[0] + "_ref_inner" + ".kicad_pcb"
err = test_file(input_filename, test_filename, 'C1', level=0, sheets=(0, 1),
err = test_file(input_filename, test_filename, 'J1', level=0, sheets=(0, 1),
containing=False, remove=True, by_group=True)
# self.assertEqual(err, 0, "inner levels failed")

Expand All @@ -118,6 +103,7 @@ def test_inner(self):
# self.assertEqual(err, 0, "inner levels failed")


@unittest.SkipTest
class TestOfficial(unittest.TestCase):
def setUp(self):
os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "replicate_layout_test_project"))
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.10
1.2.11

0 comments on commit fcf7038

Please sign in to comment.