Saving / Loading w/orthogonal links

ProtoApp and Demo1 sample applications use two different methods to save and restore a document and it’s contents. What I need to do is similar to ProtoApp which saves the state to an xml file by traversing the document and creating an xml document that respresents it’s contents. For the most part this is understandable, however, in terms of the links, I would like to save and restore orthogonal links which includes multilple segments, with jump overs, etc, to the exact location in the document specified by the user. So, I guess I need finer control of placing the links back into the document. Is anyone doing this?

You can get all of the points of the stroke by using CopyPointsArray. Upon loading, you can set all the points by calling SetPoints.
Depending on the value of GoLink.AdjustingStyle, you’ll probably want to call SetPoints after the link and both of its ports/nodes have been added to the document, and after the link has been reconnected to the ports.
Hmmm, I guess persistence is a feature we never got around to implementing in the Processor sample.

Thanks Walter for the tip. Since my posting I headed down that path and I am close to getting it to work. It would still be good to see a sample of persisting the complete state of a document to an xml or csv file by traversing through the document. In my situation I must restore the state exactly how the user left it, each object must rendered to the exact location, size, etc., as it was before.

A complete persistence example would be invaluable – using a typed XML dataset would be perfect.
Glenn.

Well, the other samples do save complete documents.
But only each application can know what information needs to be included for it to be considered “complete”. Most applications don’t care about the precise details of how each node is constructed. In fact, such details shouldn’t be saved, because newer versions of the application could easily change the appearance of nodes. Not only might each kind of node be constructed differently, but there might be additional decorative objects, both in the document as well as on each node.
It suddenly occurs to me that the StateCharter sample must be saving the control points of the Bezier curve that forms the stroke for each link.
Also, have you looked at the generalized support for XML that is in GoSvg221beta.zip, as announced in the sticky note in this forum? The SVG support is just a specialized case of writing XML from GoDiagram constructs.
Here’s some potentially useful code, from the XmlTransformer class:
///


/// Produce a string representing the given array of PointF.
///

///
/// a string of X Y pairs, all separated by spaces
public String StringVal(PointF[] val) {
String s = “”;
for (int i = 0; i < val.Length; i++) {
PointF p = val;
if (i > 0)
s += " ";
s += XmlConvert.ToString(p.X) + " " + XmlConvert.ToString(p.Y);
}
return s;
}
///
/// Parse an attribute’s string value as an array of PointF.
///

/// the name of the attribute
/// the default value to return if the attribute is not present
///
/// An array of PointFs parsed from the value of the attribute named by ;
/// if there is a parsing exception or if the attribute is not present, this method returns the value of .
///
public PointF[] PointFArrayAttr(String name, PointF[] def) {
String str = StringAttr(name, null);
if (str != null) {
try {
String[] parsed = str.Split(’ ');
PointF[] pts = new PointF[(parsed.Length+1)/2];
for (int i = 0; i < parsed.Length; i++) {
float x = XmlConvert.ToSingle(parsed);
i++;
float y = 0;
if (i < parsed.Length)
y = XmlConvert.ToSingle(parsed);
pts[i/2] = new PointF(x, y);
}
return pts;
} catch (Exception) {
return def;
}
} else {
return def;
}
}

Hello,
The project i am working at requires me to implement a custom serialization scheme. At the moment i am unable to store the layout of the (orthogonal) links. My custom link inherits directly from GoLink, and i’m calling SetPoints right after adding it to the document. Whatever value gets assigned to the AdjustingStyle property the link just won’t stay the way i want it to be.
This is in short what i am doing to deserialize:

  1. Instantiate link.
  2. Add to document.
  3. Add points using GoLink.SetPoints.
Am i doing something wrong?

Greetings and many thanks in advance,
Peter Vrenken

Are you sure you aren’t setting GoLink.FromPort or GoLink.ToPort, or moving either port (perhaps by moving either node), after calling GoLink.SetPoints?
If you want to debug this, you could set a breakpoint on GoLink.CalculateStroke, right after calling SetPoints. Depending on your debugger, you might need to override this method to just call the base method, in order to set a breakpoint.
By the way, in re-reading this note I noticed one item that is no longer valid: in version 2.3 the Processor sample application does support its own custom XML persistence, using GoXml.