Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Some strange problem (Read 6057 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Some strange problem
Mar 9th, 2011 at 12:14pm
Print Post  
Hello, Stoyo. I have the Hashtable which keeps the Diagram objects with Int32 values as keys of the Hashtable. And also I have some functions:
Code
Select All
	  public static int PutDiagramToHashTable(Diagram a_Diagram)
	  {
		m_DiagramsTable.Add(m_nDiagramIndex, a_Diagram);
		return m_nDiagramIndex++;
	  }
	  public static Diagram GetDiagramFromHashTable(int a_nDiagramId)
	  {
		if (m_DiagramsTable.ContainsKey(a_nDiagramId))
		    return m_DiagramsTable[a_nDiagramId] as Diagram;
		return null;
	  }
 


When I call the GetDiagramFromHashTable function I receive the necessary Diagram object which keeps the nodes which I expect. But when I try to set this object to my Diagram in the user control I see the clear Diagram and there are no exceptions...
Code
Select All
m_Diagram = App.GetDiagramFromHashTable(nIdx);
 


where m_Diagram is an object in the user control for displaying diagram.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some strange problem
Reply #1 - Mar 9th, 2011 at 1:47pm
Print Post  
Hi. Shouldn't you also replace the diagram in the usercontrol's root panel? I.e. remove the old one from panel.Children and add the one returned by GetDiagramFromHashTable.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Some strange problem
Reply #2 - Mar 9th, 2011 at 2:27pm
Print Post  
Yes, I can do this, but I made the following.
Code
Select All
				Diagram dgrm = App.GetDiagramFromHashTable(nIdx);
				MemoryStream stream = Utils.SaveDiagram(dgrm);
				stream.Position = 0;
				Utils.RestoreDiagram(stream.ToArray(), m_Diagram);
 


Save and Restore functions calls LoadFromString and SaveToString methods. After that all works nice but slowly when objects are large
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Some strange problem
Reply #3 - Mar 9th, 2011 at 4:08pm
Print Post  
I have another problem. I have an MDI interface with 2 user controls in 2 MDI windows. Each user control keeps the Diagram object. I select one derived from ShapeNode object and copy it into clipboard.
Code
Select All
public void Copy_Executed(object sender, ExecutedRoutedEventArgs e)
	  {
		List<DiagramLink> deselectedLinks = ExcludeUnconnectedLinksFromSelection();
		m_Diagram.CopyToClipboard(false);
		foreach (DiagramLink link in deselectedLinks)
		    m_Diagram.Selection.Links.Add(link);
	  }
 


After that I try to paste them into the another user control with another Diagram object. The code is the following:
Code
Select All
CompositeCmd undoCommand = new CompositeCmd(m_Diagram, UndoCommands.AddNode);
		m_Diagram.PasteFromClipboard(new Vector(50, 50), false);
		List<ReassignedHids> hids = new List<ReassignedHids>();
		foreach (DiagramNode node in m_Diagram.Selection.Nodes)
		{
		    AddItemCmd cmd = new AddItemCmd(node);
		    undoCommand.AddSubCmd(cmd);
		    if (node is TPDENode)
		    {
			  TPDENode tpdeNode = node as TPDENode;
			  if (tpdeNode.ShadowProps.ShowShadows)
			  {
				DropShadowEffect effect = new DropShadowEffect();
				effect.Color = tpdeNode.ShadowProps.ShadowColor;
				effect.ShadowDepth = tpdeNode.ShadowProps.ShadowDepth;
				tpdeNode.Effect = effect;
				tpdeNode.Repaint(false);
			  }
			  if (node is TechnologicalOperation)
			  {
				TechnologicalOperation operation = node as TechnologicalOperation;
				ReassignedHids hid = new ReassignedHids(operation.Id, Id.GetDescendant(LastAssignedId, SqlHierarchyId.Null));
				hids.Add(hid);
				operation.Id = Id.GetDescendant(LastAssignedId, SqlHierarchyId.Null);
				LastAssignedId = operation.Id;
				BreadCrumbProcessDescription desc = new BreadCrumbProcessDescription(operation.Text, operation.Id,
				    NodeType.SimpleProcess);
				AddProcessToBreadcrumb(desc);
			  }
			  else if (node is OperationGroupNode)
			  {
				OperationGroupNode operationGrp = node as OperationGroupNode;
				ReassignedHids hid = new ReassignedHids(operationGrp.Id, Id.GetDescendant(LastAssignedId, SqlHierarchyId.Null));
				hids.Add(hid);
				operationGrp.Id = Id.GetDescendant(LastAssignedId, SqlHierarchyId.Null);
				LastAssignedId = operationGrp.Id;
				BreadCrumbProcessDescription desc = new BreadCrumbProcessDescription(operationGrp.Text,
				    operationGrp.Id, NodeType.ComplexProcess);
				AddProcessToBreadcrumb(desc);
			  }
		    }
		}
		e.Source = hids;
		try
		{
		    undoCommand.Execute();
		}
		catch (Exception ex)
		{
		}
 


After that I catch the exception "Must disconnect specified child from current parent Visual before attaching to new parent Visual." When I do the same within one Diagram object all works ok
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some strange problem
Reply #4 - Mar 9th, 2011 at 7:04pm
Print Post  
What's shown at the top of the exception's stack trace? Copy and paste worked for me between two diagrams with standard ShapeNodes.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Some strange problem
Reply #5 - Mar 10th, 2011 at 7:11am
Print Post  
I have used th your source codes and seen that the exception take place after AddVisualChild(v); in the method internal void AddVisual(Visual v) of the class TranslateLayer: FrameworkElement. In the output console it looks like the following
Code
Select All
Step into: Stepping over method without symbols 'System.Collections.CollectionBase.Count.get'
Step into: Stepping over method without symbols 'System.Collections.CollectionBase.Count.get'
Step into: Stepping over property 'MindFusion.Diagramming.Wpf.DiagramItem.UIElement.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over property 'MindFusion.Diagramming.Wpf.DiagramItem.Adorner.get'.  To step into properties, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Step into: Stepping over method without symbols 'System.Windows.Media.Visual.AddVisualChild'
A first chance exception of type 'System.ArgumentException' occurred in PresentationCore.dll
 


For doing the same with standard ShapeNode object I need to modify my code. So it will take some time
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some strange problem
Reply #6 - Mar 10th, 2011 at 9:48am
Print Post  
Actually doesn't your code add the just pasted nodes for a second time to m_Diagram? The Paste method adds them once, and then the AddItemCmds created in the foreach loop.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Some strange problem
Reply #7 - Mar 10th, 2011 at 11:08am
Print Post  
No. I only one time call m_Diagram.PasteFromClipboard(new Vector(50, 50), false);
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Some strange problem
Reply #8 - Mar 10th, 2011 at 11:31am
Print Post  
When I try to do the same with simple rect ShapeNode I see the same: A first chance exception of type 'System.ArgumentException' occurred in PresentationCore.dll with message "Must disconnect specified child from current parent Visual before attaching to new parent Visual."
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some strange problem
Reply #9 - Mar 10th, 2011 at 11:36am
Print Post  
Code
Select All
No. I only one time call m_Diagram.PasteFromClipboard(new Vector(50, 50), false);  



However the foreach loop after that adds the pasted nodes again, if you are still using the code posted above. I suppose you will get such exceptions in that case.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Some strange problem
Reply #10 - Mar 10th, 2011 at 11:49am
Print Post  
The foreach loop doesn't add nodes again. It still set some properties and modify some other controls (if you keep in mind the loop: foreach (DiagramNode node in m_Diagram.Selection.Nodes)
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some strange problem
Reply #11 - Mar 10th, 2011 at 12:33pm
Print Post  
What do you think the AddItemCmd commands created in that loop do? I have added the command to my test and it throws that exception indeed:

diagram.PasteFromClipboard(new Vector(10, 10));
diagram.ExecuteCommand(new AddItemCmd(diagram.Selection.Nodes[0]));

Otherwise it works fine if you remove the AddItemCmd line.
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Some strange problem
Reply #12 - Mar 10th, 2011 at 12:39pm
Print Post  
But in this case how I have to organize the Undo/Redo operations if I need to undo all pasted item in one transaction? And also when I undo paste operation I need to know which nodes removes from diagram to sunchronize the diagram with my TreeView and Breadcrumb control?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Some strange problem
Reply #13 - Mar 10th, 2011 at 1:10pm
Print Post  
PasteFromClipboard already does that as an atomic operation. It creates a composite command internally with AddItemCmds for each item, so synchronizing with your other controls should not be any different from what you are doing now (in response to ActionUndone I guess?).
« Last Edit: Mar 11th, 2011 at 7:30am by Stoyo »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint