Lable On Link

Hi All

Have a happy new year !!
I am stuck on one requirement.
1-I need to have labels on the connecting links.Is this possible.
Here by i am attaching the 2 Images One is showing the current status
and 2nd image is showing what is the desired output.
Thanks
vineet

GoLabeledLink gives you a MidLabel, FromLabel and ToLabel that allows you to attach any GoObject to those 3 spots.

Do you want the label text to be angled along the link? (what you are doing with the 2 vertical labels has a couple of downsides -- one is the readability of vertical text and the other is the impact on the layout of the nodes...the label defines the minimum length of the link.)

http://www.nwoods.com/forum/forum_posts.asp?TID=272

First Thanks for replying

Do you want the label text to be angled along the link? Jake<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1-Yes

http://www.nwoods.com/forum/forum_posts.asp?TID=272

I have gone through the link and created the same classes in my project.

But I am not able to produce desired results. I have implemented the classes as under please guide me if I am doing anything wrong.

If possible please give me an example so that I can implement the same.

1 - Function CreateLabelledLink ()

Dim llnk As New GoLabeledLink()

Dim lRotateText As New App.RotatedText

lRotateText = “Hi there …Some text”

llnk.MidLabel = lRotateText

End function

This will always produce the labels in 90 degree static. My requirements is to set the label position according to link.

2 - Function CreateLabelledLink ()

Dim llnk As New GoLabeledLink()

Dim lRotateText As New App.RotatedText

Dim lRotateHolder As New App.RotatedHolder

lRotateHolder.RT.Text = “Hi there …Some text”

llnk.MidLabel = lRotateHolder.RT

End function

This function will generate the error on the RotatedText class

Dim ll As GoLabeledLink = CType(Me.Parent, GoLabeledLink)

Error : Not the valid parent. Parent is of type RotatedTextHolder

If possible please give me an example so that I can implement the same.

