major rework of Board making bidirectional syncing more reliable

This commit is contained in:
Morgan 'ARR\!' Allen 2025-04-29 10:25:16 -07:00
parent 8c41e66a1a
commit e05f3f6a3c
5 changed files with 56 additions and 17 deletions

View file

@ -13,7 +13,8 @@ class BaseObject:
def execute(self, feature):
# TODO this might not be the right move
self.onDocumentRestored(feature)
print(self, 'BaseObject.execute')
#self.onDocumentRestored(feature)
def get_api(self):
p = self.feature

View file

@ -19,23 +19,52 @@ class BoardObject(BaseObject):
super(BoardObject, self).__init__(feature)
self.kicad_board = None
self.substrate_body = None
self.substrate_sketch = None
self.via_sketch = None
feature.addProperty('App::PropertyPlacement', 'BoardOffset', 'KiConnect', 'Internal offset for zeroing out Footprint offset', hidden=True, read_only=True)
def onDocumentRestored(self, feature):
def execute(self, feature):
if self.kicad_board is None:
self.kicad_board = self.get_api().kicad.get_board()
if self.substrate_body is None:
self.extrude_substrate(feature)
self.sketch_outline(feature)
if not self.substrate_body:
self.create_substrate_body()
if not self.substrate_sketch:
self.create_substrate_sketch()
self.sketch_outline()
def onDocumentRestored(self, feature):
super(BoardObject, self).onDocumentRestored(feature)
self.kicad_board = self.get_api().kicad.get_board()
@property
def substrate_body(self):
return self.feature.getObject('Substrate')
@property
def substrate_sketch(self):
return self.substrate_body.getObject('Sketch')
def create_substrate_body(self):
substrate_body = App.ActiveDocument.addObject('PartDesign::Body', 'Substrate')
self.feature.addObject(substrate_body)
def create_substrate_sketch(self):
substrate_sketch = App.ActiveDocument.addObject('Sketcher::SketchObject', 'Sketch')
substrate_sketch.Visibility = False
self.substrate_body.addObject(substrate_sketch)
pad = self.substrate_body.newObject('PartDesign::Pad', 'Outline')
pad.Profile = substrate_sketch
pad.Length = 1.6
pad.Midplane = True
if len(self.kicad_board.get_vias()) > 0 and self.via_sketch is None:
self.setup_vias()
self.pocket_vias()
def extrude_substrate(self, feature):
self.substrate_sketch = App.ActiveDocument.addObject('Sketcher::SketchObject', 'Sketch')
@ -95,7 +124,14 @@ class BoardObject(BaseObject):
via_pocket.Midplane = True
via_pocket.Type = 1
def sketch_outline(self, feature):
def sketch_outline(self, do_offset=True):
'''
Draws the Board outline fetched from the API
Parameters:
do_offset (bool): If offset should be recalcualted, typically this is undesired after calculated the first time. (Default: True)
'''
boardpoly = self.get_boardpoly()
poly = boardpoly.polygons[0]
@ -104,13 +140,15 @@ class BoardObject(BaseObject):
self.feature.PolygonId = boardpoly.id.value
# this offset centers the board to 0,0
bb = boardpoly.bounding_box()
self.feature.BoardOffset.Base = (App.Vector(bb.pos.x, -bb.pos.y) + App.Vector(bb.size.x, -bb.size.y) / 2) / 1000000.0
if do_offset:
bb = boardpoly.bounding_box()
self.feature.BoardOffset.Base = (App.Vector(bb.pos.x, -bb.pos.y) + App.Vector(bb.size.x, -bb.size.y) / 2) / 1000000.0
begin = None
start = None
# reset Sketch Geometry
# reset Sketch Constraints and Geometry
self.substrate_sketch.Constraints = []
self.substrate_sketch.Geometry = []
# sketch outline

View file

@ -8,7 +8,7 @@ from ..project import Project
class Reload:
def GetResources(self):
tooltip = '<p>Reload KiConnect Workbench for development.</p>'
tooltip = '<p>Reload KiConnect Workbench for development.\nNOTE: Does not reload toolbars.</p>'
iconFile = os.path.join(settings.ICONPATH, 'kiconnect.svg')
return {

View file

@ -22,7 +22,7 @@ class Sync:
boards = [ sel for sel in Gui.Selection.getSelection() if sel.Type == 'KiConnect::Board' ]
for board in boards:
board.KiConnBoard.sketch_outline()
board.Proxy.sketch_outline(do_offset=False)
App.ActiveDocument.recompute()

View file

@ -21,7 +21,7 @@ class Sync:
boards = [ sel for sel in Gui.Selection.getSelection() if sel.Type == 'KiConnect::Board' ]
for board in boards:
board.KiConnBoard.sync()
board.Proxy.sync()