Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ocrd_page: invalidate AlternativeImages automatically…
Browse files Browse the repository at this point in the history
- whenever overwriting `Border`'s `Coords` or `Coords/@points`,
  remove all the `Page`'s derived images with `cropped`
- whenever overwriting `Region`'s or `TextLine`'s or `Word`'s
  or `Glyph`'s `Coords` or `Coords/@points`,
  remove all its derived images
- whenever overwriting `Page`'s or `Region`'s `@orientation`,
  remove all its derived images with `deskewed`
- add a warning to the GdsCollector each time
bertsky committed Oct 30, 2020

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 39c6281 commit bc81f87
Showing 5 changed files with 275 additions and 1 deletion.
231 changes: 230 additions & 1 deletion ocrd_models/ocrd_models/ocrd_page_generateds.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

#
# Generated Sat Oct 31 00:32:57 2020 by generateDS.py version 2.35.20.
# Generated Sat Oct 31 00:35:20 2020 by generateDS.py version 2.35.20.
# Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]
#
# Command line options:
@@ -3067,6 +3067,17 @@ def invalidate_AlternativeImage(self, feature_selector=None):
for image in removed_images:
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
image.get_comments() or '', name))
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class PageType


@@ -3218,6 +3229,22 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_points(self, points):
"""
Set coordinate polygon by given string.
Moreover, invalidate the parent's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'parent_object_'):
parent = self.parent_object_
if hasattr(parent, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
parent.invalidate_AlternativeImage()
elif hasattr(parent, 'parent_object_') and hasattr(parent.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
parent.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.points = points
# end class CoordsType


@@ -3695,6 +3722,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
for image in removed_images:
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
image.get_comments() or '', name))
def set_Coords(self, Coords):
"""
Set coordinate polygon by given object.
Moreover, invalidate self's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
self.invalidate_AlternativeImage()
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.Coords = Coords
# end class TextLineType


@@ -4140,6 +4181,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
for image in removed_images:
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
image.get_comments() or '', name))
def set_Coords(self, Coords):
"""
Set coordinate polygon by given object.
Moreover, invalidate self's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
self.invalidate_AlternativeImage()
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.Coords = Coords
# end class WordType


@@ -4538,6 +4593,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
for image in removed_images:
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
image.get_comments() or '', name))
def set_Coords(self, Coords):
"""
Set coordinate polygon by given object.
Moreover, invalidate self's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
self.invalidate_AlternativeImage()
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.Coords = Coords
# end class GlyphType


@@ -7153,6 +7222,20 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_Coords(self, Coords):
"""
Set coordinate polygon by given object.
Moreover, invalidate self's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
self.invalidate_AlternativeImage()
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.Coords = Coords
# end class BorderType


@@ -9022,6 +9105,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
for image in removed_images:
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
image.get_comments() or '', name))
def set_Coords(self, Coords):
"""
Set coordinate polygon by given object.
Moreover, invalidate self's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
self.invalidate_AlternativeImage()
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.Coords = Coords
# end class RegionType


@@ -10877,6 +10974,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class AdvertRegionType


@@ -11018,6 +11126,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class MusicRegionType


@@ -11131,6 +11250,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class MapRegionType


@@ -11273,6 +11403,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class ChemRegionType


@@ -11415,6 +11556,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class MathsRegionType


@@ -11558,6 +11710,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class SeparatorRegionType


@@ -11766,6 +11929,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class ChartRegionType


@@ -12015,6 +12189,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class TableRegionType


@@ -12194,6 +12379,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class GraphicRegionType


@@ -12373,6 +12569,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class LineDrawingRegionType


@@ -12565,6 +12772,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class ImageRegionType


@@ -13045,6 +13263,17 @@ def __hash__(self):
else:
raise ValueError("Cannot hash %s" % self)
return hash(val)
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
# end class TextRegionType


4 changes: 4 additions & 0 deletions ocrd_models/ocrd_page_user_methods.py
Original file line number Diff line number Diff line change
@@ -110,6 +110,10 @@ def _add_method(class_re, method_name, file_name=None):
_add_method(r'^(PcGtsType)$', 'get_AllAlternativeImagePaths'),
_add_method(r'^(PcGtsType)$', 'prune_ReadingOrder'),
_add_method(r'^(PageType|RegionType|TextLineType|WordType|GlyphType)$', 'invalidate_AlternativeImage'),
_add_method(r'^(BorderType|RegionType|TextLineType|WordType|GlyphType)$', 'set_Coords'),
_add_method(r'^(CoordsType)$', 'set_points'),
# for some reason, pagecontent.xsd does not declare @orientation at the abstract/base RegionType:
_add_method(r'^(PageType|AdvertRegionType|MusicRegionType|MapRegionType|ChemRegionType|MathsRegionType|SeparatorRegionType|ChartRegionType|TableRegionType|GraphicRegionType|LineDrawingRegionType|ImageRegionType|TextRegionType)$', 'set_orientation'),
)


14 changes: 14 additions & 0 deletions ocrd_models/ocrd_page_user_methods/set_Coords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def set_Coords(self, Coords):
"""
Set coordinate polygon by given object.
Moreover, invalidate self's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
self.invalidate_AlternativeImage()
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.Coords = Coords
11 changes: 11 additions & 0 deletions ocrd_models/ocrd_page_user_methods/set_orientation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def set_orientation(self, orientation):
"""
Set deskewing angle to given number.
Moreover, invalidate self's AlternativeImages
(because they will have been rotated and enlarged
with the angle of the previous value).
"""
if hasattr(self, 'invalidate_AlternativeImage'):
# PageType, RegionType:
self.invalidate_AlternativeImage(feature_selector='deskewed')
self.orientation = orientation
16 changes: 16 additions & 0 deletions ocrd_models/ocrd_page_user_methods/set_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def set_points(self, points):
"""
Set coordinate polygon by given string.
Moreover, invalidate the parent's AlternativeImages
(because they will have been cropped with a bbox
of the previous polygon).
"""
if hasattr(self, 'parent_object_'):
parent = self.parent_object_
if hasattr(parent, 'invalidate_AlternativeImage'):
# RegionType, TextLineType, WordType, GlyphType:
parent.invalidate_AlternativeImage()
elif hasattr(parent, 'parent_object_') and hasattr(parent.parent_object_, 'invalidate_AlternativeImage'):
# BorderType:
parent.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
self.points = points

0 comments on commit bc81f87

Please sign in to comment.