> This will always produce the labels in 90 degree static.
If you look at the code in the "Angle" method of rotated text, you will see the label will orient itself along the link if the parent of the RotatedText is a GoLabeledLink.
Create the label with this:
[code]
public static GoText MakeText(String s) {
GoText t = new RotatedText();
t.Alignment = GoObject.Middle;
t.Text = s;
t.Selectable = false;
t.Editable = true;
return t;
}
[/code]
In other words, don't use the RotatedHolder.
' ' * Copyright © Northwoods Software Corporation, 1998-2005. All Rights ' * Reserved. ' * ' * Restricted Rights: Use, duplication, or disclosure by the U.S. ' * Government is subject to restrictions as set forth in subparagraph ' * (c) (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR ' * 52.227-14 Alt. III, as applicable. ' */


Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports Northwoods.Go
Imports Northwoods.Go.Layout
Namespace App
<Serializable()> _
Public Class RotatedText
Inherits GoText
Public Sub New()
Me.Alignment = GoObject.Middle
End Sub
Public Overrides Sub Paint(ByVal g As Graphics, ByVal view As GoView)
Dim before As GraphicsState = g.Save()
Dim c As PointF = Me.Location
g.TranslateTransform(c.X, c.Y)
g.RotateTransform(Me.Angle)
g.TranslateTransform(-c.X, -c.Y)
MyBase.Paint(g, view)
g.Restore(before)
End Sub
Public Overrides Function ExpandPaintBounds(ByVal rect As RectangleF, ByVal view As GoView) As RectangleF
Dim b As RectangleF = GetRealBounds()
Return RectangleF.Union(rect, b)
End Function
Public Overrides Function ContainsPoint(ByVal p As PointF) As Boolean
Return GetRealBounds().Contains§
End Function
Public Overrides Function ContainedByRectangle(ByVal r As RectangleF) As Boolean
Dim b As RectangleF = GetRealBounds()
Return (r.Width > 0 And r.Height > 0 And b.Width >= 0 And b.Height >= 0 And b.X >= r.X And b.Y >= r.Y And b.X + b.Width <= r.X + r.Width And b.Y + b.Height <= r.Y + r.Height)
End Function
Public Function GetRealBounds() As RectangleF
Dim bounds As RectangleF = Me.Bounds
Dim angle As Double = Me.Angle / 180 * Math.PI
Dim origin As PointF = Me.Location
Return RotateRectangle(bounds, origin, angle)
End Function
Public Shared Function RotateRectangle(ByVal r As RectangleF, ByVal origin As PointF, ByVal angle As Double) As RectangleF
Dim otl As PointF = New PointF(r.X, r.Y)
Dim ntl As PointF = otl
If otl <> origin Then
ntl = RotatePoint(otl, origin, angle)
End If
Dim otr As PointF = New PointF(r.X + r.Width, r.Y)
Dim ntr As PointF = otr
If otr <> origin Then
ntr = RotatePoint(otr, origin, angle)
End If
Dim obr As PointF = New PointF(r.X + r.Width, r.Y + r.Height)
Dim nbr As PointF = obr
If obr <> origin Then
nbr = RotatePoint(obr, origin, angle)
End If
Dim obl As PointF = New PointF(r.X, r.Y + r.Height)
Dim nbl As PointF = obl
If obl <> origin Then
nbl = RotatePoint(obl, origin, angle)
End If
Dim minx As Single = CType(Math.Min(ntl.X, Math.Min(ntr.X, Math.Min(nbr.X, nbl.X))), Single)
Dim maxx As Single = CType(Math.Max(ntl.X, Math.Max(ntr.X, Math.Max(nbr.X, nbl.X))), Single)
Dim miny As Single = CType(Math.Min(ntl.Y, Math.Min(ntr.Y, Math.Min(nbr.Y, nbl.Y))), Single)
Dim maxy As Single = CType(Math.Max(ntl.Y, Math.Max(ntr.Y, Math.Max(nbr.Y, nbl.Y))), Single)
Return New RectangleF(minx, miny, maxx - minx, maxy - miny)
End Function
Public Shared Function RotatePoint(ByVal p As PointF, ByVal origin As PointF, ByVal angle As Double) As PointF
Dim dx As Single = p.X - origin.X
Dim dy As Single = p.Y - origin.Y
Dim pangle As Double = GoStroke.GetAngle(dx, dy) / 180 * Math.PI
Dim dist As Double = Math.Sqrt(dx * dx + dy * dy)
Dim nx As Single = CType((dist * Math.Cos(pangle + angle)), Single)
Dim ny As Single = CType((dist * Math.Sin(pangle + angle)), Single)
Return New PointF(origin.X + nx, origin.Y + ny)
End Function
Public Overrides Sub AddSelectionHandles(ByVal sel As GoSelection, ByVal selectedObject As GoObject)
RemoveSelectionHandles(sel)
If Not CanResize() Then
sel.CreateBoundingHandle(Me, selectedObject)
Return
End If
Dim rect As RectangleF = GetRealBounds()
Dim x1 As Single = rect.X
Dim x2 As Single = rect.X + (rect.Width / 2)
Dim x3 As Single = rect.X + rect.Width
Dim y1 As Single = rect.Y
Dim y2 As Single = rect.Y + (rect.Height / 2)
Dim y3 As Single = rect.Y + rect.Height
’ create the handles
sel.CreateResizeHandle(Me, selectedObject, New PointF(x1, y1), TopLeft, True)
sel.CreateResizeHandle(Me, selectedObject, New PointF(x3, y1), TopRight, True)
sel.CreateResizeHandle(Me, selectedObject, New PointF(x3, y3), BottomRight, True)
sel.CreateResizeHandle(Me, selectedObject, New PointF(x1, y3), BottomLeft, True)
If CanReshape() Then
sel.CreateResizeHandle(Me, selectedObject, New PointF(x2, y1), MiddleTop, True)
sel.CreateResizeHandle(Me, selectedObject, New PointF(x3, y2), MiddleRight, True)
sel.CreateResizeHandle(Me, selectedObject, New PointF(x2, y3), MiddleBottom, True)
sel.CreateResizeHandle(Me, selectedObject, New PointF(x1, y2), MiddleLeft, True)
End If
End Sub
Public Overrides Function CreateBoundingHandle() As IGoHandle
Dim h As GoHandle = New GoHandle()
Dim rect As RectangleF = GetRealBounds()
’ the handle rectangle should just go around the object
rect.X = rect.X - 1
rect.Y = rect.Y - 1
rect.Height += 2
rect.Width += 2
h.Bounds = rect
Return h
End Function
Public Property Angle() As Single
Get
Dim ll As GoLabeledLink = CType(Me.Parent, GoLabeledLink)
'If Not (ll Is Nothing) And (ll.MidLabel = Me)) Then
If Not (ll Is Nothing) Then
'If (ll Nothing And ll.MidLabel = Me) Then
Dim rl As GoLink = ll.RealLink
Dim midEnd As Integer = rl.PointsCount / 2
If midEnd < 1 Then
Return myAngle
End If
Dim a As PointF = rl.GetPoint(midEnd - 1)
Dim b As PointF = rl.GetPoint(midEnd)
Dim langle As Single = GoStroke.GetAngle(b.X - a.X, b.Y - a.Y)
If langle > 90 And Angle < 270 Then langle = 180
Return langle
Else
Return myAngle
End If
End Get
Set(ByVal Value As Single)
Dim old As Single = myAngle
If old <> Value Then
myAngle = Value
Changed(ChangedAngle, 0, Nothing, MakeRect(old), 0, Nothing, MakeRect(Value))
End If
End Set
End Property
Public Overrides Sub ChangeValue(ByVal e As GoChangedEventArgs, ByVal undo As Boolean)
Select Case e.SubHint
Case ChangedAngle
Me.Angle = e.GetFloat(undo)
Return
Case Else
MyBase.ChangeValue(e, undo)
Return
End Select
End Sub
Public Const ChangedAngle As Integer = 1550
Private myAngle As Single = 0
End Class
’ A RotatedText’s Bounds aren’t the “real” bounds.
’ This class implements an object that contains a RotatedText,
’ and whose Bounds will be equal to the RotatedText’s GetRealBounds(),
’ The initial RotatedText object will also be not Selectable and
’ will have a Middle Alignment.
’ You can then use an instance of this class inside other groups, such as GoListGroups.
’ You can access the RotatedText object through the RT property.
<Serializable()> _
Public Class RotatedTextHolder
Inherits GoGroup
Public Sub New()
Me.Selectable = False
Dim myRotatedText As RotatedText = New RotatedText()
myRotatedText.Selectable = False
myRotatedText.Alignment = Middle
’ notice whenever the RotatedText’s Bounds changes As myRotatedText.AddObserver(Me)
Add(myRotatedText)
End Sub
Protected Overrides Sub OnObservedChanged(ByVal observed As GoObject, ByVal subhint As Integer, ByVal oldI As Integer, ByVal oldVal As Object, ByVal oldRect As RectangleF, ByVal NewI As Integer, ByVal NewVal As Object, ByVal NewRect As RectangleF)
If subhint = GoObject.ChangedBounds Then
Me.InvalidBounds = True
End If
End Sub
Protected Overrides Function ComputeBounds() As RectangleF
Return Me.RT.GetRealBounds()
End Function
Public ReadOnly Property RT() As RotatedText
Get
Return CType(Me(0), RotatedText)
End Get
End Property
End Class
End Namespace

