Save my diagram in XML

Hello, it’s me again.

I’ve got the most important problem for my project concerning the saving.

I took the source code of stateCharter to help me for this.

My problem is that when I save the diagram only this line is wrote :

And I don’t know where the problem is.

My source code is :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.IO;
using Northwoods.Go;
using Northwoods.Go.Xml;

namespace DiagramTiphaine
{
[Serializable]
public class ManageDocument : GoDocument
{
public ManageDocument() { }

    // Chaque fois que le nom du document est changé, mise à jours de la nameTextBox dans le MainForm
    public override String Name
    {
        set
        {
            if (base.Name != value)
            {
                base.Name = value;
                MyMainForm.MainForm.UpdateForm();
            }
        }
    }

    // Garde une trace du fichier où le document est stocké
    public virtual String Path
    {
        get { return myPath; }
        set
        {
            String old = myPath;
            if (old != value)
            {
                myPath = value;
                RaiseChanged(ChangedPath, 0, null, 0, old, NullRect, 0, value, NullRect);
            }
        }
    }        

    //Faire un commentaire
    public static GoComment NewComment()
    {
        GoComment comment = new GoComment();
        comment.Text = "Enter your comment here,\r\non multiple lines.";
        comment.Label.Multiline = true;
        comment.Label.Editable = true;
        return comment;
    }

    //Création d'un lien entre deux éléments graphique
    public virtual int NumLinksBetween(IGoPort a, IGoPort b)
    {
        int count = 0;
        foreach (IGoLink l in a.DestinationLinks)
        {
            if (l.ToPort == b)
                count++;
        }
        return count;
    }     

    #region Version
    public int Version
    {
        get { return 3; }
        set
        {
            if (value != this.Version)
                throw new NotSupportedException("For simplicity, this sample application does not handle different versions of saved documents");
        }
    } 
    #endregion

    #region AdapterDocXml
    // TODO: adapt the XML elements and attributes to match your classes and their properties
    private static void InitReaderWriter(GoXmlReaderWriterBase rw)
    {
        GoXmlBindingTransformer.DefaultTracingEnabled = true;  // Pour le débogage, vérifiez votre fenêtre de Production (trace l'auditeur)
        GoXmlBindingTransformer t;

        t = new GoXmlBindingTransformer("Diagramme", new ManageDocument());
        t.AddBinding("version", "Version", GoXmlBindingFlags.RethrowsExceptions);  // let exception from Version setter propagate out
        t.AddBinding("name", "Name");
        t.AddBinding("path", "Path");
        t.AddBinding("customcolors", "CustomColors");
        rw.AddTransformer(t);

        t = new GoXmlBindingTransformer("Tache",new OneInOneOutBasicNode());
        t.IdAttributeUsedForSharedObjects = true;  // Chaque élément a un identifiant unique
        t.HandlesNamedPorts = true;  // Génère des attributs pour chacun des ports nommés, spécifiant leur IDS
        t.AddBinding("label", "Text");
        t.AddBinding("loc", "Location");
        t.AddBinding("color", "Shape.BrushColor");
        t.AddBinding("pos", "Rectangle.Position");
        t.AddBinding("size", "Rectangle.Size"); 
        rw.AddTransformer(t);

        t = new GoXmlBindingTransformer("comment", NewComment());
        t.IdAttributeUsedForSharedObjects = true;  // each GoComment gets a unique ID
        t.AddBinding("label", "Text");
        t.AddBinding("center", "Center");  // last property, since it depends on content/alignment
        rw.AddTransformer(t);

        t = new GoXmlBindingTransformer("transition", new Transition());
        t.AddBinding("from", "FromPort");
        t.AddBinding("to", "ToPort");
        t.AddBinding("label", "MidLabel.Text");
        t.AddBinding("curviness", "Curviness");
        t.AddBinding("color", "RealLink.PenColor");
        t.AddBinding("brush", "RealLink.BrushColor");
        t.AddBinding("adjusted", "RealLink.AdjustingStyle");
        t.AddBinding("points", "RealLink.Points");
        rw.AddTransformer(t);
    }

    public void StoreXml(FileStream ofile)
    {
        GoXmlWriter xw = new GoXmlWriter();
        InitReaderWriter(xw);
        xw.NodesGeneratedFirst = true;
        xw.Objects = this;
        xw.Generate(ofile);
    }

    public static ManageDocument LoadXml(Stream ifile)
    {
        GoXmlReader xr = new GoXmlReader();
        InitReaderWriter(xr);
        ManageDocument doc = xr.Consume(ifile) as ManageDocument;
        if (doc == null) return null;
        return doc;
    } 
    #endregion

    // handle undo and redo for the additional document state
    public override void ChangeValue(GoChangedEventArgs e, bool undo)
    {
        switch (e.Hint)
        {
            case ChangedPath:
                this.Path = (String)e.GetValue(undo);
                break;
            default:
                base.ChangeValue(e, undo);
                break;
        }
    }

