Exemplo n.º 1
0
        public void Copy()
        {
            int n = SelectionCount;

            tempList.Clear();
            for (int i = 0; i < n; i++)
            {
                DrawObject o = (DrawObject)GetSelectedObject(i);
                tempList.Add(o);
            }
        }
        public void Clone(VisualGraph drawArea)
        {
            int   n = tempList.Count;
            Point point;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = (DrawObject)tempList[i];
                point = new Point(o.ShapeRect.X + 10, o.ShapeRect.Y + 10);
                switch (o.ObjectType)
                {
                case Global.DrawType.DrawEllipse:
                    DrawEllipse dp = new DrawEllipse(point, drawArea);
                    dp.Selected = false;
                    objList.Add(dp);
                    break;

                case Global.DrawType.DrawLine:
                    DrawLine dl = new DrawLine(point, drawArea);
                    dl.Selected   = false;
                    dl.StartPoint = point;
                    dl.EndPoint   = new Point(point.X + o.ShapeRect.Width, point.Y + o.ShapeRect.Height);
                    dl.Width      = o.ShapeRect.Width;
                    dl.Height     = o.ShapeRect.Height;
                    dl.PenWidth   = o.PenWidth;
                    dl.Color      = o.Color;
                    objList.Add(dl);
                    break;

                case Global.DrawType.DrawRectangle:
                    DrawRectangle dr = new DrawRectangle(point, drawArea);
                    dr.Selected = false;
                    objList.Add(dr);
                    break;

                case Global.DrawType.DrawText:
                    DrawText dt = new DrawText(point, drawArea);
                    dt.Selected = false;
                    objList.Add(dt);
                    break;

                case Global.DrawType.DrawPic:
                    DrawPic   oldpic = (DrawPic)o;
                    DrawPic   dpic   = new DrawPic(point, drawArea);
                    Rectangle ret    = new Rectangle(point.X, point.Y, oldpic.ShapeRect.Width, oldpic.ShapeRect.Height);
                    dpic.ShapeRect = ret;
                    dpic.TheImage  = oldpic.TheImage;
                    dpic.Selected  = false;
                    objList.Add(dpic);
                    break;
                }
            }
            drawArea.ActivedObjType = Global.DrawType.POINTER;
        }
Exemplo n.º 3
0
        public void AlignVCenter()
        {
            int MinLeft  = MAX;
            int MaxRight = 0;
            int VCenter  = 0;
            int tempL;
            int tempR;
            int n = SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    tempL = Math.Min(l.StartPoint.X, l.EndPoint.X);
                    tempR = Math.Max(l.StartPoint.X, l.EndPoint.X);
                }
                else
                {
                    tempL = o.ShapeRect.X;
                    tempR = o.ShapeRect.Right;
                }
                if (tempL < MinLeft)
                {
                    MinLeft = tempL;
                }
                if (tempR > MaxRight)
                {
                    MaxRight = tempR;
                }
            }

            VCenter = (MinLeft + MaxRight) / 2;
            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    l.Move(VCenter - (l.StartPoint.X + l.EndPoint.X) / 2, 0);
                }
                else
                {
                    int center = (o.ShapeRect.Left + o.ShapeRect.Right) / 2;
                    o.ShapeRect = new Rectangle(o.ShapeRect.Left + (VCenter - center),
                                                o.ShapeRect.Top, o.ShapeRect.Width, o.ShapeRect.Height);
                }
            }
        }
Exemplo n.º 4
0
        public void AlignHCenter()
        {
            int MinTop    = MAX;
            int MaxBottom = 0;
            int HCenter   = 0;
            int tempT;
            int tempB;
            int n = SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    tempT = Math.Min(l.StartPoint.Y, l.EndPoint.Y);
                    tempB = Math.Max(l.StartPoint.Y, l.EndPoint.Y);
                }
                else
                {
                    tempT = o.ShapeRect.Top;
                    tempB = o.ShapeRect.Bottom;
                }
                if (tempT < MinTop)
                {
                    MinTop = tempT;
                }
                if (tempB > MaxBottom)
                {
                    MaxBottom = tempB;
                }
            }
            HCenter = (MinTop + MaxBottom) / 2;
            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    l.Move(0, HCenter - (l.StartPoint.Y + l.EndPoint.Y) / 2);
                }
                else
                {
                    int center = (o.ShapeRect.Top + o.ShapeRect.Bottom) / 2;
                    o.ShapeRect = new Rectangle(o.ShapeRect.Left, o.ShapeRect.Top +
                                                (HCenter - center), o.ShapeRect.Width, o.ShapeRect.Height);
                }
            }
        }
