r5113: *** empty log message ***
[umlisp.git] / class-support.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:         classes-support.lisp
6 ;;;; Purpose:      Support for UMLisp classes
7 ;;;; Author:       Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
9 ;;;;
10 ;;;; $Id: class-support.lisp,v 1.12 2003/06/12 16:37:44 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UMLisp, is
13 ;;;;    Copyright (c) 2000-2003 by Kevin M. Rosenberg, M.D.
14 ;;;;
15 ;;;; UMLisp users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the GNU General Public License.
17 ;;;; *************************************************************************
18
19 (in-package #:umlisp)
20
21
22 ;;; Formatting routines
23
24 (defgeneric fmt-cui (c))
25 (defmethod fmt-cui ((c ucon))
26   (fmt-cui (cui c)))
27
28 (defmethod fmt-cui ((c fixnum))
29   (prefixed-fixnum-string c #\C 7))
30
31 (defmethod fmt-cui ((c string))
32   (if (eql (aref c 0) #\C)
33       c
34       (fmt-cui (parse-integer c))))
35
36 (defmethod fmt-cui ((c null))
37   (format nil "nil"))
38
39 (defgeneric fmt-lui (c))
40 (defmethod fmt-lui ((l uterm))
41   (fmt-lui (lui l)))
42
43 (defmethod fmt-lui ((l fixnum))
44   (prefixed-fixnum-string l #\L 7))
45
46 (defmethod fmt-lui ((l string))
47   (if (eql (aref l 0) #\L)
48       l
49       (fmt-lui (parse-integer l))))
50
51 (defgeneric fmt-sui (s))
52 (defmethod fmt-sui ((s ustr))
53   (fmt-sui (sui s)))
54
55 (defmethod fmt-sui ((s fixnum))
56   (prefixed-fixnum-string s #\S 7))
57
58 (defmethod fmt-sui ((s string))
59   (if (eql (aref s 0) #\S)
60       s
61       (fmt-sui (parse-integer s))))
62
63 (defgeneric fmt-tui (tui))
64 (defmethod fmt-tui ((tui fixnum))
65   (prefixed-fixnum-string tui #\T 3))
66
67 (defmethod fmt-tui ((tui string))
68   (if (eql (aref tui 0) #\T)
69       tui
70       (fmt-tui (parse-integer tui))))
71
72 (defgeneric fmt-eui (e))
73 (defmethod fmt-eui ((e fixnum))
74   (prefixed-fixnum-string e #\E 7))
75
76 (defmethod fmt-eui ((e string))
77   (if (eql (aref e 0) #\E)
78       e
79       (fmt-eui (parse-integer e))))
80
81 (defmethod fmt-eui ((e null))
82   (format nil "nil"))
83
84 ;;; Generic display functions
85
86 (eval-when (:compile-toplevel :load-toplevel :execute)
87 (defun english-term-p (obj)
88   "Returns two values: T/NIL if term is english and T/NIL if obj is a TERM"
89   (if (eq (hyperobject::class-name (hyperobject::class-of obj)) 'uterm)
90       (values (string-equal (lat obj) "ENG") t)
91     (values nil nil))))
92
93 (defun english-term-filter (obj)
94   "Retrns NIL if object is a term and not english"
95   (multiple-value-bind (is-english is-term) (english-term-p obj)
96       (or (not is-term) is-english)))
97
98 (defun print-umlsclass (obj &key (stream *standard-output*)
99                         (category :compact-text)
100                         (file-wrapper t) (english-only t) (subobjects nil)
101                         (refvars nil) (link-printer nil))
102   (view obj :stream stream :category category :subobjects subobjects
103         :file-wrapper file-wrapper
104         :filter (if english-only nil #'english-term-filter)
105         :link-printer link-printer
106         :refvars refvars))
107
108 (defmacro define-lookup-display (newfuncname lookup-func)
109   "Defines functions for looking up and displaying objects"
110   `(defun ,newfuncname  (keyval &key (stream *standard-output*) (category :compact-text)
111                          (file-wrapper t) (english-only nil) (subobjects nil))
112      (let ((obj (funcall ,lookup-func keyval)))
113        (print-umlsclass obj :stream stream :category category
114                         :file-wrapper file-wrapper :english-only english-only
115                         :subobjects subobjects)
116        obj)))
117
118 (define-lookup-display display-con #'find-ucon-cui)
119 (define-lookup-display display-term #'find-uterm-lui)
120 (define-lookup-display display-str #'find-ustr-sui)
121
122 (defun ucon-has-tui (ucon tui)
123   "Returns T if UCON has a semantic type of TUI."
124   (some #'(lambda (usty) (= tui (tui usty))) (s#sty ucon)))
125
126 (defgeneric suistr (lo))
127 (defmethod suistr ((lo ulo))
128   "Return the string for a ulo object"
129   (find-string-sui (sui lo)))
130
131 (defun uterm-pfstr (uterm)
132   "Return the preferred string for a uterm"
133   (dolist (ustr (s#str uterm))
134     (when (string= "PF" (stt ustr))
135       (return-from uterm-pfstr (str ustr)))))
136
137 (defun remove-non-english-terms (uterms)
138   (remove-if-not #'english-term-p uterms))
139
140
141 #+(or scl cmu)
142 (dolist (c '(urank udef usat uso ucxt ustr ulo uterm usty urel ucoc uatx ucon uxw uxnw uxns lexterm labr lagr lcmp lmod lnom lprn lprp lspl ltrm ltyp lwd sdef sstr sstre1 sstre2 usrl))
143     #+cmu
144     (let ((cl (pcl:find-class c)))
145       (pcl:finalize-inheritance cl))
146     #+scl
147     (let ((cl (find-class c)))
148       (clos:finalize-inheritance cl)))