Book a Demo

Author Topic: How to handle oversized diagrams in document generation  (Read 6378 times)

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
How to handle oversized diagrams in document generation
« on: May 08, 2020, 09:44:16 pm »
Hey guys,


I've got a number of modellers working mainly with activity diagrams. The deliverables are Word documents, generated by means of a script. The problem is that the diagrams tend to get too large to be squeezed onto a single page.

I've been trying to work out a solution for this, which has resulted in a couple of Bugs&Issues posts, but I can't find a way forward that doesn't require a serious amount of manual editing of either the diagrams, or the resulting document, or both.

The template that outputs the diagrams is very simple, just a package>element>diagram>{Diagram.DiagramImg} thing. The script simply calls DocumentGenerator.DocumentElement().

My script checks the diagram's page orientation. I've found that applying a landscape version of the same template doesn't work, but if I instead InsertBreak(section) and SetPageOrientation() before and after a landscape diagram, using the portrait version of the template nearly works: the diagram is placed on a landscape page, although the document gets an unrequested blank page before the diagram.

So if the issue is that the diagram is too wide, we can get it out. It requires a needlessly complex set of GUI interactions for the modellers:
  • Open the diagram properties
  • Select the Diagram tab
  • Click the Advanced... button
  • Click the Page Setup button
  • Click the Landscape radio button
  • Click OK
  • Click OK
  • Click OK
... but it works.

But when that isn't enough, what do I do?

Divide Diagram into Multiple Pages doesn't work. And doesn't work.

Forcing the modellers to restrict their activity diagrams to what can fit on a page is not acceptable.

There are operations in Project and Diagram to get images from a diagram -- but there's nothing in DocumentGenerator to insert an image into a document.

Is it possible to use DocumentGenerator.DocumentCustomData() to insert image data? If so, how should it be encoded?

Is there another way of getting images into a document? Maybe via the image library or some magic template fragment?

Or is there some other way of getting this done?

TIA,


/Uffe
My theories are always correct, just apply them to the right reality.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to handle oversized diagrams in document generation
« Reply #1 on: May 08, 2020, 10:08:09 pm »
Uffe,

I think theoretically you could use a Document Script fragment.
If I understood this one correctly you are supposed to return raw rtf code in the script used by this template.

So if in this script, you were to create an RTF document containing the image of your diagram, you would have every degree of freedom you could want.

I'm not sure if it would be worth all the effort though  :-\

Geert


Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to handle oversized diagrams in document generation
« Reply #2 on: May 09, 2020, 08:47:38 pm »
I think theoretically you could use a Document Script fragment.
If I understood this one correctly you are supposed to return raw rtf code in the script used by this template.

So if in this script, you were to create an RTF document containing the image of your diagram, you would have every degree of freedom you could want.
I don't see how a Document Script fragment helps.

I need to split a diagram into multiple images and place each image into the document separately so I can add headers or captions to each image. I can write each page of an oversize diagram to a file using Diagram.SaveImagePage(), but how do I get them into the RTF stream being generated by DocumentGenerator? The file is an image in either .bmp, .emf or .png. How do I go from an image file on disk to an RTF document in memory?

I've tried DocumentGenerator.LoadDocument(), but it doesn't work for images (at least not for .bmp, .emf, .jpg, .png, .svg, .tif, or .wmf). It does work for .docx and .rtf, though not for .pdf. In case anyone is wondering.

Is there some other way of doing this?

I cannot be the first one to have this problem.


/U
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to handle oversized diagrams in document generation
« Reply #3 on: May 09, 2020, 09:51:09 pm »
I think this is a more basic issue. When I layout activity diagrams I have it in mind that they might be printed. So I break things down to A4. A logical unit that can be seen in one glimpse. Even 2 pages are difficult if you have to turn pages.

q.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to handle oversized diagrams in document generation
« Reply #4 on: May 09, 2020, 09:56:20 pm »
I'm not disagreeing with you. But I have been tasked essentially with generating nicely readable documents from models where the modellers don't need to care about such wordly things as layout. Or how the tool works. Or what UML is.
My theories are always correct, just apply them to the right reality.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to handle oversized diagrams in document generation
« Reply #5 on: May 10, 2020, 01:48:47 am »
I need to split a diagram into multiple images and place each image into the document separately so I can add headers or captions to each image. I can write each page of an oversize diagram to a file using Diagram.SaveImagePage(), but how do I get them into the RTF stream being generated by DocumentGenerator? The file is an image in either .bmp, .emf or .png. How do I go from an image file on disk to an RTF document in memory?