Exemplo n.º 5
0
        public int GetSelectedObjectIndex()
        {
            int n;

            n = objList.Count;
            for (int i = n - 1; i >= 0; i--)
            {
                DrawObject o = (DrawObject)objList[i];
                if (o.Selected)
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemplo n.º 6
0
        public bool DeleteSelection() //ɾ³ý
        {
            bool result = false;
            int  n      = objList.Count;

            for (int i = n - 1; i >= 0; i--)
            {
                if (((DrawObject)objList[i]).Selected)
                {
                    DrawObject o = (DrawObject)objList[i];
                    objList.RemoveAt(i);
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public void AlignLeft()
        {
            int MinLeft = MAX;
            int temp;
            int n = SelectionCount;

            //找到最左边的X左边
            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    temp = Math.Min(l.StartPoint.X, l.EndPoint.X);
                }
                else
                {
                    temp = o.ShapeRect.Left;
                }
                if (temp < MinLeft)
                {
                    MinLeft = temp;
                }
            }

            //修改所有选中元素到最左坐标
            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    if (l.StartPoint.X < l.EndPoint.X)
                    {
                        l.Move(MinLeft - l.StartPoint.X, 0);
                    }
                    else
                    {
                        l.Move(MinLeft - l.EndPoint.X, 0);
                    }
                }
                else
                {
                    o.ShapeRect = new Rectangle(MinLeft, o.ShapeRect.Top, o.ShapeRect.Width, o.ShapeRect.Height);
                }
            }
        }
Exemplo n.º 8
0
        public void LoadFromXml(string file)
        {
            XmlDocument   xdoc = new XmlDocument();
            XmlTextReader xtr  = new XmlTextReader(file);

            xdoc.Load(xtr);
            int n = xdoc.DocumentElement.ChildNodes.Count;

            for (int i = 0; i < n; i++)
            {
                XmlElement xe             = (XmlElement)xdoc.DocumentElement.ChildNodes[i];
                string     drawObjectType = xe.GetAttribute("Type");
                if (drawObjectType.Equals("VisualGraph"))
                {
                    DocFromXml(xe);
                }
                else
                {
                    DrawObject drawObject = null;
                    switch (drawObjectType)
                    {
                    case "DrawEllipse":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawEllipse));
                        break;

                    case "DrawLine":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawLine));
                        break;

                    case "DrawPic":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawPic));
                        break;

                    case "DrawRectangle":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawRectangle));
                        break;

                    case "DrawText":
                        drawObject = (DrawObject)Activator.CreateInstance(typeof(DrawText));
                        break;
                    }
                    drawObject.ReadFromXml(xe);
                    ObjList.AddObject(drawObject);
                }
            }
        }
Exemplo n.º 9
0
        public void AlignTop()
        {
            int MinTop = MAX;
            int temp;
            int n = SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine )o;
                    temp = Math.Min(l.StartPoint.Y, l.EndPoint.Y);
                }
                else
                {
                    temp = o.ShapeRect.Top;
                }
                if (temp < MinTop)
                {
                    MinTop = temp;
                }
            }
            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);

                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    if (l.StartPoint.Y < l.EndPoint.Y)
                    {
                        l.Move(0, MinTop - l.StartPoint.Y);
                    }
                    else
                    {
                        l.Move(0, MinTop - l.EndPoint.Y);
                    }
                }
                else
                {
                    o.ShapeRect = new Rectangle(o.ShapeRect.Left, MinTop, o.ShapeRect.Width, o.ShapeRect.Height);
                }
            }
        }
Exemplo n.º 10
0
        public void AlignBottom()
        {
            int MaxBottom = 0;
            int temp;
            int n = SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    temp = Math.Max(l.StartPoint.Y, l.EndPoint.Y);
                }
                else
                {
                    temp = o.ShapeRect.Bottom;
                }
                if (temp > MaxBottom)
                {
                    MaxBottom = temp;
                }
            }
            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    if (l.StartPoint.Y > l.EndPoint.Y)
                    {
                        l.Move(0, MaxBottom - l.StartPoint.Y);
                    }
                    else
                    {
                        l.Move(0, MaxBottom - l.EndPoint.Y);
                    }
                }
                else
                {
                    o.ShapeRect = new Rectangle(o.ShapeRect.Left,
                                                MaxBottom - o.ShapeRect.Height, o.ShapeRect.Width, o.ShapeRect.Height);
                }
            }
        }
Exemplo n.º 11
0
        public void AlignRight()
        {
            int MaxRight = 0;
            int temp;
            int n = SelectionCount;

            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    temp = Math.Max(l.StartPoint.X, l.EndPoint.X);
                }
                else
                {
                    temp = o.ShapeRect.Right;
                }
                if (temp > MaxRight)
                {
                    MaxRight = temp;
                }
            }
            for (int i = 0; i < n; i++)
            {
                DrawObject o = GetSelectedObject(i);
                if (o.ObjectType == Global.DrawType.DrawLine)
                {
                    DrawLine l = (DrawLine)o;
                    if (l.StartPoint.X > l.EndPoint.X)
                    {
                        l.Move(MaxRight - l.StartPoint.X, 0);
                    }
                    else
                    {
                        l.Move(MaxRight - l.EndPoint.X, 0);
                    }
                }
                else
                {
                    o.ShapeRect = new Rectangle(MaxRight - o.ShapeRect.Width, o.ShapeRect.Top,
                                                o.ShapeRect.Width, o.ShapeRect.Height);
                }
            }
        }
