Skip to content

Commit

Permalink
[Variants][Sub-PCBs] Avoid configuring a member with swig data
Browse files Browse the repository at this point in the history
It can't be cloned using deepcopy
  • Loading branch information
set-soft committed Sep 9, 2024
1 parent b4c421e commit 361b6aa
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions kibot/var_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ def config(self, parent):
self.is_zero(self.bry)):
raise KiPlotConfigurationError('No reference or rectangle specified for {} sub-PCB'.format(self.name))
self.add_units(('tlx', 'tly', 'brx', 'bry', 'tolerance'), self.units, convert=True)
self.board_rect = GS.create_eda_rect(self._tlx, self._tly, self._brx, self._bry)
if not self._tolerance and GS.ki5:
# KiCad 5 workaround: rounding issues generate 1 fm of error. So we change to 2 fm tolerance.
self._tolerance = 2
self.board_rect.Inflate(int(self._tolerance))

def get_separate_source(self):
if self.reference:
Expand Down Expand Up @@ -184,7 +182,7 @@ def _remove_items(self, iter):
if with_width:
width = m.GetWidth()
m.SetWidth(0)
if not self.board_rect.Contains(m.GetBoundingBox()):
if not self._board_rect.Contains(m.GetBoundingBox()):
GS.board.Remove(m)
self._removed.append(m)
if with_width:
Expand All @@ -196,14 +194,14 @@ def _remove_modules(self, iter, comps_hash):
We also check their position, not their BBox. """
for m in iter:
ref = m.GetReference()
if not self.board_rect.Contains(m.GetPosition()) or (self.strip_annotation and ref == self.reference):
if not self._board_rect.Contains(m.GetPosition()) or (self.strip_annotation and ref == self.reference):
GS.board.Remove(m)
self._removed.append(m)
if comps_hash:
self._excl_by_sub_pcb.add(ref)

def remove_outside(self, comps_hash):
""" Remove footprints, drawings, text and zones outside `board_rect` rectangle.
""" Remove footprints, drawings, text and zones outside `_board_rect` rectangle.
Keep them in a list to restore later. """
self._removed = []
self._remove_modules(GS.get_modules(), comps_hash)
Expand Down Expand Up @@ -305,26 +303,30 @@ def center_objects(self):
paper_center_x = GS.from_mm(pcb.paper_w/2)
paper_center_y = GS.from_mm(pcb.paper_h/2)
# Compute the offset to make it centered
self._moved = self.board_rect.GetCenter()
self._moved = self._board_rect.GetCenter()
self._moved.x = paper_center_x-self._moved.x
self._moved.y = paper_center_y-self._moved.y
self.move_objects()

def apply(self, comps_hash):
""" Apply the sub-PCB selection. """
self._excl_by_sub_pcb = set()
self._board_rect = GS.create_eda_rect(self._tlx, self._tly, self._brx, self._bry)
self._board_rect.Inflate(int(self._tolerance))
if self.tool == 'internal':
if self.reference:
# Get the rectangle containing the board edge pointed by the reference
self.board_rect = self.search_reference_rect(self.reference)
self.board_rect.Inflate(int(self._tolerance))
self._board_rect = self.search_reference_rect(self.reference)
self._board_rect.Inflate(int(self._tolerance))
# Using a rectangle
self.remove_outside(comps_hash)
# Center the PCB
self.center_objects()
else:
# Using KiKit:
self.separate_board(comps_hash)
# This can't be cloned
self._board_rect = None

def unload_board(self, comps_hash):
# Undo the sub-PCB: just reload the PCB
Expand Down

0 comments on commit 361b6aa

Please sign in to comment.