Exemple #1
0
 public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawRectangleObject(e.X, e.Y, 1, 1));
 }
Exemple #2
0
 public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawImageObject(e.X, e.Y));
 }
Exemple #3
0
        /// <summary>
        /// 按下鼠标左键
        /// </summary>
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            _selectMode = SelectionMode.None;
            PointF point = new Point(e.X, e.Y);

            // 调整大小的测试(仅当选择了控件时,光标位于句柄上)
            int n = drawArea.GraphicsList.SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = drawArea.GraphicsList.GetSelectedObject(i);

                int  handleNumber = o.HitTest(point);
                bool hitOnOutline = o.HitOnCircumferance;

                if (handleNumber > 0)
                {
                    _selectMode = SelectionMode.Size;

                    #region LineConnect
                    if (o is DrawConnectLine && handleNumber != 2)
                    {
                        ((DrawConnectLine)o).SetFollowObjectNull(handleNumber);
                    }

                    if (o is DrawConnectObject connect)
                    {
                        connect.SetFollowDrawObject(handleNumber, null, -1);
                    }
                    //if (o is WireConnectLineDrawObject && handleNumber != 2)
                    //{
                    //    ((WireConnectLineDrawObject)o).SetFollowObjectNull(handleNumber);
                    //}

                    #endregion

                    //if ( o is SingleDisConnectorDrawObject && handleNumber == 9)
                    //{
                    //    float state = ((SingleDisConnectorDrawObject)o).Switch;
                    //    ((SingleDisConnectorDrawObject)o).Switch = state == 0 ? 1 : 0;
                    //}

                    // 在类成员中保留调整大小的对象
                    _resizedObject       = o;
                    _resizedObjectHandle = handleNumber;

                    // 因为我们只想调整一个对象的大小,所以取消选择所有其他对象。
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;
                    o.MouseClickOnHandle(handleNumber);

                    break;
                }

                if (hitOnOutline && (n == 1))
                {
                    _selectMode = SelectionMode.Size;
                    o.MouseClickOnBorder();
                    o.Selected = true;
                }
            }


            // 移动测试(光标在对象上)
            if (_selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.GraphicsList.Count;
                DrawObject o  = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(point) == 0)
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    _selectMode = SelectionMode.Move;

                    // 如果未按ctrl且尚未选择单击的对象,则取消全选
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    // 选择单击的对象
                    o.Selected = true;

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            //判断是否点击到旋钮
            if (_selectMode == SelectionMode.None)
            {
                for (int i = 0; i < n; i++)
                {
                    DrawObject o         = drawArea.GraphicsList.GetSelectedObject(i);
                    bool       hitonknob = o.HitKnobTest(point);
                    if (hitonknob)
                    {
                        _selectMode = SelectionMode.Rotate;

                        // 在类成员中保留调整角度的对象
                        _rerotateObject = o;

                        // 因为我们只想调整一个对象的大小,所以取消选择所有其他对象。
                        drawArea.GraphicsList.UnselectAll();
                        o.Selected = true;

                        break;
                    }
                }
            }

            // 净选择
            if (_selectMode == SelectionMode.None)
            {
                // 点击背景
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.UnselectAll();
                }

                _selectMode = SelectionMode.NetSelection;
                drawArea.DrawNetRectangle = true;
            }
            //保存一次最近操作
            _lastPoint.X  = e.X;
            _lastPoint.Y  = e.Y;
            _startPoint.X = e.X;
            _startPoint.Y = e.Y;

            drawArea.Capture      = true;
            drawArea.NetRectangle = DrawRectangleObject.GetNormalizedRectangle(_startPoint, _lastPoint);

            drawArea.Refresh();
        }
Exemple #4
0
 public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawCircleObject(e.X, e.Y, 1, 1));
     // AddNewObject(drawArea, new DrawEllipseObject(e.X, e.Y, 1, 1));
 }
