public void AddExistRelation(IDesignRelation idr)//添加关联,自行判断是否有关联控件存在 { if (idr == null) { return; } if (NodeList.Count == 0) { return; } idr.designCanvas = this; IDesignNode sdn = null, tdn = null; if (idr.SourceID != null) { List <IDesignNode> rl = NodeList.Where(n => n.ObjectID == idr.SourceID).ToList(); if (rl.Count > 0) { sdn = rl[0]; } } if (idr.TargetID != null) { List <IDesignNode> rl = NodeList.Where(n => n.ObjectID == idr.SourceID).ToList(); if (rl.Count > 0) { tdn = rl[0]; } } if (sdn != null) { idr.StartAnchorPoint = sdn.getDefaultAnchorPoint(); idr.StartPoint = idr.StartAnchorPoint.getDesignCanvasPoint(); } else { idr.StartAnchorPoint = null; idr.StartPoint = new Point(DeseignCanvas.Width / 2 - (new Random()).Next(50), DeseignCanvas.Height / 2 - (new Random()).Next(50)); } if (tdn != null) { idr.EndAnchorPoint = tdn.getDefaultAnchorPoint(); idr.EndPoint = idr.EndAnchorPoint.getDesignCanvasPoint(); } else { idr.EndAnchorPoint = null; idr.EndPoint = new Point(DeseignCanvas.Width / 2 + (new Random()).Next(150), DeseignCanvas.Height / 2 + (new Random()).Next(150)); } FrameworkElement fe = idr.getControl(); DeseignCanvas.Children.Add(fe); idr.DrawRelationLine(idr.StartPoint, idr.EndPoint); sendObjectOperationEvent(idr, DesignOperationFlag.CreateRelation);//提示设计图增加了节点对象 RelationList.Add(idr); }
public void AddExistRelation(IDesignRelation idr, IDesignNode sdn, IDesignNode tdn)//在指定的起始节点和终止节点之间添加一个关联控件 { if (idr == null) { return; } if (NodeList.Count == 0) { return; } idr.designCanvas = this; if (sdn != null) { idr.StartAnchorPoint = sdn.getDefaultAnchorPoint(); idr.StartPoint = idr.StartAnchorPoint.getDesignCanvasPoint(); } else { idr.StartAnchorPoint = null; idr.StartPoint = new Point(DeseignCanvas.Width / 2 - (new Random()).Next(50), DeseignCanvas.Height / 2 - (new Random()).Next(50)); } if (tdn != null) { idr.EndAnchorPoint = tdn.getDefaultAnchorPoint(); idr.EndPoint = idr.EndAnchorPoint.getDesignCanvasPoint(); } else { idr.EndAnchorPoint = null; idr.EndPoint = new Point(DeseignCanvas.Width / 2 + (new Random()).Next(150), DeseignCanvas.Height / 2 + (new Random()).Next(150)); } FrameworkElement fe = idr.getControl(); DeseignCanvas.Children.Add(fe); idr.DrawRelationLine(idr.StartPoint, idr.EndPoint); sendObjectOperationEvent(idr, DesignOperationFlag.CreateRelation);//提示设计图增加了节点对象 RelationList.Add(idr); }