697bbef3e9d7be3bc93040af90eed9987b4ff5e6
1
module ParasitemiaUI.PPICalculator
6 open ParasitemiaUIControls
7 open ParasitemiaCore.Types
8 open ParasitemiaCore.UnitsOfMeasure
12 let showWindow (parent
: Window) : int option =
13 let win = PPICalculatorWindow ()
15 win.Left <- parent
.Left + parent
.ActualWidth / 2. - win.Width / 2.
16 win.Top <- parent
.Top + parent
.ActualHeight / 2. - win.Height / 2.
18 for size
in Utils.sensorSizes
do
19 win.cmbSensorSize
.Items.Add (size
) |> ignore
20 win.cmbSensorSize
.SelectedIndex <- 0
22 let resolution (w_p
: float<px
>) (w_mm
: float<mm
>) (zoom
: float) : float<ppi
> =
23 w_p
* zoom
/ mmToInch w_mm
25 let updateCurrentResolution () =
26 let { w
= w
; h
= h
} = win.cmbSensorSize
.SelectedValue :?> SensorSize
29 let parseDouble (txt
: string) (errorMess
: string) = match Double.TryParse (txt
) with true, value
-> Success value | _ -> Fail errorMess
33 let! sensorResolution
= parseDouble win.txtSensorResolution
.Text "The sensor resolution is not valid"
34 let! zoom
= parseDouble win.txtZoom
.Text "The zoom is not valid"
35 let wPixel = 1.<px
> * sqrt
(sensorResolution
* 1e6 / ratio)
36 return
! Success (float <| resolution wPixel w zoom)
38 | Success res
-> win.txtImageResolution
.Text <- int (res
/ 1000.) * 1000 |> string
39 | Fail mess
-> win.txtImageResolution
.Text <- mess
41 win.butCancel
.Click.AddHandler (fun obj args
-> win.DialogResult <- Nullable<bool> (false); win.Close ())
42 win.butOK
.Click.AddHandler (fun obj args
-> win.DialogResult <- Nullable<bool> (true); win.Close ())
44 win.cmbSensorSize
.SelectionChanged.AddHandler (fun obj arg
-> updateCurrentResolution ())
45 win.txtSensorResolution
.TextChanged.AddHandler (fun obj arg
-> updateCurrentResolution ())
46 win.txtZoom
.TextChanged.AddHandler (fun obj arg
-> updateCurrentResolution ())
48 let result = win.ShowDialog ()
49 if result.HasValue && result.Value then
50 match Int32.TryParse win.txtImageResolution
.Text with
51 | true, res
-> Some res