Skip to content

Commit

Permalink
Add test for existing groups and footprint membership in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
MitjaNemec committed Jun 6, 2023
1 parent 65fdbc1 commit da0a0bc
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion replicate_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,35 @@ def prepare_for_replication(self, level, settings):
# if needed filter them by group
self.src_drawings = self.get_drawings_for_replication(self.src_bounding_box, settings)

# get all the existing groups
groups = self.board.Groups()
g_names = []
for g in groups:
g_names.append(g.GetName())

# create groups for each destination layout if selected
if settings.group_layouts:
for sheet in self.dst_sheets:
dst_group_name = "Replicated Group {}".format(sheet)
# check if this group already exists
if dst_group_name in g_names:
raise LookupError(f"Destination group {dst_group_name} already exists")
dst_group = pcbnew.PCB_GROUP(None)
dst_group.SetName(dst_group_name)
self.board.Add(dst_group)
# store destination lauouts' groups
self.dst_groups.append(dst_group)

# check if any destination footprints are already members of some groups
for sheet in self.dst_sheets:
dst_sheet_fps = self.get_footprints_on_sheet(sheet)
for fp in dst_sheet_fps:
fp_group = fp.fp.GetParentGroup()
if fp_group != "Replicated Group {}".format(sheet):
raise LookupError(f"Destination footprint {fp} is a member of a different group. "
f"All destination plugin have either have to be members of destination group"
f" or no group at all.")

@staticmethod
def get_footprint_id(footprint):
path = footprint.GetPath().AsString().upper().replace('00000000-0000-0000-0000-0000', '').split("/")
Expand Down Expand Up @@ -873,7 +892,8 @@ def replicate_footprints(self, settings):
dst_fp.fp.SetZoneConnection(src_fp.fp.GetZoneConnection())

# add footprints to corresponding layout groups if selected
if settings.group_footprints:
# and if footprint is not already member of this group
if settings.group_footprints and dst_fp.fp.GetParentGroup() != self.dst_groups[st_index].GetName():

This comment has been minimized.

Copy link
@SiTLOOMS

SiTLOOMS Jun 22, 2023

Contributor

Will it ever be equal?
dst_fp.fp.GetParentGroup() should be something like <pcbnew.PCB_GROUP; proxy of <Swig Object of type 'PCB_GROUP *' at 0x000001EB1F0A9C60> > and
self.dst_groups[st_index].GetName()should be something like Replicated Group ['sheet_name']

This comment has been minimized.

Copy link
@MitjaNemec

MitjaNemec Jun 22, 2023

Author Owner

Yeah, I really have to add test example for grouping feature so that I can more thoroughly check this.

But it the dst_fp.fp.GetParentGroup() should probably be dst_fp.fp.GetParentGroup().GetName()

This comment has been minimized.

Copy link
@MitjaNemec

MitjaNemec Jun 22, 2023

Author Owner

thanks for spotting and letting me know

self.dst_groups[st_index].AddItem(dst_fp.fp)

# flip if dst anchor is flipped in regard to src anchor
Expand Down

0 comments on commit da0a0bc

Please sign in to comment.