Exemple #1
0
        public IGroupShape AddShape(IGroup group, PointF position, SizeF size)
        {
            if (group == null)
            {
                throw new ArgumentNullException(nameof(group));
            }

            IGroupShape result = null;

            if (GetGroupShape(group.Id) == null && Instance is IThreatModelChild child)
            {
                if (_groups == null)
                {
                    _groups = new List <IGroupShape>();
                }
                result = new GroupShape(child.Model, group)
                {
                    Position = position,
                    Size     = size
                };
                _groups.Add(result);
                if (Instance is IDirty dirtyObject)
                {
                    dirtyObject.SetDirty();
                }
                if (Instance is IGroupShapesContainer container)
                {
                    _groupShapeAdded?.Invoke(container, result);
                }
            }

            return(result);
        }
Exemple #2
0
 private void GroupShapeAdded(IGroupShapesContainer container, IGroupShape groupShape)
 {
     if (groupShape?.Identity is ITrustBoundary trustBoundary)
     {
         HandleGroupShapeEvent(trustBoundary);
     }
 }
        public static void Run()
        {
            //ExStart:CreateScalingFactorThumbnail
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Prseetation class
            using (Presentation pres = new Presentation())
            {
                // Get the first slide
                ISlide sld = pres.Slides[0];

                // Accessing the shape collection of slides
                IShapeCollection slideShapes = sld.Shapes;

                // Adding a group shape to the slide
                IGroupShape groupShape = slideShapes.AddGroupShape();

                // Adding shapes inside added group shape
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 100, 100, 100);
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 500, 100, 100, 100);
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 300, 100, 100);
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 500, 300, 100, 100);

                // Adding group shape frame
                groupShape.Frame = new ShapeFrame(100, 300, 500, 40, NullableBool.False, NullableBool.False, 0);

                // Write the PPTX file to disk
                pres.Save(dataDir + "GroupShape_out.pptx", SaveFormat.Pptx);
            }
            //ExEnd:CreateScalingFactorThumbnail
        }
