Compare commits
6 commits
934aaaf354
...
6311cdef48
Author | SHA1 | Date | |
---|---|---|---|
|
6311cdef48 | ||
|
93eb0d0483 | ||
|
c85d038700 | ||
|
bdd7ea4684 | ||
|
d2bee101ea | ||
|
8e9d8d7a38 |
9 changed files with 67 additions and 43 deletions
|
@ -5,12 +5,14 @@ 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)
|
||||||
|
@ -23,19 +25,32 @@ 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):
|
||||||
|
@ -45,6 +60,11 @@ 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
|
||||||
|
|
|
@ -2,6 +2,8 @@ class BaseObject:
|
||||||
EXTENSIONS = []
|
EXTENSIONS = []
|
||||||
TYPE = None
|
TYPE = None
|
||||||
|
|
||||||
|
save_keys = []
|
||||||
|
|
||||||
def __init__(self, feature):
|
def __init__(self, feature):
|
||||||
self.feature = feature
|
self.feature = feature
|
||||||
|
|
||||||
|
@ -62,5 +64,21 @@ class BaseObject:
|
||||||
def sync_to(self):
|
def sync_to(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __getstate__(self):
|
def dumps(self):
|
||||||
return None
|
data = [ getattr(self, 'TYPE') ]
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
|
@ -16,12 +16,15 @@ 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.kicad_board = kicad_board
|
self.substrate_body = None
|
||||||
self.board_sketch = None
|
self.board_sketch = None
|
||||||
# TODO add this to FreeCAD Preferences and Property?
|
|
||||||
self.do_offset = True
|
self.kicad_board = kicad_board
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -32,6 +35,7 @@ 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()
|
||||||
|
|
||||||
|
@ -42,17 +46,8 @@ 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')
|
||||||
|
@ -148,7 +143,7 @@ class BoardObject(BaseObject):
|
||||||
poly = boardpoly.polygons[0]
|
poly = boardpoly.polygons[0]
|
||||||
poly.outline.clear()
|
poly.outline.clear()
|
||||||
|
|
||||||
geom = self.feature.getObject('Substrate').getObject('Sketch').Geometry
|
geom = self.feature.getObject('Substrate').getObject('BoardSketch').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:
|
||||||
|
@ -196,7 +191,7 @@ def makeBoard(parent, kicad_board, polygon):
|
||||||
|
|
||||||
Parts.makeParts(feature)
|
Parts.makeParts(feature)
|
||||||
|
|
||||||
return feature
|
return feature, feature.Proxy.polygon_id
|
||||||
|
|
||||||
def extract_polygons(board):
|
def extract_polygons(board):
|
||||||
# find polygons of Edge Cuts
|
# find polygons of Edge Cuts
|
||||||
|
|
|
@ -14,8 +14,12 @@ 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
|
||||||
|
@ -23,12 +27,6 @@ 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,
|
||||||
|
@ -45,12 +43,10 @@ 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
|
# board.get_shapes needs to be called to ensure polygons are actually up to date
|
||||||
for node in self.board_polygon.polygons[0].outline:
|
board_polygon = self.get_api().get_polygon(self.polygon_id)
|
||||||
|
|
||||||
|
for node in 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
|
||||||
|
@ -76,9 +72,6 @@ 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'
|
||||||
|
|
|
@ -28,17 +28,6 @@ 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()
|
||||||
|
|
9
freecad/kiconnect/resources/icons/kicad/CREDITS
Normal file
9
freecad/kiconnect/resources/icons/kicad/CREDITS
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
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
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Loading…
Add table
Reference in a new issue