done with loading file into app (loaded triangles are visible, etc.)
This commit is contained in:
@@ -214,6 +214,17 @@ struct
|
|||||||
fun getLoadTriangleMsg model =
|
fun getLoadTriangleMsg model =
|
||||||
(model, FILE LOAD_TRIANGLES)
|
(model, FILE LOAD_TRIANGLES)
|
||||||
|
|
||||||
|
fun useTriangles (model, triangles) =
|
||||||
|
let
|
||||||
|
val model = AppWith.useTriangles (model, triangles)
|
||||||
|
val drawVec = Triangles.toVector model
|
||||||
|
val drawMsg = DRAW_TRIANGLES_AND_RESET_DOTS drawVec
|
||||||
|
in
|
||||||
|
(model, DRAW drawMsg)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun trianglesLoadError model = (model, NO_MAILBOX)
|
||||||
|
|
||||||
fun update (model: app_type, inputMsg) =
|
fun update (model: app_type, inputMsg) =
|
||||||
case inputMsg of
|
case inputMsg of
|
||||||
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
MOUSE_MOVE {x = mouseX, y = mouseY} =>
|
||||||
@@ -228,4 +239,6 @@ struct
|
|||||||
| KEY_G => toggleGraph model
|
| KEY_G => toggleGraph model
|
||||||
| KEY_CTRL_S => getSaveTrianglesMsg model
|
| KEY_CTRL_S => getSaveTrianglesMsg model
|
||||||
| KEY_CTRL_L => getLoadTriangleMsg model
|
| KEY_CTRL_L => getLoadTriangleMsg model
|
||||||
|
| USE_TRIANGLES triangles => useTriangles (model, triangles)
|
||||||
|
| TRIANGLES_LOAD_ERROR => trianglesLoadError model
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ sig
|
|||||||
* Real32.real
|
* Real32.real
|
||||||
* (Real32.real * Real32.real)
|
* (Real32.real * Real32.real)
|
||||||
-> AppType.app_type
|
-> AppType.app_type
|
||||||
|
|
||||||
|
val useTriangles: AppType.app_type * AppType.triangle list -> AppType.app_type
|
||||||
end
|
end
|
||||||
|
|
||||||
structure AppWith :> APP_WITH =
|
structure AppWith :> APP_WITH =
|
||||||
@@ -306,4 +308,36 @@ struct
|
|||||||
, mouseY = mouseY
|
, mouseY = mouseY
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun useTriangles (app: app_type, triangles) =
|
||||||
|
let
|
||||||
|
val
|
||||||
|
{ xClickPoints
|
||||||
|
, yClickPoints
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, undo
|
||||||
|
, redo
|
||||||
|
, mouseX
|
||||||
|
, mouseY
|
||||||
|
, showGraph
|
||||||
|
, triangles = _
|
||||||
|
, triangleStage = _
|
||||||
|
} = app
|
||||||
|
|
||||||
|
val triangleStage = NO_TRIANGLE
|
||||||
|
in
|
||||||
|
{ triangleStage = triangleStage
|
||||||
|
, triangles = triangles
|
||||||
|
, undo = []
|
||||||
|
, redo = []
|
||||||
|
, showGraph = showGraph
|
||||||
|
, xClickPoints = xClickPoints
|
||||||
|
, yClickPoints = yClickPoints
|
||||||
|
, windowWidth = windowWidth
|
||||||
|
, windowHeight = windowHeight
|
||||||
|
, mouseX = mouseX
|
||||||
|
, mouseY = mouseY
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
signature FILE_THREAD =
|
signature FILE_THREAD =
|
||||||
sig
|
sig
|
||||||
val run: FileMessage.t Mailbox.mbox -> unit
|
val run: FileMessage.t Mailbox.mbox * InputMessage.t Mailbox.mbox -> unit
|
||||||
end
|
end
|
||||||
|
|
||||||
structure FileThread :> FILE_THREAD =
|
structure FileThread :> FILE_THREAD =
|
||||||
struct
|
struct
|
||||||
open AppType
|
open AppType
|
||||||
open FileMessage
|
open FileMessage
|
||||||
|
open InputMessage
|
||||||
|
|
||||||
val filename = "a.dsc"
|
val filename = "a.dsc"
|
||||||
|
|
||||||
@@ -72,15 +73,18 @@ struct
|
|||||||
end
|
end
|
||||||
| NONE => let val triangles = List.rev acc in OK triangles end
|
| NONE => let val triangles = List.rev acc in OK triangles end
|
||||||
|
|
||||||
fun loadTriangles () =
|
fun loadTriangles inputMailbox =
|
||||||
let
|
let
|
||||||
val io = TextIO.openIn filename
|
val io = TextIO.openIn filename
|
||||||
val triangles = parse (io, [])
|
val triangles = parse (io, [])
|
||||||
val _ = TextIO.closeIn io
|
val _ = TextIO.closeIn io
|
||||||
|
|
||||||
|
val inputMsg =
|
||||||
|
case triangles of
|
||||||
|
OK triangles => USE_TRIANGLES triangles
|
||||||
|
| PARSE_ERROR => TRIANGLES_LOAD_ERROR
|
||||||
in
|
in
|
||||||
case triangles of
|
Mailbox.send (inputMailbox, inputMsg)
|
||||||
OK triangles => print "parse success\n"
|
|
||||||
| PARSE_ERROR => print "parse error\n"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun helpSaveTriangles (triangles, io) =
|
fun helpSaveTriangles (triangles, io) =
|
||||||
@@ -114,14 +118,14 @@ struct
|
|||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|
||||||
fun run fileMailbox =
|
fun run (fileMailbox, inputMailbox) =
|
||||||
let
|
let
|
||||||
val _ =
|
val _ =
|
||||||
case Mailbox.recv fileMailbox of
|
case Mailbox.recv fileMailbox of
|
||||||
SAVE_TRIANGLES triangles => saveTriangles triangles
|
SAVE_TRIANGLES triangles => saveTriangles triangles
|
||||||
| LOAD_TRIANGLES => loadTriangles ()
|
| LOAD_TRIANGLES => loadTriangles inputMailbox
|
||||||
| EXPORT_TRIANGLES triangles => ()
|
| EXPORT_TRIANGLES triangles => ()
|
||||||
in
|
in
|
||||||
run fileMailbox
|
run (fileMailbox, inputMailbox)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ struct
|
|||||||
, 0
|
, 0
|
||||||
))
|
))
|
||||||
|
|
||||||
val _ = CML.spawn (fn () => FileThread.run fileMailbox)
|
val _ = CML.spawn (fn () => FileThread.run (fileMailbox, inputMailbox))
|
||||||
in
|
in
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ sig
|
|||||||
| KEY_G
|
| KEY_G
|
||||||
| KEY_CTRL_S
|
| KEY_CTRL_S
|
||||||
| KEY_CTRL_L
|
| KEY_CTRL_L
|
||||||
|
| USE_TRIANGLES of AppType.triangle list
|
||||||
|
| TRIANGLES_LOAD_ERROR
|
||||||
end
|
end
|
||||||
|
|
||||||
structure InputMessage :> INPUT_MESSAGE =
|
structure InputMessage :> INPUT_MESSAGE =
|
||||||
@@ -24,4 +26,6 @@ struct
|
|||||||
| KEY_G
|
| KEY_G
|
||||||
| KEY_CTRL_S
|
| KEY_CTRL_S
|
||||||
| KEY_CTRL_L
|
| KEY_CTRL_L
|
||||||
|
| USE_TRIANGLES of AppType.triangle list
|
||||||
|
| TRIANGLES_LOAD_ERROR
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user