コード例 #1
0
ファイル: RectangleD.cs プロジェクト: ckimpel/FSE-2011-PDE
 public RectangleD(PointD location, SizeD size)
 {
     x      = location.X;
     y      = location.Y;
     width  = size.Width;
     height = size.Height;
 }
コード例 #2
0
ファイル: RectangleD.cs プロジェクト: ckimpel/FSE-2011-PDE
 /// <summary>
 /// == operator.
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <returns></returns>
 public static bool operator ==(RectangleD left, RectangleD right)
 {
     if (SizeD.FuzzEqual(left.X, right.X, SizeD.FuzzDistance) && SizeD.FuzzEqual(left.Y, right.Y, SizeD.FuzzDistance) && SizeD.FuzzEqual(left.Width, right.Width, SizeD.FuzzDistance))
     {
         return(SizeD.FuzzEqual(left.Height, right.Height, SizeD.FuzzDistance));
     }
     return(false);
 }
コード例 #3
0
ファイル: PointD.cs プロジェクト: ckimpel/FSE-2011-PDE
 /// <summary>
 /// == Operator.
 /// </summary>
 public static bool operator ==(PointD left, PointD right)
 {
     if (SizeD.FuzzEqual(left.X, right.X, SizeD.FuzzDistance))
     {
         return(SizeD.FuzzEqual(left.Y, right.Y, SizeD.FuzzDistance));
     }
     return(false);
 }
コード例 #4
0
 /// <summary>
 /// == Operator.
 /// </summary>
 public static bool operator ==(SizeD size1, SizeD size2)
 {
     if (FuzzEqual(size1.Width, size2.Width, SizeD.FuzzDistance))
     {
         return(SizeD.FuzzEqual(size1.Height, size2.Height, SizeD.FuzzDistance));
     }
     return(false);
 }
コード例 #5
0
ファイル: PointD.cs プロジェクト: ckimpel/FSE-2011-PDE
        public override bool Equals(object obj)
        {
            if (!(obj is PointD))
            {
                return(false);
            }
            PointD pointD = (PointD)obj;

            if (SizeD.FuzzEqual(X, pointD.X, SizeD.FuzzDistance) && SizeD.FuzzEqual(Y, pointD.Y, SizeD.FuzzDistance))
            {
                return(pointD.GetType().Equals(this.GetType()));
            }
            return(false);
        }
コード例 #6
0
        /// <summary>
        /// Equals implementation.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is SizeD))
            {
                return(false);
            }
            SizeD sizeD = (SizeD)obj;

            if (SizeD.FuzzEqual(Width, sizeD.Width, SizeD.FuzzDistance) && SizeD.FuzzEqual(Height, sizeD.Height, SizeD.FuzzDistance))
            {
                return(sizeD.GetType().Equals(this.GetType()));
            }
            return(false);
        }
コード例 #7
0
ファイル: RectangleD.cs プロジェクト: ckimpel/FSE-2011-PDE
        /// <summary>
        /// Equals implementation.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is RectangleD))
            {
                return(false);
            }

            RectangleD rectangleD = (RectangleD)obj;

            if (SizeD.FuzzEqual(X, rectangleD.X, SizeD.FuzzDistance) && SizeD.FuzzEqual(Y, rectangleD.Y, SizeD.FuzzDistance) && SizeD.FuzzEqual(Width, rectangleD.Width, SizeD.FuzzDistance))
            {
                return(SizeD.FuzzEqual(Height, rectangleD.Height, SizeD.FuzzDistance));
            }
            return(false);
        }
