-
-
Notifications
You must be signed in to change notification settings - Fork 131
overwrite_duplicate not working with (use_current_library = True) #233
Description
When using new_cell with the option overwrite_duplicate = True and use_current_library = True
an ValueError [GDSPY] Cell named xxx already present in library occurs.
I'm not sure if it is caused by improper usage, I do multiple calls of
gdspy.current_library.new_cell(name="testDupl", overwrite_duplicate=True).
I think this is caused because inside new_cell function the first operation is to instantiate a new cell:
Lines 2299 to 2328 in 5234778
| def new_cell(self, name, overwrite_duplicate=False, update_references=True): | |
| """ | |
| Create a new cell and add it to this library. | |
| Parameters | |
| ---------- | |
| name : string | |
| Name of the cell. | |
| overwrite_duplicate : bool | |
| If True, an existing cell with the same name in the library | |
| will be overwritten. | |
| update_references : bool | |
| If True, `CellReference` and `CellArray` instances from an | |
| overwritten cell are updated to the new one (used only when | |
| `overwrite_duplicate` is True). | |
| Returns | |
| ------- | |
| out : `Cell` | |
| The created cell. | |
| Notes | |
| ----- | |
| This is equivalent to: | |
| >>> cell = gdspy.Cell(name) | |
| >>> lib.add(cell, False, overwrite_duplicate, update_references) | |
| """ | |
| cell = Cell(name) | |
| self.add(cell, False, overwrite_duplicate, update_references) | |
| return cell |
But inside the initializer of the new cell class the overwrite_duplicate is not passed to the current_library.add function.
Lines 104 to 115 in 5234778
| def __init__(self, name, exclude_from_current=False): | |
| self.name = name | |
| self.polygons = [] | |
| self.paths = [] | |
| self.labels = [] | |
| self.references = [] | |
| self._bb_valid = False | |
| self._bounding_box = None | |
| if use_current_library and not exclude_from_current: | |
| import gdspy | |
| gdspy.current_library.add(self, include_dependencies=False) |
My workaround to fix this was a modifcation the new_cell function as follows:
def new_cell(self, name, overwrite_duplicate=False, update_references=True):
if(overwrite_duplicate and use_current_library):
cell = Cell(name, exclude_from_current=True)
else:
cell = Cell(name)
self.add(cell, False, overwrite_duplicate, update_references)
return cell
Is this a bug or wrong usage?