Compare commits
No commits in common. "c76b49e7b9d2ab645dc349a9e2c29594462f7fe3" and "b191a28a0a2c73d21c5e6b8ef4406506a00adedb" have entirely different histories.
c76b49e7b9
...
b191a28a0a
4 changed files with 26 additions and 47 deletions
|
@ -13,7 +13,6 @@ class APIObject(BaseObject):
|
||||||
|
|
||||||
def __init__(self, feature):
|
def __init__(self, feature):
|
||||||
self.boards = {}
|
self.boards = {}
|
||||||
self.polygons = {}
|
|
||||||
self.kicad = KiCad()
|
self.kicad = KiCad()
|
||||||
|
|
||||||
super(APIObject, self).__init__(feature)
|
super(APIObject, self).__init__(feature)
|
||||||
|
@ -24,49 +23,34 @@ class APIObject(BaseObject):
|
||||||
|
|
||||||
self.onDocumentRestored(feature)
|
self.onDocumentRestored(feature)
|
||||||
|
|
||||||
self.ping_connection()
|
self.ping_connection(feature)
|
||||||
|
|
||||||
self.kicad_board = self.kicad.get_board()
|
self.kicad_board = self.kicad.get_board()
|
||||||
polygons = Board.extract_polygons(self.kicad_board)
|
self.polygons = Board.extract_polygons(self.kicad_board)
|
||||||
|
|
||||||
for polygon in polygons:
|
for polygon in self.polygons:
|
||||||
board, polygon_id = Board.makeBoard(self.feature.getParent(), self.kicad_board, polygon)
|
board, polygon_id = Board.makeBoard(self.feature.getParent(), self.kicad_board, polygon)
|
||||||
self.polygons[polygon_id] = polygon
|
|
||||||
self.boards[polygon_id] = board
|
self.boards[polygon_id] = board
|
||||||
|
|
||||||
def onDocumentRestored(self, feature):
|
def onDocumentRestored(self, feature):
|
||||||
super(APIObject, self).onDocumentRestored(feature)
|
super(APIObject, self).onDocumentRestored(feature)
|
||||||
|
|
||||||
if not hasattr(self, 'polygons'):
|
|
||||||
setattr(self, 'polygons', {})
|
|
||||||
|
|
||||||
if not hasattr(self, 'boards'):
|
|
||||||
setattr(self, 'boards', {})
|
|
||||||
|
|
||||||
self.kicad = KiCad()
|
self.kicad = KiCad()
|
||||||
self.refresh_polygons()
|
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
|
||||||
|
# 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' ]
|
||||||
|
'''
|
||||||
for board in boards:
|
|
||||||
print(board)
|
|
||||||
self.boards[board.PolygonId] = board
|
|
||||||
|
|
||||||
def refresh_polygons(self):
|
|
||||||
self.ping_connection()
|
|
||||||
|
|
||||||
if self.is_connected:
|
|
||||||
self.kicad_board = self.kicad.get_board()
|
|
||||||
polygons = Board.extract_polygons(self.kicad_board)
|
|
||||||
print('>', polygons)
|
|
||||||
|
|
||||||
for poly in polygons:
|
|
||||||
self.polygons[poly.id.value] = poly
|
|
||||||
else:
|
|
||||||
print('*****NOT CONNECTED')
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
|
@ -77,11 +61,11 @@ class APIObject(BaseObject):
|
||||||
return self.feature.Connected
|
return self.feature.Connected
|
||||||
|
|
||||||
def get_polygon(self, polygon_id):
|
def get_polygon(self, polygon_id):
|
||||||
print(polygon_id, self.polygons)
|
for p in self.polygons:
|
||||||
self.refresh_polygons()
|
if p.id.value == polygon_id:
|
||||||
return self.polygons.get(polygon_id)
|
return p
|
||||||
|
|
||||||
def ping_connection(self):
|
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
|
||||||
'''
|
'''
|
||||||
|
@ -92,25 +76,25 @@ class APIObject(BaseObject):
|
||||||
try:
|
try:
|
||||||
self.kicad.ping()
|
self.kicad.ping()
|
||||||
|
|
||||||
self.feature.Connected = True
|
feature.Connected = True
|
||||||
connection_status = 'Connected'
|
connection_status = 'Connected'
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.feature.Connected = False
|
feature.Connected = False
|
||||||
connection_status = 'Disconnected'
|
connection_status = 'Disconnected'
|
||||||
|
|
||||||
if self.feature.Connected:
|
if feature.Connected:
|
||||||
try:
|
try:
|
||||||
docs = self.kicad.get_open_documents(DocumentType.DOCTYPE_PCB)
|
docs = self.kicad.get_open_documents(DocumentType.DOCTYPE_PCB)
|
||||||
document_status = f'{len(docs)} Documents'
|
document_status = f'{len(docs)} Documents'
|
||||||
self.feature.DocumentCount = len(docs)
|
feature.DocumentCount = len(docs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
self.feature.DocumentCount = 0
|
feature.DocumentCount = 0
|
||||||
|
|
||||||
self.feature.Label2 = f'{connection_status} ({document_status})'
|
feature.Label2 = f'{connection_status} ({document_status})'
|
||||||
|
|
||||||
return self.feature.Connected
|
return feature.Connected
|
||||||
|
|
||||||
|
|
||||||
class APIViewProvider(BaseViewProvider):
|
class APIViewProvider(BaseViewProvider):
|
||||||
|
|
|
@ -18,6 +18,7 @@ class BaseViewProvider:
|
||||||
self.icon = ''
|
self.icon = ''
|
||||||
|
|
||||||
if self.ICON:
|
if self.ICON:
|
||||||
|
print('>', settings.ICONPATH, self.ICON, os.path.join(settings.ICONPATH, self.ICON))
|
||||||
self.icon = os.path.join(settings.ICONPATH, self.ICON)
|
self.icon = os.path.join(settings.ICONPATH, self.ICON)
|
||||||
|
|
||||||
viewprovider.Proxy = self
|
viewprovider.Proxy = self
|
||||||
|
@ -38,6 +39,7 @@ class BaseViewProvider:
|
||||||
Gui.Selection.clearSelection()
|
Gui.Selection.clearSelection()
|
||||||
|
|
||||||
def getIcon(self):
|
def getIcon(self):
|
||||||
|
print(self.icon)
|
||||||
return self.icon
|
return self.icon
|
||||||
|
|
||||||
def getDisplayModes(self,obj):
|
def getDisplayModes(self,obj):
|
||||||
|
|
|
@ -171,7 +171,6 @@ class BoardObject(BaseObject):
|
||||||
feature.addProperty('App::PropertyVectorList', 'Vectors', 'KiConnect', 'Internal offset for zeroing out Footprint offset', hidden=True)
|
feature.addProperty('App::PropertyVectorList', 'Vectors', 'KiConnect', 'Internal offset for zeroing out Footprint offset', hidden=True)
|
||||||
|
|
||||||
feature.Doc = kicad_board.name
|
feature.Doc = kicad_board.name
|
||||||
feature.Label2 = kicad_board.name
|
|
||||||
|
|
||||||
if not feature.Thickness:
|
if not feature.Thickness:
|
||||||
feature.Thickness = 1.6
|
feature.Thickness = 1.6
|
||||||
|
|
|
@ -11,9 +11,6 @@ from kipy.util.board_layer import BoardLayer
|
||||||
|
|
||||||
from .bases import BaseObject, BaseViewProvider
|
from .bases import BaseObject, BaseViewProvider
|
||||||
|
|
||||||
class BoardPolyNotFoundException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class BoardSketchObject(BaseObject):
|
class BoardSketchObject(BaseObject):
|
||||||
TYPE = 'KiConnect::BoardSketch'
|
TYPE = 'KiConnect::BoardSketch'
|
||||||
|
|
||||||
|
@ -49,9 +46,6 @@ class BoardSketchObject(BaseObject):
|
||||||
# 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
|
||||||
board_polygon = self.get_api().get_polygon(self.polygon_id)
|
board_polygon = self.get_api().get_polygon(self.polygon_id)
|
||||||
|
|
||||||
if not board_polygon:
|
|
||||||
raise BoardPolyNotFoundException('Board Polygon not found: ' + self.polygon_id)
|
|
||||||
|
|
||||||
for node in board_polygon.polygons[0].outline:
|
for node in board_polygon.polygons[0].outline:
|
||||||
vectors.append(self.point_to_vector(node.point))
|
vectors.append(self.point_to_vector(node.point))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue