Intial code for Dia producer
Mark Addison [Fri, 20 Jan 2006 16:17:21 +0000 (16:17 +0000)]
Changes
lib/SQL/Translator/Producer/DiaUml.pm [new file with mode: 0644]
templates/dia_uml/diagram [new file with mode: 0644]
templates/dia_uml/layer [new file with mode: 0644]
templates/dia_uml/schema.tt2 [new file with mode: 0644]
templates/dia_uml/uml-attribute [new file with mode: 0644]
templates/dia_uml/uml-class [new file with mode: 0644]
templates/dia_uml/uml-class-all [new file with mode: 0644]
templates/dia_uml/uml-class-end [new file with mode: 0644]
templates/dia_uml/uml-class-start [new file with mode: 0644]

diff --git a/Changes b/Changes
index 77e89f7..b3e58e9 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@
 * Added mysql_character_set for 4.1+ -mda
 * Two experimental filters. -mda
 * Added build support for installing templates. -mda
+* Added the initial work on a template based Dia UML producer. -mda
 
 # -----------------------------------------------------------
 # 0.7    2005-06-10
diff --git a/lib/SQL/Translator/Producer/DiaUml.pm b/lib/SQL/Translator/Producer/DiaUml.pm
new file mode 100644 (file)
index 0000000..2cbf7a4
--- /dev/null
@@ -0,0 +1,98 @@
+package SQL::Translator::Producer::DiaUml;
+
+# -------------------------------------------------------------------
+# $Id: DiaUml.pm,v 1.1 2006-01-20 16:17:21 grommit Exp $
+# -------------------------------------------------------------------
+# Copyright (C) 2002-4 SQLFairy Authors
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+# 02111-1307  USA
+# -------------------------------------------------------------------
+
+=pod
+
+=head1 NAME
+
+SQL::Translator::Producer::DiaUml -
+    Produces dia UML diagrams from schema.
+
+=head1 SYNOPSIS
+
+  use SQL::Translator;
+  my $translator     = SQL::Translator->new(
+      from           => 'MySQL',
+      filename       => 'foo_schema.sql',
+      to             => 'DiaUml',
+  );
+  print $translator->translate;
+
+=head1 DESCRIPTION
+
+Currently you will get one class (with the a table
+stereotype) generated per table in the schema. The fields are added as
+attributes of the classes and their datatypes set. It doesn't currently set any
+of the relationships. It doesn't do any layout, all the classses are in one big
+stack. However it is still useful as you can use the layout tools in Dia to
+automatically arrange them horizontally or vertically.
+
+=head2 Producer Args
+
+=over 4
+
+=back
+
+=cut
+
+# -------------------------------------------------------------------
+
+use strict;
+
+use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
+$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
+$DEBUG   = 0 unless defined $DEBUG;
+
+use SQL::Translator::Utils 'debug';
+use SQL::Translator::ConfigData;
+use base qw/SQL::Translator::Producer::TT::Base/;
+# Convert produce call into a method call on our class
+sub produce { return __PACKAGE__->new( translator => shift )->run; };
+
+# Add the installed templates to the inc path.
+sub tt_config {
+    ( INCLUDE_PATH => SQL::Translator::ConfigData->config('template_dir')."/dia_uml" );
+}
+
+sub tt_schema { 'schema.tt2' }
+
+1;
+
+# -------------------------------------------------------------------
+
+=pod
+
+=head1 AUTHOR
+
+Mark Addison E<lt>grommit@users.sourceforge.netE<gt>.
+
+=head1 TODO
+
+* Add the foriegn keys from the schema as UML relations.
+
+* Layout the classes.
+
+=head1 SEE ALSO
+
+SQL::Translator.
+
+=cut
diff --git a/templates/dia_uml/diagram b/templates/dia_uml/diagram
new file mode 100644 (file)
index 0000000..8496cca
--- /dev/null
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<dia:diagram xmlns:dia="http://www.lysator.liu.se/~alla/dia/">
+  <dia:diagramdata>
+    <dia:attribute name="background">
+      <dia:color val="#ffffff"/>
+    </dia:attribute>
+    <dia:attribute name="pagebreak">
+      <dia:color val="#000099"/>
+    </dia:attribute>
+    <dia:attribute name="paper">
+      <dia:composite type="paper">
+        <dia:attribute name="name">
+          <dia:string>#A4#</dia:string>
+        </dia:attribute>
+        <dia:attribute name="tmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="bmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="lmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="rmargin">
+          <dia:real val="2.8222000598907471"/>
+        </dia:attribute>
+        <dia:attribute name="is_portrait">
+          <dia:boolean val="true"/>
+        </dia:attribute>
+        <dia:attribute name="scaling">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="fitto">
+          <dia:boolean val="false"/>
+        </dia:attribute>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="grid">
+      <dia:composite type="grid">
+        <dia:attribute name="width_x">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="width_y">
+          <dia:real val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_x">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:attribute name="visible_y">
+          <dia:int val="1"/>
+        </dia:attribute>
+        <dia:composite type="color"/>
+      </dia:composite>
+    </dia:attribute>
+    <dia:attribute name="color">
+      <dia:color val="#d8e5e5"/>
+    </dia:attribute>
+    <dia:attribute name="guides">
+      <dia:composite type="guides">
+        <dia:attribute name="hguides"/>
+        <dia:attribute name="vguides"/>
+      </dia:composite>
+    </dia:attribute>
+  </dia:diagramdata>
+
+  [% content %]
+
+</dia:diagram>
diff --git a/templates/dia_uml/layer b/templates/dia_uml/layer
new file mode 100644 (file)
index 0000000..311da56
--- /dev/null
@@ -0,0 +1,6 @@
+[%- 
+    DEFAULT name="Layer1" visible="true"
+%]
+  <dia:layer name="[% name %]" visible="[% visible %]">
+  [% content %]
+  </dia:layer>
diff --git a/templates/dia_uml/schema.tt2 b/templates/dia_uml/schema.tt2
new file mode 100644 (file)
index 0000000..d8488e3
--- /dev/null
@@ -0,0 +1,30 @@
+[%# vim:ft=tt2 -%]
+[% WRAPPER diagram %]
+    [% WRAPPER layer name="Background" %]
+        [% FOREACH table IN schema.get_tables %]
+            [% INCLUDE 'uml-class-start'
+                name       = table.name
+                stereotype = 'Table'
+                visible_operations = 'false'
+            %]
+              <dia:attribute name="attributes">
+              [% FOREACH field IN table.get_fields;
+                SET type = field.data_type;
+                SET type = "$type($field.size)" IF field.size;
+                INCLUDE "uml-attribute"
+                    name       = field.name
+                    stereotype = 'Field'
+                    type       = type
+                    value      = field.default_value
+                ;
+              END %]
+              </dia:attribute>
+              <dia:attribute name="operations"/>
+              <dia:attribute name="template">
+                <dia:boolean val="false"/>
+              </dia:attribute>
+              <dia:attribute name="templates"/>
+            [% INCLUDE 'uml-class-end' %]
+        [% END %]
+    [% END %]
+[% END %]
diff --git a/templates/dia_uml/uml-attribute b/templates/dia_uml/uml-attribute
new file mode 100644 (file)
index 0000000..1502a8b
--- /dev/null
@@ -0,0 +1,28 @@
+[%# vim:ft=tt2
+-%]
+[%-
+    DEFAULT visibility=0 abstract="false" class_scope="false"
+%]
+        <dia:composite type="umlattribute">
+          <dia:attribute name="name">
+            <dia:string>#[% name %]#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="type">
+            <dia:string>#[% type %]#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="value">
+            <dia:string>#[% value %]#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="comment">
+            <dia:string>#[% comment %]#</dia:string>
+          </dia:attribute>
+          <dia:attribute name="visibility">
+            <dia:enum val="[% visibility %]"/>
+          </dia:attribute>
+          <dia:attribute name="abstract">
+            <dia:boolean val="[% abstract %]"/>
+          </dia:attribute>
+          <dia:attribute name="class_scope">
+            <dia:boolean val="[% class_scope %]"/>
+          </dia:attribute>
+        </dia:composite>
diff --git a/templates/dia_uml/uml-class b/templates/dia_uml/uml-class
new file mode 100644 (file)
index 0000000..64112c6
--- /dev/null
@@ -0,0 +1,14 @@
+[%# vim:ft=tt2
+-%]
+    [% INCLUDE 'uml-class-start' %]
+      <dia:attribute name="attributes">
+        [%- FOREACH attributes;
+            INCLUDE "uml-attribute";
+        END %]
+      </dia:attribute>
+      <dia:attribute name="operations"/>
+      <dia:attribute name="template">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="templates"/>
+    [% INCLUDE 'uml-class-end' %]
diff --git a/templates/dia_uml/uml-class-all b/templates/dia_uml/uml-class-all
new file mode 100644 (file)
index 0000000..dfe39cb
--- /dev/null
@@ -0,0 +1,107 @@
+[%# vim:ft=tt2
+-%]
+    <dia:object type="UML - Class" version="0" id="O0">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0,0"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-0.05,-0.05;20.6,3.65"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="0,0"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="20.550000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.6000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="name">
+        <dia:string>#[% name %]#</dia:string>
+      </dia:attribute>
+      <dia:attribute name="stereotype">
+        <dia:string>#[% stereotype %]#</dia:string>
+      </dia:attribute>
+      <dia:attribute name="comment">
+        <dia:string>#[% comment %]#</dia:string>
+      </dia:attribute>
+      <dia:attribute name="abstract">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="suppress_attributes">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="suppress_operations">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="visible_attributes">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="visible_operations">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="visible_comments">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="wrap_operations">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="wrap_after_char">
+        <dia:int val="40"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_color">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="text_color">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="normal_font">
+        <dia:font family="monospace" style="0" name="Courier"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_font">
+        <dia:font family="monospace" style="88" name="Courier"/>
+      </dia:attribute>
+      <dia:attribute name="polymorphic_font">
+        <dia:font family="monospace" style="8" name="Courier"/>
+      </dia:attribute>
+      <dia:attribute name="classname_font">
+        <dia:font family="sans" style="80" name="Helvetica"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_classname_font">
+        <dia:font family="sans" style="88" name="Helvetica"/>
+      </dia:attribute>
+      <dia:attribute name="comment_font">
+        <dia:font family="sans" style="8" name="Helvetica"/>
+      </dia:attribute>
+      <dia:attribute name="font_height">
+        <dia:real val="0.80000000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="polymorphic_font_height">
+        <dia:real val="0.80000000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_font_height">
+        <dia:real val="0.80000000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="classname_font_height">
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_classname_font_height">
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="comment_font_height">
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="attributes">
+        [% FOREACH attributes %]
+            [% INCLUDE "uml-attribute" %]
+        [% END %]
+      </dia:attribute>
+      <dia:attribute name="operations"/>
+      <dia:attribute name="template">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="templates"/>
+    </dia:object>
diff --git a/templates/dia_uml/uml-class-end b/templates/dia_uml/uml-class-end
new file mode 100644 (file)
index 0000000..cbee5b7
--- /dev/null
@@ -0,0 +1,3 @@
+[%# vim:ft=tt2
+-%]
+    </dia:object>
diff --git a/templates/dia_uml/uml-class-start b/templates/dia_uml/uml-class-start
new file mode 100644 (file)
index 0000000..a96bb11
--- /dev/null
@@ -0,0 +1,98 @@
+[% # vim:ft=tt2
+    DEFAULT 
+        visible_operations='true'
+-%]
+    <dia:object type="UML - Class" version="0" id="O0">
+      <dia:attribute name="obj_pos">
+        <dia:point val="0,0"/>
+      </dia:attribute>
+      <dia:attribute name="obj_bb">
+        <dia:rectangle val="-0.05,-0.05;20.6,3.65"/>
+      </dia:attribute>
+      <dia:attribute name="elem_corner">
+        <dia:point val="0,0"/>
+      </dia:attribute>
+      <dia:attribute name="elem_width">
+        <dia:real val="20.550000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="elem_height">
+        <dia:real val="3.6000000000000001"/>
+      </dia:attribute>
+      <dia:attribute name="name">
+        <dia:string>#[% name %]#</dia:string>
+      </dia:attribute>
+      <dia:attribute name="stereotype">
+        <dia:string>#[% stereotype %]#</dia:string>
+      </dia:attribute>
+      <dia:attribute name="comment">
+        <dia:string>#[% comment %]#</dia:string>
+      </dia:attribute>
+      <dia:attribute name="abstract">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="suppress_attributes">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="suppress_operations">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="visible_attributes">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="visible_operations">
+        <dia:boolean val="[% visible_operations %]"/>
+      </dia:attribute>
+      <dia:attribute name="visible_comments">
+        <dia:boolean val="false"/>
+      </dia:attribute>
+      <dia:attribute name="wrap_operations">
+        <dia:boolean val="true"/>
+      </dia:attribute>
+      <dia:attribute name="wrap_after_char">
+        <dia:int val="40"/>
+      </dia:attribute>
+      <dia:attribute name="line_color">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="fill_color">
+        <dia:color val="#ffffff"/>
+      </dia:attribute>
+      <dia:attribute name="text_color">
+        <dia:color val="#000000"/>
+      </dia:attribute>
+      <dia:attribute name="normal_font">
+        <dia:font family="monospace" style="0" name="Courier"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_font">
+        <dia:font family="monospace" style="88" name="Courier"/>
+      </dia:attribute>
+      <dia:attribute name="polymorphic_font">
+        <dia:font family="monospace" style="8" name="Courier"/>
+      </dia:attribute>
+      <dia:attribute name="classname_font">
+        <dia:font family="sans" style="80" name="Helvetica"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_classname_font">
+        <dia:font family="sans" style="88" name="Helvetica"/>
+      </dia:attribute>
+      <dia:attribute name="comment_font">
+        <dia:font family="sans" style="8" name="Helvetica"/>
+      </dia:attribute>
+      <dia:attribute name="font_height">
+        <dia:real val="0.80000000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="polymorphic_font_height">
+        <dia:real val="0.80000000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_font_height">
+        <dia:real val="0.80000000000000004"/>
+      </dia:attribute>
+      <dia:attribute name="classname_font_height">
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="abstract_classname_font_height">
+        <dia:real val="1"/>
+      </dia:attribute>
+      <dia:attribute name="comment_font_height">
+        <dia:real val="1"/>
+      </dia:attribute>