Ejemplo n.º 1
0
 def _circular_arc_3_point_close(self, element):
     p1, chunk = self.read_point(element.params)
     p2, chunk = self.read_point(chunk)
     p3, chunk = self.read_point(chunk)
     flag = self.read_enum(chunk)[0]
     p1, p2, p3 = libgeom.apply_trafo_to_points([p1, p2, p3],
                                                self.get_trafo())
     center = libgeom.circle_center_by_3points(p1, p2, p3)
     if not center:
         return
     r = libgeom.distance(center, p1)
     angle1 = libgeom.get_point_angle(p3, center)
     angle2 = libgeom.get_point_angle(p1, center)
     x, y = center
     rect = [x - r, y - r, 2 * r, 2 * r]
     flag = {
         0: sk2const.ARC_PIE_SLICE,
         1: sk2const.ARC_CHORD
     }.get(flag, sk2const.ARC_CHORD)
     circle = sk2_model.Circle(self.layer.config,
                               self.layer,
                               rect,
                               angle1=angle1,
                               angle2=angle2,
                               circle_type=flag,
                               style=self.get_style(fill=True))
     self.layer.childs.append(circle)
Ejemplo n.º 2
0
    def tr_arc(self, chunk, arc_type=sk2const.ARC_ARC):
        ye, xe, ys, xs, bottom, right, top, left = get_data('<hhhhhhhh', chunk)
        left, top = apply_trafo_to_point([left, top], self.get_trafo())
        right, bottom = apply_trafo_to_point([right, bottom], self.get_trafo())
        xs, ys = apply_trafo_to_point([xs, ys], self.get_trafo())
        xe, ye = apply_trafo_to_point([xe, ye], self.get_trafo())

        if left != right and top != bottom:
            t = [(right - left) / 2, 0, 0, (bottom - top) / 2,
                 (right + left) / 2, (top + bottom) / 2]
            t = libgeom.invert_trafo(t)
            xs, ys = apply_trafo_to_point([xs, ys], t)
            xe, ye = apply_trafo_to_point([xe, ye], t)
            end_angle = libgeom.get_point_angle([xs, ys], [0.0, 0.0])
            start_angle = libgeom.get_point_angle([xe, ye], [0.0, 0.0])
        else:
            start_angle = end_angle = 0.0

        cfg = self.layer.config
        sk2_style = self.get_style()
        if arc_type == sk2const.ARC_ARC:
            sk2_style[0] = []
        rect = [left, top, right - left, bottom - top]
        ellipse = sk2_model.Circle(cfg, self.layer, rect, start_angle,
                                   end_angle, arc_type, sk2_style)
        self.layer.childs.append(ellipse)
Ejemplo n.º 3
0
 def _circle(self, element):
     center, chunk = self.read_point(element.params)
     r = self.read_vdc(chunk)[0] * self.scale
     x, y = libgeom.apply_trafo_to_point(center, self.get_trafo())
     rect = [x - r, y - r, 2 * r, 2 * r]
     circle = sk2_model.Circle(self.layer.config, self.layer, rect,
                               style=self.get_style(fill=True))
     self.layer.childs.append(circle)
Ejemplo n.º 4
0
    def tr_ellipse(self, chunk):
        bottom, right, top, left = get_data('<hhhh', chunk)
        left, top = apply_trafo_to_point([left, top], self.get_trafo())
        right, bottom = apply_trafo_to_point([right, bottom], self.get_trafo())

        cfg = self.layer.config
        sk2_style = self.get_style()
        rect = [left, top, right - left, bottom - top]
        ellipse = sk2_model.Circle(cfg, self.layer, rect, style=sk2_style)
        self.layer.childs.append(ellipse)
Ejemplo n.º 5
0
 def translate_ellipse(self, dest_parent, source_ellipse):
     trafo = self.get_sk2_trafo(source_ellipse)
     angle1 = source_ellipse.start_angle
     angle2 = source_ellipse.end_angle
     arc_type = SK2_ARC_TYPES[source_ellipse.arc_type]
     rect = [-1.0, -1.0, 2.0, 2.0]
     dest_ellipse = sk2_model.Circle(dest_parent.config, dest_parent, rect,
                                     angle1, angle2, arc_type)
     dest_ellipse.trafo = libgeom.multiply_trafo(dest_ellipse.trafo, trafo)
     dest_ellipse.initial_trafo = [] + dest_ellipse.trafo
     set_sk2_style(source_ellipse.properties, dest_ellipse)
     return dest_ellipse
Ejemplo n.º 6
0
 def _ellipse(self, element):
     center, chunk = self.read_point(element.params)
     cdp1, chunk = self.read_point(chunk)
     cdp2, chunk = self.read_point(chunk)
     cdp3 = libgeom.contra_point(cdp1, center)
     cdp4 = libgeom.contra_point(cdp2, center)
     bbox = libgeom.sum_bbox(cdp1 + cdp2, cdp3 + cdp4)
     bbox = libgeom.apply_trafo_to_bbox(bbox, self.get_trafo())
     rect = libgeom.bbox_to_rect(bbox)
     circle = sk2_model.Circle(self.layer.config, self.layer, rect,
                               style=self.get_style(fill=True))
     self.layer.childs.append(circle)
