Troubles copying node

Hi,

I’m trying to create a node that contains (multiple) shapes and a variable number of ports. I choose to extend GoNode.

I’m running into some trouble when copying nodes. I 've created a small test node to illustrate the problem.

class ModuleNode : GoNode
{
private GoRectangle rect;
public ModuleNode()
{
rect = new GoRectangle();
rect.Selectable = false;
Add(rect);
Size = new SizeF(50, 100);
}
}

I’m not able to do copy paste on a this node in a GoView. The strange thing is, drag and drop from a GoPalette on a GoView works like a charm. This just creates a copy, right?

I’ve searched this forum on related problems and I suppose a need to override the CopyObject and/or CopyChildren methods. I haven’t found anything regarding copying nodes in the documentation.

So to the point, why doesn’t the copying work? What do I need to do to make it work? Is there any documentation available regarding the copying of nodes and updating references?

Any help is very much appreciated.

Edit: adding [Serializable] to the class definition helps a lot … ;)
However I’m still looking for information regarding copying of nodes and specifically members that hold references.


GoGroup.CopyObject will call CallChildren to make copies of the children of the group.
here’s how GoSimpleNode does CopyChildren, to set the myXyz members.
protected override void CopyChildren(GoGroup newgroup, GoCopyDictionary env) {
base.CopyChildren(newgroup, env);
GoSimpleNode newnode = (GoSimpleNode)newgroup;
newnode.myIcon = (GoObject)env[myIcon];
newnode.myLabel = (GoText)env[myLabel];
newnode.myInPort = (GoPort)env[myInPort];
newnode.myOutPort = (GoPort)env[myOutPort];
}
But, you may find it easier to avoid the myXyz members and just use AddChildName / FindChild to reference your rectangle.