File: plugin.ml

package info (click to toggle)
mlpost 0.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,844 kB
  • sloc: ml: 21,094; javascript: 4,047; makefile: 430; ansic: 34; lisp: 19; sh: 15
file content (211 lines) | stat: -rw-r--r-- 6,657 bytes parent folder | download | duplicates (2)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
open Mlpost
open Box

(* Some custom values *)

let padding = Num.bp 15.

let delta = Num.bp 10.

let unused = "$^\\star$"

let big_title s = "\\textbf{\\Large{" ^ s ^ "}}"

let small_title s = "\\textbf{\\large{" ^ s ^ "}}"

let external_color = Color.rgb8 255 165 0

let internal_color = Color.rgb8 50 205 50

let plugin_color = Color.lightcyan

let make_color = (*Color.rgb8 46 139 97*) Color.rgb8 250 128 114

(* Some very useful functions: should be in some way in the mlpost API? *)

let box_width ?name ?style ?fill ?dy w b =
  box ?name ?style ?fill ?dy ~dx:(Num.divf (Num.subn w (width b)) 2.) b

let box_height ?name ?style ?fill ?dx h b =
  box ?name ?style ?fill ?dx ~dy:(Num.divf (Num.subn h (height b)) 2.) b

let box_hw ?name ?style ?fill h b =
  box ?name ?style ?fill
    ~dx:(Num.divf (Num.subn h (width b)) 2.)
    ~dy:(Num.divf (Num.subn h (height b)) 2.)
    b

let vbox_same_width ?name ?padding ~style l =
  let max = List.fold_left (fun acc b -> Num.maxn acc (width b)) Num.zero l in
  vbox ?name ?padding
    (List.map
       (fun b ->
         box_width max ~style ?fill:(get_fill b) ~dy:Num.zero (clear_stroke b))
       l)

let simulate_box ?name b = empty ?name ~width:(width b) ~height:(height b) ()

let xmed ?(coef = 0.5) p1 p2 =
  Num.multf coef (Num.addn (Point.xpart p1) (Point.xpart p2))

let ymed ?(coef = 0.5) p1 p2 =
  Num.multf coef (Num.addn (Point.ypart p1) (Point.ypart p2))

let med ?xcoef ?ycoef p1 p2 =
  Point.pt (xmed ?coef:xcoef p1 p2, ymed ?coef:ycoef p1 p2)

(* Some special functions for this figure *)

let modul ?(color = external_color) ?same_height ?same_width s =
  let t = tex s in
  match (same_height, same_width) with
  | None, None -> box ~name:s ~fill:color ~style:Rect t
  | Some h, None -> box_height ~name:s ~fill:color ~style:Rect h t
  | None, Some w -> box_width ~name:s ~fill:color ~style:Rect w t
  | Some h, Some w ->
      assert (h = w);
      box_hw ~name:s ~fill:color ~style:Rect w t

(* The figure itself *)

