/// <summary> /// 编辑图元 /// </summary> public void EditDataElement() { if (selectedGraphElement != null) // 有选中的图元 { if (selectedGraphElement.Enable) // 选中的图元可以编辑 { if (selectedGraphElement is RemarkGraphElement) // 编辑注释 { FlowChartEditRemarkCommand cmd = new FlowChartEditRemarkCommand(this, "编辑元注释"); InitFirstCommand(cmd); if (cmd.Execute((selectedGraphElement as RemarkGraphElement).Owner)) // 命令执行成功 { AdjustCommandList(cmd); } } else // 编辑图元 { FlowChartEditCommand cmd = new FlowChartEditCommand(this, "编辑图元"); InitFirstCommand(cmd); if (cmd.Execute(selectedGraphElement)) // 命令执行成功 { AdjustCommandList(cmd); regionManager.ChangeRegion(selectedGraphElement); } } } else { MessageBox.Show("当前图元数据无效,请检查是否连接正确!", "图元编辑", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// <summary> /// 自动连接图元 /// </summary> /// <param name="previousContainer">连出的插槽容器</param> /// <param name="currentContainer">连入的插槽容器</param> private void ConnectGraphElement(SlotContainer previousContainer, SlotContainer currentContainer) { SlotGraphElement outSlot = previousContainer.GetOutSlot(); SlotGraphElement inSlot = currentContainer.GetInSlot(); if(outSlot != null && inSlot != null) // 可能有些结点不能分配出新插槽 { FlowChartCreateAndConnectLineCommand cmd = new FlowChartCreateAndConnectLineCommand(this, "创建并连接图元"); InitFirstCommand(cmd); if (cmd.Execute(new object[] { outSlot, inSlot })) // 命令执行成功 { AdjustCommandList(cmd); ConnectorContainer line = selectedGraphElement as ConnectorContainer; regionManager.AddToRegion(line); // 调整图元所在区域 // 自动调整连接线 AdjustLine(line, currentContainer); if (previousContainer is ConditionGraphElement) // 编辑条件结点连出的连接线 { FlowChartEditCommand editCommand = new FlowChartEditCommand(this, "编辑图元"); if (editCommand.Execute(line)) { AdjustCommandList(editCommand); } } } } autoConnect = false; }
/// <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); } }
/// <summary> /// 创建图元 /// </summary> public void CreateGraphElement() { Point p = canvas.AbbreviatGraphElement.Location; FlowChartCreateCommand cmd = new FlowChartCreateCommand(this, "新建图元"); InitFirstCommand(cmd); if (cmd.Execute(new object[] { p, canvas.AbbreviatGraphElement.TypeString })) // 命令执行成功 { AdjustCommandList(cmd); // 自动调整连接线 AdjustLine(selectedGraphElement as SlotContainer); GraphElement graphElement = selectedGraphElement; if (autoConnect) { ConnectGraphElement(lastConnectGraphElement as SlotContainer, selectedGraphElement as SlotContainer); } if (lastSelectedGraphElement != null) // 将上一个被选中的图元置为非选中状态 { if (!selectedGraphElementList.Contains(lastSelectedGraphElement)) // 在多选状态需要检查上一个被选中的图元是否在多选容器中 { lastSelectedGraphElement.Selected = false; } } SelectGraphElement(graphElement, p); // 选中新建的图元 // 编辑新建的图元 FlowChartEditCommand editCommand = new FlowChartEditCommand(this, "编辑图元"); InitFirstCommand(editCommand); if (editCommand.Execute(graphElement)) // 命令执行成功 { AdjustCommandList(editCommand); } regionManager.AddToRegion(graphElement); // 调整图元所在区域 } }