1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: classes-support.lisp
6 ;;;; Purpose: Class defintions for UMLisp
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
10 ;;;; $Id: class-support.lisp,v 1.2 2003/05/02 05:37:16 kevin Exp $
12 ;;;; This file, part of UMLisp, is
13 ;;;; Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
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 ;;;; *************************************************************************
20 (declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3)))
23 ;;; Formatting routines
25 (defgeneric fmt-cui (c))
26 (defmethod fmt-cui ((c ucon))
27 (format nil "C~7,'0d" (cui c)))
29 (defmethod fmt-cui ((c fixnum))
30 (format nil "C~7,'0d" c))
32 (defmethod fmt-cui ((c string))
33 (if (eql (aref c 0) #\C)
35 (format nil "C~7,'0d" (parse-integer c))))
37 (defmethod fmt-cui ((c null))
40 (defgeneric fmt-lui (c))
41 (defmethod fmt-lui ((l uterm))
42 (format nil "L~7,'0d" (lui l)))
44 (defmethod fmt-lui ((l fixnum))
45 (format nil "L~7,'0d" l))
47 (defmethod fmt-lui ((l string))
48 (if (eql (aref l 0) #\L)
50 (format nil "L~7,'0d" (parse-integer l))))
52 (defgeneric fmt-sui (s))
53 (defmethod fmt-sui ((s ustr))
54 (format nil "S~7,'0d" (sui s)))
56 (defmethod fmt-sui ((s fixnum))
57 (format nil "S~7,'0d" s))
59 (defmethod fmt-sui ((s string))
60 (if (eql (aref s 0) #\S)
62 (format nil "S~7,'0d" (parse-integer s))))
64 (defgeneric fmt-tui (t))
65 (defmethod fmt-tui ((s fixnum))
66 (format nil "T~3,'0d" s))
68 (defmethod fmt-tui ((s string))
69 (if (eql (aref s 0) #\T)
71 (format nil "T~3,'0d" (parse-integer s))))
73 (defgeneric fmt-eui (e))
74 (defmethod fmt-eui ((e fixnum))
75 (format nil "E~7,'0d" e))
77 (defmethod fmt-eui ((e string))
78 (if (eql (aref e 0) #\E)
80 (format nil "E~7,'0d" (parse-integer e))))
82 (defmethod fmt-eui ((e null))
85 ;;; Generic display functions
87 (eval-when (:compile-toplevel :load-toplevel :execute)
88 (defun english-term-p (obj)
89 "Returns two values: T/NIL if term is english and T/NIL if obj is a TERM"
90 (if (eq (hyperobject::class-name (hyperobject::class-of obj)) 'uterm)
91 (values (string-equal (lat obj) "ENG") t)
94 (defun english-term-filter (obj)
95 "Retrns NIL if object is a term and not english"
96 (multiple-value-bind (is-english is-term) (english-term-p obj)
97 (or (not is-term) is-english)))
99 (defun print-umlsclass (obj &key (stream *standard-output*) (category :compact-text)
100 (file-wrapper t) (english-only nil) (subobjects nil)
102 (view obj :stream stream :category category :subobjects subobjects
103 :file-wrapper file-wrapper
104 :filter (if english-only nil #'english-term-filter)
107 (defmacro define-lookup-display (newfuncname lookup-func)
108 "Defines functions for looking up and displaying objects"
109 `(defun ,newfuncname (keyval &key (stream *standard-output*) (category :compact-text)
110 (file-wrapper t) (english-only nil) (subobjects nil))
111 (let ((obj (funcall ,lookup-func keyval)))
112 (print-umlsclass obj :stream stream :category category
113 :file-wrapper file-wrapper :english-only english-only
114 :subobjects subobjects)
117 (define-lookup-display display-con #'find-ucon-cui)
118 (define-lookup-display display-term #'find-uterm-lui)
119 (define-lookup-display display-str #'find-ustr-sui)
121 (defun ucon-has-tui (ucon tui)
122 "Returns T if UCON has a semantic type of TUI."
123 (some #'(lambda (usty) (= tui (tui usty))) (s#sty ucon)))
126 (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))
128 (let ((cl (pcl:find-class c)))
129 (pcl:finalize-inheritance cl))
131 (let ((cl (find-class c)))
132 (clos:finalize-inheritance cl)))