CopyObject and Custom Nodes

Hi,

I am having some problems with copying nodes using CopyObject:
1/ I am using a GoTextNode, but I show no text and I set the background to be an Image (I do this because I like the 4 ports of the GoTextNode). The problem is that the background image doesnt get copied by the standard CopyObject, and when I try to set the background image of the newobj in the CopyObject I get all orts of issues with pasting the nodes in the wrong position. Can anyone explain why this is happening, or suggest a different node typr to use?
2/ I have some custom properties inside my GoTextNode. I am actuall using the PropertyEx class to extend the propertygrid so that I can add custom properties. But this object doesnt appear to be serializable, so when I copy a node, the properties dont get copied. What is the best way to store custom properties for a node so that it works with copying, pasting, undoing etc?
Kind regards,
Neil.

1/ If you have replaced the GoTextNode.Background with a GoImage (instead of the normal GoRectangle), you shouldn’t have to override any copy method. The normal definition of CopyChildren should do the right thing.

2/ If you have a fixed number of properties, just add them as .NET properties on your class inheriting from GoTextNode. You’ll only need to override CopyObject if you want to avoid sharing references to property values in copies of the node.

If you have a variable number of properties, say in a Dictionary, you’ll need to override CopyObject to make sure you make a copy of the Dictionary with the right values in it. (This is just another case of avoiding unwanted shared references in a copied GoObject.)

All of your properties need to be serializable.

Hi Walter,

Thanks for getting back to me.
With regards to my first point, I added a GoImage to the background of the start node in the FlowCharter3 sample. The image appears in the palette, and on the flowchart, but it you copy and paste the node, the image doesn't appear on the pasted node. Can you try this youself, and let me know how to fix it.
Reagrds,
Neil.

In OnKindChanged I replaced:

Me.Background = New GoDrawing(GoFigure.Start)Me.Shape.FillShapeHighlight(Color.Green)
with:
Dim Image As New GoImage
Image.Image = MainForm.App.imageList1.Images(0)
Me.Background = Image
(and made the imageList1 public)

Images and ImageLists aren’t copied. This allows for images, which can be large, to be shared by multiple GoImages in memory.

However, the references to the images (file name or resource name or ImageList index) that are in GoImage are copied.

The problem is that you are directly assigning the GoImage.Image property. I suggest that you set the GoImage’s Index = 0 and that you set the shared property GoImage.DefaultImageList in your application constructor.

Here’s the relevant text from the FAQ (GoDiagramFAQ.chm):

·
If an image is
not appearing when the object is pasted from the clipboard, but is visible when
created and when drag-drop-copied, then the cause is a lack of knowledge about
where to retrieve the Image. You need to set GoImage.ImageList or
GoImage.ResourceManager on the newly copied objects, because those image
sources are not serialized. More convenient, when you only have a single source
of images, is to set the static/shared property GoImage.DefaultImageList
or GoImage.DefaultResourceManager.

Thanks Walter, that was exactly the information I needed.