Esempio n. 1
0
        /// <summary>
        /// 检查是否更新事件结点
        /// </summary>
        /// <param name="graphManager">图元管理器</param>
        /// <param name="graphElement">当前图元</param>
        /// <param name="eventNode">事件结点</param>
        /// <returns>是否需要更新</returns>
        private bool CheckCanBindEventNode(GraphManager graphManager, GraphElement graphElement, EventGraphElement eventNode)
        {
            bool avail = true;            
            DataManager dataManager = graphManager.CurrentFlowChartManager.CurrentDataManager;
            IComparable com1;
            IComparable com2;

            if (graphElement is SlotContainer) // 插槽容器
            {
                SlotContainer slotContainer = graphElement as SlotContainer;
                if (slotContainer.EventNode != null && slotContainer.EventNode != eventNode)
                {
                    com1 = dataManager.GetData(slotContainer.EventNode) as IComparable;
                    com2 = dataManager.GetData(eventNode) as IComparable;
                    avail = (com1.CompareTo(com2) == 0);
                }
            }
            else if (graphElement is ConnectorContainer) // 连接线
            {
                ConnectorContainer line = graphElement as ConnectorContainer;
                if (line.EventNode != null && line.EventNode != eventNode)
                {
                    com1 = dataManager.GetData(line.EventNode) as IComparable;
                    com2 = dataManager.GetData(eventNode) as IComparable;
                    avail = (com1.CompareTo(com2) == 0);
                }
            }

            return avail;
        }
Esempio n. 2
0
        protected GraphSetting graphSetting; // 绘图参数配置对象

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="owner">注释所属的图元</param>
        /// <param name="location">图元的位置</param>
        /// <param name="elementSize">图元的大小</param>
        public RemarkGraphElement(GraphElement owner, Point location, Size elementSize):
            base(location)
        {
            this.owner = owner;
            this.location = location;
            this.elementSize = elementSize;
        }
Esempio n. 3
0
        /// <summary>
        /// 获取数据元
        /// </summary>
        /// <param name="graphElement">图元</param>
        /// <returns>数据元</returns>
        public DataElement GetDataElement(GraphElement graphElement)
        {
            DataElement dataElement = null;

            if (graphTable != null)
            {
                dataElement = graphTable[graphElement] as DataElement;
            }

            return dataElement;
        }
Esempio n. 4
0
        /// <summary>
        /// 调整图元
        /// </summary>
        /// <param name="text">图元的文本</param>
        /// <param name="graphElementRectangle">图元区域</param>
        /// <param name="visibleRectable">当前可视区域</param>
        public void Adjust(string text, GraphElement graphElement, Rectangle visibleRectangle, Point mouseLocation)
        {
            this.text = text;            
            this.visibleRectangle = visibleRectangle;

            if (this.activatedGraphElement != graphElement)
            {
                this.activatedGraphElement = graphElement;
                Init(graphElement, mouseLocation);
            }            
        }
Esempio n. 5
0
        /// <summary>
        /// 初始化文本提示
        /// </summary>
        /// <param name="graphElement">需要文本提示的图元</param>
        /// <param name="location">文本提示的位置</param>
        private void InitTooltipText(GraphElement graphElement, Point location)
        {
            string tooltipText = "";

            if (!string.IsNullOrEmpty(graphElement.TooltipText) &&
                graphElement.Text != graphElement.TooltipText) // 显示图元的提示文本
            {
                tooltipText = graphElement.TooltipText;
            }

            if (selectedGraphElementList.Contains(graphElement)) // 多选图元状态
            {
                tooltipText = "<underline>鼠标拖动移动框选的图元组";
            }
            else
            {
                if (graphElement is ConnectorGraphElement) // 激活的图元是连接线控制点
                {
                    ConnectorGraphElement connector = graphElement as ConnectorGraphElement;

                    if (connector.IsHeadPoint || connector.IsTailPoint) // 连接线控制点是头结点或尾结点
                    {
                        tooltipText = "<underline>鼠标拖动连接图元结点或调整连接线形状";
                    }
                    else
                    {
                        tooltipText = "<underline>鼠标拖动调整连接线形状";
                    }
                }
                else if (graphElement is ConnectorContainer) // 激活的图元是连接线
                {
                    ConnectorContainer line = graphElement as ConnectorContainer;

                    if (tooltipText == "")
                    {
                        tooltipText = line.Text;
                    }
                    
                    if (tooltipText != "")
                    {
                        if (line.InSlotContainer != null && line.OutSlotContainer != null) // 显示连接两端的内容
                        {
                            tooltipText = string.Format("<bold>分支内容\r\n{0}\r\n<split>\r\n<bold>连接信息\r\n{1} --> {2}\r\n<split>\r\n<underline>按<>键切换到连接线两端结点\r\n<underline>鼠标双击或按Enter编辑图元",
                                                        tooltipText, line.InSlotContainer.Text, line.OutSlotContainer.Text);
                        }
                        else
                        {
                            tooltipText = string.Format("<bold>分支内容\r\n{0}\r\n<split>\r\n<underline>鼠标双击或按Enter键编辑图元",
                                                        tooltipText);
                        }
                    }
                    else
                    {
                        if (line.InSlotContainer != null && line.OutSlotContainer != null) // 显示连接两端的内容
                        {
                            tooltipText = string.Format("<bold>连接信息\r\n{0} --> {1}\r\n<split>\r\n<underline>按<>键切换到连接线两端结点\r\n<underline>鼠标双击或按Enter编辑图元",
                                                        line.InSlotContainer.Text, line.OutSlotContainer.Text);
                        }
                        else
                        {
                            tooltipText = "<underline>鼠标双击或按Enter键编辑图元";
                        }
                    }
                    
                }
                else if (graphElement is ResizeControler) // 激活的图元是缩放控制点
                {
                    tooltipText = "<underline>鼠标拖动调整图元形状";
                }
                else if (graphElement is AddButton) // 激活的图元是添加按钮
                {
                    tooltipText = "<underline>鼠标点击增加图元插槽";
                }
                else if (graphElement is ConnectButton) // 激活的图元是连接按钮
                {
                    tooltipText = "<underline>鼠标拖动创建连接线";
                }
                else if (graphElement is SlotGraphElement) // 激活的图元是插槽
                {
                    if (string.IsNullOrEmpty(graphElement.TooltipText))
                    {
                        tooltipText = "<underline>鼠标拖入或拖出连接线控制点调整图元连接";
                    }
                    else
                    {
                        tooltipText = string.Format("<bold>插槽内容\r\n{0}\r\n<split>\r\n<underline>鼠标拖入或拖出连接线控制点调整图元连接",
                                                    graphElement.TooltipText);
                    }
                }
                else if (graphElement is RemarkGraphElement) // 激活的图元是注释
                {
                    tooltipText = "<underline>鼠标双击或按Enter键编辑图元注释";
                }
                else if (graphElement is SlotContainer) // 激活的图元是插槽容器
                {
                    if (graphElement.Enable) // 激活的图元可用
                    {
                        if (tooltipText != "")
                        {
                            tooltipText = string.Format("{0}\r\n<split>\r\n<underline>鼠标双击或按Enter键编辑图元", tooltipText);
                        }
                        else
                        {
                            tooltipText = "<underline>鼠标双击或按Enter键编辑图元";
                        }
                    }
                    else // 激活的图元不可用
                    {
                        if (tooltipText != "")
                        {
                            tooltipText = string.Format("{0}\r\n<split>\r\n<underline>当前图元不可编辑,请确认连接是否正确", tooltipText);
                        }
                        else
                        {
                            tooltipText = "<underline>当前图元不可编辑,请确认连接是否正确";
                        }
                    }
                }
                else if (graphElement is Rodman)
                {
                    tooltipText = "<underline>鼠标拖动批量移动游标右边或下边的图元";
                }
            }

            InitTooltipText(graphElement, tooltipText, location);
        }
