Compare commits

..

2 commits

Author SHA1 Message Date
Morgan 'ARR\!' Allen
b191a28a0a add save_keys functionality to BaseViewProvider (mixin?) and fixed icon loading 2025-07-10 12:11:46 -07:00
Morgan 'ARR\!' Allen
417a7065de small cleanup of README 2025-07-10 12:11:12 -07:00
3 changed files with 24 additions and 14 deletions

View file

@ -6,6 +6,7 @@ KiCAD 9 API Workbench
## What works ## What works
* Create board * Create board
* Bidirectional syncing
* Add Vias * Add Vias
* Add footprint pads * Add footprint pads
* Import footprint 3d models * Import footprint 3d models
@ -19,14 +20,11 @@ KiCAD 9 API Workbench
## In Progress / To be ported ## In Progress / To be ported
### Tracks ### Tracks
Tracks can be loaded and drawn as simple `LineSegment` but more work is needed to draw properly 'widthed', and particularly whilte trying to eliminate overlapping lines. Tracks can be loaded and drawn as simple `LineSegment` but more work is needed to draw properly 'widthed', and particularly while trying to eliminate overlapping lines.
### More Pad Shapes ### More Pad Shapes
Only rectangle get drawn right now, would like to figure out how to get Sketcher to do the heavy lifting Only rectangle get drawn right now, would like to figure out how to get Sketcher to do the heavy lifting
### Sync to KiCAD
In theory this code is mostly working but there seems to be an [issue in kicad-python](https://gitlab.com/kicad/code/kicad-python/-/issues/34)
## Plans ## Plans
### Add more board features ### Add more board features

View file

@ -17,9 +17,7 @@ class BaseObject:
self.sync_from() self.sync_from()
def execute(self, feature): def execute(self, feature):
# TODO this might not be the right move pass
print(self, 'BaseObject.execute')
#self.onDocumentRestored(feature)
def get_api(self): def get_api(self):
p = self.feature p = self.feature

View file

@ -9,6 +9,8 @@ class BaseViewProvider:
TYPE = None TYPE = None
EXTENSIONS = [] EXTENSIONS = []
save_keys = []
def __init__(self, viewprovider): def __init__(self, viewprovider):
self.viewprovider = viewprovider self.viewprovider = viewprovider
self.feature = viewprovider.Object.Proxy.feature self.feature = viewprovider.Object.Proxy.feature
@ -16,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
@ -36,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):
@ -46,11 +50,21 @@ class BaseViewProvider:
'''Return the name of the default display mode. It must be defined in getDisplayModes.''' '''Return the name of the default display mode. It must be defined in getDisplayModes.'''
return 'Standard' return 'Standard'
def __getstate__(self): def dumps(self):
return { data = [ getattr(self, 'icon') ]
'icon': self.icon
}
def __setstate__(self, props): if len(self.save_keys) > 0:
for prop in props: for key in self.save_keys:
setattr(self, prop, props[prop]) try:
data.append(getattr(self, key))
except Exception as e:
#XXX logging
print(e)
return tuple(data)
def loads(self, state):
self.icon = state[0]
for idx, key in enumerate(self.save_keys):
setattr(self, key, state[idx + 1])