Ejemplo n.º 7
0
 def translate_ellipse(self, obj, cfg):
     cx = obj.center_x
     cy = obj.center_y
     rx = obj.radius_x
     ry = obj.radius_y
     props = dict(
         rect=[cx - rx, cy - ry, 2.0 * rx, 2.0 * ry],
         style=self.get_style(obj),
     )
     new_obj = sk2_model.Circle(cfg, **props)
     trafo_rotate = libgeom.trafo_rotate(-obj.angle, cx, cy)
     trafo = libgeom.multiply_trafo(new_obj.trafo, trafo_rotate)
     new_obj.trafo = libgeom.multiply_trafo(trafo, self.trafo)
     return new_obj
Ejemplo n.º 8
0
 def translate_arc(self, obj, cfg):
     cx = obj.center_x
     cy = obj.center_y
     r = libgeom.distance((cx, cy), (obj.x1, obj.y1))
     end_angle = libgeom.get_point_angle((obj.x1, obj.y1), (cx, cy))
     start_angle = libgeom.get_point_angle((obj.x3, obj.y3), (cx, cy))
     if not obj.direction:
         start_angle, end_angle = end_angle, start_angle
     circle_type = FIG_TO_SK2_ARC.get(obj.sub_type, sk2const.ARC_PIE_SLICE)
     props = dict(circle_type=circle_type,
                  rect=[cx - r, cy - r, 2.0 * r, 2.0 * r],
                  style=self.get_style(obj),
                  angle1=start_angle,
                  angle2=end_angle)
     new_obj = sk2_model.Circle(cfg, **props)
     new_obj.trafo = libgeom.multiply_trafo(new_obj.trafo, self.trafo)
     return new_obj
Ejemplo n.º 9
0
 def _circular_arc_centre(self, element):
     center, chunk = self.read_point(element.params)
     p1, chunk = self.read_point(chunk)
     p2, chunk = self.read_point(chunk)
     center, p1, p2 = libgeom.apply_trafo_to_points(
         [center, p1, p2], self.get_trafo())
     r = self.read_vdc(chunk)[0] * self.scale
     angle1 = libgeom.get_point_angle(p1, center)
     angle2 = libgeom.get_point_angle(p2, center)
     x, y = center
     rect = [x - r, y - r, 2 * r, 2 * r]
     circle = sk2_model.Circle(self.layer.config, self.layer, rect,
                               angle1=angle1,
                               angle2=angle2,
                               circle_type=sk2const.ARC_ARC,
                               style=self.get_style(stroke=True))
     self.layer.childs.append(circle)
Ejemplo n.º 10
0
 def _circular_arc_centre_close(self, element):
     center, chunk = self.read_point(element.params)
     p1, chunk = self.read_point(chunk)
     p2, chunk = self.read_point(chunk)
     flag = self.read_enum(chunk)[0]
     center, p1, p2 = libgeom.apply_trafo_to_points(
         [center, p1, p2], self.get_trafo())
     r = self.read_vdc(chunk)[0] * self.scale
     angle1 = libgeom.get_point_angle(p1, center)
     angle2 = libgeom.get_point_angle(p2, center)
     x, y = center
     rect = [x - r, y - r, 2 * r, 2 * r]
     flag = {0: sk2const.ARC_PIE_SLICE,
             1: sk2const.ARC_CHORD}.get(flag, sk2const.ARC_CHORD)
     circle = sk2_model.Circle(self.layer.config, self.layer, rect,
                               angle1=angle1,
                               angle2=angle2,
                               circle_type=flag,
                               style=self.get_style(fill=True))
     self.layer.childs.append(circle)
Ejemplo n.º 11
0
 def _circular_arc_3_point(self, element):
     p1, chunk = self.read_point(element.params)
     p2, chunk = self.read_point(chunk)
     p3, chunk = self.read_point(chunk)
     p1, p2, p3 = libgeom.apply_trafo_to_points(
         [p1, p2, p3], self.get_trafo())
     center = libgeom.circle_center_by_3points(p1, p2, p3)
     if not center:
         return
     r = libgeom.distance(center, p1)
     angle1 = libgeom.get_point_angle(p3, center)
     angle2 = libgeom.get_point_angle(p1, center)
     x, y = center
     rect = [x - r, y - r, 2 * r, 2 * r]
     circle = sk2_model.Circle(self.layer.config, self.layer, rect,
                               angle1=angle1,
                               angle2=angle2,
                               circle_type=sk2const.ARC_ARC,
                               style=self.get_style(stroke=True))
     self.layer.childs.append(circle)