Commit fae9f612 authored by Fabrice Salvaire's avatar Fabrice Salvaire

Path: fixed transformation issue

parent b2b67b96
......@@ -432,6 +432,12 @@ class PathSegment(OnePointMixin, LinearSegment):
##############################################
def to_absolute(self):
self._point = self.stop_point
self._absolute = True
##############################################
def apply_transformation(self, transformation):
OnePointMixin.apply_transformation(self, transformation)
if self._radius is not None:
......@@ -458,6 +464,11 @@ class DirectionalSegment(LinearSegment):
##############################################
def __repr__(self):
return '{0}(@{1._index}, {1.offset})'.format(self.__class__.__name__, self)
##############################################
def apply_transformation(self, transformation):
# Since a rotation will change the direction
# DirectionalSegment must be casted to PathSegment
......@@ -557,6 +568,13 @@ class QuadraticBezierSegment(PathPart, TwoPointMixin):
##############################################
def to_absolute(self):
self._point1 = self.point1
self._point2 = self.point2
self._absolute = True
##############################################
@property
def stop_point(self):
return self.point2
......@@ -594,6 +612,14 @@ class CubicBezierSegment(PathPart, ThreePointMixin):
##############################################
def to_absolute(self):
self._point1 = self.point1
self._point2 = self.point2
self._point3 = self.point3
self._absolute = True
##############################################
@property
def stop_point(self):
return self.point3
......@@ -697,6 +723,12 @@ class ArcSegment(OnePointMixin, PathPart):
##############################################
def to_absolute(self):
self._point = self.stop_point
self._absolute = True
##############################################
@property
def points(self):
return self.start_point, self.stop_point
......@@ -714,6 +746,8 @@ class Path2D(Primitive2DMixin, Primitive1P):
"""Class to implements 2D Path."""
_logger = _module_logger.getChild('Path2D')
##############################################
def __init__(self, start_point):
......@@ -789,17 +823,29 @@ class Path2D(Primitive2DMixin, Primitive1P):
def apply_transformation(self, transformation):
self._p0 = transformation * self._p0
self._logger.info(str(self) + '\n' + str(transformation.type) + '\n' + str(transformation) )
for i, part in enumerate(self._parts):
for part in self._parts:
# print(part)
if isinstance(part, PathSegment):
part._reset_cache()
if isinstance(part, DirectionalSegment):
# Since a rotation will change the direction
# DirectionalSegment must be casted to PathSegment
part = part.to_path_segment()
self._parts[i] = part
self._parts[part.index] = part
if part._absolute is False:
# print('incremental', part, part.points)
part.to_absolute()
# print('->', part.points)
# print()
self._p0 = transformation * self._p0
# print('p0', self._p0)
for part in self._parts:
# print(part)
part.apply_transformation(transformation)
# print('->', part.points)
##############################################
......
......@@ -108,12 +108,12 @@ class SceneImporter(SvgFileInternal):
)
transformation = state.transform
self._logger.info('Sate Transform\n' + str(transformation))
if isinstance(item, SvgFormat.Path):
# and state.stroke_dasharray is None
path = item.path_data
if path is not None: # Fixme:
# path = path.transform(transformation)
# Fixme:
path = path.transform(transformation)
for part in path:
self._update_bounding_box(part)
self._scene.add_path(path, path_style)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment