cf7ed67a2f70ccc1353a7ec2163f8ccd62ec45b6
[master-thesis.git] / Parasitemia / Parasitemia / GUI / GUI.fs
1 module Parasitemia.GUI
2
3 open System.IO
4 open System.Windows
5 open System.Windows.Media
6 open System.Windows.Markup
7 open System.Windows.Shapes
8 open System.Windows.Controls
9 open System.Drawing
10 open System.Diagnostics
11 open Microsoft.Win32 // For the common dialogs.
12
13 open Emgu.CV
14 open Emgu.CV.Structure
15 open Emgu.CV.WPF
16
17 open Config
18
19 let run (defaultConfig: Config) =
20 let app = new Application()
21 let mainWindow = Views.MainWindow()
22 let ctrl (name: string): 'a =
23 mainWindow.Root.FindName(name) :?> 'a
24
25 // Utils.log <- (fun m -> log mainWindow m)
26
27 let state = State.State()
28
29 let exit: Controls.MenuItem = ctrl "menuExit"
30 let save: Controls.MenuItem = ctrl "menuSave"
31 let load: Controls.MenuItem = ctrl "menuOpen"
32
33 let txtPatient: Controls.TextBox = ctrl "txtPatient"
34
35
36 let synchronizeState () =
37 state.PatientID <- txtPatient.Text
38
39 let synchronizeView () =
40 txtPatient.Text <- state.PatientID
41
42 exit.Click.AddHandler(fun obj args -> mainWindow.Root.Close())
43 save.Click.AddHandler(fun obj args ->
44 synchronizeState ()
45 if state.FilePath = ""
46 then
47 let dialog = SaveFileDialog(AddExtension = true, DefaultExt = Pia.extension, Filter = Pia.filter);
48 let res = dialog.ShowDialog()
49 if res.HasValue && res.Value
50 then
51 state.FilePath <- dialog.FileName
52 state.Save()
53 else
54 state.Save())
55
56 load.Click.AddHandler(fun obj args ->
57 // TODO: if current state not saved and not empty, ask to save it.
58 let dialog = OpenFileDialog(Filter = Pia.filter)
59 let res = dialog.ShowDialog()
60 if res.HasValue && res.Value
61 then
62 state.FilePath <- dialog.FileName
63 state.Load()
64 synchronizeView ())
65
66 (*let txtPatient: Controls.TextBox = ctrl "txtPatient"
67 txtPatient.TextChanged.AddHandler(fun obj args ->
68 state.PatientID <- txtPatient.Text)*)
69
70 (*saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
71 saveFileDialog1.FilterIndex = 2 ;
72 saveFileDialog1.RestoreDirectory = true ;*)
73
74 // display mainWindow img
75 mainWindow.Root.Show()
76 app.Run()