Convert an connected link to two new open link

Hey,

I would like to convert an connected link (i.e A link which is already drawn and connected with two nodes from both of the end) to open link (i.e link will be converted into two new links those links individually will be open from one side and another end will be connected by respective node.). In output.
In solution I’ve created a custom class tool inherited by linking tool. but now which method or custom code can help to achieve the above scenario.
Below is the image for your reference.

Do you want the resulting Links to be actually half-disconnected, or do you want there to be tiny transparent Nodes at the ends? Either way is entirely feasible.

I’ll assume the former case is what you want. First, you’ll need to make set GraphLinksModel.ValidUnconnectedLinks to Allowed.

Create a command that operates on a selected Link. In a transaction, remember the Link.ToPort, set its Link.ToPort to null, and add a new Link whose one end is connected with the old ToPort. (It isn’t clear to me which end of the link you want to connect – that’s your choice.)

You’ll need to set the Link.Route.Points list on both Links. You can have them be a simple straight segment consisting of two Points, or you can do what you’ve drawn consisting of at least four Points.

It isn’t clear to me what you want happen when the user drags one of the two nodes. If you’ve examined the “Draggable Link” sample of GoWpfDemo, you’ll notice that the disconnected end of the link remains in place. But if the link is selected along with the node, then the link is dragged along. If you want the link to be dragged along even though it is not selected, you can override DraggingTool.ComputeEffectiveCollection to make sure to include those half-connected Links that are attached to selected Nodes.

Oh, if you don’t want to allow users to draw partly disconnected links, you may need to override LinkingTool.IsValidFrom and IsValidTo to return false if either argument is null. Same goes for RelinkingTool.

okay, so i’ve achieved the above thing somewhat in similar way by deleting the existing link from Node A to Node B and creating two new links with the help of AddLink function,

but as I’ve created new links it goes automatically to the top left corner even I’ve specified the Points properly still it draws till the left-top boundary of the diagram.

Do we have some way to draw it till some point. For your reference I am using the below code and also attached images for your reference.

Below is the default template I’ve for link

    <!--Default Template for the Link/Medium/Connection-->
    <DataTemplate x:Key="{x:Static prop:Resources.DefaultLinkTemplate}">
        <go:LinkPanel  go:Part.Reshapable="True" go:Part.LayerName="{Binding Path=Part.IsSelected, Converter={StaticResource selectedLayerConverter}}">
            <go:Link.Route>
                <go:Route Routing="AvoidsNodes" Curve="JumpOver" RelinkableFrom="True" RelinkableTo="True"/>
            </go:Link.Route>
            <go:LinkShape Stroke="{Binding Path=Part.IsSelected, Converter={StaticResource theSelectionConverter}}"
                      StrokeThickness="6" />
            <go:LinkShape x:Name="Path" Stroke="Black" StrokeThickness="1" />
            <Path Fill="Black" go:LinkPanel.ToArrow="Standard"/>
        </go:LinkPanel>
    </DataTemplate>

        DiagramsModel.AddLink(new LinkData()
        {
            Category = "Link",
            From = fromNodeKey,
            FromPort = fromPort,
            To = null,
            ToPort = null,
            Points = new List<Point>() { new Point(50, 230), new Point(50, 240), new Point(50, 244), new Point(103, 244), new Point(103, 283), new Point(103, 293) },
            Text = "New Link",
        });

FYI: LinkData is just inheriting GraphLinksModelLinkData<String, String>

I’ve Added two links by calling AddLink function twice. Now these new links after drawing goes automatically to top left corner rather then sticking with the point I defined above. ? please check the image below for your reference.

I am trying to achieve the below positions point with new links ?

There is no Binding of Link.Route.Points, and there cannot be, so you have to set that property yourself on each of the new Links, as part of your command to split up the link.

I agree that we need to set the property. If you had given a look on the above snippet you will notice that I’ve provided the Point values (new List of points) while creating an new link but still it’s going to the top left corner rather close to expected result above.

You set the points on the data – I’m saying that you should set it on the Link.Route.

can we set the data template too for these newly created links to change the look and feel of it rather then drawing it with ‘Default’ view. I’ve already created a data template under DataTemplateDictionary.

Also, I’ve tried to update the link.category but as I update that with my template name it goes again back to the Top Left corner or after some more manipulation it gives me “ERROR: Cannot set Part.Category after it has been added to a Diagram

Set the category in the link data, so that the PartManager automatically instantiates the desired kind of Link.

Thanks it’s working fine,
Also I was trying to change the existing link (Already drawn) template by the same way (updating Category), it also worked (link is getting change as per new template) but it’s loosing it’s points (Route.Points) and goes back to top left corner of the diagram even I am setting it’s points manually as you have mentioned above Link.Route but still no luck.

Is this a different situation? Do you save the sequence of points beforehand, and then set Link.Route.Points on the new Link as the very last action before committing the transaction to change the category? I’m wondering if that isn’t feasible because you cannot get a reference to the completed new Link that soon.

yes, Let me more descriptive. I am using “LinkDrawn” event of go:Diagram through which I am getting link which is going to be draw on diagram. now I need to change this link template to some other template. so I am updating it’s category with the new DataTemplate name which is already defined in “DataTemplateDictionary”. Now GoWPF is updating the template design (i.e Link’s design) got updated but it lost link’s drop location and goes to top left corner.

What I’ve done - Along with category update, Manually I’ve set the Route.Points, but these new points doesn’t reflect to the Link.

Commit and rollback transaction are for undo and redo manager. Do you really think will it work !

Ah, so your code is in a “LinkDrawn” event handler. Do you have the desired category once the LinkingTool start but before the call to IDiagramModel.AddLink happens?

If so, you could override GraphLinksModel.InsertLink(…) to create the desired link data object with the desired properties and then call GraphLinksModel.InsertLink(LinkType).