Exemple #1
0
        /// <summary>
        /// 找出与元器件drawObject结点相连的直线锚点信息
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="resizedObject">输入一个要得出直线锚点的元器件</param>
        /// <returns>返回一个数组第一列表示该元器件的结点,第二列表示与该结点连接的直线索引,第三列表示直线的锚点编号</returns>
        public List <int[]> FindLineHandle(DrawArea drawArea, DrawObject drawObject)
        {
            List <int[]> temp = new List <int[]>();
            int          i, j, k;
            Point        Position;
            double       distance = 100;

            for (i = 0; i < drawArea.GraphicsList.Count; i++)
            {
                DrawObject temp1 = drawArea.GraphicsList[i];
                if (temp1 is DrawLine)
                {
                    for (j = 1; j <= drawObject.NodeCount; j++)
                    {
                        //得到每个结点的坐标,寻找与该结点相连的直线
                        Position = drawObject.GetNode(j);

                        for (k = 1; k <= 2; k++)
                        {
                            Point p = temp1.GetHandle(k);
                            distance = Math.Sqrt((Position.X - p.X) * (Position.X - p.X) + (Position.Y - p.Y) * (Position.Y - p.Y));
                            if (distance < 10)
                            {
                                DrawLine DL = temp1 as DrawLine;
                                if (DL.FindEquipmentID[k - 1] == drawObject.ObjectID && DL.FindNodeID[k - 1] == j)
                                {
                                    //该直线k锚点就是连接的这个结点
                                    temp.Add(new int[] { j, i, k });
                                    break;
                                }
                                else if (DL.ConncetSNodeCount() == 0)
                                {
                                    //如果线的两端都没有连结点
                                    temp.Add(new int[] { j, i, k });
                                    DL.FindNodeID[k - 1]      = j;
                                    DL.FindEquipmentID[k - 1] = drawObject.ObjectID;
                                    break;
                                }
                                else if (DL.ConncetSNodeCount() == 1 && DL.FindEquipmentID[k - 1] == 0)
                                {
                                    //如果线只连接了一个其他元器件的结点,则可以将该线没有连接结点的锚点于结点连接
                                    temp.Add(new int[] { j, i, k });
                                    DL.FindNodeID[k - 1]      = j;
                                    DL.FindEquipmentID[k - 1] = drawObject.ObjectID;
                                    AddEdge(drawArea, DL);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(temp);
        }
Exemple #2
0
        public override void OnMouseMove(DrawArea drawArea, System.Windows.Forms.MouseEventArgs e)
        {
            Point point    = new Point(e.X, e.Y);
            Point oldPoint = lastPoint;

            CF.NodeRange(drawArea, e);//画结点区域
            if (e.Button == MouseButtons.None)
            {
                #region 在没有按住任何鼠标键的情况下,随着鼠标移动而改变指针形状
                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 (cursor == null)
                {
                    cursor = Cursors.Default;
                }
                drawArea.Cursor = cursor;
                return;

                #endregion
            }
            //按住的不是鼠标左键
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            //按住鼠标左键移动
            int dx = e.X - lastPoint.X;
            int dy = e.Y - lastPoint.Y;

            lastPoint.X = e.X;
            lastPoint.Y = e.Y;

            if (pointerMode == PointerMode.Size)
            {
                #region 改变大小
                if (resizedObject != null)
                {
                    if (resizedObject is DrawLine)
                    {
                        // 如果线的一端在结点范围之内则将该点与结点相连
                        Point p = CF.OnRange(drawArea);
                        if (p.X < 0 || p.Y < 0)
                        {
                            if (IsCtrlOn)
                            {
                                resizedObject.MoveHandleTo(point, 10 * resizedObjectHandle);
                            }
                            else if (IsShiftOn)
                            {
                                resizedObject.MoveHandleTo(point, 30 * resizedObjectHandle);
                            }
                            else
                            {
                                resizedObject.MoveHandleTo(point, resizedObjectHandle);
                            }
                        }
                        else
                        {
                            if (IsCtrlOn)
                            {
                                resizedObject.MoveHandleTo(p, 10 * resizedObjectHandle);
                            }
                            else if (IsShiftOn)
                            {
                                resizedObject.MoveHandleTo(p, 30 * resizedObjectHandle);
                            }
                            else
                            {
                                resizedObject.MoveHandleTo(p, resizedObjectHandle);
                            }
                        }
                    }
                    else
                    {
                        //如果移动的是元器件的结点
                        List <int[]> LIndex = CF.FindLineHandle(drawArea, resizedObject);
                        Point        location;
                        if (IsShiftOn)
                        {
                            //如果该元器件有导线连接则导线随元器件的大小变动,此时是按住SHIFT键的时候
                            if (LIndex.Count != 0)
                            {
                                int[] index;
                                //循环遍历与该结点相连的所有直线锚点
                                for (int i = 0; i < LIndex.Count; i++)
                                {
                                    index    = LIndex[i];//得到其中一个直线锚点
                                    location = resizedObject.GetNode(index[0]);
                                    resizedObject.MoveHandleTo(point, 10);

                                    Point newp = resizedObject.GetNode(index[0]);
                                    int   cx   = newp.X - location.X;
                                    int   cy   = newp.Y - location.Y;
                                    //找出相对应的直线,改变直线中相应锚点的位置
                                    DrawObject O = drawArea.GraphicsList[index[1]];
                                    O.MoveHandleTo(new Point(location.X + cx, location.Y + cy), index[2]);
                                }
                            }
                            else
                            {
                                resizedObject.MoveHandleTo(point, 10);
                            }
                        }
                        else
                        {
                            //如果该元器件有导线连接则导线随元器件的大小变动
                            if (LIndex.Count != 0)
                            {
                                int[] index;
                                for (int i = 0; i < LIndex.Count; i++)
                                {
                                    //得到结点连接的每一个直线锚点信息
                                    index = LIndex[i];

                                    location = resizedObject.GetNode(index[0]);
                                    resizedObject.MoveHandleTo(point, resizedObjectHandle);

                                    Point      newp = resizedObject.GetNode(index[0]);
                                    int        cx   = newp.X - location.X;
                                    int        cy   = newp.Y - location.Y;
                                    DrawObject O    = drawArea.GraphicsList[index[1]];
                                    O.MoveHandleTo(new Point(location.X + cx, location.Y + cy), index[2]);
                                }
                            }
                            else
                            {
                                resizedObject.MoveHandleTo(point, resizedObjectHandle);
                            }
                        }
                    }
                    drawArea.Refresh();
                }
                #endregion
            }

            if (pointerMode == PointerMode.Move)
            {
                #region 移动图形
                if (drawArea.GraphicsList.Selection != null)
                {
                    List <int[]> L;
                    foreach (DrawObject o in drawArea.GraphicsList.Selection)
                    {
                        Point location = new Point();
                        //找出与元器件o结点相连的直线描点
                        L = CF.FindLineHandle(drawArea, o);

                        int[] index;
                        for (int i = 0; i < L.Count; i++)
                        {
                            index    = L[i];
                            location = o.GetNode(index[0]);
                            DrawObject O = drawArea.GraphicsList[index[1]];
                            O.MoveHandleTo(new Point(location.X + dx, location.Y + dy), index[2]);
                        }
                        o.Move(dx, dy);
                    }
                    drawArea.Cursor = Cursors.SizeAll;
                    drawArea.Refresh();
                }
                #endregion
            }

            if (pointerMode == PointerMode.Net)
            {
                #region 空绘制矩形
                // 移除旧的矩形
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectanlge.GetNormalizedRectangle(startPoint, oldPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
                // 绘制新的矩形
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectanlge.GetNormalizedRectangle(startPoint, point)),
                    Color.Black,
                    FrameStyle.Dashed);
                #endregion
            }
        }