Esempio n. 1
0
    public PointShapeViewModel?TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
    {
        if (shape is not PointShapeViewModel point)
        {
            throw new ArgumentNullException(nameof(shape));
        }

        // ReSharper disable once CompareOfFloatsByEqualityOperator
        if (point.State.HasFlag(ShapeStateFlags.Size) && scale != 1.0)
        {
            if (Point2.FromXY(point.X, point.Y).ExpandToRect(radius / scale).Contains(target.X, target.Y))
            {
                return(point);
            }
        }
        else
        {
            if (Point2.FromXY(point.X, point.Y).ExpandToRect(radius).Contains(target.X, target.Y))
            {
                return(point);
            }
        }

        return(null);
    }
Esempio n. 2
0
        public void Group_Shapes_Do_Not_Update_Source()
        {
            var shape1 = new Class1()
            {
                State = ShapeStateFlags.Default
            };
            var shape2 = new Class1()
            {
                State = ShapeStateFlags.Default
            };
            var point1 = _factory.CreatePointShape();
            var point2 = _factory.CreatePointShape();

            var shapes = new BaseShapeViewModel[] { shape1, shape2, point1, point2 };
            var source = shapes.ToList();

            var target = _factory.CreateGroupShape("g");

            target.Group(shapes, null);

            Assert.Contains(shape1, source);
            Assert.Contains(shape2, source);
            Assert.Contains(point1, source);
            Assert.Contains(point2, source);

            var count = source.Count;

            Assert.Equal(4, count);
        }
Esempio n. 3
0
        public PointShapeViewModel TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is CubicBezierShapeViewModel cubic))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var pointHitTest = registered[typeof(PointShapeViewModel)];

            if (pointHitTest.TryToGetPoint(cubic.Point1, target, radius, scale, registered) is { })
