How to measure cumulative length of selected lines

edited November 2014 in KLayout Support
Is there any option to fast measure the cumulative length of selected lines? For example a Serpent Length.
Thank you in advance.
Illia

Comments

  • edited November 2014

    Hi Illia,

    Such a function is not available, at least not directly.

    But it can be scripted.

    Here is a script which employs area and perimeter to approximate a length measure. It is precise for "thin" wires:

    # Computes the path length of all selected shapes.
    # The path length is approximated from the area and perimeter
    # using the following approach:
    #
    #   p = 2 * w + l1 + l2       (Perimeter)
    #   a = w * (l1 + l2) / 2     (Area)
    #   -> L = (l1 + l2) / 2 
    #        = p / 4 + sqrt(p * p / 16 - a)    (Center length)
    # 
    # This assumes a thin wire with width w and a left-side length 
    # of l1 and a right-side length of l2.
    
    lv = RBA::Application::instance.main_window.current_view
    lv || raise("No layout loaded")
    
    selected = RBA::Region::new
    cell = nil
    ly = nil
    dbu = nil
    lv.each_object_selected do |s|
      dbu ||= lv.cellview(s.cv_index).layout.dbu
      if !s.is_cell_inst?
        selected.insert(s.shape.polygon)
      end
    end
    
    selected.merge
    
    p = selected.perimeter * dbu
    a = selected.area * dbu * dbu
    l = p / 4 + Math.sqrt(p * p / 16 - a)
    RBA::QMessageBox::information(nil, "Approximate Length", "Area #{'%.12g'%a}, Perimeter #{'%.12g'%p} -> Length #{'%.12g'%l}")
    

    Matthias

  • edited November -1
    Then, how to select an highlighted net ?
    In next version, will it be possile to script the "highlight net" function ?

    Rgds,
    Laurent
  • edited November -1
    Hi Matthias
    Thank you for quick response
    Scrip fails for "Big/dense" structures with error:
    "bad allocation in Region::merge (class RuntimeError)"
    Thanks
    Illia
  • edited November -1

    Hi Illia,

    That means you have really big structures and KLayout runs out of memory.

    I guess that on a 32bit installation, KLayout will be able to handle structures as big as several 10M equivalent of rectangles. If you want to go further, you'll have to switch to 64bit and provide enough RAM for that.

    But I wonder whether it makes sense to compute line lengths for such structures. Are you sure that is a single wire? The algorithm only works if the structure is a thin wire without branches.

    Matthias

Sign In or Register to comment.