Exemple #4
0
        public void XAndY_ReturnXAndYAxesShapeCoordinatesOnTheSlide()
        {
            // Arrange
            IShape      shapeExCase1 = _fixture.Pre021.Slides[3].Shapes.First(sp => sp.Id == 2);
            IShape      shapeExCase2 = _fixture.Pre008.Slides[0].Shapes.First(sp => sp.Id == 3);
            IShape      shapeExCase3 = _fixture.Pre006.Slides[0].Shapes.First(sp => sp.Id == 2);
            IGroupShape groupShape   = (IGroupShape)_fixture.Pre009.Slides[1].Shapes.First(sp => sp.Id == 7);
            IShape      shapeExCase4 = groupShape.Shapes.First(sp => sp.Id.Equals(5));
            IShape      shapeExCase5 = _fixture.Pre018.Slides[0].Shapes.First(sp => sp.Id == 7);
            IShape      shapeExCase6 = _fixture.Pre009.Slides[1].Shapes.First(sp => sp.Id == 9);
            IShape      shapeExCase7 = _fixture.Pre025.Slides[2].Shapes.First(sp => sp.Id == 7);

            // Act
            long xCoordinateCase1 = shapeExCase1.X;
            long xCoordinateCase2 = shapeExCase2.X;
            long xCoordinateCase3 = shapeExCase3.X;
            long xCoordinateCase4 = shapeExCase4.X;
            long xCoordinateCase6 = shapeExCase6.X;
            long xCoordinateCase7 = shapeExCase7.X;
            long yCoordinateCase3 = shapeExCase3.Y;
            long yCoordinateCase5 = shapeExCase5.Y;
            long yCoordinateCase6 = shapeExCase6.Y;

            // Assert
            xCoordinateCase1.Should().Be(3653579);
            xCoordinateCase2.Should().Be(628650);
            xCoordinateCase3.Should().Be(1524000);
            xCoordinateCase4.Should().Be(1581846);
            xCoordinateCase6.Should().Be(699323);
            xCoordinateCase7.Should().Be(757383);
            yCoordinateCase3.Should().Be(1122363);
            yCoordinateCase5.Should().Be(4);
            yCoordinateCase6.Should().Be(3463288);
        }
        /// <summary>
        /// Creates a new <see cref="IGroupShape"/> instance.
        /// </summary>
        /// <param name="group">The group shape.</param>
        /// <param name="shapes">The shapes collection.</param>
        /// <param name="source">The source shapes collection.</param>
        public static void Group(this IGroupShape group, IEnumerable <IBaseShape> shapes, IList <IBaseShape> source = null)
        {
            if (shapes != null)
            {
                foreach (var shape in shapes)
                {
                    if (shape is IPointShape)
                    {
                        group.AddConnectorAsNone(shape as IPointShape);
                    }
                    else
                    {
                        group.AddShape(shape);
                    }

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

            if (source != null)
            {
                source.Add(group);
            }
        }
Exemple #6
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Presentation class that represents PPTX file
            Presentation pres = new Presentation(dataDir + "AltText.pptx");

            // Get the first slide
            ISlide sld = pres.Slides[0];

            for (int i = 0; i < sld.Shapes.Count; i++)
            {
                // Accessing the shape collection of slides
                IShape shape = sld.Shapes[i];

                if (shape is GroupShape)
                {
                    // Accessing the group shape.
                    IGroupShape grphShape = (IGroupShape)shape;
                    for (int j = 0; j < grphShape.Shapes.Count; j++)
                    {
                        IShape shape2 = grphShape.Shapes[j];
                        // Accessing the AltText property
                        Console.WriteLine(shape2.AlternativeText);
                    }
                }
            }
        }
Exemple #7
0
        public IGroupShape AddShape(IGroup group, PointF position, SizeF size)
        {
            if (!(IsInitialized?.Get() ?? false))
            {
                return(null);
            }
            if (group == null)
            {
                throw new ArgumentNullException(nameof(group));
            }

            IGroupShape result = null;

            if (GetGroupShape(group.Id) == null)
            {
                if (_groups == null)
                {
                    _groups = new List <IGroupShape>();
                }
                result = new GroupShape(Model?.Get(), group)
                {
                    Position = position,
                    Size     = size
                };
                _groups.Add(result);
                Dirty.IsDirty = true;
                _groupShapeAdded?.Invoke(GroupShapesContainer?.Get(), result);
            }

            return(result);
        }
Exemple #8
0
        /// <summary>
        /// Ungroup group shape.
        /// </summary>
        /// <param name="group">The group instance.</param>
        /// <param name="source">The source shapes collection.</param>
        public static void Ungroup(this IGroupShape group, IList <IBaseShape> source)
        {
            Ungroup(group.Shapes, source);
            Ungroup(group.Connectors, source);

            // Remove group from source collection.
            source.Remove(group);
        }
Exemple #9
0
        public void Add([NotNull] IGroupShape groupShape)
        {
            if (groupShape.Identity is IThreatModelChild child &&
                child.Model != _model)
            {
                throw new ArgumentException();
            }

            _groups.Add(groupShape);
        }
        /// <summary>
        /// Ungroup group shape.
        /// </summary>
        /// <param name="group">The group instance.</param>
        /// <param name="source">The source shapes collection.</param>
        public static void Ungroup(this IGroupShape group, IList <IBaseShape> source)
        {
            Ungroup(group.Shapes, source);
            Ungroup(group.Connectors, source);

            if (source != null)
            {
                source.Remove(group);
            }
        }
Exemple #11
0
        public void Add(IGroupShape groupShape)
        {
            if (groupShape == null)
            {
                throw new ArgumentNullException(nameof(groupShape));
            }

            if (_groups == null)
            {
                _groups = new List <IGroupShape>();
            }

            _groups.Add(groupShape);
        }
Exemple #12
0
        public bool RemoveShape(IGroupShape groupShape)
        {
            var result = _groups?.Remove(groupShape) ?? false;

            if (result)
            {
                Dirty.IsDirty = true;
                if (groupShape.Identity is IGroup group)
                {
                    _groupShapeRemoved?.Invoke(GroupShapesContainer?.Get(), group);
                }
            }

            return(result);
        }
Exemple #13
0
        public IGroupShape AddGroupShape(Guid groupId, PointF position, SizeF size)
        {
            IGroupShape result = null;

            if (Instance is IThreatModelChild child)
            {
                var group = child.Model?.Groups?.FirstOrDefault(x => x.Id == groupId);

                if (group != null)
                {
                    result = AddShape(group, position, size);
                }
            }

            return(result);
        }
 public static SKPath ToSKPath(this IBaseShape shape, double dx, double dy, Func <double, float> scale)
 {
     return(shape switch
     {
         ILineShape lineShape => ToSKPath(lineShape, dx, dy, scale),
         IRectangleShape rectangleShape => ToSKPath(rectangleShape, dx, dy, scale),
         IEllipseShape ellipseShape => ToSKPath(ellipseShape, dx, dy, scale),
         IImageShape imageShape => ToSKPath(imageShape, dx, dy, scale),
         IArcShape arcShape => ToSKPath(arcShape, dx, dy, scale),
         ICubicBezierShape cubicBezierShape => ToSKPath(cubicBezierShape, dx, dy, scale),
         IQuadraticBezierShape quadraticBezierShape => ToSKPath(quadraticBezierShape, dx, dy, scale),
         ITextShape textShape => ToSKPath(textShape, dx, dy, scale),
         IPathShape pathShape => ToSKPath(pathShape, dx, dy, scale),
         IGroupShape groupShape => ToSKPath(groupShape.Shapes, dx, dy, scale),
         _ => null,
     });
        public static IShape GroupShapes(List <IShape> shapes, ISlide slide)
        {
            //Shape to be added to group shape
            //Adding a group shape
            IGroupShape groupShape = slide.Shapes.AddGroupShape();

            foreach (IShape shape in shapes)
            {
                //Adding existing shape inside group shape
                groupShape.Shapes.AddClone(shape);

                //Removing the shape from slide
                slide.Shapes.Remove(shape);
            }

            return(groupShape);
        }
Exemple #16
0
        public void Add(IGroupShape groupShape)
        {
            if (!(IsInitialized?.Get() ?? false))
            {
                return;
            }
            if (groupShape == null)
            {
                throw new ArgumentNullException(nameof(groupShape));
            }

            if (_groups == null)
            {
                _groups = new List <IGroupShape>();
            }

            _groups.Add(groupShape);
        }
Exemple #17
0
        public IGroupShape AddGroupShape(Guid groupId, PointF position, SizeF size)
        {
            if (!(IsInitialized?.Get() ?? false))
            {
                return(null);
            }

            var group = Model?.Get().Groups.FirstOrDefault(x => x.Id == groupId);

            IGroupShape result = null;

            if (group != null)
            {
                result = AddShape(group, position, size);
            }

            return(result);
        }
Exemple #18
0
        public bool RemoveShape(IGroupShape groupShape)
        {
            var result = _groups?.Remove(groupShape) ?? false;

            if (result)
            {
                if (Instance is IDirty dirtyObject)
                {
                    dirtyObject.SetDirty();
                }
                if (groupShape.Identity is IGroup group && Instance is IGroupShapesContainer container)
                {
                    _groupShapeRemoved?.Invoke(container, group);
                }
            }

            return(result);
        }
Exemple #19
0
        public static void Run()
        {
            //ExStart:ConvertSvgImageObjectIntoGroupOfShapes
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_PresentationSaving();

            using (Presentation pres = new Presentation(dataDir + "image.pptx"))
            {
                PictureFrame pFrame   = pres.Slides[0].Shapes[0] as PictureFrame;
                ISvgImage    svgImage = pFrame.PictureFormat.Picture.Image.SvgImage;
                if (svgImage != null)
                {
                    // Convert svg image into group of shapes
                    IGroupShape groupShape = pres.Slides[0].Shapes.AddGroupShape(svgImage, pFrame.Frame.X, pFrame.Frame.Y,
                                                                                 pFrame.Frame.Width, pFrame.Frame.Height);
                    // remove source svg image from presentation
                    pres.Slides[0].Shapes.Remove(pFrame);
                }

                pres.Save(dataDir + "image_group.pptx", SaveFormat.Pptx);
            }
            //ExEnd:ConvertSvgImageObjectIntoGroupOfShapes
        }
Exemple #20
0
        public void WidthAndHeight_ReturnWidthAndHeightSizesOfTheShape()
        {
            // Arrange
            IShape      shapeCase1 = _fixture.Pre006.Slides[0].Shapes.First(sp => sp.Id == 2);
            IGroupShape groupShape = (IGroupShape)_fixture.Pre009.Slides[1].Shapes.First(sp => sp.Id == 7);
            IShape      shapeCase2 = groupShape.Shapes.First(sp => sp.Id == 5);
            IShape      shapeCase3 = _fixture.Pre009.Slides[1].Shapes.First(sp => sp.Id == 9);

            // Act
            long shapeWidthCase1  = shapeCase1.Width;
            long shapeWidthCase2  = shapeCase2.Width;
            long shapeWidthCase3  = shapeCase3.Width;
            long shapeHeightCase1 = shapeCase1.Height;
            long shapeHeightCase2 = shapeCase2.Height;
            long shapeHeightCase3 = shapeCase3.Height;

            // Assert
            shapeWidthCase1.Should().Be(9144000);
            shapeWidthCase2.Should().Be(1181377);
            shapeWidthCase3.Should().Be(485775);
            shapeHeightCase1.Should().Be(1425528);
            shapeHeightCase2.Should().Be(654096);
            shapeHeightCase3.Should().Be(373062);
        }
Exemple #21
0
 public bool RemoveShape(IGroupShape groupShape)
 {
     return(false);
 }
 /// <summary>
 /// Adds <see cref="IBaseShape"/> to <see cref="IGroupShape.Shapes"/> collection.
 /// </summary>
 /// <param name="group">The group shape.</param>
 /// <param name="shape">The shape object.</param>
 public static void AddShape(this IGroupShape group, IBaseShape shape)
 {
     shape.Owner        = group;
     shape.State.Flags &= ~ShapeStateFlags.Standalone;
     group.Shapes       = group.Shapes.Add(shape);
 }
 private void OnGroupShapeAdded(IGroupShapesContainer arg1, IGroupShape arg2)
 {
     _groupShapeAdded?.Invoke(arg1, arg2);
 }
Exemple #24
0
 /// <summary>
 /// Remove group.
 /// </summary>
 /// <param name="project">The project instance.</param>
 /// <param name="group">The group instance.</param>
 /// <returns>The owner group library.</returns>
 public static ILibrary <IGroupShape> RemoveGroup(this IProjectContainer project, IGroupShape group)
 {
     if (project?.GroupLibraries != null && group != null)
     {
         var library = project.GroupLibraries.FirstOrDefault(l => l.Items.Contains(group));
         if (library?.Items != null)
         {
             var previous = library.Items;
             var next     = library.Items.Remove(group);
             project?.History?.Snapshot(previous, next, (p) => library.Items = p);
             library.Items = next;
         }
         return(library);
     }
     return(null);
 }
Exemple #25
0
 /// <summary>
 /// Add group.
 /// </summary>
 /// <param name="project">The project instance.</param>
 /// <param name="library">The group library instance.</param>
 /// <param name="group">The group instance.</param>
 public static void AddGroup(this IProjectContainer project, ILibrary <IGroupShape> library, IGroupShape group)
 {
     AddItem(project, library, group);
 }