Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmdTarget"></param>
        /// <returns></returns>
        public override bool Do(object cmdTarget)
        {
            bool       success    = false;
            INode      parentNode = null;
            IBounds2DF nodeBounds = null;
            ITransform curNodeXForm;
            PointF     ptAnchor;

            parentNode = (INode)cmdTarget;

            foreach (INode curNode in this.Nodes)
            {
                nodeBounds   = curNode as IBounds2DF;
                curNodeXForm = curNode as ITransform;

                if (nodeBounds != null && curNodeXForm != null)
                {
                    ptAnchor = Geometry.CenterPoint(nodeBounds.Bounds);
                    curNodeXForm.Scale(ptAnchor, this.sx, this.sy);
                }
            }

            success = true;

            return(success);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        void IMouseEventReceiver.MouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            System.Drawing.Point ptCur      = new System.Drawing.Point(e.X, e.Y);
            IBounds2DF           nodeBounds = null;
            IGraphics            nodeGrfx   = null;
            ITransform           nodeXform  = null;
            PointF worldPt;

            if (this.Enabled && this.Active && e.Button == MouseButtons.Left)
            {
                this.nodeHit = this.HitTest(ptCur);

                if (this.nodeHit != null && this.IsNodeAllowed(this.nodeHit))
                {
                    ChangeCursor(Resources.Cursors.Rotate);
                    this.startPoint   = ptCur;
                    this.currentPoint = this.startPoint;

                    nodeBounds = this.nodeHit as IBounds2DF;
                    nodeXform  = this.nodeHit as ITransform;
                    nodeGrfx   = this.nodeHit as IGraphics;

                    if (nodeGrfx != null)
                    {
                        this.grfxPath = (GraphicsPath)nodeGrfx.GraphicsPath.Clone();
                        if (nodeXform != null)
                        {
                            this.grfxPath.Transform(nodeXform.WorldTransform);
                        }
                    }

                    if (nodeBounds != null)
                    {
                        Global.MatrixStack.Clear();
                        if (nodeXform != null)
                        {
                            Global.MatrixStack.Push(nodeXform.ParentTransform);
                        }
                        worldPt = Geometry.CenterPoint(nodeBounds.Bounds);
                        Global.MatrixStack.Clear();

                        this.origin = this.Controller.View.ViewToDevice(this.Controller.View.WorldToView(worldPt));
                        this.Controller.View.DrawTrackingLine(this.origin, this.startPoint);
                        this.trackingRect = this.Controller.View.DrawTrackingPath(this.grfxPath, this.CurrentAngle);
                        this.tracking     = true;
                    }
                }
            }
        }
Example #3
0
        private RectangleF CalcNewBounds(IBounds2DF nodeBounds)
        {
            if (nodeBounds == null)
            {
                throw new EInvalidParameter();
            }

            RectangleF rcCur  = nodeBounds.Bounds;
            float      left   = rcCur.Left + this.dx;
            float      top    = rcCur.Top + this.dy;
            float      width  = rcCur.Width;
            float      height = rcCur.Height;

            return(new RectangleF(left, top, width, height));
        }
