Compare commits
6 commits
03fc42579f
...
205254a4f3
Author | SHA1 | Date | |
---|---|---|---|
|
205254a4f3 | ||
|
6137b50208 | ||
|
0a95b5529e | ||
|
a162b98000 | ||
|
c61020242d | ||
|
638fda2daf |
6 changed files with 27 additions and 16 deletions
|
@ -54,7 +54,7 @@ class BaseObject:
|
||||||
self.feature.addExtension(ext)
|
self.feature.addExtension(ext)
|
||||||
|
|
||||||
def setup_properties(self, feature):
|
def setup_properties(self, feature):
|
||||||
feature.addProperty('App::PropertyString', 'Type', 'KiConnect', 'Internal KiConnect Type', read_only=True, hidden=True)
|
feature.addProperty('App::PropertyString', 'Type', 'KiConnect', 'Internal KiConnect Type', hidden=True)
|
||||||
|
|
||||||
def sync_from(self):
|
def sync_from(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -19,6 +19,7 @@ class BoardObject(BaseObject):
|
||||||
def __init__(self, feature, kicad_board, board_polygon):
|
def __init__(self, feature, kicad_board, board_polygon):
|
||||||
self.feature = feature
|
self.feature = feature
|
||||||
self.kicad_board = kicad_board
|
self.kicad_board = kicad_board
|
||||||
|
self.board_sketch = None
|
||||||
# TODO add this to FreeCAD Preferences and Property?
|
# TODO add this to FreeCAD Preferences and Property?
|
||||||
self.do_offset = True
|
self.do_offset = True
|
||||||
# TODO needs to be resotred in onDocumentRestored
|
# TODO needs to be resotred in onDocumentRestored
|
||||||
|
@ -72,6 +73,9 @@ class BoardObject(BaseObject):
|
||||||
|
|
||||||
return self.board_sketch
|
return self.board_sketch
|
||||||
|
|
||||||
|
def get_polygon(self, kiid):
|
||||||
|
return [ s for s in self.kicad_board.get_shapes() if s.id.value == kiid ][0]
|
||||||
|
|
||||||
def get_boardpoly(self):
|
def get_boardpoly(self):
|
||||||
# TODO remove in favor of extract_polygons class method
|
# TODO remove in favor of extract_polygons class method
|
||||||
board = self.kicad_board
|
board = self.kicad_board
|
||||||
|
@ -128,17 +132,8 @@ class BoardObject(BaseObject):
|
||||||
Pulls outline from KiCAD PolygonBoard and saves points as Vectors
|
Pulls outline from KiCAD PolygonBoard and saves points as Vectors
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# bit of a quick hack to keep the board in one place, needs more testing
|
if self.board_sketch:
|
||||||
if self.do_offset and not self.feature.BoardOffset:
|
self.board_sketch.Proxy.sync_from()
|
||||||
bb = self.board_polygon.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
|
|
||||||
|
|
||||||
vectors = []
|
|
||||||
|
|
||||||
for node in self.board_polygon.polygons[0].outline:
|
|
||||||
vectors.append(self.point_to_vector(node.point))
|
|
||||||
|
|
||||||
self.feature.Vectors = vectors
|
|
||||||
|
|
||||||
def sync_to(self):
|
def sync_to(self):
|
||||||
board = self.kicad_board
|
board = self.kicad_board
|
||||||
|
|
|
@ -23,6 +23,12 @@ class BoardSketchObject(BaseObject):
|
||||||
def execute(self, feature):
|
def execute(self, feature):
|
||||||
feature.recompute()
|
feature.recompute()
|
||||||
|
|
||||||
|
def get_parent_board(self):
|
||||||
|
try:
|
||||||
|
return self.feature.getParent().getParent().Proxy
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
def point_to_vector(self, point, offset=True):
|
def point_to_vector(self, point, offset=True):
|
||||||
return (
|
return (
|
||||||
App.Vector(point.x,
|
App.Vector(point.x,
|
||||||
|
@ -39,6 +45,11 @@ class BoardSketchObject(BaseObject):
|
||||||
feature = self.feature
|
feature = self.feature
|
||||||
vectors = []
|
vectors = []
|
||||||
|
|
||||||
|
board = self.get_parent_board()
|
||||||
|
if board:
|
||||||
|
self.board_polygon = board.get_polygon(board.polygon_id)
|
||||||
|
|
||||||
|
# board.get_shapes needs to be called to ensure polygons are actually up to date
|
||||||
for node in self.board_polygon.polygons[0].outline:
|
for node in self.board_polygon.polygons[0].outline:
|
||||||
vectors.append(self.point_to_vector(node.point))
|
vectors.append(self.point_to_vector(node.point))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
|
|
||||||
class Syncable:
|
class Syncable:
|
||||||
SYNCABLES = [ 'KiConnect::Project', 'KiConnect::Board', 'KiConnect::Parts', 'KiConnect::BoardBody', ]
|
SYNCABLES = [ 'KiConnect::Project', 'KiConnect::Board', 'KiConnect::Parts', 'KiConnect::BoardBody', 'KiConnect::BoardSketch' ]
|
||||||
|
|
||||||
def IsActive(self):
|
def IsActive(self):
|
||||||
sel = Gui.Selection.getSelection()
|
sel = Gui.Selection.getSelection()
|
||||||
|
@ -41,3 +42,5 @@ class Syncable:
|
||||||
getattr(feature, self.method)()
|
getattr(feature, self.method)()
|
||||||
|
|
||||||
s.recompute()
|
s.recompute()
|
||||||
|
|
||||||
|
App.ActiveDocument.recompute()
|
||||||
|
|
|
@ -15,12 +15,13 @@ from .bases import BaseObject, BaseViewProvider
|
||||||
class PartsObject(BaseObject):
|
class PartsObject(BaseObject):
|
||||||
TYPE = 'KiConnect::Parts'
|
TYPE = 'KiConnect::Parts'
|
||||||
|
|
||||||
|
def __init__(self, feature):
|
||||||
|
super(PartsObject, self).__init__(feature)
|
||||||
|
|
||||||
def execute(self, feature):
|
def execute(self, feature):
|
||||||
super(PartsObject, self).execute(feature)
|
super(PartsObject, self).execute(feature)
|
||||||
|
|
||||||
self.import_footprints()
|
def sync_from(self):
|
||||||
|
|
||||||
def import_footprints(self):
|
|
||||||
kiconn_board = self.feature.getParentGroup()
|
kiconn_board = self.feature.getParentGroup()
|
||||||
kicad_board = self.get_api().kicad.get_board()
|
kicad_board = self.get_api().kicad.get_board()
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Project:
|
||||||
kicad_board = self.API.Proxy.kicad.get_board()
|
kicad_board = self.API.Proxy.kicad.get_board()
|
||||||
|
|
||||||
polygons = Board.extract_polygons(kicad_board)
|
polygons = Board.extract_polygons(kicad_board)
|
||||||
|
|
||||||
for polygon in polygons:
|
for polygon in polygons:
|
||||||
self.board = Board.makeBoard(self.feature, kicad_board, polygon)
|
self.board = Board.makeBoard(self.feature, kicad_board, polygon)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue