Exemplo n.º 1
0
        /// <summary>
        /// 鼠标键抬起时执行该函数.
        /// 由于连线可以拖动来画,所以鼠标抬起时表示可以画一条连线.
        /// 由于连线的折点可以改变位置,所以鼠标抬起时也可能是折点位置修改好了。
        /// 切换工具的工作模式, 然后判断橡皮圈是否圈选了某些节点,如果是,就把它们添加到SelectedItems中。
        /// </summary>
        /// <param name="e"></param>
        private void WorkPlace_MouseUp(object sender, MouseEventArgs e)
        {
            if (ToolModel == true)                              //工具模式下
            {
                if (this.Module == 0 && _isDrawingLine == true) //画线,终止点
                {
                    Point point = new Point(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);
                    foreach (BaseComponent c in TaskItems)
                    {
                        if (c.Contains(point))
                        {
                            _endTask = c;
                            if (_endTask != _startTask)
                            {
                                var l = new Link(_startTask, _endTask)
                                {
                                    flowGuid = this.WorkFlowId
                                };
                                LineItems.Add(l);
                                IsModify = true;
                                //添加Undo操作用的

                                //	his.OperationLineItem.Add(l);
                            }
                            this._isDrawingLine = false;
                            break;
                        }
                        else
                        {
                            _endTask            = null;
                            this._isDrawingLine = false;
                        }
                    }
                    this.Invalidate();
                }
                ToolModel = LockModel; //是否锁定,画多个任务节点
            }
            Point p = new Point(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);

            //折线
            if (this.SelectedLine.Count > 0 && this.CanEdit)
            {
                if (this.SelectedLine.Count > 0)
                {
                    //oldBreakPoint.Add(link.breakPoint);
                    if (this._isZhexian)
                    {
                        _link.breakPointX[_breakIndex] = p.X;
                        _link.breakPointY[_breakIndex] = p.Y;
                        this._breakIndex = -1;
                        this._isZhexian  = false;
                        IsModify         = true;
                    }
                    //this.OperationLineItem.Add(link);
                    //this.OperationType.Add(UndoType.Zhexian);
                    this.Invalidate();
                }
            }
            //拖拽
            if (_dragger != null)
            {
                if (this.CanEdit && !_dragger.location.Equals(p))
                {
                    _dragger.DragTo(p);
                    _dragger.End();
                    IsModify = true;
                }
                _dragger = null;
                return;
            }
            //橡皮圈选择区域时的鼠标释放
            if (_rubberband != null)
            {
                Rectangle rect = _rubberband.Bounds();
                _rubberband.End();
                _rubberband = null;
                foreach (BaseComponent c in TaskItems)
                {
                    if (rect.Contains(c.bounds))
                    {
                        SelectedItems.Add(c);
                    }
                }
                this.Invalidate();
            }
        }
Exemplo n.º 2
0
        private void WorkPlace_MouseDown(object sender, MouseEventArgs e)
        {
            //点击的是右键
            if (MouseButtons == MouseButtons.Right)
            {
                if (SelectedLine.Count != 0 && SelectedItems.Count == 0) //选中直线,没有选中任务节点
                {
                    this.ContextMenu = this.contextMenu;
                }
                else if (SelectedItems.Count > 0) //选中任务节点
                {
                    this.ContextMenu = this.contextMenu;
                }
                else //直线和任务节点都没有选中
                {
                    this.ContextMenu = this.cmPanel;
                }
                return;
            }
            //点击的是左键
            if (ToolModel == true) //工具模式下
            {
                Point p = new Point(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);

                //操作节点
                switch (this.Module)
                {
                case 1:
                    this._stId++;
                    StartTask st = new StartTask(p, _stId);
                    AddItem(st, 1);
                    break;

                case 2:
                    this._endtId++;
                    EndTask endt = new EndTask(p, _endtId);
                    AddItem(endt, 2);
                    break;

                case 3:
                    this._altId++;
                    AlternateTask at = new AlternateTask(p, _altId);
                    AddItem(at, 3);
                    break;

                case 4:
                    this._jtId++;
                    JudgeTask jt = new JudgeTask(p, _jtId);
                    AddItem(jt, 4);
                    break;

                case 5:
                    this._etId++;
                    ViewTask et = new ViewTask(p, _etId);
                    AddItem(et, 5);
                    break;

                case 6:
                    this._subId++;
                    SubFlowTask sft = new SubFlowTask(p, _subId);
                    AddItem(sft, 6);
                    break;

                case 0:     //连线
                    Point point = new Point(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);
                    foreach (BaseComponent c in TaskItems)
                    {
                        if (c.Contains(point))
                        {
                            _startTask          = c;
                            this._isDrawingLine = true;
                            _startPoint.X       = e.X;
                            _startPoint.Y       = e.Y;
                            break;
                        }
                        else
                        {
                            _startTask          = null;
                            this._isDrawingLine = false;
                        }
                    }
                    break;

                case -1:     //自连线
                    point = new Point(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);
                    foreach (BaseComponent c in TaskItems)
                    {
                        if (c.Contains(point))
                        {
                            _startTask = c;
                            _endTask   = c;
                            Link lnk = new Link(_startTask, _endTask);
                            lnk.flowGuid = this.WorkFlowId;
                            this.LineItems.Add(lnk);
                            IsModify = true;
                            this.Invalidate();
                            break;
                        }
                    }
                    break;
                }
                if (NowButton != null && LockModel == false)
                {
                    NowButton.Checked = false;                                          //添加完后修改toolbar按钮为非选中状态
                }
            }
            else //非工具模式下
            {
                Point         p             = new Point(e.X - this.AutoScrollPosition.X, e.Y - this.AutoScrollPosition.Y);
                BaseComponent baseComponent = IsInAItem(p);
                _link = IsInALine(p);
                if (baseComponent != null) //鼠标点击了某一个任务节点
                {
                    if (IsInASelectedItem(p))
                    {
                        MouseDownInAComponent(p);
                    }
                    else
                    {
                        SelectedItems.Clear();
                        SelectedItems.Add(baseComponent);
                        SelectedLine.Clear();
                        MouseDownInAComponent(p);
                        this.Invalidate();
                    }
                }
                else
                {
                    if (_link != null) //点击了某条连线
                    {
                        SelectedLine.Clear();
                        SelectedLine.Add(_link);
                        SelectedItems.Clear();
                        //点中的是锚点话,拖动锚点或者删除,在这里认为是拖动.利用函数来找出startPoint,endPoint和breakIndex等
                        _isInAnchor = IsInAnchor(p);
                        _breakPoint = p;
                        this.Invalidate();
                    }
                    else
                    {
                        SelectedItems.Clear();
                        SelectedLine.Clear();
                        if (e.Button == MouseButtons.Right)
                        {
                            return;
                        }
                        else
                        {
                            _rubberband = new Rubberband(this, p);
                        }
                    }
                }
                //this.label1.Text=SelectedLine.Count.ToString();
            }
        }