def tr_polypolygon(self, chunk): polygonnum = get_data('<H', chunk[:2])[0] pointnums = [] pos = 2 for i in range(polygonnum): pointnums.append(get_data('<h', chunk[pos:pos + 2])[0]) pos += 2 paths = [] for pointnum in pointnums: points = [] for i in range(pointnum): x, y = get_data('<hh', chunk[pos:4 + pos]) points.append([float(x), float(y)]) pos += 4 if not points[0] == points[-1]: points.append([] + points[0]) paths.append([points[0], points[1:], sk2const.CURVE_CLOSED]) if not paths: return cfg = self.layer.config sk2_style = self.get_style() curve = sk2_model.Curve(cfg, self.layer, paths, self.get_trafo(), sk2_style) self.layer.childs.append(curve)
def translate_curve(self, dest_parent, source_curve): paths = deepcopy(source_curve.paths_list) trafo = [1.0, 0.0, 0.0, 1.0, self.dx, self.dy] dest_curve = sk2_model.Curve(dest_parent.config, dest_parent, paths, trafo) set_sk2_style(source_curve.properties, dest_curve) return dest_curve
def _polygon_set(self, element): paths = [] path = [None, [], sk2const.CURVE_CLOSED] chunk = element.params for _ in range(len(chunk) / (2 * self.cgm['vdc.size'] + 2)): point, chunk = self.read_point(chunk) flag, chunk = self.read_enum(chunk) if not path[0]: path[0] = point else: path[1].append(point) if flag in (2, 3): if path[0] != path[1][-1]: path[1].append([] + path[0]) paths.append(path) path = [None, [], sk2const.CURVE_CLOSED] if path[1]: if path[0] != path[1][-1]: path[1].append([] + path[0]) paths.append(path) if paths: curve = sk2_model.Curve(self.layer.config, self.layer, paths, self.get_trafo(), self.get_style(fill=True)) self.layer.childs.append(curve)
def _polygon(self, element): path = self.read_path(element.params) if path[0] != path[1][-1]: path[1].append([] + path[0]) path[2] = sk2const.CURVE_CLOSED curve = sk2_model.Curve(self.layer.config, self.layer, [path, ], self.get_trafo(), self.get_style(fill=True)) self.layer.childs.append(curve)
def tr_lineto(self, chunk): y, x = get_data('<hh', chunk) p = [x, y] paths = [[self.get_curpoint(), [p, ], sk2const.CURVE_OPENED], ] self.set_curpoint([] + p) cfg = self.layer.config sk2_style = self.get_style() sk2_style[0] = [] curve = sk2_model.Curve(cfg, self.layer, paths, self.get_trafo(), sk2_style) self.layer.childs.append(curve)
def end_stitch(self): if len(self.stitch_list) > 1: methods = self.sk2_doc.methods path = self.stitch_list curve = sk2_model.Curve( self.sk2_doc.config, parent=None, style=self.get_style(), paths=[[path[0], path[1:], sk2const.CURVE_OPENED]], trafo=[] + dst_const.DST_to_SK2_TRAFO) methods.append_object(curve, self.layer) self.stitch_list = []
def _disjoint_polyline(self, element): points = self.read_points(element.params) first_point = None paths = [] for point in points: if first_point: paths.append([first_point, [point, ], sk2const.CURVE_OPENED]) first_point = None else: first_point = point curve = sk2_model.Curve(self.layer.config, self.layer, paths, self.get_trafo(), self.get_style(stroke=True)) self.layer.childs.append(curve)
def create_curve(self, obj): config = self.pdxf_doc.config parent = self.parent_stack[-1] paths = deepcopy(obj.paths) trafo = deepcopy(obj.trafo) if not obj.style_id is None and obj.fill_id is None and obj.outl_id is None: style = [[], deepcopy(config.default_stroke), [], []] else: if obj.fill_id is None: fill = [] else: fill = self.get_fill_prop(obj.fill_id) if obj.outl_id is None: stroke = [] else: stroke = self.get_stroke_prop(obj.outl_id) style = [fill, stroke, [], []] curve = sk2_model.Curve(config, parent, paths, trafo, style) self.methods.append_object(curve, parent)
def translate_v1_polycurve(self, el): points = el.data.get('points') nodes = el.data.get('nodes') if not points or not nodes or len(points) != len(nodes): return index = 0 path = None paths = [] curve = None close = 0 def _append_path(paths, path, close): if path and path[1]: paths.append(path) if close: if path[1][-1] != path[0]: path[1].append([] + path[0]) path[2] = sk2const.CURVE_CLOSED while index < len(points): point = list(points[index]) node = nodes[index] type = (node & 0xc0) >> 6 if type == 0: _append_path(paths, path, close) close = node & 0x08 path = [point, [], sk2const.CURVE_OPENED] elif type == 1: path[1].append(point) elif type == 3: p = [ point, list(points[index + 1]), list(points[index + 2]), sk2const.NODE_CUSP ] path[1].append(p) index += 2 index += 1 _append_path(paths, path, close) if paths: style = self.get_v1_style(el) curve = sk2_model.Curve(self.sk2_model.config, paths=paths, trafo=[] + self.trafo, style=style) return curve
def translate_spline(self, obj, cfg): closed = obj.sub_type & 1 if obj.sub_type in fig_const.T_XSPLINE: path = self.xspline2path(obj.points, obj.control_points, closed) elif obj.sub_type in fig_const.T_INTERPOLATED: path = self.interpolated2path(obj.points, obj.control_points) elif obj.sub_type in fig_const.T_APPROX: path = self.aprox2path(obj.points, closed) end_marker = sk2const.CURVE_CLOSED if closed else sk2const.CURVE_OPENED if path: style = self.get_style(obj) start_point, points = path[0], path[1:] paths = [[start_point, points, end_marker]] props = dict(paths=paths, trafo=self.trafo[:], style=style) return sk2_model.Curve(cfg, **props)
def tr_polyline(self, chunk): pointnum = get_data('<h', chunk[:2])[0] points = [] for i in range(pointnum): x, y = get_data('<hh', chunk[2 + i * 4:6 + i * 4]) points.append([float(x), float(y)]) if len(points) < 2: return paths = [[points[0], points[1:], sk2const.CURVE_OPENED], ] cfg = self.layer.config sk2_style = self.get_style() sk2_style[0] = [] curve = sk2_model.Curve(cfg, self.layer, paths, self.get_trafo(), sk2_style) self.layer.childs.append(curve)
def translate(self, plt_doc, sk2_doc): jobs = plt_doc.get_jobs() page = sk2_doc.methods.get_page() layer = sk2_doc.methods.get_layer(page) style = [ deepcopy(sk2_doc.config.default_fill), deepcopy(sk2_doc.config.default_stroke), deepcopy(sk2_doc.config.default_text_style), [] ] for job in jobs: if job.cid == plt_model.JOB: curve = sk2_model.Curve(sk2_doc.config) curve.paths = [ deepcopy(job.cache_path), ] curve.trafo = [] + PLT_to_SK2_TRAFO curve.style = deepcopy(style) sk2_doc.methods.append_object(curve, layer) sk2_doc.model.do_update()
def translate_polyline(self, obj, cfg): tr = self.trafo style = self.get_style(obj) if obj.sub_type in (fig_const.T_ARC_BOX, fig_const.T_PIC_BOX): bbox = libgeom.bbox_for_points(obj.points) bbox_size = libgeom.bbox_size(bbox) rect = [bbox[0], bbox[1], bbox_size[0], bbox_size[1]] corners = sk2const.CORNERS if obj.sub_type == fig_const.T_ARC_BOX: try: wide_side = max(bbox_size) * tr[0] c = obj.radius * 2.0 * self.thickness / wide_side corners = [c, c, c, c] except ZeroDivisionError: pass else: try: pic = self.translate_pic(obj, cfg) if pic: return pic except Exception: pass props = dict(rect=rect, trafo=tr[:], style=style, corners=corners[:]) new_obj = sk2_model.Rectangle(cfg, **props) else: start_point, points = obj.points[0], obj.points[1:] end_marker = points and start_point == points[-1] paths = [[start_point, points, end_marker]] props = dict(paths=paths, trafo=tr[:], style=style) new_obj = sk2_model.Curve(cfg, **props) return new_obj
def _polyline(self, element): curve = sk2_model.Curve(self.layer.config, self.layer, [ self.read_path(element.params), ], self.get_trafo(), self.get_style(stroke=True)) self.layer.childs.append(curve)