Newer
Older
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
####################################################################################################
from Patro.Common.Logging import Logging
Logging.setup_logging()
from Patro.GeometryEngine.Path import (
Path2D,
LinearSegment, QuadraticBezierSegment, CubicBezierSegment
)
from Patro.GeometryEngine.Vector import Vector2D
from Patro.GraphicEngine.GraphicScene.GraphicItem import GraphicPathStyle, GraphicBezierStyle
from Patro.GraphicEngine.Painter.QtPainter import QtScene
from Patro.GraphicStyle import Colors, StrokeStyle
####################################################################################################
class SceneBuilder:
##############################################
def __init__(self):
self._scene = QtScene()
self._bounding_box = None
path = self._make_path()
self._add_items(path)
self._scene.bounding_box = self._bounding_box # Fixme:
##############################################
@property
def scene(self):
return self._scene
##############################################
def _update_bounding_box(self, item):
interval = item.bounding_box
if self._bounding_box is None:
self._bounding_box = interval
else:
self._bounding_box |= interval
##############################################
def _make_path(self):
start_point = Vector2D(0, 0)
path = Path2D(start_point)
path.horizontal_to(10)
path.vertical_to(10)
path.north_east_to(10)
path.north_west_to(10)
path.south_west_to(10)
path.south_east_to(5)
path.south_to(5)
path.west_to(10)
path.north_to(5)
path.east_to(5)
return path
##############################################
def _add_items(self, path):
path_style = GraphicPathStyle(
line_width=3.0,
stroke_color=Colors.black,
stroke_style=StrokeStyle.SolidLine,
)
for item in path:
print('Path part:', item)
if isinstance(item, LinearSegment):
print('linear', item.start_point, item.stop_point, item.points)
self._scene.segment(*item.points,
path_style,
user_data=item,
)
elif isinstance(item, QuadraticBezierSegment):
self._scene.quadratic_bezier(*item.points,
path_style,
user_data=item,
)
elif isinstance(item, CubicBezierSegment):
self._scene.cubic_bezier(*item.points,
path_style,
user_data=item,
)
# Fixme: why here ???
self._update_bounding_box(item)
####################################################################################################
scene = QtScene()
scene_builder = SceneBuilder()
application.qml_application.scene = scene_builder.scene