Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
 def label_line_style(self):
     return GraphicPathStyle(line_width=self._label_line_width)
Esempio n. 7
0
 def point_style(self):
     return GraphicPathStyle(fill_color=self._point_color)
Esempio n. 8
0
    def detail_scene(self, scene_cls=GraphicScene):
        """Generate a graphic scene for the detail mode

        Scene class can be customised using the *scene_cls* parameter.
        """

        scene = scene_cls()
        # Fixme: scene bounding box
        scene.bounding_box = self.bounding_box

        # Fixme: implement a transformer class to prevent if ... ?

        font = Font('', 16)

        for operation in self._operations:

            if isinstance(operation, SketchOperation.Point):
                # Register coordinate
                scene.add_coordinate(operation.name, operation.vector)
                # Draw point and label
                scene.circle(
                    operation.name,
                    '1pt',
                    GraphicPathStyle(fill_color='black'),
                    user_data=operation,
                )
                label_offset = operation.label_offset
                offset = Vector2D(label_offset.x,
                                  -label_offset.y)  # Fixme: ???
                label_position = operation.vector + offset
                if offset:
                    # arrow must point to the label center and be clipped
                    scene.segment(
                        operation.vector,
                        label_position,
                        GraphicPathStyle(line_width='.5pt'),
                        user_data=operation,
                    )
                    scene.text(label_position,
                               operation.name,
                               font,
                               user_data=operation)

                if isinstance(operation, SketchOperation.LinePropertiesMixin):
                    path_style = self._operation_to_path_style(
                        operation, line_width='2pt')
                    if isinstance(operation, SketchOperation.AlongLinePoint):
                        scene.segment(
                            operation.first_point.name,
                            operation.name,
                            path_style,
                            user_data=operation,
                        )
                    elif isinstance(operation, SketchOperation.EndLinePoint):
                        scene.segment(
                            operation.base_point.name,
                            operation.name,
                            path_style,
                            user_data=operation,
                        )
                    # elif isinstance(operation, LineIntersectPoint):
                    #     scene.segment(operation.point1_line1.name, operation.name, path_style)
                    #     source += r'\draw[{0}] ({1.point1_line1.name}) -- ({1.name});'.format(style, operation) + '\n'
                    elif isinstance(operation, SketchOperation.NormalPoint):
                        scene.segment(
                            operation.first_point.name,
                            operation.name,
                            path_style,
                            user_data=operation,
                        )

            # Draw path item like segments and Bézier curves

            elif isinstance(operation, SketchOperation.Line):
                path_style = self._operation_to_path_style(operation,
                                                           line_width='4pt')
                scene.segment(
                    operation.first_point.name,
                    operation.second_point.name,
                    path_style,
                    user_data=operation,
                )

            elif isinstance(operation,
                            SketchOperation.SimpleInteractiveSpline):
                path_style = self._operation_to_path_style(operation,
                                                           line_width='4pt')
                scene.cubic_bezier(
                    operation.first_point.name,
                    operation.control_point1,
                    operation.control_point2,
                    operation.second_point.name,
                    path_style,
                    user_data=operation,
                )

        return scene
Esempio n. 9
0
    def _operation_to_path_style(self, operation, **kwargs):
        """Generate a :class:`GraphicPathStyle` instance for a operation"""

        return GraphicPathStyle(stroke_style=operation.line_style,
                                stroke_color=operation.line_color,
                                **kwargs)