migrate Board creation from Project > API. Project will be either removed or converted to PythonFeature if proper App::Part emulation can be firgured out.
This commit is contained in:
parent
d2bee101ea
commit
bdd7ea4684
2 changed files with 21 additions and 12 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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Add table
Reference in a new issue