Add Horizontal & Vertical alignement on toolbar

edited April 2015 in General
Hi everybody,


Thank you Matthias for this wonderful software.

I would like to know the simplest way to add icons for "Edit / select / Align / Alignment Options" in the toolbar directly. I mean the icons "Horizontal / Vertical Alignment" (left, center, right, top and bottom). I checked in the setup but there is no way.

Thank you in advance.

Comments

  • edited April 2015

    Copy this to a new .lym, press the orange Properties button, make it run on startup.

    "some_slug" identifies it in case you need that elsewhere. Note also that in order to find "edit_menu.selection_menu.align" I just went File > Setup > Key bindings.

    Lastly, note that menu.action("edit_menu.selection_menu.align").trigger is actually not perfectly future-proof -- it is possible that such slugs/paths may change in future versions (albeit probably unlikely in this case, but just to make a general statement...).

    include RBA
    app = Application.instance
    mw = app.main_window
    menu = mw.menu
    
    a = Action.new
    a.title = "Some title"
    a.icon = "file path" # If picture icon is desired, else delete this line
    a.on_triggered { menu.action("edit_menu.selection_menu.align").trigger }
    
    menu.insert_item("@toolbar.end", "some_slug", a)
    

    David

  • edited November -1
    Thank you David for your quick response.

    What I'm looking exactly is a shortcut (key or icon shortcut on the toolbar) for this functions (left, H_center, right, top, V_center and bottom).
    Your code is very important and usual for me, but I do already a key shortcut to the box of Align (Alt+A).

    Note: I sent you a email on your personal website asking you a copy of your "TheRedToolbar.zip", because the link is not working.

    Thank you for your help,

    euzada
  • edited November -1

    Hi euzada,

    there is no way to directly bind a flavor of the align function to a key. You can bind "Align" as a whole, but not the specific subfunction.

    It's possible to recode the functionality in a script but that will suffer from some issues - for example it's not possible to reliably maintain the selection. That's some effort and does not really provide a convenient solution.

    Matthias

  • edited November -1
    Hi Matthias,

    Thank you for your response.

    I thought about this option because I can not understand how to take advantage of the snap to object mode when I use Move tool. The snap works just with snap to grid, but not on objects.

    If, for example, I have two boxes (A & B) and I need to align the right side of box A to the left side of box b, (snap the right edge of box A to left edge of box B) does not work with me, hence the choice to use the shortcut of alignment.

    Note that I enabled the "Snap to other objects" in "Object Editor Options (F3)" and also in "setup / snapping" I activate "Snap to edge / vertex" and the snap range = 8 pixel.

    Do you have any suggestion for me ?

    Thank you,

    euzada
  • edited April 2015

    Hi euzada,

    I believe "Snap to objects" works for, and is only intended for, drawing new shapes, not for snapping existing shapes to other existing shapes. Meaning, when it is turned on, the first click and subsequent clicks for drawing boxes, paths, polygons, will snap to underlying existing shapes.

    On the one hand, I can understand why you want this functionality, in fact it is a thought I have had before, I think it could be useful, and I don't believe it's impossible to include in KLayout, depending on Matthias's opinion and desire to include it.

    But on the other hand, it's actually a hard problem. Maybe not extremely hard algorithmically, but hard in all but simple cases to get inside the user's brain to know what to snap to what.

    For example, say you have two boxes, one moving over the other. Problem is easy. But what if you have polygons, one with N=10 vertices and the other with M=10 vertices? Then you have N*M=100 potential snapping points if you just include the ability to snap one point to another. But if you also want to be able to snap edges to edges, you have many more snapping points (depending on how many edges are parallel between the two shapes). If you also want to be able to snap points to edges or vice-versa, there could be a continuum of places to snap to. But to the user it's very clear that they want to snap this gigantic edge to that gigantic edge. The computer has to entertain each possibility with equal likelihood though.

    Probably a bigger issue - I believe for any of the above cases there could be ambiguities: the shapes could equally well snap to one location as to another (neither is preferred - so which to choose?).

    It gets further complicated - what if you are just trying to align two boxes, but there are a lot of other shapes on other layers nearby? The box would be snapping all over the place with equal likelihood of snapping to the other box where you want it.

    Anyway just some considerations.

    David

    P.S. I didn't get an email from you. Perhaps you didn't send it? My gmail addr is david.n.hutch

  • edited November -1

    Hi,

    David, thanks again for your valuable comments.

    To be frank, "snap to objects" is only a weak approximation. It will snap the mouse pointer to existing edges or vertices when moving the mouse. This applies to drawing (dragging of edges and vertices) and the partial edit mode (to some extend). It does not guarantee alignment of objects. There have to be much more options - for example snapping to a path's centerline, alignment of objects while moving them and so forth. That's probably a complex topic and strongly depends on the expectations you have. Consider someone drawing a path for a wire - when this path is supposed to attach to something, then the path end should snap to that location. There are many ways to snap a path's end - by centerline, by outline, by terminal vertex and so forth. Each serves a different purpose and which one is appropriate depends on your application or maybe the design rules you apply.

    So that feature has to be much more pronounced to meet your expectations. It's on my agenda, but not with high priority, to be honest.

    Matthias

Sign In or Register to comment.