Skip to content

Commit a8cd848

Browse files
committed
ocrd_page: invalidate AlternativeImages automatically…
- 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
1 parent 39c6281 commit a8cd848

File tree

5 files changed

+275
-1
lines changed

5 files changed

+275
-1
lines changed

ocrd_models/ocrd_models/ocrd_page_generateds.py

+230-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
#
5-
# Generated Sat Oct 31 00:32:57 2020 by generateDS.py version 2.35.20.
5+
# Generated Sat Oct 31 00:47:39 2020 by generateDS.py version 2.35.20.
66
# Python 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]
77
#
88
# Command line options:
@@ -3067,6 +3067,17 @@ def invalidate_AlternativeImage(self, feature_selector=None):
30673067
for image in removed_images:
30683068
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
30693069
image.get_comments() or '', name))
3070+
def set_orientation(self, orientation):
3071+
"""
3072+
Set deskewing angle to given number.
3073+
Moreover, invalidate self's AlternativeImages
3074+
(because they will have been rotated and enlarged
3075+
with the angle of the previous value).
3076+
"""
3077+
if hasattr(self, 'invalidate_AlternativeImage'):
3078+
# PageType, RegionType:
3079+
self.invalidate_AlternativeImage(feature_selector='deskewed')
3080+
self.orientation = orientation
30703081
# end class PageType
30713082

30723083

@@ -3218,6 +3229,22 @@ def __hash__(self):
32183229
else:
32193230
raise ValueError("Cannot hash %s" % self)
32203231
return hash(val)
3232+
def set_points(self, points):
3233+
"""
3234+
Set coordinate polygon by given string.
3235+
Moreover, invalidate the parent's AlternativeImages
3236+
(because they will have been cropped with a bbox
3237+
of the previous polygon).
3238+
"""
3239+
if hasattr(self, 'parent_object_'):
3240+
parent = self.parent_object_
3241+
if hasattr(parent, 'invalidate_AlternativeImage'):
3242+
# RegionType, TextLineType, WordType, GlyphType:
3243+
parent.invalidate_AlternativeImage()
3244+
elif hasattr(parent, 'parent_object_') and hasattr(parent.parent_object_, 'invalidate_AlternativeImage'):
3245+
# BorderType:
3246+
parent.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
3247+
self.points = points
32213248
# end class CoordsType
32223249

32233250

@@ -3695,6 +3722,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
36953722
for image in removed_images:
36963723
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
36973724
image.get_comments() or '', name))
3725+
def set_Coords(self, Coords):
3726+
"""
3727+
Set coordinate polygon by given object.
3728+
Moreover, invalidate self's AlternativeImages
3729+
(because they will have been cropped with a bbox
3730+
of the previous polygon).
3731+
"""
3732+
if hasattr(self, 'invalidate_AlternativeImage'):
3733+
# RegionType, TextLineType, WordType, GlyphType:
3734+
self.invalidate_AlternativeImage()
3735+
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
3736+
# BorderType:
3737+
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
3738+
self.Coords = Coords
36983739
# end class TextLineType
36993740

37003741

@@ -4140,6 +4181,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
41404181
for image in removed_images:
41414182
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
41424183
image.get_comments() or '', name))
4184+
def set_Coords(self, Coords):
4185+
"""
4186+
Set coordinate polygon by given object.
4187+
Moreover, invalidate self's AlternativeImages
4188+
(because they will have been cropped with a bbox
4189+
of the previous polygon).
4190+
"""
4191+
if hasattr(self, 'invalidate_AlternativeImage'):
4192+
# RegionType, TextLineType, WordType, GlyphType:
4193+
self.invalidate_AlternativeImage()
4194+
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
4195+
# BorderType:
4196+
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
4197+
self.Coords = Coords
41434198
# end class WordType
41444199

41454200

@@ -4538,6 +4593,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
45384593
for image in removed_images:
45394594
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
45404595
image.get_comments() or '', name))
4596+
def set_Coords(self, Coords):
4597+
"""
4598+
Set coordinate polygon by given object.
4599+
Moreover, invalidate self's AlternativeImages
4600+
(because they will have been cropped with a bbox
4601+
of the previous polygon).
4602+
"""
4603+
if hasattr(self, 'invalidate_AlternativeImage'):
4604+
# RegionType, TextLineType, WordType, GlyphType:
4605+
self.invalidate_AlternativeImage()
4606+
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
4607+
# BorderType:
4608+
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
4609+
self.Coords = Coords
45414610
# end class GlyphType
45424611

