Newbie Question - AvoidNodes

I’m using CustomSubGraphs with GoSimpleNodes as children within them. I’ve got GoLabeledLinks between the GoSimpleNodes. The links avoid the SimpleNodes but not the SubGraph Nodes. What I mean is that when a link is between two Simplenodes from different SubGraphs, the link does not avoid the SubGraphs between the Actual two SubGraphs that gets linked via their Simplenodes. I need the links to avoid the SubGraphs that are not part of the link.
Hope there is a simple solution for this problem
Any help will be highly appreciated.
Thank you

Hmmm. You can override GoDocument.IsAvoidable and GetAvoidableRectangle to customize what/where the document thinks should be avoided by links.
But it turns out that the code assumes recursing into GoSubGraphs is the right thing to do, so we can’t override those methods to look for GoSubGraphs. Instead, as a work-around, you can try:
public override bool IsAvoidable(GoObject obj) {
if (obj is GoSubGraphHandle)
return true;
return base.IsAvoidable(obj);
}
public override RectangleF GetAvoidableRectangle(GoObject obj) {
if (obj is GoSubGraphHandle) {
RectangleF rect = obj.Parent.Bounds;
obj.Parent.ExpandPaintBounds(rect, null);
return rect;
}
return base.GetAvoidableRectangle(obj);
}

Hi Walter
Thanks for all your help!
With the above code are you overriding the GoDocument. And If so does this mean I must create a my own GoDocument that inherits from GoDocument and then override the above methods.
Thank you

That’s right.
If you want, you can override GoView.CreateDocument to return a new instance of your document type. That way your view will automatically make use of your kind of document.
Or you can just set GoView.Document to an instance of your document class.
I think different samples do it different ways. As with most choices in GoDiagram, it just depends on how you want to architect your application. Having flexibility for organizing your code in various manners is very important for scaling your project, both for implementation and for maintainability.

Hi Walter
I don’t know if I’m doing something wrong or must include some more steps in order for the Labeled links to avoid the CustomGoSubGraphs. I’ve created a custom GoDocument and overrided the functions as indicated as listed below: I’ve set the GoView.Document to my new Custom Document Class as listed after my CustomDocument Class.
Interested to know why you use GoSubGraphHandle in the IsAvoidable
and GetAvoidableRectangle functions. However I tried GoSubGraph, this also didn’t work. Must I call these functions, IsAvoidable and GetAvoidableRectangle somewhere in my program?
Your help will be highly appreciated.
Thank you
Russell

Imports System
Imports System.Drawing
Imports Northwoods.Go
Namespace DiagramGUI
<Serializable()> Public Class CustomDocument
Inherits GoDocument
Public Sub New()
MyBase.New()
Me.Name = “SIPro User Interface”
Me.LinksLayer = Me.Layers.CreateNewLayerBefore(Me.Layers.Default)
''Me.MaintainsPartID = True
''Me.IsModified = False
End Sub
Public Overrides Function IsAvoidable(ByVal obj As GoObject) As Boolean
If (TypeOf obj Is GoSubGraphHandle) Then
Return True
Return MyBase.IsAvoidable(obj)
End If
End Function
Public Overrides Function GetAvoidableRectangle(ByVal obj As GoObject) As RectangleF
If (TypeOf obj Is GoSubGraphHandle) Then
Dim rect As RectangleF = New RectangleF
rect = obj.Parent.Bounds
obj.Parent.ExpandPaintBounds(rect, Nothing)
End If
End Function
End Class
End Namespace

Dim CustomDoc As CustomDocument = New CustomDocument
GoView1.Document = CustomDoc

Ahem, you don’t seem to be calling the base GetAvoidableRectangle method when the object isn’t a GoSubGraphHandle. In fact, you don’t seem to be returning any RectangleF at all, so how could that code compile?
Why a GoSubGraphHandle? Because I figured you were likely to have that as an easily distinguished child of a GoSubGraph. It would be better if you could look for a GoSubGraph instead, but these methods don’t get called then, since the document iterates over all of the objects and automatically recurses into GoSubGraphs. If this functionality were delegated to some method on GoObject instead of only being on GoDocument, then it would be easier to customize for each kind of object.

Hi Walter
My apologies for that oversite, the code is as you stated:
Public Overrides Function GetAvoidableRectangle(ByVal obj As GoObject) As RectangleF
If (TypeOf obj Is GoSubGraphHandle) Then
Dim rect As RectangleF = New RectangleF
rect = obj.Parent.Bounds
obj.Parent.ExpandPaintBounds(rect, Nothing)
return rect
Else
return mybase.GetAvoidableRectangle(obj)
End If
End Function
Interesting that the above code compiled as is…It seems to be working now?
However when I move a node (CustomSubGraph) the links don’t recalculate to avoid the Node.
Thank you for all your help
I think what will be most valuable in future is if your help will include examples of code implementing the property or method that is being explained, than just providing example applications.