Beispiel #1
0
        private void _annAutomationObjects_ItemRemoved(object sender, AnnObjectCollectionEventArgs e)
        {
            // Check if we are updating the zones, no need for this
            if (_ignoreAddRemove)
            {
                return;
            }
            // User deleted the annotation object, delete the corresponding zone
            ZoneAnnotationObject zoneObject = e.Object as ZoneAnnotationObject;

            if (zoneObject != null)
            {
                if (_setSelect)
                {
                    InteractiveMode = ViewerControlInteractiveMode.SelectMode;
                    return;
                }
                _setSelect = true;
                int index = zoneObject.ZoneIndex;
                _ocrPage.Zones.RemoveAt(index);

                // Reset all the zones
                for (int i = 0; i < _annAutomation.Container.Children.Count; i++)
                {
                    zoneObject = _annAutomation.Container.Children[i] as ZoneAnnotationObject;
                    zoneObject.SetZone(_ocrPage, i, _showZonesToolStripButton.Checked, _showZoneNameToolStripButton.Checked);
                }

                // We should mark the page as unrecognized since we updated its zones
                _ocrPage.Unrecognize();
                // Update the thumbnail(s)
                DoAction("RefreshPagesControl", false);
            }
        }
Beispiel #2
0
        void _annAutomation_Draw(object sender, AnnDrawDesignerEventArgs e)
        {
            if (!(e.OperationStatus == AnnDesignerOperationStatus.End))
            {
                return;
            }

            // Add a new zone from the annotation rectangle object
            ZoneAnnotationObject zoneObject = e.Object as ZoneAnnotationObject;

            if (zoneObject == null)
            {
                return;
            }

            OcrZone zone = new OcrZone();

            zone.Bounds = RestrictZoneBoundsToPage(_ocrPage, BoundsFromAnnotations(zoneObject, _annAutomation.Container));
            if (!zone.Bounds.IsEmpty)
            {
                _ocrPage.Zones.Add(zone);
            }
            else
            {
                InteractiveMode = ViewerControlInteractiveMode.DrawZoneMode;
                return;
            }

            // Set the zone
            zoneObject.SetZone(_ocrPage, _ocrPage.Zones.Count - 1, _showZonesToolStripButton.Checked, _showZoneNameToolStripButton.Checked);

            ZonesUpdated();
            InteractiveMode = ViewerControlInteractiveMode.DrawZoneMode;
            UpdateUIState();
        }
Beispiel #3
0
        /// <summary>
        /// Called from the main form when the zones are updated
        /// </summary>
        public void ZonesUpdated()
        {
            // Stop updating the viewer
            _rasterImageViewer.BeginUpdate();

            // Remove all the annotations objects and re-add them from the zones
            if (_annAutomation != null)
            {
                _annAutomation.Cancel();
                _annAutomation.Container.Children.Clear();
            }

            _ignoreAddRemove = true;
            _setSelect       = true;
            // Get the rectangle automation object so we can use the template
            // to create the new annotation objects

            bool isVisible     = _showZonesToolStripButton.Checked && !MainForm.PerspectiveDeskewActive && !MainForm.UnWarpActive;
            bool isNameVisible = _showZoneNameToolStripButton.Checked;

            if (_ocrPage != null && _ocrPage.Zones != null && _ocrPage.Zones.Count > 0)
            {
                for (int i = 0; i < _ocrPage.Zones.Count; i++)
                {
                    OcrZone zone = _ocrPage.Zones[i];

                    ZoneAnnotationObject zoneObject = new ZoneAnnotationObject();
                    zoneObject.SetZone(_ocrPage, i, isVisible, isNameVisible);

                    _annAutomation.Container.Children.Add(zoneObject);

                    // Now we can calculate the object bounds correctly
                    LeadRect  rc   = zone.Bounds;
                    LeadRectD rect = BoundsToAnnotations(zoneObject, rc, _annAutomation.Container);
                    zoneObject.Rect = rect;
                }
            }

            _ignoreAddRemove = false;

            // Re-update the viewer
            _rasterImageViewer.EndUpdate();

            _rasterImageViewer.Invalidate();
            UpdateUIState();
        }
Beispiel #4
0
        /// <summary>
        /// Called from the main form when the zones are updated
        /// </summary>
        public void ZonesUpdated()
        {
            if (_ocrPage == null)
            {
                return;
            }

            // Stop updating the viewer
            _rasterImageViewer.BeginUpdate();

            // Remove all the annotations objects and re-add them from the zones
            _annAutomation.Cancel();

            _ignoreAddRemove = true;
            _annAutomation.Container.Children.Clear();
            _setSelect = true;
            // Get the rectangle automation object so we can use the template
            // to create the new annotation objects

            bool isVisible     = _showZonesToolStripButton.Checked && !MainForm.PerspectiveDeskewActive && !MainForm.UnWarpActive;
            bool isNameVisible = _showZoneNameToolStripButton.Checked;

            ZoneAnnotationObjectRenderer zoneObjectRenderer = (ZoneAnnotationObjectRenderer)_annAutomationManager.RenderingEngine.Renderers[AnnObject.UserObjectId];

            zoneObjectRenderer.OcrPage = _ocrPage;

            for (int i = 0; i < _ocrPage.Zones.Count; i++)
            {
                OcrZone zone = _ocrPage.Zones[i];

                ZoneAnnotationObject zoneObject = new ZoneAnnotationObject();
                zoneObject.SetZone(_ocrPage, i, isVisible, isNameVisible);

                _annAutomation.Container.Children.Add(zoneObject);

                // Now we can calculate the object bounds correctly
                OcrZoneCell[] cells = null;
                cells = _ocrPage.Zones.GetZoneCells(zone);

                LeadRect  rc   = zone.Bounds;
                LeadRectD rect = BoundsToAnnotations(zoneObject, rc, _annAutomation.Container);
                zoneObject.Rect = rect;

                if (cells != null)
                {
                    foreach (OcrZoneCell cell in cells)
                    {
                        LeadRect  r  = cell.Bounds;
                        LeadRectD rd = BoundsToAnnotations(zoneObject, r, _annAutomation.Container);
                        cell.Bounds = BoundsToAnnotations(zoneObject, r, _annAutomation.Container).ToLeadRect();
                    }

                    zoneObject.Cells = cells;
                }
            }

            _ignoreAddRemove = false;

            // Re-update the viewer
            _rasterImageViewer.EndUpdate();

            _rasterImageViewer.Invalidate();
            UpdateUIState();
        }