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.
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:
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