45434612

@@ -7153,6 +7222,20 @@ def __hash__(self):
71537222
else:
71547223
raise ValueError("Cannot hash %s" % self)
71557224
return hash(val)
7225+
def set_Coords(self, Coords):
7226+
"""
7227+
Set coordinate polygon by given object.
7228+
Moreover, invalidate self's AlternativeImages
7229+
(because they will have been cropped with a bbox
7230+
of the previous polygon).
7231+
"""
7232+
if hasattr(self, 'invalidate_AlternativeImage'):
7233+
# RegionType, TextLineType, WordType, GlyphType:
7234+
self.invalidate_AlternativeImage()
7235+
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
7236+
# BorderType:
7237+
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
7238+
self.Coords = Coords
71567239
# end class BorderType
71577240

71587241

@@ -9022,6 +9105,20 @@ def invalidate_AlternativeImage(self, feature_selector=None):
90229105
for image in removed_images:
90239106
self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
90249107
image.get_comments() or '', name))
9108+
def set_Coords(self, Coords):
9109+
"""
9110+
Set coordinate polygon by given object.
9111+
Moreover, invalidate self's AlternativeImages
9112+
(because they will have been cropped with a bbox
9113+
of the previous polygon).
9114+
"""
9115+
if hasattr(self, 'invalidate_AlternativeImage'):
9116+
# RegionType, TextLineType, WordType, GlyphType:
9117+
self.invalidate_AlternativeImage()
9118+
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
9119+
# BorderType:
9120+
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
9121+
self.Coords = Coords
90259122
# end class RegionType
90269123

90279124

@@ -10877,6 +10974,17 @@ def __hash__(self):
1087710974
else:
1087810975
raise ValueError("Cannot hash %s" % self)
1087910976
return hash(val)
10977+
def set_orientation(self, orientation):
10978+
"""
10979+
Set deskewing angle to given number.
10980+
Moreover, invalidate self's AlternativeImages
10981+
(because they will have been rotated and enlarged
10982+
with the angle of the previous value).
10983+
"""
10984+
if hasattr(self, 'invalidate_AlternativeImage'):
10985+
# PageType, RegionType:
10986+
self.invalidate_AlternativeImage(feature_selector='deskewed')
10987+
self.orientation = orientation
1088010988
# end class AdvertRegionType
1088110989

1088210990

@@ -11018,6 +11126,17 @@ def __hash__(self):
1101811126
else:
1101911127
raise ValueError("Cannot hash %s" % self)
1102011128
return hash(val)
11129+
def set_orientation(self, orientation):
11130+
"""
11131+
Set deskewing angle to given number.
11132+
Moreover, invalidate self's AlternativeImages
11133+
(because they will have been rotated and enlarged
11134+
with the angle of the previous value).
11135+
"""
11136+
if hasattr(self, 'invalidate_AlternativeImage'):
11137+
# PageType, RegionType:
11138+
self.invalidate_AlternativeImage(feature_selector='deskewed')
11139+
self.orientation = orientation
1102111140
# end class MusicRegionType
1102211141

1102311142

@@ -11131,6 +11250,17 @@ def __hash__(self):
1113111250
else:
1113211251
raise ValueError("Cannot hash %s" % self)
1113311252
return hash(val)
11253+
def set_orientation(self, orientation):
11254+
"""
11255+
Set deskewing angle to given number.
11256+
Moreover, invalidate self's AlternativeImages
11257+
(because they will have been rotated and enlarged
11258+
with the angle of the previous value).
11259+
"""
11260+
if hasattr(self, 'invalidate_AlternativeImage'):
11261+
# PageType, RegionType:
11262+
self.invalidate_AlternativeImage(feature_selector='deskewed')
11263+
self.orientation = orientation
1113411264
# end class MapRegionType
1113511265

1113611266

