Printing Node Adornments

Hi

This post has two questions:

  1. Is it possible to have adornments printed along with their respective nodes when a diagram is printed?

I have a Node with an adornment (green box at the bottom, with a red border) that I would like to be printed as well when the diagram is printed:

But when then the diagram is printed, it is not included.

  1. Why does printing a diagram remove the diagram’s active node adornments?

My Node has an active adornment like in the picture above. After printing a diagram, the adornment is removed:

Thanks
Justin

Normally Adornments are not printed. This is just as in other applications – for example the selection is not printed by Microsoft Word.

I suppose you could try passing to PrintManager.Parts a collection that includes the Adornments that you want to print. I haven’t tried that, but I think that might work.

There are several situations in which all of the Adornments for a Part are removed and then Part.UpdateAdornments is called again. If you want to add Adornments, I recommend that you follow my suggestion about overriding UpdateAdornments, either on the Part or on a Tool in the MouseDownTools list.

Or you could not use Adornments at all, and avoid both of these issues.

Hi Walter

I tried your suggestion of manually including the Adornments in the collection of Parts to print but the Adornments still do not print. Here’s the code I used:

IEnumerable<Go.Part> parts = Diagram.SelectedParts;
if(parts.Count() == 0) {
parts = Diagram.PartManager.Nodes.OfType<Go.Part>().Union(Diagram.PartManager.Links.OfType<Go.Part>());
parts = parts.Union(parts.OfType<Go.Node>().SelectMany(n => n.Adornments).Where(a => a.Printable == true));
}
Diagram.PrintManager.Parts = parts;
Diagram.PrintManager.Print();

Do you have any other suggestions I can try?

I will follow your suggestion regarding UpdateAdornments. If I create my own custom DiagramTool, whose sole purpose is to manage my custom Adornments, and then add that tool to the MouseDownTools list will that be okay?

I suspect the problem is that the printing process automatically ignores Parts that are in Layers that are Layer.IsTemporary. Try putting your special Adornments in a regular Layer.

Yes, create your own DiagramTool subclass that overrides CanStart to return false and overrides UpdateAdornments to do what you need.

But as I mentioned before, I think the best solution is not to use Adornments at all.

Thanks Walter

Will give it a try and will let you know the outcome

Hi Walter

I did as you suggested. I created a NodeLayer and I set the following properties: AllowPrint = true and IsTemporary = false. I then added this layer to the DiagramPanel via Diagram.Panel.Children.Add(). I then added the adornment to this layer. The adornment still does not print when I use PrintManager.Print(). I also ensured that the adornment has AllowPrint = true.

However, if I add the adornment to the default NodeLayer, it prints.

Am I missing something in regards to configuring the custom NodeLayer?

Thanks
Justin

Maybe you also need to set the Adornment’s LayerName to be the name of your new non-temporary Layer. The default value of Adornment.LayerName is “Adornment”.

However, that would not explain why it did print when it was added to the default NodeLayer.

Hi Walter

I tried that but it didn’t work. I suspect somewhere in the printing logic Part.SetAdornment(category, null) is being called, removing the adornment which means it won’t be printed. But the doesn’t explain why it get’s printed if I add it to the default NodeLayer.

I also tried adding it to the pre-defined “Foreground” NodeLayer but it doesn’t get printed there either.

So, for now, I’m attaching the adornment to the node manually (without using MakeAdornment or SetAdorment and therefore won’t be tracked by the node being adorned) and this allows me to print it.

This workaround is good enough in my opinion, unless you can think of some circumstances that I’m not taking into consideration?

Thanks
Justin

Upon further review of the code, I believe the Adornments are being cleared for each Part as a side-effect of printing.
So you do need to print Adornments by not having them be the responsibility of the adorned Part.

So your work-around is pretty clever. But I would think that that way should allow the Adornments to be printed in any layer.

Thanks Walter