def __init__(self, cutter):
        self.cutter = cutter

        while str(self.cutter).endswith(".cf2"):
            #pass
            self.cutter = self.cutter[:-4]
        else:
            path = options.opt_dir()
            if not (path.endswith('/') or path.endswith('\\')):
                path = path + '/'
            #dir_list = []
            #dir_list.append(path)
            #dir_list.append(self.cutter)
            #dir_list.append(self.ext)
            #dir = ''.join(dir_list)
            #print type(path)
            #dir = path + str(self.cutter) + self.ext
            dir = os.path.join(path, (self.cutter).decode('utf8') +
                               (self.ext).decode('utf8'))
            f = open(dir, 'r')
            file_contents = f.read()
            f.close()
            for line in file_contents.splitlines():
                #Atribuição de UR1 e UR2
                if line.startswith('UR,'):
                    UR1, UR2 = ''.join(line.split(',')[1]), ''.join(
                        line.split(',')[2])
                    UR1, UR2 = round(float(UR1)), round(float(UR2))
                    UR1, UR2 = int(UR1), int(UR2)
                #Atribuição de LL1 e LL2
                elif line.startswith('LL,'):
                    LL1, LL2 = ''.join(line.split(',')[1]), ''.join(
                        line.split(',')[2])
                    LL1, LL2 = round(float(LL1)), round(float(LL2))
                    LL1, LL2 = int(LL1), int(LL2)
            if abs(LL1) == 0:
                self.width = UR1
            if abs(LL2) == 0:
                self.height = UR2
            if LL1 < 0:
                if UR1 > LL1:
                    self.width = abs(LL1) + abs(UR1)
                    self.width -= 1
            if LL1 > 0:
                if UR1 > LL1:
                    self.width = UR1 - LL1
            if LL2 < 0:
                if UR2 > LL2:
                    self.height = abs(LL2) + abs(UR2)
                    self.height -= 1
            if LL2 > 0:
                if UR2 > LL2:
                    self.height = UR2 - LL2
            if self.width == 0 or self.height == 0:
                return "ERROR, 0"
    def __init__(self, cutter):
        self.cutter = cutter

        while str(self.cutter).endswith(".cf2"):
            #pass
            self.cutter = self.cutter[:-4]
        else:
            path = options.opt_dir()
            if not (path.endswith('/') or path.endswith('\\')):
                path = path + '/'
            #dir_list = []
            #dir_list.append(path)
            #dir_list.append(self.cutter)
            #dir_list.append(self.ext)
            #dir = ''.join(dir_list)
            #print type(path)
            #dir = path + str(self.cutter) + self.ext
            dir = os.path.join(path, (self.cutter).decode('utf8') + (self.ext).decode('utf8'))
            f = open(dir, 'r')
            file_contents = f.read()
            f.close()
            for line in file_contents.splitlines():
                #Atribuição de UR1 e UR2
                if line.startswith('UR,'):
                    UR1,UR2 = ''.join(line.split(',')[1]),''.join(line.split(',')[2])
                    UR1,UR2 = round(float(UR1)),round(float(UR2))
                    UR1,UR2 = int(UR1),int(UR2)
                #Atribuição de LL1 e LL2
                elif line.startswith('LL,'):
                    LL1,LL2 = ''.join(line.split(',')[1]),''.join(line.split(',')[2])
                    LL1,LL2 = round(float(LL1)),round(float(LL2))
                    LL1,LL2 = int(LL1),int(LL2)
            if abs(LL1) == 0:
                self.width = UR1
            if abs(LL2) == 0:
                self.height = UR2
            if LL1 < 0:
                if UR1 > LL1:
                    self.width = abs(LL1) + abs(UR1)
                    self.width -= 1
            if LL1 > 0:
                if UR1 > LL1:
                    self.width = UR1 - LL1
            if LL2 < 0:
                if UR2 > LL2:
                    self.height = abs(LL2) + abs(UR2)
                    self.height -= 1
            if LL2 > 0:
                if UR2 > LL2:
                    self.height = UR2 - LL2
            if self.width == 0 or self.height == 0:
                return "ERROR, 0"
示例#3
0
def list_cf2(cf2):
    path = options.opt_dir()
    if not (path.endswith('/') or path.endswith('\\')):
        path = path + '/'
    path_cf2 = []
    if cf2 == "*":
        for item in os.listdir(path):
            if item.endswith(".cf2"):
                path_cf2.append(item)
        for item in path_cf2:
            cutter = Cf2(str(item))
            print cutter
    else:
        cutter = Cf2(cf2)
        print cutter
