summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/metauml/metauml_class_clipart.mp
blob: 72bae5b93e39dfd5c0d82ee4472b229148e7feff (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
% MetaUML, a MetaPost library for typesetting exquisite UML diagrams.
% Copyright (C) 2005 Ovidiu Gheorghies
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

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

input util_log;

%%
%% This file contains various drawing which can be used in
%% UML class diagrams
%%

vardef LockInfo@#(expr _width, _height, _y, _d, _span, _faceColor, _topColor, _rightColor, _lockColor)=
  numeric @#y, @#d, @#span, @#width, @#height;
  color @#faceColor, @#topColor, @#rightColor, @#lockColor;

  @#width := _width;
  @#height := _height;

  @#heightRatio := _y;
  @#depthRatio := _d;
  @#span := _span;

  @#faceColor := _faceColor;
  @#topColor := _topColor;
  @#rightColor := _rightColor;
  @#lockColor := _lockColor;
enddef;

vardef LockInfoCopy@#(text src)=
  LockInfo@#(src.width, src.height, src.heightRatio, src.depthRatio, src.span,
    src.faceColor, src.topColor, src.rightColor, src.lockColor);
enddef;

LockInfo.iLock(8, 8, .55, .15, .55, .4white, .6white, .7white, .3white);

def lockLockPen=pencircle scaled .8pt enddef;
def lockLockTension=tension(1) enddef;

vardef ELock@#(text lockInfo)(expr how)=
  ObjectEquations(@#);
  @#className := "Lock";

  generic_declare(path) _n.pFace, _n.pRight, _n.pTop;
  generic_declare(path) _n.pLock;
  generic_declare(string) _n.mode;

  LockInfoCopy.@#info(lockInfo);

  @#height = @#info.height;
  @#width  = @#info.width;

  @#mode := how;

  log "ELock completed";
enddef;

vardef Lock@#(expr how)=
  ELock@#(iLock)(how);
enddef;

vardef Lock_draw@#=
  log "Drawing lock";
  log @#nw;
  log @#se;
  generic_declare(numeric) _n.depth,_n.ya, _n.xa;

  @#depth = @#info.width * @#info.depthRatio;
  @#ya = ypart @#nw - @#height * @#info.heightRatio;
  @#xa = xpart @#se - @#depth;

  @#pFace  = (xpart @#nw, @#ya) -- (@#xa, @#ya) -- (@#xa, ypart @#se) -- (xpart @#nw, ypart @#se) -- cycle;
  @#pRight = (@#xa, ypart @#se) -- (xpart @#se, ypart @#se + @#depth) --
              (xpart @#se, @#ya + @#depth) -- (@#xa, @#ya) -- cycle;
  @#pTop   = (@#xa, @#ya) -- (xpart @#se, @#ya + @#depth) --
              (xpart @#nw + @#depth, @#ya + @#depth) -- (xpart @#nw, @#ya) -- cycle;

  save myMode; string myMode;
  myMode = "base";
  if ((@#mode="private") or (@#mode="-")):
    myMode := "closed";
  elseif ((@#mode="protected") or (@#mode="#")):
    myMode := "opened";
  fi;

  if myMode="closed":
    log "Closed!";
    generic_declare(pair) _n.A, _n.B, _n.C, _n.M;
    generic_declare(numeric) _n.span;
    @#span = @#info.span * @#width;

    @#M = ((xpart @#se + xpart @#nw) / 2, @#ya + @#depth/2);
    log @#M;
    @#A = (xpart @#M - (@#span / 2), ypart @#M);
    log @#A;
    @#B = (xpart @#M + (@#span / 2), ypart @#M);
    log @#B;
    @#C = (xpart @#M, ypart @#nw);
    log @#C;
    linecap:=butt;

    @#pLock = @#A {curl 0}..lockLockTension .. @#C .. lockLockTension .. {curl 0} @#B;
         %withcolor @#info.lockColor withpen lockLockPen;
  elseif myMode="opened":
    log "Opened!";

    generic_declare(pair) _n.A, _n.B, _n.C, _n.M;
    generic_declare(numeric) _n.span;
    @#span = @#info.span * @#width;

    @#M = ((xpart @#se + xpart @#nw) / 2, @#ya + @#depth/2);
    @#A = (xpart @#M - (@#span / 2), ypart @#M) + (0, @#height/3);
    @#B = (xpart @#M + (@#span / 2), ypart @#M);
    @#C = (xpart @#M, ypart @#nw);
    log @#M, @#A, @#B, @#C;

    linecap:=butt;

    @#pLock = @#A {curl 0}..lockLockTension .. @#C .. lockLockTension .. {curl 0} @#B;
         %withcolor @#info.lockColor withpen lockLockPen;
  fi;

  fill @#pFace withcolor @#info.faceColor;
  fill @#pRight withcolor @#info.rightColor;
  fill @#pTop withcolor @#info.topColor;

  if not ((myMode = "opened") or (myMode="closed")):
    log "No lock to draw...";
  else:
    draw @#pLock withcolor @#info.lockColor withpen lockLockPen;
  fi;
enddef;