-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathannotation.py
More file actions
163 lines (125 loc) · 4.33 KB
/
annotation.py
File metadata and controls
163 lines (125 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# -*- coding: utf-8 -*-# -*- coding: utf-8 -*-
#
# Licensed under the terms of the BSD 3-Clause
# (see plotpy/LICENSE for details)
from __future__ import annotations
from plotpy.items import (
AnnotatedCircle,
AnnotatedEllipse,
AnnotatedObliqueRectangle,
AnnotatedPoint,
AnnotatedPolygon,
AnnotatedRectangle,
AnnotatedSegment,
)
from plotpy.tools.shape import (
CircleTool,
EllipseTool,
ObliqueRectangleTool,
PointTool,
PolygonTool,
RectangleTool,
SegmentTool,
)
class AnnotatedPolygonTool(PolygonTool):
"""
Tool for creating annotated polygon shapes.
This tool extends the PolygonTool to create AnnotatedPolygon objects.
"""
def create_shape(self) -> AnnotatedPolygon:
"""
Create an annotated polygon shape.
Returns:
A tuple containing the AnnotatedPolygon object and its handle indices.
"""
annotation = AnnotatedPolygon()
self.set_shape_style(annotation)
return annotation
class AnnotatedRectangleTool(RectangleTool):
"""
Tool for creating annotated rectangle shapes.
This tool extends the RectangleTool to create AnnotatedRectangle objects.
"""
def create_shape(self) -> tuple[AnnotatedRectangle, int, int]:
"""
Create an annotated rectangle shape.
Returns:
A tuple containing the AnnotatedRectangle object and its handle indices.
"""
annotation = AnnotatedRectangle(0, 0, 1, 1)
self.set_shape_style(annotation)
return annotation, 0, 2
class AnnotatedObliqueRectangleTool(ObliqueRectangleTool):
"""
Tool for creating annotated oblique rectangle shapes.
This tool extends the ObliqueRectangleTool to create
AnnotatedObliqueRectangle objects.
"""
AVOID_NULL_SHAPE: bool = True
def create_shape(self) -> tuple[AnnotatedObliqueRectangle, int, int]:
"""
Create an annotated oblique rectangle shape.
Returns:
A tuple containing the AnnotatedObliqueRectangle object
and its handle indices.
"""
annotation = AnnotatedObliqueRectangle(0, 0, 1, 0, 1, 1, 0, 1)
self.set_shape_style(annotation)
return annotation, 0, 2
class AnnotatedCircleTool(CircleTool):
"""
Tool for creating annotated circle shapes.
This tool extends the CircleTool to create AnnotatedCircle objects.
"""
def create_shape(self) -> tuple[AnnotatedCircle, int, int]:
"""
Create an annotated circle shape.
Returns:
A tuple containing the AnnotatedCircle object and its handle indices.
"""
annotation = AnnotatedCircle(0, 0, 1, 1)
self.set_shape_style(annotation)
return annotation, 0, 1
class AnnotatedEllipseTool(EllipseTool):
"""
Tool for creating annotated ellipse shapes.
This tool extends the EllipseTool to create AnnotatedEllipse objects.
"""
def create_shape(self) -> tuple[AnnotatedEllipse, int, int]:
"""
Create an annotated ellipse shape.
Returns:
A tuple containing the AnnotatedEllipse object and its handle indices.
"""
annotation = AnnotatedEllipse(0, 0, 1, 1)
annotation.shape.switch_to_circle()
self.set_shape_style(annotation)
return annotation, 0, 1
class AnnotatedPointTool(PointTool):
"""
Tool for creating annotated point shapes.
This tool extends the PointTool to create AnnotatedPoint objects.
"""
def create_shape(self) -> tuple[AnnotatedPoint, int, int]:
"""
Create an annotated point shape.
Returns:
A tuple containing the AnnotatedPoint object and its handle indices.
"""
annotation = AnnotatedPoint(0, 0)
self.set_shape_style(annotation)
return annotation, 0, 0
class AnnotatedSegmentTool(SegmentTool):
"""
Tool for creating annotated segment shapes.
This tool extends the SegmentTool to create AnnotatedSegment objects.
"""
def create_shape(self) -> tuple[AnnotatedSegment, int, int]:
"""
Create an annotated segment shape.
Returns:
A tuple containing the AnnotatedSegment object and its handle indices.
"""
annotation = AnnotatedSegment(0, 0, 1, 1)
self.set_shape_style(annotation)
return annotation, 0, 1