Compare commits

..

No commits in common. "6311cdef4811d5f02317ee783e9326e74ccf7fa7" and "934aaaf354a3f969d6180bdda288056902c0d48c" have entirely different histories.

9 changed files with 43 additions and 67 deletions

View file

@ -5,14 +5,12 @@ from kipy import KiCad
from kipy.proto.common.types import DocumentType from kipy.proto.common.types import DocumentType
from . import settings from . import settings
from . import board as Board
from .bases import BaseObject, BaseViewProvider from .bases import BaseObject, BaseViewProvider
class APIObject(BaseObject): class APIObject(BaseObject):
TYPE = 'KiConnect::API' TYPE = 'KiConnect::API'
def __init__(self, feature): def __init__(self, feature):
self.boards = {}
self.kicad = KiCad() self.kicad = KiCad()
super(APIObject, self).__init__(feature) super(APIObject, self).__init__(feature)
@ -25,32 +23,19 @@ class APIObject(BaseObject):
self.ping_connection(feature) self.ping_connection(feature)
self.kicad_board = self.kicad.get_board()
self.polygons = Board.extract_polygons(self.kicad_board)
for polygon in self.polygons:
board, polygon_id = Board.makeBoard(self.feature.getParent(), self.kicad_board, polygon)
self.boards[polygon_id] = board
def onDocumentRestored(self, feature): def onDocumentRestored(self, feature):
super(APIObject, self).onDocumentRestored(feature) super(APIObject, self).onDocumentRestored(feature)
self.kicad = KiCad() self.kicad = KiCad()
self.ping_connection(feature) self.ping_connection(feature)
if self.is_connected:
self.kicad_board = self.kicad.get_board()
self.polygons = Board.extract_polygons(self.kicad_board)
parent = feature.getParent() parent = feature.getParent()
if not parent: return if not parent: return
'''
# XXX This gets all of the KiConnect::Board features but then does nothing with them # XXX This gets all of the KiConnect::Board features but then does nothing with them
# future multi-board support? # future multi-board support?
boards = [ board for board in parent.Group if hasattr(board, 'Type') and board.Type == 'KiConnect::Board' ] boards = [ board for board in parent.Group if hasattr(board, 'Type') and board.Type == 'KiConnect::Board' ]
'''
@property @property
def is_connected(self): def is_connected(self):
@ -60,11 +45,6 @@ class APIObject(BaseObject):
return self.feature.Connected return self.feature.Connected
def get_polygon(self, polygon_id):
for p in self.polygons:
if p.id.value == polygon_id:
return p
def ping_connection(self, feature): def ping_connection(self, feature):
''' '''
Ping the KiCAD API to determine if it's connected Ping the KiCAD API to determine if it's connected

View file

@ -2,8 +2,6 @@ class BaseObject:
EXTENSIONS = [] EXTENSIONS = []
TYPE = None TYPE = None
save_keys = []
def __init__(self, feature): def __init__(self, feature):
self.feature = feature self.feature = feature
@ -64,21 +62,5 @@ class BaseObject:
def sync_to(self): def sync_to(self):
pass pass
def dumps(self): def __getstate__(self):
data = [ getattr(self, 'TYPE') ] return None
if len(self.save_keys) > 0:
for key in self.save_keys:
try:
data.append(getattr(self, key))
except Exception as e:
#XXX logging
print(e)
return tuple(data)
def loads(self, state):
self.Type = state[0]
for idx, key in enumerate(self.save_keys):
setattr(self, key, state[idx + 1])

View file

