/// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="o">命令的参数</param>
        /// <returns>是否执行成功</returns>
        public override bool Execute(object o)
        {
            bool          success       = false;
            SlotContainer slotContainer = o as SlotContainer;
            string        remark        = "";

            try
            {
                Assembly    assembly    = Assembly.LoadFrom("Plugins\\FlowChart\\TextEditor.dll");
                DataElement dataElement = assembly.CreateInstance("TextEditor.TextEditor") as DataElement;
                Hashtable   table       = new Hashtable();
                table["data"] = slotContainer.Remark;
                if (dataElement.EditData(table))
                {
                    success = true;
                    remark  = dataElement.Data as string;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("在编辑图元注释时产生异常: " + ex.ToString(), "注释编辑", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }

            // 创建注释结点
            if (success)
            {
                // 保存执行前的数据
                description = "编辑图元注释 " + slotContainer.Name;
                if (firstCommand) // 只有第一条命令保存执行前的数据
                {
                    SaveBeforeExecute(flowChartManager.GetArguments());
                }

                slotContainer.Remark = remark;
                RemarkGraphElement remarkGraphElement;
                if (slotContainer.RemarkNode == null) // 需要创建注释结点
                {
                    remarkGraphElement = new RemarkGraphElement(slotContainer, slotContainer.Location + new Size(slotContainer.ElementSize.Width + 50, 0),
                                                                new Size(1, 1));
                    remarkGraphElement.Text   = remark;
                    remarkGraphElement.Name   = "注释结点";
                    remarkGraphElement.Enable = true;
                    remarkGraphElement.Refresh();
                    remarkGraphElement.AdjustElementSize();
                    remarkGraphElement.AdjustLine();
                    slotContainer.RemarkNode = remarkGraphElement;
                    slotContainer.ShowRemark = true;
                }
                else
                {
                    remarkGraphElement      = slotContainer.RemarkNode;
                    remarkGraphElement.Text = remark;
                    remarkGraphElement.AdjustElementSize();
                }

                // 保存执行后的数据
                flowChartManager.ContentChanged = true;
                SaveAfterExecute(flowChartManager.GetArguments());
            }

            return(success);
        }
Beispiel #2
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);
        }