Exemple #1
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;
        }