Пример #1
0
        /// <summary>
        /// 拖动图元
        /// </summary>
        /// <param name="p">鼠标当前所在点</param>
        /// <param name="moveType">移动类型</param>
        private void DragGraphElement(List<GraphElement> graphElementList, Point p, MoveType moveType)
        {            
            Size moveSize = new Size(p.X - lastSelectedPoint.X, p.Y - lastSelectedPoint.Y);

            // 计算移动方向
            Direction direction = Direction.None;

            if (moveSize.Width > 0)
            {
                direction = Direction.Right;
            }
            else if (moveSize.Width < 0)
            {
                direction = Direction.Left;
            }
            else if (moveSize.Height > 0)
            {
                direction = Direction.Down;
            }
            else if (moveSize.Height < 0)
            {
                direction = Direction.Up;
            }

            if (!CheckMoveLag(direction))
            {
                // 重置鼠标位置
                Cursor.Position = canvas.PointToScreen(lastSelectedPoint) + new Size(canvas.AutoScrollPosition);
                return;
            }

            switch (moveType)
            {
                case MoveType.SingleElement:
                    {
                        GraphElement graphElement = graphElementList[0];

                        graphElement.Move(moveSize); // 移动选中的图元

                        if (graphElement is ConnectorGraphElement) // 当前拖动的图元是连接线控制点
                        {
                            ConnectorGraphElement connector = graphElement as ConnectorGraphElement;
                            bool activated = false; // 是否有插槽被激活

                            if (connector.IsHeadPoint || connector.IsTailPoint) // 当前拖动的连接线控制点是头结点或者尾结点
                            {
                                List<SlotContainer> regionSlotContainerList = regionManager.GetSlotContainerList(connector.Location);

                                foreach (SlotContainer slotContainer in regionSlotContainerList)
                                {
                                    if (activated) // 已经有插槽或插槽容器激活,则直接跳出
                                    {
                                        break;
                                    }

                                    SlotGraphElement slot = slotContainer.GetSlotInRegion(p);

                                    if (slot != null) // 激活当前插槽
                                    {
                                        slot.Activated = true;
                                        activated = true;
                                        lastActivatedGraphElement = slot;
                                        break;
                                    }

                                    if (slotContainer.IsInRegion(p)) // 激活当前插槽容器
                                    {
                                        slotContainer.Activated = true;
                                        activated = true;
                                        lastActivatedGraphElement = slotContainer;
                                        break;
                                    }
                                }
                            }

                            connector.Line.Moving = true;

                            // 自动调整连接线                                
                            connector.Line.AdjustLine(connector);
                        }
                        else if (graphElement is SlotContainer) // 当前拖动的图元是插槽容器
                        {
                            SlotContainer slotContainer = graphElement as SlotContainer;
                            
                            slotContainer.RefreshRelevateLine(false);
                            CreateAdjustLine(slotContainer, direction, true);
                        }
                        else if (graphElement is ResizeControler) // 当前拖动的是缩放控制点
                        {
                            SlotContainer slotContainer = (graphElement as ResizeControler).Owner;
                            CreateAdjustLine(slotContainer, direction, false);
                        }

                        graphElement.Moving = true;

                        break;
                    }
                case MoveType.MultiElement:
                    {                        
                        foreach (GraphElement graphElement in graphElementList)
                        {
                            if (graphElement is ConnectorContainer) // 当前图元是连接线控制点容器
                            {
                                ConnectorContainer line = graphElement as ConnectorContainer;
                                line.Visible = false;

                                foreach (ConnectorGraphElement connector in line.GetConnectorList()) // 移动连接线控制点
                                {
                                    if (!connector.Binded) // 连接线控制点不是连接线的头结点和尾结点
                                    {
                                        connector.Move(moveSize);
                                    }
                                    else
                                    {
                                        SlotGraphElement slot = connector.GetBindingSlot();

                                        if (slot != null)
                                        {
                                            SlotContainer slotContainer = slot.SlotContainer;

                                            if (!graphElementList.Contains(slotContainer))
                                            {
                                                FlowChartDisconnectCommand cmd = new FlowChartDisconnectCommand(this, "解除连接图元");
                                                InitFirstCommand(cmd);

                                                if (cmd.Execute(slot)) // 命令执行成功
                                                {
                                                    AdjustCommandList(cmd);
                                                }

                                                slot.Move(moveSize);
                                            }
                                        }                                        
                                    }
                                }
                            }
                            else if (graphElement is SlotContainer) // 当前图元是插槽容器
                            {
                                SlotContainer slotContainer = graphElement as SlotContainer;
                                
                                slotContainer.RefreshRelevateLine(false);
                                graphElement.Move(moveSize);
                            }
                            else // 非连接线控制点容器的图元直接移动即可
                            {
                                graphElement.Move(moveSize);
                            }

                            graphElement.Moving = true;
                        }

                        canvas.CurrentMultiSelectMark.Move(moveSize);

                        break;
                    }
            }
        }       