@ -16,15 +16,12 @@ from . import board_sketch as BoardSketch
class BoardObject(BaseObject): class BoardObject(BaseObject):
TYPE = 'KiConnect::Board' TYPE = 'KiConnect::Board'
save_keys = [ 'polygon_id' ]
def __init__(self, feature, kicad_board, board_polygon): def __init__(self, feature, kicad_board, board_polygon):
self.feature = feature self.feature = feature
self.substrate_body = None
self.board_sketch = None
self.kicad_board = kicad_board self.kicad_board = kicad_board
self.board_sketch = None
# TODO add this to FreeCAD Preferences and Property?
self.do_offset = True
# TODO needs to be resotred in onDocumentRestored # TODO needs to be resotred in onDocumentRestored
#self.board_polygon = board_polygon #self.board_polygon = board_polygon
self.polygon_id = board_polygon.id.value self.polygon_id = board_polygon.id.value
@ -35,7 +32,6 @@ class BoardObject(BaseObject):
self.feature.PolygonId = board_polygon.id.value self.feature.PolygonId = board_polygon.id.value
self.substrate_body = self.create_substrate_body()
self.board_sketch = BoardSketch.makeBoardSketch(self.substrate_body, kicad_board, board_polygon) self.board_sketch = BoardSketch.makeBoardSketch(self.substrate_body, kicad_board, board_polygon)
self.create_substrate_pad() self.create_substrate_pad()
@ -46,8 +42,17 @@ class BoardObject(BaseObject):
def onDocumentRestored(self, feature): def onDocumentRestored(self, feature):
super(BoardObject, self).onDocumentRestored(feature) super(BoardObject, self).onDocumentRestored(feature)
self.board_sketch = self.feature.getObject('BoardSketch')
self.kicad_board = self.get_api().kicad.get_board() self.kicad_board = self.get_api().kicad.get_board()
self.board_sketch = self.feature.getObject('Substrate').getObject('BoardSketch')
@property
def substrate_body(self):
body = self.feature.getObject('Substrate')
if not body:
body = self.create_substrate_body()
return body
def create_substrate_body(self): def create_substrate_body(self):
substrate_body = App.ActiveDocument.addObject('PartDesign::Body', 'Substrate') substrate_body = App.ActiveDocument.addObject('PartDesign::Body', 'Substrate')
@ -143,7 +148,7 @@ class BoardObject(BaseObject):
poly = boardpoly.polygons[0] poly = boardpoly.polygons[0]
poly.outline.clear() poly.outline.clear()
geom = self.feature.getObject('Substrate').getObject('BoardSketch').Geometry geom = self.feature.getObject('Substrate').getObject('Sketch').Geometry
segments = [l for l in geom if isinstance(l, Part.LineSegment)] segments = [l for l in geom if isinstance(l, Part.LineSegment)]
for line in segments: for line in segments:
@ -191,7 +196,7 @@ def makeBoard(parent, kicad_board, polygon):
Parts.makeParts(feature) Parts.makeParts(feature)
return feature, feature.Proxy.polygon_id return feature
def extract_polygons(board): def extract_polygons(board):
# find polygons of Edge Cuts # find polygons of Edge Cuts

View file

@ -14,12 +14,8 @@ from .bases import BaseObject, BaseViewProvider
class BoardSketchObject(BaseObject): class BoardSketchObject(BaseObject):
TYPE = 'KiConnect::BoardSketch' TYPE = 'KiConnect::BoardSketch'
save_keys = [ 'polygon_id' ]
def __init__(self, feature, kicad_board, board_polygon): def __init__(self, feature, kicad_board, board_polygon):
self.board_polygon = board_polygon self.board_polygon = board_polygon
self.polygon_id = board_polygon.id.value
super(BoardSketchObject, self).__init__(feature) super(BoardSketchObject, self).__init__(feature)
#feature.Visibility = False #feature.Visibility = False
@ -27,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,
@ -43,10 +45,12 @@ class BoardSketchObject(BaseObject):
feature = self.feature feature = self.feature
vectors = [] vectors = []
# board.get_shapes needs to be called to ensure polygons are actually up to date board = self.get_parent_board()
board_polygon = self.get_api().get_polygon(self.polygon_id) if board:
self.board_polygon = board.get_polygon(board.polygon_id)
for node in board_polygon.polygons[0].outline: # board.get_shapes needs to be called to ensure polygons are actually up to date
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))
self.feature.Vectors = vectors self.feature.Vectors = vectors
@ -72,6 +76,9 @@ class BoardSketchObject(BaseObject):
feature.recompute() feature.recompute()
def __getstate__(self):
return None
class BoardSketchViewProvider(BaseViewProvider): class BoardSketchViewProvider(BaseViewProvider):
TYPE = 'KiConnect::BoardSketch' TYPE = 'KiConnect::BoardSketch'
#ICON = 'board.svg' #ICON = 'board.svg'

View file

@ -28,6 +28,17 @@ class Project:
self.API = api.makeAPI(self.feature) self.API = api.makeAPI(self.feature)
if self.API.Proxy.is_connected and self.API.DocumentCount > 0:
kicad_board = self.API.Proxy.kicad.get_board()
polygons = Board.extract_polygons(kicad_board)
for polygon in polygons:
self.board = Board.makeBoard(self.feature, kicad_board, polygon)
#self.copper = Copper(kicad_board, self.board)
#self.board.feature.addObject(self.copper.feature)
feature.ProcessTime = time.time() - start_time feature.ProcessTime = time.time() - start_time
App.ActiveDocument.recompute() App.ActiveDocument.recompute()

View file

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View file

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View file

@ -1,9 +0,0 @@
ICONS:
Original KiCad Icon work by Inigo Zuluaga and Fabrizio Tappero among others
KiCad icons were redesigned in 2020 by Aleksandr Zyrianov
KiCad nightly icon reworked by Rafael Silva based on the 2020 redesign
License: CC-BY-SA 4.0

View file

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB