コード例 #1
0
ファイル: ViewerControl.cs プロジェクト: sakpung/webstudy
        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);
            }
        }
コード例 #2
0
ファイル: ViewerControl.cs プロジェクト: sakpung/webstudy
        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();
        }
コード例 #3
0
ファイル: ViewerControl.cs プロジェクト: sakpung/webstudy
        AnnAutomationObject CreateZoneAutomationObject()
        {
            AnnAutomationObject  automationObj        = new AnnAutomationObject();
            ZoneAnnotationObject zoneAnnotationObject = new ZoneAnnotationObject();

            AnnAutomationObject rectAutomationObject = GetAutomationObject(_annAutomationManager, AnnObject.RectangleObjectId);
            AnnRectangleObject  rectObject           = rectAutomationObject.ObjectTemplate as AnnRectangleObject;

            zoneAnnotationObject.Stroke = rectObject.Stroke != null?rectObject.Stroke.Clone() as AnnStroke : null;

            zoneAnnotationObject.Fill = rectObject.Fill != null?rectObject.Fill.Clone() as AnnBrush : null;

            zoneAnnotationObject.CellPen = AnnStroke.Create(AnnSolidColorBrush.Create("Blue"), new LeadLengthD(1));

            automationObj.Id               = AnnObject.UserObjectId;
            automationObj.Name             = zoneAnnotationObject.FriendlyName;
            automationObj.ObjectTemplate   = zoneAnnotationObject;
            automationObj.DrawDesignerType = rectAutomationObject.DrawDesignerType;
            automationObj.EditDesignerType = typeof(ZoneAnnotationObjectEditDesigner);
            automationObj.RunDesignerType  = rectAutomationObject.RunDesignerType;
            automationObj.DrawCursor       = rectAutomationObject.DrawCursor;

            // Disable the rotation points
            automationObj.UseRotateThumbs = false;
            return(automationObj);
        }
コード例 #4
0
ファイル: ViewerControl.cs プロジェクト: sakpung/webstudy
        /// <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();
        }
コード例 #5
0
ファイル: ViewerControl.cs プロジェクト: sakpung/webstudy
        private void _annAutomation_AfterObjectChanged(object sender, AnnAfterObjectChangedEventArgs e)
        {
            // The annotation object has been changed, update the corresponding zone
            switch (e.ChangeType)
            {
            case AnnObjectChangedType.DesignerEdit:
            {
                // The object moved or re-sized, update the bounds
                ZoneAnnotationObject zoneObject = e.Objects[0] as ZoneAnnotationObject;

                OcrZone zone = _ocrPage.Zones[zoneObject.ZoneIndex];
                zone.Bounds = RestrictZoneBoundsToPage(_ocrPage, BoundsFromAnnotations(zoneObject, _annAutomation.Container));

                bool zoneChanged = false;
                if (_ocrPage.Zones[zoneObject.ZoneIndex].Bounds != zone.Bounds)
                {
                    zoneChanged = true;
                }

                _ocrPage.Zones[zoneObject.ZoneIndex] = zone;

                if (zoneChanged)
                {
                    _rasterImageViewer.BeginUpdate();

                    // We should mark the page as unrecognized since we updated its zones
                    _ocrPage.Unrecognize();
                    // Update the thumbnail(s)
                    DoAction("RefreshPagesControl", false);

                    _rasterImageViewer.EndUpdate();
                }
            }
            break;
            }
        }
コード例 #6
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();
        }