Esempio n. 6
0
        /// <summary>
        /// 创建显示缩略的图元
        /// </summary>
        /// <param name="graphType">图元的类型</param>
        /// <param name="point">图元的位置</param>
        /// <param name="autoConnect">是否自动连接</param>
        /// <param name="jumpConnect">是否跳转连接</param>
        public void CreateAbbreviateGraphElement(GraphType graphType, Point p, bool autoConnect)
        {
            Point point = Point.Empty;

            if (!p.IsEmpty)
            {
                point = p - new Size(canvas.AutoScrollPosition);
            }

            canvas.AbbreviatGraphElement = CreateAbbreviateGraphElement(graphType, point);
            userOperation = UserOperation.Create;
            this.autoConnect = autoConnect;

            if (autoConnect) // 记录当前选中的插槽容器
            {
                lastConnectGraphElement = selectedGraphElement as SlotContainer;

                // 创建缩略图元的连接线
                int tailX = (int)(lastConnectGraphElement.Location.X + lastConnectGraphElement.ElementSize.Width / 2);
                int tailY = (int)(lastConnectGraphElement.Location.Y + lastConnectGraphElement.ElementSize.Height);
                int headX = (int)(canvas.AbbreviatGraphElement.Location.X + canvas.AbbreviatGraphElement.ElementSize.Width / 2);
                int headY = (int)(canvas.AbbreviatGraphElement.Location.Y);

                canvas.AbbreviateLine = new ConnectorContainer(new Point(tailX, tailY), new Point(headX, headY));
                canvas.AbbreviateLine.Init();
            }
            else // 清空连接线
            {
                canvas.AbbreviateLine = null;
            }

            if (!p.IsEmpty) // 显示提示信息
            {
                InitTooltipText(canvas.AbbreviatGraphElement, "<underline>鼠标拖动移动图元\r\n<underline>鼠标点击创建图元\r\n<underline>按Esc键取消创建图元", point);
            }

            RefreshCanvas();
        }
