Compare commits
No commits in common. "6311cdef4811d5f02317ee783e9326e74ccf7fa7" and "934aaaf354a3f969d6180bdda288056902c0d48c" have entirely different histories.
6311cdef48
...
934aaaf354
9 changed files with 43 additions and 67 deletions
|
@ -5,14 +5,12 @@ from kipy import KiCad
|
|||
from kipy.proto.common.types import DocumentType
|
||||
|
||||
from . import settings
|
||||
from . import board as Board
|
||||
from .bases import BaseObject, BaseViewProvider
|
||||
|
||||
class APIObject(BaseObject):
|
||||
TYPE = 'KiConnect::API'
|
||||
|
||||
def __init__(self, feature):
|
||||
self.boards = {}
|
||||
self.kicad = KiCad()
|
||||
|
||||
super(APIObject, self).__init__(feature)
|
||||
|
@ -25,32 +23,19 @@ class APIObject(BaseObject):
|
|||
|
||||
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):
|
||||
super(APIObject, self).onDocumentRestored(feature)
|
||||
|
||||
self.kicad = KiCad()
|
||||
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()
|
||||
if not parent: return
|
||||
|
||||
'''
|
||||
# XXX This gets all of the KiConnect::Board features but then does nothing with them
|
||||
# future multi-board support?
|
||||
boards = [ board for board in parent.Group if hasattr(board, 'Type') and board.Type == 'KiConnect::Board' ]
|
||||
'''
|
||||
|
||||
|
||||
@property
|
||||
def is_connected(self):
|
||||
|
@ -60,11 +45,6 @@ class APIObject(BaseObject):
|
|||
|
||||
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):
|
||||
'''
|
||||
Ping the KiCAD API to determine if it's connected
|
||||
|
|
|
@ -2,8 +2,6 @@ class BaseObject:
|
|||
EXTENSIONS = []
|
||||
TYPE = None
|
||||
|
||||
save_keys = []
|
||||
|
||||
def __init__(self, feature):
|
||||
self.feature = feature
|
||||
|
||||
|
@ -64,21 +62,5 @@ class BaseObject:
|
|||
def sync_to(self):
|
||||
pass
|
||||
|
||||
def dumps(self):
|
||||
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])
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
|
|
@ -16,15 +16,12 @@ from . import board_sketch as BoardSketch
|
|||
class BoardObject(BaseObject):
|
||||
TYPE = 'KiConnect::Board'
|
||||
|
||||
save_keys = [ 'polygon_id' ]
|
||||
|
||||
def __init__(self, feature, kicad_board, board_polygon):
|
||||
self.feature = feature
|
||||
self.substrate_body = None
|
||||
self.board_sketch = None
|
||||
|
||||
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
|
||||
#self.board_polygon = board_polygon
|
||||
self.polygon_id = board_polygon.id.value
|
||||
|
@ -35,7 +32,6 @@ class BoardObject(BaseObject):
|
|||
|
||||
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.create_substrate_pad()
|
||||
|
||||
|
@ -46,8 +42,17 @@ class BoardObject(BaseObject):
|
|||
def onDocumentRestored(self, feature):
|
||||
super(BoardObject, self).onDocumentRestored(feature)
|
||||
|
||||
self.board_sketch = self.feature.getObject('BoardSketch')
|
||||
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):
|
||||
substrate_body = App.ActiveDocument.addObject('PartDesign::Body', 'Substrate')
|
||||
|
@ -143,7 +148,7 @@ class BoardObject(BaseObject):
|
|||
poly = boardpoly.polygons[0]
|
||||
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)]
|
||||
|
||||
for line in segments:
|
||||
|
@ -191,7 +196,7 @@ def makeBoard(parent, kicad_board, polygon):
|
|||
|
||||
Parts.makeParts(feature)
|
||||
|
||||
return feature, feature.Proxy.polygon_id
|
||||
return feature
|
||||
|
||||
def extract_polygons(board):
|
||||
# find polygons of Edge Cuts
|
||||
|
|
|
@ -14,12 +14,8 @@ from .bases import BaseObject, BaseViewProvider
|
|||
class BoardSketchObject(BaseObject):
|
||||
TYPE = 'KiConnect::BoardSketch'
|
||||
|
||||
save_keys = [ 'polygon_id' ]
|
||||
|
||||
def __init__(self, feature, kicad_board, board_polygon):
|
||||
self.board_polygon = board_polygon
|
||||
self.polygon_id = board_polygon.id.value
|
||||
|
||||
super(BoardSketchObject, self).__init__(feature)
|
||||
|
||||
#feature.Visibility = False
|
||||
|
@ -27,6 +23,12 @@ class BoardSketchObject(BaseObject):
|
|||
def execute(self, feature):
|
||||
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):
|
||||
return (
|
||||
App.Vector(point.x,
|
||||
|
@ -43,10 +45,12 @@ class BoardSketchObject(BaseObject):
|
|||
feature = self.feature
|
||||
vectors = []
|
||||
|
||||
# board.get_shapes needs to be called to ensure polygons are actually up to date
|
||||
board_polygon = self.get_api().get_polygon(self.polygon_id)
|
||||
board = self.get_parent_board()
|
||||
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))
|
||||
|
||||
self.feature.Vectors = vectors
|
||||
|
@ -72,6 +76,9 @@ class BoardSketchObject(BaseObject):
|
|||
|
||||
feature.recompute()
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
class BoardSketchViewProvider(BaseViewProvider):
|
||||
TYPE = 'KiConnect::BoardSketch'
|
||||
#ICON = 'board.svg'
|
||||
|
|
|
@ -28,6 +28,17 @@ class Project:
|
|||
|
||||
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
|
||||
|
||||
App.ActiveDocument.recompute()
|
||||
|
|
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 |
|
@ -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
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
Loading…
Add table
Reference in a new issue