Esempio n. 1
0
 /// <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;
 }
Esempio n. 2
0
        /// <summary>
        /// 创建绘图
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicCreateChart(FlowChartManager flowChartManager, object logicData)
        {
            DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager();
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            TreeView        tree            = logicData as TreeView;
            TreeNode        currentNode     = tree.SelectedNode;

            InputForm iForm = new InputForm("请输入新建绘图的名称", "新建绘图");

            if (iForm.ShowDialog() == DialogResult.OK)
            {
                TreeNode newNode = currentNode.Nodes.Add(iForm.InputText);
                newNode.ImageIndex              = 1;
                newNode.SelectedImageIndex      = 1;
                tree.SelectedNode               = newNode;
                documentManager.CurrentTreeMode = EditMode.Normal;

                // 对数据库进行操作
                string path = documentManager.GetNodePath(newNode);
                string id   = dataBaseManager.CreateNewDiagram(path, false, documentManager.CurrentChartMode);
                newNode.Tag = id;
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// 弹出右键菜单
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicPopUpMenuStrip(FlowChartManager flowChartManager, object logicData)
        {
            Point           popUpLocation   = (Point)logicData;
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            GraphManager    graphManager    = flowChartManager.CurrentGraphManager;

            if (graphManager.SelectedGraphElement is SlotContainer) // 有AI插槽容器被选中
            {
                editMenu.Popup(popUpLocation);
            }
            else if (graphManager.SelectedGraphElement == null) // 没有选中任何图元
            {
                if (documentManager.CopyTable != null)
                {
                    canvasMenu.SubItems["bPasteGraphElement"].Enabled = true;
                }
                else
                {
                    canvasMenu.SubItems["bPasteGraphElement"].Enabled = false;
                }

                if (flowChartManager.MapName == "子绘图") // 子绘图不允许重设图元ID
                {
                    canvasMenu.SubItems["bResetGraphElementID"].Enabled = false;
                }
                else
                {
                    canvasMenu.SubItems["bResetGraphElementID"].Enabled = true;
                }

                canvasMenu.Popup(popUpLocation);
            }

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// 创建图元结点
        /// </summary>
        /// <param name="graphType">图元类型</param>
        /// <param name="location">图元位置</param>
        /// <param name="autoConnect">是否自动连接</param>
        protected void CreateNode(GraphType graphType, Point location, bool autoConnect)
        {
            DocumentManager  documentManager  = DocumentManager.GetDocumentManager();
            FlowChartManager flowChartManager = documentManager.CurrentFlowChartManager;

            flowChartManager.CurrentGraphManager.CreateAbbreviateGraphElement(graphType, location, autoConnect);
        }
Esempio n. 5
0
        /// <summary>
        /// 创建并连接动作结点
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        protected virtual void CAndCActionNode(object sender, EventArgs e)
        {
            DocumentManager  documentManager  = DocumentManager.GetDocumentManager();
            FlowChartManager flowChartManager = documentManager.CurrentFlowChartManager;

            flowChartManager.CurrentGraphManager.CreateAbbreviateGraphElement(GraphType.ActionNode, Point.Empty, true);
        }
Esempio n. 6
0
        /// <summary>
        /// 打开脚本
        /// </summary>
        /// <param name="flowChartManager">逻辑管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicViewCode(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            Helper          helper          = Helper.GetHelper();
            string          relevatePath    = logicData as string;
            string          path            = Path.Combine(helper.OutputDir, string.Format("{0}.lua", relevatePath));

            if (File.Exists(path)) // 文件存在
            {
                try
                {
                    System.Diagnostics.Process.Start(path);
                }
                catch (IOException ex)
                {
                    MessageBox.Show("在查看脚本时产生IO异常:" + ex.Message, "打开脚本",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(string.Format("脚本文件{0}不存在!", path), "打开脚本",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }
Esempio n. 7
0
        /// <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;
        }
Esempio n. 8
0
        /// <summary>
        /// 撤销命令
        /// </summary>
        public override void Unexecute()
        {
            object           o                = dataBeforeExecute.LoadData();
            GraphManager     graphManager     = data as GraphManager;
            FlowChartManager flowChartManager = graphManager.CurrentFlowChartManager;

            object[] args = o as object[];
            flowChartManager.SetArguments(args);
        }
Esempio n. 9
0
        /// <summary>
        /// 初始化数据元
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicInitializeDataElement(FlowChartManager flowChartManager, object logicData)
        {
            bool         executeSuccess = true;
            GraphElement graphElement   = logicData as GraphElement;
            DataElement  dataElement    = null;

            try
            {
                switch (graphElement.TypeString)
                {
                case "InnerChart":     // 基础图元
                {
                    dataElement = new InnerChartEditor();

                    break;
                }

                case "InterfaceNode":     // 基础图元
                {
                    dataElement = new InterfaceNodeEditor();

                    break;
                }

                default:     // 自定义图元
                {
                    DataElementInfo dataElementInfo = dataElementInfoDirectory[graphElement.TypeString];

                    if (dataElementInfo != null)
                    {
                        dataElement = dataElementInfo.GetDataElement();
                    }

                    break;
                }
                }

                if (dataElement != null)
                {
                    dataElement.ID       = graphElement.ID;
                    dataElement.DataType = graphElement.TypeString;
                }
            }
            catch (Exception ex)
            {
                executeSuccess = false;
                MessageBox.Show("在初始化数据元时产生异常: " + ex.ToString(), "数据元初始化", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            flowChartManager.CurrentDataManager.InitializedDataElement = dataElement;

            return(executeSuccess);
        }
Esempio n. 10
0
        /// <summary>
        /// 在指定点创建结点
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <return>是否操作成功</return>
        protected virtual bool LogicCreateNodeAtPoint(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();

            object[] args      = logicData as object[];
            int      graphType = (int)args[0];
            Point    location  = (Point)args[1];

            switch (graphType)
            {
            case 1:     // 创建事件结点
            {
                CreateNode(GraphType.EventNode, location, false);
                break;
            }

            case 2:                                                                             // 创建条件结点
            {
                if (flowChartManager.CurrentGraphManager.SelectedGraphElement is SlotContainer) // 必须在有可连接的结点的基础上创建
                {
                    CreateNode(GraphType.ConditionNode, location, true);
                }
                else
                {
                    CreateNode(GraphType.ConditionNode, location, false);
                }

                break;
            }

            case 3:                                                                             // 创建动作结点
            {
                if (flowChartManager.CurrentGraphManager.SelectedGraphElement is SlotContainer) // 必须在有可能连接的结点的基础上创建
                {
                    CreateNode(GraphType.ActionNode, location, true);
                }
                else
                {
                    CreateNode(GraphType.ActionNode, location, false);
                }

                break;
            }

            default:
            {
                break;
            }
            }

            return(true);
        }
Esempio n. 11
0
        private FlowChartMoveCommand moveCommand; // 移动命令

        /// <summary>
        /// 单例模式的构造函数
        /// </summary>
        /// <param name="mainForm">主窗体</param>
        /// <param name="canvas">绘图面板</param>
        /// <param name="propertyGrid">属性面板</param>
        public GraphManager(FlowChartManager flowChartManager, Canvas canvas)
        {
            this.flowChartManager = flowChartManager;
            this.canvas = canvas;
            helper = Helper.GetHelper();
            documentManager = DocumentManager.GetDocumentManager();

            // 初始化背景绘图参数
            InitBackground(); 
      
            // 初始化区域管理器
            regionManager.Init(slotContainerList, connectorContainerList, background.BaseSize, background.GridSize.Width);
        }               
Esempio n. 12
0
        /// <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);
        }
Esempio n. 13
0
        /// <summary>
        /// 重新分配图元的ID
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        protected virtual void ResetGraphElementID(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定重新分配图元ID吗?", "重新分配图元ID",
                                MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                DocumentManager  documentManager  = DocumentManager.GetDocumentManager();
                FlowChartManager flowChartManager = documentManager.CurrentFlowChartManager;
                GraphManager     graphManager     = flowChartManager.CurrentGraphManager;
                DataManager      dataManager      = flowChartManager.CurrentDataManager;

                graphManager.ResetGraphElementID();
                dataManager.ResetDataElementID();
                graphManager.RefreshCanvas();
            }
        }
Esempio n. 14
0
        /// <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);
        }
Esempio n. 15
0
        /// <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);
        }
Esempio n. 16
0
        /// <summary>
        /// 刷新绘图板
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        protected virtual void RefreshCanvas(object sender, EventArgs e)
        {
            DocumentManager  documentManager  = DocumentManager.GetDocumentManager();
            FlowChartManager flowChartManager = documentManager.CurrentFlowChartManager;
            GraphManager     graphManager     = flowChartManager.CurrentGraphManager;

            // 刷新缩略图元
            graphManager.CurrentCanvas.AbbreviatGraphElement = null;
            graphManager.CurrentCanvas.AbbreviateLine        = null;

            // 恢复默认按键状态
            graphManager.ControlMode = false;
            graphManager.ShiftMode   = false;
            graphManager.AltMode     = false;

            // 刷新绘图区域
            graphManager.RefreshRegion();
            graphManager.RefreshCanvas();
        }
Esempio n. 17
0
        /// <summary>
        /// 打开文件夹
        /// </summary>
        /// <param name="flowChartManager">逻辑管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicViewFolder(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            Helper          helper          = Helper.GetHelper();
            TreeNode        currentNode     = logicData as TreeNode;

            string path = Path.Combine(helper.OutputDir, documentManager.GetNodePath(currentNode));

            if (Directory.Exists(path)) // 当前目录存在
            {
                System.Diagnostics.Process.Start("explorer.exe", path);
            }
            else // 当前目录不存在
            {
                MessageBox.Show("该目录不存在!", "打开文件夹", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }
Esempio n. 18
0
 /// <summary>
 /// 绘图加载之后的处理
 /// </summary>
 /// <param name="flowChartManager">绘图管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicAfterLoad(FlowChartManager flowChartManager, object logicData)
 {
     return(true);
 }
Esempio n. 19
0
        /// <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;
        }
Esempio n. 20
0
        /// <summary>
        /// 创建绘图
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicCreateChart(FlowChartManager flowChartManager, object logicData)
        {
            DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager();
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            TreeView tree = logicData as TreeView;
            TreeNode currentNode = tree.SelectedNode;

            InputForm iForm = new InputForm("请输入新建绘图的名称", "新建绘图");

            if (iForm.ShowDialog() == DialogResult.OK)
            {
                TreeNode newNode = currentNode.Nodes.Add(iForm.InputText);
                newNode.ImageIndex = 1;
                newNode.SelectedImageIndex = 1;
                tree.SelectedNode = newNode;
                documentManager.CurrentTreeMode = EditMode.Normal;

                // 对数据库进行操作
                string path = documentManager.GetNodePath(newNode);
                string id = dataBaseManager.CreateNewDiagram(path, false, documentManager.CurrentChartMode);
                newNode.Tag = id;
            }

            return true;
        }
Esempio n. 21
0
        /// <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;
        }
Esempio n. 22
0
 /// <summary>
 /// 删除图元之前的处理
 /// </summary>
 /// <param name="flowChartManager">绘图管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicBeforeDelete(FlowChartManager flowChartManager, object logicData)
 {
     return true;
 }
Esempio n. 23
0
        /// <summary>
        /// 保存绘图
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicSave(FlowChartManager flowChartManager, object logicData)
        {
            if (flowChartManager.CurrentPath.StartsWith("子绘图"))
            {
                string description = flowChartManager.CustomData["description"] as string;

                if (string.IsNullOrEmpty(description))
                {
                    description = flowChartManager.Name;
                }

                InputForm inputForm = new InputForm("请输入子绘图的描述", description);

                if (inputForm.ShowDialog() == DialogResult.OK)
                {
                    description = inputForm.InputText;
                    flowChartManager.CustomData["description"] = description;
                }
            }

            return true;
        }
Esempio n. 24
0
        /// <summary>
        /// 检查逻辑
        /// </summary>
        /// <param name="flowChartManager">绘图对象</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicCheckLogic(FlowChartManager flowChartManager, object logicData)
        {
            bool executeResult = CheckAIChartAvail(flowChartManager);

            return executeResult;
        }
Esempio n. 25
0
        /// <summary>
        /// 在指定点创建结点
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <return>是否操作成功</return>
        protected virtual bool LogicCreateNodeAtPoint(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            object[] args = logicData as object[];
            int graphType = (int)args[0];
            Point location = (Point)args[1];

            switch (graphType)
            {
                case 1: // 创建事件结点
                    {
                        CreateNode(GraphType.EventNode, location, false);
                        break;
                    }
                case 2: // 创建条件结点
                    {
                        if (flowChartManager.CurrentGraphManager.SelectedGraphElement is SlotContainer) // 必须在有可连接的结点的基础上创建
                        {
                            CreateNode(GraphType.ConditionNode, location, true);
                        }
                        else
                        {
                            CreateNode(GraphType.ConditionNode, location, false);
                        }

                        break;
                    }
                case 3: // 创建动作结点
                    {
                        if (flowChartManager.CurrentGraphManager.SelectedGraphElement is SlotContainer) // 必须在有可能连接的结点的基础上创建
                        {
                            CreateNode(GraphType.ActionNode, location, true);
                        }
                        else 
                        {
                            CreateNode(GraphType.ActionNode, location, false);
                        }

                        break;
                    }
                default:
                    {
                        break;
                    }                    
            }

            return true;
        }
Esempio n. 26
0
        /// <summary>
        /// 打开文件夹
        /// </summary>
        /// <param name="flowChartManager">逻辑管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicViewFolder(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            Helper helper = Helper.GetHelper();
            TreeNode currentNode = logicData as TreeNode;

            string path = Path.Combine(helper.OutputDir, documentManager.GetNodePath(currentNode));
                        
            if (Directory.Exists(path)) // 当前目录存在
            {
                System.Diagnostics.Process.Start("explorer.exe", path);
            }
            else // 当前目录不存在 
            {
                MessageBox.Show("该目录不存在!", "打开文件夹", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return true;
        }
Esempio n. 27
0
        private string requestReloadID = "";              // 需要重新编辑的图元ID

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="flowChartManager">流程图管理器</param>
        public DataManager(FlowChartManager flowChartManager)
        {
            this.flowChartManager = flowChartManager;
        }
Esempio n. 28
0
        /// <summary>
        /// 初始化数据元
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicInitializeDataElement(FlowChartManager flowChartManager, object logicData)
        {
            bool executeSuccess = true;
            GraphElement graphElement = logicData as GraphElement;
            DataElement dataElement = null;

            try
            {
                switch (graphElement.TypeString)
                {
                    case "InnerChart": // 基础图元
                        {
                            dataElement = new InnerChartEditor();

                            break;
                        }
                    case "InterfaceNode": // 基础图元
                        {
                            dataElement = new InterfaceNodeEditor();

                            break;
                        }
                    default: // 自定义图元
                        {
                            DataElementInfo dataElementInfo = dataElementInfoDirectory[graphElement.TypeString];

                            if (dataElementInfo != null)
                            {
                                dataElement = dataElementInfo.GetDataElement();                                                                    
                            }

                            break;
                        }
                }

                if (dataElement != null)
                {
                    dataElement.ID = graphElement.ID;
                    dataElement.DataType = graphElement.TypeString;
                }
            }
            catch (Exception ex)
            {
                executeSuccess = false;
                MessageBox.Show("在初始化数据元时产生异常: " + ex.ToString(), "数据元初始化", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            flowChartManager.CurrentDataManager.InitializedDataElement = dataElement;

            return executeSuccess;
        }
Esempio n. 29
0
        /// <summary>
        /// 生成脚本
        /// </summary>
        /// <returns>是否生成成功</returns>
        protected virtual bool GenerateCode()
        {
            bool             success          = true;
            Helper           helper           = Helper.GetHelper();
            DocumentManager  documentManager  = DocumentManager.GetDocumentManager();
            Hashtable        fileTable        = documentManager.FileTable;
            FlowChartManager flowChartManager = documentManager.CurrentFlowChartManager;

            if (flowChartManager == null)
            {
                return(false);
            }

            string       id           = flowChartManager.ID;
            GraphManager graphManager = flowChartManager.CurrentGraphManager;
            DataManager  dataManager  = flowChartManager.CurrentDataManager;

            List <SlotContainer>     slotContainerList = graphManager.SlotContainerList;
            List <FlowChartMetaData> metaDataList      = GetMetaData(dataManager, slotContainerList);

            if (compiler == null)
            {
                return(false);
            }

            compiler.PrintDebugInformation = documentManager.PrintText;
            compiler.SaveTheFile           = documentManager.SaveTextToFile;
            FlowChartMetaDataManager flowChartMetaDataManager = new FlowChartMetaDataManager(int.Parse(id), metaDataList);

            fileTable.Clear();
            documentManager.PrintText("------ 开始初始化脚本 ------");

            // 设置生成脚本参数
            compiler.RootDirectory           = helper.OutputDir;
            compiler.ScriptPath              = flowChartManager.CurrentPath;
            flowChartMetaDataManager.MapName = flowChartManager.MapName;
            flowChartMetaDataManager.Version = flowChartMetaDataManager.Version;

            try
            {
                success = compiler.GenerateCode(int.Parse(id), metaDataList, flowChartMetaDataManager);
            }
            catch (Exception ex) // 抛出异常则输出调试信息
            {
                documentManager.PrintText(string.Format("异常信息:{0}", ex.Message));
                success = false;
            }

            if (!success)
            {
                documentManager.PrintText("初始化脚本失败!");
                return(false);
            }

            documentManager.PrintText("初始化脚本成功!");

            // 写文件
            documentManager.PrintText("------ 开始生成脚本 ------");

            foreach (string fileName in fileTable.Keys)
            {
                success = helper.SaveFile(fileName, fileTable[fileName] as string);

                if (success) // 写文件成功
                {
                    documentManager.PrintText(string.Format("生成脚本文件 {0} 成功!", fileName));
                }
                else
                {
                    documentManager.PrintText(string.Format("生成脚本文件 {0} 失败!", fileName));
                    break;
                }
            }

            if (!success)
            {
                return(false);
            }

            documentManager.PrintText(string.Format("====== 所有文件都成功生成!共生成{0}个文件 ======", fileTable.Keys.Count));

            return(success);
        }
Esempio n. 30
0
 /// <summary>
 /// 解除连接图元
 /// </summary>
 /// <param name="flowChartManager">绘图管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicDisconnect(FlowChartManager flowChartManager, object logicData)
 {
     return(true);
 }
Esempio n. 31
0
 /// <summary>
 /// 删除图元之前的处理
 /// </summary>
 /// <param name="flowChartManager">绘图管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicBeforeDelete(FlowChartManager flowChartManager, object logicData)
 {
     return(true);
 }
Esempio n. 32
0
        /// <summary>
        /// 打开脚本
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicViewCode(FlowChartManager flowChartManager, object logicData)
        {
            Helper helper = Helper.GetHelper();
            string relevatePath = logicData as string;

            string[] data = relevatePath.Split(new char[] { '\\' });
            string shortPath = data[1];

            for (int i = 2; i < data.Length; i++)
            {
                shortPath += string.Format("\\{0}", data[i]);
            }

            string path = string.Format(@"{0}\scripts\Map\{1}\ai\{2}.lua", helper.OutputDir, data[0], shortPath);            

            if (File.Exists(path)) // 文件存在
            {
                try
                {
                    System.Diagnostics.Process.Start(path);
                }
                catch (IOException ex)
                {
                    MessageBox.Show("在查看脚本文件时产生IO异常:" + ex.Message, "打开脚本",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(string.Format("文件{0}不存在!", path), "打开脚本",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }  

            return true;
        }
Esempio n. 33
0
 /// <summary>
 /// 检查逻辑
 /// </summary>
 /// <param name="flowChartManager">逻辑管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicCheckLogic(FlowChartManager flowChartManager, object logicData)
 {
     return true;
 }
Esempio n. 34
0
        /// <summary>
        /// 打开文件夹
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicViewFolder(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            Helper helper = Helper.GetHelper();
            TreeNode currentNode = logicData as TreeNode;

            string currentPath = documentManager.GetNodePath(currentNode);
            string[] data = currentPath.Split(new char[] { '\\' });
            string path = "";
            char[] pathSymbleArray = new char[] { '\\' };

            if (data.Length > 1) // 查看场景根目录
            {
                string shortPath = data[1];

                for (int i = 2; i < data.Length; i++)
                {
                    shortPath += string.Format("\\{0}", data[i]);
                }

                path = string.Format(@"{0}\scripts\Map\{1}\ai\{2}", helper.OutputDir.TrimEnd(pathSymbleArray), data[0], shortPath);
            }
            else
            {
                path = string.Format(@"{0}\scripts\Map\{1}\ai", helper.OutputDir.TrimEnd(pathSymbleArray), data[0]);
            }
            
            if (Directory.Exists(path)) // 当前目录存在
            {
                System.Diagnostics.Process.Start("explorer.exe", path);
            }
            else // 当前目录不存在 
            {
                MessageBox.Show("该目录不存在!", "打开文件夹", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return true;
        }
Esempio n. 35
0
        /// <summary>
        /// 执行逻辑功能
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicType">逻辑类型</param>
        /// <param name="logicData">逻辑数据</param>
        /// <return>执行结果</return>
        public virtual bool DoLogicOperation(FlowChartManager flowChartManager, LogicType logicType, object logicData)
        {
            bool executeSuccess = true;

            switch (logicType)
            {
                case LogicType.Connect: // 连接图元
                    {
                        executeSuccess = LogicConnect(flowChartManager, logicData);
                        break;
                    }
                case LogicType.Disconnect: // 解除连接图元
                    {
                        executeSuccess = LogicDisconnect(flowChartManager, logicData);
                        break;
                    }
                case LogicType.BeforeDelete: // 删除图元之前
                    {
                        executeSuccess = LogicBeforeDelete(flowChartManager, logicData);
                        break;
                    }
                case LogicType.AfterDelete: // 删除图元之后
                    {
                        executeSuccess = LogicAfterDelete(flowChartManager, logicData);
                        break;
                    }
                case LogicType.Edit: // 编辑图元
                    {
                        executeSuccess = LogicEdit(flowChartManager, logicData);
                        break;
                    }
                case LogicType.Paste: // 粘贴图元
                    {
                        executeSuccess = LogicPaste(flowChartManager, logicData);
                        break;
                    }
                case LogicType.CreateLine: // 创建连接线
                    {
                        executeSuccess = LogicCreateLine(flowChartManager, logicData);
                        break;
                    }
                case LogicType.CreateAndConnectLine: // 创建并连接连接线
                    {
                        executeSuccess = LogicCreateAndConnectLine(flowChartManager, logicData);
                        break;
                    }
                case LogicType.CreateChart: // 创建绘图
                    {
                        executeSuccess = LogicCreateChart(flowChartManager, logicData);
                        break;
                    }
                case LogicType.AfterLoad: // 加载绘图之后的处理
                    {
                        executeSuccess = LogicAfterLoad(flowChartManager, logicData);
                        break;
                    }
                case LogicType.InitializeDataElement: // 初始化数据元
                    {
                        executeSuccess = LogicInitializeDataElement(flowChartManager, logicData);
                        break;
                    }
                case LogicType.PopUpContextMenu: // 弹出右键菜单
                    {
                        executeSuccess = LogicPopUpMenuStrip(flowChartManager, logicData);
                        break;
                    }
                case LogicType.CreateAtPoint: // 在指定点创建图元
                    {
                        executeSuccess = LogicCreateNodeAtPoint(flowChartManager, logicData);
                        break;
                    }
                case LogicType.ViewCode: // 打开脚本
                    {
                        executeSuccess = LogicViewCode(flowChartManager, logicData);
                        break;
                    }
                case LogicType.ViewFolder: // 打开文件夹
                    {
                        executeSuccess = LogicViewFolder(flowChartManager, logicData);
                        break;
                    }
                case LogicType.Save: // 保存绘图
                    {
                        executeSuccess = LogicSave(flowChartManager, logicData);
                        break;
                    }
                case LogicType.CompileCode: // 生成脚本
                    {
                        executeSuccess = LogicCompileCode(flowChartManager, logicData);
                        break;
                    }
                case LogicType.CheckLogic: // 检查逻辑
                    {
                        executeSuccess = LogicCheckLogic(flowChartManager, logicData);
                        break;
                    }
                case LogicType.ManageArguments: // 管理变量
                    {
                        executeSuccess = LogicManageArguments(flowChartManager, logicData);
                        break;
                    }             
                default:
                    {
                        executeSuccess = false;
                        break;
                    }
            }

            return executeSuccess;
        }
Esempio n. 36
0
        /// <summary>
        /// 生成脚本
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicCompileCode(FlowChartManager flowChartManager, object logicData)
        {
            bool executeSuccess = GenerateCode();

            // 检查脚本内容
            string[] dataArray = flowChartManager.CurrentPath.Split(new char[] { '\\' });
            string shortPath = dataArray[1];

            for (int i = 2; i < dataArray.Length; i++)
            { 
                shortPath = shortPath + string.Format("\\{0}", dataArray[i]);
            }

            string fullPath = string.Format(@"{0}\scripts\Map\{1}\ai\{2}", Helper.GetHelper().OutputDir.TrimEnd(new char[] { '\\' }), dataArray[0], shortPath);
            string fileName = string.Format("{0}.lua", fullPath);
            string content = Helper.GetHelper().ReadFile(fileName);

            if (!AIDiagramHelper.CheckScript(null, content))
            {
                MessageBox.Show("没有通过脚本检查,请根据提示信息检查AI脚本是否正确!", "脚本检查",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return executeSuccess;
        }
Esempio n. 37
0
        /// <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);
        }
Esempio n. 38
0
        /// <summary>
        /// 管理变量
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicManageArguments(FlowChartManager flowChartManager, object logicData)
        {
            bool executeResult = true;

            if (flowChartManager == null || flowChartManager.CurrentChartMode != displayName)
            {
                MessageBox.Show("当前没有AI图被激活!", "变量管理", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);

                executeResult = false;
            }
            else
            {
                TemplateParmForm tForm = new TemplateParmForm();
                DialogResult editResult = tForm.ShowDialog();

                if (editResult == DialogResult.OK)
                {
                    flowChartManager.ContentChanged = true;
                }
            }

            return executeResult;
        }
Esempio n. 39
0
        /// <summary>
        /// 创建绘图
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicCreateChart(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            TreeView tree = logicData as TreeView;

            TreeNode currentNode = tree.SelectedNode;
            string path = documentManager.GetNodePath(currentNode);

            CreateChartForm cForm = new CreateChartForm(path);

            if (cForm.ShowDialog() == DialogResult.OK)
            {
                string chartID = cForm.ChartID;
                string chartName = cForm.ChartName;

                TreeNode newNode = currentNode.Nodes.Add(chartName);
                newNode.Name = chartName;
                newNode.ImageIndex = 1;
                newNode.SelectedImageIndex = 1;
                newNode.Tag = chartID;
                tree.SelectedNode = newNode;
                documentManager.CurrentTreeMode = EditMode.Normal;
            }

            return true;
        }
Esempio n. 40
0
 /// <summary>
 /// 解除连接图元
 /// </summary>
 /// <param name="flowChartManager">绘图管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicDisconnect(FlowChartManager flowChartManager, object logicData)
 {
     return true;
 }
Esempio n. 41
0
 /// <summary>
 /// 绘图加载之后的操作
 /// </summary>
 /// <param name="flowChartManager">绘图管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected override bool LogicAfterLoad(FlowChartManager flowChartManager, object logicData)
 {
     return true;
 }
Esempio n. 42
0
        /// <summary>
        /// 编辑图元
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicEdit(FlowChartManager flowChartManager, object logicData)
        {
            bool executeResult = true;

            GraphManager graphManager = flowChartManager.CurrentGraphManager;
            DataManager dataManager = flowChartManager.CurrentDataManager;
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            GraphElement graphElement = logicData as GraphElement;
            DataElement dataElement = dataManager.GetDataElement(graphElement);

            object data = dataManager.GetData(graphElement);
            Hashtable information = new Hashtable();

            information["data"] = data;
            information["prev_data"] = dataManager.GetPreviousData(graphElement);
            information["next_data"] = dataManager.GetNextData(graphElement);
            information["neighbor_data"] = dataManager.GetNeighborData(graphElement);
            information["globe_args"] = dataManager.GlobeArgs;
            information["flowchart_name"] = flowChartManager.Name;
            information["map_name"] = flowChartManager.MapName;
            information["client_dir"] = Helper.GetHelper().OutputDir;

            dataElement.PrintInformation = new DataElement.PrintInfo(documentManager.PrintText);

            try
            {
                executeResult = dataElement.EditData(information);
            }
            catch (Exception ex)
            {
                executeResult = false;

                MessageBox.Show("当前图元由于以下原因无法编辑:\n\n" + ex.Message, "图元编辑",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            if (executeResult) // 保存图元数据
            {
                Hashtable previousDataTable = information["prev_data"] as Hashtable;
                Hashtable nextDataTable = information["next_data"] as Hashtable;
                GraphElement currentGraphElement;
                DataElement editDataElement;

                // 检查是否需要更新图元和数据元的数据
                foreach (string id in previousDataTable.Keys)
                {
                    editDataElement = previousDataTable[id] as DataElement;

                    if (editDataElement != null && editDataElement.Data == null)
                    {
                        currentGraphElement = dataManager.FindGraphElementByID(int.Parse(id));
                        currentGraphElement.Text = editDataElement.Text;
                        currentGraphElement.TooltipText = editDataElement.TooltipText;
                        currentGraphElement.ShowText = false;
                    }
                }

                foreach (string id in nextDataTable.Keys)
                {
                    editDataElement = nextDataTable[id] as DataElement;

                    if (editDataElement != null && editDataElement.Data == null)
                    {
                        currentGraphElement = dataManager.FindGraphElementByID(int.Parse(id));
                        currentGraphElement.Text = editDataElement.Text;
                        currentGraphElement.TooltipText = editDataElement.TooltipText;
                        currentGraphElement.ShowText = false;
                    }
                }

                graphElement.TooltipText = dataElement.TooltipText;
                graphElement.Text = dataElement.Text;

                if (string.IsNullOrEmpty(dataElement.Text))
                {
                    graphElement.ShowText = false;
                }
                else
                {
                    graphElement.ShowText = true;
                }

                // 调整文本
                if (graphElement is SlotContainer)
                {
                    SlotContainer slotContainer = graphElement as SlotContainer;
                    slotContainer.AdjustText();

                    // 根据文本内容调整插槽容器的大小
                    slotContainer.AdjustElementSize();
                }
                else if (graphElement is ConnectorContainer)
                {
                    ConnectorContainer line = graphElement as ConnectorContainer;
                    line.AdjustText();
                }
            }

            return executeResult;
        }
Esempio n. 43
0
        /// <summary>
        /// 弹出右键菜单
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicPopUpMenuStrip(FlowChartManager flowChartManager, object logicData)
        {
            GraphManager graphManager = flowChartManager.CurrentGraphManager;

            Point popUpLocation = (Point)logicData;
            DocumentManager documentManager = DocumentManager.GetDocumentManager();

            if (graphManager.SelectedGraphElement is SlotContainer) // 有AI插槽容器被选中
            {
                if (graphManager.SelectedGraphElement is AIStateGraphElement)
                {
                    editMenu.SubItems["bCAndCStateNode"].Enabled = false;
                    editMenu.SubItems["bSetInitialState"].Enabled = true;
                }
                else
                {
                    editMenu.SubItems["bCAndCStateNode"].Enabled = true;
                    editMenu.SubItems["bSetInitialState"].Enabled = false;
                }

                if (flowChartManager.MapName == "子绘图")
                {
                    // 子绘图内不能再创建子绘图结点
                    editMenu.SubItems["bCAndCInnerChartNode"].Enabled = false;

                    // 只有子绘图能创建接口结点
                    editMenu.SubItems["bCAndCInterfaceNode"].Enabled = true;
                }
                else
                {                    
                    editMenu.SubItems["bCAndCInnerChartNode"].Enabled = true;                    
                    editMenu.SubItems["bCAndCInterfaceNode"].Enabled = false;
                }

                editMenu.Popup(popUpLocation);
            }
            else if (graphManager.SelectedGraphElement == null) // 没有选中任何图元
            {
                if (documentManager.CopyTable != null)
                {
                    canvasMenu.SubItems["bPasteGraphElement"].Enabled = true;
                }
                else
                {
                    canvasMenu.SubItems["bPasteGraphElement"].Enabled = false;
                }

                if (flowChartManager.MapName == "子绘图") 
                {
                    // 子绘图不允许重设图元ID
                    canvasMenu.SubItems["bResetGraphElementID"].Enabled = false;
                    
                    // 子绘图内不能再创建子绘图结点
                    canvasMenu.SubItems["bCreateInnerChartNode"].Enabled = false;

                    // 只有子绘图能创建接口结点
                    canvasMenu.SubItems["bCreateInterfaceNode"].Enabled = true;
                }
                else
                {
                    canvasMenu.SubItems["bResetGraphElementID"].Enabled = true;
                    canvasMenu.SubItems["bCreateInnerChartNode"].Enabled = true;
                    canvasMenu.SubItems["bCreateInterfaceNode"].Enabled = false;
                }

                canvasMenu.Popup(popUpLocation);
            }

            return true;
        }
Esempio n. 44
0
        /// <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;
        }
Esempio n. 45
0
        /// <summary>
        /// 在指定点创建结点
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicCreateNodeAtPoint(FlowChartManager flowChartManager, object logicData)
        {
            GraphManager graphManager = flowChartManager.CurrentGraphManager;

            object[] args = logicData as object[];
            int graphType = (int)args[0];
            Point location = (Point)args[1];

            switch (graphType)
            {
                case 1: // 创建AI状态结点
                    {
                        if ((graphManager.SelectedGraphElement is AISlotContainer) &&
                            !(graphManager.SelectedGraphElement is AIStateGraphElement))
                        {
                            CreateNode(GraphType.AIStateNode, location, true);
                        }
                        else
                        {
                            CreateNode(GraphType.AIStateNode, location, false);
                        }

                        break;
                    }
                case 2: // 创建AI动作结点
                    {
                        if (graphManager.SelectedGraphElement is AISlotContainer)
                        {
                            CreateNode(GraphType.AIActionNode, location, true);
                        }
                        else
                        {
                            CreateNode(GraphType.AIActionNode, location, false);
                        }

                        break;
                    }
                case 3: // 创建AI动作组结点
                    {
                        if (graphManager.SelectedGraphElement is AISlotContainer)
                        {
                            CreateNode(GraphType.AIActionsNode, location, true);
                        }
                        else
                        {
                            CreateNode(GraphType.AIActionsNode, location, false);
                        }

                        break;
                    }
                case 4: // 创建子绘图结点
                    {
                        if (graphManager.SelectedGraphElement is AISlotContainer)
                        {
                            CreateNode(GraphType.InnerChart, location, true);
                        }
                        else
                        {
                            CreateNode(GraphType.InnerChart, location, false);
                        }

                        break;
                    }
                case 5:// 创建 接口结点
                    {
                        if (graphManager.SelectedGraphElement is AISlotContainer)
                        {
                            CreateNode(GraphType.InterfaceNode, location, true);
                        }
                        else
                        {
                            CreateNode(GraphType.InterfaceNode, location, false);
                        }

                        break;
                    }
            }

            return true;
        }
Esempio n. 46
0
 /// <summary>
 /// 绘图加载之后的处理
 /// </summary>
 /// <param name="flowChartManager">绘图管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicAfterLoad(FlowChartManager flowChartManager, object logicData)
 {
     return true;
 }
Esempio n. 47
0
        /// <summary>
        /// 编辑图元
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicEdit(FlowChartManager flowChartManager, object logicData)
        {
            bool executeResult = true;

            GraphManager    graphManager    = flowChartManager.CurrentGraphManager;
            DataManager     dataManager     = flowChartManager.CurrentDataManager;
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            GraphElement    graphElement    = logicData as GraphElement;
            DataElement     dataElement     = dataManager.GetDataElement(graphElement);

            object    data        = dataManager.GetData(graphElement);
            Hashtable information = new Hashtable();

            information["data"]           = data;
            information["prev_data"]      = dataManager.GetPreviousData(graphElement);
            information["next_data"]      = dataManager.GetNextData(graphElement);
            information["neighbor_data"]  = dataManager.GetNeighborData(graphElement);
            information["globe_args"]     = dataManager.GlobeArgs;
            information["flowchart_name"] = flowChartManager.Name;
            information["map_name"]       = flowChartManager.MapName;
            information["client_dir"]     = Helper.GetHelper().OutputDir;

            dataElement.PrintInformation = new DataElement.PrintInfo(documentManager.PrintText);

            try
            {
                executeResult = dataElement.EditData(information);
            }
            catch (Exception ex)
            {
                executeResult = false;

                MessageBox.Show("当前图元由于以下原因无法编辑:\n\n" + ex.Message, "图元编辑",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            if (executeResult) // 保存图元数据
            {
                Hashtable    previousDataTable = information["prev_data"] as Hashtable;
                Hashtable    nextDataTable     = information["next_data"] as Hashtable;
                GraphElement currentGraphElement;
                DataElement  editDataElement;

                // 检查是否需要更新图元和数据元的数据
                foreach (string id in previousDataTable.Keys)
                {
                    editDataElement = previousDataTable[id] as DataElement;

                    if (editDataElement != null && editDataElement.Data == null)
                    {
                        currentGraphElement             = dataManager.FindGraphElementByID(int.Parse(id));
                        currentGraphElement.Text        = editDataElement.Text;
                        currentGraphElement.TooltipText = editDataElement.TooltipText;
                        currentGraphElement.ShowText    = false;
                    }
                }

                foreach (string id in nextDataTable.Keys)
                {
                    editDataElement = nextDataTable[id] as DataElement;

                    if (editDataElement != null && editDataElement.Data == null)
                    {
                        currentGraphElement             = dataManager.FindGraphElementByID(int.Parse(id));
                        currentGraphElement.Text        = editDataElement.Text;
                        currentGraphElement.TooltipText = editDataElement.TooltipText;
                        currentGraphElement.ShowText    = false;
                    }
                }

                graphElement.TooltipText = dataElement.TooltipText;
                graphElement.Text        = dataElement.Text;

                if (string.IsNullOrEmpty(dataElement.Text))
                {
                    graphElement.ShowText = false;
                }
                else
                {
                    graphElement.ShowText = true;
                }

                // 调整文本
                if (graphElement is SlotContainer)
                {
                    SlotContainer slotContainer = graphElement as SlotContainer;
                    slotContainer.AdjustText();

                    // 根据文本内容调整插槽容器的大小
                    slotContainer.AdjustElementSize();
                }
                else if (graphElement is ConnectorContainer)
                {
                    ConnectorContainer line = graphElement as ConnectorContainer;
                    line.AdjustText();
                }
            }

            return(executeResult);
        }
Esempio n. 48
0
        /// <summary>
        /// 弹出右键菜单
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicPopUpMenuStrip(FlowChartManager flowChartManager, object logicData)
        {
            Point popUpLocation = (Point)logicData;
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            GraphManager graphManager = flowChartManager.CurrentGraphManager;

            if (graphManager.SelectedGraphElement is SlotContainer) // 有AI插槽容器被选中
            {                
                editMenu.Popup(popUpLocation);
            }
            else if (graphManager.SelectedGraphElement == null) // 没有选中任何图元
            {
                if (documentManager.CopyTable != null)
                {
                    canvasMenu.SubItems["bPasteGraphElement"].Enabled = true;
                }
                else
                {
                    canvasMenu.SubItems["bPasteGraphElement"].Enabled = false;
                }

                if (flowChartManager.MapName == "子绘图") // 子绘图不允许重设图元ID
                {
                    canvasMenu.SubItems["bResetGraphElementID"].Enabled = false;
                }
                else
                {
                    canvasMenu.SubItems["bResetGraphElementID"].Enabled = true;
                }

                canvasMenu.Popup(popUpLocation);
            }

            return true;
        }
Esempio n. 49
0
        /// <summary>
        /// 生成脚本
        /// </summary>
        /// <param name="flowChartManager">逻辑管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicCompileCode(FlowChartManager flowChartManager, object logicData)
        {
            bool executeSuccess = GenerateCode();

            return(executeSuccess);
        }
Esempio n. 50
0
        /// <summary>
        /// 打开脚本
        /// </summary>
        /// <param name="flowChartManager">逻辑管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicViewCode(FlowChartManager flowChartManager, object logicData)
        {
            DocumentManager documentManager = DocumentManager.GetDocumentManager();
            Helper helper = Helper.GetHelper();
            string relevatePath = logicData as string;
            string path = Path.Combine(helper.OutputDir, string.Format("{0}.lua", relevatePath));
            
            if (File.Exists(path)) // 文件存在
            {
                try
                {
                    System.Diagnostics.Process.Start(path);
                }
                catch (IOException ex)
                {
                    MessageBox.Show("在查看脚本时产生IO异常:" + ex.Message, "打开脚本",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(string.Format("脚本文件{0}不存在!", path), "打开脚本",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return true;
        }
Esempio n. 51
0
 /// <summary>
 /// 检查逻辑
 /// </summary>
 /// <param name="flowChartManager">逻辑管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicCheckLogic(FlowChartManager flowChartManager, object logicData)
 {
     return(true);
 }
Esempio n. 52
0
        /// <summary>
        /// 生成脚本
        /// </summary>
        /// <param name="flowChartManager">逻辑管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicCompileCode(FlowChartManager flowChartManager, object logicData)
        {
            bool executeSuccess = GenerateCode();

            return executeSuccess;
        }
Esempio n. 53
0
 /// <summary>
 /// 管理变量
 /// </summary>
 /// <param name="flowChartManager">逻辑管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicManageArguments(FlowChartManager flowChartManager, object logicData)
 {
     return(true);
 }
Esempio n. 54
0
 /// <summary>
 /// 管理变量
 /// </summary>
 /// <param name="flowChartManager">逻辑管理器</param>
 /// <param name="logicData">逻辑数据</param>
 /// <returns>是否操作成功</returns>
 protected virtual bool LogicManageArguments(FlowChartManager flowChartManager, object logicData)
 {
     return true;
 }
Esempio n. 55
0
        /// <summary>
        /// 执行逻辑功能
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicType">逻辑类型</param>
        /// <param name="logicData">逻辑数据</param>
        /// <return>执行结果</return>
        public virtual bool DoLogicOperation(FlowChartManager flowChartManager, LogicType logicType, object logicData)
        {
            bool executeSuccess = true;

            switch (logicType)
            {
            case LogicType.Connect:     // 连接图元
            {
                executeSuccess = LogicConnect(flowChartManager, logicData);
                break;
            }

            case LogicType.Disconnect:     // 解除连接图元
            {
                executeSuccess = LogicDisconnect(flowChartManager, logicData);
                break;
            }

            case LogicType.BeforeDelete:     // 删除图元之前
            {
                executeSuccess = LogicBeforeDelete(flowChartManager, logicData);
                break;
            }

            case LogicType.AfterDelete:     // 删除图元之后
            {
                executeSuccess = LogicAfterDelete(flowChartManager, logicData);
                break;
            }

            case LogicType.Edit:     // 编辑图元
            {
                executeSuccess = LogicEdit(flowChartManager, logicData);
                break;
            }

            case LogicType.Paste:     // 粘贴图元
            {
                executeSuccess = LogicPaste(flowChartManager, logicData);
                break;
            }

            case LogicType.CreateLine:     // 创建连接线
            {
                executeSuccess = LogicCreateLine(flowChartManager, logicData);
                break;
            }

            case LogicType.CreateAndConnectLine:     // 创建并连接连接线
            {
                executeSuccess = LogicCreateAndConnectLine(flowChartManager, logicData);
                break;
            }

            case LogicType.CreateChart:     // 创建绘图
            {
                executeSuccess = LogicCreateChart(flowChartManager, logicData);
                break;
            }

            case LogicType.AfterLoad:     // 加载绘图之后的处理
            {
                executeSuccess = LogicAfterLoad(flowChartManager, logicData);
                break;
            }

            case LogicType.InitializeDataElement:     // 初始化数据元
            {
                executeSuccess = LogicInitializeDataElement(flowChartManager, logicData);
                break;
            }

            case LogicType.PopUpContextMenu:     // 弹出右键菜单
            {
                executeSuccess = LogicPopUpMenuStrip(flowChartManager, logicData);
                break;
            }

            case LogicType.CreateAtPoint:     // 在指定点创建图元
            {
                executeSuccess = LogicCreateNodeAtPoint(flowChartManager, logicData);
                break;
            }

            case LogicType.ViewCode:     // 打开脚本
            {
                executeSuccess = LogicViewCode(flowChartManager, logicData);
                break;
            }

            case LogicType.ViewFolder:     // 打开文件夹
            {
                executeSuccess = LogicViewFolder(flowChartManager, logicData);
                break;
            }

            case LogicType.Save:     // 保存绘图
            {
                executeSuccess = LogicSave(flowChartManager, logicData);
                break;
            }

            case LogicType.CompileCode:     // 生成脚本
            {
                executeSuccess = LogicCompileCode(flowChartManager, logicData);
                break;
            }

            case LogicType.CheckLogic:     // 检查逻辑
            {
                executeSuccess = LogicCheckLogic(flowChartManager, logicData);
                break;
            }

            case LogicType.ManageArguments:     // 管理变量
            {
                executeSuccess = LogicManageArguments(flowChartManager, logicData);
                break;
            }

            default:
            {
                executeSuccess = false;
                break;
            }
            }

            return(executeSuccess);
        }
Esempio n. 56
0
        /// <summary>
        /// 粘贴图元
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected override bool LogicPaste(FlowChartManager flowChartManager, object logicData)
        {
            DataManager dataManager = flowChartManager.CurrentDataManager;

            List<GraphElement> graphElementList = logicData as List<GraphElement>;
            dataManager.InitCompileTable();

            foreach (GraphElement graphElement in graphElementList)
            {
                RenameGraphElement(dataManager, graphElement);
            }

            return true;
        }
Esempio n. 57
0
        /// <summary>
        /// 键盘按下事件响应
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件</param>
        private void canvas_KeyDown(object sender, KeyEventArgs e)
        {
            DocumentManager  documentManager  = DocumentManager.GetDocumentManager();
            FlowChartManager flowChartManager = documentManager.CurrentFlowChartManager;

            graphManager.ControlMode = e.Control;
            graphManager.ShiftMode   = e.Shift;
            graphManager.AltMode     = e.Alt;

            switch (e.KeyCode)
            {
            case Keys.Enter:     // 响应enter按键
            {
                graphManager.EditDataElement();

                break;
            }

            case Keys.Escape:     // 响应esc按键
            {
                graphManager.DeleteAbbreviateGraphElement();

                break;
            }

            case Keys.Space:     // 响应空格键
            {
                graphManager.CurrentBackground.DebugMode = !graphManager.CurrentBackground.DebugMode;

                break;
            }

            case Keys.Left:     // 响应左方向键
            {
                graphManager.MoveSelectedGraphElement(new Size(-1, 0));

                break;
            }

            case Keys.Up:     // 响应上方向键
            {
                graphManager.MoveSelectedGraphElement(new Size(0, -1));

                break;
            }

            case Keys.Right:     // 响应右方向键
            {
                graphManager.MoveSelectedGraphElement(new Size(1, 0));

                break;
            }

            case Keys.Down:     // 响应下方向键
            {
                graphManager.MoveSelectedGraphElement(new Size(0, 1));

                break;
            }

            case Keys.Delete:    // 响应delete按键
            {
                graphManager.DeleteSelectedGraphElement();

                break;
            }

            case Keys.D1:     // 响应1按键
            {
                // 执行逻辑操作
                LogicBaseManager logicManager = Helper.GetHelper().GetLogicManager(flowChartManager.CurrentChartMode);
                object[]         logicData    = new object[2];
                logicData[0] = 1;
                logicData[1] = (sender as Canvas).PointToClient(Cursor.Position);
                logicManager.DoLogicOperation(flowChartManager, LogicType.CreateAtPoint, logicData);

                break;
            }

            case Keys.NumPad1:     // 响应1按键
            {
                goto case Keys.D1;
            }

            case Keys.D2:     // 响应2按键
            {
                // 执行逻辑操作
                LogicBaseManager logicManager = Helper.GetHelper().GetLogicManager(flowChartManager.CurrentChartMode);
                object[]         logicData    = new object[2];
                logicData[0] = 2;
                logicData[1] = (sender as Canvas).PointToClient(Cursor.Position);
                logicManager.DoLogicOperation(flowChartManager, LogicType.CreateAtPoint, logicData);

                break;
            }

            case Keys.NumPad2:     // 响应2按键
            {
                goto case Keys.D2;
            }

            case Keys.D3:     // 响应3按键
            {
                // 执行逻辑操作
                LogicBaseManager logicManager = Helper.GetHelper().GetLogicManager(flowChartManager.CurrentChartMode);
                object[]         logicData    = new object[2];
                logicData[0] = 3;
                logicData[1] = (sender as Canvas).PointToClient(Cursor.Position);
                logicManager.DoLogicOperation(flowChartManager, LogicType.CreateAtPoint, logicData);

                break;
            }

            case Keys.NumPad3:     // 响应3按键
            {
                goto case Keys.D3;
            }

            case Keys.D4:     // 响应4按键
            {
                // 执行逻辑操作
                LogicBaseManager logicManager = Helper.GetHelper().GetLogicManager(flowChartManager.CurrentChartMode);
                object[]         logicData    = new object[2];
                logicData[0] = 4;
                logicData[1] = (sender as Canvas).PointToClient(Cursor.Position);
                logicManager.DoLogicOperation(flowChartManager, LogicType.CreateAtPoint, logicData);

                break;
            }

            case Keys.NumPad4:     // 响应4按键
            {
                goto case Keys.D4;
            }

            case Keys.D5:     // 响应5按键
            {
                // 执行逻辑操作
                LogicBaseManager logicManager = Helper.GetHelper().GetLogicManager(flowChartManager.CurrentChartMode);
                object[]         logicData    = new object[2];
                logicData[0] = 5;
                logicData[1] = (sender as Canvas).PointToClient(Cursor.Position);
                logicManager.DoLogicOperation(flowChartManager, LogicType.CreateAtPoint, logicData);

                break;
            }

            case Keys.NumPad5:     // 响应5按键
            {
                goto case Keys.D5;
            }

            case Keys.Oemplus:     // 响应+按键
            {
                graphManager.CurrentCanvas.AutoScroll = false;
                graphManager.AdjustCanvasScale(1.1f);
                documentManager.RefreshCanvasScaleDisplay();

                break;
            }

            case Keys.OemMinus:     // 响应-按键
            {
                graphManager.CurrentCanvas.AutoScroll = false;
                graphManager.AdjustCanvasScale(0.9f);
                documentManager.RefreshCanvasScaleDisplay();

                break;
            }

            case Keys.Oemcomma:     // 逗号
            {
                graphManager.SelectLineInSlotContainer();

                break;
            }

            case Keys.OemPeriod:     // 句号
            {
                graphManager.SelectLineOutSlotContainer();

                break;
            }

            case Keys.F5:     // 刷新绘图板
            {
                graphManager.RefreshRegion();

                break;
            }
            }
        }