Пример #2
0
        /// <summary>
        /// 确认移动操作
        /// </summary>
        /// <param name="p">鼠标当前所在点</param>
        private void ConfirmLocation(Point point)
        {
            Point p = AdjustMouseLocation(point);
            Rectangle multiSelectRegion = canvas.CurrentMultiSelectMark.RegionRectangle;

            switch (userOperation) // 检查用户当前操作状态
            {                        
                case UserOperation.RegionSelect:
                    {
                        SelectGraphElementInRegion(multiSelectRegion);

                        break;
                    }
                case UserOperation.SingleSelect:
                    {
                        bool bind = false; // 是否已经绑定图元
                        bool unbind = false; // 是否已经解除绑定图元
                        selectedGraphElement.Moving = false;

                        // 自动调整绘图板大小
                        AdjustOutOfBorder();

                        if (selectedGraphElement is ConnectorGraphElement) // 拖动的是连接线控制点
                        {
                            ConnectorGraphElement connector = selectedGraphElement as ConnectorGraphElement;
                            SlotContainer slotContainer;
                            SlotGraphElement slot = null;

                            // 先解除绑定连接线控制点
                            if (connector.Binded)
                            {
                                slot = connector.GetBindingSlot();                                

                                if (slot != null)
                                {
                                    FlowChartDisconnectCommand cmd = new FlowChartDisconnectCommand(this, "解除连接图元");
                                    InitFirstCommand(cmd);

                                    if (cmd.Execute(slot)) // 命令执行成功
                                    {
                                        AdjustCommandList(cmd);
                                        unbind = true;
                                    }
                                }                                
                            }

                            if (lastActivatedGraphElement is SlotGraphElement) // 检查是否激活了插槽
                            {
                                slot = lastActivatedGraphElement as SlotGraphElement;

                                if (slot.IsInRegion(p)) // 绑定连接线控制点
                                {
                                    FlowChartConnectCommand cmd = new FlowChartConnectCommand(this, "连接图元");
                                    InitFirstCommand(cmd);

                                    if (cmd.Execute(new object[] { slot, connector })) // 命令执行成功
                                    {
                                        AdjustCommandList(cmd);
                                        bind = true;
                                    }
                                }
                            }
                            else if (lastActivatedGraphElement is SlotContainer) // 检查是否激活了插槽容器
                            {
                                slotContainer = lastActivatedGraphElement as SlotContainer;

                                if (slotContainer.IsInRegion(p)) // 绑定连接线控制点
                                {
                                    if (connector.IsHeadPoint) // 头连接点
                                    {
                                        slot = slotContainer.GetInSlot();
                                    }
                                    else if (connector.IsTailPoint) // 尾连接点
                                    {
                                        slot = slotContainer.GetOutSlot();
                                    }

                                    if (slot != null)
                                    {
                                        FlowChartConnectCommand cmd = new FlowChartConnectCommand(this, "连接图元");
                                        InitFirstCommand(cmd);

                                        if (cmd.Execute(new object[] { slot, connector })) // 命令执行成功
                                        {
                                            AdjustCommandList(cmd);
                                            bind = true;
                                        }
                                        else
                                        {
                                            slotContainer.RemoveSlot(slot);                                            
                                        }
                                    }
                                }
                            }

                            connector.Line.Moving = false;
                            connector.Line.AdjustRectangle();
                            regionManager.ChangeRegion((selectedGraphElement as ConnectorGraphElement).Line);
                        }
                        else if (selectedGraphElement is SlotContainer) // 拖动的是插槽容器
                        {
                            SlotContainer slotContainer = selectedGraphElement as SlotContainer;

                            foreach (ConnectorContainer line in slotContainer.GetConnectedLine())
                            {
                                AdjustLine(line, slotContainer);
                            }

                            slotContainer.RefreshRelevateLine(true);
                            AdjustLine(slotContainer);
                        }
                        else if (selectedGraphElement is ResizeControler) // 拖动的是缩放控制点
                        {
                            regionManager.ChangeRegion((selectedGraphElement as ResizeControler).Owner);
                        }

                        regionManager.ChangeRegion(selectedGraphElement);

                        if (!bind && !unbind) // 没有绑定和接触绑定图元,则是在移动图元
                        {
                            if (moveCommand.Execute(new object[] { selectedGraphElement, p })) // 命令执行成功
                            {
                                AdjustCommandList(moveCommand);
                            }
                        }
                        else // 已经绑定或者解除绑定图元
                        {
                            ConnectorContainer line = (selectedGraphElement as ConnectorGraphElement).Line;
                            
                            // 自动调整连接线
                            ConnectorGraphElement connector = selectedGraphElement as ConnectorGraphElement;
                            SlotContainer currentSlotContainer = null;
                            if (connector.IsHeadPoint)
                            {
                                currentSlotContainer = connector.Line.OutSlotContainer;
                            }
                            else
                            {
                                currentSlotContainer = connector.Line.InSlotContainer;
                            }
                            
                            AdjustLine(line, currentSlotContainer);
                        } 

                        break;
                    }
                case UserOperation.MultiSelect:
                    {                        
                        // 自动调整绘图板大小
                        AdjustOutOfBorder();

                        foreach (GraphElement graphElement in selectedGraphElementList)
                        {
                            if (graphElement is ConnectorContainer) // 连接线
                            {
                                graphElement.Visible = true;                               
                            }
                            else if (graphElement is SlotContainer) // 插槽容器
                            {
                                SlotContainer slotContainer = graphElement as SlotContainer;                                
                                slotContainer.RefreshRelevateLine(true);
                            }

                            regionManager.ChangeRegion(graphElement);
                            graphElement.Moving = false;
                        }
                       
                        // 自动调整连接线
                        List<SlotContainer> affectedSlotContainerList = regionManager.GetSlotContainerList(multiSelectRegion);
                        List<ConnectorContainer> affectedLineList = regionManager.GetConnectorContainerList(multiSelectRegion);

                        foreach (ConnectorContainer line in affectedLineList)
                        {
                            foreach (SlotContainer slotContainer in affectedSlotContainerList)
                            {
                                if (line.LineIntersect(slotContainer))
                                {                                    
                                    AdjustLine(line, null);
                                    break;
                                }
                            }
                        }                        

                        if (moveCommand.Execute(new object[] { selectedGraphElement, p })) // 命令执行成功
                        {
                            AdjustCommandList(moveCommand);
                        }

                        break;
                    }
                case UserOperation.MoveRodman:
                    {
                        // 自动调整绘图板大小
                        AdjustOutOfBorder();

                        foreach (GraphElement graphElement in moveGraphElementList)
                        {
                            if (graphElement is ConnectorContainer) // 连接线
                            {
                                ConnectorContainer line = graphElement as ConnectorContainer;
                                line.Visible = true;
                                line.AdjustRectangle();
                            }
                            else if (graphElement is SlotContainer) // 插槽容器
                            {
                                SlotContainer slotContainer = graphElement as SlotContainer;                                
                                slotContainer.RefreshRelevateLine(true);
                            }

                            regionManager.ChangeRegion(graphElement);
                            graphElement.Moving = false;
                        }

                        // 自动调整连接线
                        List<SlotContainer> affectedSlotContainerList = regionManager.GetSlotContainerList(multiMoveRegion);
                        List<ConnectorContainer> affectedLineList = regionManager.GetConnectorContainerList(multiMoveRegion);

                        foreach (ConnectorContainer line in affectedLineList)
                        {
                            foreach (SlotContainer slotContainer in affectedSlotContainerList)
                            {
                                if (line.LineIntersect(slotContainer))
                                {
                                    AdjustLine(line, null);
                                    break;
                                }
                            }
                        } 

                        if (moveCommand.Execute(new object[] { selectedGraphElement, p })) // 命令执行成功
                        {
                            AdjustCommandList(moveCommand);
                        }

                        break;
                    }
            }

            lockMoveDrag = false; // 拖动图元解锁
            userOperation = UserOperation.None;         
            canvas.Cursor = Cursors.Default; // 恢复绘图板的鼠标形状
            canvas.CurrentGuideLine.ClearGuideLineList();

            RefreshCanvas();
        }