コード例 #8
0
        /// <summary>
        /// Sets the size of this item and propagates it to the hosted shape element if allowed.
        /// </summary>
        /// <param name="newWidth">Size to apply.</param>
        /// <remarks>
        /// This function needs to be called withing a modeling transaction.
        /// </remarks>
        public virtual void SetSize(SizeD newSize)
        {
            SizeD oldSize = this.Size;

            this.Size = newSize;

            UpdateAbsoluteLocation();
            ResizeParentIfRequired();

            // for children: we need to change position if they are left of right side of this shape
            foreach (NodeShape shape in this.RelativeChildren)
            {
                if (shape.MovementBehaviour == ShapeMovementBehaviour.PositionRelativeToParent)
                {
                    PointD newPosition = new PointD(shape.Location.X, shape.Location.Y);
                    if (newPosition.X >= oldSize.Width)
                    {
                        newPosition.X += this.Size.Width - oldSize.Width;
                    }
                    if (newPosition.Y >= oldSize.Height)
                    {
                        newPosition.Y += this.Size.Height - oldSize.Height;
                    }

                    shape.SetLocationOnParentChange(newPosition);
                }
                else if (shape.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent)
                {
                    if (newSize.Width != oldSize.Width && shape.PlacementSide == PortPlacement.Right)
                    {
                        shape.SetLocationOnParentChange(shape.Location);
                    }
                    else if (newSize.Height != oldSize.Height && shape.PlacementSide == PortPlacement.Bottom)
                    {
                        shape.SetLocationOnParentChange(shape.Location);
                    }
                }
            }

            if (this.IsRelativeChildShape)
            {
                if (this.MovementBehaviour == ShapeMovementBehaviour.PositionOnEdgeOfParent)
                {
                    // size of this element changed, need to reposition it on the edge of the parent element
                    this.SetLocationOnParentChange(this.Location);
                }
            }
        }
        protected BaseDiagramItemElementViewModel(ViewModelStore viewModelStore, DiagramSurfaceViewModel diagram, NodeShape shapeElement)
            : base(viewModelStore, diagram, shapeElement)
        {
            this.itemLocation = shapeElement.Location;
            this.itemSize = shapeElement.Size;
            
            this.parentItem = null;

            this.nestedChildItems = new ObservableCollection<BaseDiagramItemElementViewModel>();
            this.nestedChildItemsRO = new ReadOnlyObservableCollection<BaseDiagramItemElementViewModel>(nestedChildItems);

            this.relativeChildItems = new ObservableCollection<BaseDiagramItemElementViewModel>();
            this.relativeChildItemsRO = new ReadOnlyObservableCollection<BaseDiagramItemElementViewModel>(relativeChildItems);

            Subscribe();
        }
コード例 #10
0
        /// <summary>
        /// Resizes the parent of this item if this is required.
        /// </summary>
        /// <remarks>
        /// This function needs to be called withing a modeling transaction.
        /// </remarks>
        public virtual void ResizeParentIfRequired()
        {
            if (this.Parent != null && !this.IsRelativeChildShape)
            {
                RectangleD bounds     = this.Bounds;
                SizeD      parentSize = this.Parent.Size;

                SizeD size = new SizeD(
                    Math.Max(parentSize.Width, bounds.Right),
                    Math.Max(parentSize.Height, bounds.Bottom));

                if (parentSize.Width < size.Width || parentSize.Height < size.Height)
                {
                    this.Parent.SetSize(
                        new SizeD(this.Parent.Size.Width + (size.Width - parentSize.Width) + 3.0,
                                  this.Parent.Size.Height + (size.Height - parentSize.Height) + 3.0));
                }
            }
        }
コード例 #11
0
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            if (e.ModelElement == null)
            {
                return;
            }

            if (e.ModelElement.Store.InSerializationTransaction)
            {
                return;
            }

            NodeShape nodeShape = e.ModelElement as NodeShape;

            if (nodeShape != null)
            {
                if (e.DomainProperty.Id == NodeShape.LocationDomainPropertyId)
                {
                    PointD oldLocation = (PointD)e.OldValue;
                    PointD newLocation = (PointD)e.NewValue;

                    nodeShape.CorrectLinkShapesOnLocationChanged(oldLocation, newLocation);
                }
                else if (e.DomainProperty.Id == NodeShape.SizeDomainPropertyId)
                {
                    SizeD oldSize = (SizeD)e.OldValue;
                    SizeD newSize = (SizeD)e.NewValue;

                    if (oldSize.Width != 0.0 && oldSize.Height != 0.0)
                    {
                        nodeShape.CorrectLinkShapesOnSizeChanged(oldSize, newSize);
                    }
                }
            }
        }
