Saving Shapes

Is there a sample that shows you how to save the shapes when you modify the basiclayoutnode from the standard default circle to say a 200,100 circle, or when each node is a custom size? I’m trying to save and load documents, but when I do all of the size settings for the nodes are lost. I am customizing each node to a unique size to create a chart with a unique size for each node. So when I save it, I have to know the size to reload. So I’m looking for a sample that shows this.

Currently, the samples do not save the shape or size information. They just reload using the same layout, which recreates the same size and shape. But since mine are custom, I cannot take that approach. I need to save the shape and size in the XML file itself and then reload it to regenerate the diagram.

Basically, you have to store something into the XML that is going to result in the same call you make in your code to “set” the size when the node is restored.



So, you mentioned BasicLayoutNode, from LayoutDemo. There are a couple of things you need to do:



In InitReaderWriter, add this line:





t.AddBinding(“pos”, “Ellipse.Position”);

t.AddBinding(“size”, “Ellipse.Size”); // new line



which should be enough… but LayoutDemo has some code in BasicLayoutNode.LayoutChildren to change the ellipse size based on the number of ports… which sets the size back to the default. Unless the number of ports or the setting of “Horizontal” changes for the node, I think you can just comment out that code… thus:



//SizeF temp1; //with every layout, resize the ellipse.

//if (horizontal)

// temp1 = new SizeF((myStdSize / 2) * (myPorts.Count + 1), myStdSize);

//else

// temp1 = new SizeF(myStdSize, (myStdSize / 2) * (myPorts.Count + 1));

//myEllipse.Size = temp1;





so… the xml file now looks like:



















(I saved the file and edited the size values by hand to simulate what you’re doing in code.) the graph looks like this when opened:





Thanks for information. That makes complete sense.

I was trying to do basically what you are doing here and I could not get it to work. Everything else saves except for the size. But I may have messed up the "pos" attributes, as that is the key to save the information. Actually, if I recall, I think I had "Pos" and not "pos". Is it case sensitive? I think I found "Pos" in an example somewhere.
But seeing what you are doing here, I'm sure I have some errors in my approach. So I should be able to get this to work now with your working sample.
Thanks for your help.

Yes, XML element (and attribute) names are case-sensitive.