Esempio n. 1
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;
        }
Esempio n. 2
0
        /// <summary>
        /// 删除图元
        /// </summary>
        /// <param name="graphElement">要删除的图元</param>
        /// <return>是否删除成功</return>
        protected bool DeleteGraphElement(GraphElement graphElement)
        {
            Helper helper = Helper.GetHelper();
            GraphManager graphManager = data as GraphManager;
            FlowChartManager flowChartManager = graphManager.CurrentFlowChartManager;
            DataManager dataManager = flowChartManager.CurrentDataManager;            
            bool deleteSuccess = false; // 是否删除成功            

            // 执行逻辑操作
            LogicBaseManager logicManager = helper.GetLogicManager(flowChartManager.CurrentChartMode);            
            logicManager.DoLogicOperation(flowChartManager, LogicType.BeforeDelete, graphElement); 

            if (graphElement is SlotContainer) // 要删除的图元是插槽容器
            {
                SlotContainer slotContainer = graphElement as SlotContainer;
                List<GraphElement> graphElementList = new List<GraphElement>();

                // 解除绑定连接线控制点                
                foreach (ConnectorContainer line in slotContainer.GetConnectedLine())
                {
                    graphElementList.Add(line);
                }

                slotContainer.UnBind();

                // 执行逻辑操作
                logicManager.DoLogicOperation(flowChartManager, LogicType.AfterDelete, graphElementList);

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

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

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

                // 执行逻辑操作
                logicManager.DoLogicOperation(flowChartManager, LogicType.AfterDelete, graphElementList);

                graphManager.ConnectorContainerList.Remove(connectorContainer); // 从连接线控制点索引容器中删除
                deleteSuccess = true;
            }
            else if (graphElement is ConnectorGraphElement) // 要删除的图元是连接线控制点
            {
                ConnectorGraphElement connector = graphElement as ConnectorGraphElement;
                ConnectorContainer connectorContainer = connector.Line;
                List<GraphElement> graphElementList = new List<GraphElement>();

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

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

                // 执行逻辑操作
                logicManager.DoLogicOperation(flowChartManager, LogicType.AfterDelete, graphElementList);

                graphManager.ConnectorContainerList.Remove(connectorContainer); // 从连接线控制点索引容器中删除
                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;
        }