155c1d1e17ad2cdc0eeaf27dd2f5b97efea8f6d0
1
module Parasitemia.GUI
5 open System.Windows.Media
6 open System.Windows.Markup
7 open System.Windows.Shapes
8 open System.Windows.Controls
10 open System.Diagnostics
11 open Microsoft.Win32 // For the common dialogs.
14 //open Emgu.CV.Structure
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
25 // Utils.log <- (fun m -> log mainWindow m)
27 let state = State.State()
29 let exit: MenuItem = ctrl "menuExit"
30 let saveFile: MenuItem = ctrl "menuSave"
31 let loadFile: MenuItem = ctrl "menuOpen"
32 let newFile: MenuItem = ctrl "menuNew"
34 let addSourceImage: MenuItem = ctrl "menuAddSourceImage"
36 let txtPatient: TextBox = ctrl "txtPatient"
38 let stackPreviews: StackPanel = ctrl "stackPreviews"
40 let butStartAnalysis: Button = ctrl "butStartAnalysis"
42 let synchronizeState () =
43 state.PatientID <- txtPatient.Text
45 let updatePreviews () =
46 stackPreviews.Children.Clear ()
47 state.ImagesSource |> Seq.iteri
(fun i imgSrc
->
48 let imgCtrl = Views.ImageSourcePreview(Margin = Thickness(3.))
49 imgCtrl.lblImageNumber
.Content <- i
+ 1
51 let height = imgSrc
.img
.Height * width / imgSrc
.img
.Width
52 imgCtrl.imagePreview
.Source <- BitmapSourceConvert.ToBitmapSource(imgSrc
.img
.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic))
53 stackPreviews.Children.Add(imgCtrl) |> ignore
)
56 txtPatient.Text <- state.PatientID
59 exit.Click.AddHandler(fun obj args
-> mainWindow.Root.Close())
60 saveFile.Click.AddHandler(fun obj args
->
62 if state.FilePath = ""
64 let dialog = SaveFileDialog(AddExtension = true, DefaultExt = Pia.extension
, Filter = Pia.filter
);
65 let res = dialog.ShowDialog()
66 if res.HasValue && res.Value
68 state.FilePath <- dialog.FileName
73 loadFile.Click.AddHandler(fun obj args
->
74 // TODO: if current state not saved and not empty, ask to save it.
75 let dialog = OpenFileDialog(Filter = Pia.filter
)
76 let res = dialog.ShowDialog()
77 if res.HasValue && res.Value
79 state.FilePath <- dialog.FileName
83 newFile.Click.AddHandler(fun obj args
->
84 // TODO: if current state not saved and not empty, ask to save it.
88 addSourceImage.Click.AddHandler(fun obj args
->
89 let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff")
90 let res = dialog.ShowDialog()
91 if res.HasValue && res.Value
93 state.AddSourceImage(dialog.FileName)
96 butStartAnalysis.Click.AddHandler(fun obj args
-> ())
98 (*let txtPatient: Controls.TextBox = ctrl "txtPatient"
99 txtPatient.TextChanged.AddHandler(fun obj args ->
100 state.PatientID <- txtPatient.Text)*)
102 (*saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
103 saveFileDialog1.FilterIndex = 2 ;
104 saveFileDialog1.RestoreDirectory = true ;*)
106 // display mainWindow img
107 mainWindow.Root.Show()