Exemplo n.º 1
0
        /// <summary>
        /// 获取流程图元数据
        /// </summary>
        /// <param name="dataManager">数据管理器</param>
        /// <param name="slotContainerList">流程图插槽容器的链表</param>
        /// <returns>流程图元数据的链表</returns>
        protected override List<FlowChartMetaData> GetMetaData(DataManager dataManager, List<SlotContainer> slotContainerList)
        {
            // 初始化ID
            maxID = dataManager.CurrentFlowChartManager.CurrentGraphManager.IDIndex + 1;

            List<FlowChartMetaData> metaDataList = new List<FlowChartMetaData>();
            List<GraphElement> graphElementList = new List<GraphElement>();
            Hashtable graphElementTable = new Hashtable();
            dataManager.InitCompileTable();

            Hashtable actionsTable = new Hashtable(); // 动作组数据哈希表

            // 预处理动作组结点
            foreach (SlotContainer slotContainer in slotContainerList)
            {
                if (slotContainer is AIActionsGraphElement)
                {
                    AIActionsGraphElement actionsGraphElement = slotContainer as AIActionsGraphElement;
                    List<FlowChartMetaData> actionsMetaDataList = GetActionsMetaDataList(dataManager, actionsGraphElement);
                    actionsTable[actionsGraphElement] = actionsMetaDataList;
                }
            }

            // 预处理子绘图结点
            AIStateGraphElement stateNode = null;            

            foreach (SlotContainer slotContainer in slotContainerList)
            {
                // 所有子绘图的图元都重新分配ID
                if (slotContainer is InnerChart)
                {
                    InnerChart innerChart = slotContainer as InnerChart;
                    InnerChartEditor innerChartEditor = dataManager.GetDataElement(innerChart) as InnerChartEditor;
                    List<GraphElement> list = innerChartEditor.GraphElementList;

                    foreach (GraphElement graphElement in list)
                    {
                        graphElement.ID = maxID;
                        graphElement.Tag = innerChart.ID;
                        maxID++;

                        dataManager.AddCompileData(graphElement, innerChartEditor.GetDataElement(graphElement));

                        // 重命名名称                        
                        RenameGraphElement(dataManager, graphElement);

                        if (graphElement is AIStateGraphElement)
                        {
                            AIStateGraphElement aiStateGraphElement = graphElement as AIStateGraphElement;

                            if (aiStateGraphElement.IsInitialState)
                            {
                                stateNode = aiStateGraphElement;
                            }
                        }
                        else if (graphElement is AIActionsGraphElement)
                        {
                            AIActionsGraphElement actionsGraphElement = graphElement as AIActionsGraphElement;
                            List<FlowChartMetaData> actionsMetaDataList = GetActionsMetaDataList(dataManager, actionsGraphElement);
                            actionsTable[actionsGraphElement] = actionsMetaDataList;
                        }
                    }
                }
            }

            // 处理绘图结点
            foreach (SlotContainer slotContainer in slotContainerList)
            {
                if (slotContainer is AIStateGraphElement)
                {
                    AIStateGraphElement stateGraphElement = slotContainer as AIStateGraphElement;

                    if (stateGraphElement.IsInitialState)
                    {
                        stateNode = stateGraphElement;
                        break;
                    }                    
                }
            }

            if (stateNode != null)
            {
                object data = dataManager.GetCompileData(stateNode);
                DataElement dataElement = dataManager.GetCompileDataElement(stateNode);
                FlowChartMetaData metaData = new FlowChartMetaData(stateNode.ID, data, "AIStateNode");
                string stateNodeName = CodeProviderClass.GetStateString(data);

                metaData.Code = stateNodeName;
                metaData.DisplayText = stateNode.Text;
                FindNextMetaData(dataManager, stateNode, metaData, graphElementList, graphElementTable, actionsTable);
                metaDataList.Add(metaData);
            }

            return metaDataList;
        }