Can not get rounded end by using pya.Path() command.

I used code like below.

obj = pya.Path(points, width, bgn_ext, end_ext, r)
print(obj) # (0,0;1,0;1,1;2,1) w=1 bx=1 ex=1 r=true

From the print result I get right result. But when I export it into KLayout. The end is still rectangular rather than round. Is this a bug?

Comments

  • edited December 2024

    I think it's not a bug.
    Maybe you saved it to a GDS file.

    The round end of a Path can be saved and drawn if and only if:
    (1) the output format is GDS
    (2) (if not zero) bgn_ext = end_ext = width/2

    See the experiments below.


    #--------------------------------------------------------------------------------------
    # Assumptions:
    #   1) A new design has been created with a top cell named "TOP" and dbu=0.001 [um].
    #   2) Two new layers L/D=1/0 and L/D=2/0 have also been added.
    #   3) Then, start the Macro Development tool to run this macro.
    #--------------------------------------------------------------------------------------
    import pya
    
    points  = [pya.Point(0,0), pya.Point(1,0), pya.Point(1,1), pya.Point(2,1)]
    width   = 1.0
    bgn_ext = 1.0
    end_ext = 1.0
    rndends = True
    path1   = pya.DPath(points, width, bgn_ext, end_ext, rndends)
    path2   = pya.DPath(points, width, width/2, width/2, rndends)
    print(path1)
    print(path2)
    
    layout_view = pya.Application.instance().main_window().current_view()
    layout      = layout_view.active_cellview().layout()
    top_cell    = layout.cell("TOP")
    layer_idx1  = layout.find_layer(1, 0)
    layer_idx2  = layout.find_layer(2, 0)
    top_cell.shapes(layer_idx1).insert(path1)
    top_cell.shapes(layer_idx2).insert(path2)
    layout_view.zoom_fit()
    
    layout.write("f2644.gds")
    layout.write("f2644.oas")
    



  • Oh! Thank you very much, bro. Your explanation is very clear to me.

    You deserve a small red flower from my side.

    Have a nice day.

  • @BigPanda To the perfect explanation of @sekigawa I can only add that in your original sample all the parameters are very small values. If you use Path, the coordinates are in database units - so they are integers and as the database unit is typically very small (fractions of nanometers), a width of 1 corresponds to a very small width.

    Furthermore, 1 cannot be divided by two for the extensions, so you cannot create a round-ended path with a width of 1 database units.

    There is some documentation about paths here: https://www.klayout.de/doc-qt5/programming/geometry_api.html#h2-266.

    Matthias

  • edited December 2024

    Thank you. I get it. So is there a way to change unit from dbu to um by using Python Script? I mean not by multiplying like 1e3 or something. What I really want is like a global unit control.

    1. When I created the empty layout, I set dbu=0.001 [um].
      This is equivalent to using the class Layout's setter:

    1. I first defined the four integer coordinates Point in the macro.


    1. Then, I created two DPath (not Path) instances by passing the integer Points, where
      DPath's constructor takes care of type-casting.
      In other words, DPath needs DPoints and knows how to construct them from Points.


    1. Thus, the initial integer 1 becomes 1.0 [um] == 1000 [dbu] in the layout.
      See the grid scale of the screenshots.
  • edited December 2024

    Sorry, I do not understand very well, for first step, how you set dbu = 0.001 um?

  • Here is a PyPI version...

    #--------------------------------------------------------------------------------------
    # Assumptions:
    #   1) You have the Python3 environment.
    #   2) You have installed the KLayout Python Module.
    #          (https://www.klayout.org/klayout-pypi/)
    #--------------------------------------------------------------------------------------
    import klayout.db as kdb  # import the KLayout Database Module
    
    # [1] Create a new layout and set the DBU to 0.001[um] = 1.0[nm]
    layout     = kdb.Layout()
    layout.dbu = 0.001 # <=== !!!
    
    # [2] Create a new cell "TOP"
    top_cell = layout.create_cell("TOP")
    
    # [3] Create two new layers
    layer_idx1 = layout.layer(1, 0)
    layer_idx2 = layout.layer(2, 0)
    
    # [4] Create two DPath objects
    points  = [kdb.Point(0,0), kdb.Point(1,0), kdb.Point(1,1), kdb.Point(2,1)]
    width   = 1.0
    bgn_ext = 1.0
    end_ext = 1.0
    rndends = True
    path1   = kdb.DPath(points, width, bgn_ext, end_ext, rndends)
    path2   = kdb.DPath(points, width, width/2, width/2, rndends)
    print(path1)
    print(path2)
    
    # [5] Insert the two DPath objects into the layout
    top_cell.shapes(layer_idx1).insert(path1)
    top_cell.shapes(layer_idx2).insert(path2)
    
    # [6] Export the layout to files
    layout.write("f2644-pypi.gds")
    layout.write("f2644-pypi.oas")
    
  • Thank you very much , you are so patient. Have a nice day! @sekigawa . Thank you for the same. @Matthias . Both of you are nice.

Sign In or Register to comment.