Exemplo n.º 12
0
        public override void OnMouseUp(VisualGraph drawArea, MouseEventArgs e)
        {
            Point point = new Point(e.X, e.Y);

            if (selectMode == SelectionMode.NetSelection)
            {
                drawArea.ObjList.SelectInRectangle(drawArea.NetRectangle);
                selectMode = SelectionMode.None;
                drawArea.DrawNetRectangle = false;
            }
            if (resizedObject != null)
            {
                resizedObject.Normalize();
                resizedObject = null;
            }
            selectMode = SelectionMode.None;
            drawArea.Refresh();
        }
        public void LoadFromXml(string file)
        {
            XmlDocument   xdoc = new XmlDocument();
            XmlTextReader xtr  = new XmlTextReader(file);

            xdoc.Load(xtr);
            int n = xdoc.DocumentElement.ChildNodes.Count;

            for (int i = 0; i < n; i++)
            {
                XmlElement xe             = (XmlElement)xdoc.DocumentElement.ChildNodes[i];
                string     drawObjectType = xe.GetAttribute("Type");
                if (drawObjectType.Equals("VisualGraph"))
                {
                    DocFromXml(xe);
                }
                else
                {
                    DrawObject drawObject = (DrawObject)Activator.CreateInstance("VisualGraph", "VisualGraph." + drawObjectType).Unwrap();
                    drawObject.ReadFromXml(xe);
                    ObjList.AddObject(drawObject);
                }
            }
        }
Exemplo n.º 14
0
        public override void OnMouseMove(VisualGraph drawArea, MouseEventArgs e)
        {
            Point point = new Point(e.X, e.Y);

            if (e.Button == MouseButtons.None)
            {
                Cursor cursor = null;
                for (int i = drawArea.ObjList.Count() - 1; i >= 0; i--)
                {
                    int n = drawArea.ObjList[i].HitTest(point);
                    if (n > 0)
                    {
                        cursor = drawArea.ObjList[i].GetHandleCursor(n);
                        break;
                    }
                }
                if (cursor == null)
                {
                    cursor = Cursors.Default;
                }
                drawArea.Cursor = cursor;
                return;
            }

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

            int dx = point.X - lastPoint.X;
            int dy = point.Y - lastPoint.Y;

            lastPoint.X = point.X;
            lastPoint.Y = point.Y;
            if (selectMode == SelectionMode.Size)
            {
                if (resizedObject != null)
                {
                    resizedObject.MoveHandleTo(point, resizedObjectHandle);
                    drawArea.Refresh();
                }
            }


            if (selectMode == SelectionMode.Move)
            {
                int n = drawArea.ObjList.SelectionCount;

                for (int i = n - 1; i >= 0; i--)
                {
                    drawArea.ObjList.GetSelectedObject(i).Move(dx, dy);
                }
                DrawObject l = (DrawObject)drawArea.ObjList.GetSelectedObject(point);
                if (l != null)
                {
                    drawArea.Cursor = Cursors.SizeAll;
                }
                drawArea.Refresh();
            }
            if (selectMode == SelectionMode.NetSelection)
            {
                drawArea.NetRectangle = GetNormalizedRectangle(startPoint, lastPoint);
                drawArea.Refresh();
                return;
            }
        }
Exemplo n.º 15
0
        public override void OnMouseDown(VisualGraph drawArea, MouseEventArgs e)
        {
            Point point = new Point(e.X, e.Y);

            selectMode = SelectionMode.None;

            int n = drawArea.ObjList.SelectionCount;

            for (int i = n - 1; i >= 0; i--)
            {
                DrawObject o = drawArea.ObjList.GetSelectedObject(i);

                int handleNumber = o.HitTest(point);
                if (handleNumber > 0)
                {
                    selectMode          = SelectionMode.Size;
                    resizedObject       = o;
                    resizedObjectHandle = handleNumber;
                    drawArea.ObjList.UnselectAll();
                    o.Selected = true;

                    break;
                }
            }

            if (selectMode == SelectionMode.None)
            {
                int        m = drawArea.ObjList.Count();
                DrawObject o = null;
                for (int i = m - 1; i >= 0; i--)
                {
                    if (drawArea.ObjList[i].HitTest(point) == 0)
                    {
                        o = drawArea.ObjList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    selectMode = SelectionMode.Move;
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.ObjList.UnselectAll();
                    }
                    o.Selected = true;
                    //»­Ñ¡Ôñ±ß¿ò
                    drawArea.Cursor = Cursors.SizeAll;
                }
            }
            if (selectMode == SelectionMode.None)
            {
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.ObjList.UnselectAll();
                }
                selectMode = SelectionMode.NetSelection;
                drawArea.DrawNetRectangle = true;
            }
            lastPoint.X  = point.X;
            lastPoint.Y  = point.Y;
            startPoint.X = point.X;
            startPoint.Y = point.Y;

            drawArea.Capture      = true;
            drawArea.NetRectangle = GetNormalizedRectangle(startPoint, lastPoint);

            drawArea.Refresh();
        }
Exemplo n.º 16
0
 public void AddObject(DrawObject o)
 {
     objList.Add(o);
 }