So this is a follow up to my previous posting regarding Layout Positioning. See: Why Doesn’t This Work?? - Port Positioning at
I have followed up by:
a) modifying and making the layout occur in LayoutChildren().
b) I made positioning relative to the [0] node which is either a GoText or GoImage object.
None of this is working. And I am getting rather weird results. A few comments before I get into the scenarios I am seeing…
-
I find that doing things in LayoutChildren() is a bit hairy as it seems to be a very recursive function. For instance if I call SetSpotLocation() and as part of the parameter list I use the node (this), then it gets called recursively 2-3 times.
-
When I use the [0] object for relative setting of the SetSpotLocation(), versus the node, I get crap, nothing even reasonable. When I use the node as in the call, I get varying results, and notice in the debugger that the width and height of the node are constantly changing as I am adding port/labels.
-
The documentation on all of this is VERY weak and I am finding it frustrating. For instance do you use GoObject.TopCenter or GoObject.MiddleCenter to mean the top of the referenced object? I would assume TopCenter, but your documentation (GoUserGuide pg 46) uses MiddleCenter.
Scenarios:
-
In scenario 1, I used iterate over all ports each time LayoutChildren is called and call the appropriate SetSpotLocation() routine using the node itself as the obj passed in. In this scenario, I can get North/South to position reasonable correctly to Center, but when I add East, East overlaps center. However, add an West and suddenly East works properly. Contrarily, if I take North (or South) away, the opposite still works. Interestingly as I add cardinal direction (N,S,E,W, SE, SW, NW, NE) the size grows, until with all of them I have to full screen the view to see them - yet they are positioned correctly.
-
In scenario 2, I am doing the same as scenario 1, except I only SetSpotLocation() with the changedObj passed into the function, and leave the rest alone. This one never works even with pairs of coordinates.
-
In scenario 3, I iterate over all ports each time LayoutChildren is called, but in the SetSpotLocation() I pass the reference object as the center child node which (currently) is a GoText object, already positioned and centered. In this case, the whole node (which was centered in a view moves to upper-left of the view, and all text is dropped over the same spot.
Below is the relevant code. My organization is on the verge of purchasing licenses for our work, but if I can’t figure out the ju ju black magic involved here, it is gonna put a big crimp in that.
public class DiagramNode : GoNode
{
public DiagramNode()
{
this.Initializing = true;
}
public Image IconImage
{
get
{
GoObject obj = this[0];
if (obj is GoImage)
return ((GoImage)obj).Image;
else
return null;
}
set
{
GoObject obj = this[0];
if (obj is GoImage)
((GoImage)obj).Image = value;
else
{
GoImage gimg = new GoImage();
gimg.Image = value;
Insert(0, gimg);
}
}
}
public override GoText Label
{
get
{
GoObject obj = this[0];
if (obj is GoGeneralNodePort)
{
return (GoText)((GoGeneralNodePort)obj).PortObject;
}
else
return null;
}
set
{
AddLabelAt(DiagramConstants.CardinalDirections.Center, value.Text);
}
}
public void AddLinkAt(DiagramConstants.CardinalDirections direction, DiagramLink link)
{
}
public void ConnectNodeAt(DiagramConstants.CardinalDirections direction, DiagramNode node)
{
}
public void AddLabelAt(DiagramConstants.CardinalDirections direction, string text)
{
GoGeneralNodePort port = new GoGeneralNodePort();
port.ToSpot = (int) direction;
port.FromSpot = (int) direction;
port.Style = GoPortStyle.Object;
GoText gtext = new GoText();
gtext.Text = text;
port.Editable = false;
port.PortObject = gtext;
if (direction == DiagramConstants.CardinalDirections.Center)
Insert(0, port);
else
Add(port);
}
public override void LayoutChildren(GoObject childchanged)
{
if (!this.Initializing)
{
//base.LayoutChildren(childchanged);
GoObject center = null;
if (this[0] is GoPort)
{
center = ((GoGeneralNodePort)this[0]).PortObject;
}
else if (this[0] is GoImage)
{
center = this[0];
}
else
center = new GoRectangle();
foreach (GoPort p in this.Ports)
{
int direction = p.ToSpot;
switch (direction)
{
case (int)DiagramConstants.CardinalDirections.Center:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.Center, this, (int)DiagramConstants.CardinalDirections.Center);
break;
case (int)DiagramConstants.CardinalDirections.East:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.West, center, (int)DiagramConstants.CardinalDirections.East);
break;
case (int)DiagramConstants.CardinalDirections.North:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.South, center, (int)DiagramConstants.CardinalDirections.North);
break;
case (int)DiagramConstants.CardinalDirections.NorthEast:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.SouthWest, center, (int)DiagramConstants.CardinalDirections.NorthEast);
break;
case (int)DiagramConstants.CardinalDirections.NorthWest:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.SouthEast, center, (int)DiagramConstants.CardinalDirections.NorthWest);
break;
case (int)DiagramConstants.CardinalDirections.South:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.North, center, (int)DiagramConstants.CardinalDirections.South);
break;
case (int)DiagramConstants.CardinalDirections.SouthEast:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.NorthWest, center, (int)DiagramConstants.CardinalDirections.SouthEast);
break;
case (int)DiagramConstants.CardinalDirections.SouthWest:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.NorthEast, center, (int)DiagramConstants.CardinalDirections.SouthWest);
break;
case (int)DiagramConstants.CardinalDirections.West:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.East, center, (int)DiagramConstants.CardinalDirections.West);
break;
}
}
/*if (childchanged is GoGeneralNodePort)
{
GoGeneralNodePort p = (GoGeneralNodePort)childchanged;
int direction = p.ToSpot;
switch (direction)
{
case (int)DiagramConstants.CardinalDirections.Center:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.Center, this, (int)DiagramConstants.CardinalDirections.Center);
break;
case (int)DiagramConstants.CardinalDirections.East:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.West, this, (int)DiagramConstants.CardinalDirections.East, this.Width * 2, 0F);
break;
case (int)DiagramConstants.CardinalDirections.North:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.South, this, (int)DiagramConstants.CardinalDirections.North, 0F, -5F);
break;
case (int)DiagramConstants.CardinalDirections.NorthEast:
p.SetSpotLocation((int)direction, this, (int)direction);
break;
case (int)DiagramConstants.CardinalDirections.NorthWest:
p.SetSpotLocation((int)direction, this, (int)direction);
break;
case (int)DiagramConstants.CardinalDirections.South:
p.SetSpotLocation((int)DiagramConstants.CardinalDirections.North, this, (int)DiagramConstants.CardinalDirections.South, 0F, 5F);
break;
case (int)DiagramConstants.CardinalDirections.SouthEast:
p.SetSpotLocation((int)direction, this, (int)direction);
break;
case (int)DiagramConstants.CardinalDirections.SouthWest:
p.SetSpotLocation((int)direction, this, (int)direction);
break;
case (int)DiagramConstants.CardinalDirections.West:
p.SetSpotLocation((int)direction, this, (int)direction);
break;
}
}*/
}
}
}
public static DiagramNode CreateTextOnlyNode(string text)
{
DiagramNode node = new DiagramNode();
//GoText textComp = new GoText();
//textComp.Text = text;
//node.Label = textComp;
node.Editable = false;
node.Width = 200;
node.Height = 200;
string text2 = text + "port";
node.AddLabelAt(DiagramConstants.CardinalDirections.Center, "Center");
node.AddLabelAt(DiagramConstants.CardinalDirections.North, "North");
node.AddLabelAt(DiagramConstants.CardinalDirections.East, "East");
//node.AddLabelAt(DiagramConstants.CardinalDirections.South, "South");
//node.AddLabelAt(DiagramConstants.CardinalDirections.West, "West");
//node.AddLabelAt(DiagramConstants.CardinalDirections.NorthEast, "NorthEast");
//node.AddLabelAt(DiagramConstants.CardinalDirections.SouthEast, "SouthEast");
//node.AddLabelAt(DiagramConstants.CardinalDirections.SouthWest, "SouthWest");
//node.AddLabelAt(DiagramConstants.CardinalDirections.NorthWest, "NorthWest");
return node;
}</i>
Scenario 3 Image
Scenario 1&2 Images