gdspy icon indicating copy to clipboard operation
gdspy copied to clipboard

overwrite_duplicate not working with (use_current_library = True)

Open userx14 opened this issue 1 year ago • 1 comments

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: https://github.com/heitzmann/gdspy/blob/5234778068e8d85dde955056517dd5f95379b6d4/gdspy/library.py#L2299-L2328

But inside the initializer of the new cell class the overwrite_duplicate is not passed to the current_library.add function. https://github.com/heitzmann/gdspy/blob/5234778068e8d85dde955056517dd5f95379b6d4/gdspy/library.py#L104-L115

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?

userx14 avatar Jul 08 '23 17:07 userx14