- let imageSourceSelection = Views.ImageSourceSelection(Tag = srcImg, Margin = Thickness(3.))
-
- let updateResolution () =
- match parseAndValidatePPI imageSourceSelection.txtResolution.Text with
- | Some resolution -> srcImg.config.Parameters <- { srcImg.config.Parameters with resolution = resolution * 1.<ppi> }
- | None -> ()
-
- imageSourceSelection.txtImageNumber.Text <- srcImg.num.ToString()
- let height = srcImg.img.Height * width / srcImg.img.Width
- imageSourceSelection.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource(srcImg.img.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic))
- imageSourceSelection.chkSelection.IsChecked <- Nullable<bool>(srcImg.dateLastAnalysis.Ticks = 0L)
- imageSourceSelection.lblDateLastAnalysis.Content <- if srcImg.dateLastAnalysis.Ticks = 0L then "<Never>" else srcImg.dateLastAnalysis.ToString()
-
- imageSourceSelection.txtResolution.Text <- srcImg.config.Parameters.resolution.ToString()
- imageSourceSelection.menuZoom50X.Click.AddHandler(fun obj args -> imageSourceSelection.txtResolution.Text <- "230000"; updateResolution ())
- imageSourceSelection.menuZoom100X.Click.AddHandler(fun obj args -> imageSourceSelection.txtResolution.Text <- "460000"; updateResolution ())
-
- imageSourceSelection.txtResolution.PreviewTextInput.AddHandler(fun obj args ->
- let text = imageSourceSelection.txtResolution.Text + args.Text
- args.Handled <- match parseAndValidatePPI text with Some _ -> false | None -> true)
-
- imageSourceSelection.imagePreview.MouseLeftButtonDown.AddHandler(fun obj args ->
- let checkbox = imageSourceSelection.chkSelection
- checkbox.IsChecked <- Nullable<bool>(not (checkbox.IsChecked.HasValue && checkbox.IsChecked.Value)))
-
- imageSourceSelection.txtResolution.LostFocus.AddHandler(fun obj args -> updateResolution ())
-
- stackImagesSourceSelection.Children.Add(imageSourceSelection) |> ignore
-
- butClose.Click.AddHandler(fun obj args -> window.Root.Close())
-
- butStart.Click.AddHandler(fun obj args ->
- let imagesToProcess = [
- for imageSelection in stackImagesSourceSelection.Children |> Seq.cast<Views.ImageSourceSelection> do
- let chk = imageSelection.chkSelection.IsChecked
- if chk.HasValue && chk.Value
- then
- let srcImg = imageSelection.Tag :?> SourceImage
- 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
+ let imageSourceSelection = ImageSourceSelection (Tag = srcImg, Margin = Thickness 3.)
+ imageSourceSelection.Tag <- srcImg
+
+ imageSourceSelection.txtImageNumber.Text <- string srcImg.RomanNum
+ let height = srcImg.Img.Height * width / srcImg.Img.Width
+ imageSourceSelection.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource (srcImg.Img.Resize (width, height, Emgu.CV.CvEnum.Inter.Cubic))
+ imageSourceSelection.chkSelection.IsChecked <- Nullable<bool> (srcImg.DateLastAnalysis.Ticks = 0L)
+ imageSourceSelection.lblDateLastAnalysis.Content <- if srcImg.DateLastAnalysis.Ticks = 0L then "<Never>" else string srcImg.DateLastAnalysis
+
+ imageSourceSelection.txtResolution.Text <- if srcImg.DateLastAnalysis.Ticks = 0L then "" else string srcImg.Config.Parameters.resolution
+
+ for ppi in Utils.predefinedPPI do
+ let menu = MenuItem ()
+ menu.Header <- string ppi
+ menu.Click.AddHandler (fun obj args -> imageSourceSelection.txtResolution.Text <- string ppi.ppi)
+ imageSourceSelection.predefinedValuesMenu.Items.Add menu |> ignore
+
+ imageSourceSelection.butPPICalculator.Click.AddHandler (
+ fun obj args ->
+ match PPICalculator.showWindow win with
+ | Some resolution -> imageSourceSelection.txtResolution.Text <- string resolution
+ | None -> ()
+ )
+
+ imageSourceSelection.txtResolution.PreviewTextInput.AddHandler (
+ fun obj args ->
+ let text = imageSourceSelection.txtResolution.Text + args.Text
+ args.Handled <- match parseAndValidatePPI text with Some _ -> false | None -> true
+ )
+
+ imageSourceSelection.imagePreview.MouseLeftButtonDown.AddHandler (
+ fun obj args ->
+ let checkbox = imageSourceSelection.chkSelection
+ checkbox.IsChecked <- Nullable<bool> (not (checkbox.IsChecked.HasValue && checkbox.IsChecked.Value))
+ )
+
+ win.stackSourceImagesSelection.Children.Add (imageSourceSelection) |> ignore
+
+ // Get the new parameters for each image. If an error occurs then 'None' is returned and a message box is displayed.
+ // The boolean is 'true' if the image is selected (checked).
+ let getInputImagesParameters () : (SourceImage * bool * Parameters) list option =
+ let sourceImagesControls = win.stackSourceImagesSelection.Children |> Seq.cast<ImageSourceSelection>
+ 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 ->
+ Some (srcImg, isChecked.HasValue && isChecked.Value, { srcImg.Config.Parameters with resolution = resolution * 1.<ppi> })
+ | None ->
+ MessageBox.Show (sprintf "No resolution defined for the image number %d" srcImg.Num, "No resolution defined", MessageBoxButton.OK, MessageBoxImage.Information) |> ignore
+ None
+ } |> Seq.takeWhile (fun e -> e.IsSome) |> Seq.map (fun e -> e.Value) |> List.ofSeq
+
+ if parameters.Count () <> sourceImagesControls.Count () then
+ None