Ejemplo n.º 1
0
    def style_class(self, name, style):
        if not self._stream_id:
            self._logger.error('A stream must set before adding a style rule.')
            return self

        stream_rule = edict(name=name, style=build_object_style(style))
        self._temp_stream.style_classes.append(stream_rule)
        return self
Ejemplo n.º 2
0
 def style_class(self, name, style):
     if not self._stream_id:
         self._logger.error('A stream must set before adding a style rule.')
         return self
     style_class = self._temp_stream.style_classes.add()
     style_class.name = name
     style_class.style.MergeFrom(build_object_style(style))
     return self
Ejemplo n.º 3
0
    def _format_primitive(self):
        # XXX: Need to flatten arrays, TODO: need more elegant way
        # flatten_vertices = [item for sublist in self._vertices for item in sublist]

        # Embed primitive data
        if self._type == PRIMITIVE_TYPES.POLYGON:
            obj = Polygon(vertices=self._vertices)
        elif self._type == PRIMITIVE_TYPES.POLYLINE:
            obj = Polyline(vertices=self._vertices)
        elif self._type == PRIMITIVE_TYPES.POINT:
            obj = Point(points=self._vertices)
            if self._colors:
                obj.colors = bytes(self._colors)
        elif self._type == PRIMITIVE_TYPES.TEXT:
            obj = Text(position=self._vertices[0], text=self._text)
        elif self._type == PRIMITIVE_TYPES.CIRCLE:
            obj = Circle(center=self._vertices[0], radius=self._radius)
        elif self._type == PRIMITIVE_TYPES.STADIUM:
            obj = Stadium(start=self._vertices[0],
                          end=self._vertices[1],
                          radius=self._radius)
        elif self._type == PRIMITIVE_TYPES.IMAGE:
            if self._vertices:
                self._image.position = self._vertices[0]
            obj = self._image

        # Embed base data
        have_base = False
        base = PrimitiveBase()

        if self._id:
            have_base = True
            base.object_id = self._id
        if self._style:
            have_base = True
            base.style.MergeFrom(build_object_style(self._style))
        if self._classes:
            have_base = True
            base.classes.extend(self._classes)

        if have_base:
            obj.base.MergeFrom(base)

        return obj
Ejemplo n.º 4
0
    def _format_primitive(self, stream_pos: int):
        # Embed primitive data
        if self._type == PRIMITIVE_TYPES.POLYGON:
            obj = Polygon(vertices=self._vertices)
        elif self._type == PRIMITIVE_TYPES.POLYLINE:
            obj = Polyline(vertices=self._vertices)
        elif self._type == PRIMITIVE_TYPES.POINT:
            obj = Point()
            assert len(self._buffers[self._stream_id]) == stream_pos
            self._buffers[self._stream_id].append(self._vertices_buffer)
            if self._colors is not None:
                obj.colors = self._colors.tobytes()
        elif self._type == PRIMITIVE_TYPES.TEXT:
            obj = Text(position=self._vertices[0], text=self._text)
        elif self._type == PRIMITIVE_TYPES.CIRCLE:
            obj = Circle(center=self._vertices[0], radius=self._radius)
        elif self._type == PRIMITIVE_TYPES.STADIUM:
            obj = Stadium(start=self._vertices[0],
                          end=self._vertices[1],
                          radius=self._radius)
        elif self._type == PRIMITIVE_TYPES.IMAGE:
            if self._vertices:
                self._image.position = self._vertices[0]
            obj = self._image
            self._buffers[self._stream_id].append(self._image_buffer)

        # Embed base data
        have_base = False
        base = PrimitiveBase()

        if self._id:
            have_base = True
            base.object_id = self._id
        if self._style:
            have_base = True
            base.style.MergeFrom(build_object_style(self._style))
        if self._classes:
            have_base = True
            base.classes.extend(self._classes)

        if have_base:
            obj.base.MergeFrom(base)

        return obj