Support to identify any connector overlapping with other shape (C# .NET)

Hi,

I have next issue.
While I’m building charts consisting of shapes and connectors (curved, bent, straight connectors) I’m facing situations when connectors are overlapping some of shapes.

E.g.

using (var presentation = new Presentation())
        {
            var slide = presentation.Slides[0];
            var primaryShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 50, 100, 30);
            primaryShape.TextFrame.Text = "shape 1";
            
            var targetShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 350, 250, 100, 30);
            targetShape.TextFrame.Text = "shape 2";

            var intersectedShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 180, 100, 30);
            intersectedShape.TextFrame.Text = "intersected shape";

            var arrow = slide.Shapes.AddConnector(ShapeType.CurvedConnector2, 0, 0, 10, 10, true);
            arrow.LineFormat.FillFormat.FillType = FillType.Solid;
            arrow.LineFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.Red;
            arrow.StartShapeConnectionSiteIndex = 3;
            arrow.StartShapeConnectedTo = primaryShape;
            arrow.EndShapeConnectedTo = targetShape;
            arrow.EndShapeConnectionSiteIndex = 0;

            presentation.Save(fileNameToSave, Aspose.Slides.Export.SaveFormat.Pptx);
        }

Here the connector will overlap with shape ‘intersected shape’.
Issue 1) I don’t know when connector is overlapping some particular shape. I haven’t found in documentation any way to understand that. Also the connector itself provides only the connector frame, but I don’t know what is the exact connector shape line and in which point it crosses the underlying shape.

Issue 2) I cannot increase the curvature or set the bent point manually. Is there any known way to do that?

Is there any plan to add such functionality in nearest future since it is crucial for our project?
We are trying to build clear charts avoiding any connector intersections.

Thank you

@LostAndFound,

I have observed your requirements. Can you please share the generated presentation on your end along with desired output presentation that you want to get using Aspose.Slides. We will try to investigate the requirements based on shared information to help you out.

Hi,

Please find example PPTs attachedexample.zip (46.5 KB)

@LostAndFound,

I have observed your requirements and regret to share that there is no such provision in API that may assist if there is any shape intersecting the path of added connector between two shapes. Please feel free to share with us if there is any further we may help you.

@LostAndFound,

We have created a new feature request in our issue tracking system with ID SLIDESNET-41675 that would return Coordinates of connector points on slide. Using these points you may draw arbitrary line and devise your own logic if that line passes through any of already added shape. I hope this feature will be helpful to you when implemented.

Good news. Is there any estimation on how many months it may take to be released?
Will it provide coordinates of all points of the connector line or only the start and the end points?
Thank you

@LostAndFound,

The tentative ETA for the feature support is Aspose.Slides for .NET 20.2. We will share the good news with you as soon as the feature will be available in API and request for your patience in this regard.

1 Like

@LostAndFound,

We have investigated the requirements on our end. Can you please try using following sample code and share that its useful to you using latest Aspose.Slides for .NET 20.1. In the following code, we have shared approach to get the coordinates. Rest you may devise your own logic based on extracted point coordinate that if that is intersecting any shape in between two consecutive points or not.

using (var presentation = new Presentation())
{
    var slide = presentation.Slides[0];
    var primaryShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 50, 100, 30);
    primaryShape.TextFrame.Text = "shape 1";

    var targetShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 350, 250, 100, 30);
    targetShape.TextFrame.Text = "shape 2";

    var intersectedShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 180, 100, 30);
    intersectedShape.TextFrame.Text = "intersected shape";

    var connector = slide.Shapes.AddConnector(ShapeType.StraightConnector1, 0, 0, 10, 10, true);
    connector.LineFormat.FillFormat.FillType = FillType.Solid;
    connector.LineFormat.FillFormat.SolidFillColor.Color = Color.Red;
    connector.StartShapeConnectionSiteIndex = 2;
    connector.StartShapeConnectedTo = primaryShape;
    connector.EndShapeConnectedTo = targetShape;
    connector.EndShapeConnectionSiteIndex = 0;

    var connectorElement = (ShapeElement)connector.CreateShapeElements()[0];

    // points of the straight connector path
    PointF connectorPoint1 = connectorElement.GraphicsPath.PathPoints[0];
    PointF connectorPoint2 = connectorElement.GraphicsPath.PathPoints[1];

    // If the connector was transformed, you should transform the points.

    // one edge of the intersectedShape
    PointF shapePoint1 = new PointF(intersectedShape.X, intersectedShape.Y);
    PointF shapePoint2 = new PointF(intersectedShape.X + intersectedShape.Width, intersectedShape.Y);

    // Now you can use these points for intersection checking.

    presentation.Save(presentationPath, SaveFormat.Pptx);
}

