示例#1
0
        /// <summary>
        /// 初始化区域管理器
        /// </summary>
        /// <param name="slotContainerList">插槽容器链表</param>
        /// <param name="connectorContainerList">连接线链表</param>
        /// <param name="canvasSize">绘图板的大小</param>
        public void Init(List <SlotContainer> slotContainerList, List <ConnectorContainer> connectorContainerList, Size canvasSize, int gridWidth)
        {
            regionDataList.Clear();

            for (int i = 0; i < canvasSize.Width; i += 600)
            {
                for (int j = 0; j < canvasSize.Height; j += 600)
                {
                    Rectangle regionRectangle = Rectangle.Empty;
                    regionRectangle.Location = new Point(i, j);
                    int regionWidth  = 600;
                    int regionHeight = 600;

                    if (i + 600 > canvasSize.Width)
                    {
                        regionWidth = canvasSize.Width - i;
                    }

                    if (j + 600 > canvasSize.Height)
                    {
                        regionHeight = canvasSize.Height - j;
                    }

                    regionRectangle.Size = new Size(regionWidth, regionHeight);

                    RegionData regionData = new RegionData(regionRectangle);
                    regionDataList.Add(regionData);
                }
            }

            foreach (SlotContainer slotContainer in slotContainerList)
            {
                foreach (RegionData regionData in regionDataList)
                {
                    if (regionData.IsInRegion(slotContainer.InvalidRectangle))
                    {
                        regionData.Add(slotContainer);
                    }
                }
            }

            foreach (ConnectorContainer line in connectorContainerList)
            {
                foreach (RegionData regionData in regionDataList)
                {
                    if (regionData.IsInRegion(line.InvalidRectangle))
                    {
                        regionData.Add(line);
                    }
                }
            }

            InitCanvasGridBoard(slotContainerList, canvasSize, gridWidth);

            backupRegionData = new RegionData(Rectangle.Empty);
        }
示例#2
0
        /// <summary>
        /// 将插槽容器加入区域中
        /// </summary>
        /// <param name="slotContainer">当前插槽容器</param>
        private void AddToRegion(SlotContainer slotContainer)
        {
            bool added = false;

            foreach (RegionData regionData in regionDataList)
            {
                if (regionData.IsInRegion(slotContainer.InvalidRectangle))
                {
                    regionData.Add(slotContainer);
                    added = true;
                }
            }

            if (!added)
            {
                backupRegionData.Add(slotContainer);
            }

            // 更新网格数据
            UpdateSlotContainerGrid(slotContainer);
        }
示例#3
0
        /// <summary>
        /// 初始化区域管理器
        /// </summary>
        /// <param name="slotContainerList">插槽容器链表</param>
        /// <param name="connectorContainerList">连接线链表</param>
        /// <param name="canvasSize">绘图板的大小</param>
        public void Init(List<SlotContainer> slotContainerList, List<ConnectorContainer> connectorContainerList, Size canvasSize, int gridWidth)
        {
            regionDataList.Clear();

            for (int i = 0; i < canvasSize.Width; i += 600)
            {
                for (int j = 0; j < canvasSize.Height; j += 600)
                {
                    Rectangle regionRectangle = Rectangle.Empty;
                    regionRectangle.Location = new Point(i, j);
                    int regionWidth = 600;
                    int regionHeight = 600;

                    if (i + 600 > canvasSize.Width)
                    {
                        regionWidth = canvasSize.Width - i;
                    }

                    if (j + 600 > canvasSize.Height)
                    {
                        regionHeight = canvasSize.Height - j;
                    }

                    regionRectangle.Size = new Size(regionWidth, regionHeight);

                    RegionData regionData = new RegionData(regionRectangle);
                    regionDataList.Add(regionData);
                }
            }

            foreach (SlotContainer slotContainer in slotContainerList)
            {
                foreach (RegionData regionData in regionDataList)
                {
                    if (regionData.IsInRegion(slotContainer.InvalidRectangle))
                    {
                        regionData.Add(slotContainer);
                    }
                }
            }

            foreach (ConnectorContainer line in connectorContainerList)
            {
                foreach (RegionData regionData in regionDataList)
                {
                    if (regionData.IsInRegion(line.InvalidRectangle))
                    {
                        regionData.Add(line);
                    }
                }
            }

            InitCanvasGridBoard(slotContainerList, canvasSize, gridWidth);

            backupRegionData = new RegionData(Rectangle.Empty);
        }