Ejemplo n.º 1
0
        // If the is a common (trimmed) data value for the provided data label in the given fileIDs, return that value, otherwise null.
        public string GetValueDisplayStringCommonToFileIds(string dataLabel)
        {
            List <int> fileIds = this.ThumbnailGrid.GetSelected();

            // There used to be a bug in this code, which resulted from this being invoked in SwitchToThumbnailGridView() when the grid was already being displayed.
            //  I have kept the try/catch in just in case it rears its ugly head elsewhere. Commented out Debug statements are here just in case we need to reexamine it.
            try
            {
                // If there are no file ids, there is nothing to show
                if (fileIds.Count == 0)
                {
                    return(null);
                }

                // This can cause the crash, when the id in fileIds[0] doesn't exist
                ImageRow imageRow = this.FileDatabase.FileTable[fileIds[0]];

                // The above line is what causes the crash, when the id in fileIds[0] doesn't exist
                // System.Diagnostics.Debug.Print("Success: " + dataLabel + ": " + fileIds[0]);

                string contents = imageRow.GetValueDisplayString(dataLabel);
                contents = contents.Trim();

                // If the values of success imagerows (as defined by the fileIDs) are the same as the first one,
                // then return that as they all have a common value. Otherwise return an empty string.
                int fileIdsCount = (fileIds == null) ? 0 : fileIds.Count;
                for (int i = 1; i < fileIdsCount; i++)
                {
                    imageRow = this.FileDatabase.FileTable[fileIds[i]];
                    string new_contents = imageRow.GetValueDisplayString(dataLabel);
                    new_contents = new_contents.Trim();
                    if (new_contents != contents)
                    {
                        // We have a mismatch
                        return(null);
                    }
                }
                // All values match
                return(contents);
            }
            catch
            {
                // This catch occurs when the id in fileIds[0] doesn't exist
                System.Diagnostics.Debug.Write("Catch in GetValueDisplayStringCommonToFileIds: " + dataLabel);
                return(null);
            }
        }
Ejemplo n.º 2
0
        // Update the species detected against the threshold in both the database and the file table
        private void UpdateSpeciesDetected(double threshold)
        {
            FileTable fileTable = this.fileDatabase.FileTable;
            // We now have an unselected temporary data table
            // Get the original value of each, and update each date by the corrected amount if possible
            List <ImageRow> filesToAdjust = new List <ImageRow>();
            List <ColumnTuplesWithWhere> filesToUpdate = new List <ColumnTuplesWithWhere>();

            for (int row = 0; row < fileTable.RowCount; row++)
            {
                ImageRow imageRow = this.fileDatabase.FileTable[row];
                bool?    newSpeciesDetectedValue = null;
                bool     forceUpdate             = false;
                // Get the current SpeciesDetected value
                if (bool.TryParse(imageRow.GetValueDisplayString(Constant.Recognition.SpeciesDetectedDataLabel), out bool currentSpeciesDetectedValue) == false)
                {
                    forceUpdate = true;
                }
                if (double.TryParse(imageRow.GetValueDisplayString(Constant.Recognition.DataLabelMaxConfidence), out double maxConfidence) == false)
                {
                    // If there is no confidence level, then the detector is likely not working so we always set the new Species detected value to false
                    forceUpdate             = true;
                    newSpeciesDetectedValue = false;
                }
                else
                {
                    newSpeciesDetectedValue = (maxConfidence >= threshold) ? true : false;
                }
                if (forceUpdate == true || newSpeciesDetectedValue != currentSpeciesDetectedValue)
                {
                    // System.Diagnostics.Debug.Print(newSpeciesDetectedValue.ToString());
                    string newSpeciesDetectedValueAsString = (newSpeciesDetectedValue == true)
                        ? Constant.BooleanValue.True
                        : Constant.BooleanValue.False;
                    imageRow.SetValueFromDatabaseString(Constant.Recognition.SpeciesDetectedDataLabel, newSpeciesDetectedValueAsString);
                    filesToAdjust.Add(imageRow);
                    filesToUpdate.Add(new ColumnTuplesWithWhere(new List <ColumnTuple>
                    {
                        new ColumnTuple(Constant.Recognition.SpeciesDetectedDataLabel, newSpeciesDetectedValueAsString)
                    }, imageRow.ID));
                }
            }
            // update the database with the new values
            this.fileDatabase.UpdateFiles(filesToUpdate);
        }
Ejemplo n.º 3
0
        // Propagate the current value of this control forward from this point across the current set of selected images
        protected virtual void MenuItemPropagateForward_Click(object sender, RoutedEventArgs e)
        {
            // Check the arguments for null
            ThrowIf.IsNullArgument(sender, nameof(sender));

            // Get the chosen data entry control
            DataEntryControl control = (DataEntryControl)((MenuItem)sender).Tag;

            if (control == null)
            {
                return;
            }

            int currentRowIndex = (this.ThumbnailGrid.IsVisible == false) ? this.ImageCache.CurrentRow : this.ThumbnailGrid.GetSelected()[0];
            int imagesAffected  = this.FileDatabase.CountAllCurrentlySelectedFiles - currentRowIndex - 1;

            if (imagesAffected == 0)
            {
                // Display a dialog box saying there is nothing to copy forward.
                // Note that this should never be displayed, as the menu shouldn't be highlit if we are on the last image
                // But just in case...
                Dialogs.DataEntryNothingToCopyForwardDialog(Application.Current.MainWindow);
                return;
            }

            // Display the appropriate dialog box that explains what will happen. Arguments indicate how many files will be affected, and is tuned to the type of control
            ImageRow imageRow     = (this.ThumbnailGrid.IsVisible == false) ? this.ImageCache.Current : this.FileDatabase.FileTable[this.ThumbnailGrid.GetSelected()[0]];
            string   valueToCopy  = imageRow.GetValueDisplayString(control.DataLabel);
            bool     checkForZero = control is DataEntryCounter;

            if (Dialogs.DataEntryConfirmCopyForwardDialog(Application.Current.MainWindow, valueToCopy, imagesAffected, checkForZero) != true)
            {
                return;
            }

            // Update the files from the next row (as we are copying from the current row) to the end.
            Mouse.OverrideCursor = Cursors.Wait;
            int nextRowIndex = (this.ThumbnailGrid.IsVisible == false) ? this.ImageCache.CurrentRow + 1 : this.ThumbnailGrid.GetSelected()[0] + 1;

            this.FileDatabase.UpdateFiles(imageRow, control.DataLabel, nextRowIndex, this.FileDatabase.CountAllCurrentlySelectedFiles - 1);
            Mouse.OverrideCursor = null;
        }