Esempio n. 1
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);
        }