let fig =
  (* special external modules: Makefile.dynamic + Design *)
  let design =
    rect ~fill:external_color ~name:"design"
      (vbox [ tex ("Design" ^ unused); tex "(GUI extension point)" ])
  in
  let std_modul = modul ~same_height:(height design) in
  let dynmake = std_modul ~color:make_color "Makefile.dynamic" in

  (* empty modules *)
  let empty_modules =
    let empty_module =
      std_modul ~color:internal_color ~same_width:(height design) ""
    in
    let points = tex "\\dots" in
    hbox ~padding [ empty_module; points; empty_module ]
  in

  (* Plug-in implem *)
  let title = tex (small_title "Plug-in implementation") in
  let register = std_modul ~color:internal_color "Register" in
  let options = std_modul ~color:internal_color "Options" in
  let b = vbox_same_width ~padding:delta ~style:Rect [ register; options ] in
  let b = vbox ~padding:delta [ title; b; empty_modules ] in
  let implem =
    round_rect ~name:"implem" ~fill:internal_color ~dx:delta ~dy:delta b
  in

  (* Plug-in GUI *)
  let gui = tex (small_title "Plug-in GUI$^\\star$") in
  let gui =
    round_rect ~name:"gui" ~dx:delta
      ~dy:(Num.addn delta (Num.divf padding 2.))
      ~fill:internal_color
      (vbox ~padding:delta [ gui; empty_modules ])
  in

  (* Makefile *)
  let makefile =
    let t = tex "\\large{Makefile}" in
    box_height ~name:"makefile" ~style:RoundRect ~fill:make_color
      (Num.subn (height implem) (Num.addn (height gui) padding))
      t
  in

  (* Makefile + Plug-in GUI *)
  let right_box =
    vbox_same_width ~name:"right" ~padding ~style:RoundRect [ makefile; gui ]
  in

  (* left column *)
  let db = std_modul "Db.Main" in
  let dyn = std_modul ("Dynamic" ^ unused) in
  let journal = std_modul ("Journal" ^ unused) in
  let plugin = std_modul "Plugin" in
  let prj = std_modul ("Project" ^ unused) in
  let typ = std_modul ("Type" ^ unused) in
  let left_box =
    vbox_same_width ~padding ~style:Rect [ db; dyn; plugin; typ; journal; prj ]
  in

  (* setting the components as a matrix *)
  let figure =
    hbox ~padding:(Num.multf 3. padding)
      [
        left_box;
        tabularl ~hpadding:padding ~vpadding:(Num.multf 3. padding)
          [
            [ empty (); dynmake ];
            [
              simulate_box ~name:"ei" implem; simulate_box ~name:"er" right_box;
            ];
            [ empty (); design ];
          ];
      ]
  in
  let getf s = get s figure in

  (* add the Plug-in directory and merge it in the matrix *)
  let nwp = north_west (getf "ei") in
  let sep = south_east (getf "er") in
  let main_box = hbox ~padding [ implem; right_box ] in
  let title = tex (big_title "Plug-in directory") in
  let b = vbox ~padding:delta [ title; main_box ] in
  let directory_box =
    let r = round_rect ~fill:plugin_color ~dx:padding ~dy:delta b in
    center (med nwp sep) r
  in

  (* caption *)
  let caption =
    tabularl ~pos:`Right ~hpadding:delta
      [
        [ tex "\\textbf{Caption:}"; empty () ];
        [ tex "$\\star$"; tex "part not covered in this tutorial" ];
        [
          hbox ~padding [ empty ~name:"c1" (); empty ~name:"c2" () ];
          tex "registration points";
        ];
      ]
  in

  let full_box = vbox ~padding ~pos:`Right [ figure; caption ] in

  let arrow src dst = Helpers.box_arrow src dst in
  let third_arrow coef ?(yscale = 1.) src dst =
    let p1 = Point.yscale (Num.bp yscale) (west src) in
    let p4 =
      (*east dst*)
      (* JS: don't know why it doesn't work *)
      Point.pt (Point.xpart (east left_box), Point.ypart (east dst))
    in
    let x = xmed ~coef p1 p4 in
    let p2 = Point.pt (x, Point.ypart p1) in
    let p3 = Point.pt (x, Point.ypart p4) in
    (* Why [Arrow.draw] does not provide the same result? *)
    Arrow.simple (Path.pathp ~style:Path.jLine [ p1; p2; p3; p4 ])
  in
  let getf s = get s full_box in
  Command.seq
    [
      draw full_box;
      draw directory_box;
      arrow (getf "c1") (getf "c2");
      arrow (get "gui" directory_box) (getf "design");
      arrow (get "makefile" directory_box) (getf "Makefile.dynamic");
      third_arrow 0.32 (get "Options" directory_box) (getf "Plugin");
      third_arrow 0.35
        (get "Register" directory_box)
        (getf ("Dynamic" ^ unused));
      third_arrow 0.35 (get "Register" directory_box) (getf "Db.Main");
      third_arrow 0.4 ~yscale:1.23
        (get "implem" directory_box)
        (getf ("Journal" ^ unused));
      third_arrow 0.4 ~yscale:1.23
        (get "implem" directory_box)
        (getf ("Type" ^ unused));
      third_arrow 0.55 ~yscale:1.5 directory_box (getf ("Project" ^ unused));
    ]

let _ = Metapost.emit "plugin" fig