@@ -11273,6 +11403,17 @@ def __hash__(self):
1127311403
else:
1127411404
raise ValueError("Cannot hash %s" % self)
1127511405
return hash(val)
11406+
def set_orientation(self, orientation):
11407+
"""
11408+
Set deskewing angle to given number.
11409+
Moreover, invalidate self's AlternativeImages
11410+
(because they will have been rotated and enlarged
11411+
with the angle of the previous value).
11412+
"""
11413+
if hasattr(self, 'invalidate_AlternativeImage'):
11414+
# PageType, RegionType:
11415+
self.invalidate_AlternativeImage(feature_selector='deskewed')
11416+
self.orientation = orientation
1127611417
# end class ChemRegionType
1127711418

1127811419

@@ -11415,6 +11556,17 @@ def __hash__(self):
1141511556
else:
1141611557
raise ValueError("Cannot hash %s" % self)
1141711558
return hash(val)
11559+
def set_orientation(self, orientation):
11560+
"""
11561+
Set deskewing angle to given number.
11562+
Moreover, invalidate self's AlternativeImages
11563+
(because they will have been rotated and enlarged
11564+
with the angle of the previous value).
11565+
"""
11566+
if hasattr(self, 'invalidate_AlternativeImage'):
11567+
# PageType, RegionType:
11568+
self.invalidate_AlternativeImage(feature_selector='deskewed')
11569+
self.orientation = orientation
1141811570
# end class MathsRegionType
1141911571

1142011572

@@ -11558,6 +11710,17 @@ def __hash__(self):
1155811710
else:
1155911711
raise ValueError("Cannot hash %s" % self)
1156011712
return hash(val)
11713+
def set_orientation(self, orientation):
11714+
"""
11715+
Set deskewing angle to given number.
11716+
Moreover, invalidate self's AlternativeImages
11717+
(because they will have been rotated and enlarged
11718+
with the angle of the previous value).
11719+
"""
11720+
if hasattr(self, 'invalidate_AlternativeImage'):
11721+
# PageType, RegionType:
11722+
self.invalidate_AlternativeImage(feature_selector='deskewed')
11723+
self.orientation = orientation
1156111724
# end class SeparatorRegionType
1156211725

1156311726

@@ -11766,6 +11929,17 @@ def __hash__(self):
1176611929
else:
1176711930
raise ValueError("Cannot hash %s" % self)
1176811931
return hash(val)
11932+
def set_orientation(self, orientation):
11933+
"""
11934+
Set deskewing angle to given number.
11935+
Moreover, invalidate self's AlternativeImages
11936+
(because they will have been rotated and enlarged
11937+
with the angle of the previous value).
11938+
"""
11939+
if hasattr(self, 'invalidate_AlternativeImage'):
11940+
# PageType, RegionType:
11941+
self.invalidate_AlternativeImage(feature_selector='deskewed')
11942+
self.orientation = orientation
1176911943
# end class ChartRegionType
1177011944

1177111945

@@ -12015,6 +12189,17 @@ def __hash__(self):
1201512189
else:
1201612190
raise ValueError("Cannot hash %s" % self)
1201712191
return hash(val)
12192+
def set_orientation(self, orientation):
12193+
"""
12194+
Set deskewing angle to given number.
12195+
Moreover, invalidate self's AlternativeImages
12196+
(because they will have been rotated and enlarged
12197+
with the angle of the previous value).
12198+
"""
12199+
if hasattr(self, 'invalidate_AlternativeImage'):
12200+
# PageType, RegionType:
12201+
self.invalidate_AlternativeImage(feature_selector='deskewed')
12202+
self.orientation = orientation
1201812203
# end class TableRegionType
1201912204

1202012205

@@ -12194,6 +12379,17 @@ def __hash__(self):
1219412379
else:
1219512380
raise ValueError("Cannot hash %s" % self)
1219612381
return hash(val)
12382+
def set_orientation(self, orientation):
12383+
"""
12384+
Set deskewing angle to given number.
12385+
Moreover, invalidate self's AlternativeImages
12386+
(because they will have been rotated and enlarged
12387+
with the angle of the previous value).
12388+
"""
12389+
if hasattr(self, 'invalidate_AlternativeImage'):
12390+
# PageType, RegionType:
12391+
self.invalidate_AlternativeImage(feature_selector='deskewed')
12392+
self.orientation = orientation
1219712393
# end class GraphicRegionType
1219812394