Example #4
0
        /// <summary>
        /// Constructs NodeTracker from a given view and node collection.
        /// </summary>
        /// <param name="view">View to render onto</param>
        /// <param name="nodes">Collection of nodes to track</param>
        public NodeBoundsTracker(View view, NodeCollection nodes) : base(view)
        {
            // Load array of bounding rectangles
            this.ptUpperLeft = new Point(int.MaxValue, int.MaxValue);
            System.Drawing.Rectangle curBounds;
            int nodeIdx = 0;

            this.nodeBounds = new System.Drawing.Rectangle[nodes.Count];

            foreach (INode curNode in nodes)
            {
                IBounds2DF nodeBounds = curNode as IBounds2DF;
                ITransform nodeTrans  = curNode as ITransform;

                // Push the parent transforms for the current node onto the stack
                if (nodeTrans != null)
                {
                    Global.MatrixStack.Push(nodeTrans.ParentTransform);
                }

                // Get the bounds of the current node in world coordinates
                if (nodeBounds != null)
                {
                    curBounds = this.view.ViewToDevice(this.view.WorldToView(nodeBounds.Bounds));

                    if (curBounds.Left < this.ptUpperLeft.X)
                    {
                        this.ptUpperLeft.X = curBounds.Left;
                    }

                    if (curBounds.Top < this.ptUpperLeft.Y)
                    {
                        this.ptUpperLeft.Y = curBounds.Top;
                    }
                }
                else
                {
                    curBounds = new System.Drawing.Rectangle(0, 0, 0, 0);
                }

                // Reset matrix stack
                Global.MatrixStack.Clear();

                // Add bounds to array
                this.nodeBounds[nodeIdx++] = curBounds;
            }
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        void IMouseEventReceiver.MouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            IBounds2DF boundsObj = null;

            if (this.Enabled && e.Button == MouseButtons.Left)
            {
                System.Drawing.Point ptCur = new System.Drawing.Point(e.X, e.Y);
                this.nodeHit   = this.Controller.ResizeHandleHitNode;
                this.handleHit = this.Controller.ResizeHandleHit;

                if (this.nodeHit != null)
                {
                    boundsObj = this.nodeHit as IBounds2DF;
                    if (boundsObj != null)
                    {
                        this.startBounds = Controller.View.ViewToDevice(Controller.View.WorldToView(boundsObj.Bounds));
                        this.curBounds   = ResizeTool.MoveAnchorPoint(this.startBounds, this.handleHit, ptCur);
                        Controller.View.DrawTrackingRect(this.curBounds);
                    }

                    this.Controller.ActivateTool(this);
                }
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodes"></param>
        /// <returns></returns>
        public static System.Drawing.RectangleF GetAggregateBounds(NodeCollection nodes)
        {
            RectangleF rcBounds  = new RectangleF(0, 0, 0, 0);
            bool       firstNode = true;

            foreach (INode node in nodes)
            {
                IBounds2DF nodeBounds = node as IBounds2DF;
                if (nodeBounds != null)
                {
                    if (firstNode)
                    {
                        rcBounds  = nodeBounds.Bounds;
                        firstNode = false;
                    }
                    else
                    {
                        rcBounds = Geometry.Union(rcBounds, nodeBounds.Bounds);
                    }
                }
            }

            return(rcBounds);
        }
Example #7
0
        /// <summary>
        /// Constructs a NodePathTracker object given a view and a collection
        /// of nodes to track.
        /// </summary>
        /// <param name="view">View to attach to</param>
        /// <param name="nodes">Collection of nodes to track</param>
        public NodePathTracker(View view, NodeCollection nodes) : base(view)
        {
            // Load array of bounding rectangles
            this.trackingPath = new GraphicsPath();
            this.ptUpperLeft  = new Point(int.MaxValue, int.MaxValue);
            System.Drawing.Rectangle curBounds;

            foreach (INode curNode in nodes)
            {
                IGraphics      graphicsObj = curNode as IGraphics;
                IBounds2DF     nodeBounds  = curNode as IBounds2DF;
                ITransform     nodeTrans   = curNode as ITransform;
                ICompositeNode nodeParent  = curNode.Parent;

                // Push the parent transforms for the current node onto the stack
                if (nodeTrans != null)
                {
                    Global.MatrixStack.Push(nodeTrans.ParentTransform);
                }

                // Get the bounds of the current node in world coordinates
                if (nodeBounds != null)
                {
                    curBounds = this.view.ViewToDevice(this.view.WorldToView(nodeBounds.Bounds));

                    if (curBounds.Left < this.ptUpperLeft.X)
                    {
                        this.ptUpperLeft.X = curBounds.Left;
                    }

                    if (curBounds.Top < this.ptUpperLeft.Y)
                    {
                        this.ptUpperLeft.Y = curBounds.Top;
                    }
                }
                else
                {
                    curBounds = new System.Drawing.Rectangle(0, 0, 0, 0);
                }

                if (graphicsObj != null)
                {
                    GraphicsPath grfxPath = graphicsObj.GraphicsPath;
                    if (grfxPath != null)
                    {
                        this.trackingPath.AddPath(grfxPath, false);
                    }
                }
                else if (nodeBounds != null)
                {
                    this.trackingPath.AddRectangle(curBounds);
                }

                // Get the constraining region for the current node and add it
                // to the constraining region for the tracker
                Region curRgnConstraint = null;
                if (nodeParent != null)
                {
                    curRgnConstraint = nodeParent.GetConstrainingRegion(curNode);
                    if (curRgnConstraint != null)
                    {
                        if (this.rgnConstraint == null)
                        {
                            this.rgnConstraint = curRgnConstraint.Clone();
                        }
                        else
                        {
                            this.rgnConstraint.Union(curRgnConstraint);
                        }
                    }
                }

                // Reset matrix stack
                Global.MatrixStack.Clear();
            }
        }
Example #8
0
        /// <summary>
        /// Executes the alignment command.
        /// </summary>
        /// <param name="cmdTarget">Unused</param>
        /// <returns>true if successful, otherwise false</returns>
        /// <remarks>
        /// This method iterates through each node and aligns them to the
        /// anchor node, which is always the first node in the list. The nodes
        /// are aligned either vertically or horizontally depending on the value
        /// of the <see cref="Syncfusion.Windows.Forms.Diagram.AlignCmd.Orientation"/> property.
        /// </remarks>
        public override bool Do(object cmdTarget)
        {
            IBounds2DF anchorBounds   = null;
            RectangleF rcAnchor       = new RectangleF(0, 0, 0, 0);
            PointF     ptAnchorCenter = new PointF(0, 0);
            IBounds2DF curBounds      = null;
            RectangleF rcCur;
            PointF     ptCurCenter;

            this.undoVerbs.Clear();

            foreach (INode curNode in this.Nodes)
            {
                if (anchorBounds == null)
                {
                    anchorBounds = curNode as IBounds2DF;
                    if (anchorBounds != null)
                    {
                        rcAnchor       = anchorBounds.Bounds;
                        ptAnchorCenter = Geometry.CenterPoint(rcAnchor);
                    }
                }
                else
                {
                    curBounds = curNode as IBounds2DF;

                    if (curBounds != null)
                    {
                        rcCur = curBounds.Bounds;

                        this.undoVerbs.Add(new SetBounds(curBounds, rcCur));

                        float offsetX = 0.0f;
                        float offsetY = 0.0f;

                        switch (this.orientation)
                        {
                        case BoxOrientation.Left:
                            offsetX = rcAnchor.Left - rcCur.Left;
                            break;

                        case BoxOrientation.Right:
                            offsetX = rcAnchor.Right - rcCur.Right;
                            break;

                        case BoxOrientation.Top:
                            offsetY = rcAnchor.Top - rcCur.Top;
                            break;

                        case BoxOrientation.Bottom:
                            offsetY = rcAnchor.Bottom - rcCur.Bottom;
                            break;

                        case BoxOrientation.Middle:
                            ptCurCenter = Geometry.CenterPoint(rcCur);
                            offsetY     = ptAnchorCenter.Y - ptCurCenter.Y;
                            break;

                        case BoxOrientation.Center:
                            ptCurCenter = Geometry.CenterPoint(rcCur);
                            offsetX     = ptAnchorCenter.X - ptCurCenter.X;
                            break;
                        }

                        rcCur.Offset(offsetX, offsetY);
                        curBounds.Bounds = rcCur;
                    }
                }
            }

            return(true);
        }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 public SetBounds(IBounds2DF boundsObj, RectangleF boundingRect)
 {
     this.boundsObj    = boundsObj;
     this.boundingRect = boundingRect;
 }
Example #10
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="cmdTarget"></param>
		/// <returns></returns>
		public override bool Do(object cmdTarget)
		{
			bool success = false;

			IBounds2DF curBounds = null;
			RectangleF rcCur;
			PointF ptCurCenter;
			float left = float.MaxValue;
			float right = float.MinValue;
			float top = float.MaxValue;
			float bottom = float.MinValue;
			float spacing = 0.0f;
			float curPos = 0.0f;
			float offset;
			ITransform curTransform = null;

			this.undoVerbs.Clear();

			int numNodes = this.Nodes.Count;

			if (numNodes >= 3)
			{
				foreach (INode curNode in this.Nodes)
				{
					curBounds = curNode as IBounds2DF;

					if (curBounds != null)
					{
						rcCur = curBounds.Bounds;
						ptCurCenter = Geometry.CenterPoint(rcCur);

						if (ptCurCenter.X < left)
						{
							left = ptCurCenter.X;
						}

						if (ptCurCenter.X > right)
						{
							right = ptCurCenter.X;
						}

						if (ptCurCenter.Y < top)
						{
							top = ptCurCenter.Y;
						}

						if (ptCurCenter.Y > bottom)
						{
							bottom = ptCurCenter.Y;
						}
					}
				}

				if (this.dir == SpacingDirection.Down)
				{
					spacing = (bottom - top) / (float) numNodes;
					curPos = top;
					foreach (INode curNode in this.Nodes)
					{
						curBounds = curNode as IBounds2DF;
						curTransform = curNode as ITransform;

						if (curBounds != null && curTransform != null)
						{
							rcCur = curBounds.Bounds;
							ptCurCenter = Geometry.CenterPoint(rcCur);
							offset = curPos - ptCurCenter.Y;
							curTransform.Translate(0.0f, offset);
							this.undoVerbs.Add(new TranslateNode(curTransform, 0.0f, -offset));
						}
						curPos += spacing;
					}
				}
				else
				{
					spacing = (right - left) / (float) numNodes;
					curPos = left;
					foreach (INode curNode in this.Nodes)
					{
						curBounds = curNode as IBounds2DF;
						curTransform = curNode as ITransform;

						if (curBounds != null && curTransform != null)
						{
							rcCur = curBounds.Bounds;
							ptCurCenter = Geometry.CenterPoint(rcCur);
							offset = curPos - ptCurCenter.X;
							curTransform.Translate(offset, 0.0f);
							this.undoVerbs.Add(new TranslateNode(curTransform, -offset, 0.0f));
						}
						curPos += spacing;
					}
				}

				success = true;
			}

			return success;
		}
Example #11
0
        private RectangleF CalcNewBounds(IBounds2DF nodeBounds)
        {
            if (nodeBounds == null)
            {
                throw new EInvalidParameter();
            }

            RectangleF rcCur = nodeBounds.Bounds;
            float      left;
            float      top;
            float      width;
            float      height;
            float      dx = this.offset.Width;
            float      dy = this.offset.Height;

            switch (this.posHandle)
            {
            case BoxPosition.TopLeft:
                left   = rcCur.Left - dx;
                top    = rcCur.Top - dy;
                width  = rcCur.Right - left;
                height = rcCur.Bottom - top;
                break;

            case BoxPosition.TopCenter:
                left   = rcCur.Left;
                top    = rcCur.Top - dy;
                width  = rcCur.Width;
                height = rcCur.Bottom - top;
                break;

            case BoxPosition.TopRight:
                left   = rcCur.Left;
                top    = rcCur.Top - dy;
                width  = rcCur.Width + dx;
                height = rcCur.Bottom - top;
                break;

            case BoxPosition.MiddleLeft:
                left   = rcCur.Left - dx;
                top    = rcCur.Top;
                width  = rcCur.Right - left;
                height = rcCur.Height;
                break;

            case BoxPosition.MiddleRight:
                left   = rcCur.Left;
                top    = rcCur.Top;
                width  = rcCur.Width + dx;
                height = rcCur.Height;
                break;

            case BoxPosition.BottomLeft:
                left   = rcCur.Left - dx;
                top    = rcCur.Top;
                width  = rcCur.Right - left;
                height = rcCur.Height + dy;
                break;

            case BoxPosition.BottomCenter:
                left   = rcCur.Left;
                top    = rcCur.Top;
                width  = rcCur.Width;
                height = rcCur.Height + dy;
                break;

            case BoxPosition.BottomRight:
                left   = rcCur.Left;
                top    = rcCur.Top;
                width  = rcCur.Width + dx;
                height = rcCur.Height + dy;
                break;

            default:
                left   = rcCur.Left;
                top    = rcCur.Top;
                width  = rcCur.Width;
                height = rcCur.Height;
                break;
            }

            return(new RectangleF(left, top, width, height));
        }