Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Undo Redo Operations (Read 4377 times)
Ktmr
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 24
Joined: Mar 27th, 2020
Undo Redo Operations
May 4th, 2021 at 7:40am
Print Post  
Hi,

When I used CopyToClipboard, paste function is not working.

Then I use below code to copy

for (int i = 0; i < diagram1.Selection.Items.Count; ++i)
{
if (diagram1.Selection.Items[i] is OperationNode)
clipboard.Add(diagram1.Selection.Items[i]);
}

Copy and paste operations are working now but undo operation throws null reference exception.

How can I fix this issue?

Thanks
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Undo Redo Operations
Reply #1 - May 4th, 2021 at 8:39am
Print Post  
Hi,

If you are using custom node types, you must implement Clone method and binary serialization methods for built-in clipboard to work. For undo you might have to override CreateState, SaveState and RestoreState methods. Please post full stack trace if still getting an exception with them.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Ktmr
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 24
Joined: Mar 27th, 2020
Re: Undo Redo Operations
Reply #2 - May 4th, 2021 at 9:33am
Print Post  
Hi Slavcho,

Clone method works. How can I get node properties which is copied?

Thanks
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Undo Redo Operations
Reply #3 - May 4th, 2021 at 9:38am
Print Post  
Hi,

A custom Clone override will copy whatever properties you specify. If you asking how to copy base type's properties, you should be able to use a copy constructor for that. Actually DiagramItem.Clone calls copy constructor via reflection, so it should be enough if you implement just the constructor for a custom class and keep using base Clone implementation.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Ktmr
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 24
Joined: Mar 27th, 2020
Re: Undo Redo Operations
Reply #4 - May 4th, 2021 at 10:43am
Print Post  
Hi,

I change node properties after node is created. Can I get properties in constructor?

When I try undo method, it throws below exceptions

   konum: MindFusion.Diagramming.ShapeNode.DrawHandles(IGraphics graphics, HandlesVisualStyle style, RenderOptions options)
   konum: MindFusion.Diagramming.Diagram.c92e983a12cf70f2fdcd13fa39d7731d7(IGraphics c6c92d7b0a001e45905428290158c2b17)
   konum: MindFusion.Diagramming.Selection.Draw(IGraphics graphics, RenderOptions options)
   konum: MindFusion.Diagramming.Diagram.c85c9fb5f1477600f0b8e47a76b97a8a7(IGraphics c6c92d7b0a001e45905428290158c2b17, RectangleF cba5fe945e4bbdbc1273efda679d7f4fe, Boolean c4f62962e65ed617349113106456b7633)
   konum: MindFusion.Diagramming.Diagram.Draw(IGraphics graphics, RenderOptions options, RectangleF clipRect, Boolean noModifiedItems)
   konum: MindFusion.Diagramming.WinForms.DiagramView.cbdcbabce8bb735d287c1c0e3584d6497(IG
raphics c6c92d7b0a001e45905428290158c2b17, RectangleF c9261db5050cfcb2acba21bce194905d7, Boolean cdca9e96975ed25325aeab09ccb659e27)
   konum: MindFusion.Diagramming.WinForms.DiagramView.OnPaint(PaintEventArgs pe)
   konum: System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   konum: System.Windows.Forms.Control.WmPaint(Message& m)
   konum: System.Windows.Forms.Control.WndProc(Message& m)
   konum: MindFusion.Diagramming.WinForms.DiagramView.WndProc(Message& m)
   konum: System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   konum: System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   konum: System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Undo Redo Operations
Reply #5 - May 4th, 2021 at 11:13am
Print Post  
What kind of action are you undoing exactly?
  
Back to top
 
IP Logged
 
Ktmr
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 24
Joined: Mar 27th, 2020
Re: Undo Redo Operations
Reply #6 - May 4th, 2021 at 11:19am
Print Post  
I created new node for copy and pasted the node to the diagram.

Then called undomanager.undo method.
« Last Edit: May 4th, 2021 at 12:27pm by Ktmr »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Undo Redo Operations
Reply #7 - May 4th, 2021 at 12:49pm
Print Post  
Please let me know what we should change to reproduce:

Code
Select All
public class TestNode : ShapeNode
{
	public string TestProp { get; set; }

	public TestNode()
	{
	}

	// following are required for clipboard support
	public TestNode(TestNode prototype) :
		base(prototype)
	{
		TestProp = prototype.TestProp;
	}

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

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

Diagram.RegisterItemClass(typeof(TestNode), "my:TestNode", 100);

diagram.UndoManager.UndoEnabled = true;

var node = new TestNode {Text = "test", TestProp = "test"};
diagram.Items.Add(node);

diagramView.Refresh(); // repaint immediately for the test
Thread.Sleep(1000);

diagram.Selection.Change(node);

diagramView.Refresh();
Thread.Sleep(1000);

diagramView.CopyToClipboard(true);
diagramView.PasteFromClipboard(10, 10);

diagramView.Refresh();
Thread.Sleep(1000);

diagram.UndoManager.Undo();

diagramView.Refresh();
Thread.Sleep(1000);

diagram.UndoManager.Redo();

diagramView.Refresh();
Thread.Sleep(1000); 



Or are you getting exception using standard ShapeNodes? I'm not sure this has anything to do with custom types, I have only vague memories we might have discussed custom node types with you before.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Ktmr
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 24
Joined: Mar 27th, 2020
Re: Undo Redo Operations
Reply #8 - May 5th, 2021 at 6:22am
Print Post  
Sorry for my mistake. I had created new node without copy constructor.  So I had got exceptions.

It works now. Thank you.

I have got another question.

I am creating new node by dragging shape from the shapelist and dropping it into to the diagramview. After the node is created, I change its properties. When undoing, the user should not see the first node.

I want to delete last action in undohistory. Is it possible or do you have any suggestion?


  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Undo Redo Operations
Reply #9 - May 5th, 2021 at 7:51am
Print Post  
Hi,

Do you mean you are replacing a ShapeNode created by ShapeListBox with one of your custom class? You could instead add custom node's instances to NodeListView control, and drag-and-drop will clone them directly then, so you won't have to deal with extraneous undo commands. Otherwise you could immediately call Undo() after copying the ShapeNode into your class' instance, but before adding the new instance to the diagram. That should leave only the record for your node in undo history.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Ktmr
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 24
Joined: Mar 27th, 2020
Re: Undo Redo Operations
Reply #10 - May 5th, 2021 at 10:48am
Print Post  
Hi,

Thank you I will try NodeListView control.

There is another problem. I am using lanegrid in diagram and listing nodes in this grid. Every cell should contain one node. How can manage this with PasteFromClipboard method?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Undo Redo Operations
Reply #11 - May 5th, 2021 at 12:50pm
Print Post  
Hi,

You could align nodes from NodePasted event handler. E.g. see some code that align node vertically in Lanes sample project.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Ktmr
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 24
Joined: Mar 27th, 2020
Re: Undo Redo Operations
Reply #12 - May 5th, 2021 at 2:51pm
Print Post  
Hi,

I mean how can I use pastefromclipboard method multiple custom nodes and get them in grid rows?

I found a solution: I am copying and pasting items one by one and controlling grid cell is empty.

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