How to print class hierarchy diagram?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to print class hierarchy diagram?

Dmitry Pankratov
I would like to print the whole class diagram for learning purposes, but I
could not find the way of doing this. Impossible? :(

Regards,
Dmitry


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Ian Bartholomew-13
Dmitry,

> I would like to print the whole class diagram for learning purposes, but I
> could not find the way of doing this. Impossible? :(

No, it can be done - although it is not as simple as pressing a button.

To get the following to work you will have to -

1) Download my Goodies to obtain one of it's classes,
DeviceIndependentBitmap, as this provides a way of saving Bitmaps to a disk
file.  I can mail you a copy if that is accessing the web
(http://www.iandb.org.uk) site is a problem.

2) Modify the MoenTreeView>>onPaintRequired: method to read as below.

3) Display a ClassDiagram in the normal way.  Nothing will be displayed in
the view (because we are using a different canvas) but you should now find a
large bitmap file in your root folder.

4) Open the bitmap file into an editor of your choice and print ....

Regards
    Ian

onPaintRequired: aPaintEvent
    "Private - Paint the receiver's view."

    | canvas bmp |
    bmp := DeviceIndependentBitmap
        width: 2000
        height: 10000
        depth: 8.

    (canvas := bmp canvas)
        fillRectangle: (0 @ 0 extent: 2000 @ 10000) brush: Brush white;
        font: self actualFont;
        pen: self linePen.

    self setDefaultCanvasColors: canvas.
    anchorNode childrenDo:
        [:each |
            self
                paint: each
                on: canvas
                fromPoint: nil].

    bmp saveToFile: 'c:\class.bmp'


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Ian Bartholomew-13
Some other things I just thought of

-  You might have to change the Bitmap width/height to make sure you get the
whole diagram in. FWIW my working image fits in 1400x14000.

- Close the ClassDiagram view or, preferably, shut down Dolphin (without
saving the image) before viewing the bitmap otherwise every time the diagram
is redrawn the file will be rewritten and might start generating OS file
sharing errors.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Dmitry Pankratov
Thanks Ian,

Now I'm going to add a popup menu item for "one-button-click" printing :)

I noticed that some of the entries in this hierarchy are truncated. Is it
possible to build a complete diagram (and glue a hard copy afterwards)?

Regards,
Dmitry


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Ian Bartholomew-13
Dmitry,

> Now I'm going to add a popup menu item for "one-button-click" printing :)

It's not too difficult to print the diagram directly from Dolphin. You just
have to break the Bitmap into printer page sized pieces, blit each page in
turn onto a PrinterCanvas and let it print.  As you don't want to save it
you could just use a normal Bitmap or DIBSection.

> I noticed that some of the entries in this hierarchy are truncated. Is it
> possible to build a complete diagram (and glue a hard copy afterwards)?

QuickAndDirty (tm). Add the following to the start of the #onPaintRequired:
method you modified earlier and all the labels should display in full.

self maxTextExtent: self maxTextExtent * 2.

Regards

    Ian


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Ian Bartholomew-13
> It's not too difficult to print the diagram directly from Dolphin.

Just to prove it :-)

Modify MoenTreeView to read

onPaintRequired: aPaintEvent
    "Private - Paint the receiver's view."
    | canvas bmp |

    self maxTextExtent: self maxTextExtent * 2.
    bmp := DIBSection
        width: 1400
        height: 14000
        depth: 24.

    (canvas := bmp canvas)
        fillRectangle: (0 @ 0 extent: 1400 @ 14000) brush: Brush white;
        font: self actualFont;
        pen: self linePen.
    self setDefaultCanvasColors: canvas.
    anchorNode childrenDo:
        [:each |
            self
                paint: each
                on: canvas
                fromPoint: nil].
    Smalltalk at: #ClassTree put: bmp

Display a ClassDiagram as before and then close the view.

Evaluate the following in a workspace and you should end up with a bit less
blank paper and ink :-)

bmp := Smalltalk at: #ClassTree.
p := PrinterCanvas choose.
x := y := 0.
width := 400.
height := 600.
p startDoc.
0 to: 1399 by: width do: [:left |
    0 to: 13999 by: height do: [:top |
        p startPage.
        p drawBitmap: bmp
            at: 0 @ 0
            extent: (width @ height) * 5
            from: left @ top
            extent: width @ height
            rop: 13369376 "SRCCOPY".
        p endPage]].
p endDoc

You will have to adjust the overall bitmap size (1400x14000 above), the
amount of that printed on each page (400x600) and the magnification (x5 -
needed because there are more pixels per inch on the printer than in the
bitmap) for your set-up.  All these values can be calculated properly to get
an exact representation of the screen but the above seems to give a good
enough, readable, rendering for me.

Now all you need is some scissors, a tube of prit and a used squeezy bottle
(as they say on children's TV) :-)

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Ian Bartholomew-13
OK, my final reply to myself (before everyone gets too bored with the
subject)  ...

There was a couple of problems with the workspace code that didn't show up
in my testing (surprise surprise) so the following is a version that, I
think, works and also does all the calculations for itself.

bmp := Smalltalk at: #ClassTree.
p := PrinterCanvas choose.
x := y := 0.
width := (p extent x * (bmp canvas resolution x / p resolution x)) rounded .
height := (p extent y * (bmp canvas resolution y / p resolution y)) rounded
p startDoc.
0 to: bmp extent y - 1 by: height do: [:top |
    0 to: bmp extent x - 1 by: width do: [:left |
        p startPage.
        p
            drawBitmap: bmp
            at: 0@0
            extent: p extent
            from: left @ top
            extent: (bmp extent x - left min: width) @ (bmp extent y - top
min: height)
            rop: 13369376 "SRCCOPY".
        p endPage]].
p endDoc


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Louis Sumberg-2
Ian,

I thought I'd try this, since you make it soooo easy, putting together the
code in a workspace ... but I crap out on the reference to #ClassTree.  I
don't see ClassTree in any of your goodies either.  Am I missing something
here?

-- Louis


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Christopher J. Demers
Louis Sumberg <[hidden email]> wrote in message
news:ad11qu$7jj$[hidden email]...
> I thought I'd try this, since you make it soooo easy, putting together the
> code in a workspace ... but I crap out on the reference to #ClassTree.  I
> don't see ClassTree in any of your goodies either.  Am I missing something
> here?

Look at his previous posting dated Tuesday, May 28, 2002 11:44 AM, it looks
like he is using ClassTree as a global to grab a reference to the bitmap, he
sets it in MoenTreeView<<onPaintRequired: (so it not just workspace code) .
Then the workspace code works on it.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Costas
In reply to this post by Dmitry Pankratov
You can also easily output the hierarchy to the Transcript. Add this
method:

Object>>showClasses: aClass indentWith: indentChars
        Transcript show:  indentChars , aClass printString; cr.
        aClass subclasses do: [ :each |
                 self showClasses: each indentWith: indentChars, ' '].

Then from the workspace execute this code.

Object showClasses: Object indentWith: ''

Then cut and paste into Notepad and print.

Costas

On Tue, 28 May 2002 12:38:04 +0200, "Dmitry Pankratov"
<[hidden email]> wrote:

>I would like to print the whole class diagram for learning purposes, but I
>could not find the way of doing this. Impossible? :(
>
>Regards,
>Dmitry
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: How to print class hierarchy diagram?

Louis Sumberg-2
In reply to this post by Christopher J. Demers
Thanks, Chris ... silly me, not paying attention (again).

> Look at his previous posting <snip>