| 1 |
% Copyright 2005 2015 Ovidiu Gheorghies |
| 2 |
% Licensed under the Apache License, Version 2.0. |
| 3 |
|
| 4 |
if known _metauml_templates_mp: |
| 5 |
expandafter endinput |
| 6 |
fi; |
| 7 |
_metauml_templates_mp:=1; |
| 8 |
|
| 9 |
% Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost. |
| 10 |
% The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times, |
| 11 |
% but this macro makes sure that MetaPost won't try to load the file and display a message for that. |
| 12 |
def inputonce text libraryFile= |
| 13 |
if not known scantokens ("_" & str libraryFile & "_mp"): |
| 14 |
%includeonce% show "Loading " & str libraryFile; |
| 15 |
scantokens ("input " & str libraryFile); |
| 16 |
else: |
| 17 |
%includeonce% show str libraryFile & " already loaded."; |
| 18 |
fi; |
| 19 |
enddef; |
| 20 |
|
| 21 |
inputonce metauml_defaults; |
| 22 |
inputonce util_log; |
| 23 |
|
| 24 |
vardef TemplateInfo@#= |
| 25 |
color @#background; |
| 26 |
color @#borderColor; |
| 27 |
numeric @#borderScale; |
| 28 |
|
| 29 |
@#background := .9white; |
| 30 |
@#borderColor := black; |
| 31 |
@#borderScale := 1; |
| 32 |
|
| 33 |
FontInfo.@#iFont(metauml_defaultFont, .9); |
| 34 |
PictureInfo.@#iPict(2, 2, 2, 2)(@#iFont); |
| 35 |
PictureStackInfo.@#iStack(2, 2, 1, 1)(7)(@#iPict); |
| 36 |
|
| 37 |
@#iStack.iPict.ignoreNegativeBase := 1; |
| 38 |
enddef; |
| 39 |
|
| 40 |
vardef TemplateInfoCopy@#(text src)= |
| 41 |
color @#background; |
| 42 |
color @#borderColor; |
| 43 |
numeric @#borderScale; |
| 44 |
|
| 45 |
@#background := src.background; |
| 46 |
@#borderColor := src.borderColor; |
| 47 |
@#borderScale := src.borderScale; |
| 48 |
|
| 49 |
FontInfoCopy.@#iFont(src.iFont); |
| 50 |
PictureInfoCopy.@#iPict(src.iPict); |
| 51 |
PictureStackInfoCopy.@#iStack(src.iStack); |
| 52 |
enddef; |
| 53 |
|
| 54 |
TemplateInfo.iTemplate; |
| 55 |
|
| 56 |
% |
| 57 |
% Template |
| 58 |
% |
| 59 |
vardef ETemplate@#(text _info)(text templates) = |
| 60 |
ObjectEquations(@#); |
| 61 |
@#className := "Template"; |
| 62 |
|
| 63 |
TemplateInfoCopy.@#info(_info); |
| 64 |
|
| 65 |
EPictureStack.@#elementsStack(@#info.iStack)(templates)("vleftbase"); |
| 66 |
|
| 67 |
@#nw = @#elementsStack.nw; |
| 68 |
@#se = @#elementsStack.se; |
| 69 |
enddef; |
| 70 |
|
| 71 |
vardef Template@#(text templates) = |
| 72 |
ETemplate@#(iTemplate)(templates); |
| 73 |
enddef; |
| 74 |
|
| 75 |
vardef EClassTemplate@#(text _info)(text templates)(text theClass)= |
| 76 |
ETemplate.@#(_info)(templates); |
| 77 |
Template_attachToClass.@#(theClass); |
| 78 |
enddef; |
| 79 |
|
| 80 |
vardef ClassTemplate@#(text templates)(text theClass)= |
| 81 |
EClassTemplate.@#(iTemplate)(templates)(theClass); |
| 82 |
enddef; |
| 83 |
|
| 84 |
vardef Template_layout@#= |
| 85 |
if @#laidout = 1: |
| 86 |
log "Template " & (str @#) & " has already been layed out"; |
| 87 |
else: |
| 88 |
@#laidout := 1; |
| 89 |
log "Template layout: " & (str @#); |
| 90 |
PictureStack_layout.@#elementsStack; |
| 91 |
fi; |
| 92 |
enddef; |
| 93 |
|
| 94 |
vardef Template_paintSkin@# = |
| 95 |
log "Painting template skin..."; |
| 96 |
|
| 97 |
fill objectBox(@#) withcolor @#info.background; |
| 98 |
|
| 99 |
draw objectBox(@#) dashed evenly scaled .8 |
| 100 |
withpen pencircle scaled @#info.borderScale withcolor @#info.borderColor; |
| 101 |
enddef; |
| 102 |
|
| 103 |
vardef Template_draw@# = |
| 104 |
Template_layout.@#; |
| 105 |
|
| 106 |
Template_paintSkin.@#; |
| 107 |
drawObject(@#elementsStack); |
| 108 |
enddef; |
| 109 |
|
| 110 |
vardef Template_attachToClass@#(text theClass)= |
| 111 |
Template_layout.@#; |
| 112 |
Class_layout.theClass; |
| 113 |
|
| 114 |
log "--- Attaching template " & (str @#) & " to class " & (str theClass); |
| 115 |
|
| 116 |
save __nItems, __nameToRight; |
| 117 |
|
| 118 |
__nItems := @#elementsStack.nItems; |
| 119 |
__nameToRight := theClass.right - theClass.namePict.right; |
| 120 |
|
| 121 |
@#elementsStack.pict[__nItems-1].midy = theClass.top; |
| 122 |
|
| 123 |
if __nameToRight > @#width/2: |
| 124 |
@#midx = theClass.right; |
| 125 |
log "X"; |
| 126 |
else: |
| 127 |
@#midx = theClass.right + (@#width/2 - __nameToRight) + 2; |
| 128 |
log "Y"; |
| 129 |
fi; |
| 130 |
|
| 131 |
%@#elementsStack.pict[__nItems-1].info.boxed:=1; |
| 132 |
enddef; |