Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic About using the library to store all the information of the selected ShapeNode in the diagram (Read 2325 times)
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
About using the library to store all the information of the selected ShapeNode in the diagram
Sep 28th, 2020 at 6:29am
Print Post  
Hi, there Smiley

I want to talk about a function I want to achieve:
After clicking a button, a library will be created. The function of this library is to store a series of operations on the selected ShapeNode, including screenshots, coordinate positions, rotation angles, etc. within the range of this ShapeNode. This library can also be exported Save it to the computer's hard drive, and import it into the program to restore all the display information of this ShapeNode in the diagram when necessary. Excuse me, which way is better to generate this library?

Any assistance would be appreciated.

Cheers,

Jack
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: About using the library to store all the information of the selected ShapeNode in the diagram
Reply #1 - Sep 28th, 2020 at 7:27am
Print Post  
Hi,

You can achieve similar functionality, by handling the Diagram.ActionRecorded event (you will need to enable undo/redo operations by setting Diagram.UndoManager.UndoEnabled to true), and from the handler saving the diagram state (how to save the diagram state, refer tohttps://www.mindfusion.eu/onlinehelp/wpfdiagram/index.htm?Serializing_Diagrams.h...). You can then restore the diagram from those snapshot states.

To handle item property changes other than bounds changes, you will need to create ChangeItemCmd instances to record those changes in the UndoManager history and raise the ActionRecorded event. How to do that, you can see here: https://www.mindfusion.eu/onlinehelp/wpfdiagram/index.htm?CC_Undo_or_Redo_of_Pro...

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: About using the library to store all the information of the selected ShapeNode in the diagram
Reply #2 - Sep 28th, 2020 at 7:45am
Print Post  
Hi, Lyubo. Smiley

Please don't mind, because my current technical knowledge of wpf is not proficient enough, I implore you to write an example for my reference.

Best regards.
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: About using the library to store all the information of the selected ShapeNode in the diagram
Reply #3 - Oct 22nd, 2020 at 1:03pm
Print Post  
Hi,

First make sure you enable the undo functionality by setting Diagram.UndoManager.UndoEnabled to true. That will enable the undo history and the Diagram.ActionRecorded event, which will be raised on any change that is recorded in the UndoManager's history. From an ActionRecorded event handler, you can save the diagram state at the moment of the change to file or to string, which can be stored at your convenience. The diagram can later be restored to that state by calling the appropriate Load* method. The following code will create separate xml files after each recorded change in the diagram:

Code
Select All
diagram.UndoManager.UndoEnabled = true;
diagram.ActionRecorded += Diagram_ActionRecorded;

// ...

private void Diagram_ActionRecorded(object sender, UndoEventArgs e)
{
    var timestamp = DateTime.Now.Ticks.ToString();
    diagram.SaveToXml(string.Format("diagram_state_{0}.xml", timestamp));
} 



To record non-interactive changes to diagram items, you will need to implement ChangeItem commands. How to achieve that (and with examples) is explained in detail here: https://www.mindfusion.eu/onlinehelp/wpfdiagram/index.htm?CC_Undo_or_Redo_of_Pro...

Regards,
Lyubo
MindFusion
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: About using the library to store all the information of the selected ShapeNode in the diagram
Reply #4 - Oct 23rd, 2020 at 1:41am
Print Post  
Thank you very much for your professional answer.
It is really helpful to me. Smiley

Best regards to you.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint