2024-08-28 20:42:52 +01:00
|
|
|
signature FILE_THREAD =
|
|
|
|
|
sig
|
|
|
|
|
val run: FileMessage.t Mailbox.mbox -> unit
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
structure FileThread :> FILE_THREAD =
|
|
|
|
|
struct
|
2024-08-29 00:05:30 +01:00
|
|
|
open AppType
|
2024-08-28 20:42:52 +01:00
|
|
|
open FileMessage
|
|
|
|
|
|
2024-08-29 00:05:30 +01:00
|
|
|
val filename = "a.dsc"
|
|
|
|
|
|
|
|
|
|
fun helpSaveTriangles (triangles, io) =
|
|
|
|
|
case triangles of
|
|
|
|
|
{x1, y1, x2, y2, x3, y3} :: tl =>
|
|
|
|
|
let
|
|
|
|
|
val triString = String.concat
|
|
|
|
|
[ "x1:"
|
|
|
|
|
, Real32.toString x1
|
|
|
|
|
, " y1:"
|
|
|
|
|
, Real32.toString y1
|
|
|
|
|
|
|
|
|
|
, " x2:"
|
|
|
|
|
, Real32.toString x2
|
|
|
|
|
, " y2:"
|
|
|
|
|
, Real32.toString y2
|
|
|
|
|
|
|
|
|
|
, " x3:"
|
|
|
|
|
, Real32.toString x3
|
|
|
|
|
, " y3:"
|
|
|
|
|
, Real32.toString y3
|
|
|
|
|
, "\n"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
val _ = TextIO.output (io, triString)
|
|
|
|
|
in
|
|
|
|
|
helpSaveTriangles (tl, io)
|
|
|
|
|
end
|
|
|
|
|
| [] => ()
|
|
|
|
|
|
|
|
|
|
fun saveTriangles triangles =
|
|
|
|
|
let val io = TextIO.openOut filename
|
|
|
|
|
in helpSaveTriangles (triangles, io)
|
|
|
|
|
end
|
|
|
|
|
|
2024-08-28 20:42:52 +01:00
|
|
|
fun run fileMailbox =
|
|
|
|
|
let
|
|
|
|
|
val _ =
|
|
|
|
|
case Mailbox.recv fileMailbox of
|
2024-08-29 00:05:30 +01:00
|
|
|
SAVE_TRIANGLES triangles => saveTriangles triangles
|
|
|
|
|
| LOAD_TRIANGLES => ()
|
2024-08-28 20:42:52 +01:00
|
|
|
| EXPORT_TRIANGLES triangles => ()
|
|
|
|
|
in
|
|
|
|
|
run fileMailbox
|
|
|
|
|
end
|
|
|
|
|
end
|