It looks like you're new here. If you want to get involved, click one of these buttons!
Hi Matthias,
Thanks for creating a great layout viewing and editing tool.
One of the ways in which the editor could be improved is if there was a second cursor (shaped like a diamond or cross-hairs) that snapped to the grid so that one could see where a path or polygon's starting point will be.
I've perused the code and it seems that such behaviours are handled with ViewService objects (to catch mouse events) and ViewObjects (to draw dynamic objects on the canvas) - is this correct?
Can you provide any hints as to the general approach to take to implement this behaviour?
Thanks for any help.
Simon
Comments
Hi Simon,
thanks :-)
A good starting point for such an implementation is
ShapeEditService::do_mouse_move_inactive
inedtServiceImpl.cc
. This method gets called when the mouse is moved while there is no shape being drawn. The current implementation snaps the coordinates to the grid (or other vertices/edges) and displays the results in the status line.Regards,
Matthias
Hi Matthias,
It's taken a while to come back to this (only four years) but I've finally had a go and I'm a bit stuck.
Issue 1: I'm using the marker thing. All the other uses of it use what looks like a scaling of 1.0/layout().dbu(). When I try this in do_mouse_move_inactive, KLayout crashes. I'm guessing that layout().dbu() is returniong zero and it's a divide-by-zero issue. Is there something I need to do to make layout().dbu() return the correct answer and not zero?
Issue 2: I'm trying to draw a box around the snapped co-ordinates. I'd prefer a diamond but I'll get the box working first then upgrade. How to I offset the co-ordinates by a number of pixels rather than a number of (I assume) nano-meters? Otherwise the size of my box will change with zoom factor...
The code below doesn't crash but isn't doing anything at all it seems. I change the scale factor to 1.0 to avoid the crash but this is wrong. I attempt to make a box that's offset by 10nm from the cursor point by adding/subracting 10 from the x and y co-ordinates. I have no idea if I'm doing this wrong.
Thanks for any help with this.
Simon
Here is the code: