Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Undo weird behavior (Read 1466 times)
corcav
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 17
Joined: Apr 1st, 2009
Undo weird behavior
Apr 1st, 2009 at 3:47pm
Print Post  
I use this kind of code to create composite shapes:

     // Implicitly created undo records will be saved here
     CompositeCmd composite = this.diagram1.UndoManager.StartComposite("Create group", true);
     // Call methods that create undo records
     ShapeNode node1 = new ShapeNode();
     node1.Resize(130, 130);
     node1.Move(0, 0);
     ShapeNode node2 = new ShapeNode();
     node2.Move(0, 0);
     node2.Resize(30, 30);
     Group g = diagram1.Factory.CreateGroup(node1);
     g.AttachProportional(node2, 10, 10, 40, 40);
     node1.SubordinateGroup.AutoDeleteItems = true;
     this.diagram1.Nodes.Add(node2);
     this.diagram1.Nodes.Add(node1);
     node1.ZIndex = 0;
     composite.Execute();

The reason I'm not using Factory method is because i want to create instance of my class that inherits from ShapeNode. Unfortunately if i add 2 nodes and i undo operation i get weird result (e.g: parts of the composite shape are deleted instead of the full shape)
What Am I doing wrong?

-Corrado
  
Back to top
 
IP Logged
 
corcav
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 17
Joined: Apr 1st, 2009
Re: Undo weird behavior
Reply #1 - Apr 1st, 2009 at 4:05pm
Print Post  
This is a easier sample that has the same effect
     CompositeCmd composite = this.diagram1.UndoManager.StartComposite("Creategroup", true);
     ShapeNode node1 = new ShapeNode();
     node1.Resize(130, 130);
     node1.Move(0, 0);
     ShapeNode node2 = new ShapeNode();
     node2.Move(0, 0);
     node2.Resize(30, 30);
     this.diagram1.Nodes.Add(node2);
     this.diagram1.Nodes.Add(node1);
     node1.ZIndex = 0;
     composite.Execute();

Run it one time, move the nodes, then run it again.
Now invoke undo, i never end up with a blank view.

Thanks
-Corrado
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Undo weird behavior
Reply #2 - Apr 2nd, 2009 at 9:14am
Print Post  
Are you using try/catch around the Undo call? Seems the group undo records are in some invalid state and Undo throws an exception, beause when the group creation method stores undo information, it expects the nodes are already added to the diagram. I have rearranged the lines a bit, and this seems to work:

Code
Select All
// Implicitly created undo records will be saved here
CompositeCmd composite = diagram.UndoManager.StartComposite("Create group", true);
// Call methods that create undo records
ShapeNode node1 = new ShapeNode();
node1.Resize(130, 130);
node1.Move(0, 0);
ShapeNode node2 = new ShapeNode();
node2.Move(0, 0);
node2.Resize(30, 30);
this.diagram.Nodes.Add(node1);
this.diagram.Nodes.Add(node2);
Group g = diagram.Factory.CreateGroup(node1);
g.AttachProportional(node2, 10, 10, 40, 40);
g.AutoDeleteItems = true;
composite.Execute();
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint