/// <summary> /// 刷新子绘图连接线的数据 /// </summary> /// <param name="innerChart">子绘图</param> protected virtual void RefreshInnerChartLine(InnerChart innerChart) { DocumentManager documentManager = DocumentManager.GetDocumentManager(); FlowChartManager flowChartManager = documentManager.CurrentFlowChartManager; GraphManager graphManager = flowChartManager.CurrentGraphManager; DataManager dataManager = flowChartManager.CurrentDataManager; }
/// <summary> /// 编辑数据 /// </summary> /// <param name="o">数据元的数据</param> /// <return>是否编辑成功</return> public override bool EditData(Hashtable table) { bool editSuccess = false; InnerChartForm innerChartForm = new InnerChartForm(innerChartPath); if (innerChartForm.ShowDialog() == DialogResult.OK) { innerChartPath = innerChartForm.InnerChartPath; graphElementList = innerChartForm.GraphElementList; graphTable = innerChartForm.GraphTable; interfaceNodeTable = innerChartForm.InterfaceNodeTable; this.text = innerChartPath; // 更新数据 UpdateData(innerChartForm.InSlotInfo, innerChartForm.OutSlotInfo); InnerChart innerChart = DocumentManager.GetDocumentManager().CurrentFlowChartManager.CurrentDataManager.FindGraphElementByID(id) as InnerChart; // 更新插槽数量 UpdateSlotCount(innerChart, innerChartForm.InSlotCount, innerChartForm.OutSlotCount, false); List <int> inIDList = new List <int>(); List <int> outIDList = new List <int>(); foreach (string nodeID in innerChartForm.InSlotInfo.Keys) { inIDList.Add(int.Parse(nodeID)); } foreach (string nodeID in innerChartForm.OutSlotInfo.Keys) { outIDList.Add(int.Parse(nodeID)); } foreach (InterfaceGraphElement interfaceNode in interfaceNodeTable.Values) { interfaceNode.Tag = id.ToString(); } // 刷新插槽信息 RefreshSlotInfo(innerChart, inIDList, outIDList, innerChartForm.InSlotInfo, innerChartForm.OutSlotInfo); editSuccess = true; } return(editSuccess); }
/// <summary> /// 更新插槽数量 /// </summary> /// <param name="innerChart">子绘图结点</param> /// <param name="inSlotCount">入口插槽数量</param> /// <param name="outSlotCount">出口插槽数量</param> /// <param name="showMessage">是否显示消息</param> private void UpdateSlotCount(InnerChart innerChart, int inSlotCount, int outSlotCount, bool showMessage) { // 更新插槽信息 if (innerChart.InSlotCount != inSlotCount || innerChart.OutSlotCount != outSlotCount) { innerChart.InSlotCount = inSlotCount; innerChart.OutSlotCount = outSlotCount; innerChart.LockInSlot(); innerChart.LockOutSlot(); if (showMessage) { MessageBox.Show(string.Format("子绘图结点{0} (ID:{1})的插槽参数更新,需要重新连接!", innerChart.Text, innerChart.ID), "子绘图更新", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// 刷新插槽信息 /// </summary> /// <param name="innerChart">子绘图结点</param> /// <param name="inIDList">入口插槽ID链表</param> /// <param name="outIDList">出口插槽ID链表</param> /// <param name="inSlotInfo">入口插槽信息</param> /// <param name="outSlotInfo">出口插槽信息</param> private void RefreshSlotInfo(InnerChart innerChart, List <int> inIDList, List <int> outIDList, Hashtable inSlotInfo, Hashtable outSlotInfo) { StringBuilder descriptionInfo = new StringBuilder(); descriptionInfo.AppendLine("<bold>入口插槽"); // 刷新插槽信息 inIDList.Sort(); List <SlotGraphElement> slotList = innerChart.GetInSlotList(); for (int i = 0; i < inIDList.Count; i++) { string nodeID = inIDList[i].ToString(); string nodeName = inSlotInfo[nodeID] as string; slotList[i].Tag = nodeID; slotList[i].TooltipText = nodeName; descriptionInfo.AppendLine(string.Format("{0}:{1}", i, nodeName)); } outIDList.Sort(); slotList = innerChart.GetOutSlotList(); descriptionInfo.AppendLine("<split>"); descriptionInfo.AppendLine("<bold>出口插槽"); for (int i = 0; i < outIDList.Count; i++) { string nodeID = outIDList[i].ToString(); string nodeName = outSlotInfo[nodeID] as string; slotList[i].Tag = nodeID; descriptionInfo.AppendLine(string.Format("{0}:{1}", i, nodeName)); } // 刷新提示信息 tooltipText = descriptionInfo.ToString(); }
/// <summary> /// 执行命令 /// </summary> /// <param name="o">当前对象</param> /// <returns>是否执行成功</returns> public override bool Execute(object o) { bool success = true; object[] args = o as object[]; int id = graphManager.AllocateGraphElementID(); Point p = (Point)args[0]; string typeString = args[1] as string; GraphSetting graphSetting = GraphSetting.GetGraphSetting(); // 保存命令执行前的数据 if (firstCommand) // 只有第一条命令保存执行前的数据 { SaveBeforeExecute(flowChartManager.GetArguments()); } switch (typeString) { case "ConditionNode": // 条件结点 { ConditionGraphElement conditionGraphElement = new ConditionGraphElement(p, graphSetting.ConditionNodeElementSize); InitSlotContainer(conditionGraphElement, id, "条件结点"); break; } case "ActionNode": // 动作结点 { ActionGraphElement actionGraphElement = new ActionGraphElement(p, graphSetting.ActionNodeElementSize); InitSlotContainer(actionGraphElement, id, "动作结点"); break; } case "EventNode": // 事件结点 { EventGraphElement eventGraphElement = new EventGraphElement(p, graphSetting.EventNodeElementSize); InitSlotContainer(eventGraphElement, id, "事件结点"); break; } case "AIStateNode": // ai状态结点 { AIStateGraphElement aiStateGraphElement = new AIStateGraphElement(p, graphSetting.AIStateNodeElementSize); InitSlotContainer(aiStateGraphElement, id, "AI状态结点"); break; } case "AIActionNode": // ai动作结点 { AIActionGraphElement aiActionGraphElement = new AIActionGraphElement(p, graphSetting.AIActionNodeElementSize); InitSlotContainer(aiActionGraphElement, id, "AI动作结点"); break; } case "AIActionsNode": // ai动作组结点 { AIActionsGraphElement aiActionsGraphElement = new AIActionsGraphElement(p, graphSetting.AIActionsNodeElementSize); InitSlotContainer(aiActionsGraphElement, id, "AI动作组结点"); break; } case "InnerChart": // 子绘图结点 { InnerChart innerChart = new InnerChart(p, graphSetting.InnerChartElementSize); InitSlotContainer(innerChart, id, "子绘图结点"); break; } case "InterfaceNode": // 接口结点 { InterfaceGraphElement interfaceGraphElement = new InterfaceGraphElement(p, graphSetting.InterfaceNodeElementSize); InitSlotContainer(interfaceGraphElement, id, "接口结点"); break; } } if (success) // 保存命令执行后的数据 { flowChartManager.ContentChanged = true; SaveAfterExecute(flowChartManager.GetArguments()); } return(success); }
/// <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="table">当前数据</param> /// <return>是否重读成功</return> public override bool ReloadData(Hashtable table) { Hashtable dataInfo = data as Hashtable; if (dataInfo != null) { innerChartPath = dataInfo["innerChartPath"] as string; // 初始化绘图数据表 InitGraphTable(); if (graphTable != null) { int inSlotCount = 0; int outSlotCount = 0; Hashtable inSlotInfo = new Hashtable(); Hashtable outSlotInfo = new Hashtable(); graphElementList = new List <GraphElement>(); interfaceNodeTable = new Hashtable(); List <int> inIDList = new List <int>(); List <int> outIDList = new List <int>(); foreach (GraphElement graphElement in graphTable.Keys) { if (graphElement is InterfaceGraphElement) { InterfaceGraphElement interfaceGraphElement = graphElement as InterfaceGraphElement; InterfaceNodeEditor interfaceEditor = graphTable[graphElement] as InterfaceNodeEditor; if (interfaceEditor.IsInput) { inSlotInfo[interfaceEditor.ID.ToString()] = interfaceEditor.InterfaceName; inIDList.Add(interfaceGraphElement.ID); inSlotCount++; } else { outSlotInfo[interfaceEditor.ID.ToString()] = interfaceEditor.InterfaceName; outIDList.Add(interfaceGraphElement.ID); outSlotCount++; } interfaceGraphElement.Tag = id.ToString(); interfaceNodeTable[interfaceEditor.ID.ToString()] = graphElement; } else { graphElementList.Add(graphElement); } } InnerChart innerChart = DocumentManager.GetDocumentManager().CurrentFlowChartManager.CurrentDataManager.FindGraphElementByID(id) as InnerChart; // 更新数据 UpdateData(inSlotInfo, outSlotInfo); // 更新插槽数量 UpdateSlotCount(innerChart, inSlotCount, outSlotCount, true); // 更新插槽信息 RefreshSlotInfo(innerChart, inIDList, outIDList, inSlotInfo, outSlotInfo); } } return(true); }