예제 #1
0
    def _csp_to_satin(self, csp):
        node = deepcopy(self.node)
        d = paths.CubicSuperPath(csp).to_path()
        node.set("d", d)

        # we've already applied the transform, so get rid of it
        if node.get("transform"):
            del node.attrib["transform"]

        return SatinColumn(node)
 def getPoints(self):
     self.p1 = np.array([0., 100.])
     self.p1 = np.array([100., 100.])
     # Get variables of a selected object
     for id, node in self.svg.selected.items():
         # if it is a path:
         if node.tag == inkex.addNS('path', 'svg'):
             d = node.get('d')
             p = paths.CubicSuperPath(d)
             # p has all nodes with the anchor points in a list;
             # the rule is [anchorpoint, node, anchorpoint]
             # the points are lists with x and y coordinate
             self.p1 = np.array(p[0][0][1])
             self.p2 = np.array(p[0][-1][1])
예제 #3
0
 def effect(self):
     for node in self.selected.items():
         output_all = output_nodes = ""
         for id, node in self.selected.items():
             if node.tag == inkex.addNS('path', 'svg'):
                 output_all += ""
                 output_nodes += ""
                 node.apply_transform()
                 d = node.get('d')
                 p = paths.CubicSuperPath(d)
                 for subpath in p:
                     for csp in subpath:
                         output_nodes += str(csp[1][0]) + "\t" + str(
                             csp[1][1]) + "\n"
         sys.stderr.write(output_nodes)
    def effect(self):
        data = "(module $my_footprint$ (layer F.Cu) (tedit 6006CE23)\n" \
               " (fp_text reference REF** (at 0 0.5) (layer F.SilkS) hide\n" \
               "     (effects (font (size 1 1) (thickness 0.15)))\n" \
               " )\n" \
               " (fp_text value $my_footprint$ (at 0 -0.5) (layer F.Fab)\n" \
               "     (effects (font (size 1 1) (thickness 0.15)))\n" \
               " )\n"

        cu_layer = ""
        mask_layer = ""

        for id, node in self.selected.items():
            if node.tag == inkex.addNS('path', 'svg'):
                line = "(fp_poly\n\t(pts "
                node.apply_transform()
                d = node.get('d')
                p = paths.CubicSuperPath(d)
                for subpath in p:
                    for csp in subpath:
                        line += "(xy " + str(csp[1][0]) + " " + str(
                            csp[1][1]) + ") "

                cu_layer = line + ")\n\t(layer F.Cu) (width 0.01))\n"
                mask_layer = line + ")\n\t(layer F.Mask) (width 0.01))\n"
                data += cu_layer
                data += mask_layer
        if not self.selected.items():
            inkex.errormsg(
                _("Please select some paths. And don't forget to convert objects to paths."
                  ))
            return

        data += ")\n"
        ext = 'kicad_mod'
        ftypes = [('KiCad Footpring', '*.' + ext)]
        with filedialog.asksaveasfile(filetypes=ftypes,
                                      defaultextension=ext) as file:
            filename = os_path.splitext(os_path.basename(file.name))[0]
            file.write(data.replace("$my_footprint$", filename))
예제 #5
0
def getArea(path):
    return abs(measure.csparea(paths.CubicSuperPath(path + "z")))
예제 #6
0
    def effect(self):
        seenSegments = set()
        coordsCache = FixedRadiusSearch()

        for element in self.svg.selected.values():
            if element.tag == inkex.addNS('path','svg'):
                d = element.get('d')
                path = paths.CubicSuperPath(d).to_path().to_arrays()
                newPath = []
                start = prev = None
                pathclosed = True
                
                for i in range(0, len(path)):
                    command = path[i][0]
                    coords = path[i][1]

                    newCoords = []
                    for x, y in zip(*[iter(coords)]*2):
                        newCoords.extend(list(coordsCache.get_or_add((x, y))))
                    coords = newCoords
                    tcoords = tuple(coords)

                    if command == 'M':
                        #remove this M command and it's point, if the next dataset conaints an M command too. 
                        # Like "M 49.8584,109.276 M ..." which creates just a single point but not a valid path
                        if i+1 != len(path) and path[i][0] == path[i+1][0]: 
                            continue 
                        newPath.append([command, coords])
                        start = prev = tcoords
                        pathclosed = True
                    elif command == 'L':
                        if ('L', prev, tcoords) in seenSegments or \
                           ('L', tcoords, prev) in seenSegments:
                            newPath.append(['M', coords])
                            pathclosed = False
                        else:
                            newPath.append([command, coords])
                            seenSegments.add(('L', prev, tcoords))
                        prev = tcoords
                    elif command == 'Z':
                        if ('L', prev, start) in seenSegments or \
                           ('L', start, prev) in seenSegments:
                            newPath.append(['M', start])
                        else:
                            if pathclosed:
                                newPath.append([command, coords])
                            else:
                                newPath.append(['L', start])
                            seenSegments.add(('L', prev, start))
                        prev = start
                    elif command == 'C':
                        if ('C', prev, tcoords) in seenSegments or \
                           ('C', tcoords[4:], (tcoords[2:4], tcoords[0:2], prev)) in seenSegments:
                            newPath.append(['M', coords[4:]])
                        else:
                            newPath.append(['C', coords])
                            seenSegments.add(('C', prev, tcoords))
                        prev = tcoords[4:]                        
                    else:
                        newPath.append([command, coords])
                while len(newPath) and newPath[-1][0] == 'M':
                    newPath = newPath[:-1]
                element.set('d',str(paths.Path(newPath)))
