示例#1
0
        public static Rectangle CalculateRectangle(Hashtable transformers)
        {
            Rectangle rec = Rectangle.Empty;

            if (transformers == null || transformers.Count == 0)
            {
                return(Rectangle.Empty);
            }
            bool first = true;

            foreach (object val in transformers.Values)
            {
                EntityBone bone = (EntityBone)val;
                if (bone.Rectangle.Equals(Rectangle.Empty))
                {
                    continue;
                }
                if (first)
                {
                    rec   = bone.Rectangle;
                    first = false;
                }
                else
                {
                    rec = Rectangle.Union(rec, bone.Rectangle);
                }
            }
            return(rec);
        }
        public void MouseDown(MouseEventArgs e)
        {
            if (e == null)
                throw new ArgumentNullException("The argument object is 'null'");
            if (e.Button == MouseButtons.Left && Enabled && !IsSuspended)
            {

                if (Selection.SelectedItems.Count > 0)
                {
                    //let the tracker tell us if anything was hit
                    Point gripPoint = this.Controller.View.Tracker.Hit(e.Location);
                    Cursor c = null;
                    changing = false;

                    #region determine and set the corresponding cursor
                    switch (gripPoint.X)
                    {
                        case -1:
                            switch (gripPoint.Y)
                            {
                                case -1:
                                    c = Cursors.SizeNWSE;
                                    transform = TransformTypes.NW;
                                    //the origin is the right-bottom of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 0:
                                    c = Cursors.SizeWE;
                                    transform = TransformTypes.W;
                                    //the origin is the right-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 1:
                                    c = Cursors.SizeNESW;
                                    transform = TransformTypes.SW;
                                    //the origin is the right-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                            }
                            break;
                        case 0:
                            switch (gripPoint.Y)
                            {
                                case -1:
                                    c = Cursors.SizeNS;
                                    transform = TransformTypes.N;
                                    //the origin is the center-bottom of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 1:
                                    c = Cursors.SizeNS;
                                    transform = TransformTypes.S;
                                    //the origin is the left-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                            }
                            break;
                        case 1:
                            switch (gripPoint.Y)
                            {
                                case -1:
                                    c = Cursors.SizeNESW;
                                    transform = TransformTypes.NE;
                                    //the origin is the left-bottom of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 0:
                                    c = Cursors.SizeWE;
                                    transform = TransformTypes.E;
                                    //the origin is the left-top of the rectangle
                                    ox = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;// +this.Controller.View.Tracker.Rectangle.Width / 2;
                                    oy = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                                    changing = true;
                                    break;
                                case 1:
                                    c = Cursors.SizeNWSE;
                                    transform = TransformTypes.SE;
                                    //the origin is the left-top of the tracker rectangle plus the little tracker offset
                                    ox = this.Controller.View.Tracker.Rectangle.X + ViewBase.TrackerOffset;
                                    oy = this.Controller.View.Tracker.Rectangle.Y + ViewBase.TrackerOffset;

                                    changing = true;
                                    break;
                            }
                            break;
                    }

                    #endregion

                    if (changing)
                    {
                        //the point where the scaling or dragging of the tracker started
                        initialPoint = e.Location;
                        //recursive location of the dragging location
                        lastPoint = initialPoint;
                        //start the tool
                        this.ActivateTool();
                        //set the cursor corresponding to the grip
                        Controller.View.CurrentCursor = c;
                        //create a new collection for the transforming entities
                        transformers = new Hashtable();
                        //the points of the connectors
                        Point[] points = null;
                        //the entity bone
                        EntityBone bone;
                        //take the flat selection and keep the current state as a reference for the transformation
                        //until the mouseup pins down the final scaling
                        foreach (IDiagramEntity entity in Selection.FlattenedSelectionItems)
                        {
                            bone = new EntityBone();

                            if (entity is IShape)
                            {
                                IShape shape = entity as IShape;
                                if (shape.Connectors.Count > 0)
                                {
                                    points = new Point[shape.Connectors.Count];
                                    for (int m = 0; m < shape.Connectors.Count; m++)
                                    {
                                        points[m] = shape.Connectors[m].Point;
                                    }
                                }
                                else
                                    points = null;
                                bone.Rectangle = entity.Rectangle;
                                bone.ConnectorPoints = points;
                            }
                            else if (entity is IConnection)
                            {
                                IConnection con = entity as IConnection;
                                points = new Point[2] { Point.Empty, Point.Empty };
                                //Only non-attached connection connectors have to be scaled
                                //Attached connectors will move with their parent.
                                if (con.From.AttachedTo == null)
                                    points[0] = con.From.Point;
                                if (con.To.AttachedTo == null)
                                    points[1] = con.To.Point;
                                //We define a connection as a bone with empty rectangle
                                //One could use some additional members to label it but it's only overhead at this point.
                                bone.Rectangle = Rectangle.Empty;
                                bone.ConnectorPoints = points;
                            }
                            transformers.Add(entity, bone);
                        }
                    }
                }

            }
        }
示例#3
0
        public void MouseDown(MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("The argument object is 'null'");
            }
            if (e.Button == MouseButtons.Left && Enabled && !IsSuspended)
            {
                if (Selection.SelectedItems.Count > 0)
                {
                    //let the tracker tell us if anything was hit
                    Point  gripPoint = this.Controller.View.Tracker.Hit(e.Location);
                    Cursor c         = null;
                    changing = false;

                    #region determine and set the corresponding cursor
                    switch (gripPoint.X)
                    {
                    case -1:
                        switch (gripPoint.Y)
                        {
                        case -1:
                            c         = Cursors.SizeNWSE;
                            transform = TransformTypes.NW;
                            //the origin is the right-bottom of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                            oy       = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 0:
                            c         = Cursors.SizeWE;
                            transform = TransformTypes.W;
                            //the origin is the right-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 1:
                            c         = Cursors.SizeNESW;
                            transform = TransformTypes.SW;
                            //the origin is the right-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Right - ViewBase.TrackerOffset;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;
                        }
                        break;

                    case 0:
                        switch (gripPoint.Y)
                        {
                        case -1:
                            c         = Cursors.SizeNS;
                            transform = TransformTypes.N;
                            //the origin is the center-bottom of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 1:
                            c         = Cursors.SizeNS;
                            transform = TransformTypes.S;
                            //the origin is the left-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;
                        }
                        break;

                    case 1:
                        switch (gripPoint.Y)
                        {
                        case -1:
                            c         = Cursors.SizeNESW;
                            transform = TransformTypes.NE;
                            //the origin is the left-bottom of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;
                            oy       = this.Controller.View.Tracker.Rectangle.Bottom - ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 0:
                            c         = Cursors.SizeWE;
                            transform = TransformTypes.E;
                            //the origin is the left-top of the rectangle
                            ox       = this.Controller.View.Tracker.Rectangle.Left + ViewBase.TrackerOffset;  // +this.Controller.View.Tracker.Rectangle.Width / 2;
                            oy       = this.Controller.View.Tracker.Rectangle.Top + ViewBase.TrackerOffset;
                            changing = true;
                            break;

                        case 1:
                            c         = Cursors.SizeNWSE;
                            transform = TransformTypes.SE;
                            //the origin is the left-top of the tracker rectangle plus the little tracker offset
                            ox = this.Controller.View.Tracker.Rectangle.X + ViewBase.TrackerOffset;
                            oy = this.Controller.View.Tracker.Rectangle.Y + ViewBase.TrackerOffset;

                            changing = true;
                            break;
                        }
                        break;
                    }

                    #endregion


                    if (changing)
                    {
                        //the point where the scaling or dragging of the tracker started
                        initialPoint = e.Location;
                        //recursive location of the dragging location
                        lastPoint = initialPoint;
                        //start the tool
                        this.ActivateTool();
                        //set the cursor corresponding to the grip
                        Controller.View.CurrentCursor = c;
                        //create a new collection for the transforming entities
                        transformers = new Hashtable();
                        //the points of the connectors
                        Point[] points = null;
                        //the entity bone
                        EntityBone bone;
                        //take the flat selection and keep the current state as a reference for the transformation
                        //until the mouseup pins down the final scaling
                        foreach (IDiagramEntity entity in Selection.FlattenedSelectionItems)
                        {
                            bone = new EntityBone();

                            if (entity is IShape)
                            {
                                IShape shape = entity as IShape;
                                if (shape.Connectors.Count > 0)
                                {
                                    points = new Point[shape.Connectors.Count];
                                    for (int m = 0; m < shape.Connectors.Count; m++)
                                    {
                                        points[m] = shape.Connectors[m].Point;
                                    }
                                }
                                else
                                {
                                    points = null;
                                }
                                bone.Rectangle       = entity.Rectangle;
                                bone.ConnectorPoints = points;
                            }
                            else if (entity is IConnection)
                            {
                                IConnection con = entity as IConnection;
                                points = new Point[2] {
                                    Point.Empty, Point.Empty
                                };
                                //Only non-attached connection connectors have to be scaled
                                //Attached connectors will move with their parent.
                                if (con.From.AttachedTo == null)
                                {
                                    points[0] = con.From.Point;
                                }
                                if (con.To.AttachedTo == null)
                                {
                                    points[1] = con.To.Point;
                                }
                                //We define a connection as a bone with empty rectangle
                                //One could use some additional members to label it but it's only overhead at this point.
                                bone.Rectangle       = Rectangle.Empty;
                                bone.ConnectorPoints = points;
                            }
                            transformers.Add(entity, bone);
                        }
                    }
                }
            }
        }