Copying labeled ports

Hi *,
I need to have labeled ports on my nodes.For this I built the following objects:
EquipmentNode inherited from GoNode
EquipPort inherited from GoPort
FDLabel inherited from GoText
EquipPort creates in its constructor a FDLabel object and stores a reference to it(_label variable of type FDLabel available through Label property).Whenever an EquipPort is added to the EquipmentNode I need the corresponding FDLabel to be added (the similar logic when removing ports).For this I override Add method of the Equipment node as follows :
public override void Add(GoObject obj)
base.Add (obj);
if (obj is EquipPort)
EquipPort port = obj as EquipPort;
I also override the CopyObject method of EquipPort as follows:
public override Northwoods.Go.GoObject CopyObject(Northwoods.Go.GoCopyDictionary env)
EquipPort newPort= (EquipPort)base.CopyObject (env);
if(newPort == null)
return null;
FDLabel label = (FDLabel)env[_label];
newPort._label= label;
return newPort;
… but it seems that _label is not mapped in the dictionary (because I get a null reference).
What am I doing wrong here ?
Any help would be appreciated.

Yes, whether or not you find an object and its corresponding copy in the copy dictionary during copy depends on the order in which things are copied. I guess in your case that hadn’t happened yet.
That’s why copying is a two pass process. But rather than using the general mechanism involving the GoCopyDictionary.Delayeds collection and the GoObject.CopyObjectDelayed method, as for example GoPort and GoLink do, it might be possible for you to do something easier because your situation is relatively simple.
You could put the reference fixups in your node’s CopyChildren method. As long as you call base.CopyChildren first, you know all of the group’s child objects will have been copied, so they’ll be in the GoCopyDictionary.
OR, alternatively, you could try replacing the lookup “(FDLabel)env[_label]” with a call to “(FDLabel)env.Copy(_label)”. I haven’t looked at your code carefully enough (and I probably don’t know enough anyway) to be able to tell if that will work for you. This is, though, what GoGeneralNodePort does (with GoGeneralNodePortLabel).

Thanks Walter, (FDLabel)env.Copy(_label) works great :) .