Skip to content

Commit

Permalink
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
  • Loading branch information
bertsky committed Oct 30, 2020
1 parent 39c6281 commit a8cd848
Show file tree
Hide file tree
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
Expand Up @@ -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:47:39 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:
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
4 changes: 4 additions & 0 deletions ocrd_models/ocrd_page_user_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)


Expand Down
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
Loading

0 comments on commit a8cd848

Please sign in to comment.