GetToNodeForLink

Hello,

I’d like to exchange “from” to “to” node if user make a link at reverse sens, whitout errors.

I made this code :
<BR>protected override void InsertLink(QD_Link linkdata)<BR> { <BR> int iRes = IsLinkOk(linkdata, null);<BR> if ( iRes == 0) this.RollbackTransaction();<BR> else if (iRes == -1)<BR> {<BR> QD_Node oToNode = this.GetToNodeForLink(linkdata);<BR> QD_Node oFromNode = this.GetFromNodeForLink(linkdata);<BR> this.RollbackTransaction(); <--- breakpoint<BR><BR> Application.Current.Dispatcher.BeginInvoke((Action)(() =><BR> {<BR> QD_Link oNewLink = new QD_Link(this.Options);<BR> oNewLink.From = oToNode.Key;<BR> oNewLink.To = oFromNode.Key;<BR> oNewLink.QDCategory = QD_Link.ECategory.Belongs;<BR> iRes = IsLinkOk(oNewLink, null);<BR> if (iRes == 1)<BR> {<BR> this.AddLink(oNewLink);<BR> }<BR> }), DispatcherPriority.ApplicationIdle);<BR> }<BR> else<BR> {<BR> base.InsertLink(linkdata); <BR> }<BR>}<BR>

Where IsLinkOk verify if node is acceptable.
I’ve put a breakpoint at rollbacktransaction, and this is the data state : (I can’t insert image then i will copy the results :

linkdata.From "11"
linkdata.To "1"
this.GetToNodeForLink(linkdata) null ??
- this.NodesSource Count = 11
+ [0] {1} SphinxV6.Concept.QDiagram.QD_Node
+ [1] {2} SphinxV6.Concept.QDiagram.QD_Node
+ [2] {10} SphinxV6.Concept.QDiagram.QD_Node
+ [3] {3} SphinxV6.Concept.QDiagram.QD_Node
+ [4] {4} SphinxV6.Concept.QDiagram.QD_Node
+ [5] {5} SphinxV6.Concept.QDiagram.QD_Node
+ [6] {6} SphinxV6.Concept.QDiagram.QD_Node
+ [7] {7} SphinxV6.Concept.QDiagram.QD_Node
+ [8] {8} SphinxV6.Concept.QDiagram.QD_Node
+ [9] {9} SphinxV6.Concept.QDiagram.QD_Node
+ [10] {11} SphinxV6.Concept.QDiagram.QD_Node
why this.GetToNodeForLink(linkdata) gives null value ?
I use WPF version 1.2.6.3
Aurore

Instead of allowing the user to draw an invalid link and then trying to fix it up afterwards, why not prevent the incorrect link from being drawn at all?

Replace the standard Diagram.LinkingTool with one that overrides LinkingTool.IsValidLink to check what you want.

If your application supports relinking, you’ll probably want to override RelinkingTool.IsValidLink too.

Yes it could be a possibility,

but from user point of view, added a variable in a part could be drawing from part to variable and from variable to part (even if we have drawn an arrow from part to variable).

If the way i take is too complex, i will use IsValidLink of course.

But just to know, why the GetToNodeForLink gives null. The node is present in the nodessource…

Thanks
Aurore

I’ve solved my problem.

I don’t use Node but key string representation, only needed for link.From and link.To.

Have a nice day

Aurore