Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthordavidnhutch
    • CommentTimeAug 20th 2016 edited
     

    I've only ever instanced Basic.TEXT PCells, and it's worked fine.

    Now I tried to instance some other PCells using the same method, and it's not working...

    See the final three lines below for the test cases. Can you please tell me why CIRCLE and ARC (and others) don't seem to work? I observe some black handles on the layout, but nothing on Layer 1 for CIRCLE and ARC.

    include RBA
    
    def place_pcell(lib_dot_pcell, cell, params)
    
      lib_str, pcell_str = lib_dot_pcell.split('.')
    
      lib = Library.library_by_name(lib_str)
      lib || raise("Unkown lib '#{lib_str}'")
    
      pcell_decl = lib.layout.pcell_declaration(pcell_str)
      pcell_decl || raise("Unknown PCell '#{pcell_str}'")  
    
      pv = pcell_decl.get_parameters.collect { |p| 
        params[p.name] || p.default 
      }
    
      pcell_var = cell.layout.add_pcell_variant(lib, pcell_decl.id, pv)
      trans = Trans.new(Trans::R0, 0, 0)
      cell.insert(CellInstArray.new(pcell_var, trans))
    end
    
    ##### START OF SCRIPT ###
    include RBA
    app = Application.instance
    mw = app.main_window
    lv = mw.current_view
    lv || raise("No view selected")
    ly = lv.active_cellview.layout
    dbu = ly.dbu
    cell = lv.active_cellview.cell
    
    layer = LayerInfo.new(1,0)
    text_params = { "layer" => layer, "text" => "KLAYOUT RULES", "mag" => 100 }
    circ_params = { "layer" => layer, "radius" => 10, "npoints" => 64 }
    arc_params = { "layer" => layer, "radius1" => 10, "radius2" => 12, "a1" => 0, "a2" => 90}
    
    place_pcell("Basic.TEXT", cell, text_params) # WORKS
    place_pcell("Basic.CIRCLE", cell, circ_params) # DOESN'T WORK
    place_pcell("Basic.ARC", cell, arc_params) # DOESN'T WORK
    
    • CommentAuthorMatthias
    • CommentTimeAug 21st 2016 edited
     

    Hi,

    thanks for that nicely prepared testcase.

    The solution is quite simple: the true parameters are not "radius" .. but "actual_radius" etc. The working code is:

    ...
    circ_params = { "layer" => layer, "actual_radius" => 10, "npoints" => 64 }
    arc_params = { "layer" => layer, "actual_radius1" => 10, "actual_radius2" => 12, "actual_start_angle" => 0, "actual_end_angle" => 90}
    ...
    

    The background is the following: the PCell's of the BASIC lib are intended to interactive use. They provide "handles" which can be moved with the mouse to adjust parameters. So basically there are two ways to manipulate the parameters: through the parameter page and through the handles. The handles are independent - there is no way currently to tie the handles (which are just points) to the derived parameters such as radius and angles. The PCell solves this problem by keeping three parameter sets: one for the parameters on the parameter page, one for the handles and a (hidden) parameter set for the parameters actually used. So if asked to update itself (upon "coerce"), it will check which parameter set has changed and update the actual parameters. From those parameters it will produce the shapes.

    Anyway, that just indicates that there is some magic behind PCells, specifically the Basic primitives. I wonder why people want to instantiate a Circle - it is probably the most difficult way to produce a circle. If you generate layout, then why not directly generate a circle? There is even a Polygon constructor for that purpose (Polygon#ellipse). Or you code it yourself: http://klayout.de/forum/comments.php?DiscussionID=562.

    Matthias

  1.  

    Thanks Matthias,

    You are right, in this case it's easier to code a circle myself. I was more reporting what I thought was a strange behavior, and unsure of where else (in more complicated scenarios) it would show up.

    I see now I was using the wrong parameter. Thanks!

    As a side-note, you mention placing a circle PCell is more coding than just drawing a circle itself. However, that need not be the case. I would think it would be really nice to implement something like my "place_pcell" method above, so PCells could be placed with just one line of code. For example if it was a method of the Cell class, to place a pcell inside cell 'cell' you'd just have to write

    cell.instance_pcell("Basic.ARC", arc_params)
    

    Perhaps a feature request for the API :-)

  2.  

    Hi David,

    since 0.24 there already is a similar function: It is accessible via a Layout object and called create_cell which takes the name and a parameter map (see the documentation for more info).

    By the way, some time ago I had pretty much the same idea/request, and this is where Matthias informed me about create_cell:

    http://klayout.de/forum/comments.php?DiscussionID=630&Focus=2844#Comment_2844

    I agree that having a method like place_pcell available on the Cell class would be even more convenient. This is probably even possible to add via Ruby, but I haven't tried that yet :-)