Пример #3
0
        /// <summary>
        /// 移动选中的图元
        /// </summary>
        /// <param name="moveSize">移动的位移</param>
        public void MoveSelectedGraphElement(Size moveSize)
        {
            if (selectedGraphElementList.Count > 0) // 多选图元
            {
                foreach (GraphElement graphElement in selectedGraphElementList)
                {
                    if (graphElement is ConnectorContainer) // 当前图元是连接线控制点容器
                    {
                        ConnectorContainer line = graphElement as ConnectorContainer;

                        foreach (ConnectorGraphElement connector in line.GetConnectorList()) // 移动连接线控制点
                        {
                            if (!connector.Binded) // 连接线控制点不是连接线的头结点和尾结点
                            {
                                connector.Move(moveSize);
                            }
                            else
                            {
                                SlotGraphElement slot = connector.GetBindingSlot();

                                if (slot != null)
                                {
                                    SlotContainer slotContainer = slot.SlotContainer;

                                    if (!selectedGraphElementList.Contains(slotContainer))
                                    {
                                        FlowChartDisconnectCommand cmd = new FlowChartDisconnectCommand(this, "解除连接图元");
                                        InitFirstCommand(cmd);

                                        if (cmd.Execute(slot)) // 命令执行成功
                                        {
                                            AdjustCommandList(cmd);
                                        }

                                        slot.Move(moveSize);
                                    }
                                }
                            }
                        }
                    }
                    else // 非连接线控制点容器的图元直接移动即可
                    {
                        graphElement.Move(moveSize);
                    }

                    // 刷新绘图区域数据
                    regionManager.ChangeRegion(graphElement);
                }

                canvas.CurrentMultiSelectMark.Move(moveSize);

                Direction direction = Direction.None;
                if (moveSize.Width > 0)
                {
                    direction = Direction.Right;
                }
                else if (moveSize.Width < 0)
                {
                    direction = Direction.Left;
                }
                else if (moveSize.Height > 0)
                {
                    direction = Direction.Down;
                }
                else if (moveSize.Height < 0)
                {
                    direction = Direction.Up;
                }

                AutoScrollAndResizeCanvas(MoveType.MultiElement, direction); // 自动滚动并放缩
                RefreshCanvas();
            }
            else if (selectedGraphElement != null) // 单选图元
            {
                selectedGraphElement.Move(moveSize);
                Direction direction = Direction.None;

                if (moveSize.Width > 0)
                {
                    direction = Direction.Right;
                }
                else if (moveSize.Width < 0)
                {
                    direction = Direction.Left;
                }
                else if(moveSize.Height > 0)
                {
                    direction = Direction.Down;
                }
                else if(moveSize.Height < 0)
                {
                    direction = Direction.Up;
                }

                // 显示网格调整线
                if (selectedGraphElement is SlotContainer)
                {
                    CreateAdjustLine(selectedGraphElement as SlotContainer, direction, false);
                }        
        
                AutoScrollAndResizeCanvas(MoveType.SingleElement, direction); // 自动滚动并放缩

                // 刷新绘图区域数据
                regionManager.ChangeRegion(selectedGraphElement);

                RefreshCanvas();
            }
            else // 滚动滚动条
            {
                ScrollCanvas(moveSize, true);
            }
        }