Skip to content

Commit

Permalink
cloning and lib_symbols/pins fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
psychogenic committed Feb 5, 2024
1 parent b03f2fa commit bbd23d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/skip/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,17 @@ def _cleanse_key(self, key:str):
def name_for(cls, element):
return None


@classmethod
def set_name_for(cls, to_name:str, element):
return None

def append(self, element):
super().append(element)
name_for = self.name_for(element)
if name_for is not None and len(name_for):
if name_for in self._named:
name_for = f'{name_for}_'
self.set_name_for(f'{name_for}_', element)
self.elementAdd(name_for, element)


Expand Down
19 changes: 18 additions & 1 deletion src/skip/eeschema/lib_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,31 @@ class LibSymbolsListWrapper(NamedElementCollection):
def __init__(self, pv:ParsedValue):
super().__init__(None, [], None)
self._pv = pv
self._libsyms_by_id = dict()
self._libsyms_attrib_names = []
for i in range(len(pv.children)):
c = LibSymbol(pv[i])
pv.children[i] = c
c_name = c.value
# c_clean = pv.toSafeAttributeKey(c_name)
self._libsyms_by_id[c_name] = c #
self._libsyms_attrib_names.append(pv[i].toSafeAttributeKey(c_name))
self.append(c)
self.elementAdd(c_name, c)


def __contains__(self, key):
return key in self._libsyms_by_id

def __getitem__(self, key:int):
'''
syms by id
'''
if key in self._libsyms_by_id:
return self._libsyms_by_id[key]


raise AttributeError(f'No {key} here')

def property_changed(self, name:str, to_value:str, from_value:str):
return # nothing to do

Expand Down
4 changes: 4 additions & 0 deletions src/skip/eeschema/schematic/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def __init__(self, parent, elements:list):
def name_for(cls, element):
return element.property.Reference.value


@classmethod
def set_name_for(cls, to_name:str, element):
element.property.Reference.value = to_name

def reference_startswith(self, prefix:str):
'''
Expand Down
9 changes: 4 additions & 5 deletions src/skip/sexp/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,17 @@ def clone(self):
wrappedClone = clonedObj.parent_top.wrap(clonedObj)

if self.parent is not None:
log.debug(f'Have parent of type{type(self.parent)}')
if hasattr(self.parent, 'children'):
log.debug(f'adding to children')
self.parent.children.append(clonedObj)
else:

# log.error(f'no chiiiwdwen children')
log.info(f'Object parent exists but has no children {self.parent}')
if hasattr(self.parent, self.entity_type):
ent_container = getattr(self.parent, self.entity_type)
if hasattr(ent_container, 'append'):
ent_container.append(clonedObj)
ent_container.append(wrappedClone)



Expand Down Expand Up @@ -572,9 +574,6 @@ def __dir__(self):
def __str__(self):
return str(self._pv)

def clone(self):
return self._pv.clone()


@property
def value(self):
Expand Down

0 comments on commit bbd23d1

Please sign in to comment.