Additional text node to GoGeneralNode

Hello!

I want to add an additional text node to my class - Fb. The class Fb derives from GoGeneralNode. The code I have used to create the additional text node is very similar to the code below -

public partial class Form1 : Form
{
private GoView view;

    public Form1()
    {
          InitializeComponent();
          InitGoObjects();
          Controls.Add(view);              
    }

    private void InitGoObjects()
    {
          view = new AView();
          view.Dock = DockStyle.Fill;                   
    }      

}

public class GgnWithExtra : GoGeneralNode
{
    private GoText veryBottomLabel;
    
    public override void Initialize(System.Resources.ResourceManager res, string iconname, string top, string bottom, int numinports, int numoutports)
    {
          base.Initialize(res, iconname, top, bottom, numinports, numoutports);

          veryBottomLabel = CreateBottomMostText();
          Add(veryBottomLabel);
    }        

    public string NameOfBottomMostLabel
    {
          get { return veryBottomLabel.Text; }
          set { veryBottomLabel.Text = value; }
    }

    public virtual GoText CreateBottomMostText()
    {
          GoText t = new GoText();
          t.Text = "foo";
          return t;
    }

    public override void LayoutChildren(GoObject childchanged)
    {
          base.LayoutChildren(childchanged);

          if (this.Icon != null && veryBottomLabel != null)
          {
              this.Icon.SetSpotLocation(MiddleBottom, this.Icon, MiddleBottom);
              this.veryBottomLabel.SetSpotLocation(MiddleBottom, this.Icon, MiddleBottom);
          }
    }


}

public class AView : GoView
{
    private GgnWithExtra node;

    public AView()
    {
          node = new GgnWithExtra();
          node.Initialize(null, "", "Top", "Bottom", 4, 2);
          node.Position = new PointF(50, 50);
          Document.Add(node);      
    }

    protected override void OnObjectSingleClicked(GoObjectEventArgs evt)
    {
          Random random = new Random();
          node.NameOfBottomMostLabel = random.Next().ToString();
          base.OnObjectSingleClicked(evt);
    }
}

As far as I can tell, the only difference between the above code and my application code is in the LayoutChildren method. The LayoutChildren method that I have in my application code is -

public override void LayoutChildren(GoObject childchanged)
{
if (bLayoutSetting)
{
base.LayoutChildren(childchanged);
GoObject botlab = BottomLabel;
GoGroup icongrp = Icon as GoGroup;

              if (botlab != null && icongrp != null && textForCycleTime != null && icongrp.Count > 0)
              {
                  GoObject toprect = icongrp[0];
                  botlab.Center = toprect.Center;
                  this.TextForCycleTime.SetSpotLocation(MiddleTop, this.Icon, MiddleBottom);
              }
          }
    }

The problem is that, the text I assign to my additional GoText doesn’t get refreshed.

What am I missing?

Thanks in advance,

Pradip

I don’t understand what the problem is. I tried your GgnWithExtra class, and it worked fine. I couldn’t try your alternative LayoutChildren method, but that shouldn’t matter w.r.t. updating the GoText.Text string.
A few comments. The following statement never moves the Icon:
this.Icon.SetSpotLocation(MiddleBottom, this.Icon, MiddleBottom);
And I might suggest that you make that extra GoText object in CreateBottomMostText not Selectable.
It’s odd defining a subclass of GoView just to override an event method, when you could just implement an event handler. And the use of the “node” variable isn’t good practice either. Instead I would use the event arguments, as follows:
Random random = new Random();
GgnWithExtra node = evt.GoObject.ParentNode as GgnWithExtra;
if (node != null) node.NameOfBottomMostLabel = random.Next().ToString();

Thanks Walter, for your helpful remarks.

Consider my GgnWithExtra class above. Theoretically, what does it mean if the value of veryBottomLabel.Text doesn’t refresh? Also, what does it mean if veryBottomLabel.View is null? What if veryBottomLabel.Document is null?

Thanks,

Pradip

GoObject.View will be non-null if the object belongs to a GoLayer that belongs to a GoView, i.e. only displayed as part of a view and not a part of the GoDocument model.
GoObject.Document will be non-null if the object belongs to a GoLayer that is part of a GoDocument.
Both properties will be null if it isn’t part of any layer. Typically this is because you just constructed the GoObject, or because you just removed it from a layer, usually to discard it.
Normally, modifying any predefined visible property of document GoObjects will automatically update all GoViews that are displaying that document. So that should work if the GoText.Layer is non-null.
But I suppose you might have turned on SuspendsUpdates either on the GoObject or on the GoDocument. We recommend against ever setting that property (we probably never should have let that be public!).
More likely, the GoText whose Text property you are changing isn’t the one that you see in the view. You’ll need to debug whether that GoText object really does belong to the node that you think it does. GoText.Document ought to be the same as your GoView.Document. GoText.Bounds ought to be about where you see it.
If aText is the GoText whose Text property you are changing, then calling GoView.PickObject(true, false, aText.Center, false) ought to return that same aText object. That will check if there is some other object in front that is hiding aText.