Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to SaveToFile and LoadFromFile the Custom Node Type? (Read 1610 times)
GoldyWang
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 34
Joined: May 7th, 2012
How to SaveToFile and LoadFromFile the Custom Node Type?
May 22nd, 2012 at 3:28pm
Print Post  
I save the custom nodes in file, and load then from the file, they are not the custom nodes as i wish them to be. they are just the plain ShapeNode type instance.

My Custom Type coding like this:
(Followed the developer guide, the types override the SaveTo and LoadFrom methods)

public class TShapeNode : ShapeNode
{

......
//---------------------------------------------------------------------
protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext ctx)
{
base.SaveTo(writer, ctx);

// Save the label using the standard .NET BinaryWriter
//writer.Write(label);

//// Save the image using the built-in image saving code,
//// which stores the contents of shared images only once.
//ctx.SaveImage(icon);
}
//---------------------------------------------------------------------
protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext ctx)
{
base.LoadFrom(reader, ctx);

//label = reader.ReadString();
//icon = ctx.LoadImage();
}
//---------------------------------------------------------------------
....
}

public class TPlace : TShapeNode
{

......
//---------------------------------------------------------------------
protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext ctx)
{
base.SaveTo(writer, ctx);

// Save the label using the standard .NET BinaryWriter
//writer.Write(label);

//// Save the image using the built-in image saving code,
//// which stores the contents of shared images only once.
//ctx.SaveImage(icon);
}
//---------------------------------------------------------------------
protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext ctx)
{
base.LoadFrom(reader, ctx);

//label = reader.ReadString();
//icon = ctx.LoadImage();
}
//---------------------------------------------------------------------
....
}

and the creating node, is coded as following:

node = new TPlace(diagram);
node.Text = "p";

diagram.Nodes.Add(node);
RectangleF bounds = node.GetBounds();
bounds.Location = pt;
node.SetBounds(bounds, false, false);

I am on .NET Diagramming v5.8
is there something more i should do?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to SaveToFile and LoadFromFile the Custom Node Type?
Reply #1 - May 23rd, 2012 at 7:19am
Print Post  
Call the RegisterItemClass method. E.g. the IconNodes sample project that you copied some code from does this in the MainForm constructor:

Diagram.RegisterItemClass(typeof(IconNode), "IconNode", 1);

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
GoldyWang
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 34
Joined: May 7th, 2012
Re: How to SaveToFile and LoadFromFile the Custom Node Type?
Reply #2 - May 23rd, 2012 at 7:57am
Print Post  
thanks, Diagram.RegisterItemClass works

    public class TShapeNode : ShapeNode
    {
        static TShapeNode()
        {
            Diagram.RegisterItemClass(typeof(TShapeNode), "TShapeNode", 1);
        }

.....
    }
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint