How to use the location of labels to connect two ports (in Python scripting)

Hi,

I'm struggling with writing a Python script to draw paths between labeled ports (boxes). The labels are on top of the ports and I guess there should be a way to use the location of these labels as the location of the ports as well. What I would like to do is to extract the location of these labels and use them as two ends of a path that I want to draw between them.

Any suggestions?

Thanks in advance.

Comments

  • Hi, Mo!

    I think text method of Shape class should be used. It returns None or object of Text class that has methods to get coordinates.

  • @EugeneZelenko
    Thanks for your response. I have already used the Text Class to label the ports, and I can basically draw traces knowing the coordinates of each port. However, for each trace between two ports I need to calculate the coordinates of the ports, which does not make sense as it would be very time-consuming. Instead, if there was a way to use the labels (because there is a text associated with them) then simply I could make a path between the port with label 'X' and the port with label 'Y'.

    Hope this makes sense.

    Thank you!

  • It'll be useful if you'll create diagram of your layout. Where X/Y labels are located? In same layer/datatype or different one? You could also use user properties (see Shape's property, set_property methods) to identify ports or their coordinates instead of labels.

  • Not Python but can be converted



    # Enter your Ruby code here include RBA ly = RBA::Application::instance.main_window.current_view.active_cellview.layout layer = 9 datatype = 0 topcell = ly.top_cell.name input = ly.layer_indices.find { |li| lp = ly.get_info(li); lp.layer == layer && lp.datatype = datatype } input || raise("Input layer not found") si = ly.cell(ly.cell_by_name(topcell)).begin_shapes_rec(input) texts = 0 # Display its string and xy location while !si.at_end? if si.shape.is_text? # If it's not a text then skip it bbox = si.shape.bbox.transformed(si.trans) string = si.shape.text_string texts += 1 puts "#{texts}: #{topcell}, #{layer}\\#{datatype}, #{string}, #{'%.3f'%(bbox.center.x*ly.dbu)},#{'%.3f'%(bbox.center.y*ly.dbu)}" end si.next end
  • Thank you @EugeneZelenko and @tagger5896 for your suggestions. I will look into them and if I have any questions I will reach out to you.

  • It would be great if answers / examples came back as well....

  • @dick_freebird

    Let's see
    you could do the following below in the while statement add a array to capture the text name and x/y coords
    such as this , then process the saved array, then use a A* to route, that's another topic

    cords = Array.new
      # Display its string and xy location
      while !si.at_end? 
        if si.shape.is_text? # If it's not a text then skip it
           bbox = si.shape.bbox.transformed(si.trans)
           string = si.shape.text_string
           texts += 1
           x = bbox.center.x*ly.dbu
           y = bbox.center.y*ly.dbu
           cords  << [string,x,y]
           #puts "#{texts}: #{topcell}, #{layer}\\#{datatype}, #{string}, #{'%.3f'%(bbox.center.x*ly.dbu)},#{'%.3f'%(bbox.center.y*ly.dbu)}"
        end
        si.next
      end
    #Sort the Text names 
    srt = p cords.sort_by{|ar| ar.first.downcase}
    puts "#{srt}"
    
  • Update Proof of Concept Router to Ports using A*
    Discussion is here
    https://www.klayout.de/forum/discussion/1778/proof-of-concept-router-for-klayout#latest

  • edited March 2021

    Dear all,

    thanks to all for this discussion and the code.

    I'd like to add that extracting the coordinates of texts should not be time consuming. If the code above is too slow, you can specialize the RecursiveShapeIterator to only deliver texts:

    si.shape_flags = RBA::Shapes::STexts
    

    This way your loop will only visit texts (is_text? should not longer be necessary) and it should be quite fast.

    Matthias

Sign In or Register to comment.