major rework of Board making bidirectional syncing more reliable
This commit is contained in:
parent
8c41e66a1a
commit
e05f3f6a3c
5 changed files with 56 additions and 17 deletions
|
@ -13,7 +13,8 @@ class BaseObject:
|
||||||
|
|
||||||
def execute(self, feature):
|
def execute(self, feature):
|
||||||
# TODO this might not be the right move
|
# TODO this might not be the right move
|
||||||
self.onDocumentRestored(feature)
|
print(self, 'BaseObject.execute')
|
||||||
|
#self.onDocumentRestored(feature)
|
||||||
|
|
||||||
def get_api(self):
|
def get_api(self):
|
||||||
p = self.feature
|
p = self.feature
|
||||||
|
|
|
@ -19,23 +19,52 @@ class BoardObject(BaseObject):
|
||||||
super(BoardObject, self).__init__(feature)
|
super(BoardObject, self).__init__(feature)
|
||||||
|
|
||||||
self.kicad_board = None
|
self.kicad_board = None
|
||||||
self.substrate_body = None
|
|
||||||
self.substrate_sketch = None
|
|
||||||
self.via_sketch = None
|
self.via_sketch = None
|
||||||
|
|
||||||
feature.addProperty('App::PropertyPlacement', 'BoardOffset', 'KiConnect', 'Internal offset for zeroing out Footprint offset', hidden=True, read_only=True)
|
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:
|
if self.kicad_board is None:
|
||||||
self.kicad_board = self.get_api().kicad.get_board()
|
self.kicad_board = self.get_api().kicad.get_board()
|
||||||
|
|
||||||
if self.substrate_body is None:
|
if not self.substrate_body:
|
||||||
self.extrude_substrate(feature)
|
self.create_substrate_body()
|
||||||
self.sketch_outline(feature)
|
|
||||||
|
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):
|
def extrude_substrate(self, feature):
|
||||||
self.substrate_sketch = App.ActiveDocument.addObject('Sketcher::SketchObject', 'Sketch')
|
self.substrate_sketch = App.ActiveDocument.addObject('Sketcher::SketchObject', 'Sketch')
|
||||||
|
@ -95,7 +124,14 @@ class BoardObject(BaseObject):
|
||||||
via_pocket.Midplane = True
|
via_pocket.Midplane = True
|
||||||
via_pocket.Type = 1
|
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()
|
boardpoly = self.get_boardpoly()
|
||||||
poly = boardpoly.polygons[0]
|
poly = boardpoly.polygons[0]
|
||||||
|
|
||||||
|
@ -104,13 +140,15 @@ class BoardObject(BaseObject):
|
||||||
self.feature.PolygonId = boardpoly.id.value
|
self.feature.PolygonId = boardpoly.id.value
|
||||||
|
|
||||||
# this offset centers the board to 0,0
|
# this offset centers the board to 0,0
|
||||||
bb = boardpoly.bounding_box()
|
if do_offset:
|
||||||
self.feature.BoardOffset.Base = (App.Vector(bb.pos.x, -bb.pos.y) + App.Vector(bb.size.x, -bb.size.y) / 2) / 1000000.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
|
||||||
|
|
||||||
begin = None
|
begin = None
|
||||||
start = None
|
start = None
|
||||||
|
|
||||||
# reset Sketch Geometry
|
# reset Sketch Constraints and Geometry
|
||||||
|
self.substrate_sketch.Constraints = []
|
||||||
self.substrate_sketch.Geometry = []
|
self.substrate_sketch.Geometry = []
|
||||||
|
|
||||||
# sketch outline
|
# sketch outline
|
||||||
|
|
|
@ -8,7 +8,7 @@ from ..project import Project
|
||||||
|
|
||||||
class Reload:
|
class Reload:
|
||||||
def GetResources(self):
|
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')
|
iconFile = os.path.join(settings.ICONPATH, 'kiconnect.svg')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Sync:
|
||||||
boards = [ sel for sel in Gui.Selection.getSelection() if sel.Type == 'KiConnect::Board' ]
|
boards = [ sel for sel in Gui.Selection.getSelection() if sel.Type == 'KiConnect::Board' ]
|
||||||
|
|
||||||
for board in boards:
|
for board in boards:
|
||||||
board.KiConnBoard.sketch_outline()
|
board.Proxy.sketch_outline(do_offset=False)
|
||||||
|
|
||||||
App.ActiveDocument.recompute()
|
App.ActiveDocument.recompute()
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Sync:
|
||||||
boards = [ sel for sel in Gui.Selection.getSelection() if sel.Type == 'KiConnect::Board' ]
|
boards = [ sel for sel in Gui.Selection.getSelection() if sel.Type == 'KiConnect::Board' ]
|
||||||
|
|
||||||
for board in boards:
|
for board in boards:
|
||||||
board.KiConnBoard.sync()
|
board.Proxy.sync()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue