Initial Commit
[packages] / xemacs-packages / cogre / cogre-uml.el
1 ;;; cogre-uml.el --- UML support for COGRE
2
3 ;;; Copyright (C) 2001 Eric M. Ludlam
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: oop, uml
7 ;; X-RCS: $Id: cogre-uml.el,v 1.1 2007-11-26 15:04:23 michaels Exp $
8
9 ;; This file is not part of GNU Emacs.
10
11 ;; This is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This software is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27 ;;
28 ;; Provides UML support for COGRE.
29 ;;
30 ;; See http://c2.com/cgi/wiki?UmlAsciiArt for more examples of using
31 ;; ASCII to draw UML diagrams.
32
33 (require 'cogre)
34
35 ;;; Code:
36 (defclass cogre-package (cogre-node)
37   ((name-default :initform "Package")
38    (blank-lines-top :initform 0)
39    (blank-lines-bottom :initform 0)
40    (alignment :initform left)
41    (subgraph :initarg :subgraph
42              :initform nil
43              :type (or null cogre-graph)
44              :documentation
45              "A graph which represents the classes within this package.
46 The subgraph should be scanned to extract all the elements drawn into
47 the package node.")
48    )
49   "A Package node.
50 Packages represent other class diagrams, and list the major nodes
51 within them.  They can be linked by dependency links.")
52
53 (defmethod cogre-node-slots ((package cogre-package))
54   "Return a list containing the list of classes in PACKAGE.
55 The `subgraph' slot must be scanned for this information."
56   (list nil)
57   )
58
59 (defclass cogre-class (cogre-node)
60   ((name-default :initform "Class")
61    (blank-lines-top :initform 0)
62    (blank-lines-bottom :initform 0)
63    (alignment :initform left)
64    (class :initarg :class
65           :initform nil
66           :type (or string list)
67           :custom sexp
68           :documentation
69           "The semantic token representing the class this is drawing.")
70    (attributes :initarg :attributes
71                :initform nil
72                :type list
73                :custom sexp
74                :documentation
75                "A list of attributes belonging to this Class representation.
76 Each attribute must in the form of a semantic token. ei.
77  (\"object-name\" variable \"type\" ... )
78 See `semantic-fetch-tags' for details on possible token forms.
79 These items do not need to be REAL semantic tokens, however.
80 Only the format is needed to get the name/typing information.")
81    (methods :initarg :methods
82             :initform nil
83             :type list
84             :custom sexp
85             :documentation
86             "A list of methods belonging to this Class representation.
87 See `attribute' slot for details on the form of each token in this list.")
88    )
89   "A Class node.
90 Class nodes represent a class, and can list the attributes and methods
91 within them.  Classes can have attribute links, and class hierarchy links.")
92
93 (defmethod cogre-uml-stoken->uml ((class cogre-class) stoken &optional text)
94   "For CLASS convert a Semantic style token STOKEN into a uml definition.
95 It also adds properties that enable editing, and interaction with
96 this node.  Optional argument TEXT is a preformatted string."
97   (let ((newtext 
98          (or text
99              (concat (car stoken) ":"
100                      (cond ((stringp (nth 2 stoken))
101                             (nth 2 stoken))
102                            ((listp (nth 2 stoken))
103                             (car (nth 2 stoken)))
104                            (t ""))))))
105     ;; Add in some useful properties
106     (add-text-properties 0 (length newtext)
107                          (list 'semantic stoken
108                                
109                                )
110                          newtext)
111     ;; Return the string
112     newtext))
113
114 (defmethod cogre-node-slots ((class cogre-class))
115   "Return a list of each section, including title, attributes, and methods.
116 Argument CLASS is the class whose slots are referenced."
117   (list
118    (mapcar (lambda (s) (cogre-uml-stoken->uml class s)) (oref class attributes))
119    (mapcar (lambda (s) (cogre-uml-stoken->uml class s)) (oref class methods))
120    ))
121
122 (defclass cogre-inherit (cogre-link)
123   ((end-glyph :initform [ (" ^ " "/_\\")
124                           ("_|_" "\\ /" " V ")
125                           (" /|" "< |" " \\|")
126                           ("|\\" "|/") ])
127    (horizontal-preference-ratio :initform .1)
128    )
129   "This type of link indicates that the two nodes reference infer inheritance.
130 The `start' node is the child, and the `end' node is the parent.
131 This is supposed to infer that START inherits from END.")
132
133 (defclass cogre-aggrigate (cogre-link)
134   ((start-glyph :initform [ ("/\\ " "\\/" )
135                             ("/\\ " "\\/" )
136                             ("<>") ("<>") ])
137    (horizontal-preference-ratio :initform 1)
138    )
139   "This type of link indicates aggregation.
140 The `start' node is the owner of the aggregation, the `end' node is
141 the item being aggregated.
142 This is supposed to infer that START contains END.")
143
144
145 (provide 'cogre-uml)
146
147 ;;; cogre-uml.el ends here