def convertToSegments(cls, path_node): path_start = None currentPoint = None # work on copy to be shure not breaking anything path = copy.deepcopy(path_node) # apply transformation info on path, otherwise dealing with transform would be a mess simpletransform.fuseTransform(path) for cmd, params in simplepath.parsePath(path.get('d')): print_('cmd, params', cmd, params) if cmd == 'M': if(path_start is None): path_start = params currentPoint = params elif cmd == 'L': yield Segment(currentPoint, params) currentPoint = params elif cmd in ['A', 'Q', 'C']: yield Segment(currentPoint, params[-2:], command=cmd, extra_parameters=params[:-2]) currentPoint = params[-2:] elif (cmd == 'Z'): # Z is a line between the last point and the start of the shape yield Segment(currentPoint, path_start) currentPoint = None path_start = None else: inkex.errormsg("Path Command %s not managed Yet" % cmd)
def similar(a, b): print_(a, b) if type(a) is list and type(b) is list: return False not in[similar(c[0], c[1]) for c in zip(a, b)] else: return abs(roundValue(a) - roundValue(b)) <= 2 / PRECISION
def similar(a, b): print_(a, b) if type(a) is list and type(b) is list: return False not in [similar(c[0], c[1]) for c in zip(a, b)] else: return abs(roundValue(a) - roundValue(b)) <= 2 / PRECISION
def effect(self): print_(self.options) parent = self.current_layer centre = self.view_center print_("-- %s -- %s --" % (centre[0], centre[1])) fgcolor = "#FF0000" bgcolor = None try: if (self.options.closed == 'true'): for shape in self.box_with_top( self.options.path_id, centre[0], centre[1], bgcolor, fgcolor, self.options.width, self.options.depth, self.options.height, self.options.tab_size, self.options.thickness, self.options.backlash): inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape) else: for shape in self.box_without_top( self.options.path_id, centre[0], centre[1], bgcolor, fgcolor, self.options.width, self.options.depth, self.options.height, self.options.tab_size, self.options.thickness, self.options.backlash): inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape) except BoxGenrationError as e: inkex.errormsg(e.value)
def effect(self): print_(self.options) parent = self.current_layer centre = self.view_center tabs = self.tabs(self.options.width, self.options.tab_size, self.options.thickness, backlash=self.options.backlash * -1, lastUp=True) shape = self.getPath(self.toPathString(self.mm2u(tabs)), '%s_bottom' % self.options.path_id, centre[0], centre[1], None, '#FF0000') inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape) tabs = [[0, 0]] tabs.extend( self.tabs(self.options.width, self.options.tab_size, self.options.thickness, backlash=self.options.backlash)) shape = self.getPath(self.toPathString(self.mm2u(tabs)), '%s_bottom' % self.options.path_id, centre[0], centre[1] + 2 * self.mm2u(self.options.thickness), None, '#00FF00') inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape)
def effect(self): print_(self.options) parent = self.current_layer centre = self.view_center tabs = self.tabs(self.options.width, self.options.tab_size, self.options.thickness, backlash=self.options.backlash * -1, lastUp=True) shape = self.getPath(self.toPathString(self.mm2u(tabs)), '%s_bottom' % self.options.path_id, centre[0], centre[1], None, '#FF0000') inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape) tabs = [[0, 0]] tabs.extend(self.tabs(self.options.width, self.options.tab_size, self.options.thickness, backlash=self.options.backlash)) shape = self.getPath(self.toPathString(self.mm2u(tabs)), '%s_bottom' % self.options.path_id, centre[0], centre[1] + 2 * self.mm2u(self.options.thickness), None, '#00FF00') inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape)
def effect(self): print_(self.options) parent = self.current_layer centre = self.view_center print_("-- %s -- %s --" % (centre[0], centre[1])) fgcolor = "#FF0000" bgcolor = None try: if(self.options.closed == 'true'): for shape in self.box_with_top(self.options.path_id, centre[0], centre[1], bgcolor, fgcolor, self.options.width, self.options.depth, self.options.height, self.options.tab_size, self.options.thickness, self.options.backlash): inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape) else: for shape in self.box_without_top(self.options.path_id, centre[0], centre[1], bgcolor, fgcolor, self.options.width, self.options.depth, self.options.height, self.options.tab_size, self.options.thickness, self.options.backlash): inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape) except BoxGenrationError as e: inkex.errormsg(e.value)
def convertToSegments(cls, path_node): path_start = None currentPoint = None # work on copy to be shure not breaking anything path = copy.deepcopy(path_node) # apply transformation info on path, otherwise dealing with transform would be a mess simpletransform.fuseTransform(path) for cmd, params in simplepath.parsePath(path.get('d')): print_('cmd, params', cmd, params) if cmd == 'M': if (path_start is None): path_start = params currentPoint = params elif cmd == 'L': yield Segment(currentPoint, params) currentPoint = params elif cmd in ['A', 'Q', 'C']: yield Segment(currentPoint, params[-2:], command=cmd, extra_parameters=params[:-2]) currentPoint = params[-2:] elif (cmd == 'Z'): # Z is a line between the last point and the start of the shape yield Segment(currentPoint, path_start) currentPoint = None path_start = None else: inkex.errormsg("Path Command %s not managed Yet" % cmd)