llnk.MidLabel = MakeText("Hi there")
I am calling the function like this but still i am getting the text is on the 90 degree. And it is not aligning according to link.
Please advice me .....!
Thanks Jake in advance.

This line

If langle > 90 And Angle < 270 Then langle = 180
doesn't match the c# line...
if (angle > 90 && angle < 270) angle -= 180;
I haven't checked the rest of the code carefully, but I note at least this one thing. Set a breakpoint in "Angle" and see if it is returning an angle based on the slope of the link.
Ohh I have corrected the line.I have applied the break point on the Angle its giving me '0.0' value all the time.
I have applied same code to C# project sample .Its working fine ....but its not working with my vb project.
can i have same http://www.nwoods.com/forum/forum_posts.asp?TID=272 vb files.
i will be greatful to you.

Sorry, but we don’t have a VB version of that class. But if you don’t want to translate it, you could use that C# class by putting it into a separate project.

It should be easy enough to set a breakpoint at Angle and step through the code to see why it isn't computing the angle correctly in your vb version of the code.
Hello Jake.
1-i am very much thankfull to you for the support. I got the solution.Code files are proper even with VB.
2- Dim a As PointF = rl.GetPoint(midEnd - 1)
Dim b As PointF = rl.GetPoint(midEnd)
my Node Type =GoTextNode
if some condition
llnk.FromPort = fromNode.BottomPort
llnk.ToPort = toNode.TopPort
end if
This will compute X values of a and b variable same and resulting it to 90 degree always.

Code will work only for this condition
if some condition
llnk.FromPort = fromNode.BottomPort
llnk.ToPort = toNode.BottomPort
or
llnk.FromPort = fromNode.topPort
llnk.ToPort = toNode.topPort
end if

Thanks again for the help.
vineet