/// <summary> /// 绑定连接线控制点 /// </summary> /// <param name="connector">连接线控制点</param> public void Bind(ConnectorGraphElement connector) { if (binded && connector != bindingConnector) // 已经绑定了连接线控制点 { MessageBox.Show("该插槽已经绑定了连接线控制点!", "连接绑定检查", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (isInSlot && connector.IsTailPoint) { MessageBox.Show("入口插槽不能绑定出端连接线控制点!", "连接绑定检查", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (isOutSlot && connector.IsHeadPoint) { MessageBox.Show("出口插槽不能绑定了入端连接线控制点!", "连接绑定检查", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { bindingConnector = connector; bindingConnector.Binded = true; bindingConnector.Location = location; Binded = true; // 处理逻辑连接信息 if (connector.IsHeadPoint) // 连接线控制点是头控制点 { connector.Line.OutSlotContainer = slotContainer; } else // 连接线控制点是尾控制点 { connector.Line.InSlotContainer = slotContainer; } } }
/// <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> /// <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 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> public void UnBind() { // 处理逻辑连接信息 if (bindingConnector.IsHeadPoint) // 连接线控制点是头控制点 { bindingConnector.Line.OutSlotContainer = null; } else // 连接线控制点是尾控制点 { bindingConnector.Line.InSlotContainer = null; } bindingConnector.Binded = false; bindingConnector = null; Binded = false; }
/// <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> /// <param name="n">连接线控制点数量</param> protected virtual void AdjustConnector(int n) { if (n == connectorList.Count) // 连接线控制点数量没有变化 { return; } if (n < connectorList.Count) // 连接线控制点数量减少 { List<ConnectorGraphElement> deleteConnectorList = new List<ConnectorGraphElement>(); // 要删除的连接线控制点链表 int deleteCount = connectorList.Count - n; for (int i = 0; i < deleteCount; i++) { deleteConnectorList.Add(connectorList[connectorList.Count - 2 - i]); } foreach (ConnectorGraphElement connector in deleteConnectorList) { connectorList.Remove(connector); } } else // 连接线控制点数量增加 { int addCount = n - connectorList.Count; Point point1 = connectorList[connectorList.Count - 2].Location; Point point2 = connectorList[connectorList.Count - 1].Location; Point newPoint; ConnectorGraphElement newConnector; ConnectorGraphElement headConnector; int newX; int newY; // 先移除连接线的头连接控制点,最后再添加回去,保证新加的点都是在最后第二个点和最后一个点之间 headConnector = connectorList[connectorList.Count - 1]; connectorList.Remove(headConnector); for (int i = 1; i <= addCount; i++) { newX = (int)(point1.X + (point2.X - point1.X) * i / (addCount + 1) - 3); newY = (int)(point1.Y + (point2.Y - point1.Y) * i / (addCount + 1) - 3); newPoint = new Point(newX, newY); newConnector = new ConnectorGraphElement(this, newPoint, new Size(6, 6)); newConnector.Name = "连接线控制点"; newConnector.Refresh(); connectorList.Add(newConnector); } connectorList.Add(headConnector); } }
/// <summary> /// 初始化连接线控制点 /// </summary> /// <param name="tail">尾部连接控制点</param> /// <param name="head">头部连接控制点</param> protected virtual void InitConnector(Point tail, Point head) { int x1 = tail.X - 3; int y1 = tail.Y - 3; int x2 = head.X - 3; int y2 = head.Y - 3; connectorList.Clear(); ConnectorGraphElement connector1 = new ConnectorGraphElement(this, new Point(x1, y1), new Size(6, 6)); ConnectorGraphElement connector2 = new ConnectorGraphElement(this, new Point(x2, y2), new Size(6, 6)); connector1.Name = "连接线控制点"; connector1.IsTailPoint = true; connector2.Name = "连接线控制点"; connector2.IsHeadPoint = true; tailConnector = connector1; headConnector = connector2; connectorList.Add(connector1); connectorList.Add(connector2); }
/// <summary> /// 调整连接线 /// </summary> /// <param name="currentConnector">当前的连接线控制点</param> public virtual void AdjustLine(ConnectorGraphElement currentConnector) { if (inSlotContainer != null && outSlotContainer != null) // 连接线两端均已连接图元 { int headX = headConnector.Location.X; int headY = headConnector.Location.Y; int tailX = tailConnector.Location.X; int tailY = tailConnector.Location.Y; switch (connectorCount) { case 2: { break; } case 4: { ConnectorGraphElement connector1 = connectorList[0]; ConnectorGraphElement connector2 = connectorList[1]; ConnectorGraphElement connector3 = connectorList[2]; ConnectorGraphElement connector4 = connectorList[3]; if (currentConnector == connector1) { connector2.Location = new Point(connector1.Location.X, connector2.Location.Y); } else if (currentConnector == connector2) { connector2.Location = new Point(connector1.Location.X, connector2.Location.Y); connector3.Location = new Point(connector4.Location.X, connector2.Location.Y); } else if (currentConnector == connector3) { connector3.Location = new Point(connector4.Location.X, connector3.Location.Y); connector2.Location = new Point(connector1.Location.X, connector3.Location.Y); } else if (currentConnector == connector4) { connector3.Location = new Point(connector4.Location.X, connector3.Location.Y); } break; } case 6: { ConnectorGraphElement connector1 = connectorList[0]; ConnectorGraphElement connector2 = connectorList[1]; ConnectorGraphElement connector3 = connectorList[2]; ConnectorGraphElement connector4 = connectorList[3]; ConnectorGraphElement connector5 = connectorList[4]; ConnectorGraphElement connector6 = connectorList[5]; if (currentConnector == connector1) { connector2.Location = new Point(connector1.Location.X, connector2.Location.Y); } else if (currentConnector == connector2) { connector2.Location = new Point(connector1.Location.X, connector2.Location.Y); connector3.Location = new Point(connector3.Location.X, connector2.Location.Y); } else if (currentConnector == connector3) { connector2.Location = new Point(connector1.Location.X, connector3.Location.Y); connector4.Location = new Point(connector3.Location.X, connector5.Location.Y); } else if (currentConnector == connector4) { connector3.Location = new Point(connector4.Location.X, connector3.Location.Y); connector5.Location = new Point(connector6.Location.X, connector4.Location.Y); } else if (currentConnector == connector5) { connector4.Location = new Point(connector4.Location.X, connector5.Location.Y); connector5.Location = new Point(connector6.Location.X, connector5.Location.Y); } else if (currentConnector == connector6) { connector5.Location = new Point(connector6.Location.X, connector5.Location.Y); } break; } } } }
/// <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="connector">连接线控制点</param> public void Bind(ConnectorGraphElement connector) { if(binded && connector != bindingConnector) // 已经绑定了连接线控制点 { MessageBox.Show("该插槽已经绑定了连接线控制点!", "连接绑定检查", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if(isInSlot && connector.IsTailPoint) { MessageBox.Show("入口插槽不能绑定出端连接线控制点!", "连接绑定检查", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if(isOutSlot && connector.IsHeadPoint) { MessageBox.Show("出口插槽不能绑定了入端连接线控制点!", "连接绑定检查", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { bindingConnector = connector; bindingConnector.Binded = true; bindingConnector.Location = location; Binded = true; // 处理逻辑连接信息 if (connector.IsHeadPoint) // 连接线控制点是头控制点 { connector.Line.OutSlotContainer = slotContainer; } else // 连接线控制点是尾控制点 { connector.Line.InSlotContainer = slotContainer; } } }