Version 0 of Playing UML

Updated 2001-10-02 17:30:56

Richard Suchenwirth - UML, the Unified Modeling Language, is a convention for drawing diagrams in object-oriented analysis and design. After an OOA/D course (without a CASE tool at hand), I felt tempted to draw UML graphic objects on a canvas.

The first shot is a class box for class diagrams:

 proc umlbox {c x y class} {
  foreach {name atts meths} $class break
  set id [$c create text $x $y -text $name -anchor nw -font {Helvetica 8 bold}]
  $c itemconfig $id -tag box$id
   set y1 [expr [lindex [$c bbox $id] 3]]
   $c create text $x $y1 -text [join $atts \n] -anchor nw -font {Helvetica 8} -tag box$id
   set y2 [expr [lindex [$c bbox box$id] 3]]
   $c create text $x $y2 -text [join $meths \n] -anchor nw -font {Helvetica 8} -tag box$id
   foreach {x0 y0 x1 y3} [$c bbox box$id] break
   set x0 [expr $x0-2]
   $c create rect $x0 $y0 $x1 $y3 -tag box$id
   $c create line $x0 $y1 $x1 $y1 -tag box$id
   $c create line $x0 $y2 $x1 $y2 -tag box$id   
   return box$id
 }

Usage example:

 umlbox $c 50 50 {Longname {att1 att2} {meth1 meth2}}

More to come...


Arts and crafts of Tcl-Tk programming