Hi,
I have two nodes a start node and a stop node. I want the start node to allow only outgoing connections and the stop node to only allow incoming connections. The start node seems to be okay when I try to link to it from another node. However the stop node allows linking from it to any node, even the start node which is set to disallow this. I’ve included the code below. Am I missing something really obvious?
Regards,
Martin
public class StartNode : GoNode
{
private GoEllipse circle = null;
private GoTriangle triangle = null;
private GoPort topPort = null;
private GoPort bottomPort = null;
private GoPort rightPort = null;
public StartNode()
{
Initialize();
}
private void Initialize()
{   ;
this.Resizable = false;
circle = new GoEllipse();
circle.Pen = Pens.Black;
circle.Brush = Brushes.WhiteSmoke;
circle.Selectable = false;
circle.Movable = false;
circle.Resizable = false;
Add(circle);
triangle = new GoTriangle();
triangle.Pen = Pens.Black;
triangle.Brush = Brushes.Green;
triangle.Selectable = false;
triangle.Movable = false;
triangle.Resizable = false;
Add(triangle);
topPort = new GoPort();
topPort.Style = GoPortStyle.Rectangle;
topPort.IsValidTo = false;
Add(topPort);
bottomPort = new GoPort();
bottomPort.IsValidTo = false;
bottomPort.Style = GoPortStyle.Rectangle;
Add(bottomPort);
rightPort = new GoPort();
rightPort.IsValidTo = false;
rightPort.Style = GoPortStyle.Rectangle;
Add(rightPort);
}
public override void LayoutChildren(GoObject childchanged)
{
if (Initializing) return;
base.LayoutChildren(childchanged);
if (triangle != null && circle != null)
{
triangle.A = new PointF(circle.Center.X + circle.Width / 3, circle.Center.Y );
triangle.B = new PointF(circle.Center.X - circle.Width / 4, circle.Center.Y - circle.Height / 4);
triangle.C = new PointF(circle.Center.X - circle.Width / 4, circle.Center.Y + circle.Height / 4);
if (topPort != null)
{
topPort.Size = new SizeF(4, 4);
PointF pt = new PointF(circle.Center.X, this.Top);
topPort.SetSpotLocation(TopCenter, pt);
}
if (bottomPort != null)
{
bottomPort.Size = new SizeF(4, 4);
PointF pt = new PointF(circle.Center.X, this.Bottom);
bottomPort.SetSpotLocation(BottomCenter, pt);
}
if (rightPort != null)
{
rightPort.Size = new SizeF(4, 4);
PointF pt = new PointF(this.Right, this.Top + this.Height/2);
rightPort.SetSpotLocation(MiddleRight, pt);
}
}
}
}
public class StopNode : GoNode
{
private GoEllipse circle = null;
private GoRectangle rectangle = null;
private GoPort topPort = null;
private GoPort bottomPort = null;
private GoPort leftPort = null;
public StopNode()
{
Initialize();
}
private void Initialize()
{
this.Resizable = false;
circle = new GoEllipse();
circle.Pen = Pens.Black;
circle.Brush = Brushes.WhiteSmoke;
circle.Selectable = false;
circle.Movable = false;
circle.Resizable = false;
Add(circle);
rectangle = new GoRectangle();
rectangle.Pen = Pens.Black;
rectangle.Brush = Brushes.Red;
rectangle.Selectable = false;
rectangle.Movable = false;
rectangle.Resizable = false;
Add(rectangle);
topPort = new GoPort();
topPort.IsValidFrom = false;
topPort.Style = GoPortStyle.Rectangle;
Add(topPort);
bottomPort = new GoPort();
bottomPort.IsValidFrom = false;
bottomPort.Style = GoPortStyle.Rectangle;
Add(bottomPort);
leftPort = new GoPort();
leftPort.IsValidFrom = false;
leftPort.Style = GoPortStyle.Rectangle;
Add(leftPort);
}
public override void LayoutChildren(GoObject childchanged)
{
if (Initializing) return;
base.LayoutChildren(childchanged);
if (rectangle != null && circle != null)
{
rectangle.Bounds= new RectangleF(circle.Center.X - circle.Width / 4, circle.Center.Y - circle.Width / 4, circle.Width / 2, circle.Height / 2);
if (topPort != null)
{
topPort.Size = new SizeF(4, 4);
PointF pt = new PointF(circle.Center.X, this.Top);
topPort.SetSpotLocation(TopCenter, pt);
}
if (bottomPort != null)
{
bottomPort.Size = new SizeF(4, 4);
PointF pt = new PointF(circle.Center.X, this.Bottom);
bottomPort.SetSpotLocation(BottomCenter, pt);
}
if (leftPort != null)
{
leftPort.Size = new SizeF(4, 4);
PointF pt = new PointF(this.Left, this.Top + this.Height / 2);
leftPort.SetSpotLocation(MiddleLeft, pt);
}
}
}
}