| 1 |
% Copyright 2005 2015 Ovidiu Gheorghies |
| 2 |
% Licensed under the Apache License, Version 2.0. |
| 3 |
|
| 4 |
%% |
| 5 |
%% This file contains various drawings which can be used in |
| 6 |
%% UML usecase diagrams |
| 7 |
%% |
| 8 |
|
| 9 |
if known _metauml_usecase_clipart_mp: |
| 10 |
expandafter endinput |
| 11 |
fi; |
| 12 |
_metauml_usecase_clipart_mp:=1; |
| 13 |
|
| 14 |
% Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost. |
| 15 |
% The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times, |
| 16 |
% but this macro makes sure that MetaPost won't try to load the file and display a message for that. |
| 17 |
def inputonce text libraryFile= |
| 18 |
if not known scantokens ("_" & str libraryFile & "_mp"): |
| 19 |
%includeonce% show "Loading " & str libraryFile; |
| 20 |
scantokens ("input " & str libraryFile); |
| 21 |
else: |
| 22 |
%includeonce% show str libraryFile & " already loaded."; |
| 23 |
fi; |
| 24 |
enddef; |
| 25 |
|
| 26 |
inputonce util_log; |
| 27 |
|
| 28 |
vardef HumanInfo@#(expr _width, _height, _yHeadRatio, _yBodyRatio, _yHandsRatio, _xHandsRatio, _xLegsRatio)= |
| 29 |
attributes(@#); |
| 30 |
|
| 31 |
var(numeric) width, height, yHeadRatio, yBodyRatio, |
| 32 |
yHandsRatio, xHandsRatio, xLegsRatip; |
| 33 |
var(color) foreColor, shadeColor; |
| 34 |
var(numeric) shade; |
| 35 |
|
| 36 |
@#width := _width; |
| 37 |
@#height := _height; |
| 38 |
@#yHeadRatio := _yHeadRatio; |
| 39 |
@#yBodyRatio := _yBodyRatio; |
| 40 |
@#yHandsRatio := _yHandsRatio; |
| 41 |
@#xHandsRatio := _xHandsRatio; |
| 42 |
@#xLegsRatio := _xLegsRatio; |
| 43 |
|
| 44 |
@#foreColor := black; |
| 45 |
@#shadeColor := .7white; |
| 46 |
@#shade := .5; |
| 47 |
|
| 48 |
Margins.@#(2,2,1,0); |
| 49 |
enddef; |
| 50 |
|
| 51 |
vardef HumanInfoCopy@#(text src)= |
| 52 |
HumanInfo@#(src.width, src.height, src.yHeadRatio, src.yBodyRatio, src.yHandsRatio, src.xHandsRatio, src.xLegsRatio); |
| 53 |
|
| 54 |
_n_ := str @#; |
| 55 |
var(color) foreColor, shadeColor; |
| 56 |
var(numeric) shade; |
| 57 |
|
| 58 |
@#foreColor := src.foreColor; |
| 59 |
@#shadeColor := src.shadeColor; |
| 60 |
@#shade := src.shade; |
| 61 |
|
| 62 |
MarginsCopy.@#(src); |
| 63 |
enddef; |
| 64 |
|
| 65 |
HumanInfo.iHuman(25, 25, .3, .35, .55, 1, 1); |
| 66 |
|
| 67 |
vardef EHuman@#(text _info)= |
| 68 |
ObjectEquations(@#); |
| 69 |
@#className := "Human"; |
| 70 |
|
| 71 |
var(path) pHead, pBody, pHands, pLegs; |
| 72 |
|
| 73 |
HumanInfoCopy.@#info(_info); |
| 74 |
enddef; |
| 75 |
|
| 76 |
vardef Human@#= |
| 77 |
EHuman@#(iHuman); |
| 78 |
enddef; |
| 79 |
|
| 80 |
vardef Human_layout@#= |
| 81 |
if @#laidout = 1: |
| 82 |
log "Human " & (str @#) & " has already been layed out"; |
| 83 |
else: |
| 84 |
@#laidout := 1; |
| 85 |
log "Human layout: " & (str @#); |
| 86 |
|
| 87 |
attributes(@#); |
| 88 |
|
| 89 |
@#height = @#info.height; |
| 90 |
@#width = @#info.width; |
| 91 |
|
| 92 |
log "(W, H) MUST BE SET. Their values are: " & (decimal @#height) &" "& (decimal @#width); |
| 93 |
|
| 94 |
var(numeric) actualHeight, actualWidth; |
| 95 |
@#actualHeight = @#height - @#info.top - @#info.bottom; |
| 96 |
@#actualWidth = @#width - @#info.left - @#info.right; |
| 97 |
|
| 98 |
% HEAD |
| 99 |
var(pair) headS, headE, headW; |
| 100 |
|
| 101 |
ypart @#headW = ypart @#headE; |
| 102 |
.5[@#n - (0, @#info.top), @#headS] = .5[@#headE, @#headW]; |
| 103 |
(ypart @#n - @#info.top) - (ypart @#headS) = |
| 104 |
(xpart @#headE) - (xpart @#headW) = |
| 105 |
@#actualHeight * @#info.yHeadRatio; |
| 106 |
(xpart @#headS) = (xpart @#n); |
| 107 |
|
| 108 |
% BODY |
| 109 |
var(pair) bodyS; |
| 110 |
xpart @#bodyS = xpart @#headS; |
| 111 |
ypart @#headS - ypart @#bodyS = @#actualHeight * @#info.yBodyRatio; |
| 112 |
|
| 113 |
% HANDS |
| 114 |
var(pair) handsW, handsE; |
| 115 |
ypart @#handsW = ypart @#handsE = ypart @#n - (@#actualHeight * @#info.yHandsRatio); |
| 116 |
.5[xpart @#handsE, xpart @#handsW] = @#midx; |
| 117 |
xpart @#handsE - xpart @#handsW = @#actualWidth * @#info.xHandsRatio; |
| 118 |
|
| 119 |
% LEGS |
| 120 |
var(pair) footW, footE; |
| 121 |
ypart @#footW = ypart @#footE = ypart @#s + @#info.bottom; |
| 122 |
.5[xpart @#footW, xpart @#footE] = @#midx; |
| 123 |
xpart @#footE - xpart @#footW = @#actualWidth * @#info.xLegsRatio; |
| 124 |
|
| 125 |
log "Human layout completed"; |
| 126 |
fi; |
| 127 |
enddef; |
| 128 |
|
| 129 |
vardef Human_draw@#= |
| 130 |
log "Drawing human"; |
| 131 |
|
| 132 |
Human_layout.@#; |
| 133 |
objectEnsurePositioning.@#; |
| 134 |
|
| 135 |
% all coordinates must be set to known values in order to compute the paths |
| 136 |
@#pHead := (@#n - (0, @#info.top)) .. @#headE .. @#headS .. @#headW .. cycle; |
| 137 |
@#pBody := @#headS -- @#bodyS; |
| 138 |
@#pHands := @#handsW -- @#handsE; |
| 139 |
@#pLegs := @#footW -- @#bodyS -- @#footE; |
| 140 |
|
| 141 |
attributes(@#); |
| 142 |
var(pair) shadeShift; |
| 143 |
@#shadeShift = (@#info.shade, -@#info.shade); |
| 144 |
|
| 145 |
draw @#pHead shifted @#shadeShift withcolor @#info.shadeColor; |
| 146 |
draw @#pBody shifted @#shadeShift withcolor @#info.shadeColor; |
| 147 |
draw @#pHands shifted @#shadeShift withcolor @#info.shadeColor; |
| 148 |
draw @#pLegs shifted @#shadeShift withcolor @#info.shadeColor; |
| 149 |
|
| 150 |
draw @#pHead withcolor @#info.foreColor; |
| 151 |
draw @#pBody withcolor @#info.foreColor; |
| 152 |
draw @#pHands withcolor @#info.foreColor; |
| 153 |
draw @#pLegs withcolor @#info.foreColor; |
| 154 |
enddef; |
| 155 |
|
| 156 |
vardef Human_border@#= |
| 157 |
objectBox(@#) |
| 158 |
enddef; |