Exemple #1
0
        /// <summary>
        /// 自动连接图元
        /// </summary>
        /// <param name="previousContainer">连出的插槽容器</param>
        /// <param name="currentContainer">连入的插槽容器</param>
        private void ConnectGraphElement(SlotContainer previousContainer, SlotContainer currentContainer)
        {
            SlotGraphElement outSlot = previousContainer.GetOutSlot();
            SlotGraphElement inSlot = currentContainer.GetInSlot();            

            if(outSlot != null && inSlot != null) // 可能有些结点不能分配出新插槽
            {
                FlowChartCreateAndConnectLineCommand cmd = new FlowChartCreateAndConnectLineCommand(this, "创建并连接图元");
                InitFirstCommand(cmd);

                if (cmd.Execute(new object[] { outSlot, inSlot })) // 命令执行成功
                {
                    AdjustCommandList(cmd);

                    ConnectorContainer line = selectedGraphElement as ConnectorContainer;
                    regionManager.AddToRegion(line); // 调整图元所在区域                    
                    
                    // 自动调整连接线                    
                    AdjustLine(line, currentContainer);

                    if (previousContainer is ConditionGraphElement) // 编辑条件结点连出的连接线
                    {
                        FlowChartEditCommand editCommand = new FlowChartEditCommand(this, "编辑图元");

                        if (editCommand.Execute(line))
                        {
                            AdjustCommandList(editCommand);
                        }
                    }
                }
            }                       

            autoConnect = false;
        }