コード例 #1
0
ファイル: test-convex-hull.py プロジェクト: maaaash/Patro
    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        for item in (self._make_polygon(), ):
            self._add_item(item)
        self._scene.bounding_box = self._bounding_box  # Fixme:
コード例 #2
0
    def __init__(self, dxf_path):

        self._importer = DxfImporter(dxf_path)
        self._scene = QtScene()

        self._bounding_box = None
        for item in self._importer:
            self._add_item(item)
        self._scene.bounding_box = self._bounding_box  # Fixme:
コード例 #3
0
ファイル: test-ellipse.py プロジェクト: maaaash/Patro
    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        self._line_width = 5.
        for path in self._make_figure1():
            self._add_item(path)
        self._scene.bounding_box = self._bounding_box # Fixme:
コード例 #4
0
    def __init__(self, svg_path):

        self._bounding_box = None
        self._item_counter = 0
        self._scene = QtScene()

        super().__init__(svg_path)

        # Fixme:
        self._scene.bounding_box = self._bounding_box

        self._logger.info('Number of SVG item: {}'.format(self._item_counter))
        self._logger.info('Number of scene item: {}'.format(self._scene.number_of_items))
コード例 #5
0
    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        for path in (
                self._make_directional_path((0, 0)),
                self._make_rounded_rectangle((20, 0),
                                             width=10,
                                             height=15,
                                             radius=5),
                self._make_closed_path((35, 0), radius=None),
                self._make_closed_path((55, 0), radius=3),
                self._make_absolute_cw_path((0, 40), radius=3),
                self._make_absolute_ccw_path((0, 45), radius=3),
                self._make_quadratic((25, 40)),
                self._make_absolute_quadratic((35, 40)),
                self._make_cubic((40, 40)),
                self._make_absolute_cubic((50, 40)),
        ):
            self._add_path(path)
        self._scene.bounding_box = self._bounding_box  # Fixme:
コード例 #6
0
class SceneImporter:

    _logger = _module_logger.getChild('SceneImporter')

    ##############################################

    def __init__(self, dxf_path):

        self._importer = DxfImporter(dxf_path)
        self._scene = QtScene()

        self._bounding_box = None
        for item in self._importer:
            self._add_item(item)
        self._scene.bounding_box = self._bounding_box  # Fixme:

    ##############################################

    @property
    def scene(self):
        return self._scene

    ##############################################

    def _update_bounding_box(self, item):

        if hasattr(item, 'bounding_box'):
            interval = item.bounding_box
            if self._bounding_box is None:
                self._bounding_box = interval
            else:
                self._bounding_box |= interval

    ##############################################

    def _add_item(self, item):

        self._logger.info(item)

        line_width = 3.

        path_style = GraphicPathStyle(
            line_width=line_width,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
        )

        if isinstance(item, list):
            for segment in item:
                self._add_item(segment)

        elif isinstance(item, BSpline2D):
            path_style = GraphicPathStyle(
                line_width=line_width,
                stroke_color=Colors.blue_blue,
            )
            self._scene.polyline(
                item.points,
                path_style,
                user_data=item,
            )
            path_style = GraphicBezierStyle(
                line_width=5.0,
                stroke_color=Colors.black,
                show_control=True,
                control_color=Colors.red,
            )
            self._scene.add_spline(item, path_style)

        else:
            self._scene.add_geometry(item, path_style)

        self._update_bounding_box(item)
