Esempio n. 1
0
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="o">命令的参数</param>
        /// <returns>是否执行成功</returns>
        public override bool Execute(object o)
        {
            bool success             = true;
            List <GraphElement> list = new List <GraphElement>();

            // 保存命令执行前的数据
            if (firstCommand) // 只有第一条命令保存执行前的数据
            {
                SaveBeforeExecute(flowChartManager.GetArguments());
            }

            if (graphManager.SelectedGraphElementList.Count > 0) // 剪切多个图元
            {
                List <GraphElement> graphElementList = graphManager.SelectedGraphElementList;
                description = "剪切图元组";

                foreach (GraphElement graphElement in graphElementList)
                {
                    if (graphElement is SlotContainer) // 图元是插槽容器
                    {
                        SlotContainer slotContainer = graphElement as SlotContainer;

                        foreach (SlotGraphElement slot in slotContainer.GetSlotList())
                        {
                            if (slot.Binded && !graphElementList.Contains(slot.BindingConnector.Line))
                            {
                                slot.UnBind();
                            }
                        }

                        graphManager.SlotContainerList.Remove(slotContainer);
                    }
                    else if (graphElement is ConnectorContainer) // 图元是连接线
                    {
                        ConnectorContainer      line           = graphElement as ConnectorContainer;
                        List <SlotGraphElement> deleteSlotList = new List <SlotGraphElement>();

                        if (line.InSlotContainer != null && !graphElementList.Contains(line.InSlotContainer))
                        {
                            line.UnbindInSlotContainer();
                        }

                        graphManager.ConnectorContainerList.Remove(line);
                    }

                    list.Add(graphElement);
                }
            }
            else // 剪切单个图元
            {
                GraphElement graphElement = graphManager.SelectedGraphElement;
                description = "剪切图元 " + graphElement.Name;

                if (graphElement is SlotContainer) // 图元是插槽容器
                {
                    SlotContainer slotContainer = graphElement as SlotContainer;

                    slotContainer.UnBind();
                    graphManager.SlotContainerList.Remove(slotContainer);
                }
                else if (graphElement is ConnectorContainer) // 图元是连接线
                {
                    ConnectorContainer line = graphElement as ConnectorContainer;

                    if (line.InSlotContainer != null)
                    {
                        line.UnbindInSlotContainer();
                    }

                    if (line.OutSlotContainer != null)
                    {
                        line.UnbindOutSlotContainer();
                    }

                    graphManager.ConnectorContainerList.Remove(line);
                }

                list.Add(graphElement);
            }

            Hashtable cutTable = new Hashtable();

            foreach (GraphElement g in list)
            {
                cutTable[g] = dataManager.GetData(g);
            }
            documentManager.CopyTable = cutTable;

            if (success) // 保存命令执行后的数据
            {
                flowChartManager.ContentChanged = true;
                SaveAfterExecute(flowChartManager.GetArguments());
            }

            return(success);
        }
Esempio n. 2
0
        /// <summary>
        /// 删除图元
        /// </summary>
        /// <param name="graphElement">要删除的图元</param>
        /// <return>是否删除成功</return>
        protected bool DeleteGraphElement(GraphElement graphElement)
        {
            GraphManager        graphManager = data as GraphManager;
            DataManager         dataManager  = graphManager.CurrentFlowChartManager.CurrentDataManager;
            List <GraphElement> list         = new List <GraphElement>(); // 记录遍历过图元的链表
            bool deleteSuccess = false;                                   // 是否删除成功

            if (graphElement is SlotContainer)                            // 要删除的图元是插槽容器
            {
                SlotContainer slotContainer = graphElement as SlotContainer;
                ReBindEventNode(list, slotContainer, null, false); // 重新设定事件结点及图元是否可用

                foreach (SlotGraphElement slot in slotContainer.GetSlotList())
                {
                    if (slot.Binded)                                                  // 解除绑定连接线控制点
                    {
                        if (slot.IsOutSlot && slotContainer is ConditionGraphElement) // 对条件结点连出的线要进行有效性检查
                        {
                            ConnectorContainer line = slot.BindingConnector.Line;
                            if (line.Text == "×")
                            {
                                line.Invalid  = false;
                                line.ShowText = false;
                            }
                        }
                        slot.UnBind();
                    }
                }

                graphManager.SlotContainerList.Remove(slotContainer); // 从插槽容器索引链表中删除
                deleteSuccess = true;
            }
            else if (graphElement is ConnectorContainer) // 要删除的图元是连接线控制点容器
            {
                ConnectorContainer connectorContainer = graphElement as ConnectorContainer;

                SlotContainer inSlotContainer = connectorContainer.InSlotContainer;
                if (inSlotContainer != null)
                {
                    connectorContainer.UnbindInSlotContainer();
                }

                ReBindEventNode(list, connectorContainer, null, false); // 重新设定事件结点及图元是否可用

                SlotContainer outSlotContainer = connectorContainer.OutSlotContainer;
                if (outSlotContainer != null)
                {
                    connectorContainer.UnbindOutSlotContainer();
                }

                if (inSlotContainer is ConditionGraphElement) // 对条件结点连出的线要进行有效性检查
                {
                    dataManager.CheckLineValid(inSlotContainer);
                }

                graphManager.ConnectorContainerList.Remove(connectorContainer); // 从连接线控制点索引容器中删除
                deleteSuccess = true;
            }
            else if (graphElement is ConnectorGraphElement) // 要删除的图元是连接线控制点
            {
                ConnectorGraphElement connector = graphElement as ConnectorGraphElement;
                if (connector.IsHeadPoint || connector.IsTailPoint) // 不允许删除头结点和尾结点
                {
                    MessageBox.Show("不能删除头连接线控制点和尾连接线控制点!", "图元删除", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    connector.Line.RemoveConnector(connector);
                    deleteSuccess = true;
                }
            }
            else if (graphElement is SlotGraphElement) // 要删除的图元是插槽
            {
                SlotGraphElement slot = graphElement as SlotGraphElement;

                if (slot.CanDelete && (slot.IsInSlot || slot.SlotContainer.OutSlotCount > 1)) // 插槽可以删除
                {
                    SlotContainer slotContainer = slot.SlotContainer;
                    slotContainer.RemoveSlot(slot);
                    deleteSuccess = true;
                }
                else
                {
                    MessageBox.Show("该插槽不能删除", "图元删除", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (graphElement is RemarkGraphElement) // 要删除的图元是注释结点
            {
                RemarkGraphElement remarkGraphElement = graphElement as RemarkGraphElement;
                SlotContainer      slotContainer      = remarkGraphElement.Owner as SlotContainer;

                slotContainer.RemarkNode = null;
                remarkGraphElement.Owner = null;
                remarkGraphElement       = null;
                deleteSuccess            = true;
            }

            if (deleteSuccess) // 释放图元所占的资源
            {
                dataManager.DeleteData(graphElement);
                graphElement.Release();
            }

            return(deleteSuccess);
        }