Пример #1
0
        private void InitAnnotations()
        {
            _annAutomationManager = new AnnAutomationManager();

            // Disable the rotation
            _annAutomationManager.RotateModifierKey   = AnnKeys.None;
            _annAutomationManager.EditObjectAfterDraw = false;

            _annAutomationManager.CreateDefaultObjects();

            _annAutomation = new AnnAutomation(_annAutomationManager, _rasterImageViewer);
            _annAutomation.AfterObjectChanged      += new EventHandler <AnnAfterObjectChangedEventArgs>(_annAutomation_AfterObjectChanged);
            _annAutomation.Container.ObjectAdded   += new EventHandler <AnnObjectCollectionEventArgs>(_annAutomationObjects_ItemAdded);
            _annAutomation.Container.ObjectRemoved += new EventHandler <AnnObjectCollectionEventArgs>(_annAutomationObjects_ItemRemoved);
            _annAutomation.OnShowContextMenu       += new EventHandler <AnnAutomationEventArgs>(_annAutomation_OnShowContextMenu);
            _annAutomation.Draw          += new EventHandler <AnnDrawDesignerEventArgs>(_annAutomation_Draw);
            _annAutomation.SetCursor     += new EventHandler <AnnCursorEventArgs>(_annAutomation_SetCursor);
            _annAutomation.RestoreCursor += new EventHandler(_annAutomation_RestoreCursor);
            // We are not going to do undo/redeo
            _annAutomation.UndoCapacity = 0;
            // Set this as the one and only active automation object so mouse and keyboard events
            // get to it
            _annAutomation.Active = true;
            _annAutomation.DefaultCurrentObjectId = AnnObject.None;


            // Get the rectangle and select objects
            AnnAutomationObject selectAutomationObject = GetAutomationObject(_annAutomationManager, AnnObject.SelectObjectId);

            AnnAutomationObject zoneAutomationObject = CreateZoneAutomationObject();

            _automationManagerHelper = new AutomationManagerHelper(_annAutomationManager);

            ZoneAnnotationObjectRenderer zoneObjectRenderer         = new ZoneAnnotationObjectRenderer();
            IAnnObjectRenderer           annRectangleObjectRenderer = _annAutomationManager.RenderingEngine.Renderers[AnnObject.RectangleObjectId];

            zoneObjectRenderer.LocationsThumbStyle     = annRectangleObjectRenderer.LocationsThumbStyle;
            zoneObjectRenderer.RotateCenterThumbStyle  = annRectangleObjectRenderer.RotateCenterThumbStyle;
            zoneObjectRenderer.RotateGripperThumbStyle = annRectangleObjectRenderer.RotateGripperThumbStyle;

            _annAutomationManager.Objects.Clear();

            ContextMenu cm = new ContextMenu();

            cm.MenuItems.Add(new MenuItem("&Delete", _zoneDeleteMenuItem_Click));
            cm.MenuItems.Add(new MenuItem("-", null as EventHandler));
            cm.MenuItems.Add(new MenuItem("&Properties...", _zonePropertiesMenuItem_Click));

            zoneAutomationObject.ContextMenu = cm;

            _annAutomationManager.RenderingEngine.Renderers[AnnObject.UserObjectId] = zoneObjectRenderer;

            _annAutomationManager.Objects.Add(selectAutomationObject);
            _annAutomationManager.Objects.Add(zoneAutomationObject);

            // Disable Annotation selection object since we don't want users to group annotation objects.
            var selectionObject = _annAutomationManager.FindObjectById(AnnObject.SelectObjectId);

            selectionObject.DrawDesignerType = null;
        }
Пример #2
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();
        }