コード例 #7
0
ファイル: test-ellipse.py プロジェクト: maaaash/Patro
class SceneBuilder:

    ##############################################

    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        self._line_width = 5.
        for path in self._make_figure1():
            self._add_item(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_figure1(self):

        center = (0, 0)
        ellipses = [Ellipse2D(center, 20, 10, angle=angle)
                    for angle in range(0, 360, 20)]
        center = (50, 0)
        ellipse_arc = Ellipse2D(center, 20, 10, angle=60, domain=AngularDomain(30, 160))

        ellipses_bezier = [ellipse.to_bezier() for ellipse in ellipses]
        flat_ellipses_bezier = []
        for segments in ellipses_bezier:
            flat_ellipses_bezier += list(segments)

        return [
            *flat_ellipses_bezier,
            *ellipse_arc.to_bezier(),
        ]

    ##############################################

    def _add_item(self, item):

        path_style = GraphicPathStyle(
            line_width=self._line_width,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
            cap_style=CapStyle.RoundCap,
        )

        self._scene.add_geometry(item, path_style)
        # Fixme: why here ???
        self._update_bounding_box(item)
コード例 #8
0
ファイル: test-ellipse.py プロジェクト: maaaash/Patro
        flat_ellipses_bezier = []
        for segments in ellipses_bezier:
            flat_ellipses_bezier += list(segments)

        return [
            *flat_ellipses_bezier,
            *ellipse_arc.to_bezier(),
        ]

    ##############################################

    def _add_item(self, item):

        path_style = GraphicPathStyle(
            line_width=self._line_width,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
            cap_style=CapStyle.RoundCap,
        )

        self._scene.add_geometry(item, path_style)
        # Fixme: why here ???
        self._update_bounding_box(item)

####################################################################################################

scene = QtScene()

scene_builder = SceneBuilder()
application.qml_application.scene = scene_builder.scene
コード例 #9
0
class SceneBuilder:

    ##############################################

    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        for path in (
                self._make_directional_path((0, 0)),
                self._make_rounded_rectangle((20, 0),
                                             width=10,
                                             height=15,
                                             radius=5),
                self._make_closed_path((35, 0), radius=None),
                self._make_closed_path((55, 0), radius=3),
                self._make_absolute_cw_path((0, 40), radius=3),
                self._make_absolute_ccw_path((0, 45), radius=3),
                self._make_quadratic((25, 40)),
                self._make_absolute_quadratic((35, 40)),
                self._make_cubic((40, 40)),
                self._make_absolute_cubic((50, 40)),
        ):
            self._add_path(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_directional_path(self, start_point):

        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 _make_rounded_rectangle(self, start_point, width, height, radius):

        path = Path2D(start_point)
        path.horizontal_to(width)
        path.vertical_to(height, radius=radius)
        path.horizontal_to(-width, radius=radius)
        path.close(radius=radius, close_radius=radius)

        return path

    ##############################################

    def _make_closed_path(self, start_point, radius):

        path = Path2D(start_point)
        path.line_to(Vector2D(10, 0))
        path.line_to(Vector2D(0, 10), radius=radius)
        path.line_to(Vector2D(10, 0), radius=radius)
        path.line_to(Vector2D(0, 20), radius=radius)
        path.line_to(Vector2D(-10, 0), radius=radius)
        path.line_to(Vector2D(0, -10), radius=radius)
        path.close(radius=radius, close_radius=radius)

        return path

    ##############################################

    def _make_absolute_cw_path(self, start_point, radius):

        # radius = None
        path = Path2D(start_point)
        for i, vector in enumerate((
            (10, -5),
            (5, -15),
            (-5, -15),
            (-10, -5),
        )):
            path.line_to(path.p0 + Vector2D(vector),
                         absolute=True,
                         radius=(radius if i else None))
        path.close(radius=radius, close_radius=radius)

        return path

    ##############################################

    def _make_absolute_ccw_path(self, start_point, radius):

        path = Path2D(start_point)
        for i, vector in enumerate((
            (10, 0),
            (15, 10),
            (5, 15),
            (-5, 10),
        )):
            path.line_to(path.p0 + Vector2D(vector),
                         absolute=True,
                         radius=(radius if i else None))
        path.close(radius=radius, close_radius=radius)

        return path

    ##############################################

    def _make_quadratic(self, start_point):

        path = Path2D(start_point)
        path.quadratic_to(
            Vector2D(0, 10),
            Vector2D(10, 10),
        )

        return path

    ##############################################

    def _make_absolute_quadratic(self, start_point):

        path = Path2D(start_point)
        path.quadratic_to(
            path.p0 + Vector2D(0, 10),
            path.p0 + Vector2D(10, 10),
            absolute=True,
        )

        return path

    ##############################################

    def _make_cubic(self, start_point):

        path = Path2D(start_point)
        path.cubic_to(
            Vector2D(5, 10),
            Vector2D(10, 10),
            Vector2D(15, 0),
        )

        return path

    ##############################################

    def _make_absolute_cubic(self, start_point):

        path = Path2D(start_point)
        path.cubic_to(
            path.p0 + Vector2D(5, 10),
            path.p0 + Vector2D(10, 10),
            path.p0 + Vector2D(15, 0),
            absolute=True,
        )

        return path

    ##############################################

    def _add_path(self, path):

        path_style = GraphicPathStyle(
            line_width=3.0,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
        )

        self._scene.add_path(path, path_style)

        # Fixme: why here ???
        self._update_bounding_box(path)
コード例 #10
0
ファイル: test-arrow.py プロジェクト: maaaash/Patro
class SceneBuilder:

    ##############################################

    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        self._line_width = 5.
        for path in self._make_figure1():
            self._add_item(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_figure1(self):

        items = []
        for angle in range(0, 360, 30):
            point1 = Vector2D(0, 0)
            point2 = Vector2D.from_polar(50, angle)
            segment = Segment2D(point1, point2)
            items.append(segment)
            head = TriangularHead(point2, segment.direction, length=5, width=5)
            # head = head.to_path()
            items.append(head)

        return items

    ##############################################

    def _add_item(self, item):

        path_style = GraphicPathStyle(
            line_width=self._line_width,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
            cap_style=CapStyle.RoundCap,
        )

        if isinstance(item, ArrowHead):
            path_style.fill_color = Colors.black

        self._scene.add_geometry(item, path_style)
        # Fixme: why here ???
        self._update_bounding_box(item)
コード例 #11
0
class SceneImporter(SvgFileInternal):

    _logger = _module_logger.getChild('SceneImporter')

    ##############################################

    def __init__(self, svg_path):

        self._bounding_box = None
        self._item_counter = 0
        self._scene = QtScene()

        super().__init__(svg_path)

        # Fixme:
        self._scene.bounding_box = self._bounding_box

        self._logger.info('Number of SVG item: {}'.format(self._item_counter))
        self._logger.info('Number of scene item: {}'.format(self._scene.number_of_items))

    ##############################################

    @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 on_svg_root(self, svg_root):
        super().on_svg_root(svg_root)
        self._screen_transformation = AffineTransformation2D.Screen(self._view_box.y.sup)

    ##############################################

    def on_group(self, group):
        # self._logger.info('Group: {}\n{}'.format(group.id, group))
        pass

    ##############################################

    def on_graphic_item(self, item):

        # d="
        # m 31.589881,269.68673
        # a 5,10 0 0 1  7.061333,   0.48142
        #   5,10 0 0 1 -0.229465,  14.12342
        #   5,10 0 0 1 -7.062064,  -0.43644
        #   5,10 0 0 1  0.20697 , -14.1248
        # L 35,277.00003
        # Z"
        # if item.id == 'ellipse':
        #     print(item)
        #     for part in item.path_data:
        #         print(part)

        state = self._dispatcher.state.clone().merge(item)
        # self._logger.info('Item: {}\n{}'.format(item.id, item))
        # self._logger.info('Item State:\n' + str(state))

        self._item_counter += 1

        stroke_style = StrokeStyle.SolidLine if state.stroke_dasharray is None else StrokeStyle.DashLine
        fill_color = None if state.fill is None else Color(state.fill)

        path_style = GraphicPathStyle(
            line_width=2,
            stroke_color=Colors.black,
            stroke_style=stroke_style,
            cap_style=CapStyle.RoundCap,
            # fill_color=fill_color,
        )

        transformation = self._screen_transformation * state.transform
        # 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
        elif isinstance(item, SvgFormat.Rect):
            path = item.geometry
        path = path.transform(transformation)
        self._update_bounding_box(path)
        self._scene.add_path(path, path_style)
コード例 #12
0
ファイル: test-convex-hull.py プロジェクト: maaaash/Patro
class SceneBuilder:

    ##############################################

    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        for item in (self._make_polygon(), ):
            self._add_item(item)
        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_polygon(self):

        points = Vector2D.from_coordinates(
            (0, 0),
            (-1, 2),
            (0, 3),
            (2, 4),
            (1, 5),
            (4, 6),
            (3, 3),
            (5, 3),
            (7, 3),
            (7, 2),
            (6, 1),
            (3, 2),
            (2, 1),
        )

        polygon = Polygon2D(*points)
        return polygon

    ##############################################

    def _add_item(self, item):

        path_style = GraphicPathStyle(
            line_width=3.0,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
        )

        self._scene.add_geometry(item, path_style)

        # Fixme: why here ???
        self._update_bounding_box(item)
コード例 #13
0
class SceneBuilder:

    ##############################################

    def __init__(self):

        self._scene = QtScene()

        self._bounding_box = None
        self._line_width = 5.
        for path in self._make_figure1():
            self._add_item(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_figure1(self):

        width = 30
        space = 2
        seam_length = width / 4
        long_arm_length = width / 2
        short_arm_length = long_arm_length * .6
        height = 4
        radius = 2

        vertical_seam_position = short_arm_length * 2 / 3
        vertical_seam_length = height * 1.5

        right_side_length = width / 4
        y_right_side = height * 1.5
        right_side_circle_radius = 1

        path1 = Path2D((short_arm_length + space / 2, -height / 2))
        path1.west_to(short_arm_length)
        path1.north_to(height, radius=radius)
        path1.east_to(long_arm_length, radius=radius)

        path2 = path1.x_mirror(clone=True)

        path3 = Path2D((-seam_length / 2, 0))
        path3.east_to(seam_length)

        path4 = Path2D((vertical_seam_position, -vertical_seam_length / 2))
        path4.north_to(vertical_seam_length)

        path5 = path4.x_mirror(clone=True)

        path6 = Path2D((-right_side_length / 2, y_right_side))
        path6.east_to(right_side_length)

        circle = Circle2D((0, y_right_side), right_side_circle_radius)

        return [path1, path2, path3, path4, path5, path6, circle]

    ##############################################

    def _add_item(self, item):

        if isinstance(item, Path2D):
            self._add_path(item)
        elif isinstance(item, Circle2D):
            self._add_circle(item)

    ##############################################

    def _add_path(self, path):

        path_style = GraphicPathStyle(
            line_width=self._line_width,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
            cap_style=CapStyle.RoundCap,
        )

        self._scene.add_path(path, path_style)
        # Fixme: why here ???
        self._update_bounding_box(path)

    ##############################################

    def _add_circle(self, circle):

        path_style = GraphicPathStyle(
            line_width=self._line_width,
            stroke_color=Colors.black,
            stroke_style=StrokeStyle.SolidLine,
        )

        self._scene.add_geometry(circle, path_style)
        self._update_bounding_box(circle)