Dances with Layers


Four ‘simple’ questions:

  1. I need to have several layers with different types of ports and links. I need to be able to toggle separate layers with all their links and ports. The problem is when I move a port to another layer using GoLayer.AddCollection() the port appears in the upper left corner of the view, it behaves like a separete object, not part of a node (all nodes are on Default layer). How can I move ports to different layers still being able to treat the node with the ports as single object?

  2. I created a completely custom node (derived from GoNode). I overrode LayoutChildren() and used main shape’s position as reference for placing the children (ports, other shapes). I made this shape SelectionObject, because when the whole node was selected, moving it caused the children from the right and bottom edges to move all around the document - probably the node size changed before all children were moved together with it. Now I have a different problem - when I’m pressing Delete key, only the shape is deleted, not the whole node. What am I doing wrong?

  3. How can I copy link path from one link to the other? I want some links to appear on different layers. Short stupid example: a USB cable is both data cable and power cable (it delivers power to the connected device), so it should appear on data layer and on power layer and both links should have precisely the same path so that when the user hides data layer, the link should be still there, but with different style and color.

  4. How can I align newly inserted node with the grid? The user doubleclicks the grid and a new node appears, but not aligned with the grid. I have to move it manually to align it with the grid.

  1. All the parts of an object are necessarily in the same layer as the top-level object. So moving the port from being a child of a node to be a top-level object in a layer caused it to be removed from that node, so the node’s LayoutChildren method no longer has the port to position as it desires.
It is possible to keep the position of multiple top-level objects in sync. But before you implement that code, perhaps it would be easier to just change the Visible property or the Style of your ports to make them disappear and reappear. Set the GoPort.Style to Hidden if you don't want the port to have any appearance, but still want it to participate in linking operations, for example.
2. You forgot to set Selectable to false on that main shape.
3. A GoLink is a GoStroke, so you can set all the points by doing:
4. In your GoView.BackgroundDoubleClick event handler, when you create the node and add it to the view's Document, you can find the nearest grid point by calling GoView.SnapPoint.
Or you can just make sure your new node is selected (in the GoView.Selection) and then call GoView.MoveSelection, which will snap the object's Location to be at the closest grid point.

Everything works. Thanks a lot!