Esempio n. 1
0
        /// <summary>
        /// 连接图元
        /// </summary>
        /// <param name="flowChartManager">绘图管理器</param>
        /// <param name="logicData">逻辑数据</param>
        /// <returns>是否操作成功</returns>
        protected virtual bool LogicConnect(FlowChartManager flowChartManager, object logicData)
        {
            object[]              data      = logicData as object[];
            SlotGraphElement      slot      = data[0] as SlotGraphElement;
            ConnectorGraphElement connector = data[1] as ConnectorGraphElement;
            ConnectorContainer    line      = connector.Line;

            if ((line.InSlotContainer != null && line.OutSlotContainer != null) || connector.Selected) // 连接线控制点处于被选中状态
            {
                flowChartManager.CurrentGraphManager.EditDataElement(line);
            }

            return(true);
        }
Esempio n. 2
0
 public ConnectEventArgs(SlotGraphElement slot, ConnectorGraphElement connector)
 {
     this.slot = slot;
     this.connector = connector;
 }
Esempio n. 3
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. 4
0
        /// <summary>
        /// 绘制图元自身
        /// </summary>
        /// <param name="g">图形对象</param>
        public override void Paint(Graphics g)
        {
            // 绘制边框色
            Pen framePen;
            Pen frameArrawPen;

            //Pen shadowPen;
            //Pen shadowArrawPen;
            //Color shadowColor;

            if (activated) // 当前图元被激活
            {
                framePen      = new Pen(activatedColor, 1);
                frameArrawPen = new Pen(activatedColor, 1);
                //shadowColor = Color.FromArgb(127, activatedColor);
                //shadowPen = new Pen(shadowColor, 2);
                //shadowArrawPen = new Pen(shadowColor, 2);
            }
            else if (selected) // 当前图元被选中
            {
                framePen      = new Pen(selectedColor, 1);
                frameArrawPen = new Pen(SelectedColor, 1);
                //shadowColor = Color.FromArgb(127, selectedColor);
                //shadowPen = new Pen(shadowColor, 2);
                //shadowArrawPen = new Pen(shadowColor, 2);
            }
            else // 当前图元没有被选中和激活
            {
                if (enable) // 图元的数据有效
                {
                    framePen      = new Pen(frameColor, 1);
                    frameArrawPen = new Pen(frameColor, 1);
                }
                else
                {
                    framePen      = new Pen(disableColor, 1);
                    frameArrawPen = new Pen(disableColor, 1);
                }
                // shadowColor = Color.FromArgb(127, frameColor);
                // shadowPen = new Pen(shadowColor, 2);
                // shadowArrawPen = new Pen(shadowColor, 2);
            }

            frameArrawPen.CustomEndCap = new AdjustableArrowCap((float)(frameArrawPen.Width * 3), (float)(frameArrawPen.Width * 4), true);
            frameArrawPen.DashStyle    = DashStyle.Dash;
            framePen.DashStyle         = DashStyle.Dash;
            // shadowArrawPen.CustomEndCap = new AdjustableArrowCap((float)(shadowArrawPen.Width * 3), (float)(shadowArrawPen.Width * 4), true);

            int index = 0;
            ConnectorGraphElement head;
            ConnectorGraphElement tail;
            Size shadowSize = new Size(2, 0);

            while (index + 1 < connectorList.Count)
            {
                head = connectorList[index];
                tail = connectorList[index + 1];

                if (index + 1 == connectorList.Count - 1) // 绘制带箭头的尾线
                {
                    g.DrawLine(frameArrawPen, head.Location, tail.Location);
                    // g.DrawLine(shadowArrawPen, head.Location + shadowSize, tail.Location + shadowSize); // 绘制阴影
                }
                else // 绘制不带箭头的线
                {
                    g.DrawLine(framePen, head.Location, tail.Location);
                    // g.DrawLine(shadowPen, head.Location + shadowSize, tail.Location + shadowSize); // 绘制阴影
                }

                index++;
            }

            // 绘制连接点
            foreach (ConnectorGraphElement c in connectorList)
            {
                c.Paint(g);
            }

            // 绘制文本
            if (showText)
            {
                int textX;
                int textY;

                if (connectorList.Count == 2) // 容器只有两个连接线控制点
                {
                    ConnectorGraphElement connector1 = connectorList[0];
                    ConnectorGraphElement connector2 = connectorList[1];
                    textX = (int)((connector1.Location.X + connector2.Location.X) / 2 + 10);
                    textY = (int)((connector1.Location.Y + connector2.Location.Y) / 2 + 10);
                }
                else
                {
                    ConnectorGraphElement connector = connectorList[1];
                    textX = connector.Location.X + 10;
                    textY = connector.Location.Y;
                }

                Brush textBrush = new SolidBrush(textColor);
                g.DrawString(text, textFont, textBrush, textX, textY);
            }
        }
Esempio n. 5
0
 public ConnectEventArgs(SlotGraphElement slot, ConnectorGraphElement connector)
 {
     this.slot      = slot;
     this.connector = connector;
 }