c1187ec80ea4df343057066c1ca24de8facd7ba6
1
module ParasitemiaUI.PPICalculator
5 open System.Windows.Media
6 open System.Windows.Markup
7 open System.Windows.Shapes
8 open System.Windows.Controls
9 open System.Diagnostics
11 open ParasitemiaCore.Types
12 open ParasitemiaCore.UnitsOfMeasure
16 let showWindow (parent
: Window) : int option =
17 let win = Views.PPICalculatorWindow()
18 win.Root.Owner <- parent
19 win.Root.Left <- parent
.Left + parent
.ActualWidth / 2. - win.Root.Width / 2.
20 win.Root.Top <- parent
.Top + parent
.ActualHeight / 2. - win.Root.Height / 2.
22 for size
in Utils.sensorSizes
do
23 win.cmbSensorSize
.Items.Add(size
) |> ignore
24 win.cmbSensorSize
.SelectedIndex <- 0
26 let resolution (w_p
: float<px
>) (w_mm
: float<mm
>) (zoom
: float) : float<ppi
> =
27 w_p
* zoom
/ mmToInch w_mm
29 let updateCurrentResolution () =
30 let { w
= w
; h
= h
} = win.cmbSensorSize
.SelectedValue :?> SensorSize
33 let parseDouble txt
errorMess = match Double.TryParse(txt
) with true, value
-> Success value | _ -> Fail errorMess
36 { let! sensorResolution
= parseDouble win.txtSensorResolution
.Text "The sensor resolution is not valid"
37 let! zoom
= parseDouble win.txtZoom
.Text "The zoom is not valid"
38 let wPixel = 1.<px
> * sqrt
(sensorResolution
* 1e6 / ratio)
39 return
! Success (float <| resolution wPixel w zoom) } with
40 | Success res
-> win.txtImageResolution
.Text <- (int (res
/ 1000.) * 1000).ToString()
41 | Fail mess
-> win.txtImageResolution
.Text <- mess
43 win.butCancel
.Click.AddHandler(fun obj args
-> win.Root.DialogResult <- Nullable<bool>(false); win.Root.Close())
44 win.butOK
.Click.AddHandler(fun obj args
-> win.Root.DialogResult <- Nullable<bool>(true); win.Root.Close())
46 win.cmbSensorSize
.SelectionChanged.AddHandler(fun obj arg
-> updateCurrentResolution ())
47 win.txtSensorResolution
.TextChanged.AddHandler(fun obj arg
-> updateCurrentResolution ())
48 win.txtZoom
.TextChanged.AddHandler(fun obj arg
-> updateCurrentResolution ())
50 let result = win.Root.ShowDialog()
51 if result.HasValue && result.Value
53 match Int32.TryParse win.txtImageResolution
.Text with
54 | true, res
-> Some res