示例#4
0
    def __init__(self, cutter):
        self.cutter = cutter

        while str(self.cutter).endswith(".cf2"):
            # pass
            self.cutter = self.cutter[:-4]
        else:
            path = os.path.normpath(str(options.opt_dir()))
            dir = os.path.join(path, self.cutter + self.ext)

        f = open(dir, 'r')
        file_contents = f.read()
        f.close()
        for line in file_contents.splitlines():

            if line.startswith('UR,'):
                UR1, UR2 = ''.join(line.split(',')[1]), ''.join(
                    line.split(',')[2])
                UR1, UR2 = float(UR1), float(UR2)
            elif line.startswith('LL,'):
                LL1, LL2 = ''.join(line.split(',')[1]), ''.join(
                    line.split(',')[2])
                LL1, LL2 = float(LL1), float(LL2)
        if abs(LL1) == 0:
            self.width = UR1
        if abs(LL2) == 0:
            self.height = UR2
        if LL1 < 0:
            if UR1 > LL1:
                self.width = abs(LL1) + abs(UR1)
        if LL1 > 0:
            if UR1 > LL1:
                self.width = UR1 - LL1
        if LL2 < 0:
            if UR2 > LL2:
                self.height = abs(LL2) + abs(UR2)
        if LL2 > 0:
            if UR2 > LL2:
                self.height = UR2 - LL2
        if self.width == 0 or self.height == 0:
            return "ERROR, 0"
        """Create SVG file"""
        svg_size_w = self.width * mm
        svg_size_h = self.height * mm
        colors = ['grey', 'black', 'red', 'green', 'blue']
        dwg = Drawing(self.cutter + '.svg',
                      size=(svg_size_w, svg_size_h),
                      profile='full')
        defs_OnUP = Defs(id='defs_t')
        symbol_t = Symbol(id='OneUP')

        block_driwing = []
        START, END = 'SUB', 'END'
        inblock = False
        for line in fileinput.input(files=dir, mode='r'):
            line = line.rstrip()
            if inblock:
                if END in line:
                    inblock = False
                else:
                    # print(line)
                    line = line.split(',')
                    line_type = int(line[2])
                    stroke_width = 5
                    '''
                    linetype (cut/erese/perf/dim/bleed) = color line
                    '''
                    if line[0] == 'L':
                        v1 = float(line[4]) * self.coef
                        '''start X'''
                        v2 = float(line[5]) * self.coef
                        '''start Y'''
                        v3 = float(line[6]) * self.coef
                        '''End X'''
                        v4 = float(line[7]) * self.coef
                        '''End Y'''
                        symbol_t.add((Line(start=(v1, v2),
                                           end=(v3, v4),
                                           stroke=colors[line_type],
                                           stroke_width=stroke_width)))
                        # symbol_t.add(dwg.line(start=(v1, v2),
                        #                       end=(v3, v4), stroke="red", stroke_width="5"))
                    elif line[0] == 'A':
                        v1 = float(line[4]) * self.coef
                        '''start X'''
                        v2 = float(line[5]) * self.coef
                        '''start Y'''
                        v3 = float(line[6]) * self.coef
                        '''End X'''
                        v4 = float(line[7]) * self.coef
                        '''End Y'''
                        v5 = float(line[8]) * self.coef
                        '''Centre X'''
                        v6 = float(line[9]) * self.coef
                        '''Centre Y'''
                        dirc = str(line[10])
                        '''Direction of rotation'''
                        auxLT = line[3]
                        '''Auxillery line type   - the common file auxiliary linetype'''
                        radius = self.find_radius(v1, v2, v5, v6)
                        if '+' in dirc:
                            dirc = 1
                        else:
                            dirc = 0

                        if (v1 == v3) and (v2 == v4):
                            symbol_t.add(
                                Circle(center=(v5, v6),
                                       r=radius,
                                       fill="none",
                                       stroke=colors[line_type],
                                       stroke_width=stroke_width))
                        else:
                            dd = f"M{v1},{v2}A{radius},{radius},1,0,{dirc},{v3},{v4}"
                            # print(str(dd))
                            w = dwg.path(d=str(dd),
                                         fill="none",
                                         stroke=colors[line_type],
                                         stroke_width=stroke_width)
                            symbol_t.add(w)
                    elif line[0] == 'T':
                        print('TEXT')

            elif START in line:  # not in block
                print(line)
                inblock = True
        print(' /////// ')

        defs_OnUP.add(symbol_t)
        dwg.add(defs_OnUP)
        dwg.add(Use(href='#OneUP', insert=(5 * mm, 5 * mm)))
        dwg.save()
示例#5
0
def main():
    list_cf2(os.path.normpath(str(options.opt_dir())))