/// <summary> /// 复制图元及其信息 /// </summary> /// <param name="dataTable">保存图元信息的哈希表</param> /// <returns>复制的数据</returns> protected Hashtable CopyGraphElement(Hashtable dataTable) { GraphManager graphManager = data as GraphManager; FlowChartManager flowChartManager = graphManager.CurrentFlowChartManager; DataManager dataManager = flowChartManager.CurrentDataManager; Hashtable copyTable = new Hashtable(); Hashtable graphTable = new Hashtable(); List <ConnectorContainer> lineList = new List <ConnectorContainer>(); List <GraphElement> graphElementList = new List <GraphElement>(); if (dataTable.Keys.Count > 1) // 复制多个图元 { SlotContainer slotContainer; SlotContainer newSlotContainer; ConnectorContainer line; ConnectorContainer newLine; SlotGraphElement slot; ICloneable cloneData; EventGraphElement newEventNode; List <EventGraphElement> eventList = new List <EventGraphElement>(); foreach (object o in dataTable.Keys) { GraphElement graphElement = o as GraphElement; if (graphElement is SlotContainer) // 插槽容器 { slotContainer = graphElement as SlotContainer; newSlotContainer = slotContainer.Clone(); graphTable[slotContainer] = newSlotContainer; cloneData = dataTable[slotContainer] as ICloneable; if (slotContainer is EventGraphElement) { eventList.Add(slotContainer as EventGraphElement); } if (cloneData != null) { copyTable[newSlotContainer] = cloneData.Clone(); } else { copyTable[newSlotContainer] = null; } graphElementList.Add(slotContainer); } else if (graphElement is ConnectorContainer) // 连接线 { line = graphElement as ConnectorContainer; newLine = line.Clone(); graphTable[line] = newLine; lineList.Add(line); cloneData = dataTable[line] as ICloneable; if (cloneData != null) { copyTable[newLine] = cloneData.Clone(); } else { copyTable[newLine] = null; } graphElementList.Add(line); } } // 重新构建复制图元的连接关系 foreach (ConnectorContainer connectorContainer in lineList) { if (connectorContainer.InSlotContainer != null && graphElementList.Contains(connectorContainer.InSlotContainer)) { newSlotContainer = graphTable[connectorContainer.InSlotContainer] as SlotContainer; newLine = graphTable[connectorContainer] as ConnectorContainer; slot = newSlotContainer.GetOutSlot(); slot.Bind(newLine.TailConnector); } if (connectorContainer.OutSlotContainer != null && graphElementList.Contains(connectorContainer.OutSlotContainer)) { newSlotContainer = graphTable[connectorContainer.OutSlotContainer] as SlotContainer; newLine = graphTable[connectorContainer] as ConnectorContainer; slot = newSlotContainer.GetInSlot(); slot.Bind(newLine.HeadConnector); } } // 重设图元对应的事件结点 if (eventList.Count > 0) { foreach (object o in dataTable.Keys) { GraphElement graphElement = o as GraphElement; if (graphElement is SlotContainer) // 插槽容器 { slotContainer = graphElement as SlotContainer; if (slotContainer.EventNode != null) { newSlotContainer = graphTable[slotContainer] as SlotContainer; if (eventList.Contains(slotContainer.EventNode)) { newEventNode = graphTable[slotContainer.EventNode] as EventGraphElement; newSlotContainer.EventNode = newEventNode; } else { newSlotContainer.EventNode = slotContainer.EventNode; } } } else if (graphElement is ConnectorContainer) // 连接线 { line = graphElement as ConnectorContainer; if (line.EventNode != null) { newLine = graphTable[line] as ConnectorContainer; if (eventList.Contains(line.EventNode)) { newEventNode = graphTable[line.EventNode] as EventGraphElement; newLine.EventNode = newEventNode; } else { newLine.EventNode = line.EventNode; } } } } } } else // 复制单个图元 { GraphElement graphElement = null; foreach (object o in dataTable.Keys) { graphElement = o as GraphElement; } ICloneable cloneData; if (graphElement is SlotContainer) // 插槽容器 { SlotContainer slotContainer = graphElement as SlotContainer; SlotContainer newSlotContainer = slotContainer.Clone(); cloneData = dataTable[slotContainer] as ICloneable; if (cloneData != null) { copyTable[newSlotContainer] = cloneData.Clone(); } else { copyTable[newSlotContainer] = null; } } else if (graphElement is ConnectorContainer) // 连接线 { ConnectorContainer line = graphElement as ConnectorContainer; ConnectorContainer newLine = line.Clone(); cloneData = dataTable[line] as ICloneable; if (cloneData != null) { copyTable[newLine] = cloneData.Clone(); } else { copyTable[newLine] = null; } } } return(copyTable); }