Commits

Anonymous committed c50811d Draft

init

  • Participants

Comments (0)

Files changed (3)

+^3d/
+let zinfo_exe = "./zinfo_stub"
+
+;;
+(************)
+
+#use "topfind";;
+#require "unix";;
+
+let ( / ) = Filename.concat
+
+open Printf
+
+(**********)
+
+let step = 0.01
+let prefix = "/home/x/cnc"
+let out = prefix / "tmp/a.png"
+let tmpstl = prefix / "tmp/tmp.stl"
+let defs = "-m -w1280 -h800 --cavity=black --core=white"
+let template = prefix / "etc/60mm.stl"
+
+type box =
+  { xmin : float
+  ; xmax : float
+  ; ymin : float
+  ; ymax : float
+  ; zmin : float
+  ; zmax : float
+  }
+
+let get_zinfo arg =
+  let inch = Unix.open_process_in (zinfo_exe ^ " " ^ Filename.quote arg) in
+  let finally () = ignore (Unix.close_process_in inch) in
+  try
+    ( let rec get_vals () =
+        try
+          Scanf.fscanf inch " %[^=]=%f "
+            (fun k v -> (k, v) :: get_vals ())
+        with End_of_file -> []
+      in
+      let vals = get_vals ()
+      in
+      let v n = List.assoc n vals in
+      { xmin = v "X_MIN"
+      ; xmax = v "X_MAX"
+      ; ymin = v "Y_MIN"
+      ; ymax = v "Y_MAX"
+      ; zmin = v "Z_MIN"
+      ; zmax = v "Z_MAX"
+      }
+    )
+  with e -> (finally (); raise e)
+
+let read_all arg =
+  let bt = get_zinfo template in
+  let b = get_zinfo arg in
+  let bad =
+        bt.xmin < b.xmin
+     || bt.ymin < b.ymin
+     || bt.zmin < b.zmin
+     || bt.xmax > b.xmax
+     || bt.ymax > b.ymax
+     || bt.zmax > b.zmax
+  in
+  let () =
+    printf
+      "x = %f .. %f\n\
+       y = %f .. %f\n\
+       z = %f .. %f\n\
+       step = %f\n\
+       out = %s\n\
+       template = %s\n\
+      "
+       b.xmin b.xmax
+       b.ymin b.ymax
+       b.zmin b.zmax
+       step
+       out
+       template
+  in
+  let () = printf "check size..\n" in
+  if bad
+  then
+    failwith "Size out of range!"
+  else
+    let cmd_ok fmt =
+      ksprintf
+        (fun cmd ->
+           match Sys.command cmd with
+           | 0 -> ()
+           | c -> failwith (sprintf "exit code %i from command: %s" c cmd)
+        )
+        fmt
+    in
+    let q () = Filename.quote in
+    ( printf "merge stl with border..\n"
+    ; cmd_ok "stlmerge %a %a %a" q template q arg q tmpstl
+    ; printf "start slice.py..\n"
+    ; cmd_ok "slice.py %a %a -o %a -z%f,%f,%f"
+        q defs q tmpstl q out b.zmin b.zmax step
+    ; printf " Done."
+    )
+
+let () =
+  match Sys.argv with
+  | [| _me ; arg |] -> read_all arg
+  | _ -> failwith "you must specify exactly one argument"
+#!/bin/sh
+
+echo 'X_MIN=0.000000 X_MAX=10.000000 Y_MIN=0.000000 Y_MAX=10.000000 Z_MIN=0.000000 Z_MAX=10.000000'