Save predefined PPI and sensor sizes in JSON files.
[master-thesis.git] / Parasitemia / ParasitemiaUI / Analysis.fs
index 5bb3500..9c7ddf0 100644 (file)
@@ -60,8 +60,12 @@ let showWindow (parent: Window) (state: State.State) : bool =
             imageSourceSelection.lblDateLastAnalysis.Content <- if srcImg.dateLastAnalysis.Ticks = 0L then "<Never>" else srcImg.dateLastAnalysis.ToString()
 
             imageSourceSelection.txtResolution.Text <- if srcImg.dateLastAnalysis.Ticks = 0L then "" else srcImg.config.Parameters.resolution.ToString()
-            imageSourceSelection.menuZoom50X.Click.AddHandler(fun obj args -> imageSourceSelection.txtResolution.Text <- "230000")
-            imageSourceSelection.menuZoom100X.Click.AddHandler(fun obj args -> imageSourceSelection.txtResolution.Text <- "460000")
+
+            for ppi in Utils.predefinedPPI do
+                let menu = MenuItem()
+                menu.Header <- ppi.ToString()
+                menu.Click.AddHandler(fun obj args -> imageSourceSelection.txtResolution.Text <- ppi.ppi.ToString())
+                imageSourceSelection.predefinedValuesMenu.Items.Add(menu) |> ignore
 
             imageSourceSelection.butPPICalculator.Click.AddHandler(fun obj args ->
                 match PPICalculator.showWindow win.Root with
@@ -128,17 +132,18 @@ let showWindow (parent: Window) (state: State.State) : bool =
                             | Some results ->
                                 for id, cells in results do
                                     state.SetResult (int id) cells
-
-                                win.Root.Dispatcher.Invoke(fun () ->
-                                    win.stackSourceImagesSelection.IsEnabled <- true
-                                    win.butStart.IsEnabled <- true
-                                    win.butClose.Content <- "Close"
-                                    updateSourceImages ())
-
                                 Logger.Log.User("All analyses terminated successfully")
                                 atLeastOneAnalysisPerformed <- true
                                 analysisPerformed <- true
-                            | None -> ())
+                            | None ->
+                                Logger.Log.User("Analysis aborted")
+
+                            win.Root.Dispatcher.Invoke(fun () ->
+                                win.progress.Value <- if maybeResults.IsSome then 100. else 0.
+                                win.stackSourceImagesSelection.IsEnabled <- true
+                                win.butStart.IsEnabled <- true
+                                win.butClose.Content <- "Close"
+                                updateSourceImages ()))
                 } |> Async.Start
         | _ -> ())
 
@@ -151,5 +156,6 @@ let showWindow (parent: Window) (state: State.State) : bool =
     lock monitor (fun () ->
         if not analysisPerformed
             then
+                // To cancel the current analysis if one is running on the next call to the progress function.
                 analysisCancelled <- true
         atLeastOneAnalysisPerformed)