Group shape.
Inheritance: Core2D.Shape.BaseShape
Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="XGroup"/> instance.
        /// </summary>
        /// <param name="name">The group name.</param>
        /// <param name="shapes">The shapes collection.</param>
        /// <param name="source">The source shapes collection.</param>
        /// <returns>The new instance of the <see cref="XGroup"/> class.</returns>
        public static XGroup Group(string name, IEnumerable <BaseShape> shapes, IList <BaseShape> source = null)
        {
            var group = XGroup.Create(name);

            if (shapes != null)
            {
                foreach (var shape in shapes)
                {
                    if (shape is XPoint)
                    {
                        group.AddConnectorAsNone(shape as XPoint);
                    }
                    else
                    {
                        group.AddShape(shape);
                    }

                    if (source != null)
                    {
                        source.Remove(shape);
                    }
                }
            }

            if (source != null)
            {
                source.Add(group);
            }

            return(group);
        }
Exemplo n.º 2
0
        public void ShapesProperties_Gets_Shapes_And_Connectors_Properties()
        {
            var target = new XGroup();

            var shape = new Class1();
            shape.Data.Properties = shape.Data.Properties.Add(new XProperty());
            target.Shapes = target.Shapes.Add(shape);

            var point = new XPoint();
            point.Data.Properties = point.Data.Properties.Add(new XProperty());
            target.Connectors = target.Connectors.Add(point);

            Assert.Equal(2, target.ShapesProperties.Length);
        }
Exemplo n.º 3
0
        public void ShapesProperties_Cache_Should_Reset_After_Connectors_Updated()
        {
            var target = new XGroup();

            var point1 = new XPoint();
            point1.Data.Properties = point1.Data.Properties.Add(new XProperty());
            target.Connectors = target.Connectors.Add(point1);

            Assert.Equal(1, target.ShapesProperties.Length);

            var point2 = new XPoint();
            point2.Data.Properties = point2.Data.Properties.Add(new XProperty());
            target.Connectors = target.Connectors.Add(point2);

            Assert.Equal(2, target.ShapesProperties.Length);
        }
Exemplo n.º 4
0
        public void ShapesProperties_Cache_Should_Reset_After_Shapes_Updated()
        {
            var target = new XGroup();

            var shape1 = new Class1();
            shape1.Data.Properties = shape1.Data.Properties.Add(new XProperty());
            target.Shapes = target.Shapes.Add(shape1);

            Assert.Equal(1, target.ShapesProperties.Length);

            var shape2 = new Class1();
            shape2.Data.Properties = shape2.Data.Properties.Add(new XProperty());
            target.Shapes = target.Shapes.Add(shape2);

            Assert.Equal(2, target.ShapesProperties.Length);
        }
Exemplo n.º 5
0
        public void GetPoints_Returns_Shapes_And_Connector_Points()
        {
            var target = new XGroup();

            var text = new XText();
            text.Data.Properties = text.Data.Properties.Add(new XProperty());
            target.Shapes = target.Shapes.Add(text);

            var point = new XPoint();
            point.Data.Properties = point.Data.Properties.Add(new XProperty());
            target.Connectors = target.Connectors.Add(point);

            Assert.Equal(3, target.GetPoints().Count());
        }
Exemplo n.º 6
0
 public void Connectors_Not_Null()
 {
     var target = new XGroup();
     Assert.NotNull(target.Connectors);
 }
Exemplo n.º 7
0
 public void Shapes_Not_Null()
 {
     var target = new XGroup();
     Assert.NotNull(target.Shapes);
 }
Exemplo n.º 8
0
        public void Ungroup_Shape_Remove_And_Add_To_Source()
        {
            var shape = new Class1();
            var point1 = new XPoint();
            var point2 = new XPoint();
            var point3 = new XPoint();

            var target = new XGroup();

            target.AddShape(shape);
            target.AddConnectorAsNone(point1);
            target.AddConnectorAsInput(point2);
            target.AddConnectorAsOutput(point3);

            var source = new List<BaseShape> { target };

            XGroup.Ungroup(target, source);

            Assert.Contains(shape, source);
            Assert.Contains(point1, source);
            Assert.Contains(point2, source);
            Assert.Contains(point3, source);
            Assert.Equal(4, source.Count);

            Assert.False(point1.State.Flags.HasFlag(ShapeStateFlags.Connector | ShapeStateFlags.None));
            Assert.False(point2.State.Flags.HasFlag(ShapeStateFlags.Connector | ShapeStateFlags.Input));
            Assert.False(point3.State.Flags.HasFlag(ShapeStateFlags.Connector | ShapeStateFlags.Output));

            Assert.True(shape.State.Flags.HasFlag(ShapeStateFlags.Standalone));
            Assert.True(point1.State.Flags.HasFlag(ShapeStateFlags.Standalone));
            Assert.True(point2.State.Flags.HasFlag(ShapeStateFlags.Standalone));
            Assert.True(point3.State.Flags.HasFlag(ShapeStateFlags.Standalone));
        }
Exemplo n.º 9
0
 public void Inherits_From_BaseShape()
 {
     var target = new XGroup();
     Assert.True(target is BaseShape);
 }
Exemplo n.º 10
0
        public void AddConnectorAsOutput_Add_Point_To_Connectors_As_Output()
        {
            var target = new XGroup();
            var point = new XPoint();

            target.AddConnectorAsOutput(point);

            Assert.Equal(point.Owner, target);
            Assert.True(point.State.Flags.HasFlag(ShapeStateFlags.Connector | ShapeStateFlags.Output));
            Assert.False(point.State.Flags.HasFlag(ShapeStateFlags.Standalone));
            Assert.Contains(point, target.Connectors);
            Assert.Equal(1, target.Connectors.Length);
        }
Exemplo n.º 11
0
        public void AddShape_Add_Shape_To_Shapes()
        {
            var target = new XGroup();
            var shape = new Class1();

            target.AddShape(shape);

            Assert.Equal(shape.Owner, target);
            Assert.False(shape.State.Flags.HasFlag(ShapeStateFlags.Standalone));
            Assert.Contains(shape, target.Shapes);
            Assert.Equal(1, target.Shapes.Length);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="group"></param>
        /// <param name="v"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static BaseShape HitTestGroup(XGroup group, Vector2 v, double threshold, double dx, double dy)
        {
            foreach (var connector in group.Connectors.Reverse())
            {
                if (ShapeBounds.GetPointBounds(connector, threshold, dx, dy).Contains(v))
                {
                    return connector;
                }
            }

            var result = HitTest(group.Shapes.Reverse(), v, threshold, dx, dy);
            if (result != null)
            {
                return group;
            }

            return null;
        }
Exemplo n.º 13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="group"></param>
        /// <param name="rect"></param>
        /// <param name="selection"></param>
        /// <param name="selected"></param>
        /// <param name="threshold"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns></returns>
        public static bool HitTestGroup(XGroup group, Rect2 rect, Vector2[] selection, ISet<BaseShape> selected, double threshold, double dx, double dy)
        {
            if (HitTest(group.Shapes.Reverse(), rect, selection, null, threshold, dx, dy) == true)
            {
                if (selected != null)
                {
                    selected.Add(group);
                    return false;
                }
                else
                {
                    return true;
                }
            }

            return false;
        }