Skip to content

Commit

Permalink
chore: cleanup footprint position
Browse files Browse the repository at this point in the history
  • Loading branch information
bennymeg committed Apr 25, 2024
1 parent 05e10eb commit 28ea32f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions plugins/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,24 @@ def generate_netlist(self, temp_dir):

def _get_footprint_position(self, footprint):
"""Calculate position based on center of bounding box."""
if footprint.GetAttributes() & pcbnew.FP_SMD:
return footprint.GetPosition()
if footprint.GetAttributes() & pcbnew.FP_THROUGH_HOLE:
return footprint.GetBoundingBox(False, False).GetCenter()

# handle Unspecified footprint type
pads = footprint.Pads()
# get bounding box based on pads only to ignore non-copper layers, e.g. silkscreen
bbox = pads[0].GetBoundingBox() # start with small bounding box
for pad in pads:
bbox.Merge(pad.GetBoundingBox()) # expand bounding box
return bbox.GetCenter()
position = footprint.GetPosition()
attributes = footprint.GetAttributes()

if attributes & pcbnew.FP_SMD:
position = footprint.GetPosition()
elif attributes & pcbnew.FP_THROUGH_HOLE:
position = footprint.GetBoundingBox(False, False).GetCenter()
else: # handle Unspecified footprint type
pads = footprint.Pads()
if len(pads) > 0:
# get bounding box based on pads only to ignore non-copper layers, e.g. silkscreen
bbox = pads[0].GetBoundingBox() # start with small bounding box
for pad in pads:
bbox.Merge(pad.GetBoundingBox()) # expand bounding box

position = bbox.GetCenter()

return position

def generate_tables(self, temp_dir, auto_translate, exclude_dnp):
'''Generate the data tables.'''
Expand Down Expand Up @@ -173,8 +179,9 @@ def generate_tables(self, temp_dir, auto_translate, exclude_dnp):
footprint_designators[footprint.GetReference()] -= 1

designator = "{}{}{}".format(footprint.GetReference(), "" if unique_id == "" else "_", unique_id)
mid_x = (self._get_footprint_position(footprint)[0] - self.board.GetDesignSettings().GetAuxOrigin()[0]) / 1000000.0
mid_y = (self._get_footprint_position(footprint)[1] - self.board.GetDesignSettings().GetAuxOrigin()[1]) * -1.0 / 1000000.0
position = self._get_footprint_position(footprint)
mid_x = (position[0] - self.board.GetDesignSettings().GetAuxOrigin()[0]) / 1000000.0
mid_y = (position[1] - self.board.GetDesignSettings().GetAuxOrigin()[1]) * -1.0 / 1000000.0
rotation = footprint.GetOrientation().AsDegrees() if hasattr(footprint.GetOrientation(), 'AsDegrees') else footprint.GetOrientation() / 10.0
rotation_offset_db = self._get_rotation_from_db(footprint_name) # internal database offset
rotation_offset_manual = self._get_rotation_offset_from_footprint(footprint) # explicated offset by the designer
Expand Down

0 comments on commit 28ea32f

Please sign in to comment.