def run(self): """ Converts an SVG into HPGL. """ # Set initial HPGL commands hpgl = ['IN', 'SP1'] hpgl.extend(self.commands['send_before']) if self.device['cutting_force'][1]: hpgl.append('FS%d' % self.device['cutting_force'][0]) if self.device['cutting_speed'][1]: hpgl.append('VS%d' % self.device['cutting_speed'][0]) # Read the input SVG into a Graphic to provide easy manipulation. g = Graphic(self.input) g.set_rotation(self.device['axis_rotation']) g.set_scale(self.device['axis_scale'][0] * HPGL_SCALE, self.device['axis_scale'][1] * HPGL_SCALE) g.set_position(self.device['axis_translate'][0], self.device['axis_translate'][1]) # Create the HPGL data paths = g.get_polyline() # Apply device specific settings if self.device['cutting_overlap'][1]: Plugin.apply_cutting_overlap(paths, self.device['cutting_overlap'][0]) if self.device['cutting_blade_offset'][1]: Plugin.apply_cutting_blade_offset( paths, self.device['cutting_blade_offset'][0]) data = [] for path in paths: x, y = path.pop(0)[1] data.append('PU%i,%i' % (round(x), round(y))) cmd = "PD" for line in path: x, y = line[1] cmd += '%i,%i,' % (round(x), round(y)) data.append(cmd[:-1]) hpgl.extend(data) hpgl.extend(self.commands['send_after']) # Not friendly for large files! self.output = ";\n".join(hpgl) + ";"
def run(self): """ Converts an SVG into HPGL. """ # Set initial HPGL commands hpgl = ['IN','SP1'] hpgl.extend(self.commands['send_before']) if self.device['cutting_force'][1]: hpgl.append('FS%d'%self.device['cutting_force'][0]) if self.device['cutting_speed'][1]: hpgl.append('VS%d'%self.device['cutting_speed'][0]) # Read the input SVG into a Graphic to provide easy manipulation. g = Graphic(self.input) g.set_rotation(self.device['axis_rotation']) g.set_mirror_x(True) # The coordinate systems are flipped in HPGL from SVG g.set_scale(self.device['axis_scale'][0]*HPGL_SCALE,self.device['axis_scale'][1]*HPGL_SCALE) g.set_position(self.device['axis_translate'][0],self.device['axis_translate'][1]) g.set_smoothness(1) # Create the HPGL data paths = g.get_polyline() # Apply device specific settings if self.device['cutting_overlap'][1]: Plugin.apply_cutting_overlap(paths,self.device['cutting_overlap'][0]) if self.device['cutting_blade_offset'][1]: Plugin.apply_cutting_blade_offset(paths,self.device['cutting_blade_offset'][0]) data = [] for path in paths: x,y = path.pop(0)[1] data.append('PU%i,%i'%(round(x),round(y))) cmd = "PD" for line in path: x,y = line[1] cmd +='%i,%i,'%(round(x),round(y)) data.append(cmd[:-1]) hpgl.extend(data) hpgl.extend(self.commands['send_after']) pos = self.plot['finish_position'] hpgl.append('PU%i,%i'%(round(self.device['axis_scale'][0]*HPGL_SCALE*pos[0]),round(y*self.device['axis_scale'][1]*HPGL_SCALE*pos[1]))) # Not friendly for large files! self.output = ";\n".join(hpgl)+";"