Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom link copy & paste problem in 5.0.1 (Read 3380 times)
yeoupooh
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Sep 27th, 2007
Custom link copy & paste problem in 5.0.1
Dec 3rd, 2007 at 8:58am
Print Post  
Hi, Stoyo.

I got a problem in coping and pasting custom link.

MyLink.cs code is...
Code
Select All
    public class MyLink : DiagramLink
    {
	  public MyLink(Diagram diagram)
		: base(diagram)
	  {
	  }

	  public MyLink(Diagram diagram, MyNode src, MyNode dest)
		: base(diagram, src, dest)
	  {
	  }

	  public MyLink(MyLink prototype, MyNode src, MyNode dest)
		: base(prototype, src, dest)
	  {
	  }

	  public MyLink(MyLink prototype, Diagram diagram)
		: base(diagram)
	  {
	  }

	  protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext context)
	  {
		base.LoadFrom(reader, context);
	  }

	  protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext context)
	  {
		base.SaveTo(writer, context);
	  }
    }
 



MyNode.cs code is...
Code
Select All
    public class MyNode:DiagramNode
    {
	  public MyNode(Diagram diagram)
		: base(diagram)
	  {
	  }

	  public MyNode(MyNode prototype)
		: base(prototype)
	  {
	  }

	  protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext context)
	  {
		base.LoadFrom(reader, context);
	  }

	  protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext context)
	  {
		base.SaveTo(writer, context);
	  }

	  public override void Draw(MindFusion.Drawing.IGraphics graphics, RenderOptions options)
	  {
		graphics.DrawRectangle(Pens.Black, Rectangle.Truncate(this.bounds));
	  }

	  public override void DrawShadow(MindFusion.Drawing.IGraphics graphics)
	  {

	  }
    }
 



and Form1.cs code here.

Code
Select All
    public partial class Form1 : Form
    {
	  public Form1()
	  {
		InitializeComponent();

		Diagram.RegisterItemClass(typeof(MyNode), "MyNode", 1);
		Diagram.RegisterItemClass(typeof(MyLink), "MyLink", 1);
	  }

	  private void button1_Click(object sender, EventArgs e)
	  {
		MyNode node = new MyNode(diagram1);
		node.Bounds = new RectangleF(10, 10, 20, 10);
		diagram1.Nodes.Add(node);

		MyNode node2 = new MyNode(diagram1);
		node2.Bounds = new RectangleF(50, 10, 20, 10);
		diagram1.Nodes.Add(node2);

		MyLink link = new MyLink(diagram1, node, node2);
		diagram1.Links.Add(link);
	  }

	  private void button2_Click(object sender, EventArgs e)
	  {
		diagramView1.CopyToClipboard(false);
	  }

	  private void button3_Click(object sender, EventArgs e)
	  {
		diagramView1.PasteFromClipboard(0, 0);
	  }
    }
 



When I copy MyNodes and MyLinks and paste, Diagram has pasted MyNode objects and DiagramLink objects (not MyLink).

So, MyLink objects not serialized normally.

Has MyLink.cs code problem or not?

Thanks in advance,
Jinwoo.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom link copy & paste problem in 5.0.1
Reply #1 - Dec 3rd, 2007 at 10:21am
Print Post  
Hi Jinwoo,

Your link class must implement the Clone() method. For nodes it is enough to have a copy constructor, but apparently the Paste operation can create links only by calling Clone(). Your Clone() method does not have to set the link's origin and destination; the Paste method will take care of setting them to the pasted node instances.

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


I love YaBB 1G - SP1!

Posts: 8
Joined: Sep 27th, 2007
Re: Custom link copy & paste problem in 5.0.1
Reply #2 - Dec 5th, 2007 at 11:28pm
Print Post  
It works nice! Thanks, Stoyan.

p.s. I didn't found it in Help documentations.
It needs to be documented.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom link copy & paste problem in 5.0.1
Reply #3 - Dec 6th, 2007 at 6:45am
Print Post  
Yes, actually what is required for clipboard operations is the Clone method , both for nodes and links. However, the base Clone method of nodes is implemented by calling a copy constructor through the Reflection API, so as a side effect you could use just a copy constructor in your custom node class. At this time the DiagramLink simply creates a new DiagramLink(...) from its Clone implementation, so you must override Clone in the derived link class.

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