/// <summary> /// 初始化结点的插槽 /// </summary> /// <param name="Size">当前图元的大小</param> protected override void InitSlot(Size size) { Helper helper = Helper.GetHelper(); int x1 = location.X + (int)(size.Width / 2); int y1 = location.Y; int x2 = x1; int y2 = location.Y + size.Height; SlotGraphElement slot1 = new SlotGraphElement(this, new Point(x1, y1), new Size(6, 6)); SlotGraphElement slot2 = new SlotGraphElement(this, new Point(x2, y2), new Size(6, 6)); slot1.Name = "连接插槽"; slot1.IsInSlot = true; slot1.CanDelete = false; slot2.Name = "连接插槽"; slot2.IsOutSlot = true; slot2.CanDelete = false; ConnectButton button = new ConnectButton(slot2, new Point(x2 - 6, y2 + 25), new Size(12, 8)); button.Name = "连接按钮"; slot2.BindingConnectButton = button; inSlotList.Add(slot1); outSlotList.Add(slot2); buttonList.Add(button); slotList.Add(slot1); slotList.Add(slot2); // 重设插槽优先级 ResetSlotProperty(inSlotList); ResetSlotProperty(outSlotList); }
/// <summary> /// 初始化结点的插槽 /// </summary> /// <param name="size">图元的大小</param> protected override void InitSlot(Size size) { Helper helper = Helper.GetHelper(); int x1 = location.X + (int)(size.Width / 2); int y1 = location.Y; int x2 = location.X; int y2 = location.Y + (int)(size.Height / 2); int x3 = location.X + size.Width; int y3 = y2; int x4 = location.X + (int)(size.Width / 2); int y4 = location.Y + size.Height; SlotGraphElement slot1 = new SlotGraphElement(this, new Point(x1, y1), new Size(6, 6)); SlotGraphElement slot2 = new SlotGraphElement(this, new Point(x2, y2), new Size(6, 6)); SlotGraphElement slot3 = new SlotGraphElement(this, new Point(x3, y3), new Size(6, 6)); SlotGraphElement slot4 = new SlotGraphElement(this, new Point(x4, y4), new Size(6, 6)); slot1.Name = "连接插槽"; slot1.IsInSlot = true; slot2.Name = "连接插槽"; slot2.IsOutSlot = true; slot2.CanDelete = false; slot2.Priority = 101; ConnectButton button1 = new ConnectButton(slot2, new Point(x2 - 6, y2 + 25), new Size(12, 8)); button1.Name = "连接按钮"; slot2.BindingConnectButton = button1; slot3.Name = "连接插槽"; slot3.IsOutSlot = true; slot3.CanDelete = false; slot3.Priority = 100; ConnectButton button2 = new ConnectButton(slot3, new Point(x3 - 6, y3 + 25), new Size(12, 8)); button2.Name = "连接按钮"; slot3.BindingConnectButton = button2; slot4.Name = "连接插槽"; slot4.IsOutSlot = true; slot4.CanDelete = false; ConnectButton button3 = new ConnectButton(slot4, new Point(x4 - 6, y4 + 25), new Size(12, 8)); button3.Name = "连接按钮"; slot4.BindingConnectButton = button3; inSlotList.Add(slot1); outSlotList.Add(slot2); outSlotList.Add(slot3); outSlotList.Add(slot4); buttonList.Add(button1); buttonList.Add(button2); buttonList.Add(button3); slotList.Add(slot1); slotList.Add(slot2); slotList.Add(slot3); slotList.Add(slot4); // 重设插槽优先级 ResetSlotProperty(inSlotList); ResetSlotProperty(outSlotList); }
/// <summary> /// 获取出口插槽 /// </summary> /// <returns>出口插槽</returns> public override SlotGraphElement GetOutSlot() { int priority = -1; SlotGraphElement newSlot = null; foreach (SlotGraphElement slot in outSlotList) { if (!slot.Binded) { if (slot.Priority < priority || priority == -1) { newSlot = slot; priority = slot.Priority; } } } return(newSlot); }
/// <summary> /// 调整出口插槽链表 /// </summary> /// <param name="n">插槽数量</param> protected override void AdjustOutSlotList(int n) { int newX; int newY; Point newPoint = Point.Empty; if (n == outSlotList.Count) // 不需要调整插槽 { newX = location.X; newY = (int)(location.Y + elementSize.Height / 2); newPoint.X = newX; newPoint.Y = newY; outSlotList[0].Location = newPoint; outSlotList[0].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[0].Binded) // 调整绑定的连接线控制点 { outSlotList[0].BindingConnector.Location = newPoint; } newX = location.X + elementSize.Width; newY = (int)(location.Y + elementSize.Height / 2); newPoint.X = newX; newPoint.Y = newY; outSlotList[1].Location = newPoint; outSlotList[1].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[1].Binded) // 调整绑定的连接线控制点 { outSlotList[1].BindingConnector.Location = newPoint; } // 调整插糟的坐标 for (int i = 2; i < outSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } } else if (n < outSlotList.Count) // 需要减少插槽数量 { int deleteCount = outSlotList.Count - n; List<SlotGraphElement> deleteSlotList = new List<SlotGraphElement>(); for (int i = 0; i < deleteCount; i++) { deleteSlotList.Add(outSlotList[outSlotList.Count - 1 - i]); } foreach (SlotGraphElement slot in deleteSlotList) { if (slot.Binded) { slot.UnBind(); } buttonList.Remove(slot.BindingConnectButton); slot.BindingConnectButton = null; outSlotList.Remove(slot); slotList.Remove(slot); } // 调整插糟的坐标 for (int i = 2; i < outSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } } else // 需要增加插槽数量 { Helper helper = Helper.GetHelper(); int oldCount = outSlotList.Count; SlotGraphElement newSlot; // 添加插槽并调整插槽的坐标 for (int i = 2; i < n; i++) { if (i < oldCount) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } else { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; newSlot = new SlotGraphElement(this, newPoint, new Size(6, 6)); newSlot.Name = "连接插槽"; newSlot.IsOutSlot = true; newSlot.CanDelete = true; newSlot.Refresh(); ConnectButton button = new ConnectButton(newSlot, new Point(newX - 6, location.Y + elementSize.Height + 25), new Size(12, 8)); button.Name = "连接按钮"; button.Refresh(); newSlot.BindingConnectButton = button; outSlotList.Add(newSlot); buttonList.Add(button); slotList.Add(newSlot); } } } ResetSlotProperty(outSlotList); }
public ConnectEventArgs(SlotGraphElement slot, ConnectorGraphElement connector) { this.slot = slot; this.connector = connector; }
private SlotGraphElement bindingSlot; // 绑定的插槽 /// <summary> /// 构造函数 /// </summary> /// <param name="bindingSlot">绑定的插槽</param> /// <param name="location">图元的位置</param> /// <param name="elementSize">图元的大小</param> public ConnectButton(SlotGraphElement bindingSlot, Point location, Size elementSize) :base(location, elementSize) { this.bindingSlot = bindingSlot; }
/// <summary> /// 初始化结点的插槽 /// </summary> /// <param name="Size">当前图元的大小</param> protected override void InitSlot(Size size) { int x1 = location.X + (int)(size.Width / 2); int y1 = location.Y; int x2 = location.X + (int)(size.Width * 1 / 4); int y2 = location.Y + size.Height; int x3 = location.X + (int)(size.Width * 2 / 4); int y3 = y2; int x4 = location.X + (int)(size.Width * 3 / 4); int y4 = y2; SlotGraphElement slot1 = new SlotGraphElement(this, new Point(x1, y1), new Size(6, 6)); SlotGraphElement slot2 = new SlotGraphElement(this, new Point(x2, y2), new Size(6, 6)); SlotGraphElement slot3 = new SlotGraphElement(this, new Point(x3, y3), new Size(6, 6)); SlotGraphElement slot4 = new SlotGraphElement(this, new Point(x4, y4), new Size(6, 6)); slot1.Name = "连接插槽"; slot1.IsInSlot = true; slot1.CanDelete = false; slot2.Name = "连接插槽"; slot2.IsOutSlot = true; slot2.CanDelete = false; slot3.Name = "连接插槽"; slot3.IsOutSlot = true; slot3.CanDelete = false; slot4.Name = "连接插槽"; slot4.IsOutSlot = true; slot4.CanDelete = false; ConnectButton button1 = new ConnectButton(slot2, new Point(x2 - 6, y2 + 25), new Size(12, 8)); button1.Name = "连接按钮"; slot2.BindingConnectButton = button1; ConnectButton button2 = new ConnectButton(slot3, new Point(x3 - 6, y3 + 25), new Size(12, 8)); button2.Name = "连接按钮"; slot3.BindingConnectButton = button2; ConnectButton button3 = new ConnectButton(slot4, new Point(x4 - 6, y4 + 25), new Size(12, 8)); button3.Name = "连接按钮"; slot4.BindingConnectButton = button3; inSlotList.Add(slot1); outSlotList.Add(slot2); outSlotList.Add(slot3); outSlotList.Add(slot4); buttonList.Add(button1); buttonList.Add(button2); buttonList.Add(button3); slotList.Add(slot1); slotList.Add(slot2); slotList.Add(slot3); slotList.Add(slot4); // 重设插槽优先级 ResetSlotProperty(inSlotList); ResetSlotProperty(outSlotList); }
/// <summary> /// 调整入口插槽链表 /// </summary> /// <param name="n">插槽数量</param> protected virtual void AdjustInSlotList(int n) { if (n == inSlotList.Count) // 不需要调整插槽 { int newX; Point newPoint; // 调整插糟的坐标 for (int i = 0; i < inSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i + 1) / (n + 1)); newPoint = new Point(newX, location.Y); inSlotList[i].Location = newPoint; if (inSlotList[i].Binded) // 调整绑定的连接线控制点 { inSlotList[i].BindingConnector.Location = newPoint; } } } else if (n < inSlotList.Count) // 需要减少插槽数量 { int deleteCount = inSlotList.Count - n; int newX; Point newPoint; List<SlotGraphElement> deleteSlotList = new List<SlotGraphElement>(); for (int i = 0; i < deleteCount; i++) { deleteSlotList.Add(inSlotList[inSlotList.Count - 1 - i]); } foreach (SlotGraphElement slot in deleteSlotList) { if (slot.Binded) { slot.UnBind(); } inSlotList.Remove(slot); slotList.Remove(slot); } // 调整插糟的坐标 for (int i = 0; i < inSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i + 1) / (n + 1)); newPoint = new Point(newX, location.Y); inSlotList[i].Location = newPoint; if (inSlotList[i].Binded) // 调整绑定的连接线控制点 { inSlotList[i].BindingConnector.Location = newPoint; } } } else // 需要增加插槽数量 { int oldCount = inSlotList.Count; SlotGraphElement newSlot; Point newPoint; int newX; // 添加插槽并调整插槽的坐标 for (int i = 0; i < n; i++) { if (i < oldCount) { newX = (int)(location.X + elementSize.Width * (i + 1) / (n + 1)); newPoint = new Point(newX, location.Y); inSlotList[i].Location = newPoint; if (inSlotList[i].Binded) // 调整绑定的连接线控制点 { inSlotList[i].BindingConnector.Location = newPoint; } } else { newX = (int)(location.X + elementSize.Width * (i + 1) / (n + 1)); newPoint = new Point(newX, location.Y); newSlot = new SlotGraphElement(this, newPoint, new Size(6, 6)); newSlot.Name = "连接插槽"; newSlot.IsInSlot = true; newSlot.CanDelete = true; newSlot.Refresh(); inSlotList.Add(newSlot); slotList.Add(newSlot); } } } ResetSlotProperty(inSlotList); }
/// <summary> /// 删除出口插槽 /// </summary> /// <param name="slot">要删除的插槽</param> protected virtual void RemoveOutSlot(SlotGraphElement slot) { if (slot.Binded) // 解除绑定 { slot.UnBind(); } outSlotList.Remove(slot); slotList.Remove(slot); buttonList.Remove(slot.BindingConnectButton); outSlotCount = outSlotList.Count; AdjustOutSlotList(outSlotList.Count); }
/// <summary> /// 删除入口插槽 /// </summary> /// <param name="slot">要删除的插槽</param> protected virtual void RemoveInSlot(SlotGraphElement slot) { if(slot.Binded) // 解除绑定 { slot.UnBind(); } inSlotList.Remove(slot); slotList.Remove(slot); inSlotCount = inSlotList.Count; AdjustInSlotList(inSlotList.Count); }
/// <summary> /// 删除插槽 /// </summary> /// <param name="slot">要删除的插槽</param> public virtual void RemoveSlot(SlotGraphElement slot) { if (slot.IsInSlot) // 入口插槽 { RemoveInSlot(slot); } else // 出口插槽 { RemoveOutSlot(slot); } }
/// <summary> /// 调整出口插槽链表 /// </summary> /// <param name="n">插槽数量</param> protected override void AdjustOutSlotList(int n) { int newX; int newY; Point newPoint = Point.Empty; if (n == outSlotList.Count) // 不需要调整插槽 { newX = location.X; newY = (int)(location.Y + elementSize.Height / 2); newPoint.X = newX; newPoint.Y = newY; outSlotList[0].Location = newPoint; outSlotList[0].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[0].Binded) // 调整绑定的连接线控制点 { outSlotList[0].BindingConnector.Location = newPoint; } newX = location.X + elementSize.Width; newY = (int)(location.Y + elementSize.Height / 2); newPoint.X = newX; newPoint.Y = newY; outSlotList[1].Location = newPoint; outSlotList[1].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[1].Binded) // 调整绑定的连接线控制点 { outSlotList[1].BindingConnector.Location = newPoint; } // 调整插糟的坐标 for (int i = 2; i < outSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } } else if (n < outSlotList.Count) // 需要减少插槽数量 { int deleteCount = outSlotList.Count - n; List <SlotGraphElement> deleteSlotList = new List <SlotGraphElement>(); for (int i = 0; i < deleteCount; i++) { deleteSlotList.Add(outSlotList[outSlotList.Count - 1 - i]); } foreach (SlotGraphElement slot in deleteSlotList) { if (slot.Binded) { slot.UnBind(); } buttonList.Remove(slot.BindingConnectButton); slot.BindingConnectButton = null; outSlotList.Remove(slot); slotList.Remove(slot); } // 调整插糟的坐标 for (int i = 2; i < outSlotList.Count; i++) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } } else // 需要增加插槽数量 { Helper helper = Helper.GetHelper(); int oldCount = outSlotList.Count; SlotGraphElement newSlot; // 添加插槽并调整插槽的坐标 for (int i = 2; i < n; i++) { if (i < oldCount) { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; outSlotList[i].Location = newPoint; outSlotList[i].BindingConnectButton.Location = new Point(newX - 6, newY + 25); if (outSlotList[i].Binded) // 调整绑定的连接线控制点 { outSlotList[i].BindingConnector.Location = newPoint; } } else { newX = (int)(location.X + elementSize.Width * (i - 2 + 1) / (n - 2 + 1)); newY = location.Y + elementSize.Height; newPoint.X = newX; newPoint.Y = newY; newSlot = new SlotGraphElement(this, newPoint, new Size(6, 6)); newSlot.Name = "连接插槽"; newSlot.IsOutSlot = true; newSlot.CanDelete = true; newSlot.Refresh(); ConnectButton button = new ConnectButton(newSlot, new Point(newX - 6, location.Y + elementSize.Height + 25), new Size(12, 8)); button.Name = "连接按钮"; button.Refresh(); newSlot.BindingConnectButton = button; outSlotList.Add(newSlot); buttonList.Add(button); slotList.Add(newSlot); } } } ResetSlotProperty(outSlotList); }