It looks like you're new here. If you want to get involved, click one of these buttons!
Hi Matthias,
Sorry to bother you again, I'm trying to extract text coordinate from a database, however encountered the transformation issue and have no idea how to solve it, could you please help to check where I made mistakes? thanks.
The partial codes:
(0..(layout.cells-1)).each do |ci|
cell = layout.cell(ci)
cell.shapes(l1).each do |shape|
text = shape.text
#position = text.trans.trans(text.trans.disp)*layout.dbu
position = (text.trans.disp)*layout.dbu
printf("%s (%.3f,%.3f)\n", text.string, position.x, position.y)
end
end
If I use the marked code, it would transfer the coordinate to a strange value.
If I use current code, it would show the coordinates of all texts with the same result.
chhung
Comments
Hi chhung,
I guess the problem is caused because when you multiply a Point object with a double value (the DBU), it still stays an integer coordinate point object.
For example:
But:
because 100 times 0.001 is 0.1 which will render 0 when rounded to integer. The same happens to 200 times 0.001.
To solve this, you could either scale both coordinates explicitly, i.e.
In that case, Ruby will convert the integers to floating-point itself.
Or you convert the "disp" attribute to a DPoint which uses floating-point coordinates:
Best regards,
Matthias
Hi Matthias,
The whole code as follow, I'd like to read the specified layer with text, and print all the coordinates of texts.
However the result of the code doesn't work as I think.
This code would extract all the text with the same coordinates like:
However all the coordinates could be display correctly in klayout properties window.
Best Regards,
chhung
Hi chhung,
first, I'd apply the changes suggested above. I'd also suggest to use Layout#each_cell to iterate over all cells and test for shape.is_text? before using shape.text.
But the reason for the problem appears to be something different. I suspect that the texts are in different cells and the coordinate you are looking for must be transformed into the top cell. Maybe the text coordinates are actually all the same but the cells they are in are instantiated differently. Can you confirm that, i.e. by printing the cell name before the texts?
Best regards,
Matthias
Hi Matthias,
I modified the codes as follow:
And it prints the results:
The layout hierarchy should be like:
I think I have to add a trans.trans to convert the coordinate of every text with their parent cell's coordinate, however I have no idea how to do that. @_@
Best Regards,
chhung
Hi chhung,
the easiest solution is to flatten the layout. After that there is no hierarchy and the text coordinates should correspond to the coordinates as seen from the top cell. But that modifies the layout and bloats up you data potentially.
A more convenient method is to use the RecursiveShapeIterator object. It is delivered by Layout#begin_shapes:
Best regards,
Matthias
Hi Matthias,
Really appreciate for your kindly help, I've solved this issue via your code.
I tried the flatten method and found the performance would be much slower than RecursiveShapeIterator, so it might be better use on small files.
About the t.disp.x and t.disp.y , I guess it's typo of t.trans.disp.x and y.
Anyway, thank you~
Best Regards,
chhung
Hi chhung,
you're right, it's t.trans.disp, not t.disp.
I corrected my post above already.
Thanks and best regards,
Matthias