I'm not sure how. I would hope there are libraries you could use to build an RTF document and add those images.
If not you could still write the RTF code manually I guess

Still feels like a major effort, and as I said I'm not sure if it's all worth it.

Geert

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: How to handle oversized diagrams in document generation
« Reply #6 on: May 10, 2020, 09:16:10 am »
Not an easy problem to solve. I remember we had a finite state machine that had about 400 states and at first we used an A0 plotter. However I customer wanted it documented in A4 documents so we addressed that particular problem by learning to model in an hierarchical fashion having multiple diagrams. It was time consuming and painful but we managed in the end.

My first thought to avoid the problem with those needless UI interactions is may be use the rotate image option on the diagram dialog.

My second thought is may be try and automate those diagram settings if its possible using script and the API . Don't know if its possible but it would be something like this;
Scan the diagram objects for the x and y values storing the min and max x and y values. Depending on the min and max values you could probably put into an algorithm to set portrait, landscape, rotate, scale to one page etc diagram settings.

If that's not possible another approach might be to think of attacking problem in a two phased approach using both Sparx EA script and MS Word Script. For example
1. Generate the document as best as you can.
2. Automate using MS word those manual edits you mentioned .

Of course in the longer term we could suggest Sparx Systems making the UI a bit easier to set the landscape and and portrait settings which has always been a bit of a pain anyway and is in dire need of change to make it more user friendly. Or even write into Sparx EA application an automated algorithm chooses the best fit for the diagram. I know that's possible as I've seen it in another tool but can't remember what it was.

Well hope that provides some food for thought to help inspire some ideas to solve the problem for you.
Happy to help
:)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: How to handle oversized diagrams in document generation
« Reply #7 on: May 11, 2020, 08:30:30 am »
I'm not disagreeing with you. But I have been tasked essentially with generating nicely readable documents from models where the modellers don't need to care about such worldly things as layout. Or how the tool works. Or what UML is.
Another of our essential problems...

If that is so, then "modellers" isn't the correct term for the makers of the models.

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

michielper

  • EA User
  • **
  • Posts: 176
  • Karma: +2/-1
    • View Profile
Re: How to handle oversized diagrams in document generation
« Reply #8 on: May 15, 2020, 07:16:37 pm »
Hey guys,


I've got a number of modellers working mainly with activity diagrams. The deliverables are Word documents, generated by means of a script. The problem is that the diagrams tend to get too large to be squeezed onto a single page.

I've been trying to work out a solution for this, which has resulted in a couple of Bugs&Issues posts, but I can't find a way forward that doesn't require a serious amount of manual editing of either the diagrams, or the resulting document, or both.

The template that outputs the diagrams is very simple, just a package>element>diagram>{Diagram.DiagramImg} thing. The script simply calls DocumentGenerator.DocumentElement().

My script checks the diagram's page orientation. I've found that applying a landscape version of the same template doesn't work, but if I instead InsertBreak(section) and SetPageOrientation() before and after a landscape diagram, using the portrait version of the template nearly works: the diagram is placed on a landscape page, although the document gets an unrequested blank page before the diagram.

So if the issue is that the diagram is too wide, we can get it out. It requires a needlessly complex set of GUI interactions for the modellers:
  • Open the diagram properties
  • Select the Diagram tab
  • Click the Advanced... button
  • Click the Page Setup button
  • Click the Landscape radio button
  • Click OK
  • Click OK
  • Click OK
... but it works.

But when that isn't enough, what do I do?

Divide Diagram into Multiple Pages doesn't work. And doesn't work.

Forcing the modellers to restrict their activity diagrams to what can fit on a page is not acceptable.

There are operations in Project and Diagram to get images from a diagram -- but there's nothing in DocumentGenerator to insert an image into a document.

Is it possible to use DocumentGenerator.DocumentCustomData() to insert image data? If so, how should it be encoded?

Is there another way of getting images into a document? Maybe via the image library or some magic template fragment?

Or is there some other way of getting this done?

TIA,


/Uffe

I had the same problem. One way to deal with this is through a (very) small script in Word that resizes the picture if it is too large and which you run directly after saving the RTF file as docx. This is how I do it. I found that running some script(s) in Word is useful anyway, also e.g. to fix line- and pagebreaks at odd positions.