/// <summary> /// 执行命令 /// </summary> /// <param name="o">当前对象</param> /// <returns>是否执行成功</returns> public override bool Execute(object o) { bool success = true; Helper helper = Helper.GetHelper(); object[] args = o as object[]; SlotGraphElement slot = args[0] as SlotGraphElement; ConnectorGraphElement connector = args[1] as ConnectorGraphElement; // 保存命令执行前的数据 if (firstCommand) // 只有第一条命令保存执行前的数据 { SaveBeforeExecute(flowChartManager.GetArguments()); } description = "连接图元 " + slot.SlotContainer.Name; slot.Bind(connector); // 执行逻辑功能 LogicBaseManager logicManager = helper.GetLogicManager(flowChartManager.CurrentChartMode); success = logicManager.DoLogicOperation(flowChartManager, LogicType.Connect, o); if (success) // 保存命令执行后的数据 { flowChartManager.ContentChanged = true; SaveAfterExecute(flowChartManager.GetArguments()); } return(success); }
/// <summary> /// 解除连接图元 /// </summary> /// <param name="flowChartManager">绘图管理器</param> /// <param name="logicData">逻辑数据</param> /// <returns>是否操作成功</returns> protected override bool LogicDisconnect(FlowChartManager flowChartManager, object logicData) { DataManager dataManager = flowChartManager.CurrentDataManager; object[] args = logicData as object[]; SlotGraphElement slot = args[0] as SlotGraphElement; ConnectorGraphElement connector = args[1] as ConnectorGraphElement; ConnectorContainer line = connector.Line; SlotContainer slotContainer = slot.SlotContainer; List <GraphElement> list = new List <GraphElement>(); // 记录遍历的图元的链表 if (connector.IsHeadPoint) // 移出连接线的头结点 { ReBindEventNode(dataManager, list, slotContainer, false); // 重新绑定当前图元与其连出图元的事件结点 } else // 移出连接线的尾结点 { SlotContainer outSlotContainer = connector.Line.OutSlotContainer; if (outSlotContainer != null) { ReBindEventNode(dataManager, list, connector.Line, false); // 重新绑定当前图元与其连出图元的事件结点 } } return(true); }
/// <summary> /// 增加跳转插槽 /// </summary> /// <returns>新增的插槽</returns> public SlotGraphElement AddJumpSlot() { JumpSlotCount = jumpSlotCount + 1; SlotGraphElement newSlot = jumpSlotList[jumpSlotCount - 1]; return(newSlot); }
/// <summary> /// 连接图元 /// </summary> /// <param name="flowChartManager">绘图管理器</param> /// <param name="logicData">逻辑数据</param> /// <returns>是否操作成功</returns> protected override bool LogicConnect(FlowChartManager flowChartManager, object logicData) { bool executeSuccess = true; DataManager dataManager = flowChartManager.CurrentDataManager; object[] data = logicData as object[]; SlotGraphElement slot = data[0] as SlotGraphElement; ConnectorGraphElement connector = data[1] as ConnectorGraphElement; bool enableConnect = true; List <GraphElement> list = new List <GraphElement>(); // 记录遍历过的图元的链表 if (connector.IsHeadPoint) // 连入插槽容器 { SlotContainer inSlotContainer = connector.Line.InSlotContainer; if (inSlotContainer != null) { List <DataElement> eventList = dataManager.GetEventList(connector.Line.OutSlotContainer); // 检查事件结点互斥 enableConnect = LogicCheck.CheckEventExclusion(eventList); if (enableConnect) // 允许连接事件结点 { bool enable = dataManager.IsConnectEventNode(inSlotContainer); ReBindEventNode(dataManager, list, slot.SlotContainer, enable); // 重新绑定当前图元与其连出图元的事件结点 } else { slot.UnBind(); executeSuccess = false; } } } else // 连出插槽容器 { SlotContainer outSlotContainer = connector.Line.OutSlotContainer; if (outSlotContainer != null) { List <DataElement> eventList = dataManager.GetEventList(outSlotContainer); if (enableConnect) // 允许连接事件结点 { bool enable = dataManager.IsConnectEventNode(slot.SlotContainer); ReBindEventNode(dataManager, list, connector.Line, enable); // 重新绑定当前图元与其连出图元的事件结点 } else { slot.UnBind(); executeSuccess = false; } } } return(executeSuccess); }
/// <summary> /// 连接图元 /// </summary> /// <param name="flowChartManager">绘图管理器</param> /// <param name="logicData">逻辑数据</param> /// <returns>是否操作成功</returns> protected virtual bool LogicConnect(FlowChartManager flowChartManager, object logicData) { object[] data = logicData as object[]; SlotGraphElement slot = data[0] as SlotGraphElement; ConnectorGraphElement connector = data[1] as ConnectorGraphElement; ConnectorContainer line = connector.Line; if ((line.InSlotContainer != null && line.OutSlotContainer != null) || connector.Selected) // 连接线控制点处于被选中状态 { flowChartManager.CurrentGraphManager.EditDataElement(line); } return(true); }
/// <summary> /// 创建并连接连接线 /// </summary> /// <param name="flowChartManager">绘图管理器</param> /// <param name="logicData">逻辑数据</param> /// <returns>是否操作成功</returns> protected virtual bool LogicCreateAndConnectLine(FlowChartManager flowChartManager, object logicData) { GraphManager graphManager = flowChartManager.CurrentGraphManager; object[] args = logicData as object[]; int id = graphManager.AllocateGraphElementID(); SlotGraphElement outSlot = args[0] as SlotGraphElement; SlotGraphElement inSlot = args[1] as SlotGraphElement; ConnectorContainer line = CreateLine(outSlot.Location, inSlot.Location, id); flowChartManager.CurrentGraphManager.SelectGraphElement(line, false); return(true); }
/// <summary> /// 创建连接线 /// </summary> /// <param name="flowChartManager">绘图管理器</param> /// <param name="logicData">逻辑数据</param> /// <returns>是否操作成功</returns> protected virtual bool LogicCreateLine(FlowChartManager flowChartManager, object logicData) { GraphManager graphManager = flowChartManager.CurrentGraphManager; object[] args = logicData as object[]; int id = graphManager.AllocateGraphElementID(); SlotGraphElement slot = args[0] as SlotGraphElement; Point p = (Point)args[1]; ConnectorContainer line = CreateLine(slot.Location, p, id); slot.Bind(line.TailConnector); flowChartManager.CurrentGraphManager.SelectGraphElement(line, false); return(true); }
/// <summary> /// 执行命令 /// </summary> /// <param name="o">当前对象</param> /// <returns>是否执行成功</returns> public override bool Execute(object o) { bool success = true; Helper helper = Helper.GetHelper(); object[] args = o as object[]; SlotGraphElement outSlot = args[0] as SlotGraphElement; SlotGraphElement inSlot = args[1] as SlotGraphElement; // 保存命令执行前的数据 if (firstCommand) // 只有第一条命令保存执行前的数据 { SaveBeforeExecute(flowChartManager.GetArguments()); } // 执行逻辑操作 LogicBaseManager logicManager = helper.GetLogicManager(flowChartManager.CurrentChartMode); logicManager.DoLogicOperation(flowChartManager, LogicType.CreateAndConnectLine, o); ConnectorContainer line = graphManager.SelectedGraphElement as ConnectorContainer; outSlot.Bind(line.GetConnectorList()[0]); inSlot.Bind(line.GetConnectorList()[1]); graphManager.ConnectorContainerList.Add(line); graphManager.SelectGraphElement(line, false); description = "创建并连接图元 " + outSlot.SlotContainer.Name + " - " + inSlot.SlotContainer.Name; dataManager.AddDataElement(line); graphManager.ReconstructCanvasGraphElementList(); // 执行逻辑操作 object[] logicData = new object[] { outSlot, outSlot.BindingConnector }; logicManager.DoLogicOperation(flowChartManager, LogicType.Connect, logicData); if (success) // 保存命令执行后的数据 { flowChartManager.ContentChanged = true; SaveAfterExecute(flowChartManager.GetArguments()); } return(success); }
/// <summary> /// 创建连接线 /// </summary> /// <param name="flowChartManager">绘图管理器</param> /// <param name="logicData">逻辑数据</param> /// <returns>是否操作成功</returns> protected override bool LogicCreateLine(FlowChartManager flowChartManager, object logicData) { GraphManager graphManager = flowChartManager.CurrentGraphManager; DataManager dataManager = flowChartManager.CurrentDataManager; object[] args = logicData as object[]; int id = graphManager.AllocateGraphElementID(); SlotGraphElement slot = args[0] as SlotGraphElement; Point p = (Point)args[1]; // 创建连接线 base.LogicCreateLine(flowChartManager, logicData); // 绑定连接线的事件 List <GraphElement> list = new List <GraphElement>(); bool enable = dataManager.IsConnectEventNode(slot.SlotContainer); ReBindEventNode(dataManager, list, slot.SlotContainer, enable); return(true); }
/// <summary> /// 获取绑定的插槽 /// </summary> /// <returns>绑定的插槽</returns> public SlotGraphElement GetBindingSlot() { SlotGraphElement slotGraphElement = null; SlotContainer slotContainer; if (isHeadPoint) { slotContainer = line.OutSlotContainer; if (slotContainer != null) { foreach (SlotGraphElement slot in slotContainer.GetInSlotList()) { if (slot.BindingConnector == this) { slotGraphElement = slot; break; } } } } else if (isTailPoint) { slotContainer = line.InSlotContainer; if (slotContainer != null) { foreach (SlotGraphElement slot in slotContainer.GetOutSlotList()) { if (slot.BindingConnector == this) { slotGraphElement = slot; break; } } } } return(slotGraphElement); }
/// <summary> /// 执行命令 /// </summary> /// <param name="o">当前对象</param> /// <returns>是否执行成功</returns> public override bool Execute(object o) { bool success = true; Helper helper = Helper.GetHelper(); SlotGraphElement slot = o as SlotGraphElement; // 保存命令执行前的数据 if (firstCommand) // 只有第一条命令保存执行前的数据 { SaveBeforeExecute(flowChartManager.GetArguments()); } ConnectorGraphElement connector = slot.BindingConnector; ConnectorContainer line = connector.Line; SlotContainer slotContainer = slot.SlotContainer; description = "解除连接图元 " + slotContainer.Name; slot.UnBind(); if (slot.CanDelete && (slot.IsInSlot || slot.SlotContainer.OutSlotCount > 1)) // 插槽可以删除 { slotContainer.RemoveSlot(slot); } // 执行逻辑操作 LogicBaseManager logicManager = helper.GetLogicManager(flowChartManager.CurrentChartMode); object[] logicData = new object[] { slot, connector }; logicManager.DoLogicOperation(flowChartManager, LogicType.Disconnect, logicData); if (success) // 保存命令执行后的数据 { flowChartManager.ContentChanged = true; SaveAfterExecute(flowChartManager.GetArguments()); } return(success); }
/// <summary> /// 获取跳转插槽 /// </summary> /// <returns>跳转插槽</returns> public SlotGraphElement GetJumpSlot() { bool find = false; // 是否已经找到没有绑定连接线控制点的插槽 SlotGraphElement newSlot = null; foreach (SlotGraphElement slot in jumpSlotList) { if (!slot.Binded) { newSlot = slot; find = true; break; } } if (!find) // 没有找到没有绑定连接线控制点的插槽,则新建一个入口插槽 { JumpSlotCount = jumpSlotCount + 1; newSlot = jumpSlotList[jumpSlotCount - 1]; } return(newSlot); }
private SlotGraphElement bindingSlot; // 绑定的插槽 /// <summary> /// 构造函数 /// </summary> /// <param name="bindingSlot">绑定的插槽</param> /// <param name="location">图元的位置</param> /// <param name="elementSize">图元的大小</param> public ConnectButton(SlotGraphElement bindingSlot, Point location, Size elementSize) : base(location, elementSize) { this.bindingSlot = bindingSlot; }
/// <summary> /// 调整插槽数量 /// </summary> /// <param name="n">插槽数量</param> private void AdjustJumpSlotList(int n) { if (n == jumpSlotList.Count) // 不需要调整插槽 { int newY; Point newPoint; // 调整插糟的坐标 for (int i = 0; i < jumpSlotList.Count; i++) { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); jumpSlotList[i].Location = newPoint; jumpSlotList[i].BindingConnectButton.Location = new Point(location.X + elementSize.Width + 5, newY - 6); if (jumpSlotList[i].Binded) // 调整绑定的连接线控制点 { jumpSlotList[i].BindingConnector.Location = newPoint; } } } else if (n < jumpSlotList.Count) // 需要减少插槽数量 { int deleteCount = jumpSlotList.Count - n; int newY; Point newPoint; List <SlotGraphElement> deleteSlotList = new List <SlotGraphElement>(); for (int i = 0; i < deleteCount; i++) { deleteSlotList.Add(jumpSlotList[jumpSlotList.Count - 1 - i]); } foreach (SlotGraphElement slot in deleteSlotList) { if (slot.Binded) { slot.UnBind(); } jumpSlotList.Remove(slot); slotList.Remove(slot); } // 调整插糟的坐标 for (int i = 0; i < jumpSlotList.Count; i++) { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); jumpSlotList[i].Location = newPoint; jumpSlotList[i].BindingConnectButton.Location = new Point(location.X + elementSize.Width + 5, newY - 6); if (jumpSlotList[i].Binded) // 调整绑定的连接线控制点 { jumpSlotList[i].BindingConnector.Location = newPoint; } } } else // 需要增加插槽数量 { int oldCount = jumpSlotList.Count; SlotGraphElement newSlot; Point newPoint; int newY; // 添加插槽并调整插槽的坐标 for (int i = 0; i < n; i++) { if (i < oldCount) { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); jumpSlotList[i].Location = newPoint; jumpSlotList[i].BindingConnectButton.Location = new Point(location.X + elementSize.Width + 5, newY - 6); if (jumpSlotList[i].Binded) // 调整绑定的连接线控制点 { jumpSlotList[i].BindingConnector.Location = newPoint; } } else { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); newSlot = new SlotGraphElement(this, newPoint, new Size(6, 6)); newSlot.Name = "连接插槽"; newSlot.FrameColor = Color.RoyalBlue; newSlot.SelectedColor = Color.Red; newSlot.ActivatedColor = Color.DarkOrange; newSlot.BindedColor = Color.Lime; newSlot.IsInSlot = false; newSlot.IsOutSlot = false; newSlot.IsJumpSlot = true; newSlot.CanDelete = false; ConnectJumpButton button = new ConnectJumpButton(newSlot, new Point(location.X + elementSize.Width + 5, newY - 6), new Size(12, 18)); button.Name = "连接按钮"; button.NormalImage = connectJumpButtonNormalImage; button.SelectedImage = connectJumpButtonSelectedImage; button.ActivatedImage = connectJumpButtonActivatedImage; newSlot.BindingConnectButton = button; buttonList.Add(button); jumpSlotList.Add(newSlot); slotList.Add(newSlot); } } } }
/// <summary> /// 删除出口插槽 /// </summary> /// <param name="slot">要删除的插槽</param> public override void RemoveOutSlot(SlotGraphElement slot) { }
/// <summary> /// 初始化结点的插槽 /// </summary> /// <param name="Size">当前图元的大小</param> protected override void InitSlot(Size size) { int x1 = location.X + (int)(size.Width / 2) - 3; int y1 = location.Y - 3; int x2 = x1; int y2 = location.Y + size.Height; int x3 = location.X + size.Width - 3; int y3 = location.Y + (int)((size.Height - 20) / 2) - 3 + 20; SlotGraphElement slot1 = new SlotGraphElement(this, new Point(x1, y1), new Size(6, 6)); SlotGraphElement slot2 = new SlotGraphElement(this, new Point(x2, y2), new Size(6, 6)); SlotGraphElement slot3 = new SlotGraphElement(this, new Point(x3, y3), new Size(6, 6)); slot1.Name = "连接插槽"; slot1.FrameColor = Color.RoyalBlue; slot1.SelectedColor = Color.Red; slot1.ActivatedColor = Color.DarkOrange; slot1.BindedColor = Color.Lime; slot1.IsInSlot = true; slot1.IsOutSlot = false; slot1.IsJumpSlot = false; slot1.CanDelete = true; slot2.Name = "连接插槽"; slot2.FrameColor = Color.RoyalBlue; slot2.SelectedColor = Color.Red; slot2.ActivatedColor = Color.DarkOrange; slot2.BindedColor = Color.Lime; slot2.IsInSlot = false; slot2.IsOutSlot = true; slot2.IsJumpSlot = false; slot2.CanDelete = true; slot3.Name = "连接插槽"; slot3.FrameColor = Color.RoyalBlue; slot3.SelectedColor = Color.Red; slot3.ActivatedColor = Color.DarkOrange; slot3.BindedColor = Color.Lime; slot3.IsInSlot = false; slot3.IsOutSlot = false; slot3.IsJumpSlot = true; slot3.CanDelete = false; ConnectButton button = new ConnectButton(slot2, new Point(x2 - 6, y2 + 5), new Size(12, 18)); button.Name = "连接按钮"; button.NormalImage = connectButtonNormalImage; button.SelectedImage = connectButtonSelectedImage; button.ActivatedImage = connectButtonActivatedImage; slot2.BindingConnectButton = button; ConnectJumpButton jumpButton = new ConnectJumpButton(slot3, new Point(x3 + 5, y3 - 6), new Size(18, 12)); jumpButton.Name = "连接按钮"; jumpButton.NormalImage = connectJumpButtonNormalImage; jumpButton.SelectedImage = connectJumpButtonSelectedImage; jumpButton.ActivatedImage = connectJumpButtonActivatedImage; slot3.BindingConnectButton = jumpButton; inSlotList.Add(slot1); outSlotList.Add(slot2); jumpSlotList.Add(slot3); buttonList.Add(button); buttonList.Add(jumpButton); slotList.Add(slot1); slotList.Add(slot2); slotList.Add(slot3); }
/// <summary> /// 删除出口插槽 /// </summary> /// <param name="slot">要删除的插槽</param> public override void RemoveOutSlot(SlotGraphElement slot) { }
/// <summary> /// 调整插槽数量 /// </summary> /// <param name="n">插槽数量</param> private void AdjustJumpSlotList(int n) { if (n == jumpSlotList.Count) // 不需要调整插槽 { int newY; Point newPoint; // 调整插糟的坐标 for (int i = 0; i < jumpSlotList.Count; i++) { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); jumpSlotList[i].Location = newPoint; jumpSlotList[i].BindingConnectButton.Location = new Point(location.X + elementSize.Width + 5, newY - 6); if (jumpSlotList[i].Binded) // 调整绑定的连接线控制点 { jumpSlotList[i].BindingConnector.Location = newPoint; } } } else if (n < jumpSlotList.Count) // 需要减少插槽数量 { int deleteCount = jumpSlotList.Count - n; int newY; Point newPoint; List<SlotGraphElement> deleteSlotList = new List<SlotGraphElement>(); for (int i = 0; i < deleteCount; i++) { deleteSlotList.Add(jumpSlotList[jumpSlotList.Count - 1 - i]); } foreach (SlotGraphElement slot in deleteSlotList) { if (slot.Binded) { slot.UnBind(); } jumpSlotList.Remove(slot); slotList.Remove(slot); } // 调整插糟的坐标 for (int i = 0; i < jumpSlotList.Count; i++) { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); jumpSlotList[i].Location = newPoint; jumpSlotList[i].BindingConnectButton.Location = new Point(location.X + elementSize.Width + 5, newY - 6); if (jumpSlotList[i].Binded) // 调整绑定的连接线控制点 { jumpSlotList[i].BindingConnector.Location = newPoint; } } } else // 需要增加插槽数量 { int oldCount = jumpSlotList.Count; SlotGraphElement newSlot; Point newPoint; int newY; // 添加插槽并调整插槽的坐标 for (int i = 0; i < n; i++) { if (i < oldCount) { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); jumpSlotList[i].Location = newPoint; jumpSlotList[i].BindingConnectButton.Location = new Point(location.X + elementSize.Width + 5, newY - 6); if (jumpSlotList[i].Binded) // 调整绑定的连接线控制点 { jumpSlotList[i].BindingConnector.Location = newPoint; } } else { newY = (int)(location.Y + (elementSize.Height - 20) * (i + 1) / (n + 1) - 3 + 20); newPoint = new Point(location.X + elementSize.Width - 3, newY); newSlot = new SlotGraphElement(this, newPoint, new Size(6, 6)); newSlot.Name = "连接插槽"; newSlot.FrameColor = Color.RoyalBlue; newSlot.SelectedColor = Color.Red; newSlot.ActivatedColor = Color.DarkOrange; newSlot.BindedColor = Color.Lime; newSlot.IsInSlot = false; newSlot.IsOutSlot = false; newSlot.IsJumpSlot = true; newSlot.CanDelete = false; ConnectJumpButton button = new ConnectJumpButton(newSlot, new Point(location.X + elementSize.Width + 5, newY - 6), new Size(12, 18)); button.Name = "连接按钮"; button.NormalImage = connectJumpButtonNormalImage; button.SelectedImage = connectJumpButtonSelectedImage; button.ActivatedImage = connectJumpButtonActivatedImage; newSlot.BindingConnectButton = button; buttonList.Add(button); jumpSlotList.Add(newSlot); slotList.Add(newSlot); } } } }
/// <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); }
/// <summary> /// 获取连出的图元链表 /// </summary> /// <param name="graphElement">当前图元</param> /// <param name="hasInnerChart">是否处理子绘图</param> /// <returns>连出的图元链表</returns> public List <GraphElement> GetNextGraphElements(GraphElement graphElement, bool dealInnerChart) { List <GraphElement> list = new List <GraphElement>(); if (graphElement is SlotContainer) // 当前图元是插槽容器 { SlotContainer slotContainer = graphElement as SlotContainer; foreach (SlotGraphElement slot in slotContainer.GetOutSlotList()) { if (slot.Binded) { list.Add(slot.BindingConnector.Line); } } } else if (graphElement is ConnectorContainer) // 当前图元是连接线控制点容器 { ConnectorContainer line = graphElement as ConnectorContainer; if (line.OutSlotContainer != null) { if (dealInnerChart) { SlotContainer slotContainer = line.OutSlotContainer; if (slotContainer is InnerChart) { SlotGraphElement slot = slotContainer.GetBindedInSlot(line); InnerChartEditor innerChartEditor = GetDataElement(slotContainer) as InnerChartEditor; if (slot != null) { InterfaceGraphElement interfaceNode = innerChartEditor.GetInterfaceNode(slot.Tag.ToString()); if (interfaceNode != null) { GraphElement connectedGraphElement = interfaceNode.GetConnectedOutGraphElement(); if (connectedGraphElement != null) { list.Add(connectedGraphElement); } } } } else if (slotContainer is InterfaceGraphElement) { InnerChart innerChart = FindGraphElementByID(int.Parse(slotContainer.Tag as string)) as InnerChart; foreach (SlotGraphElement slot in innerChart.GetOutSlotList()) { if (slot.Binded) { ConnectorContainer connectedLine = slot.BindingConnector.Line; string lineData = GetData(connectedLine) as string; if (!string.IsNullOrEmpty(lineData)) { string[] dataArray = lineData.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (dataArray[0] == slotContainer.ID.ToString()) { list.AddRange(GetNextGraphElements(slot.BindingConnector.Line, true)); break; } } /* * if (!string.IsNullOrEmpty(connectedLine.Text)) * { * string[] dataArray = connectedLine.Text.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); * * if (dataArray[0] == slotContainer.ID.ToString()) * { * list.AddRange(GetNextGraphElements(slot.BindingConnector.Line, true)); * break; * } * } */ } } /* * foreach (SlotGraphElement slot in innerChart.GetOutSlotList()) * { * if (slot.Tag.ToString() == slotContainer.ID.ToString()) * { * slotGraphElement = slot; * break; * } * } * * if (slotGraphElement != null) * { * if (slotGraphElement.Binded) * { * list.AddRange(GetNextGraphElements(slotGraphElement.BindingConnector.Line, true)); * } * } */ } else { list.Add(slotContainer); } } else { list.Add(line.OutSlotContainer); } } } return(list); }
/// <summary> /// 初始化结点的插槽 /// </summary> /// <param name="Size">当前图元的大小</param> protected override void InitSlot(Size size) { int x1 = location.X + (int)(size.Width / 2) - 3; int y1 = location.Y - 3; int x2 = x1; int y2 = location.Y + size.Height; int x3 = location.X + size.Width - 3; int y3 = location.Y + (int)((size.Height - 20) / 2) - 3 + 20; SlotGraphElement slot1 = new SlotGraphElement(this, new Point(x1, y1), new Size(6, 6)); SlotGraphElement slot2 = new SlotGraphElement(this, new Point(x2, y2), new Size(6, 6)); SlotGraphElement slot3 = new SlotGraphElement(this, new Point(x3, y3), new Size(6, 6)); slot1.Name = "连接插槽"; slot1.FrameColor = Color.RoyalBlue; slot1.SelectedColor = Color.Red; slot1.ActivatedColor = Color.DarkOrange; slot1.BindedColor = Color.Lime; slot1.IsInSlot = true; slot1.IsOutSlot = false; slot1.IsJumpSlot = false; slot1.CanDelete = true; slot2.Name = "连接插槽"; slot2.FrameColor = Color.RoyalBlue; slot2.SelectedColor = Color.Red; slot2.ActivatedColor = Color.DarkOrange; slot2.BindedColor = Color.Lime; slot2.IsInSlot = false; slot2.IsOutSlot = true; slot2.IsJumpSlot = false; slot2.CanDelete = true; slot3.Name = "连接插槽"; slot3.FrameColor = Color.RoyalBlue; slot3.SelectedColor = Color.Red; slot3.ActivatedColor = Color.DarkOrange; slot3.BindedColor = Color.Lime; slot3.IsInSlot = false; slot3.IsOutSlot = false; slot3.IsJumpSlot = true; slot3.CanDelete = false; ConnectButton button = new ConnectButton(slot2, new Point(x2 - 6, y2 + 5), new Size(12, 18)); button.Name = "连接按钮"; button.NormalImage = connectButtonNormalImage; button.SelectedImage = connectButtonSelectedImage; button.ActivatedImage = connectButtonActivatedImage; slot2.BindingConnectButton = button; ConnectJumpButton jumpButton = new ConnectJumpButton(slot3, new Point(x3 + 5, y3 - 6), new Size(18, 12)); jumpButton.Name = "连接按钮"; jumpButton.NormalImage = connectJumpButtonNormalImage; jumpButton.SelectedImage = connectJumpButtonSelectedImage; jumpButton.ActivatedImage = connectJumpButtonActivatedImage; slot3.BindingConnectButton = jumpButton; inSlotList.Add(slot1); outSlotList.Add(slot2); jumpSlotList.Add(slot3); buttonList.Add(button); buttonList.Add(jumpButton); slotList.Add(slot1); slotList.Add(slot2); slotList.Add(slot3); }
/// <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); }
private SlotGraphElement bindingSlot; // 绑定的插槽 /// <summary> /// 构造函数 /// </summary> /// <param name="bindingSlot">绑定的插槽</param> /// <param name="location">图元的位置</param> /// <param name="elementSize">图元的大小</param> public ConnectJumpButton(SlotGraphElement bindingSlot, Point location, Size elementSize) :base(location, elementSize) { this.bindingSlot = bindingSlot; }
public ConnectEventArgs(SlotGraphElement slot, ConnectorGraphElement connector) { this.slot = slot; this.connector = connector; }