Adding Icons to a Link
The Link object in ILOG Diagrammer for .NET lets you easily add text items at any position on the link path (using the TextItems property), but there is no out-of-the box functionality to add other graphic decorations like icons. Here is a sample that shows how to achieve this.
The meat of the sample is the DecoratedLink class. It is a subclass of Link with a new Decorations property that contains a collection of LinkDecoration objects. Each LinkDecoration has an Image property (the icon to display), a Position property (Start, Middle or End) and an Offset property that shifts the icon by the specified number of pixels along the link path.
Here is the source code: in C#, and in Visual Basic.
Feel free to use (and adapt) the DecoratedLink class if you need this functionality in your applications.









August 13th, 2008 at 11:33 am
Forgot to attach the source code… Click on the word ’sample’ in the first paragraph to get it.
August 14th, 2008 at 3:52 am
Added the VB version of the source code.
August 20th, 2008 at 3:56 am
Great thanks!
September 2nd, 2008 at 12:38 pm
I using it with “GraphicObject”(user symbol) instead “Image”(bitmap picture) and it looks good
And..
When its not “Link”, but “Line” object, where i can put “PlaceDecorations()” method?
In “Link” its override of “SetLinkPoints” method.
September 3rd, 2008 at 2:17 am
I think you can call PlaceDecorations() from UpdateGraphicsPath().
November 5th, 2008 at 8:26 am
Double great thanks! Now i have decorated node lines and decorated links for electrical scheme.
And now i need a decoration cut for my decoration on link, like textcut
(for example if i have decoration with “rectangle” image object wich have fill=null, i want to cut line inside this rectangle).
I use textitem with text opacity = 0, but its not comfortable when i have other text items and not usable when i need to resize my decoration image.
Can you help me? )
How it looks:
http://i021.radikal.ru/0811/23/417b6e65f2e3.jpg
November 6th, 2008 at 5:46 am
Alexey,
Your application looks really nice.
For the cut problem, there is no simple solution. The only way is to override UpdateGraphicsPath and compute the “cuts” yourself… I had a try at it, you can find a modified version of the project here:
http://blogs.ilog.com/netvisu/wp-content/uploads/2008/11/decoratedlinksample_cut.zip
As you will see, there is a new “Cut” property in LinkDecoration, you must set it to true to have the link cut at this decoration.
Note also that you cannot use the normal “cap” arrows, because the arrow would appear before each cut. So, you must use a “shape” arrow instead (using a triangle shape). See the Diagram1.cs example in the project.
Note that this code is a quick try, and has some tricky edge-cases, but it seems to work (not tested very intensively though). I hope you will find it useful.
Oh, and please don’t ask the VB version…
You can use one of the many C#->VB translators out there on the net.
November 6th, 2008 at 12:27 pm
You are the great man.
I don`t need VB. And i also don’t need arrows.
Its exactly what i want x)
I just little set it right, like that:
http://upload0000.webasyst.net/files/737cd809
(vs 2005 solution)
just another decorations comparison for sort method, and 4 private properties: cut, bounds, corners, computedPosition
“public bool Cut{ get; set;}” not works )
November 6th, 2008 at 12:36 pm
Oh yes, this was VS 2008 / .NET Framework 3.5 code…
Glad it works for you.