From: Greg Burri Date: Fri, 8 Jan 2016 12:25:17 +0000 (+0100) Subject: Add the panel to display image source previews. X-Git-Tag: 1.0.11~61 X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=da6b1ee15d0368ef9f2d9734b0d72996cbc227d8;p=master-thesis.git Add the panel to display image source previews. --- diff --git a/Parasitemia/Parasitemia/GUI/GUI.fs b/Parasitemia/Parasitemia/GUI/GUI.fs index cf7ed67..155c1d1 100644 --- a/Parasitemia/Parasitemia/GUI/GUI.fs +++ b/Parasitemia/Parasitemia/GUI/GUI.fs @@ -10,8 +10,8 @@ open System.Drawing open System.Diagnostics open Microsoft.Win32 // For the common dialogs. -open Emgu.CV -open Emgu.CV.Structure +//open Emgu.CV +//open Emgu.CV.Structure open Emgu.CV.WPF open Config @@ -26,21 +26,38 @@ let run (defaultConfig: Config) = let state = State.State() - let exit: Controls.MenuItem = ctrl "menuExit" - let save: Controls.MenuItem = ctrl "menuSave" - let load: Controls.MenuItem = ctrl "menuOpen" + let exit: MenuItem = ctrl "menuExit" + let saveFile: MenuItem = ctrl "menuSave" + let loadFile: MenuItem = ctrl "menuOpen" + let newFile: MenuItem = ctrl "menuNew" - let txtPatient: Controls.TextBox = ctrl "txtPatient" + let addSourceImage: MenuItem = ctrl "menuAddSourceImage" + let txtPatient: TextBox = ctrl "txtPatient" + + let stackPreviews: StackPanel = ctrl "stackPreviews" + + let butStartAnalysis: Button = ctrl "butStartAnalysis" let synchronizeState () = state.PatientID <- txtPatient.Text - let synchronizeView () = + let updatePreviews () = + stackPreviews.Children.Clear () + state.ImagesSource |> Seq.iteri (fun i imgSrc -> + let imgCtrl = Views.ImageSourcePreview(Margin = Thickness(3.)) + imgCtrl.lblImageNumber.Content <- i + 1 + let width = 200 + let height = imgSrc.img.Height * width / imgSrc.img.Width + imgCtrl.imagePreview.Source <- BitmapSourceConvert.ToBitmapSource(imgSrc.img.Resize(width, height, Emgu.CV.CvEnum.Inter.Cubic)) + stackPreviews.Children.Add(imgCtrl) |> ignore ) + + let updateGUI () = txtPatient.Text <- state.PatientID + updatePreviews () exit.Click.AddHandler(fun obj args -> mainWindow.Root.Close()) - save.Click.AddHandler(fun obj args -> + saveFile.Click.AddHandler(fun obj args -> synchronizeState () if state.FilePath = "" then @@ -53,7 +70,7 @@ let run (defaultConfig: Config) = else state.Save()) - load.Click.AddHandler(fun obj args -> + loadFile.Click.AddHandler(fun obj args -> // TODO: if current state not saved and not empty, ask to save it. let dialog = OpenFileDialog(Filter = Pia.filter) let res = dialog.ShowDialog() @@ -61,7 +78,22 @@ let run (defaultConfig: Config) = then state.FilePath <- dialog.FileName state.Load() - synchronizeView ()) + updateGUI ()) + + newFile.Click.AddHandler(fun obj args -> + // TODO: if current state not saved and not empty, ask to save it. + state.Reset() + updateGUI()) + + addSourceImage.Click.AddHandler(fun obj args -> + let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff") + let res = dialog.ShowDialog() + if res.HasValue && res.Value + then + state.AddSourceImage(dialog.FileName) + updatePreviews ()) + + butStartAnalysis.Click.AddHandler(fun obj args -> ()) (*let txtPatient: Controls.TextBox = ctrl "txtPatient" txtPatient.TextChanged.AddHandler(fun obj args -> diff --git a/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml b/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml new file mode 100644 index 0000000..3593e0e --- /dev/null +++ b/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml.fs b/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml.fs new file mode 100644 index 0000000..b92e9af --- /dev/null +++ b/Parasitemia/Parasitemia/GUI/ImageSourcePreview.xaml.fs @@ -0,0 +1,17 @@ +namespace Parasitemia.Views + +open System +open System.Windows +open System.Windows.Data +open System.Windows.Input + +open FSharp.ViewModule +open FsXaml + +type ImageSourcePreview = XAML<"GUI/ImageSourcePreview.xaml", true> + +(* type ImageSourcePreviewController() = + inherit UserControlViewController() *) + +(* type ImageSourcePreviewViewModel() = + inherit ViewModelBase() *) diff --git a/Parasitemia/Parasitemia/GUI/MainWindow.xaml b/Parasitemia/Parasitemia/GUI/MainWindow.xaml index 5b7a3c5..2892330 100644 --- a/Parasitemia/Parasitemia/GUI/MainWindow.xaml +++ b/Parasitemia/Parasitemia/GUI/MainWindow.xaml @@ -9,6 +9,9 @@ + + + @@ -17,8 +20,8 @@ + - @@ -34,6 +37,18 @@ + + + + + + + + + +