/// <summary> /// 添加连接,之所以使用偏移而不使用起始点,是因为在保存文件时,double会导致精度问题,从而点跑出框外 /// </summary> /// <param name="pt1">起点偏移</param> /// <param name="pt2">终点偏移</param> public void AddLink(Point pt1, Point pt2, DeviceCard srcCard, DeviceCard dstCard, DeviceSocket srcSocket, DeviceSocket dstSocket, DeviceBase dest) { Link lnk = new Link(); lnk.PTSrcOffset = pt1; lnk.PTDstOffset = pt2; lnk.PTSRC = new Point( pt1.X + (double)ImageBorder.GetValue(Canvas.LeftProperty), pt1.Y + (double)ImageBorder.GetValue(Canvas.TopProperty)); lnk.PTDST = new Point( pt2.X + (double)dest.ImageBorder.GetValue(Canvas.LeftProperty), pt2.Y + (double)dest.ImageBorder.GetValue(Canvas.TopProperty)); lnk.PaintBoard = paintBoard; lnk.SrcDevice = this; lnk.SrcCard = srcCard; lnk.SrcSocket = srcSocket; lnk.DstDevice = dest; lnk.DstCard = dstCard; lnk.DstSocket = dstSocket; lnk.TextSrc.Text = srcCard.toString(); if (srcCard.ShowSocket) lnk.TextSrc.Text += "/" + srcSocket.toString(); lnk.TextDst.Text = dstCard.toString(); if (dstCard.ShowSocket) lnk.TextDst.Text += "/" + dstSocket.toString(); try { if (SetDeviceSocketUsed(srcCard, srcSocket, this) && SetDeviceSocketUsed(dstCard, dstSocket, dest)) { linkList.Add(lnk); dest.GetLinkList().Add(lnk); paintBoard.Children.Add(lnk); AdjustLinkPosition(lnk); destination = null; } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
private bool SetDeviceSocketUsed(DeviceCard card, DeviceSocket socket, DeviceBase device) { if (card != null && socket != null) { socket.Used = true; card.Socket_Used_Number++; return true; } else return false; }