Esempio n. 4
0
    public PointShapeViewModel TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
    {
        if (shape is not EllipseShapeViewModel ellipse)
        {
            throw new ArgumentNullException(nameof(shape));
        }

        var pointHitTest = registered[typeof(PointShapeViewModel)];

        if (pointHitTest.TryToGetPoint(ellipse.TopLeft, target, radius, scale, registered) is { })
Esempio n. 5
0
        public PointShapeViewModel TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is GroupShapeViewModel group))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var pointHitTest = registered[typeof(PointShapeViewModel)];

            foreach (var groupPoint in group.Connectors.Reverse())
            {
                if (pointHitTest.TryToGetPoint(groupPoint, target, radius, scale, registered) is { })
Esempio n. 6
0
        public ShapeBox(BaseShapeViewModel shape)
        {
            _shapeViewModel = shape;

            Points = new List <PointShapeViewModel>();

            _shapeViewModel.GetPoints(Points);

            Bounds = new Box();

            Update();
        }
    private static bool IsPointMovable(BaseShapeViewModel shape, PointShapeViewModel point)
    {
        if (point.State.HasFlag(ShapeStateFlags.Locked) || (point.Owner is BaseShapeViewModel ower && ower.State.HasFlag(ShapeStateFlags.Locked)))
        {
            return(false);
        }

        if (point.State.HasFlag(ShapeStateFlags.Connector) && point.Owner != shape)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 8
0
    public static bool IsPointMovable(PointShapeViewModel point, BaseShapeViewModel parent)
    {
        if (point.State.HasFlag(ShapeStateFlags.Locked) || (point.Owner is BaseShapeViewModel owner && owner.State.HasFlag(ShapeStateFlags.Locked)))
        {
            return(false);
        }

        if (point.State.HasFlag(ShapeStateFlags.Connector) && point.Owner != null && point.Owner != parent)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 9
0
 public bool Overlaps(BaseShapeViewModel shape, Rect2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
 {
     if (!(shape is PointShapeViewModel point))
     {
         throw new ArgumentNullException(nameof(shape));
     }
     if (point.State.HasFlag(ShapeStateFlags.Size) && scale != 1.0)
     {
         return(Point2.FromXY(point.X, point.Y).ExpandToRect(radius / scale).IntersectsWith(target));
     }
     else
     {
         return(Point2.FromXY(point.X, point.Y).ExpandToRect(radius).IntersectsWith(target));
     }
 }
Esempio n. 10
0
        public PointShapeViewModel TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is PathShapeViewModel path))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            var pointHitTest = registered[typeof(PointShapeViewModel)];

            _points.Clear();
            path.GetPoints(_points);

            foreach (var pathPoint in _points)
            {
                if (pointHitTest.TryToGetPoint(pathPoint, target, radius, scale, registered) is { })
        private void ToGeometryDrawing(BaseShapeViewModel shape, StringBuilder sb, IPathConverter converter)
        {
            if (shape is GroupShapeViewModel group)
            {
                foreach (var child in group.Shapes)
                {
                    ToGeometryDrawing(child, sb, converter);
                }
                return;
            }

            if (shape.IsFilled)
            {
                var path = converter.ToFillPathShape(shape);
                if (path is { })
Esempio n. 12
0
    public PointShapeViewModel?TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
    {
        if (shape is not LineShapeViewModel line)
        {
            throw new ArgumentNullException(nameof(shape));
        }

        if (line.Start is null || line.End is null)
        {
            return(null);
        }

        var pointHitTest = registered[typeof(PointShapeViewModel)];

        if (pointHitTest.TryToGetPoint(line.Start, target, radius, scale, registered) is { })
Esempio n. 13
0
 public BoxDecoratorViewModel(IServiceProvider serviceProvider) : base(serviceProvider)
 {
     _factory             = serviceProvider.GetService <IFactory>();
     _sizeLarge           = 4m;
     _sizeSmall           = 4m;
     _rotateDistance      = -16.875m;
     _handleStyle         = _factory.CreateShapeStyle("Handle", 255, 0, 191, 255, 255, 255, 255, 255, 2.0);
     _boundsStyle         = _factory.CreateShapeStyle("Bounds", 255, 0, 191, 255, 255, 255, 255, 255, 1.0);
     _selectedHandleStyle = _factory.CreateShapeStyle("SelectedHandle", 255, 0, 191, 255, 255, 0, 191, 255, 2.0);
     _selectedBoundsStyle = _factory.CreateShapeStyle("SelectedBounds", 255, 0, 191, 255, 255, 255, 255, 255, 1.0);
     _rotateHandle        = _factory.CreateEllipseShape(0, 0, 0, 0, _handleStyle, true, true, name: "_rotateHandle");
     _topLeftHandle       = _factory.CreateEllipseShape(0, 0, 0, 0, _handleStyle, true, true, name: "_topLeftHandle");
     _topRightHandle      = _factory.CreateEllipseShape(0, 0, 0, 0, _handleStyle, true, true, name: "_topRightHandle");
     _bottomLeftHandle    = _factory.CreateEllipseShape(0, 0, 0, 0, _handleStyle, true, true, name: "_bottomLeftHandle");
     _bottomRightHandle   = _factory.CreateEllipseShape(0, 0, 0, 0, _handleStyle, true, true, name: "_bottomRightHandle");
     _topHandle           = _factory.CreateRectangleShape(0, 0, 0, 0, _handleStyle, true, true, name: "_topHandle");
     _bottomHandle        = _factory.CreateRectangleShape(0, 0, 0, 0, _handleStyle, true, true, name: "_bottomHandle");
     _leftHandle          = _factory.CreateRectangleShape(0, 0, 0, 0, _handleStyle, true, true, name: "_leftHandle");
     _rightHandle         = _factory.CreateRectangleShape(0, 0, 0, 0, _handleStyle, true, true, name: "_rightHandle");
     _boundsHandle        = _factory.CreateRectangleShape(0, 0, 0, 0, _boundsStyle, true, false, name: "_boundsHandle");
     _rotateLine          = _factory.CreateLineShape(0, 0, 0, 0, _boundsStyle, true, name: "_rotateLine");
     _handles             = new List <BaseShapeViewModel>
     {
         //_rotateHandle,
         _topLeftHandle,
         _topRightHandle,
         _bottomLeftHandle,
         _bottomRightHandle,
         _topHandle,
         _bottomHandle,
         _leftHandle,
         _rightHandle,
         _boundsHandle,
         //_rotateLine
     };
     _currentHandle            = null;
     _rotateHandle.State      |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _topLeftHandle.State     |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _topRightHandle.State    |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _bottomLeftHandle.State  |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _bottomRightHandle.State |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _topHandle.State         |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _bottomHandle.State      |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _leftHandle.State        |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _rightHandle.State       |= ShapeStateFlags.Size | ShapeStateFlags.Thickness;
     _boundsHandle.State      |= ShapeStateFlags.Thickness;
     _rotateLine.State        |= ShapeStateFlags.Thickness;
 }
Esempio n. 14
0
    public void SetShapeName(BaseShapeViewModel shape, IEnumerable <BaseShapeViewModel>?source = null)
    {
        if (_project is null)
        {
            return;
        }
        var input  = source?.ToList() ?? _project.GetAllShapes().ToList();
        var shapes = input.Where(s => s.GetType() == shape.GetType() && s != shape).ToList();
        var count  = shapes.Count + 1;
        var update = string.IsNullOrEmpty(shape.Name) || input.Any(x => x != shape && x.Name == shape.Name);

        if (update)
        {
            shape.Name = shape.GetType().Name.Replace("ShapeViewModel", " ") + count;
        }
    }
Esempio n. 15
0
        public PointShapeViewModel TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale, IDictionary <Type, IBounds> registered)
        {
            if (!(shape is PointShapeViewModel point))
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (point.State.HasFlag(ShapeStateFlags.Size) && scale != 1.0)
            {
                if (Point2.FromXY(point.X, point.Y).ExpandToRect(radius / scale).Contains(target.X, target.Y))
                {
                    return(point);
                }
            }
            else
            {
                if (Point2.FromXY(point.X, point.Y).ExpandToRect(radius).Contains(target.X, target.Y))
                {
                    return(point);
                }
            }

            return(null);
        }
Esempio n. 16
0
 public void Finalize(BaseShapeViewModel shape)
 {
 }
Esempio n. 17
0
 public void Move(BaseShapeViewModel shape)
 {
 }
Esempio n. 18
0
 public static void AddShape(this GroupShapeViewModel group, BaseShapeViewModel shape)
 {
     shape.Owner  = group;
     shape.State &= ~ShapeStateFlags.Standalone;
     group.Shapes = group.Shapes.Add(shape);
 }
Esempio n. 19
0
 public PointShapeViewModel?TryToGetPoint(BaseShapeViewModel shape, Point2 target, double radius, double scale)
 {
     return(Registered[shape.TargetType].TryToGetPoint(shape, target, radius, scale, Registered));
 }