diff --git a/doc/sphinx/source/_static/patro-dxf-import.png b/doc/sphinx/source/_static/patro-dxf-import.png
new file mode 100644
index 0000000000000000000000000000000000000000..0e4d90aade741651ac5395ce61a6257c26e64e2c
Binary files /dev/null and b/doc/sphinx/source/_static/patro-dxf-import.png differ
diff --git a/doc/sphinx/source/examples/dxf-import.rst b/doc/sphinx/source/examples/dxf-import.rst
index ca6e72a7731e71ed25e43a9a6e15f6e81ead06a7..908e98e24af419c7447d18bcb8a29a75cbf3c3e0 100644
--- a/doc/sphinx/source/examples/dxf-import.rst
+++ b/doc/sphinx/source/examples/dxf-import.rst
@@ -5,8 +5,8 @@
============
DXF Import
============
-
-This screenshot show the file :file:`.dxf`.
+x
+This screenshot show the file :file:`test-dxf-r15.dxf` used as a test case.
.. image:: /_static/patro-dxf-import.png
:alt: Patro DXF Import
diff --git a/examples/file-format/dxf/SplineFromSvg.py b/examples/file-format/dxf/SplineFromSvg.py
new file mode 100644
index 0000000000000000000000000000000000000000..856f604ee301a92963246a1b281391e092766702
--- /dev/null
+++ b/examples/file-format/dxf/SplineFromSvg.py
@@ -0,0 +1,95 @@
+####################################################################################################
+#
+# Patro - A Python library to make patterns for fashion design
+# Copyright (C) 2019 Fabrice Salvaire
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+####################################################################################################
+
+####################################################################################################
+
+def spline_from_svg(scene_importer):
+
+ # m 74.999689,150.7821
+ # c
+ # 9,-10 14.500002,-5 18.916662,-0.83334 4.41667,4.16667 7.749999,7.5 11.083339,5.83334
+ # 3.33333,-1.66667 6.66666,-8.33334 13.33333,-11.66667 6.66667,-3.33333 16.66667,-3.33333
+ # 16.66667,-3.33333
+
+ # Vector2D[40. 50.]
+ # Vector2D[49. 60.]
+ # Vector2D[54.500002 55. ]
+ # Vector2D[58.916662 50.83334 ]
+ # Vector2D[63.333332 46.66667 ]
+ # Vector2D[66.666661 43.33334 ]
+ # Vector2D[70.000001 45. ]
+ # Vector2D[73.333331 46.66667 ]
+ # Vector2D[76.666661 53.33334 ]
+ # Vector2D[83.333331 56.66667 ]
+ # Vector2D[90.000001 60. ]
+ # Vector2D[100.000001 60. ]
+ # Vector2D[100.000001 60. ]
+
+ # CubicBezier2D(Vector2D[40. 50.], Vector2D[49. 60.], Vector2D[54.5 55. ], Vector2D[58.91666667 50.83333333])
+ # CubicBezier2D(Vector2D[58.91666667 50.83333333], Vector2D[63.33333333 46.66666667], Vector2D[66.66666667 43.33333333], Vector2D[70. 45.])
+ # CubicBezier2D(Vector2D[70. 45.], Vector2D[73.33333333 46.66666667], Vector2D[76.66666667 53.33333333], Vector2D[83.33333333 56.66666667])
+ # CubicBezier2D(Vector2D[83.33333333 56.66666667], Vector2D[90. 60.], Vector2D[100. 60.], Vector2D[100. 60.])
+
+ x0, y0 = 40, 50
+ control_points = (
+ (9, -10),
+ (14.500002, -5),
+ (18.916662, -0.83334),
+
+ (4.41667, 4.16667),
+ (7.749999, 7.5),
+ (11.083339, 5.83334),
+
+ (3.33333, -1.66667),
+ (6.66666, -8.33334),
+ (13.33333, -11.66667),
+
+ (6.66667, -3.33333),
+ (16.66667, -3.33333),
+ (16.66667, -3.33333),
+ )
+
+ vertices = []
+ point = Vector2D(x0, y0)
+ vertices.append(point)
+ for i, xy in enumerate(control_points):
+ xi, yi = xy
+ yi = -yi
+ if (i+1) % 3:
+ x = xi + x0
+ y = yi + y0
+ else:
+ x0 += xi
+ y0 += yi
+ x, y = x0, y0
+ point = Vector2D(x, y)
+ vertices.append(point)
+
+ path_style = GraphicBezierStyle(
+ line_width=3.0,
+ stroke_color=Colors.blue,
+ stroke_style=StrokeStyle.SolidLine,
+ show_control=True,
+ control_color=Colors.red,
+ )
+
+ for vertex in vertices:
+ print(vertex)
+ # scene_importer.scene.bezier_path(vertices, degree=3, path_style=path_style, user_data=None)
diff --git a/examples/file-format/dxf/test-dxf.py b/examples/file-format/dxf/test-dxf.py
index 48d75bd1c1f11f95c6ff9367c83ab055b1185bfc..8dd155eed41a87aee0b2f1759c80e37ea22241ce 100644
--- a/examples/file-format/dxf/test-dxf.py
+++ b/examples/file-format/dxf/test-dxf.py
@@ -1,99 +1,47 @@
+####################################################################################################
+#
+# Patro - A Python library to make patterns for fashion design
+# Copyright (C) 2019 Fabrice Salvaire
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+####################################################################################################
+
####################################################################################################
-from pathlib import Path
+import logging
from Patro.Common.Logging import Logging
Logging.setup_logging()
from Patro.FileFormat.Dxf.Importer import DxfImporter
-from Patro.GeometryEngine.Conic import Circle2D, Ellipse2D
-from Patro.GeometryEngine.Segment import Segment2D
from Patro.GeometryEngine.Spline import BSpline2D
-from Patro.GeometryEngine.Vector import Vector2D
from Patro.GraphicEngine.GraphicScene.GraphicStyle import GraphicPathStyle, GraphicBezierStyle
from Patro.GraphicEngine.Painter.QtPainter import QtScene
from Patro.GraphicStyle import Colors, StrokeStyle
+from PatroExample import find_data_path
####################################################################################################
-def spline_from_svg(scene_importer):
-
- # m 74.999689,150.7821
- # c
- # 9,-10 14.500002,-5 18.916662,-0.83334 4.41667,4.16667 7.749999,7.5 11.083339,5.83334
- # 3.33333,-1.66667 6.66666,-8.33334 13.33333,-11.66667 6.66667,-3.33333 16.66667,-3.33333
- # 16.66667,-3.33333
-
- # Vector2D[40. 50.]
- # Vector2D[49. 60.]
- # Vector2D[54.500002 55. ]
- # Vector2D[58.916662 50.83334 ]
- # Vector2D[63.333332 46.66667 ]
- # Vector2D[66.666661 43.33334 ]
- # Vector2D[70.000001 45. ]
- # Vector2D[73.333331 46.66667 ]
- # Vector2D[76.666661 53.33334 ]
- # Vector2D[83.333331 56.66667 ]
- # Vector2D[90.000001 60. ]
- # Vector2D[100.000001 60. ]
- # Vector2D[100.000001 60. ]
-
- # CubicBezier2D(Vector2D[40. 50.], Vector2D[49. 60.], Vector2D[54.5 55. ], Vector2D[58.91666667 50.83333333])
- # CubicBezier2D(Vector2D[58.91666667 50.83333333], Vector2D[63.33333333 46.66666667], Vector2D[66.66666667 43.33333333], Vector2D[70. 45.])
- # CubicBezier2D(Vector2D[70. 45.], Vector2D[73.33333333 46.66666667], Vector2D[76.66666667 53.33333333], Vector2D[83.33333333 56.66666667])
- # CubicBezier2D(Vector2D[83.33333333 56.66666667], Vector2D[90. 60.], Vector2D[100. 60.], Vector2D[100. 60.])
-
- x0, y0 = 40, 50
- control_points = (
- (9, -10),
- (14.500002, -5),
- (18.916662, -0.83334),
-
- (4.41667, 4.16667),
- (7.749999, 7.5),
- (11.083339, 5.83334),
-
- (3.33333, -1.66667),
- (6.66666, -8.33334),
- (13.33333, -11.66667),
-
- (6.66667, -3.33333),
- (16.66667, -3.33333),
- (16.66667, -3.33333),
- )
-
- vertices = []
- point = Vector2D(x0, y0)
- vertices.append(point)
- for i, xy in enumerate(control_points):
- xi, yi = xy
- yi = -yi
- if (i+1) % 3:
- x = xi + x0
- y = yi + y0
- else:
- x0 += xi
- y0 += yi
- x, y = x0, y0
- point = Vector2D(x, y)
- vertices.append(point)
-
- path_style = GraphicBezierStyle(
- line_width=3.0,
- stroke_color=Colors.blue,
- stroke_style=StrokeStyle.SolidLine,
- show_control=True,
- control_color=Colors.red,
- )
-
- for vertex in vertices:
- print(vertex)
- # scene_importer.scene.bezier_path(vertices, degree=3, path_style=path_style, user_data=None)
+_module_logger = logging.getLogger(__name__)
####################################################################################################
class SceneImporter:
+ _logger = _module_logger.getChild('SceneImporter')
+
##############################################
def __init__(self, dxf_path):
@@ -127,32 +75,25 @@ class SceneImporter:
def _add_item(self, item):
- # Fixme:
+ self._logger.info(item)
+
+ line_width = 3.
+
path_style = GraphicPathStyle(
- line_width=2.0,
+ line_width=line_width,
stroke_color=Colors.black,
stroke_style=StrokeStyle.SolidLine,
)
- if isinstance(item, Segment2D):
- self._scene.segment(item.p0, item.p1,
- path_style,
- user_data=item,
- )
- elif isinstance(item, Circle2D):
- kwargs = dict(user_data=item)
- if item.domain:
- kwargs['start_angle'] = item.domain.start
- kwargs['stop_angle'] = item.domain.stop
- self._scene.circle(item.center, item.radius,
- path_style,
- **kwargs,
- )
+ if isinstance(item, list):
+ for segment in item:
+ self._add_item(segment)
+
elif isinstance(item, BSpline2D):
path_style = GraphicPathStyle(
- line_width=3.,
- stroke_color=Colors.green,
- ) # Fixme
+ line_width=line_width,
+ stroke_color=Colors.blue_blue,
+ )
self._scene.polyline(item.points,
path_style,
user_data=item,
@@ -162,37 +103,18 @@ class SceneImporter:
stroke_color=Colors.black,
show_control=True,
control_color=Colors.red,
- ) # Fixme
- for bezier in item.to_bezier():
- self._scene.cubic_bezier(*bezier.points,
- path_style,
- user_data=item,
- )
- elif isinstance(item, Ellipse2D):
- self._scene.ellipse(item.center,
- item.x_radius,
- item.y_radius,
- item.angle,
- path_style,
- user_data=item,
)
- elif isinstance(item, list):
- for segment in item:
- self._add_item(segment)
+ self._scene.add_spline(item, path_style)
+
+ else:
+ self._scene.add_geometry(item, path_style)
+
self._update_bounding_box(item)
####################################################################################################
-# filename = 'protection-rectangulaire-v2.dxf'
-filename = 'test-dxf-r15.dxf'
-try:
- dxf_path = Path(__file__).parent.joinpath(filename)
-except:
- dxf_path = Path('examples', 'dxf', filename)
+dxf_path = find_data_path('dxf', 'test-dxf-r15.dxf')
scene_importer = SceneImporter(dxf_path)
-
-# spline_from_svg(scene_importer)
-
application.qml_application.scene = scene_importer.scene