X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FAnalysis.fs;h=e276be6232daede51dd7be603af3c5c7823290e0;hp=9c7ddf0541cd2988062313f456a82f19ca30b771;hb=e8d14548fc5b127970fccb19bad146512f7ac6d9;hpb=9343c4deb0bf88c58d9c92d465d8e99f64656875 diff --git a/Parasitemia/ParasitemiaUI/Analysis.fs b/Parasitemia/ParasitemiaUI/Analysis.fs index 9c7ddf0..e276be6 100644 --- a/Parasitemia/ParasitemiaUI/Analysis.fs +++ b/Parasitemia/ParasitemiaUI/Analysis.fs @@ -18,25 +18,28 @@ open ParasitemiaCore.Config open Types -let showWindow (parent: Window) (state: State.State) : bool = +let showWindow (parent : Window) (state : State.State) : bool = let win = Views.AnalysisWindow() - win.Root.Owner <- parent - win.Root.Left <- parent.Left + parent.ActualWidth / 2. - win.Root.Width / 2. - win.Root.Top <- parent.Top + parent.ActualHeight / 2. - win.Root.Height / 2. + win.Owner <- parent + win.Left <- (if parent.WindowState = WindowState.Maximized then 0. else parent.Left) + parent.ActualWidth / 2. - win.Width / 2. + win.Top <- (if parent.WindowState = WindowState.Maximized then 0. else parent.Top) + parent.ActualHeight / 2. - win.Height / 2. let logListener = - { new Logger.IListener with - member this.NewEntry severity mess = - win.Root.Dispatcher.Invoke(fun () -> - win.textLog.Inlines.Add(Documents.Run(mess)) - win.textLog.Inlines.Add(Documents.LineBreak()) - win.scrollLog.ScrollToBottom()) } + { + new Logger.IListener with + member this.NewEntry severity _header mess = + win.Dispatcher.Invoke(fun () -> + win.textLog.Inlines.Add(Documents.Run(mess)) + win.textLog.Inlines.Add(Documents.LineBreak()) + win.scrollLog.ScrollToBottom() + ) + } Logger.Log.AddListener(logListener) let minPPI = 1. let maxPPI = 10e6 - let parseAndValidatePPI (input: string) : float option = + let parseAndValidatePPI (input : string) : float option = match Double.TryParse(input) with | true, value when value >= minPPI && value <= maxPPI -> Some value | _ -> None @@ -68,7 +71,7 @@ let showWindow (parent: Window) (state: State.State) : bool = imageSourceSelection.predefinedValuesMenu.Items.Add(menu) |> ignore imageSourceSelection.butPPICalculator.Click.AddHandler(fun obj args -> - match PPICalculator.showWindow win.Root with + match PPICalculator.showWindow win with | Some resolution -> imageSourceSelection.txtResolution.Text <- resolution.ToString() | None -> ()) @@ -86,33 +89,38 @@ let showWindow (parent: Window) (state: State.State) : bool = // The boolean is 'true' if the image is selected (checked). let getInputImagesParameters () : (SourceImage * bool * Parameters) list option = let sourceImagesControls = win.stackSourceImagesSelection.Children |> Seq.cast - let parameters = seq { - for srcImgCtrl in sourceImagesControls do - let srcImg = srcImgCtrl.Tag :?> SourceImage - let isChecked = srcImgCtrl.chkSelection.IsChecked - match parseAndValidatePPI srcImgCtrl.txtResolution.Text with - | Some resolution -> - yield Some (srcImg, isChecked.HasValue && isChecked.Value, { srcImg.config.Parameters with resolution = resolution * 1. }) - | None -> - MessageBox.Show(sprintf "No resolution defined for the image number %d" srcImg.num, "No resolution defined", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore - yield None } |> Seq.takeWhile (fun e -> e.IsSome) |> Seq.map (fun e -> e.Value) |> List.ofSeq - if parameters.Count() <> sourceImagesControls.Count() - then None - else Some parameters - - win.butClose.Click.AddHandler(fun obj args -> win.Root.Close()) + let parameters = + seq { + for srcImgCtrl in sourceImagesControls do + let srcImg = srcImgCtrl.Tag :?> SourceImage + let isChecked = srcImgCtrl.chkSelection.IsChecked + match parseAndValidatePPI srcImgCtrl.txtResolution.Text with + | Some resolution -> + yield Some (srcImg, isChecked.HasValue && isChecked.Value, { srcImg.config.Parameters with resolution = resolution * 1. }) + | None -> + MessageBox.Show(sprintf "No resolution defined for the image number %d" srcImg.num, "No resolution defined", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore + yield None + } |> Seq.takeWhile (fun e -> e.IsSome) |> Seq.map (fun e -> e.Value) |> List.ofSeq + + if parameters.Count() <> sourceImagesControls.Count() then + None + else + Some parameters + + win.butClose.Click.AddHandler(fun obj args -> win.Close()) win.butStart.Click.AddHandler(fun obj args -> match getInputImagesParameters () with | Some imagesParameters -> - let imagesToProcess = [ - for srcImg, selected, parameters in imagesParameters do - srcImg.config.Parameters <- parameters // Save parameters. - if selected - then yield srcImg.num.ToString(), srcImg.config, srcImg.img ] - - if imagesToProcess.IsEmpty - then + let imagesToProcess = + [ + for srcImg, selected, parameters in imagesParameters do + srcImg.config.Parameters <- parameters // Save parameters. + if selected then + yield srcImg.num.ToString(), srcImg.config, srcImg.img + ] + + if imagesToProcess.IsEmpty then MessageBox.Show("No image selected", "Cannot start analysis", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore else win.stackSourceImagesSelection.IsEnabled <- false @@ -124,7 +132,7 @@ let showWindow (parent: Window) (state: State.State) : bool = let maybeResults = ParasitemiaCore.Analysis.doMultipleAnalysis imagesToProcess - (Some (fun progress -> win.Root.Dispatcher.Invoke(fun () -> win.progress.Value <- float progress); not analysisCancelled)) + (Some (fun progress -> win.Dispatcher.Invoke(fun () -> win.progress.Value <- float progress); not analysisCancelled)) lock monitor ( fun() -> @@ -132,30 +140,34 @@ let showWindow (parent: Window) (state: State.State) : bool = | Some results -> for id, cells in results do state.SetResult (int id) cells - Logger.Log.User("All analyses terminated successfully") + Logger.Log.Info "All analyses terminated successfully" atLeastOneAnalysisPerformed <- true analysisPerformed <- true | None -> - Logger.Log.User("Analysis aborted") + Logger.Log.Info "Analysis aborted" - win.Root.Dispatcher.Invoke(fun () -> + win.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 ())) + updateSourceImages () + ) + ) } |> Async.Start - | _ -> ()) + | _ -> () + ) - win.Root.Loaded.AddHandler(fun obj args -> updateSourceImages ()) + win.Loaded.AddHandler(fun obj args -> updateSourceImages ()) - win.Root.ShowDialog() |> ignore + win.ShowDialog() |> ignore Logger.Log.RmListener(logListener) - lock monitor (fun () -> - if not analysisPerformed - then + 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) + atLeastOneAnalysisPerformed + )