Additional selection lines

Hi,
we are working with GoDiagram for years and now have the following problem. If you have huge graphs at a small scale, the selection handles are not really visible any more (see pictury below).

To highlight the selected object (primary selection only) we want to add additional horizonat and vertical lines as shown in the picture below.

These lines should be drawn across the complete view area. Please can you point me in the correct direction of implementing this feature.

Kind regards
Iggy

I’ll look at this on Monday.

Is the primary selection object a node or a link?

The primary selection object can be a node, a link, a port or a subgraph.

OK… assuming this is something like a GoBasicNode that has a “SelectionObject”, you would extend the GoShape that is the Shape of the node.

  [Serializable]
  public class CustomTreeEllipse : GoEllipse
  {
    public override void AddSelectionHandles(GoSelection sel, GoObject selectedObj)
    {
      base.AddSelectionHandles(sel, selectedObj);

      if (selectedObj == sel.Primary)
      {
        // vertical
        IGoHandle h1 = sel.CreateBoundingHandle(this, selectedObj);
        GoShape h1s = h1.GoObject as GoShape;
        if (h1s != null)
        {
          h1s.Pen = Pens.Red;
          h1s.Bounds = new RectangleF(selectedObj.Center.X, selectedObj.Center.Y - 1000, 1, 2000);
        }

        // horizontal
        IGoHandle h2 = sel.CreateBoundingHandle(this, selectedObj);
        GoShape h2s = h2.GoObject as GoShape;
        if (h2s != null)
        {
          h2s.Pen = Pens.Red;
          h2s.Bounds = new RectangleF(selectedObj.Center.X-1000, selectedObj.Center.Y, 2000, 1);
        }
      }

    }
  }

and you would override CreateShape in the node class to create such a Shape object:

  [Serializable]
  public class CustomTreeBasicNode : GoBasicNode
  {
    protected override GoShape CreateShape(GoPort p)
    {
      // create the bigger circle/ellipse around and behind the port
      GoShape e = new CustomTreeEllipse();
      SizeF psize = p.Size;
      e.Size = new SizeF(psize.Width + 2 * margin.Width,
                         psize.Height + 2 * margin.Height);
      e.Selectable = false;
      e.Resizable = false;
      e.Reshapable = false;
      e.Brush = Brushes.White;
      return e;
    }
    private static readonly SizeF margin = new SizeF(7, 7);
  }

note I’ve cheated on making the size of the red lines really be the width and height of the view, just using “+ and - 1000”. Zooming after selection isn’t going to change the size of the handle anyway.

Hi Jake,

thanks for your answer. I’ve choosen a similar but more general approach. I’ve extended GoSelection and overridden CreateBoundingHandle() and CreateResizeHandle() to add my additional lines (handles) if the current object is the primary selection.

The lines are implemented by deriving GoHandle and overriding Paint() and ExpandPaintBounds() in a way similar to your GoGrid implementation, so that the lines are always drawn across the whole view area, even on zooming and scrolling.

It works like a charm but I’ve found one problem (may be bug) when dragging the selection.

Normally the selection handles are hidden during dragging so that the additional lines will not cause any problems. But there is one situation where this is not the case. You can reproduce the issue with your SubGraphApp evalution sample. If you start the application and immediately start to drag one of the nodes (without clicking anywhere else before), you will see that the selection handle is not hidden. I think this is not correct.

Kind regards
Iggy

Well, that’s interesting. I see this in samples that are trying to track the selection for a property sheet, but not in simpler apps.

I don’t think my solution above has this issue, but it may be something about the app I’m testing it in.

Yes that is really interesting, because it happens only on some of your evaluation samples. You can observe the same behaviour if you open a previously saved graph with your “DrawDemo” application and immediately start to drag one of the shapes. The resize handles are not hidden.

Since the GoToolDragging.HideSelectionHandles property is set to true by default, the handles will always be recreated during dragging in this state. So I’ve modified your “SubGraphApp” evalution sample to use the following classes instead of the default classes.

private class GraphView : GoView
{
    public override GoSelection CreateSelection()
    {
        return new GraphSelection(this);
    }
}

private class GraphSelection : GoSelection
{
    public GraphSelection(GoView view)
        : base(view)
    {
    }

    private int counter = 0;

    public override IGoHandle CreateBoundingHandle(GoObject obj, GoObject selectedObj)
    {
        if(counter++ == 50)
        {
            throw new Exception();
        }

        return base.CreateBoundingHandle(obj, selectedObj);
    }
}

If you now start the application and start dragging one of the nodes the exception is thrown almost immediately and Shows the following stack trace:

OnPaint: System.Exception: An exception of type “System.Exception” was thrown.
at SubGraphApp.Form1.GraphSelection.CreateBoundingHandle(GoObject obj, GoObject selectedObj) in c:\Users\Iggy\Documents\GoDiagram Win 5.2.0.46\Samples\SubGraphApp\Form1.cs:row 1385.
at Northwoods.Go.GoObject.AddSelectionHandles(GoSelection sel, GoObject selectedObj)
at Northwoods.Go.GoView.UpdateDelayedSelectionHandles()
at Northwoods.Go.GoView.onPaintCanvas(PaintEventArgs evt)
at Northwoods.Go.GoView.OnPaint(PaintEventArgs evt)

I don’t know what the highlighted method does but may be this helps you to find the problem.

Kind regards
Iggy

Hi Jake,

do you have investigted the problem or do you not agree that this is a bug in GoDiagram?

Kind regards
Iggy

I’ll offer a workaround, since we just had a GoDiagram release and it will be a while before the next one.

In your Paint code… look at the goview.Tool and see if it is typeof(GoToolDragging). If it is, don’t do the red line painting.