    public const int ChangedPath = GoDocument.LastHint + 1;
    private String myPath = "";
    
}


[Serializable]
public class Transition : GoLabeledLink
{
    public Transition()
    {
        this.Style = GoStrokeStyle.Bezier;
        this.ToArrow = true;
        this.RealLink.PenColor = Color.Black;
        this.RealLink.PenWidth = 2;
        GoText cond = new GoText();
        cond.Selectable = false;
        cond.Editable = true;
        cond.Multiline = true;
        cond.Text = "Lien";
        this.MidLabel = cond;
        this.MidLabelCentered = true;
    }

    public override GoLink CreateRealLink()
    {
        return new TransitionLink();
    }
}

[Serializable]
public class TransitionLink : GoLink
{
    public TransitionLink() { }

    // Chaque fois que l'utilisateur redimenssionne un lien, ne recalcul pas automatiquement le coup, systématiquement
    public override void DoResize(GoView view, RectangleF origRect, PointF newPoint,
                                  int whichHandle, GoInputState evttype, SizeF min, SizeF max)
    {
        base.DoResize(view, origRect, newPoint, whichHandle, evttype, min, max);
        this.AdjustingStyle = GoLinkAdjustingStyle.Scale;
    }
}

}

Can you help me?

Are you getting any TRACE messages in the output window in the debugger?



Note that StateCharter uses a fully initialized “NewNode()” in the transformer, and you are just doing a new OneInOneOutBasicNode(). The problem may be in that.

I try to adapt the code with mine, and I my nodes are created in the class OneInOneOutBasicNode.
I thought that it was possible…

It is possible.



Are you getting any TRACE messages in the output window in the debugger?

No there’s no message in the output window Confused

Just this:

Property ‘CustomColors’ not found on type: DiagramTiphaine.ManageDocument for attribute ‘customcolors’

But I don’t use CustomColors

but you have it in the code you posted:



t.AddBinding(“customcolors”, “CustomColors”);



----



Did you change the line



t = new GoXmlBindingTransformer(“Tache”,new OneInOneOutBasicNode());



to use a fully initialized node?

Indeed I saw the line with CustomColors and I remove it because I don’t use it.

What are you meaning by “use a fully initialized node”?
Are you talking about a node already created in you example?

OK… this line:



t = new GoXmlBindingTransformer(“Tache”,new OneInOneOutBasicNode());



If you compare this to StateCharter, you will notice it doesn’t do “new GoBasicNode()”, it does “NewNode()”. NewNode() initialzes a bunch of things that don’t get saved in the XML, like the LabelSpot and Shape.



and 2)



In your Node GoXmlBindingTransformer:



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

t.AddBinding(“size”, “Rectangle.Size”);



Do you really have a Rectangle property in your node? If not, you should be seeing trace messages like:



No property ‘Rectangle’ on type: OneInOneOutBasicNode, for attribute ‘pos’



But neither of these is why the XML just has the Document element in it. I don’t see a reason for that.

No I haven’t got Rectangle property, I thought as my node is of type rectangle that I needed those lines.

But NewNode() is of type GoBasicNode like my class OneInOneOutBasicNode().

I’m a little lost for the initialisation of this part. Confused

Is it possible to send you a .zip of my project maybe with all the project you will see my error??

Yes, but look at what NewNode() does… it sets up the appearance of the node. Many of those properties aren’t saved in the XML (like LabelSpot). When you Load an XML file, it makes a copy of this prototype, then sets the fields saved in the XML.



If I change StateCharter to this:





t = new GoXmlBindingTransformer(“state”, new GoBasicNode()); //NewNode());



and load a saved XML file… the result looks like this:







and with:



t = new GoXmlBindingTransformer(“state”, NewNode());



where NewNode() does this:



public static GoBasicNode NewNode() {

GoBasicNode state = new GoBasicNode();

state.LabelSpot = GoObject.Middle;

state.Shape = new GoRoundedRectangle();

state.Shape.FillShapeHighlight(Color.FromArgb(80, 180, 240), Color.FromArgb(255,255,255));

state.Editable = true;

state.Text = “state”;

state.Label.EditableWhenSelected = true;

state.Label.Editable = true;

state.Label.Multiline = true;

state.Port.IsValidDuplicateLinks = true;

state.Port.IsValidSelfNode = true;

return state;

}



I get this when I load the SAME XML FILE:



Is it possible to send you a .zip of my project maybe with all the project you will see my error??



Yes. use “godiagram” at the domain this forum uses.

It works.

I restart with the code of stateCharter and step by step I change according to my need.

I think my class OneInOneOutBasicNode() had an error.

Thank you for your answers :). I think I’ll have others ;)