Exemple #5
0
        /// <summary>
        /// 释放鼠标右键
        /// </summary>
        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            if (_selectMode == SelectionMode.NetSelection)
            {
                // 分组选择
                drawArea.GraphicsList.SelectInRectangle(drawArea.NetRectangle);

                _selectMode = SelectionMode.None;
                drawArea.DrawNetRectangle = false;
            }

            if (_resizedObject != null)
            {
                //if(_resizedObject is DeviceDrawObject)
                //{
                //    var device = (DeviceDrawObject)_resizedObject;
                //    for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                //    {
                //        if (!(drawArea.GraphicsList[i] is DeviceDrawObject)) continue;
                //        int hithandle = drawArea.GraphicsList[i].HitTest(device.GetHandle(_resizedObjectHandle));
                //        if ( hithandle>= 0)
                //        {
                //            device.SetConnect(hithandle, (DeviceDrawObject) drawArea.GraphicsList[i]);
                //            ((DeviceDrawObject) drawArea.GraphicsList[i]).SetConnect(hithandle, device);
                //        }
                //    }
                //}

                #region LineConnect
                if (_resizedObjectHandle != 2 && _resizedObject is DrawConnectLine)
                {
                    var line = (DrawConnectLine)_resizedObject;
                    for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                    {
                        if (drawArea.GraphicsList[i] is DrawConnectLine)
                        {
                            continue;
                        }
                        if (drawArea.GraphicsList[i] is DrawLineObject)
                        {
                            continue;
                        }
                        if (drawArea.GraphicsList[i].HitTest(line.GetHandle(_resizedObjectHandle)) >= 0)
                        {
                            line.SetFollowObject(_resizedObjectHandle, drawArea.GraphicsList[i]);
                        }
                    }
                }

                if (_resizedObject is DrawConnectObject connect)
                {
                    for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                    {
                        if (drawArea.GraphicsList[i] is DeviceDrawObjectBase device)
                        {
                            if (device.HitTest(connect.GetHandle(_resizedObjectHandle)) >= 0)
                            {
                                connect.SetFollowDrawObject(_resizedObjectHandle,
                                                            device, device.GetNearestPort(connect.GetHandle(_resizedObjectHandle)));
                            }
                        }
                    }
                }
                //if (_resizedObjectHandle != 2 && _resizedObject is WireConnectLineDrawObject line1)
                //{
                //    for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                //    {
                //        //if (drawArea.GraphicsList[i] is WireConnectLineDrawObject) continue;
                //        //if (drawArea.GraphicsList[i] is WireConnectLineDrawObject) continue;
                //        int hit = drawArea.GraphicsList[i].HitTest(line1.GetHandle(_resizedObjectHandle));
                //        if (hit >= 0)
                //        {
                //            if (hit == 0)
                //            {
                //                float mins = 99999;
                //                int hits = 0;
                //                for (int j = 0; j < drawArea.GraphicsList[i].HandleCount; j++)
                //                {
                //                    var point = drawArea.GraphicsList[i].GetHandle(j);
                //                    var dis = (point.X - e.X) * (point.X - e.X) + (point.Y - e.Y) * (point.Y - e.Y);
                //                    if ( dis < mins)
                //                    {
                //                        mins = dis;
                //                        hits = j;
                //                    }
                //                }

                //                hit = hits;
                //            }
                //            //if (drawArea.GraphicsList[i] is DeviceDrawObject
                //            //    && !(drawArea.GraphicsList[i] is WireConnectLineDrawObject))
                //            //{
                //            //    PortDrawObject port = null;

                //            //    foreach (var portDrawObject in ((DeviceDrawObject)drawArea.GraphicsList[i]).PortDrawObjects)
                //            //    {
                //            //        if(portDrawObject.OwnerDevice != drawArea.GraphicsList[i]) break;
                //            //        if (portDrawObject.OwnerDeviceHandle != hit) continue;
                //            //        port = portDrawObject;
                //            //        break;

                //            //    }

                //            //    if (port == null)
                //            //    {
                //            //        port = new PortDrawObject(e.X, e.Y)
                //            //        {
                //            //            ConnectDevice = _resizedObject as DeviceDrawObject,
                //            //            //OwnerDeviceHandle = hit,
                //            //            OwnerDevice = drawArea.GraphicsList[i] as DeviceDrawObject
                //            //        };
                //            //        port.OwnerDeviceHandle = hit;
                //            //        ((DeviceDrawObject)drawArea.GraphicsList[i]).PortDrawObjects.Add(port);
                //            //        drawArea.GraphicsList.Add(port);

                //            //    }


                //                //line1.SetFollowObject(_resizedObjectHandle, port, 9);
                //                //break;
                //            }
                //            else
                //            {
                //                line1.SetFollowObject(_resizedObjectHandle, drawArea.GraphicsList[i]);
                //                break;
                //            }

                //        }
                //}
                //}

                #endregion



                // 调整大小后
                _resizedObject.MouseClickOnHandleUp(_resizedObjectHandle);
                _resizedObject.Normalize();
                _resizedObject = null;
                drawArea.ResizeCommand(drawArea.GraphicsList.GetFirstSelected(),
                                       new PointF(_startPoint.X, _startPoint.Y),
                                       new PointF(e.X, e.Y),
                                       _resizedObjectHandle);
            }

            if (_rerotateObject != null)
            {
                _rerotateObject.Normalize();
                _rerotateObject = null;
                drawArea.RerotateCommand(drawArea.GraphicsList.GetFirstSelected(),
                                         new PointF(_startPoint.X, _startPoint.Y),
                                         new PointF(e.X, e.Y));
            }

            drawArea.Capture = false;
            drawArea.Refresh();

            //立即按命令撤消/重做列表
            if (_selectMode == SelectionMode.Move)
            {
                var movedItemsList = new ArrayList();

                for (int i = 0; i < drawArea.GraphicsList.SelectionCount; i++)
                {
                    movedItemsList.Add(drawArea.GraphicsList.GetSelectedObject(i));
                }

                var delta = new PointF {
                    X = e.X - _startPoint.X, Y = e.Y - _startPoint.Y
                };
                drawArea.MoveCommand(movedItemsList, delta);
            }

            IsComplete = true;
        }
