Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon Jan 12, 2015 2:18 am

I want to insert a connector(several lines formed arrow) between shapes.
Currently, I only have a bad implementation:
1. I insert a line as a ShapeConnector. However, I have to rotate it to the correct direction.
Is there other method to insert a line?
e.g. Can I insert a line by its two end points as in "Microsoft.Office.Interop.PowerPoint".
2. If I want to insert an elbow line, should I insert several sub-lines and group them into one single shape?
I found a function to group shapes, while I'm still trying to learn how to use it.

Thank you so much!

Code: Select all
IShape ish= CurPresentation.Slides[1].Shapes.AppendShapeConnector(dropConnectors[i].DropConnectorShapeType,
                        new RectangleF(posX, posY, w, h));
shape.ShapeStyle.LineColor.Color = Color.Black;
                    shape.Rotation = (int)(rotateAng);

xchangcheng
 
Posts: 7
Joined: Mon Dec 22, 2014 6:37 am

Mon Jan 12, 2015 6:24 am

To insert any line by two points, currently I use the following method:
insert a basic line -----> rotate it to the proper location and direction.

Code: Select all
var pointList = new List<PointD>{p1,p2};
var rect = UtilFull.GetBoundingBox(pointList);
int rotateAng = GetLineRotateAngForPpt(pointList[j], pointList[j + 1]);
var rectf = new RectangleF((float) (rect.Left), (float)(rect.Bottom), (float) (rect.Width), (float) (rect.Height));
var shape = CurPresentation.Slides[slideIdx].Shapes.AppendShape(dropConnectors[i].DropConnectorShapeType, rectf);
shape.ShapeStyle.LineColor.Color = Color.Black;
shape.Rotation = rotateAng;

//function to caculate the rotation angle

/// <summary>
        /// get the line (p1-p2) rotate angle([0,180])
        /// Attention: the line will be from p1 to p2
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns>value: 0 - 180</returns>
        public static int GetLineRotateAngForPpt(PointD p1, PointD p2)
        {
            var rotateAng = 0;
            PointD startP, endP;
            if (p1.X < p2.X)
            {
                startP = p1;
                endP = p2;
            }
            else
            {
                startP = p2;
                endP = p1;
            }
           
            var ang = GetAngle(endP, startP, new PointD(startP.X + 10, startP.Y));

            //in spire.presentation, line is dropped from left-up to right-down
            if (startP.Y > endP.Y)
                rotateAng = (int)((1 - ((ang * 2) / Math.PI)) * 180);

            if (p2.Y < p1.Y)
                rotateAng += 180;

            return rotateAng;
        }

/// <summary>
        /// Get the ang formed by vector,(p2 -> p1) and (p2 -> p3)
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <returns>O~PI</returns>
        public static double GetAngle(PointD p1, PointD p2, PointD p3)
        {
            double x1 = p1.X - p2.X, y1 = p1.Y - p2.Y, x2 = p3.X - p2.X, y2 = p3.Y - p2.Y;
            double a = Math.Sqrt(x1 * x1 + y1 * y1), b = Math.Sqrt(x2 * x2 + y2 * y2);
            if (a < double.Epsilon || b < double.Epsilon) return 0;
            double c = x1 * x2 + y1 * y2;
            return Math.Acos(c / (a * b));
        }

xchangcheng
 
Posts: 7
Joined: Mon Dec 22, 2014 6:37 am

Mon Jan 12, 2015 8:53 am

Hello,

Please try the below line to draw elbow line.
Code: Select all
 presentation.Slides[0].Shapes.AppendShape(ShapeType.BentConnector3, new RectangleF(100, 100, 250, 50));


Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Jan 12, 2015 9:32 am

Thank you so much!
Yes. We can insert basic elbow lines like above. However, it can only support simple elbow lines and it's hard to control.
If we can group any shapes (e.g. line) to a single shape(a group of basic shapes like lines), we can get much more diverse shapes.

xchangcheng
 
Posts: 7
Joined: Mon Dec 22, 2014 6:37 am

Tue Jan 13, 2015 1:32 am

Hello,

Thanks for your reply.
Sorry that we don't support the function likes grouping any shapes (e.g. line) to a single shape(a group of basic shapes like lines) at present. We will continue improving our Spire.Presentation to present a better support in the furture.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Presentation