open Config
open Types
-let run (defaultConfig: Config) =
+let run (defaultConfig: Config) (fileToOpen: string option) =
let app = new Application()
let mainWindow = Views.MainWindow()
- let ctrl (name: string): 'a =
- mainWindow.Root.FindName(name) :?> 'a
+ let ctrl (name: string): 'a = mainWindow.Root.FindName(name) :?> 'a
let colorRBCHealthy = Brushes.YellowGreen
let colorRBCInfected = Brushes.Red
let menuLoadFile: MenuItem = ctrl "menuOpen"
let menuNewFile: MenuItem = ctrl "menuNew"
let menuAddSourceImage: MenuItem = ctrl "menuAddSourceImage"
+ let menuAnalysis: MenuItem = ctrl "menuAnalysis"
let menuStartAnalysis: MenuItem = ctrl "menuStartAnalysis"
+ let menuView: MenuItem = ctrl "menuView"
let menuHightlightRBC: MenuItem = ctrl "menuHightlightRBC"
+ let menuAbout: MenuItem = ctrl "menuAbout"
let txtPatient: TextBox = ctrl "txtPatient"
let txtGlobalParasitemia: TextBox = ctrl "txtGlobalParasitemia"
let y = rbc.center.Y - rbcHeight / 2. |> Utils.roundInt
let w = Utils.roundInt rbcWidth
let h = Utils.roundInt rbcHeight
- //Utils.dprintfn "w: %A, h: %A, cx: %A, cy: %A, img.w: %A, img.h: %A" w h x y img.Width img.Height
img.GetSubRect(System.Drawing.Rectangle(System.Drawing.Point((if x < 0 then 0 else x), (if y < 0 then 0 else y)),
System.Drawing.Size((if x + w >= img.Width then img.Width - x else w),
(if y + h >= img.Height then img.Height - y else h))))
txtImageInformation.Inlines.Add(Documents.LineBreak())
txtImageInformation.Inlines.Add(Documents.Run("Average erytrocyte diameter: ", FontWeight = FontWeights.Bold))
- txtImageInformation.Inlines.Add(Documents.Run(string (Utils.roundInt <| 2. * srcImg.rbcRadius)))
- txtImageInformation.Inlines.Add(Documents.Run(" px"))
+ txtImageInformation.Inlines.Add(Documents.Run(srcImg.config.RBCRadius.ToString()))
txtImageInformation.Inlines.Add(Documents.LineBreak())
txtImageInformation.Inlines.Add(Documents.Run("Last analysis: ", FontWeight = FontWeights.Bold))
then
imgCtrl.ReleaseMouseCapture())
-
let updatePreviews () =
stackPreviews.Children.Clear ()
for srcImg in state.SourceImages do
updatePreviews ()
updateGlobalParasitemia ()
- txtPatient.TextChanged.AddHandler(fun obj args -> state.PatientID <- txtPatient.Text)
+ let loadFile (filepath: string) =
+ askSaveCurrent ()
+ state.FilePath <- filepath
+ state.Load()
+ updateGUI ()
+
+ txtPatient.LostFocus.AddHandler(fun obj args -> state.PatientID <- txtPatient.Text)
menuExit.Click.AddHandler(fun obj args ->
askSaveCurrent ()
let dialog = OpenFileDialog(Filter = PiaZ.filter)
let res = dialog.ShowDialog()
if res.HasValue && res.Value
- then
- askSaveCurrent ()
- state.FilePath <- dialog.FileName
- state.Load()
- updateGUI ())
+ then loadFile dialog.FileName)
menuNewFile.Click.AddHandler(fun obj args ->
askSaveCurrent ()
updateGUI())
menuAddSourceImage.Click.AddHandler(fun obj args ->
- let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff")
+ let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff", Multiselect = true)
let res = dialog.ShowDialog()
if res.HasValue && res.Value
then
- let srcImg = state.AddSourceImage(dialog.FileName)
- addPreview srcImg
+ let noSourceImage = state.SourceImages.Count() = 0
+
+ for filename in dialog.FileNames do
+ let srcImg = state.AddSourceImage filename defaultConfig
+ addPreview srcImg
+
updateGlobalParasitemia ()
- if state.SourceImages.Count() = 1
+
+ if noSourceImage
then
updateCurrentImage ())
+ menuAnalysis.SubmenuOpened.AddHandler(fun obj args -> menuStartAnalysis.IsEnabled <- state.SourceImages.Count() > 0)
+
menuStartAnalysis.Click.AddHandler(fun obj args ->
- if Analysis.showWindow mainWindow.Root state defaultConfig
+ if Analysis.showWindow mainWindow.Root state
then
updateGlobalParasitemia ()
updateCurrentImage ())
updateRBCFramesPreview ()
updateRBCFramesCurrent ())
+ menuAbout.Click.AddHandler(fun obj args -> About.showWindow mainWindow.Root)
+
// Zoom on the current image.
let adjustCurrentImageBorders (deltaX: float) (deltaY: float) =
borderCurrentImage.BorderThickness <-
scrollViewCurrentImage.ScrollChanged.AddHandler(fun obj args -> updateViewportPreview ())
mainWindow.Root.Show()
+
+ match fileToOpen with
+ | Some filepath -> loadFile filepath
+ | None -> ()
+
app.Run()
\ No newline at end of file