コード例 #12
0
 /// <summary>
 /// Substracts the specified size from the specified point.
 /// </summary>
 /// <param name="point">Point to substract the size from.</param>
 /// <param name="size">Size to substract.</param>
 /// <returns>Returns the result of subtracting specified Size from the specified Point.</returns>
 public static PointD Subtract(PointD point, SizeD size)
 {
     return new PointD(point.X - size.Width, point.Y - size.Height);
 }
コード例 #13
0
 /// <summary>
 /// Adds the specified size to the specified point.
 /// </summary>
 /// <param name="point">Point to add the size to.</param>
 /// <param name="size">Size to add.</param>
 /// <returns>Point with the added size.</returns>
 public static PointD Add(PointD point, SizeD size)
 {
     return new PointD(point.X + size.Width, point.Y + size.Height);
 }
コード例 #14
0
 /// <summary>
 /// Constror.
 /// </summary>
 /// <param name="size"></param>
 public SizeD(SizeD size)
 {
     width = size.width;
     height = size.height;
 }
コード例 #15
0
 /// <summary>
 /// Constror.
 /// </summary>
 /// <param name="size"></param>
 public SizeD(SizeD size)
 {
     width  = size.width;
     height = size.height;
 }
コード例 #16
0
ファイル: PointD.cs プロジェクト: ckimpel/FSE-2011-PDE
 /// <summary>
 /// Substracts the specified size from the specified point.
 /// </summary>
 /// <param name="point">Point to substract the size from.</param>
 /// <param name="size">Size to substract.</param>
 /// <returns>Returns the result of subtracting specified Size from the specified Point.</returns>
 public static PointD Subtract(PointD point, SizeD size)
 {
     return(new PointD(point.X - size.Width, point.Y - size.Height));
 }
コード例 #17
0
ファイル: PointD.cs プロジェクト: ckimpel/FSE-2011-PDE
 /// <summary>
 /// Adds the specified size to the specified point.
 /// </summary>
 /// <param name="point">Point to add the size to.</param>
 /// <param name="size">Size to add.</param>
 /// <returns>Point with the added size.</returns>
 public static PointD Add(PointD point, SizeD size)
 {
     return(new PointD(point.X + size.Width, point.Y + size.Height));
 }
 /// <summary>
 /// Sets the size of this item and propagates it to the hosted shape element if allowed.
 /// </summary>
 /// <param name="newSize">Size to apply.</param>
 /// <remarks>
 /// This function needs to be called withing a modeling transaction.
 /// </remarks>
 public virtual void SetSize(SizeD newSize)
 {
     if (this.ShapeElement.Size != newSize)
         this.ShapeElement.SetSize(newSize);
 }
