summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/metauml/metauml_templates.mp
blob: 940377bc202e1854a7002307e9e983372972734e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
% Copyright 2005 2015 Ovidiu Gheorghies
% Licensed under the Apache License, Version 2.0.

if known _metauml_templates_mp:
  expandafter endinput
fi;
_metauml_templates_mp:=1;

% Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost.
% The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times, 
% but this macro makes sure that MetaPost won't try to load the file and display a message for that.
def inputonce text libraryFile=
	if not known scantokens ("_" & str libraryFile & "_mp"):
		%includeonce% show "Loading " & str libraryFile;
		scantokens ("input " & str libraryFile);
	else:
		%includeonce% show str libraryFile & " already loaded.";
	fi;
enddef;

inputonce metauml_defaults;
inputonce util_log;

vardef TemplateInfo@#=
  color @#background;
  color @#borderColor;
  numeric @#borderScale;

  @#background := .9white;
  @#borderColor := black;
  @#borderScale := 1;

  FontInfo.@#iFont(metauml_defaultFont, .9);
  PictureInfo.@#iPict(2, 2, 2, 2)(@#iFont);
  PictureStackInfo.@#iStack(2, 2, 1, 1)(7)(@#iPict);

  @#iStack.iPict.ignoreNegativeBase := 1;
enddef;

vardef TemplateInfoCopy@#(text src)=
  color @#background;
  color @#borderColor;
  numeric @#borderScale;

  @#background := src.background;
  @#borderColor := src.borderColor;
  @#borderScale := src.borderScale;

  FontInfoCopy.@#iFont(src.iFont);
  PictureInfoCopy.@#iPict(src.iPict);
  PictureStackInfoCopy.@#iStack(src.iStack);
enddef;

TemplateInfo.iTemplate;

%
% Template
%
vardef ETemplate@#(text _info)(text templates) =
  ObjectEquations(@#);
  @#className := "Template";

  TemplateInfoCopy.@#info(_info);

  EPictureStack.@#elementsStack(@#info.iStack)(templates)("vleftbase");

  @#nw = @#elementsStack.nw;
  @#se = @#elementsStack.se;
enddef;

vardef Template@#(text templates) =
  ETemplate@#(iTemplate)(templates);
enddef;

vardef EClassTemplate@#(text _info)(text templates)(text theClass)=
  ETemplate.@#(_info)(templates);
  Template_attachToClass.@#(theClass);
enddef;

vardef ClassTemplate@#(text templates)(text theClass)=
  EClassTemplate.@#(iTemplate)(templates)(theClass);
enddef;

vardef Template_layout@#=
  if @#laidout = 1:
    log "Template " & (str @#) & " has already been layed out";
  else:
    @#laidout := 1;
    log "Template layout: " & (str @#);
    PictureStack_layout.@#elementsStack;
  fi;
enddef;

vardef Template_paintSkin@# =
  log "Painting template skin...";

  fill objectBox(@#) withcolor @#info.background;

  draw objectBox(@#) dashed evenly scaled .8
       withpen pencircle scaled @#info.borderScale withcolor @#info.borderColor;
enddef;

vardef Template_draw@# =
  Template_layout.@#;

  Template_paintSkin.@#;
  drawObject(@#elementsStack);
enddef;

vardef Template_attachToClass@#(text theClass)=
  Template_layout.@#;
  Class_layout.theClass;

  log "--- Attaching template " & (str @#) & " to class " & (str theClass);

  save __nItems, __nameToRight;

  __nItems := @#elementsStack.nItems;
  __nameToRight := theClass.right - theClass.namePict.right;

  @#elementsStack.pict[__nItems-1].midy = theClass.top;

  if __nameToRight > @#width/2:
    @#midx = theClass.right;
    log "X";
  else:
    @#midx = theClass.right + (@#width/2 - __nameToRight) + 2;
    log "Y";
  fi;

  %@#elementsStack.pict[__nItems-1].info.boxed:=1;
enddef;