예제 #7
0
def parsePath(d):
    return paths.CubicSuperPath(paths.Path(d))
예제 #8
0
def unCubicSuperPath(csp):
    return paths.CubicSuperPath(csp).to_path().to_arrays()
예제 #9
0
    def effect(self):
        # loop over all selected paths
        if self.options.selection == "Path_lengthselection":
            for id, node in self.svg.selected.items():
                if node.tag == inkex.addNS('path', 'svg'):
                    l1, l2, l3, l4, l5 = [], [], [], [], []
                    p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))
                    slengths = csplength(p)
                    b = [slengths, p]

                    # path length select
                    for x in range(0, len(slengths)):
                        if sum(b[0][x]) < self.options.len1:
                            l1.append(b[1][x])
                        if self.options.len2 > sum(
                                b[0][x]) >= self.options.len1:
                            l2.append(b[1][x])
                        if self.options.len3 > sum(
                                b[0][x]) >= self.options.len2:
                            l3.append(b[1][x])
                        if self.options.len4 > sum(
                                b[0][x]) >= self.options.len3:
                            l4.append(b[1][x])
                        if sum(b[0][x]) >= self.options.len4:
                            l5.append(b[1][x])

                # make path
                lensel = [l1, l2, l3, l4, l5]
                strlen = [
                    '#FF0001', '#00FF02', '#AAFF03', '#87CEE4', '#000FF5'
                ]
                for i, x in zip(strlen, lensel):
                    s = {
                        'stroke-linejoin': 'miter',
                        'stroke-width': '0.5px',
                        'stroke-opacity': '1.0',
                        'fill-opacity': '1.0',
                        'stroke': i,
                        'stroke-linecap': 'butt',
                        'fill': 'none'
                    }
                    attribs = {
                        'style':
                        str(inkex.Style(s)),
                        'd':
                        str(
                            paths.Path(
                                paths.CubicSuperPath(x).to_path().to_arrays()))
                    }
                    etree.SubElement(node.getparent(),
                                     inkex.addNS('path', 'svg'), attribs)

        if self.options.selection == "Path_slantselection":
            for id, node in self.svg.selected.items():
                if node.tag == inkex.addNS('path', 'svg'):
                    hor1, ver2, slan3 = [], [], []
                    p = paths.CubicSuperPath(inkex.paths.Path(node.get('d')))

                    # path slant select
                    for i, x in enumerate(p):
                        tn = roughBBox(x)
                        if tn < self.options.hor:
                            hor1.append(p[i])
                        elif tn > self.options.ver:
                            ver2.append(p[i])
                        else:
                            slan3.append(p[i])

                # make path
                slnsel = [hor1, ver2, slan3]
                strsln = ['#FF0001', '#00FF02', '#000FF5']
                for i, x in zip(strsln, slnsel):
                    s = {
                        'stroke-linejoin': 'miter',
                        'stroke-width': '0.5px',
                        'stroke-opacity': '1.0',
                        'fill-opacity': '1.0',
                        'stroke': i,
                        'stroke-linecap': 'butt',
                        'fill': 'none'
                    }
                    attribs = {
                        'style':
                        str(inkex.Style(s)),
                        'd':
                        str(
                            paths.Path(
                                paths.CubicSuperPath(x).to_path().to_arrays()))
                    }
                    etree.SubElement(node.getparent(),
                                     inkex.addNS('path', 'svg'), attribs)