1219912395

@@ -12373,6 +12569,17 @@ def __hash__(self):
1237312569
else:
1237412570
raise ValueError("Cannot hash %s" % self)
1237512571
return hash(val)
12572+
def set_orientation(self, orientation):
12573+
"""
12574+
Set deskewing angle to given number.
12575+
Moreover, invalidate self's AlternativeImages
12576+
(because they will have been rotated and enlarged
12577+
with the angle of the previous value).
12578+
"""
12579+
if hasattr(self, 'invalidate_AlternativeImage'):
12580+
# PageType, RegionType:
12581+
self.invalidate_AlternativeImage(feature_selector='deskewed')
12582+
self.orientation = orientation
1237612583
# end class LineDrawingRegionType
1237712584

1237812585

@@ -12565,6 +12772,17 @@ def __hash__(self):
1256512772
else:
1256612773
raise ValueError("Cannot hash %s" % self)
1256712774
return hash(val)
12775+
def set_orientation(self, orientation):
12776+
"""
12777+
Set deskewing angle to given number.
12778+
Moreover, invalidate self's AlternativeImages
12779+
(because they will have been rotated and enlarged
12780+
with the angle of the previous value).
12781+
"""
12782+
if hasattr(self, 'invalidate_AlternativeImage'):
12783+
# PageType, RegionType:
12784+
self.invalidate_AlternativeImage(feature_selector='deskewed')
12785+
self.orientation = orientation
1256812786
# end class ImageRegionType
1256912787

1257012788

@@ -13045,6 +13263,17 @@ def __hash__(self):
1304513263
else:
1304613264
raise ValueError("Cannot hash %s" % self)
1304713265
return hash(val)
13266+
def set_orientation(self, orientation):
13267+
"""
13268+
Set deskewing angle to given number.
13269+
Moreover, invalidate self's AlternativeImages
13270+
(because they will have been rotated and enlarged
13271+
with the angle of the previous value).
13272+
"""
13273+
if hasattr(self, 'invalidate_AlternativeImage'):
13274+
# PageType, RegionType:
13275+
self.invalidate_AlternativeImage(feature_selector='deskewed')
13276+
self.orientation = orientation
1304813277
# end class TextRegionType
1304913278

1305013279

ocrd_models/ocrd_page_user_methods.py

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def _add_method(class_re, method_name, file_name=None):
110110
_add_method(r'^(PcGtsType)$', 'get_AllAlternativeImagePaths'),
111111
_add_method(r'^(PcGtsType)$', 'prune_ReadingOrder'),
112112
_add_method(r'^(PageType|RegionType|TextLineType|WordType|GlyphType)$', 'invalidate_AlternativeImage'),
113+
_add_method(r'^(BorderType|RegionType|TextLineType|WordType|GlyphType)$', 'set_Coords'),
114+
_add_method(r'^(CoordsType)$', 'set_points'),
115+
# for some reason, pagecontent.xsd does not declare @orientation at the abstract/base RegionType:
116+
_add_method(r'^(PageType|AdvertRegionType|MusicRegionType|MapRegionType|ChemRegionType|MathsRegionType|SeparatorRegionType|ChartRegionType|TableRegionType|GraphicRegionType|LineDrawingRegionType|ImageRegionType|TextRegionType)$', 'set_orientation'),
113117
)
114118

115119

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def set_Coords(self, Coords):
2+
"""
3+
Set coordinate polygon by given object.
4+
Moreover, invalidate self's AlternativeImages
5+
(because they will have been cropped with a bbox
6+
of the previous polygon).
7+
"""
8+
if hasattr(self, 'invalidate_AlternativeImage'):
9+
# RegionType, TextLineType, WordType, GlyphType:
10+
self.invalidate_AlternativeImage()
11+
elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'invalidate_AlternativeImage'):
12+
# BorderType:
13+
self.parent_object_.invalidate_AlternativeImage(feature_selector='cropped')
14+
self.Coords = Coords

0 commit comments

Comments
 (0)