Exemple #6
0
        /// <summary>
        /// 鼠标移动。
        /// 无按钮按下,OT左按钮按下。
        /// </summary>
        public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
        {
            var point = new Point(e.X, e.Y);

            // 不按鼠标按钮时设置光标
            if (e.Button == MouseButtons.None)
            {
                Cursor cursor = null;

                for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                {
                    int n = drawArea.GraphicsList[i].HitTest(point);

                    if (n > 0)
                    {
                        cursor = drawArea.GraphicsList[i].GetHandleCursor(n);
                        break;
                    }
                    if (drawArea.GraphicsList[i].HitOnCircumferance)
                    {
                        cursor = drawArea.GraphicsList[i].GetOutlineCursor(n);
                        break;
                    }

                    bool hitknob = drawArea.GraphicsList[i].HitKnobTest(point);
                    if (hitknob)
                    {
                        cursor = drawArea.GraphicsList[i].GetKnodCursor();
                    }
                }

                if (cursor == null)
                {
                    cursor = Cursors.Default;
                }

                drawArea.Cursor = cursor;

                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }


            // 查找上一个位置和当前位置之间的差异
            float dx = e.X - _lastPoint.X;
            float dy = e.Y - _lastPoint.Y;

            _lastPoint.X = e.X;
            _lastPoint.Y = e.Y;

            // resize
            if (_selectMode == SelectionMode.Size)
            {
                if (_resizedObject != null)
                {
                    _resizedObject.MoveHandleTo(point, _resizedObjectHandle);
                    drawArea.SetDirty();
                    drawArea.Refresh();
                }
            }

            // move
            if (_selectMode == SelectionMode.Move)
            {
                int n = drawArea.GraphicsList.SelectionCount;

                for (int i = 0; i < n; i++)
                {
                    drawArea.GraphicsList.GetSelectedObject(i).Move(dx, dy);
                }

                drawArea.Cursor = Cursors.SizeAll;
                drawArea.SetDirty();
                drawArea.Refresh();
            }

            if (_selectMode == SelectionMode.Rotate)
            {
                if (_rerotateObject != null)
                {
                    //_rerotateObject.RotateKnobTo(point);
                    _rerotateObject.Rotate((dx + dy) / 2);
                    drawArea.SetDirty();
                    drawArea.Refresh();
                }
            }

            if (_selectMode == SelectionMode.NetSelection)
            {
                drawArea.NetRectangle = DrawRectangleObject.GetNormalizedRectangle(_startPoint, _lastPoint);
                drawArea.Refresh();
                return;
            }
        }
Exemple #7
0
 public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
 {
     Cursor = _openHand;
 }
Exemple #8
0
 public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e)
 {
     drawArea.Cursor = e.Button == MouseButtons.Left ? _closedHand : _openHand;
 }
Exemple #9
0
 public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
 {
     drawArea.Cursor = _closedHand;
 }