Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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);
        }