Esempio n. 7
0
        /// <summary>
        /// 粘贴图元
        /// </summary>
        public void PasteGraphElement()
        {
            Point pastePoint = canvas.PointToClient(Cursor.Position) - (Size)canvas.AutoScrollPosition; // 粘贴位置
            FlowChartPasteCommand cmd = new FlowChartPasteCommand(this, "粘贴图元");
            InitFirstCommand(cmd);

            if (cmd.Execute(pastePoint)) // 命令执行成功
            {
                AdjustCommandList(cmd);

                bool multiPaste = false;

                if(flowChartManager.PasteTable.Keys.Count > 1) // 复制多个图元
                {
                    multiPaste = true;

                    // 清空多选区域
                    ClearSelectedGraphElementList();
                }

                // 将粘贴的图元加入到区域中
                foreach(object o in flowChartManager.PasteTable.Keys)
                {
                    GraphElement graphElement = o as GraphElement;

                    if (graphElement is ConnectorContainer) // 连接线
                    {
                        ConnectorContainer line = graphElement as ConnectorContainer;
                        line.AdjustRectangle();
                    }

                    regionManager.AddToRegion(graphElement);

                    if (multiPaste)
                    {                        
                        selectedGraphElementList.Add(graphElement);
                    }
                    else
                    {
                        selectedGraphElement = graphElement;
                    }

                    graphElement.Selected = true;
                }

                // 选中粘贴的多个图元
                if (multiPaste)
                {                    
                    CreateMultiSelectRegion();
                }

                // 自动调整绘图板大小
                AdjustOutOfBorder();
               
                ReconstructCanvasGraphElementList();

                // 执行逻辑操作                
                List<GraphElement> graphElementList = new List<GraphElement>();

                if (multiPaste)
                {
                    graphElementList.AddRange(selectedGraphElementList);
                }
                else
                {
                    graphElementList.Add(selectedGraphElement);
                }

                LogicBaseManager logicManager = helper.GetLogicManager(flowChartManager.CurrentChartMode);
                logicManager.DoLogicOperation(flowChartManager, LogicType.Paste, graphElementList);                
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 选中图元
        /// </summary>
        /// <param name="graphElement">当前图元</param>
        /// <param name="showMultiSelectRegion">是否显示框选区域</param>
        public void SelectGraphElement(GraphElement graphElement, bool showMultiSelectRegion)
        {
            if (lastSelectedGraphElement != null) // 将上一个被选中的图元置为非选中状态
            {
                if (!selectedGraphElementList.Contains(lastSelectedGraphElement)) // 在多选状态需要检查上一个被选中的图元是否在多选容器中
                {
                    lastSelectedGraphElement.Selected = false;
                }
            }

            if (lastResizingGraphElement != null) // 将上一个缩放的插槽容器置为非缩放状态
            {
                lastResizingGraphElement.Resizing = false;
            }

            // 清空选中的图元链表
            ClearSelectedGraphElementList();

            // 很奇怪,Control键有很大几率会被认为是按下的,在这里重置一下
            controlMode = false;

            graphElement.Selected = true;
            selectedGraphElement = graphElement;
            lastSelectedGraphElement = graphElement;            
            documentManager.ShowObjectProperty(graphElement);

            // 创建框选区域显示突出显示
            if (showMultiSelectRegion)
            {
                canvas.CurrentMultiSelectMark.Adjust(graphElement.Location + new Size(-5, -5), graphElement.ElementSize + new Size(10, 10));
                canvas.CurrentMultiSelectMark.ShowBackground = false;
                canvas.CurrentMultiSelectMark.Visible = true;

                // 屏幕自动滚动居中
                AutoScrollToPoint(graphElement.Location - new Size((canvas.ClientSize.Width - graphElement.ElementSize.Width) / 2,
                                  (canvas.ClientSize.Height - graphElement.ElementSize.Height) / 2));
            }                        

            // 刷新绘图            
            RefreshCanvas(graphElement.InvalidRectangle);
        }
Esempio n. 9
0
        /// <summary>
        /// 删除选中的图元
        /// </summary>
        public void DeleteSelectedGraphElement()
        {
            if (selectedGraphElementList.Count > 0) // 删除所有选中的图元
            {
                // 调整图元区域
                foreach (GraphElement graphElement in selectedGraphElementList)
                {                    
                    regionManager.DeleteFromRegion(graphElement);
                }

                FlowChartMultiDeleteCommand cmd = new FlowChartMultiDeleteCommand(this, "删除图元");
                InitFirstCommand(cmd);

                if (cmd.Execute(selectedGraphElementList)) // 命令执行成功
                {
                    AdjustCommandList(cmd);
                    canvas.CurrentMultiSelectMark.Visible = false;
                    selectedGraphElement = null;
                    lastSelectedGraphElement = null;
                    lastActivatedGraphElement = null;
                    ReconstructCanvasGraphElementList();
                }                
            }

            if (selectedGraphElement != null) // 删除单个选中的图元
            {
                List<ConnectorContainer> list = new List<ConnectorContainer>();
                DataManager dataManager = flowChartManager.CurrentDataManager;
                
                if (selectedGraphElement is SlotContainer) // 要删除插槽容器
                {
                    SlotContainer slotContainer = selectedGraphElement as SlotContainer;

                    foreach (GraphElement graphElement in dataManager.GetPreviousGraphElements(slotContainer))
                    {
                        ConnectorContainer line = graphElement as ConnectorContainer;

                        if (dataManager.GetData(graphElement) == null && !list.Contains(line))
                        {
                            list.Add(line);
                        }
                    }

                    foreach (GraphElement graphElement in dataManager.GetNextGraphElements(slotContainer, false))
                    {
                        ConnectorContainer line = graphElement as ConnectorContainer;

                        if (dataManager.GetData(graphElement) == null && !list.Contains(line))
                        {
                            list.Add(line);
                        }
                    }
                }       
         
                regionManager.DeleteFromRegion(selectedGraphElement);

                FlowChartDeleteCommand cmd = new FlowChartDeleteCommand(this, "删除图元");
                InitFirstCommand(cmd);

                if (cmd.Execute(selectedGraphElement)) // 命令执行成功
                {
                    AdjustCommandList(cmd);
                    
                    if (list.Count > 0) // 删除无数据的连接线
                    {
                        foreach (ConnectorContainer line in list)
                        {
                            SlotContainer inSlotContainer = line.InSlotContainer;
                            List<GraphElement> graphElementList = new List<GraphElement>();

                            // 执行逻辑操作
                            LogicBaseManager logicManager = helper.GetLogicManager(flowChartManager.CurrentChartMode);
                            logicManager.DoLogicOperation(flowChartManager, LogicType.BeforeDelete, line);

                            if (line.InSlotContainer != null)
                            {
                                line.UnbindInSlotContainer();
                            }

                            if (line.OutSlotContainer != null)
                            {
                                graphElementList.Add(line.OutSlotContainer);
                                line.UnbindOutSlotContainer();
                            }

                            // 执行逻辑操作
                            logicManager.DoLogicOperation(flowChartManager, LogicType.AfterDelete, graphElementList);

                            connectorContainerList.Remove(line); // 从连接线控制点索引容器中删除
                        }
                    }
                    
                    selectedGraphElement = null;
                    lastSelectedGraphElement = null;
                    lastActivatedGraphElement = null;
                    ReconstructCanvasGraphElementList();                    
                }                                               
            }

            canvas.PaintCanvas = true; // 避免绘制时使用已经释放的资源
            RefreshCanvas();
        }
Esempio n. 10
0
 /// <summary>
 /// 初始化文本提示
 /// </summary>
 /// <param name="graphElement">当前图元</param>
 /// <param name="text">文本内容</param>
 /// <param name="mouseLocation">鼠标位置</param>
 private void InitTooltipText(GraphElement graphElement, string text, Point mouseLocation)
 {
     canvas.TooltipGraphElement.Adjust(text, graphElement, canvas.VisibleRectangle, mouseLocation);
     canvas.TooltipGraphElement.Visible = true;
 }        
Esempio n. 11
0
        /// <summary>
        /// 激活图元
        /// </summary>
        /// <param name="p">鼠标当前所在点</param>
        private void ActivateGraphElement(Point p)
        {
            bool activated = false; // 是否有图元被激活
            canvas.TooltipGraphElement.Visible = false; // 消除文本提示                  
            
            // 先做一次短路检查
            if (lastActivatedGraphElement != null)
            {
                if (lastActivatedGraphElement is ConnectorContainer)
                {
                    ConnectorContainer line = lastActivatedGraphElement as ConnectorContainer;
                    ConnectorGraphElement connector = line.GetConnectorInRegion(p);

                    if (connector != null)
                    {
                        lastActivatedGraphElement = connector;
                        activated = true;
                    }
                    else
                    {
                        if (line.IsInRegion(p))
                        {
                            activated = true;
                        }                        
                    }
                }
                else if (lastActivatedGraphElement is SlotContainer)
                {
                    SlotContainer node = lastActivatedGraphElement as SlotContainer;
                    SlotGraphElement slot = node.GetSlotInRegion(p);

                    if (slot != null)
                    {
                        lastActivatedGraphElement = slot;
                        activated = true;
                    }
                    else
                    {
                        if (node.IsInRegion(p))
                        {
                            activated = true;
                        }
                    }
                }
                else if (lastActivatedGraphElement is Rodman)
                {
                    ; // 游标需要特殊处理
                }
                else
                {
                    if (lastActivatedGraphElement.IsInRegion(p))
                    {
                        activated = true;
                    }
                }                
            }

            if (!activated)
            {
                // 检查是否激活游标
                canvas.CurrentRodman.Init(p, canvas.VisibleRectangle);

                if (canvas.CurrentRodman.IsInRegion(p))
                {
                    lastActivatedGraphElement = canvas.CurrentRodman;
                    activated = true;
                }
            }            

            // 检查是否有连接线控制点被激活
            foreach (ConnectorContainer connectorContainer in regionManager.GetConnectorContainerList(p))
            {
                if (activated) // 如果已经有图元被激活,则直接跳出循环
                {
                    break;
                }

                ConnectorGraphElement connector = connectorContainer.GetConnectorInRegion(p);

                if (connector != null)
                {
                    lastActivatedGraphElement = connector;
                    activated = true;
                    break;
                }
                
                if (connectorContainer.IsInRegion(p)) // 检查连接线是否可以激活
                {
                    lastActivatedGraphElement = connectorContainer;
                    activated = true;
                    break;
                }                        
            }

            bool resizeControlerActivated = false; // 是否有缩放控制点被激活

            foreach (SlotContainer slotContainer in regionManager.GetSlotContainerList(p)) // 检查是否有插槽容器被激活
            {
                if (activated) // 如果已经有图元被激活,则直接跳出循环
                {
                    break;
                }

                ResizeControler resizeControler = slotContainer.GetResizeControlerInRegion(p);
                
                if (resizeControler != null)
                {
                    resizeControlerActivated = true;
                    activated = true;
                    lastActivatedGraphElement = resizeControler;
                    ChangeMouseCursur(resizeControler.CurrentDirection); // 改变鼠标指针形状
                    break;
                }                

                // 遍历检查容器的按钮是否被激活
                BaseButton baseButton = slotContainer.GetButtonInRegion(p);

                if (baseButton != null)
                {
                    activated = true;
                    lastActivatedGraphElement = baseButton;
                    break;
                }                

                // 检查是否有注释图元被选中
                if (slotContainer.RemarkNode != null)
                {
                    if (slotContainer.RemarkNode.IsInRegion(p))
                    {
                        lastActivatedGraphElement = slotContainer.RemarkNode;
                        activated = true;
                        break;
                    }
                }

                if (slotContainer.IsInRegion(p)) // 检查当前点是否在图元区域内
                {
                    SlotGraphElement slot = slotContainer.GetSlotInRegion(p);

                    if (slot != null)
                    {
                        activated = true;
                        lastActivatedGraphElement = slot;
                        break;
                    }
                    
                    activated = true;
                    lastActivatedGraphElement = slotContainer;
                    break;                    
                }
            }

            if (activated) // 有图元被激活
            {
                lastActivatedGraphElement.Activated = true; // 激活图元                

                if (lastActivatedGraphElement is SlotContainer) // 取消标记插槽容器周围的连接线
                {
                    MarkRelavateLines(lastActivatedGraphElement as SlotContainer, true);
                }

                // 初始化文本提示
                InitTooltipText(lastActivatedGraphElement, p);
            }

            if (!resizeControlerActivated) // 恢复绘图板的默认指针样式
            {
                canvas.Cursor = Cursors.Default;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// 设置图元是否可用
        /// </summary>
        /// <param name="dataManager">事件管理器</param>
        /// <param name="list">遍历过的图元链表</param>
        /// <param name="graphElement">当前图元</param>
        /// <param name="enable">图元是否可用</param>
        public void ReBindEventNode(DataManager dataManager, List<GraphElement> list, GraphElement graphElement, bool enable)
        {
            if (!list.Contains(graphElement)) // 还没有遍历过当前图元
            {
                list.Add(graphElement);

                if(enable)
                {
                    graphElement.Enable = enable;
                }
                else
                {
                    if(graphElement is SlotContainer) // 插槽容器
                    {
                        if(!dataManager.IsConnectEventNode(graphElement as SlotContainer))
                        {
                            graphElement.Enable = enable;
                        }
                    }
                    else if(graphElement is ConnectorContainer) // 连接线
                    {
                        if (!dataManager.IsConnectEventNode(graphElement as ConnectorContainer))
                        {
                            graphElement.Enable = enable;
                        }
                    }                    
                }

                foreach (GraphElement g in dataManager.GetNextGraphElements(graphElement, false))
                {
                    ReBindEventNode(dataManager, list, g, enable);
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 刷新未初始化数据元的图元的数据
        /// </summary>
        /// <param name="dataManager">数据管理器实例</param>
        /// <param name="graphElement">图元对象</param>
        /// <param name="data">数据</param>
        private void ReloadData(DataManager dataManager, GraphElement graphElement, object data)
        {
            DataElement dataElement = dataManager.InitDataElement(graphElement);
            Hashtable table = new Hashtable();
            table["globe_args"] = dataManager.GlobeArgs;

            if (dataElement != null)
            {
                dataElement.Data = data;
                dataElement.ReloadData(table);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 获取下一个流程图元数据
        /// </summary>
        /// <param name="dataManager">数据管理器</param>
        /// <param name="graphElement">当前图元</param>
        /// <param name="metaData">流程图元数据</param>
        /// <param name="graphElementList">遍历过的图元链表</param>
        /// <param name="graphElementTable">流程图索引哈希表</param>
        private void FindNextMetaData(DataManager dataManager, GraphElement graphElement, FlowChartMetaData metaData, List<GraphElement> graphElementList, Hashtable graphElementTable)
        {
            graphElementList.Add(graphElement);
            graphElementTable[graphElement] = metaData;
            List<GraphElement> list = dataManager.GetNextGraphElements(graphElement, false);

            foreach (GraphElement g in list)
            {
                object data = dataManager.GetData(g);                
                
                if(!graphElementList.Contains(g))
                {
                    DataElement dataElement = dataManager.GetDataElement(g);
                    FlowChartMetaData newMetaData = new FlowChartMetaData(g.ID, data, dataElement.DataType);
                    newMetaData.Code = CodeProvider.CodeProviderClass.ConvertToCode(data, dataElement.DataType);
                    newMetaData.DisplayText = g.TooltipText;
                    newMetaData.AddPreviousMetaData(metaData);
                    metaData.AddNextMetaData(newMetaData);
                    FindNextMetaData(dataManager, g, newMetaData, graphElementList, graphElementTable);
                }
                else
                {
                    FlowChartMetaData newMetaData = graphElementTable[g] as FlowChartMetaData;
                    newMetaData.AddPreviousMetaData(metaData);
                    metaData.AddNextMetaData(newMetaData);
                }
            }

            if (graphElement is ConditionGraphElement) // 条件结点
            {
                bool avail = true; // 是否需要生成else连接线

                foreach(GraphElement g in list)
                {
                    if(dataManager.GetData(g) == null) // 找到else连接线
                    {
                        avail = false;
                        break;
                    }
                }

                if(avail) // 需要生成else连接线
                {
                    FlowChartMetaData lineMetaData = new FlowChartMetaData(0, null, "Line");
                    lineMetaData.Code = "";
                    lineMetaData.AddPreviousMetaData(metaData);
                    metaData.AddNextMetaData(lineMetaData);
                    FlowChartMetaData endMetaData = new FlowChartMetaData(0, null, "EndNode");
                    endMetaData.AddPreviousMetaData(lineMetaData);
                    lineMetaData.AddNextMetaData(endMetaData);
                }
                else // 连接线需要重排序
                {
                    List<GraphElement> lineList = new List<GraphElement>();
                    GraphElement elseLine = null;
                    FlowChartMetaData newMetaData;

                    foreach(GraphElement g in list)
                    {
                        if(dataManager.GetData(g) == null) // else连接线
                        {
                            elseLine = g;
                        }
                        else // 普通连接线
                        {
                            lineList.Add(g);
                        }
                    }

                    metaData.ClearNextMetaDataList();
                    foreach(GraphElement g in lineList)
                    {
                        newMetaData = graphElementTable[g] as FlowChartMetaData;
                        metaData.AddNextMetaData(newMetaData);
                    }
                    newMetaData = graphElementTable[elseLine] as FlowChartMetaData;
                    metaData.AddNextMetaData(newMetaData);
                }
            }
            else
            {
                if(list.Count == 0) // 当前图元没有后续图元
                {
                    FlowChartMetaData lineMetaData = new FlowChartMetaData(0, null, "Line");
                    lineMetaData.AddPreviousMetaData(metaData);
                    metaData.AddNextMetaData(lineMetaData);
                    FlowChartMetaData endMetaData = new FlowChartMetaData(0, null, "EndNode");
                    endMetaData.AddPreviousMetaData(lineMetaData);
                    lineMetaData.AddNextMetaData(endMetaData);
                }
            }                        
        }
Esempio n. 15
0
        /// <summary>
        /// 检查图元是否能够编辑
        /// </summary>
        /// <param name="graphElement">当前图元</param>
        /// <returns>图元是否能够编辑</returns>
        private bool CheckGraphElementEditable(GraphElement graphElement)
        {
            bool result = true;

            if (graphElement is ConnectorContainer)
            {
                ConnectorContainer line = graphElement as ConnectorContainer;
                if (line.InSlotContainer != null && !(line.InSlotContainer is ConditionGraphElement))
                {
                    result = false;
                }
            }

            return result;
        }
Esempio n. 16
0
        /// <summary>
        /// 获取连出的图元链表
        /// </summary>
        /// <param name="graphElement">当前图元</param>
        /// <param name="hasInnerChart">是否处理子绘图</param>
        /// <returns>连出的图元链表</returns>
        public List<GraphElement> GetNextGraphElements(GraphElement graphElement, bool dealInnerChart)
        {
            List<GraphElement> list = new List<GraphElement>();

            if (graphElement is SlotContainer) // 当前图元是插槽容器
            {
                SlotContainer slotContainer = graphElement as SlotContainer;

                foreach (SlotGraphElement slot in slotContainer.GetOutSlotList())
                {
                    if (slot.Binded)
                    {
                        list.Add(slot.BindingConnector.Line);
                    }
                }
            }
            else if (graphElement is ConnectorContainer) // 当前图元是连接线控制点容器
            {
                ConnectorContainer line = graphElement as ConnectorContainer;

                if (line.OutSlotContainer != null)
                {
                    if (dealInnerChart)
                    {
                        SlotContainer slotContainer = line.OutSlotContainer;

                        if (slotContainer is InnerChart)
                        {
                            SlotGraphElement slot = slotContainer.GetBindedInSlot(line);
                            InnerChartEditor innerChartEditor = GetDataElement(slotContainer) as InnerChartEditor;

                            if (slot != null)
                            {
                                InterfaceGraphElement interfaceNode = innerChartEditor.GetInterfaceNode(slot.Tag.ToString());

                                if (interfaceNode != null)
                                {
                                    GraphElement connectedGraphElement = interfaceNode.GetConnectedOutGraphElement();

                                    if (connectedGraphElement != null)
                                    {
                                        list.Add(connectedGraphElement);
                                    }
                                }
                            }
                        }
                        else if (slotContainer is InterfaceGraphElement)
                        {
                            InnerChart innerChart = FindGraphElementByID(int.Parse(slotContainer.Tag as string)) as InnerChart;

                            foreach (SlotGraphElement slot in innerChart.GetOutSlotList())
                            {
                                if (slot.Binded)
                                {
                                    ConnectorContainer connectedLine = slot.BindingConnector.Line;
                                    string lineData = GetData(connectedLine) as string;

                                    if (!string.IsNullOrEmpty(lineData))
                                    {
                                        string[] dataArray = lineData.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                                        if (dataArray[0] == slotContainer.ID.ToString())
                                        {
                                            list.AddRange(GetNextGraphElements(slot.BindingConnector.Line, true));
                                            break;
                                        }
                                    }

                                    /*
                                    if (!string.IsNullOrEmpty(connectedLine.Text))
                                    {
                                        string[] dataArray = connectedLine.Text.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                                        if (dataArray[0] == slotContainer.ID.ToString())
                                        {
                                            list.AddRange(GetNextGraphElements(slot.BindingConnector.Line, true));
                                            break;
                                        }
                                    }
                                    */ 
                                }
                            }

                            /*
                            foreach (SlotGraphElement slot in innerChart.GetOutSlotList())
                            {
                                if (slot.Tag.ToString() == slotContainer.ID.ToString())
                                {
                                    slotGraphElement = slot;
                                    break;
                                }
                            }

                            if (slotGraphElement != null)
                            {
                                if (slotGraphElement.Binded)
                                {
                                    list.AddRange(GetNextGraphElements(slotGraphElement.BindingConnector.Line, true));
                                }
                            }
                            */
                        }
                        else
                        {
                            list.Add(slotContainer);
                        }
                    }
                    else
                    {
                        list.Add(line.OutSlotContainer);
                    }                    
                }
            }            

            return list;
        }
Esempio n. 17
0
        /// <summary>
        /// 检查两个图元是否连接的辅助函数
        /// </summary>
        /// <param name="fromGraphElement">起始图元</param>
        /// <param name="toGraphElement">终结图元</param>
        /// <param name="list">当前遍历过的图元链表</param>
        private void IsConnect(GraphElement fromGraphElement, GraphElement toGraphElement, List<GraphElement> list)
        {
            if (fromGraphElement == toGraphElement)
            {
                list.Add(toGraphElement);
            }
            else
            {
                if (!list.Contains(fromGraphElement))
                {
                    list.Add(fromGraphElement);

                    foreach (GraphElement graphElement in GetNextGraphElements(fromGraphElement, false))
                    {
                        IsConnect(graphElement, toGraphElement, list);
                    }
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// 检查两个图元是否连接
        /// </summary>
        /// <param name="fromGraphElement">起始图元</param>
        /// <param name="toGraphElement">终结图元</param>
        /// <returns>两个图元是否连接</returns>
        public bool IsConnect(GraphElement fromGraphElement, GraphElement toGraphElement)
        {
            List<GraphElement> list = new List<GraphElement>(); // 记录当前遍历过的图元,避免死循环
            IsConnect(fromGraphElement, toGraphElement, list);
            bool result = list.Contains(toGraphElement);

            return result;
        }
Esempio n. 19
0
        /// <summary>
        /// 拖动图元
        /// </summary>
        /// <param name="p">鼠标当前所在点</param>
        /// <param name="moveType">移动类型</param>
        private void DragGraphElement(List<GraphElement> graphElementList, Point p, MoveType moveType)
        {            
            Size moveSize = new Size(p.X - lastSelectedPoint.X, p.Y - lastSelectedPoint.Y);

            // 计算移动方向
            Direction direction = Direction.None;

            if (moveSize.Width > 0)
            {
                direction = Direction.Right;
            }
            else if (moveSize.Width < 0)
            {
                direction = Direction.Left;
            }
            else if (moveSize.Height > 0)
            {
                direction = Direction.Down;
            }
            else if (moveSize.Height < 0)
            {
                direction = Direction.Up;
            }

            if (!CheckMoveLag(direction))
            {
                // 重置鼠标位置
                Cursor.Position = canvas.PointToScreen(lastSelectedPoint) + new Size(canvas.AutoScrollPosition);
                return;
            }

            switch (moveType)
            {
                case MoveType.SingleElement:
                    {
                        GraphElement graphElement = graphElementList[0];

                        graphElement.Move(moveSize); // 移动选中的图元

                        if (graphElement is ConnectorGraphElement) // 当前拖动的图元是连接线控制点
                        {
                            ConnectorGraphElement connector = graphElement as ConnectorGraphElement;
                            bool activated = false; // 是否有插槽被激活

                            if (connector.IsHeadPoint || connector.IsTailPoint) // 当前拖动的连接线控制点是头结点或者尾结点
                            {
                                List<SlotContainer> regionSlotContainerList = regionManager.GetSlotContainerList(connector.Location);

                                foreach (SlotContainer slotContainer in regionSlotContainerList)
                                {
                                    if (activated) // 已经有插槽或插槽容器激活,则直接跳出
                                    {
                                        break;
                                    }

                                    SlotGraphElement slot = slotContainer.GetSlotInRegion(p);

                                    if (slot != null) // 激活当前插槽
                                    {
                                        slot.Activated = true;
                                        activated = true;
                                        lastActivatedGraphElement = slot;
                                        break;
                                    }

                                    if (slotContainer.IsInRegion(p)) // 激活当前插槽容器
                                    {
                                        slotContainer.Activated = true;
                                        activated = true;
                                        lastActivatedGraphElement = slotContainer;
                                        break;
                                    }
                                }
                            }

                            connector.Line.Moving = true;

                            // 自动调整连接线                                
                            connector.Line.AdjustLine(connector);
                        }
                        else if (graphElement is SlotContainer) // 当前拖动的图元是插槽容器
                        {
                            SlotContainer slotContainer = graphElement as SlotContainer;
                            
                            slotContainer.RefreshRelevateLine(false);
                            CreateAdjustLine(slotContainer, direction, true);
                        }
                        else if (graphElement is ResizeControler) // 当前拖动的是缩放控制点
                        {
                            SlotContainer slotContainer = (graphElement as ResizeControler).Owner;
                            CreateAdjustLine(slotContainer, direction, false);
                        }

                        graphElement.Moving = true;

                        break;
                    }
                case MoveType.MultiElement:
                    {                        
                        foreach (GraphElement graphElement in graphElementList)
                        {
                            if (graphElement is ConnectorContainer) // 当前图元是连接线控制点容器
                            {
                                ConnectorContainer line = graphElement as ConnectorContainer;
                                line.Visible = false;

                                foreach (ConnectorGraphElement connector in line.GetConnectorList()) // 移动连接线控制点
                                {
                                    if (!connector.Binded) // 连接线控制点不是连接线的头结点和尾结点
                                    {
                                        connector.Move(moveSize);
                                    }
                                    else
                                    {
                                        SlotGraphElement slot = connector.GetBindingSlot();

                                        if (slot != null)
                                        {
                                            SlotContainer slotContainer = slot.SlotContainer;

                                            if (!graphElementList.Contains(slotContainer))
                                            {
                                                FlowChartDisconnectCommand cmd = new FlowChartDisconnectCommand(this, "解除连接图元");
                                                InitFirstCommand(cmd);

                                                if (cmd.Execute(slot)) // 命令执行成功
                                                {
                                                    AdjustCommandList(cmd);
                                                }

                                                slot.Move(moveSize);
                                            }
                                        }                                        
                                    }
                                }
                            }
                            else if (graphElement is SlotContainer) // 当前图元是插槽容器
                            {
                                SlotContainer slotContainer = graphElement as SlotContainer;
                                
                                slotContainer.RefreshRelevateLine(false);
                                graphElement.Move(moveSize);
                            }
                            else // 非连接线控制点容器的图元直接移动即可
                            {
                                graphElement.Move(moveSize);
                            }

                            graphElement.Moving = true;
                        }

                        canvas.CurrentMultiSelectMark.Move(moveSize);

                        break;
                    }
            }
        }       
Esempio n. 20
0
 /// <summary>
 /// 编辑数据元
 /// </summary>
 /// <param name="graphElement">索引的数据元</param>
 /// <return>是否编辑成功</return>
 public bool EditDataElement(GraphElement graphElement)
 {            
     bool result = dataManager.EditData(graphElement);
     return result;
 }
Esempio n. 21
0
        /// <summary>
        /// 选中并记录图元
        /// </summary>
        /// <param name="graphElement">图元</param>
        /// <param name="p">鼠标当前所在点</param>
        private void SelectGraphElement(GraphElement graphElement, Point p)
        {
            graphElement.Selected = true;
            selectedGraphElement = graphElement;
            lastSelectedGraphElement = graphElement;
            moveOffset.Width = p.X - graphElement.Location.X;
            moveOffset.Height = p.Y - graphElement.Location.Y;            
            documentManager.ShowObjectProperty(graphElement);

            // 创建Move命令,保存当前状态
            moveCommand = new FlowChartMoveCommand(this, "移动图元");

            if (commandIndex == -1) // 检查是否是第一条命令
            {
                moveCommand.FirstCommand = true;
                moveCommand.SaveCurrentState(p);
            }            
        }
Esempio n. 22
0
        /// <summary>
        /// 重命名图元
        /// </summary>
        /// <param name="graphElement">数据管理器</param>
        /// <param name="graphElement">图元</param>
        private void RenameGraphElement(DataManager dataManager, GraphElement graphElement)
        {
            object data = dataManager.GetCompileData(graphElement);

            if (graphElement is AIStateGraphElement) // 自动为状态结点重命名
            {
                AI_State aiState = data as AI_State;

                if (aiState != null)
                {
                    aiState.Ename = string.Format("State{0}", graphElement.ID.ToString());
                }
            }
            else if (graphElement is AIActionGraphElement) // 自动为自定义脚本的动作结点重命名
            {
                AI_SingleAction singleAction = data as AI_SingleAction;

                if (singleAction != null)
                {
                    string newName = string.Format("CustomAction{0}", graphElement.ID.ToString());
                    int actionID = 2000 + graphElement.ID;
                    RenameAIAction(singleAction.Action, newName, actionID);
                }
            }
            else if (graphElement is AIActionsGraphElement) // 自动为动作组中自定义脚本的动作结点重命名
            {                
                AI_MultiAction multiAction = data as AI_MultiAction;

                if (multiAction != null)
                {
                    int actionIndex = 0;
                    List<AI_SingleAction> aiActionList = multiAction.ActionList;

                    foreach (AI_SingleAction singleAction in aiActionList)
                    {
                        string newName = string.Format("CustomAction{0}_{1}", graphElement.ID.ToString(),
                                                        actionIndex.ToString());
                        int actionID = (2000 + graphElement.ID) * 10 + actionIndex;
                        RenameAIAction(singleAction.Action, newName, actionID);
                        actionIndex++;
                    }
                }
            } 
        }
Esempio n. 23
0
        /// <summary>
        /// 检查是否图元被选中
        /// </summary>
        /// <param name="p">鼠标当前所在点</param>
        public void CheckGraphElementSelected(Point point)
        {
            Point p = AdjustMouseLocation(point);
            RecordLastSelectedPoint(p);          
  
            selectedGraphElement = null;
            ConnectorContainer newLine = null; // 自动新建的连接线
            bool selected = false; // 是否已经有图元被选中
            GraphElement graphElement = null; // 当前图元

            if (lastSelectedGraphElement != null) // 将上一个被选中的图元置为非选中状态
            {
                if (!selectedGraphElementList.Contains(lastSelectedGraphElement)) // 在多选状态需要检查上一个被选中的图元是否在多选容器中
                {
                    lastSelectedGraphElement.Selected = false;
                }
            }

            if (lastResizingGraphElement != null) // 将上一个缩放的插槽容器置为非缩放状态
            {
                lastResizingGraphElement.Resizing = false;
            }

            // 检查游标是否被选中
            if (canvas.CurrentRodman.IsInRegion(p))
            {
                InitMoveGraphElementList();
                graphElement = canvas.CurrentRodman;
                selected = true;
            }

            // 索引检查是否有连接线控制点容器被选中
            foreach (ConnectorContainer connectorContainer in regionManager.GetConnectorContainerList(p))
            {
                if (selected) // 已经有图元被选中时自动跳出循环
                {
                    break;
                }

                // 先遍历检查是否有连接线控制点被选中
                ConnectorGraphElement connector = connectorContainer.GetConnectorInRegion(p);

                if (connector != null)
                {
                    graphElement = connector;
                    selected = true;
                    break;
                }

                if (connectorContainer.IsInRegion(p)) // 连接线被选中
                {
                    graphElement = connectorContainer;
                    selected = true;
                    break;
                }
            }

            foreach (SlotContainer slotContainer in regionManager.GetSlotContainerList(p)) // 索引检查是否有插槽容器被选中
            {
                if (selected) // 如果有图元被选中的话则自动跳出循环
                {
                    break;
                }

                // 检查是否有缩放控制点被选中
                ResizeControler resizeControler = slotContainer.GetResizeControlerInRegion(p);
                
                if (resizeControler != null)
                {
                    graphElement = resizeControler;
                    selected = true;
                    slotContainer.Resizing = true;
                    lastResizingGraphElement = slotContainer;
                    ChangeMouseCursur(resizeControler.CurrentDirection); // 改变鼠标指针形状
                    break;
                }
                
                // 检查是否有按钮被选中
                BaseButton baseButton = slotContainer.GetButtonInRegion(p);

                if (baseButton != null)
                {
                    if (baseButton is ConnectButton) // 是连接按钮
                    {
                        SlotGraphElement slot = (baseButton as ConnectButton).BindingSlot;

                        if (!slot.Binded && slot.IsOutSlot) // 插槽没有绑定连接线控制点,则新建连接线并绑定到当前插槽上
                        {
                            FlowChartCreateLineCommand cmd = new FlowChartCreateLineCommand(this, "创建图元");
                            InitFirstCommand(cmd);

                            if (cmd.Execute(new object[] { slot, p }))
                            {
                                AdjustCommandList(cmd);
                                newLine = selectedGraphElement as ConnectorContainer;
                                ConnectorGraphElement connector = newLine.GetConnectorList()[1];
                                graphElement = connector;
                                selected = true;
                            }

                            break;
                        }
                    }
                    else if (baseButton is AddButton) // 是添加按钮
                    {
                        SlotGraphElement slot = slotContainer.AddOutSlot();
                        graphElement = slotContainer;
                        selected = true;
                        break;
                    }
                }

                // 检查是否有注释图元被选中
                if (slotContainer.RemarkNode != null)
                {
                    if (slotContainer.RemarkNode.IsInRegion(p))
                    {
                        graphElement = slotContainer.RemarkNode;
                        selected = true;
                        break;
                    }
                }
                
                if (slotContainer.IsInRegion(p))
                {
                    SlotGraphElement slot = slotContainer.GetSlotInRegion(p);

                    if (slot != null)
                    {
                        graphElement = slot;
                        selected = true;
                        break;
                    }

                    slotContainer.Resizing = true;
                    lastResizingGraphElement = slotContainer;
                    graphElement = slotContainer;
                    selected = true;
                    break;
                }
            }

            if (selected) // 已经有图元被选中
            {
                SelectGraphElement(graphElement, p);
                userOperation = UserOperation.SingleSelect;

                if (selectedGraphElementList.Contains(selectedGraphElement)) // 进行多图元操作
                {
                    if (controlMode) // 在control模式下需要反选图元
                    {
                        selectedGraphElementList.Remove(selectedGraphElement);
                        selectedGraphElement.Selected = false;
                        selectedGraphElement = null;
                        lastSelectedGraphElement = null;
                        userOperation = UserOperation.None;

                        if (selectedGraphElementList.Count == 0)
                        {
                            canvas.CurrentMultiSelectMark.Visible = false;
                        }
                        else
                        {
                            CreateMultiSelectRegion();
                        }
                    }
                    else
                    {
                        userOperation = UserOperation.MultiSelect;
                    }
                }
                else
                {
                    if (controlMode) // 在control模式下需要加入图元
                    {
                        selectedGraphElementList.Add(selectedGraphElement);
                        CreateMultiSelectRegion();

                        userOperation = UserOperation.MultiSelect;
                    }
                    else
                    {
                        if (graphElement is Rodman)
                        {
                            userOperation = UserOperation.MoveRodman;
                            CreateMultiMoveRegion();
                        }

                        // 清空多选图元链表
                        ClearSelectedGraphElementList();
                    }
                }
            }
            else // 没有图元被选中
            {
                userOperation = UserOperation.RegionSelect;

                // 显示背景属性                
                documentManager.ShowObjectProperty(background);
                multiSelectStartPoint = p;

                // 清空多选图元链表
                ClearSelectedGraphElementList();
            }            

            RefreshCanvas();
        }
Esempio n. 24
0
        /// <summary>
        /// 获取下一个绘图元数据
        /// </summary>
        /// <param name="dataManager">数据管理器</param>
        /// <param name="graphElement">当前图元</param>
        /// <param name="metaData">绘图元数据</param>
        /// <param name="graphElementList">遍历过的图元链表</param>
        /// <param name="graphElementTable">流程图索引哈希表</param>
        /// <param name="actionsTable">动作组数据哈希表</param>
        private void FindNextMetaData(DataManager dataManager, GraphElement graphElement, FlowChartMetaData metaData, List<GraphElement> graphElementList, Hashtable graphElementTable, Hashtable actionsTable)
        {
            graphElementList.Add(graphElement);
            graphElementTable[graphElement] = metaData;
            List<GraphElement> list = dataManager.GetNextGraphElements(graphElement, true);

            foreach (GraphElement g in list)
            {
                object data = dataManager.GetCompileData(g);
                DataElement dataElement =  dataManager.GetCompileDataElement(g);

                if (!graphElementList.Contains(g))
                {                    
                    FlowChartMetaData newMetaData = new FlowChartMetaData(g.ID, data, dataElement.DataType);
                    newMetaData.DisplayText = g.Text;                    
                    
                    if (g is AIStateGraphElement) // 状态
                    {
                        string stateNodeName = CodeProviderClass.GetStateString(data);
                        newMetaData.Code = stateNodeName;

                        InitSetStateMetaData(metaData, newMetaData);
                        FindNextMetaData(dataManager, g, newMetaData, graphElementList, graphElementTable, actionsTable);
                    }
                    else if (g is AILineGraphElement) // 连接线
                    {
                        newMetaData.Code = CodeProviderClass.GetEventString(data);

                        newMetaData.AddPreviousMetaData(metaData);
                        metaData.AddNextMetaData(newMetaData);
                        FindNextMetaData(dataManager, g, newMetaData, graphElementList, graphElementTable, actionsTable);                        
                    }
                    else if (g is AIActionGraphElement) // 动作
                    {
                        newMetaData.AddPreviousMetaData(metaData);
                        metaData.AddNextMetaData(newMetaData);
                        FindNextMetaData(dataManager, g, newMetaData, graphElementList, graphElementTable, actionsTable);
                    }
                    else if (g is AIActionsGraphElement) // 动作组
                    {                    
                        List<FlowChartMetaData> metaDataList = actionsTable[g] as List<FlowChartMetaData>;

                        metaDataList[0].AddPreviousMetaData(metaData);
                        metaData.AddNextMetaData(metaDataList[0]);

                        FindNextMetaData(dataManager, g, metaDataList[metaDataList.Count - 1], graphElementList, graphElementTable, actionsTable);
                    }
                }
                else
                {
                    if (g is AIActionsGraphElement) // 动作组要特殊处理
                    {
                        List<FlowChartMetaData> metaDataList = actionsTable[g] as List<FlowChartMetaData>;
                        metaDataList[0].AddPreviousMetaData(metaData);
                        metaData.AddNextMetaData(metaDataList[0]);
                    }
                    else if (g is AIStateGraphElement) // 状态结点要特殊处理
                    {
                        FlowChartMetaData newMetaData = graphElementTable[g] as FlowChartMetaData;

                        InitSetStateMetaData(metaData, newMetaData);
                    }
                    else
                    {
                        FlowChartMetaData newMetaData = graphElementTable[g] as FlowChartMetaData;
                        newMetaData.AddPreviousMetaData(metaData);
                        metaData.AddNextMetaData(newMetaData);
                    }                    
                }
            }                      
        }
Esempio n. 25
0
        /// <summary>
        /// 剪切图元
        /// </summary>
        public void CutGraphElement()
        {
            // 将当前图元从所在区域清除
            if (selectedGraphElementList.Count > 0) // 剪切多个图元
            {
                foreach (GraphElement graphElement in selectedGraphElementList)
                {                    
                    regionManager.DeleteFromRegion(graphElement);
                }                
            }
            else if (selectedGraphElement != null) // 剪切单个图元
            {
                regionManager.DeleteFromRegion(selectedGraphElement);
            }

            FlowChartCutCommand cmd = new FlowChartCutCommand(this, "剪切图元");
            InitFirstCommand(cmd);

            if (cmd.Execute(null)) // 命令执行成功
            {
                AdjustCommandList(cmd);
                
                if (selectedGraphElementList.Count > 0) // 剪切多个图元
                {
                    selectedGraphElementList.Clear();
                    canvas.CurrentMultiSelectMark.Visible = false;
                }
                else if (selectedGraphElement != null) // 剪切单个图元
                {
                    selectedGraphElement = null;
                }

                ReconstructCanvasGraphElementList();
            }
        }
Esempio n. 26
0
        /// <summary>
        /// 获取下一个图元数据
        /// </summary>
        /// <param name="dataManager">数据管理器</param>
        /// <param name="graphElement">当前图元</param>
        /// <param name="metaData">图元数据</param>
        /// <param name="graphElementList">遍历过的图元链表</param>
        /// <param name="graphElementTable">绘图索引哈希表</param>
        private void FindNextMetaData(DataManager dataManager, GraphElement graphElement, FlowChartMetaData metaData, List<GraphElement> graphElementList, Hashtable graphElementTable)
        {
            graphElementList.Add(graphElement);
            graphElementTable[graphElement] = metaData;
            List<GraphElement> list = dataManager.GetNextGraphElements(graphElement, false);

            foreach (GraphElement g in list)
            {
                object data = dataManager.GetData(g);

                if (!graphElementList.Contains(g))
                {
                    DataElement dataElement = dataManager.GetDataElement(g);
                    FlowChartMetaData newMetaData = new FlowChartMetaData(g.ID, data, dataElement.DataType);
                    newMetaData.DisplayText = g.TooltipText;
                    newMetaData.AddPreviousMetaData(metaData);
                    metaData.AddNextMetaData(newMetaData);
                    FindNextMetaData(dataManager, g, newMetaData, graphElementList, graphElementTable);
                }
                else
                {
                    FlowChartMetaData newMetaData = graphElementTable[g] as FlowChartMetaData;
                    newMetaData.AddPreviousMetaData(metaData);
                    metaData.AddNextMetaData(newMetaData);
                }
            }
        }
Esempio n. 27
0
        /// <summary>
        /// 编辑图元
        /// </summary>
        /// <param name="graphElement">当前图元</param>
        public void EditDataElement(GraphElement graphElement)
        {
            FlowChartEditCommand cmd = new FlowChartEditCommand(this, "编辑数据元");
            InitFirstCommand(cmd);

            if (cmd.Execute(graphElement)) // 命令执行成功
            {
                AdjustCommandList(cmd);
                regionManager.ChangeRegion(selectedGraphElement);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// 删除图元
        /// </summary>
        /// <param name="graphElement">要删除的图元</param>
        /// <return>是否删除成功</return>
        protected bool DeleteGraphElement(GraphElement graphElement)
        {
            GraphManager graphManager = data as GraphManager;
            DataManager dataManager = graphManager.CurrentFlowChartManager.CurrentDataManager;
            List<GraphElement> list = new List<GraphElement>(); // 记录遍历过图元的链表
            bool deleteSuccess = false; // 是否删除成功

            if (graphElement is SlotContainer) // 要删除的图元是插槽容器
            {
                SlotContainer slotContainer = graphElement as SlotContainer;
                ReBindEventNode(list, slotContainer, null, false); // 重新设定事件结点及图元是否可用

                foreach (SlotGraphElement slot in slotContainer.GetSlotList())
                {
                    if (slot.Binded) // 解除绑定连接线控制点
                    {
                        if (slot.IsOutSlot && slotContainer is ConditionGraphElement) // 对条件结点连出的线要进行有效性检查
                        {
                            ConnectorContainer line = slot.BindingConnector.Line;
                            if (line.Text == "×")
                            {
                                line.Invalid = false;
                                line.ShowText = false;
                            }
                        }
                        slot.UnBind();
                    }
                }

                graphManager.SlotContainerList.Remove(slotContainer); // 从插槽容器索引链表中删除
                deleteSuccess = true;
            }
            else if (graphElement is ConnectorContainer) // 要删除的图元是连接线控制点容器
            {
                ConnectorContainer connectorContainer = graphElement as ConnectorContainer;

                SlotContainer inSlotContainer = connectorContainer.InSlotContainer;
                if (inSlotContainer != null)
                {
                    connectorContainer.UnbindInSlotContainer();
                }

                ReBindEventNode(list, connectorContainer, null, false); // 重新设定事件结点及图元是否可用

                SlotContainer outSlotContainer = connectorContainer.OutSlotContainer;
                if (outSlotContainer != null)
                {
                    connectorContainer.UnbindOutSlotContainer();
                }

                if (inSlotContainer is ConditionGraphElement) // 对条件结点连出的线要进行有效性检查
                {
                    dataManager.CheckLineValid(inSlotContainer);
                }

                graphManager.ConnectorContainerList.Remove(connectorContainer); // 从连接线控制点索引容器中删除
                deleteSuccess = true;
            }
            else if (graphElement is ConnectorGraphElement) // 要删除的图元是连接线控制点
            {
                ConnectorGraphElement connector = graphElement as ConnectorGraphElement;
                if (connector.IsHeadPoint || connector.IsTailPoint) // 不允许删除头结点和尾结点
                {
                    MessageBox.Show("不能删除头连接线控制点和尾连接线控制点!", "图元删除", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    connector.Line.RemoveConnector(connector);
                    deleteSuccess = true;
                }
            }
            else if (graphElement is SlotGraphElement) // 要删除的图元是插槽
            {
                SlotGraphElement slot = graphElement as SlotGraphElement;

                if (slot.CanDelete && (slot.IsInSlot || slot.SlotContainer.OutSlotCount > 1)) // 插槽可以删除
                {
                    SlotContainer slotContainer = slot.SlotContainer;
                    slotContainer.RemoveSlot(slot);                    
                    deleteSuccess = true;
                }
                else
                {
                    MessageBox.Show("该插槽不能删除", "图元删除", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (graphElement is RemarkGraphElement) // 要删除的图元是注释结点
            {
                RemarkGraphElement remarkGraphElement = graphElement as RemarkGraphElement;
                SlotContainer slotContainer = remarkGraphElement.Owner as SlotContainer;

                slotContainer.RemarkNode = null;
                remarkGraphElement.Owner = null;
                remarkGraphElement = null;
                deleteSuccess = true;
            }

            if (deleteSuccess) // 释放图元所占的资源
            {
                dataManager.DeleteData(graphElement);
                graphElement.Release();
            }

            return deleteSuccess;
        }
Esempio n. 29
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void Init(GraphElement graphElement, Point mouseLocation)
        {
            // 计算图元区域
            if (graphElement is SlotContainer)
            {
                SlotContainer slotContainer = graphElement as SlotContainer;
                graphElementRectangle = slotContainer.TextRectangle;
            }
            else if (graphElement is ConnectorContainer)
            {
                graphElementRectangle.Location = mouseLocation;
                graphElementRectangle.Size = graphElementInterval;
            }
            else
            {
                graphElementRectangle.Location = graphElement.Location;
                graphElementRectangle.Size = graphElement.ElementSize + graphElementInterval;
            }

            // 计算文字大小
            lineList.Clear();
            formatList.Clear();

            elementSize = Size.Empty;
            string[] lines = text.Split(lineSpliter, StringSplitOptions.RemoveEmptyEntries);
            Graphics g = Helper.GetHelper().GraphicsObject;
            
            textSize.Height = lines.Length * charWidth;
            int currentWidth = 0;            
            SizeF textSizeF;
            string displayLine;

            foreach (string line in lines)
            {                
                if (line.StartsWith(boldStyleString))
                {
                    displayLine = line.Replace(boldStyleString, "");
                    textSizeF = g.MeasureString(displayLine, graphSetting.GraphElementTextBoldFont);
                    currentWidth = (int)textSizeF.Width + 1;
                    
                    lineList.Add(displayLine);
                    formatList.Add(TipFormat.Bold);
                }
                else if (line.StartsWith(italicStyleString))
                {
                    displayLine = line.Replace(italicStyleString, "");
                    textSizeF = g.MeasureString(displayLine, graphSetting.GraphElementTextItalicFont);
                    currentWidth = (int)textSizeF.Width + 1;
                    
                    lineList.Add(displayLine);
                    formatList.Add(TipFormat.UnderLine);
                }
                else if (line.StartsWith(splitStyleString))
                {
                    currentWidth = 0;

                    displayLine = line.Replace(splitStyleString, "");
                    lineList.Add(displayLine);
                    formatList.Add(TipFormat.Split);
                }
                else
                {
                    displayLine = line;
                    textSizeF = g.MeasureString(displayLine, graphSetting.GraphElementTextFont);
                    currentWidth = (int)textSizeF.Width + 1;
                    
                    lineList.Add(displayLine);
                    formatList.Add(TipFormat.Normal);
                }

                if (currentWidth > textSize.Width)
                {
                    textSize.Width = currentWidth;
                }
            }

            elementSize.Width = textSize.Width + textInterval * 2;
            elementSize.Height = textSize.Height + textInterval * 2;

            // 计算文字位置
            if (graphElementRectangle.Right + elementSize.Width > visibleRectangle.Right)
            {
                location.X = graphElementRectangle.Left - elementSize.Width - tipInterval;
                location.Y = graphElementRectangle.Top;
            }
            else
            {
                location.X = graphElementRectangle.Right + tipInterval;
                location.Y = graphElementRectangle.Top;
            }

            textLocation.X = location.X + textInterval;
            textLocation.Y = location.Y + textInterval;
        }
Esempio n. 30
0
        /// <summary>
        /// 设置图元是否可用
        /// </summary>
        /// <param name="list">遍历过的图元链表</param>
        /// <param name="graphElement">当前图元</param>
        /// <param name="eventNode">事件结点</param>
        /// <param name="enable">图元是否可用</param>
        protected virtual void ReBindEventNode(List<GraphElement> list, GraphElement graphElement, EventGraphElement eventNode, bool enable)
        {
            if(!list.Contains(graphElement)) // 还没有遍历过当前图元
            {
                GraphManager graphManager = data as GraphManager;
                DataManager dataManager = graphManager.CurrentFlowChartManager.CurrentDataManager;               

                if(graphElement is SlotContainer) // 该图元是插槽容器
                {
                    SlotContainer slotContainer = graphElement as SlotContainer;

                    if(!enable && slotContainer.EventNode != null && dataManager.IsConnect(slotContainer.EventNode, slotContainer)) // 不需要更新当前图元的事件结点
                    {

                    }
                    else
                    {
                        list.Add(slotContainer);
                        slotContainer.Enable = enable;
                        slotContainer.EventNode = eventNode;

                        foreach (GraphElement g in dataManager.GetNextGraphElements(graphElement))
                        {
                            ReBindEventNode(list, g, eventNode, enable);
                        }
                    }
                }
                else if(graphElement is ConnectorContainer) // 该图元是连接线控制点容器
                {
                    ConnectorContainer line = graphElement as ConnectorContainer;

                    if(!enable && line.EventNode != null && dataManager.IsConnect(line.EventNode, line)) // 不需要更新当前图元的事件结点
                    {                            
                        
                    } 
                    else
                    {
                        list.Add(line);
                        line.Enable = enable;
                        line.EventNode = eventNode;

                        foreach (GraphElement g in dataManager.GetNextGraphElements(graphElement))
                        {
                            ReBindEventNode(list, g, eventNode, enable);
                        }
                    }
                }                
            }
        }