コード例 #19
0
        /// <summary>
        /// Corret link shapes placement.
        /// </summary>
        /// <param name="sizeOld"></param>
        /// <param name="sizeNew"></param>
        internal void CorrectLinkShapesOnSizeChanged(SizeD sizeOld, SizeD sizeNew)
        {
            // List<LinkShape> shapesToLayout = new List<LinkShape>();

            double widthChange  = (sizeNew.Width - sizeOld.Width);
            double heightChange = (sizeNew.Height - sizeOld.Height);

            double widthFactor  = sizeNew.Width / sizeOld.Width;
            double heightFactor = sizeNew.Height / sizeOld.Height;

            foreach (SourceAnchor anchor in this.SourceAnchors)
            {
                if (anchor.FromShape == null)
                {
                    continue;
                }

                if (anchor.IsDeleted || anchor.IsDeleting)
                {
                    continue;
                }

                NodeShape shape     = anchor.FromShape;
                LinkShape linkShape = anchor.LinkShape;

                double newLeft = (anchor.AbsoluteLocation.X - shape.AbsoluteLocation.X) * widthFactor + shape.AbsoluteLocation.X;
                double newTop  = (anchor.AbsoluteLocation.Y - shape.AbsoluteLocation.Y) * heightFactor + shape.AbsoluteLocation.Y;

                if (linkShape.LinkPlacementStart == LinkPlacement.Bottom)
                {
                    anchor.AbsoluteLocation = new PointD(newLeft, anchor.AbsoluteLocation.Y + heightChange);
                }
                else if (linkShape.LinkPlacementStart == LinkPlacement.Top)
                {
                    anchor.AbsoluteLocation = new PointD(newLeft, anchor.AbsoluteLocation.Y);
                }
                else if (linkShape.LinkPlacementStart == LinkPlacement.Right)
                {
                    anchor.AbsoluteLocation = new PointD(anchor.AbsoluteLocation.X + widthChange, newTop);
                }
                else if (linkShape.LinkPlacementStart == LinkPlacement.Left)
                {
                    anchor.AbsoluteLocation = new PointD(anchor.AbsoluteLocation.X, newTop);
                }

                //if (!shapesToLayout.Contains(anchor.LinkShape))
                //    shapesToLayout.Add(anchor.LinkShape);
            }

            foreach (TargetAnchor anchor in this.TargetAnchors)
            {
                if (anchor.ToShape == null)
                {
                    continue;
                }

                if (anchor.IsDeleted || anchor.IsDeleting)
                {
                    continue;
                }

                NodeShape shape     = anchor.ToShape;
                LinkShape linkShape = anchor.LinkShape;

                double newLeft = (anchor.AbsoluteLocation.X - shape.AbsoluteLocation.X) * widthFactor + shape.AbsoluteLocation.X;
                double newTop  = (anchor.AbsoluteLocation.Y - shape.AbsoluteLocation.Y) * heightFactor + shape.AbsoluteLocation.Y;

                if (linkShape.LinkPlacementEnd == LinkPlacement.Bottom)
                {
                    anchor.AbsoluteLocation = new PointD(newLeft, anchor.AbsoluteLocation.Y + heightChange);
                }
                else if (linkShape.LinkPlacementEnd == LinkPlacement.Top)
                {
                    anchor.AbsoluteLocation = new PointD(newLeft, anchor.AbsoluteLocation.Y);
                }
                else if (linkShape.LinkPlacementEnd == LinkPlacement.Right)
                {
                    anchor.AbsoluteLocation = new PointD(anchor.AbsoluteLocation.X + widthChange, newTop);
                }
                else if (linkShape.LinkPlacementEnd == LinkPlacement.Left)
                {
                    anchor.AbsoluteLocation = new PointD(anchor.AbsoluteLocation.X, newTop);
                }

                //if (!shapesToLayout.Contains(anchor.LinkShape))
                //   shapesToLayout.Add(anchor.LinkShape);
            }

            //foreach (LinkShape s in shapesToLayout)
            //    s.Layout(FixedGeometryPoints.SourceAndTarget);
        }
        /// <summary>
        /// Called whenever the size of the hosted shape changes.
        /// </summary>
        /// <param name="args"></param>
        protected virtual void OnSizeChanged(ElementPropertyChangedEventArgs args)
        {
            if (this.Size != (SizeD)args.NewValue)
            {
                SizeD oldSize = this.itemSize;
                this.itemSize = (SizeD)args.NewValue;

                if (oldSize.Width != this.itemSize.Width || oldSize.Height != this.itemSize.Height)
                {
                    OnPropertyChanged("Size");

                    if (oldSize.Width != this.itemSize.Width)
                        OnPropertyChanged("Width");

                    if (oldSize.Height != this.itemSize.Height)
                        OnPropertyChanged("Height");
                }
            }
        }