Hello,

I tried to run your code and I did a minor change to add a small brown hexagon in each connector point, so that it will be easier to understand what all those coordinates mean. You can find the solution here (7.4 KB)

As a result we have the following cases:

StraightConnector1
This type of connector has two PathPoints that mark the beginning and the end of the straight line, as we can see in StraightConnector1.PNG (4.3 KB)
In this scenario it may be possible through a custom algorithm to figure out if there is an intersection with another shape.
Interesting thing in this scenario, the connector.Adjustments is empty.

CurvedConnector2
This type of connector has seven PathPoints that most probably mark the path of the curved connector before applying any adjustments, as we can see in CurvedConnector2.PNG (4.6 KB). Looks like some mirroring/rotation is applied too.
In this scenario I’m not sure how to identify an intersection with another shape.
Interesting thing in this scenario, the connector.Adjustments is having 1 object with those values: {Aspose.Slides.AdjustValue}
AngleValue: 0.8333333
Name: "adj1"
RawValue: 50000

BentConnector3
This type of connector has four PathPoints that most probably mark the path of the elbow connector before applying any adjustments, as we can see in BentConnector3.PNG (3.3 KB). Looks like some mirroring/rotation is applied too.
In this scenario I’m not sure how to identify an intersection with another shape.
Interesting thing in this scenario, the connector.Adjustments is having 1 object with those values: {Aspose.Slides.AdjustValue}
AngleValue: 0.8333333
Name: "adj1"
RawValue: 50000

Based on the above experiment, I’d like to ask you if there is any way to know all the points of a connector of any type. It will be really helpful if we can set those values during runtime, so that we’ll have full control on the path that a connector will follow. Finally is anywhere any documentation on the meaning of the Names of AdjustValues?

Kind regards,
FB

Hi @mudassir.fayyaz , any update on questions above from @fireball4?
Thank you

@LostAndFound,

I have verified from our issue tracking system and like to share that at present there are no further updates available for the state of the issue. I will share them with you as soon as they will be availble.

Hello @mudassir.fayyaz,
I think that my question is not related to your tracking system. I just need to know if currently you are supporting this. Please take a closer look.
Kind regards,
FB

@fireball4,

I understand your point and like to share that the sample provided in following thread link (shared before) is at the moment supported possible option.

However, based on your following requirements, we are still working over them and will be able to share any workaround with you as soon as possible.

@fireball4,

We have investigated the example code from you. The coordinates of the points obtained in this way can be transformed. The code sample below can help to check a transformation and to find points in the slide coordinate system:

var connectorElement = (ShapeElement)connector.CreateShapeElements()[0];
var pathPoints = (PointF[])connectorElement.GraphicsPath.PathPoints.Clone();

bool pointsAreTransformed = connector.Frame.FlipH == NullableBool.True || connector.Frame.FlipV == NullableBool.True || connector.Frame.Rotation != 0;
if (pointsAreTransformed)
{
    Matrix transformMatrix = new Matrix();

    transformMatrix.Translate(connector.Frame.CenterX, connector.Frame.CenterY);
    transformMatrix.Rotate(-connector.Frame.Rotation);
    if (connector.Frame.FlipH == NullableBool.True) transformMatrix.Scale(-1, 1);
    if (connector.Frame.FlipV == NullableBool.True) transformMatrix.Scale(1, -1);
    transformMatrix.Translate(-connector.Frame.CenterX, -connector.Frame.CenterY);

    transformMatrix.TransformPoints(pathPoints);
}

Please note that these points are key points and may not lie on the curve of a connector (excluding the first and last). That’s why he should use point types also for an approximate algorithm:

var pointTypes = connectorElement.GraphicsPath.PathTypes;