It looks like you're new here. If you want to get involved, click one of these buttons!
Hi,
A bit torn whether I should ask here or github. Since I assume that the (logic) error is on my side, I will post here as in that case it's more of a question.
I am a bit confused about the purpose of assign
(specifically this time about the one in db.Layout
this time). The docs say that "Assigns another object to self". But when looking at the following code, it seems that it rather does more or less what dup
does but with an existing layout object instead of creating a new one. Is that the intended behavior? If yes, maybe the docs should say more along the lines "Copies another object to self".
To illustrate my case more see the following, I would have assumed from the docs that the last case is False
since both ly
and ly2
should point to the same object.
>>> import klayout.db as kdb
>>> ly = kdb.Layout()
>>> ly
<klayout.dbcore.Layout object at 0x7f9ba978adf0>
>>> ly2 = kdb.Layout()
>>> ly2
<klayout.dbcore.Layout object at 0x7f9ba978af30>
>>> ly2.assign(ly)
<klayout.dbcore.Layout object at 0x7f9ba978af30>
>>> ly2
<klayout.dbcore.Layout object at 0x7f9ba978af30>
>>> ly2.create_cell("TOP")
<klayout.dbcore.Cell object at 0x7f9ba7afcaf0>
>>> ly2.cells()
1
>>> ly.cells()
0
>>> ly.cell("TOP")
>>> ly.cell("TOP") is None
True
My usecase is that I would like to overwrite the layout()
of a kdb.Library
and I would like to keep the initial layout object as it has some definitely legit added stuff in python . I understand that's not supported from KLayout, so no worries there about needing to change stuff if necessary.
Also, would it be possible to expose Layout.set_library
to python/ruby or does this only work during the constructor of the Library/Layout?
Best,
Sebastian
Comments
Hi Sebastian,
"assign" is actually kind of "dup" (deep copy), but clearing self first and overwriting it with a copy of the argument. So
Will clear "a" and overwrite it with a deep copy of "b".
Technically "assign" is the binding of "operator=(...)" of C++. It's a kind of "a = b" by value.
"set_library" is somewhat internal. It's used by the Library to tell "it's" Layout where it belongs to. But to change the Layout inside a Library, "assign" should be the right thing to do. If that is what you want.
Matthias