From 6cb9b85473366c6749bbecdcc7dc9490b48a69e8 Mon Sep 17 00:00:00 2001 From: marmni Date: Sat, 5 Mar 2016 18:07:31 +0100 Subject: [PATCH] Code update --- PCBobjects.py | 12 +- formats/eagle.py | 568 +++++++-------- formats/fidocadj.py | 651 +++++++++++------- formats/kicad_v3.py | 195 ++++-- formats/razen.py | 100 ++- script/eagle/eagle_v5/scr/freecad.scr | 3 +- script/eagle/eagle_v5/ulp/freecad-conf.ulp | 45 ++ script/eagle/eagle_v5/ulp/freecad.ulp | 32 +- script/eagle/eagle_v5/ulp/freecad_pcb.conf | 1 + script/eagle/newer_versions/scr/freecad.scr | 3 +- .../eagle/newer_versions/ulp/freecad-conf.ulp | 35 + script/eagle/newer_versions/ulp/freecad.ulp | 21 +- .../eagle/newer_versions/ulp/freecad_pcb.conf | 1 + 13 files changed, 1038 insertions(+), 629 deletions(-) create mode 100644 script/eagle/eagle_v5/ulp/freecad-conf.ulp create mode 100644 script/eagle/eagle_v5/ulp/freecad_pcb.conf create mode 100644 script/eagle/newer_versions/ulp/freecad-conf.ulp create mode 100644 script/eagle/newer_versions/ulp/freecad_pcb.conf diff --git a/PCBobjects.py b/PCBobjects.py index db587f9..dbcaa19 100644 --- a/PCBobjects.py +++ b/PCBobjects.py @@ -1210,8 +1210,8 @@ def addArc3P(self, p1, p2, p3): #def addArc_v2(self, p1, p2, curve, width=0, cap='round'): #return self.spisObiektowTXT[-1]['objects'].append(['arcV2', p1, p2, curve, width, cap]) - def addElipse(self, x, y, r1, r2): - self.spisObiektowTXT[-1]['objects'].append(['elipse', x, y, r1, r2]) + def addElipse(self, x, y, r1, r2, w=0): + self.spisObiektowTXT[-1]['objects'].append(['elipse', x, y, r1, r2, w]) ################ ################ @@ -1318,11 +1318,15 @@ def makePolygon(self, obj): y = i[2] r1 = i[3] r2 = i[4] + w = i[4] if r2 > r1: obj['rotations'].append([x, y, 90]) - - data.append(self.createElipse(x, y, r1, r2)) + + if w > 0: + data.append(self.createElipse(x, y, r1 + w / 2., r2 + w / 2.)) + else: + data.append(self.createElipse(x, y, r1, r2)) elif i[0] == 'line': x1 = i[1] y1 = i[2] diff --git a/formats/eagle.py b/formats/eagle.py index dac1983..34a4c69 100644 --- a/formats/eagle.py +++ b/formats/eagle.py @@ -165,7 +165,165 @@ def getElements(self): side = 1 # TOP self.elements.append({'name': name, 'library': library, 'package': package, 'value': value, 'x': x, 'y': y, 'locked': locked, 'smashed': smashed, 'rot': rot, 'side': side, 'attr': attribute}) - + + def getSection(self, name): + if name.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return '' + + try: + return re.findall("<{0}>(.+?)".format(name), self.projektBRD, re.MULTILINE|re.DOTALL)[0] + except: + return '' + + def getPolygons(self, section, layer): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + for i in re.findall('(.+?)' % str(lay), section, re.MULTILINE|re.DOTALL): + data.append(re.findall('', i)) + + return data + + def getRectangle(self, section, layer, m=[0,0]): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + for i in re.findall('' % str(lay), section): + x1 = float(i[0]) + y1 = float(i[1]) + x2 = float(i[2]) + y2 = float(i[3]) + + if [x1, y1] == [x2, y2]: + continue + if m[0] != 0: + x1 += m[0] + x2 += m[0] + if m[1] != 0: + y1 += m[1] + y2 += m[1] + + if i[5] == "": + rot = 0. + else: + rot = float(re.search('R([0-9,.-]*)', i[5]).groups()[0]) + + xs = x1 + (abs(x1 - x2) / 2.) + ys = y1 + (abs(y1 - x2) / 2.) + + data.append({ + 'x1': x1, + 'y1': y1, + 'x2': x2, + 'y2': y2, + 'xs': xs, + 'ys': ys, + 'rot': rot, + 'layer': lay, + }) + + return data + + def getCircles(self, section, layer, m=[0,0]): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + for i in re.findall('' % str(lay), section): + x = float(i[0]) + y = float(i[1]) + r = float(i[2]) + w = float(i[3]) + + if w == 0: + w = 0.01 + if m[0] != 0: + x += m[0] + if m[1] != 0: + y += m[1] + + data.append({ + 'x': x, + 'y': y, + 'r': r, + 'width': w, + 'layer': lay, + }) + + return data + + def getWires(self, section, layer, m=[0,0]): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + for i in re.findall('' % str(lay), section): + x1 = float(i[0]) + y1 = float(i[1]) + x2 = float(i[2]) + y2 = float(i[3]) + width = float(i[4]) + style = i[6] + + if [x1, y1] == [x2, y2]: + continue + if m[0] != 0: + x1 += m[0] + x2 += m[0] + if m[1] != 0: + y1 += m[1] + y2 += m[1] + + if i[8] == '': + curve = 0 + else: + curve = float(i[8]) + + if i[10] == '': + cap = 'round' + else: + cap = i[10] + + if width == 0: + width = 0.01 + + data.append({ + 'x1': x1, + 'y1': y1, + 'x2': x2, + 'y2': y2, + 'width': width, + 'style': style, + 'curve': curve, + 'cap': cap, + 'layer': lay, + }) + + return data + ############################## # MAIN FUNCTIONS ############################## @@ -176,69 +334,68 @@ def setProject(self, filename): def getPCB(self): PCB = [] wygenerujPada = True - dane = re.findall("(.+?)", self.projektBRD, re.MULTILINE|re.DOTALL)[0] + dane = self.getSection('plain') # - dane1 = re.findall('', dane) - for i in dane1: - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - - if i[5] == '': - PCB.append(['Line', x1, y1, x2, y2]) - else: # arc - curve = float(i[5]) - PCB.append(['Arc', x2, y2, x1, y1, curve]) - wygenerujPada = False + for i in self.getWires(dane, 20): + if not i['curve']: + PCB.append(['Line', i['x1'], i['y1'], i['x2'], i['y2']]) + else: + PCB.append(['Arc', i['x2'], i['y2'], i['x1'], i['y1'], i['curve']]) # - dane1 = re.findall('', dane) - for i in dane1: - x = float(i[0]) - y = float(i[1]) - r = float(i[2]) - - PCB.append(['Circle', x, y, r]) + for i in self.getCircles(dane, 20): + PCB.append(['Circle', i['x'], i['y'], i['r']]) + # + self.getLibraries() + self.getElements() + + for i in self.elements: + ROT = i['rot'] + ####### + #linie/luki + for j in self.getWires(self.libraries[i['library']][i['package']], 20, [i['x'], i['y']]): + [x1, y1] = self.obrocPunkt2([j['x1'], j['y1']], [i['x'], i['y']], ROT) + [x2, y2] = self.obrocPunkt2([j['x2'], j['y2']], [i['x'], i['y']], ROT) + if i['side'] == 0: + x1 = self.odbijWspolrzedne(x1, i['x']) + x2 = self.odbijWspolrzedne(x2, i['x']) + + if not j['curve']: + PCB.append(['Line', x1, y1, x2, y2]) + else: + curve = j['curve'] + if i['side'] == 0: + curve *= -1 + + PCB.append(['Arc', x2, y2, x1, y1, curve]) + #okregi + for j in self.getCircles(self.libraries[i['library']][i['package']], 20, [i['x'], i['y']]): + [x, y] = self.obrocPunkt2([j['x'], j['y']], [i['x'], i['y']], ROT) + if i['side'] == 0: + x = self.odbijWspolrzedne(x, i['x']) + + PCB.append(['Circle', x, y, j['r']]) # return [PCB, wygenerujPada] def getGlue(self, layerNumber): glue = {} - data = re.findall("(.+?)", self.projektBRD, re.MULTILINE|re.DOTALL)[0] + dane = self.getSection('plain') # line/arc - for i in re.findall(''.format(layerNumber), data): - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - width = float(i[4]) + for i in self.getWires(dane, layerNumber): - if [x1, y1] != [x2, y2]: - if not width in glue.keys(): - glue[width] = [] - - if i[8] == '': - glue[width].append(['line', x1, y1, x2, y2]) - else: - curve = float(i[8]) - - if i[10] == '': - cap = 'round' - else: - cap = i[10] - - glue[width].append(['arc', x2, y2, x1, y1, curve, cap]) - #circle - for i in re.findall(''.format(layerNumber), data): - x = float(i[0]) - y = float(i[1]) - r = float(i[2]) - width = float(i[03]) - - if not width in glue.keys(): - glue[width] = [] + if not i['width'] in glue.keys(): + glue[i['width']] = [] - glue[width].append(['circle', x, y, r]) + if not i['curve']: + glue[i['width']].append(['line', i['x1'], i['y1'], i['x2'], i['y2']]) + else: + glue[i['width']].append(['arc', i['x2'], i['y2'], i['x1'], i['y1'], i['curve'], i['cap']]) + # circle + for i in self.getCircles(dane, layerNumber): + if not i['width'] in glue.keys(): + glue[i['width']] = [] + + glue[i['width']].append(['circle', i['x'], i['y'], i['r']]) # return glue @@ -432,65 +589,19 @@ def getParts(self, koloroweElemnty, adjustParts, groupParts, partMinX, partMinY, def getConstraintAreas(self, layerNumber): areas = [] - data = re.findall("(.+?)", self.projektBRD, re.MULTILINE|re.DOTALL)[0] - #kola - for i in re.findall(''.format(layerNumber), data): - x = float(i[0]) - y = float(i[1]) - r = float(i[2]) - w = float(i[03]) - - areas.append(['circle', x, y, r, w]) - #kwadraty - for i in re.findall(''.format(layerNumber), data): - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - - if i[5] == "": - rot = 0 - else: - rot = float(re.search('R(.*)', i[5]).groups()[0]) - # - areas.append(['rect', x1, y1, x2, y2, 0, rot]) - #polygon - for i in re.findall('(.+?)'.format(layerNumber), data, re.MULTILINE|re.DOTALL): - polygonL = re.findall('', i) - - areas.append(['polygon', self.getPolygon(polygonL)]) + dane = self.getSection('plain') + # kola + for i in self.getCircles(dane, layerNumber): + areas.append(['circle', i['x'], i['y'], i['r'], i['width']]) + # kwadraty + for i in self.getRectangle(dane, layerNumber): + areas.append(['rect', i['x1'], i['y1'], i['x2'], i['y2'], 0, i['rot']]) + # polygon + for i in self.getPolygons(dane, layerNumber): + areas.append(['polygon', self.getPolygon(i)]) # return areas - #def centerDrill(self, doc, layerNumber, grp, layerName, layerColor): - #layerName = "{0}_{1}".format(layerName, layerNumber) - ##layerSide = PCBlayers[softLayers["eagle"][layerNumber][1]][0] - ##### - #dane1 = self.pobierzParametryPCB("plain", "circle", 116) - #if len(dane1): - #layerType = PCBlayers[softLayers["eagle"][layerNumber][1]][3] - - #layerS = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", layerName) - #layerNew = layerSilkObject(layerS, layerType) - ##layerNew.defHeight = defHeight - ##### - #for i in dane1: - #x = float(i.getAttribute("x")) - #y = float(i.getAttribute("y")) - #radius = float(i.getAttribute("radius")) - #width = float(i.getAttribute("width")) - - #layerNew.createObject() - #layerNew.addCircle(x, y, radius, width) - #layerNew.setFace() - ##### - #layerNew.generuj(layerS) - #layerNew.updatePosition_Z(layerS) - #viewProviderLayerSilkObject(layerS.ViewObject) - #layerS.ViewObject.ShapeColor = layerColor - #grp.addObject(layerS) - - #def getPolygons(self, layerNumber): #if layerNumber == 998: #layerNumber = 1 @@ -540,30 +651,15 @@ def getPaths(self, layerNumber): wires = [] num = 1 # - dane = re.findall("", self.projektBRD, re.MULTILINE|re.DOTALL)[0] - dane1= re.findall(''.format(layerNumber), dane) - - for i in dane1: + dane = self.getSection('signals') + # + for i in self.getWires(dane, layerNumber): signal.append([]) # - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - width = float(i[4]) - - if [x1, y1] != [x2, y2]: - if i[8] == '': - wires.append(['line', x1, y1, x2, y2, width]) - else: - curve = float(i[8]) - - if i[10] == '': - cap = 'round' - else: - cap = i[10] - - wires.append(['arc', x1, y1, x2, y2, curve, width, cap]) + if not i['curve']: + wires.append(['line', i['x1'], i['y1'], i['x2'], i['y2'], i['width']]) + else: + wires.append(['arc', i['x1'], i['y1'], i['x2'], i['y2'], i['curve'], i['width'], i['cap']]) # signal[-1].append(num) num += 1 @@ -650,35 +746,20 @@ def getPads(self, doc, layerNumber, grp, layerName, layerColor, defHeight): elif layerNumber == 18: newLayer = 16 ## - data = re.findall("(.+?)", self.projektBRD, re.MULTILINE|re.DOTALL)[0] - for i in re.findall(''.format(newLayer, layerNumber), data): - x = float(i[0]) - y = float(i[1]) - radius = float(i[2]) - width = float(i[3]) - + dane = self.getSection('plain') + # + for i in self.getCircles(dane, [newLayer, layerNumber]): layerNew.createObject() - layerNew.addCircle(x, y, diameter / 2., width) + layerNew.addCircle(i['x'], i['y'], i['r'] / 2., i['width']) layerNew.setFace() - ## - data = re.findall("(.+?)", self.projektBRD, re.MULTILINE|re.DOTALL)[0] - for i in re.findall(''.format(newLayer, layerNumber), data): - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - - dx = x1 - x2 - dy = y1 - y2 - - if i[6] != "": - rot = float(re.search('R([0-9,.-]*)', i[6]).groups()[0]) - else: - rot = 0 + # kwadraty + for i in self.getRectangle(dane, [newLayer, layerNumber]): + dx = i['x1'] - i['x2'] + dy = i['y1'] - i['y2'] layerNew.createObject() - layerNew.addRectangle(x1, y1, x2, y2) - layerNew.addRotation(x1 - (dx / 2.), y1 - (dy / 2.), rot) + layerNew.addRectangle(i['x1'], i['y1'], i['x2'], i['y2']) + layerNew.addRotation(i['x1'] - (dx / 2.), i['y1'] - (dy / 2.), i['rot']) layerNew.setFace() ##### self.getLibraries() @@ -833,143 +914,70 @@ def getSilkLayer(self, doc, layerNumber, grp, layerName, layerColor, defHeight): if i['side'] != layerSide: continue ####### - #linie/luki - for j in re.findall('', self.libraries[i['library']][i['package']]): - if int(j[5]) in szukanaWarstwa: - x1 = float(j[0]) + i['x'] - y1 = float(j[1]) + i['y'] - x2 = float(j[2]) + i['x'] - y2 = float(j[3]) + i['y'] - width = float(j[4]) - style = j[7] - - if [x1, y1] != [x2, y2]: - if j[9] == '': - layerNew.createObject() - layerNew.addLineWidth(x1, y1, x2, y2, width, style) - layerNew.addRotation(i['x'], i['y'], i['rot']) - layerNew.setChangeSide(i['x'], i['y'], i['side']) - layerNew.setFace() - else: - curve = float(j[9]) - - if j[11] == '': - cap = 'round' - else: - cap = j[11] - - layerNew.createObject() - layerNew.addArcWidth([x1, y1], [x2, y2], curve, width, cap) - layerNew.addRotation(i['x'], i['y'], i['rot']) - layerNew.setChangeSide(i['x'], i['y'], i['side']) - layerNew.setFace() - #okregi - for j in re.findall('', self.libraries[i['library']][i['package']]): - if int(j[4]) in szukanaWarstwa: - x = float(j[0]) + i['x'] - y = float(j[1]) + i['y'] - radius = float(j[2]) - width = float(j[3]) - + # linie/luki + for j in self.getWires(self.libraries[i['library']][i['package']], szukanaWarstwa, [i['x'], i['y']]): + if not j['curve']: layerNew.createObject() - layerNew.addCircle(x, y, radius, width) + layerNew.addLineWidth(j['x1'], j['y1'], j['x2'], j['y2'], j['width'], j['style']) layerNew.addRotation(i['x'], i['y'], i['rot']) layerNew.setChangeSide(i['x'], i['y'], i['side']) layerNew.setFace() - #kwadraty - for j in re.findall('', self.libraries[i['library']][i['package']]): - if int(j[4]) in szukanaWarstwa: - x1 = float(j[0]) + i['x'] - y1 = float(j[1]) + i['y'] - x2 = float(j[2]) + i['x'] - y2 = float(j[3]) + i['y'] - - xs = x1 + (abs(x1 - x2) / 2.) - ys = y1 + (abs(y1 - y2) / 2.) - - if j[6] == "": - ROT_2 = 0. - else: - ROT_2 = float(re.search('R([0-9,.-]*)', j[6]).groups()[0]) - - layerNew.createObject() - layerNew.addRectangle(x1, y1, x2, y2) - layerNew.addRotation(xs, ys, ROT_2) - layerNew.addRotation(i['x'], i['y'], i['rot']) - layerNew.setChangeSide(i['x'], i['y'], i['side']) - layerNew.setFace() - #polygon - for j in re.findall('(.+?)', self.libraries[i['library']][i['package']], re.MULTILINE|re.DOTALL): - if int(j[0]) in szukanaWarstwa: - polygonL = re.findall('', j[1]) - + else: layerNew.createObject() - layerNew.addPolygon(self.getPolygon(polygonL, i['x'], i['y'])) + layerNew.addArcWidth([j['x1'], j['y1']], [j['x2'], j['y2']], j['curve'], j['width'], j['cap']) layerNew.addRotation(i['x'], i['y'], i['rot']) layerNew.setChangeSide(i['x'], i['y'], i['side']) layerNew.setFace() + # okregi + for j in self.getCircles(self.libraries[i['library']][i['package']], szukanaWarstwa, [i['x'], i['y']]): + layerNew.createObject() + layerNew.addCircle(j['x'], j['y'], j['r'], j['width']) + layerNew.addRotation(i['x'], i['y'], i['rot']) + layerNew.setChangeSide(i['x'], i['y'], i['side']) + layerNew.setFace() + # kwadraty + for j in self.getRectangle(self.libraries[i['library']][i['package']], szukanaWarstwa, [i['x'], i['y']]): + layerNew.createObject() + layerNew.addRectangle(j['x1'], j['y1'], j['x2'], j['y2']) + layerNew.addRotation(j['xs'], j['ys'], j['rot']) + layerNew.addRotation(i['x'], i['y'], i['rot']) + layerNew.setChangeSide(i['x'], i['y'], i['side']) + layerNew.setFace() + # polygon + for j in self.getPolygons(self.libraries[i['library']][i['package']], szukanaWarstwa): + layerNew.createObject() + layerNew.addPolygon(self.getPolygon(j, i['x'], i['y'])) + layerNew.addRotation(i['x'], i['y'], i['rot']) + layerNew.setChangeSide(i['x'], i['y'], i['side']) + layerNew.setFace() ###### ###### - data = re.findall("(.+?)", self.projektBRD, re.MULTILINE|re.DOTALL)[0] - #linie/luki - for i in re.findall(''.format(layerNumber), data): - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - width = float(i[4]) - - if [x1, y1] != [x2, y2]: - if i[8] == '': - layerNew.createObject() - layerNew.addLineWidth(x1, y1, x2, y2, width) - layerNew.setFace() - else: - curve = float(i[8]) - - if i[10] == '': - cap = 'round' - else: - cap = i[10] - - layerNew.createObject() - layerNew.addArcWidth([x1, y1], [x2, y2], curve, width, cap) - layerNew.setFace() - #kola - for i in re.findall(''.format(layerNumber), data): - x = float(i[0]) - y = float(i[1]) - radius = float(i[2]) - width = float(i[03]) - + dane = self.getSection('plain') + # linie/luki + for i in self.getWires(dane, layerNumber): + if not i['curve']: + layerNew.createObject() + layerNew.addLineWidth(i['x1'], i['y1'], i['x2'], i['y2'], i['width']) + layerNew.setFace() + else: + layerNew.createObject() + layerNew.addArcWidth([i['x1'], i['y1']], [i['x2'], i['y2']], i['curve'], i['width'], i['cap']) + layerNew.setFace() + # kola + for i in self.getCircles(dane, layerNumber): layerNew.createObject() - layerNew.addCircle(x, y, radius, width) + layerNew.addCircle(i['x'], i['y'], i['r'], i['width']) layerNew.setFace() - #kwadraty - for i in re.findall(''.format(layerNumber), data): - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - - xs = x1 + (abs(x1 - x2) / 2.) - ys = y1 + (abs(y1 - y2) / 2.) - - if i[5] == "": - ROT_2 = 0. - else: - ROT_2 = float(re.search('R(.*)', i[5]).groups()[0]) - + # kwadraty + for i in self.getRectangle(dane, layerNumber): layerNew.createObject() - layerNew.addRectangle(x1, y1, x2, y2) - layerNew.addRotation(xs, ys, ROT_2) + layerNew.addRectangle(i['x1'], i['y1'], i['x2'], i['y2']) + layerNew.addRotation(i['xs'], i['ys'], i['rot']) layerNew.setFace() - #polygon - for i in re.findall('(.+?)'.format(layerNumber), data, re.MULTILINE|re.DOTALL): - polygonL = re.findall('', i) - + # polygon + for i in self.getPolygons(dane, layerNumber): layerNew.createObject() - layerNew.addPolygon(self.getPolygon(polygonL)) + layerNew.addPolygon(self.getPolygon(i)) layerNew.setFace() ####### layerNew.generuj(layerS) @@ -1054,7 +1062,7 @@ def getAnnotations(self, dane1, mode='anno'): def getDimensions(self): wymiary = [] # - data = re.findall("(.+?)", self.projektBRD, re.MULTILINE|re.DOTALL)[0] + data = self.getSection('plain') for i in re.findall('', data): x1 = float(i[0]) y1 = float(i[1]) diff --git a/formats/fidocadj.py b/formats/fidocadj.py index 66b7879..22f8354 100644 --- a/formats/fidocadj.py +++ b/formats/fidocadj.py @@ -74,6 +74,186 @@ def __init__(self, filename): self.mnoznik = 0.127 self.databaseType = "fidocadj" + def getPolygons(self, section, layer, m=[0,0], filled=False): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + if filled: + dane1 = re.findall(r'PP\s+(.+?)\s+%s\s+' % lay, section) + else: + dane1 = re.findall(r'PV\s+(.+?)\s+%s\s+' % lay, section) + + for i in dane1: + pass + + return data + + def getLines(self, section, layer, m=[0,0]): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + dane1 = re.findall(r'LI\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+%s\s+' % lay, section) + dane1 += re.findall(r'PL\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+%s\s+' % lay, section) + + for i in dane1: + if m[0] == 0: + x1 = float(i[0]) * self.mnoznik + x2 = float(i[2]) * self.mnoznik + else: + x1 = ((m[0] / 2 - 100 + float(i[0])) + m[0] / 2) * self.mnoznik + x2 = ((m[0] / 2 - 100 + float(i[2])) + m[0] / 2) * self.mnoznik + + if m[1] == 0: + y1 = float(i[1]) * self.mnoznik * (-1.) + y2 = float(i[3]) * self.mnoznik * (-1.) + else: + y1 = ((m[1] / 2 - 100 + float(i[1])) + m[1] / 2) * self.mnoznik * (-1) + y2 = ((m[1] / 2 - 100 + float(i[3])) + m[1] / 2) * self.mnoznik * (-1) + + try: + width = float(i[4]) * self.mnoznik + except: + width = 0 + + if [x1, y1] == [x2, y2]: + continue + + if width == 0: + width = 0.1 + + data.append({ + 'x1': x1, + 'y1': y1, + 'x2': x2, + 'y2': y2, + 'width': width, + 'layer': lay, + }) + + return data + + def getCircles(self, section, layer, f=[], m=[0,0], filled=False): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + if filled: + dane1 = re.findall(r'EP\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+%s\s+' % lay, section) + else: + dane1 = re.findall(r'EV\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+%s\s+' % lay, section) + + for i in dane1: + if m[0] == 0: + x1 = float(i[0]) * self.mnoznik + x2 = float(i[2]) * self.mnoznik + else: + x1 = ((m[0] / 2 - 100 + float(i[0])) + m[0] / 2) * self.mnoznik + x2 = ((m[0] / 2 - 100 + float(i[2])) + m[0] / 2) * self.mnoznik + + if m[1] == 0: + y1 = float(i[1]) * self.mnoznik * (-1) + y2 = float(i[3]) * self.mnoznik * (-1) + else: + y1 = ((m[1] / 2 - 100 + float(i[1])) + m[1] / 2) * self.mnoznik * (-1) + y2 = ((m[1] / 2 - 100 + float(i[3])) + m[1] / 2) * self.mnoznik * (-1) + + dx = float("%4.4f" % ((x1 - x2) / 2.)) + dy = float("%4.4f" % ((y1 - y2) / 2.)) + + xs = x1 + dx * (-1) + ys = y1 + dy * (-1) + r = abs(dx) + width = 0.1 + + out = {'x': xs, + 'y': ys, + 'r': r, + 'dx': abs(dx), + 'dy': abs(dy), + 'width': width, + 'layer': lay, + 'filled': filled, + } + + if abs(dx) == abs(dy): + out['type'] = 'circle' + else: + out['type'] = 'elipse' + + if 'c' in f and abs(dx) == abs(dy): # circle + data.append(out) + elif 'e' in f and abs(dx) != abs(dy): # elipse + data.append(out) + else: + data.append(out) + + return data + + def getRectangles(self, section, layer, m=[0,0], filled=False): + if section.strip() == "": + FreeCAD.Console.PrintWarning("Incorrect parameter!\n".format(e)) + return [] + + if not isinstance(layer, list): + layer = [layer] + + data = [] + for lay in layer: + if filled: + dane1 = re.findall(r'RP\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+%s\s+' % lay, section) + else: + dane1 = re.findall(r'RV\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+([-,.0-9]+)\s+%s\s+' % lay, section) + + for i in dane1: + if m[0] == 0: + x1 = float(i[0]) * self.mnoznik + x2 = float(i[2]) * self.mnoznik + else: + x1 = ((m[0] / 2 - 100 + float(i[0])) + m[0] / 2) * self.mnoznik + x2 = ((m[0] / 2 - 100 + float(i[2])) + m[0] / 2) * self.mnoznik + + if m[1] == 0: + y1 = float(i[1]) * self.mnoznik * (-1.) + y2 = float(i[3]) * self.mnoznik * (-1.) + else: + y1 = ((m[1] / 2 - 100 + float(i[1])) + m[1] / 2) * self.mnoznik * (-1) + y2 = ((m[1] / 2 - 100 + float(i[3])) + m[1] / 2) * self.mnoznik * (-1) + + if [x1, y1] == [x2, y2]: + continue + + data.append({ + 'x1': x1, + 'y1': y1, + 'x2': x2, + 'y2': y2, + 'layer': lay, + 'filled': filled, + }) + + return data + + ############################## + # MAIN FUNCTIONS + ############################## + def setProject(self, filename): self.projektBRD = __builtin__.open(filename, "r").read().replace("\r\n", "\n").replace("\r", "\n") @@ -247,19 +427,9 @@ def getPaths(self, layerNumber): wires = [] signal = [] # - dane1 = re.findall(r'PL ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([1-2]+)', self.projektBRD) - for i in dane1: - if int(i[5]) == layerNumber: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik * (-1) - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik * (-1) - width = float(i[4]) * self.mnoznik - if width == 0: - width = 0.01 - - wires.append(['line', x1, y1, x2, y2, width]) - #### + for i in self.getLines(self.projektBRD, layerNumber): + wires.append(['line', i['x1'], i['y1'], i['x2'], i['y2'], i['width']]) + # wires.append(signal) return wires @@ -343,94 +513,59 @@ def getSilkLayer(self, doc, layerNumber, grp, layerName, layerColor, defHeight): #poin.append(FreeCAD.Vector(x, y, 0.0)) #layerNew.addObject(layerNew.makeFace(layerNew.addBSpline(poin))) - # line - dane1 = re.findall(r'LI ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik * (-1) - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik * (-1) - + # lines + for i in self.getLines(self.projektBRD, 3): layerNew.createObject() - layerNew.addLineWidth(x1, y1, x2, y2, 0.1) + layerNew.addLineWidth(i['x1'], i['y1'], i['x2'], i['y2'], i['width']) layerNew.setFace() - # empty circle/elipse - dane1 = re.findall(r'EV ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik - dx = float("%4.4f" % ((x1 - x2) / 2.)) - dy = float("%4.4f" % ((y1 - y2) / 2.)) - - if abs(dx) == abs(dy): # circle - xs = x1 + dx * (-1) - ys = (y1 + dy * (-1)) * (-1) - r = abs(dx) + # circles/elipses + for i in self.getCircles(self.projektBRD, 3) + self.getCircles(self.projektBRD, 3, filled=True): + if i['filled']: + if i['type'] == 'circle': + layerNew.createObject() + layerNew.addCircle(i['x'], i['y'], i['r']) + layerNew.setFace() + else: + layerNew.createObject() + layerNew.addElipse(i['x'], i['y'], i['dx'] - i['r'] / 2., i['dy'] - i['r'] / 2.) + layerNew.setFace() + else: # empty circle + if i['type'] == 'circle': + layerNew.createObject() + layerNew.addCircle(i['x'], i['y'], i['r'], i['width']) + layerNew.setFace() + else: + pass + #layerNew.createObject() + #layerNew.addElipse(i['x'], i['y'], i['dx'], i['dy'], i['width']) + #layerNew.setFace() + # rectangles + for i in self.getRectangles(self.projektBRD, 3) + self.getRectangles(self.projektBRD, 3, filled=True): + x1 = i['x1'] + y1 = i['y1'] + x2 = i['x2'] + y2 = i['y2'] + # + if i['filled']: + layerNew.createObject() + layerNew.addRectangle(x1, y1, x2, y2) + layerNew.setFace() + else: + layerNew.createObject() + layerNew.addLineWidth(x1, y1, x2, y1, 0.1) + layerNew.setFace() layerNew.createObject() - layerNew.addCircle(xs, ys, r, 0.1) + layerNew.addLineWidth(x2, y1, x2, y2, 0.1) layerNew.setFace() - else: # elipse - pass - # filled circle/elipse - dane1 = re.findall(r'EP ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik - dx = float("%4.4f" % ((x1 - x2) / 2.)) - dy = float("%4.4f" % ((y1 - y2) / 2.)) - - xs = x1 + dx * (-1) - ys = (y1 + dy * (-1)) * (-1) - - if abs(dx) == abs(dy): - r = abs(dx) layerNew.createObject() - layerNew.addCircle(xs, ys, r) + layerNew.addLineWidth(x2, y2, x1, y2, 0.1) layerNew.setFace() - else: # elipse + layerNew.createObject() - layerNew.addElipse(xs, ys, abs(dx), abs(dy)) + layerNew.addLineWidth(x1, y2, x1, y1, 0.1) layerNew.setFace() - # empty rectangle - dane1 = re.findall(r'RV ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik * (-1) - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik * (-1) - - layerNew.createObject() - layerNew.addLineWidth(x1, y1, x2, y1, 0.1) - layerNew.setFace() - - layerNew.createObject() - layerNew.addLineWidth(x2, y1, x2, y2, 0.1) - layerNew.setFace() - - layerNew.createObject() - layerNew.addLineWidth(x2, y2, x1, y2, 0.1) - layerNew.setFace() - - layerNew.createObject() - layerNew.addLineWidth(x1, y2, x1, y1, 0.1) - layerNew.setFace() - # filled rectangle - dane1 = re.findall(r'RP ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik * (-1) - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik * (-1) - - layerNew.createObject() - layerNew.addRectangle(x1, y1, x2, y2) - layerNew.setFace() ################### elem = re.findall(r'MC ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) (.+?)\.(.*)\n', self.projektBRD) for i in elem: @@ -444,6 +579,9 @@ def getSilkLayer(self, doc, layerNumber, grp, layerName, layerColor, defHeight): warst = 1 warstWyn = 3 + if layerNumber != warstWyn: + continue + library = i[4] package = i[5] @@ -458,28 +596,27 @@ def getSilkLayer(self, doc, layerNumber, grp, layerName, layerColor, defHeight): except: continue - # line - for k in re.findall(r'LI ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', j): - if layerNumber == warstWyn: - x1 = ((X1 / 2 - 100 + float(k[0])) + X1 / 2) * self.mnoznik - y1 = ((Y1 / 2 - 100 + float(k[1])) + Y1 / 2) * self.mnoznik * (-1) - x2 = ((X1 / 2 - 100 + float(k[2])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(k[3])) + Y1 / 2) * self.mnoznik * (-1) - + # lines + for k in self.getLines(j, 3, [X1, Y1]): + layerNew.createObject() + layerNew.addLineWidth(k['x1'], k['y1'], k['x2'], k['y2'], k['width']) + layerNew.addRotation(Xr, Yr, ROT) + layerNew.setChangeSide(Xr, Yr, warst) + layerNew.setFace() + # rectangles + for k in self.getRectangles(j, 3, [X1, Y1]) + self.getRectangles(j, 3, [X1, Y1], True): + x1 = k['x1'] + y1 = k['y1'] + x2 = k['x2'] + y2 = k['y2'] + # + if k['filled']: layerNew.createObject() - layerNew.addLineWidth(x1, y1, x2, y2, 0.1) + layerNew.addRectangle(x1, y1, x2, y2) layerNew.addRotation(Xr, Yr, ROT) layerNew.setChangeSide(Xr, Yr, warst) layerNew.setFace() - ### - # empty rectangle - for k in re.findall(r'RV ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', j): - if layerNumber == warstWyn: - x1 = ((X1 / 2 - 100 + float(k[0])) + X1 / 2) * self.mnoznik - y1 = ((Y1 / 2 - 100 + float(k[1])) + Y1 / 2) * self.mnoznik * (-1) - x2 = ((X1 / 2 - 100 + float(k[2])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(k[3])) + Y1 / 2) * self.mnoznik * (-1) - + else: layerNew.createObject() layerNew.addLineWidth(x1, y1, x2, y1, 0.1) layerNew.addRotation(Xr, Yr, ROT) @@ -503,120 +640,73 @@ def getSilkLayer(self, doc, layerNumber, grp, layerName, layerColor, defHeight): layerNew.addRotation(Xr, Yr, ROT) layerNew.setChangeSide(Xr, Yr, warst) layerNew.setFace() - ## - # filled rectangle - for k in re.findall(r'RP ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', j): - if layerNumber == warstWyn: - x1 = ((X1 / 2 - 100 + float(k[0])) + X1 / 2) * self.mnoznik - y1 = ((Y1 / 2 - 100 + float(k[1])) + Y1 / 2) * self.mnoznik * (-1) - x2 = ((X1 / 2 - 100 + float(k[2])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(k[3])) + Y1 / 2) * self.mnoznik * (-1) - - layerNew.createObject() - layerNew.addRectangle(x1, y1, x2, y2) - layerNew.addRotation(Xr, Yr, ROT) - layerNew.setChangeSide(Xr, Yr, warst) - layerNew.setFace() - ## # empty polygon for l in re.findall(r'PV (.+?) 3\n', j): - if layerNumber == warstWyn: - punkty = l.split(" ") - for k in range(0, len(punkty), 2): - x1 = ((X1 / 2 - 100 + float(punkty[k])) + X1 / 2) * self.mnoznik - y1 = ((Y1 / 2 - 100 + float(punkty[k + 1])) + Y1 / 2) * self.mnoznik * (-1) - - if k + 3 > len(punkty): - x2 = ((X1 / 2 - 100 + float(punkty[0])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(punkty[1])) + Y1 / 2) * self.mnoznik * (-1) - else: - x2 = ((X1 / 2 - 100 + float(punkty[k + 2])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(punkty[k + 3])) + Y1 / 2) * self.mnoznik * (-1) - - if [x1, y1] != [x2, y2]: - layerNew.createObject() - layerNew.addLineWidth(x1, y1, x2, y2, 0.1) - layerNew.addRotation(Xr, Yr, ROT) - layerNew.setChangeSide(Xr, Yr, warst) - layerNew.setFace() - ## + punkty = l.split(" ") + for k in range(0, len(punkty), 2): + x1 = ((X1 / 2 - 100 + float(punkty[k])) + X1 / 2) * self.mnoznik + y1 = ((Y1 / 2 - 100 + float(punkty[k + 1])) + Y1 / 2) * self.mnoznik * (-1) + + if k + 3 > len(punkty): + x2 = ((X1 / 2 - 100 + float(punkty[0])) + X1 / 2) * self.mnoznik + y2 = ((Y1 / 2 - 100 + float(punkty[1])) + Y1 / 2) * self.mnoznik * (-1) + else: + x2 = ((X1 / 2 - 100 + float(punkty[k + 2])) + X1 / 2) * self.mnoznik + y2 = ((Y1 / 2 - 100 + float(punkty[k + 3])) + Y1 / 2) * self.mnoznik * (-1) + + if [x1, y1] != [x2, y2]: + layerNew.createObject() + layerNew.addLineWidth(x1, y1, x2, y2, 0.1) + layerNew.addRotation(Xr, Yr, ROT) + layerNew.setChangeSide(Xr, Yr, warst) + layerNew.setFace() # filled polygon polygonL = [] for l in re.findall(r'PP (.+?) 3\n', j): - if layerNumber == warstWyn: - punkty = l.split(" ") - for k in range(0, len(punkty), 2): - x1 = ((X1 / 2 - 100 + float(punkty[k])) + X1 / 2) * self.mnoznik - y1 = ((Y1 / 2 - 100 + float(punkty[k + 1])) + Y1 / 2) * self.mnoznik * (-1) - - if k + 3 > len(punkty): - x2 = ((X1 / 2 - 100 + float(punkty[0])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(punkty[1])) + Y1 / 2) * self.mnoznik * (-1) - else: - x2 = ((X1 / 2 - 100 + float(punkty[k + 2])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(punkty[k + 3])) + Y1 / 2) * self.mnoznik * (-1) - - if [x1, y1] != [x2, y2]: - polygonL.append(['Line', x1, y1, x2, y2]) - - layerNew.createObject() - layerNew.addPolygon(polygonL) - layerNew.addRotation(Xr, Yr, ROT) - layerNew.setChangeSide(Xr, Yr, warst) - layerNew.setFace() - ## - # empty circle/elipse - for k in re.findall(r'EV ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', j): - if layerNumber == warstWyn: - x1 = ((X1 / 2 - 100 + float(k[0])) + X1 / 2) * self.mnoznik - y1 = ((Y1 / 2 - 100 + float(k[1])) + Y1 / 2) * self.mnoznik * (-1) - x2 = ((X1 / 2 - 100 + float(k[2])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(k[3])) + Y1 / 2) * self.mnoznik * (-1) - dx = float("%4.4f" % ((x1 - x2) / 2.)) - dy = float("%4.4f" % ((y1 - y2) / 2.)) - - xs = x1 + dx * (-1) - ys = (y1 + dy * (-1)) - - if abs(dx) == abs(dy): - r = abs(dx) + punkty = l.split(" ") + for k in range(0, len(punkty), 2): + x1 = ((X1 / 2 - 100 + float(punkty[k])) + X1 / 2) * self.mnoznik + y1 = ((Y1 / 2 - 100 + float(punkty[k + 1])) + Y1 / 2) * self.mnoznik * (-1) + + if k + 3 > len(punkty): + x2 = ((X1 / 2 - 100 + float(punkty[0])) + X1 / 2) * self.mnoznik + y2 = ((Y1 / 2 - 100 + float(punkty[1])) + Y1 / 2) * self.mnoznik * (-1) + else: + x2 = ((X1 / 2 - 100 + float(punkty[k + 2])) + X1 / 2) * self.mnoznik + y2 = ((Y1 / 2 - 100 + float(punkty[k + 3])) + Y1 / 2) * self.mnoznik * (-1) + if [x1, y1] != [x2, y2]: + polygonL.append(['Line', x1, y1, x2, y2]) + + layerNew.createObject() + layerNew.addPolygon(polygonL) + layerNew.addRotation(Xr, Yr, ROT) + layerNew.setChangeSide(Xr, Yr, warst) + layerNew.setFace() + # circles/elipses + for k in self.getCircles(j, 3, m=[X1, Y1]) + self.getCircles(j, 3, m=[X1, Y1], filled=True): + if k['filled']: + if k['type'] == 'circle': layerNew.createObject() - layerNew.addCircle(xs, ys, r, 0.1) + layerNew.addCircle(k['x'], k['y'], k['r']) layerNew.addRotation(Xr, Yr, ROT) layerNew.setChangeSide(Xr, Yr, warst) layerNew.setFace() - else: - pass - ### - # filled circle/elipse - for k in re.findall(r'EP ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 3\n', j): - if layerNumber == warstWyn: - x1 = ((X1 / 2 - 100 + float(k[0])) + X1 / 2) * self.mnoznik - y1 = ((Y1 / 2 - 100 + float(k[1])) + Y1 / 2) * self.mnoznik * (-1) - x2 = ((X1 / 2 - 100 + float(k[2])) + X1 / 2) * self.mnoznik - y2 = ((Y1 / 2 - 100 + float(k[3])) + Y1 / 2) * self.mnoznik * (-1) - dx = float("%4.4f" % ((x1 - x2) / 2.)) - dy = float("%4.4f" % ((y1 - y2) / 2.)) - - xs = x1 + dx * (-1) - ys = (y1 + dy * (-1)) - - if abs(dx) == abs(dy): - r = abs(dx) - layerNew.createObject() - layerNew.addCircle(xs, ys, r) + layerNew.addElipse(k['x'], k['y'], k['dx'] - k['r'] / 2., k['dy'] - k['r'] / 2.) layerNew.addRotation(Xr, Yr, ROT) layerNew.setChangeSide(Xr, Yr, warst) layerNew.setFace() - else: # elipse + else: # empty circle + if k['type'] == 'circle': layerNew.createObject() - layerNew.addElipse(xs, ys, abs(dx), abs(dy)) + layerNew.addCircle(k['x'], k['y'], k['r'], k['width']) layerNew.addRotation(Xr, Yr, ROT) layerNew.setChangeSide(Xr, Yr, warst) layerNew.setFace() + else: + pass ##### layerNew.generuj(layerS) layerNew.updatePosition_Z(layerS) @@ -914,28 +1004,14 @@ def getPCB(self): wygenerujPada = True ### # linie - dane1 = re.findall(r'LI ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 0\n', self.projektBRD) - dane1 += re.findall(r'PL ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) .+? 0\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik * (-1.) - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik * (-1.) - - PCB.append(['Line', x1, y1, x2, y2]) - ### + for i in self.getLines(self.projektBRD, 0): + PCB.append(['Line', i['x1'], i['y1'], i['x2'], i['y2']]) # kwadraty - dane1 = re.findall(r'RV ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 0\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) * self.mnoznik - y1 = float(i[1]) * self.mnoznik * (-1.) - x2 = float(i[2]) * self.mnoznik - y2 = float(i[3]) * self.mnoznik * (-1.) - - PCB.append(['Line', x1, y1, x2, y1]) - PCB.append(['Line', x2, y1, x2, y2]) - PCB.append(['Line', x2, y2, x1, y2]) - PCB.append(['Line', x1, y2, x1, y1]) + for i in self.getRectangles(self.projektBRD, 0): + PCB.append(['Line', i['x1'], i['y1'], i['x2'], i['y1']]) + PCB.append(['Line', i['x2'], i['y1'], i['x2'], i['y2']]) + PCB.append(['Line', i['x2'], i['y2'], i['x1'], i['y2']]) + PCB.append(['Line', i['x1'], i['y2'], i['x1'], i['y1']]) # polyline dane1 = re.findall(r'PV (.+?) 0\n', self.projektBRD) for i in dane1: @@ -951,26 +1027,113 @@ def getPCB(self): else: x2 = float(punkty[j + 1][0]) * self.mnoznik y2 = float(punkty[j + 1][1]) * self.mnoznik * (-1.) - - PCB.append(['Line', x1, y1, x2, y2]) - # kola - dane1 = re.findall(r'EV ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) 0\n', self.projektBRD) - for i in dane1: - x1 = float(i[0]) - y1 = float(i[1]) - x2 = float(i[2]) - y2 = float(i[3]) - - if abs(x2 - x1) == abs(y2 - y1): - x1 *= self.mnoznik - y1 *= self.mnoznik - x2 *= self.mnoznik - y2 *= self.mnoznik - radius = abs(x2 - x1) / 2. - x = x1 + ((x2 - x1) / 2.) - y = (y1 + ((y2 - y1) / 2.)) * -1 - PCB.append(['Circle', x, y, radius]) + PCB.append(['Line', x1, y1, x2, y2]) + # kola + for i in self.getCircles(self.projektBRD, 0, f=['c']): + PCB.append(['Circle', i['x'], i['y'], i['r']]) ### + elem = re.findall(r'MC ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) (.+?)\.(.*)\n', self.projektBRD) + for i in elem: + X1 = float(i[0]) + Y1 = float(i[1]) + ROT = int(i[2]) * (-90) + if i[3] == '1': # bottom + warst = 0 + else: + warst = 1 + + library = i[4] + package = i[5] + + Xr = X1 * self.mnoznik + Yr = Y1 * self.mnoznik * (-1) + + projektLIB = self.znajdzBiblioteke(library) + if projektLIB: + try: + lib = re.search('\[{0} .+?\]\s+(.+?)\s+\['.format(package.upper()), projektLIB, re.MULTILINE|re.DOTALL).groups() + j = lib[0] + '\n' + except: + continue + + # line + for k in self.getLines(j, 0, [X1, Y1]): + [x1, y1] = self.obrocPunkt2([k['x1'], k['y1']], [Xr, Yr], ROT) + [x2, y2] = self.obrocPunkt2([k['x2'], k['y2']], [Xr, Yr], ROT) + if warst == 0: + x1 = self.odbijWspolrzedne(x1, Xr) + x2 = self.odbijWspolrzedne(x2, Xr) + + PCB.append(['Line', x1, y1, x2, y2]) + # empty rectangle + for k in self.getRectangles(j, 0, [X1, Y1]): + x1 = k['x1'] + y1 = k['y1'] + x2 = k['x2'] + y2 = k['y2'] + # + [x1R, y1R] = self.obrocPunkt2([x1, y1], [Xr, Yr], ROT) + [x2R, y2R] = self.obrocPunkt2([x2, y1], [Xr, Yr], ROT) + if warst == 0: + x1R = self.odbijWspolrzedne(x1R, Xr) + x2R = self.odbijWspolrzedne(x2R, Xr) + + PCB.append(['Line', x1R, y1R, x2R, y2R]) + # + [x1R, y1R] = self.obrocPunkt2([x2, y1], [Xr, Yr], ROT) + [x2R, y2R] = self.obrocPunkt2([x2, y2], [Xr, Yr], ROT) + if warst == 0: + x1R = self.odbijWspolrzedne(x1R, Xr) + x2R = self.odbijWspolrzedne(x2R, Xr) + + PCB.append(['Line', x1R, y1R, x2R, y2R]) + # + [x1R, y1R] = self.obrocPunkt2([x2, y2], [Xr, Yr], ROT) + [x2R, y2R] = self.obrocPunkt2([x1, y2], [Xr, Yr], ROT) + if warst == 0: + x1R = self.odbijWspolrzedne(x1R, Xr) + x2R = self.odbijWspolrzedne(x2R, Xr) + + PCB.append(['Line', x1R, y1R, x2R, y2R]) + # + [x1R, y1R] = self.obrocPunkt2([x1, y2], [Xr, Yr], ROT) + [x2R, y2R] = self.obrocPunkt2([x1, y1], [Xr, Yr], ROT) + if warst == 0: + x1R = self.odbijWspolrzedne(x1R, Xr) + x2R = self.odbijWspolrzedne(x2R, Xr) + + PCB.append(['Line', x1R, y1R, x2R, y2R]) + # empty polygon + for l in re.findall(r'PV (.+?) 0\n', j): + punkty = l.split(" ") + for k in range(0, len(punkty), 2): + x1 = ((X1 / 2 - 100 + float(punkty[k])) + X1 / 2) * self.mnoznik + y1 = ((Y1 / 2 - 100 + float(punkty[k + 1])) + Y1 / 2) * self.mnoznik * (-1) + + if k + 3 > len(punkty): + x2 = ((X1 / 2 - 100 + float(punkty[0])) + X1 / 2) * self.mnoznik + y2 = ((Y1 / 2 - 100 + float(punkty[1])) + Y1 / 2) * self.mnoznik * (-1) + else: + x2 = ((X1 / 2 - 100 + float(punkty[k + 2])) + X1 / 2) * self.mnoznik + y2 = ((Y1 / 2 - 100 + float(punkty[k + 3])) + Y1 / 2) * self.mnoznik * (-1) + + if [x1, y1] != [x2, y2]: + [x1R, y1R] = self.obrocPunkt2([x1, y1], [Xr, Yr], ROT) + [x2R, y2R] = self.obrocPunkt2([x2, y2], [Xr, Yr], ROT) + if warst == 0: + x1R = self.odbijWspolrzedne(x1R, Xr) + x2R = self.odbijWspolrzedne(x2R, Xr) + + PCB.append(['Line', x1R, y1R, x2R, y2R]) + # empty circle/elipse + for k in self.getCircles(j, 0, ['c'], [X1, Y1]): + [xs, ys] = self.obrocPunkt2([k['x'], k['y']], [Xr, Yr], ROT) + if warst == 0: + xs = self.odbijWspolrzedne(xs, Xr) + + PCB.append(['Circle', xs, ys, k['r']]) + ##### + return [PCB, wygenerujPada] diff --git a/formats/kicad_v3.py b/formats/kicad_v3.py index c368625..f34ce13 100644 --- a/formats/kicad_v3.py +++ b/formats/kicad_v3.py @@ -246,41 +246,22 @@ def getGlue(self, layerNumber): glue = {} # lines for i in self.getLine(layer, self.projektBRD, "gr_line"): - x1 = i[0] - y1 = i[1] - x2 = i[2] - y2 = i[3] - width = i[4] + if not i['width'] in glue.keys(): + glue[i['width']] = [] - if [x1, y1] != [x2, y2]: - if not width in glue.keys(): - glue[width] = [] - - glue[width].append(['line', x1, y1, x2, y2]) + glue[i['width']].append(['line', i['x1'], i['y1'], i['x2'], i['y2']]) # circles for i in self.getCircle(layer, self.projektBRD, "gr_circle"): - x = i[0] - y = i[1] - r = i[2] - width = i[3] - - if not width in glue.keys(): - glue[width] = [] + if not i['width'] in glue.keys(): + glue[i['width']] = [] - glue[width].append(['circle', x, y, r]) + glue[i['width']].append(['circle', i['x'], i['y'], i['r']]) # arcs for i in self.getArc(layer, self.projektBRD, "gr_arc"): - x1 = i[0] - y1 = i[1] - x2 = i[2] - y2 = i[3] - curve = i[4] - width = i[5] + if not i['width'] in glue.keys(): + glue[i['width']] = [] - if not width in glue.keys(): - glue[width] = [] - - glue[width].append(['arc', x2, y2, x1, y1, curve, True]) + glue[i['width']].append(['arc', i['x2'], i['y2'], i['x1'], i['y1'], i['curve'], True]) ## return glue @@ -518,7 +499,7 @@ def getHoles(self, types): #### return holes - def getLine(self, layer, source, oType): + def getLine(self, layer, source, oType, m=[0,0]): data = [] # dane1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)(\s+\(angle\s+[0-9\.-]*?\)\s+|\s+)\(layer\s+{0}\)\s+\(width\s+([0-9\.]*?)\)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL) @@ -529,11 +510,31 @@ def getLine(self, layer, source, oType): y2 = float(i[3]) * (-1) width = float(i[5]) - data.append([x1, y1, x2, y2, width]) + if [x1, y1] == [x2, y2]: + continue + if m[0] != 0: + x1 += m[0] + x2 += m[0] + if m[1] != 0: + y1 += m[1] + y2 += m[1] + + if width == 0: + width = 0.01 + + data.append({ + 'x1': x1, + 'y1': y1, + 'x2': x2, + 'y2': y2, + 'width': width, + 'layer': layer, + 'type': oType, + }) # return data - def getCircle(self, layer, source, oType): + def getCircle(self, layer, source, oType, m=[0,0]): data = [] # dane1 = re.findall(r'\({1}\s+\(center\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)\)|)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL) @@ -542,18 +543,30 @@ def getCircle(self, layer, source, oType): ys = float(i[1]) * (-1) x1 = float(i[2]) y1 = float(i[3]) * (-1) - radius = sqrt((xs - x1) ** 2 + (ys - y1) ** 2) + r = sqrt((xs - x1) ** 2 + (ys - y1) ** 2) if i[5] == '': width = 0.01 else: width = float(i[5]) - data.append([xs, ys, radius, width]) + if m[0] != 0: + xs += m[0] + if m[1] != 0: + ys += m[1] + + data.append({ + 'x': xs, + 'y': ys, + 'r': r, + 'width': width, + 'layer': layer, + 'type': oType, + }) # return data - def getArc(self, layer, source, oType): + def getArc(self, layer, source, oType, m=[0,0]): data = [] # dane1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(angle\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)\)|)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL) @@ -563,15 +576,33 @@ def getArc(self, layer, source, oType): x1 = float(i[2]) y1 = float(i[3]) curve = float(i[4]) + [x2, y2] = self.obrocPunkt2([x1, y1], [xs, ys], curve) if i[6].strip() != '': width = float(i[6]) else: width = 0 + + y1 *= -1 + y2 *= -1 - [x2, y2] = self.obrocPunkt2([x1, y1], [xs, ys], curve) + if m[0] != 0: + x1 += m[0] + x2 += m[0] + if m[1] != 0: + y1 += m[1] + y2 += m[1] - data.append([x1, y1 * (-1), x2, y2 * (-1), curve, width]) + data.append({ + 'x1': x1, + 'y1': y1, + 'x2': x2, + 'y2': y2, + 'curve': curve, + 'width': width, + 'layer': layer, + 'type': oType, + }) # return data @@ -581,14 +612,69 @@ def getPCB(self): ### # lines for i in self.getLine(self.getLayerName(self.borderLayerNumber), self.projektBRD, 'gr_line'): - PCB.append(['Line', i[0], i[1], i[2], i[3]]) + PCB.append(['Line', i['x1'], i['y1'], i['x2'], i['y2']]) # circles for i in self.getCircle(self.getLayerName(self.borderLayerNumber), self.projektBRD, 'gr_circle'): - PCB.append(['Circle', i[0], i[1], i[2]]) + PCB.append(['Circle', i['x'], i['y'], i['r']]) # arc for i in self.getArc(self.getLayerName(self.borderLayerNumber), self.projektBRD, 'gr_arc'): - PCB.append(['Arc', i[0], i[1], i[2], i[3], i[4]]) + PCB.append(['Arc', i['x1'], i['y1'], i['x2'], i['y2'], i['curve']]) wygenerujPada = False + # obj + lType = re.escape(self.getLayerName(self.borderLayerNumber)) + + for j in re.findall(r'\[start\]\(module(.+?)\)\[stop\]', self.projektBRD, re.MULTILINE|re.DOTALL): + [X1, Y1, ROT] = re.search(r'\(at\s+([0-9\.-]*?)\s+([0-9\.-]*?)(\s+[0-9\.-]*?|)\)', j).groups() + layer = re.search(r'\(layer\s+(.+?)\)', j).groups()[0] + + X1 = float(X1) + Y1 = float(Y1) * (-1) + + if ROT == '': + ROT = 0.0 + else: + ROT = float(ROT) + + if self.databaseType == "kicad": + if self.spisWarstw[layer] == 15: # top + side = 1 + else: + side = 0 + else: # eagle v4 + if self.spisWarstw[layer] == 0: # top + side = 1 + else: + side = 0 + + # line + for i in self.getLine(lType, j, 'fp_line', [X1, Y1]): + [x1, y1] = self.obrocPunkt2([i['x1'], i['y1']], [X1, Y1], ROT) + [x2, y2] = self.obrocPunkt2([i['x2'], i['y2']], [X1, Y1], ROT) + #if side == 0: + #y1 = self.odbijWspolrzedne(y1, Y1) + #y2 = self.odbijWspolrzedne(y2, Y1) + + PCB.append(['Line', x1, y1, x2, y2]) + # circle + for i in self.getCircle(lType, j, 'fp_circle', [X1, Y1]): + [x, y] = self.obrocPunkt2([i['x'], i['y']], [X1, Y1], ROT) + #if side == 0: + #y = self.odbijWspolrzedne(y, Y1) + + PCB.append(['Circle', x, y, i['r']]) + # arc + for i in self.getArc(lType, j, 'fp_arc', [X1, Y1]): + [x1, y1] = self.obrocPunkt2([i['x1'], i['y1']], [X1, Y1], ROT) + [x2, y2] = self.obrocPunkt2([i['x2'], i['y2']], [X1, Y1], ROT) + #if side == 0: + #y1 = self.odbijWspolrzedne(y1, Y1) + #y2 = self.odbijWspolrzedne(y2, Y1) + + curve = i['curve'] + #if side == 0: + #curve *= -1 + + PCB.append(['Arc', x1, y1, x2, y2, curve]) ### return [PCB, wygenerujPada] @@ -715,17 +801,17 @@ def getSilkLayer(self, doc, layerNumber, grp, layerName, layerColor, defHeight): # lines for i in self.getLine(lType, self.projektBRD, 'gr_line'): layerNew.createObject() - layerNew.addLineWidth(i[0], i[1], i[2], i[3], i[4]) + layerNew.addLineWidth(i['x1'], i['y1'], i['x2'], i['y2'], i['width']) layerNew.setFace() # circles for i in self.getCircle(lType, self.projektBRD, 'gr_circle'): layerNew.createObject() - layerNew.addCircle(i[0], i[1], i[2], i[3]) + layerNew.addCircle(i['x'], i['y'], i['r'], i['width']) layerNew.setFace() # arc for i in self.getArc(lType, self.projektBRD, 'gr_arc'): layerNew.createObject() - layerNew.addArcWidth([i[0], i[1]], [i[2], i[3]], i[4], i[5]) + layerNew.addArcWidth([i['x1'], i['y1']], [i['x2'], i['y2']], i['curve'], i['width']) layerNew.setFace() # obj for j in re.findall(r'\[start\]\(module(.+?)\)\[stop\]', self.projektBRD, re.MULTILINE|re.DOTALL): @@ -740,34 +826,21 @@ def getSilkLayer(self, doc, layerNumber, grp, layerName, layerColor, defHeight): ROT = float(ROT) # line - for i in self.getLine(lType, j, 'fp_line'): - x1 = i[0] + X1 - y1 = i[1] + Y1 - x2 = i[2] + X1 - y2 = i[3] + Y1 - + for i in self.getLine(lType, j, 'fp_line', [X1, Y1]): layerNew.createObject() - layerNew.addLineWidth(x1, y1, x2, y2, i[4]) + layerNew.addLineWidth(i['x1'], i['y1'], i['x2'], i['y2'], i['width']) layerNew.addRotation(X1, Y1, ROT) layerNew.setFace() # circle - for i in self.getCircle(lType, j, 'fp_circle'): - xs = i[0] + X1 - ys = i[1] + Y1 - + for i in self.getCircle(lType, j, 'fp_circle', [X1, Y1]): layerNew.createObject() - layerNew.addCircle(xs, ys, i[2], i[3]) + layerNew.addCircle(i['x'], i['y'], i['r'], i['width']) layerNew.addRotation(X1, Y1, ROT) layerNew.setFace() # arc - for i in self.getArc(lType, j, 'fp_arc'): - x1 = i[0] + X1 - y1 = i[1] + Y1 - x2 = i[2] + X1 - y2 = i[3] + Y1 - + for i in self.getArc(lType, j, 'fp_arc', [X1, Y1]): layerNew.createObject() - layerNew.addArcWidth([x1, y1], [x2, y2], i[4], i[5]) + layerNew.addArcWidth([i['x1'], i['y1']], [i['x2'], i['y2']], i['curve'], i['width']) layerNew.addRotation(X1, Y1, ROT) layerNew.setFace() ## diff --git a/formats/razen.py b/formats/razen.py index 17791bf..61b4ec0 100644 --- a/formats/razen.py +++ b/formats/razen.py @@ -94,13 +94,12 @@ def setProject(self, filename): except: self.fileVersion = False - def getParts(self): + def getParts(self, koloroweElemnty, adjustParts, groupParts, partMinX, partMinY, partMinZ): self.__SQL__.reloadList() - ## - PCB_EL = [] - elementy = self.projektBRD["elts"] - - for i in elementy: + # + PCB_ER = [] + # + for i in self.projektBRD["elts"]: try: if i["_t"] == "Footprint": x = self.setUnit(i['pos'][0], self.fileVersion) @@ -149,11 +148,20 @@ def getParts(self): except Exception, e: FreeCAD.Console.PrintWarning(u"{0} \n".format(e)) # - PCB_EL.append([[name, package, value, x, y, rot, side, library], EL_Name, EL_Value]) + newPart = [[name, package, value, x, y, rot, side, library], EL_Name, EL_Value] + wyn = self.addPart(newPart, koloroweElemnty, adjustParts, groupParts, partMinX, partMinY, partMinZ) + # + if wyn[0] == 'Error': # lista brakujacych elementow + partNameTXT = partNameTXT_label = self.generateNewLabel(name) + if isinstance(partNameTXT, unicode): + partNameTXT = unicodedata.normalize('NFKD', partNameTXT).encode('ascii', 'ignore') + + PCB_ER.append([partNameTXT, package, value, library]) except Exception, e: - FreeCAD.Console.PrintWarning(u"{0} \n".format(e)) + FreeCAD.Console.PrintWarning(u"Error: {0} \n".format(e)) ####### - return PCB_EL + return PCB_ER + def getAnnotations(self): adnotacje = [] @@ -575,11 +583,14 @@ def generate(self, doc, groupBRD, filename): types = {'H':self.dialogMAIN.plytkaPCB_otworyH.isChecked(), 'V':self.dialogMAIN.plytkaPCB_otworyV.isChecked(), 'P':self.dialogMAIN.plytkaPCB_otworyP.isChecked()} self.generateHoles(self.getHoles(types), doc, self.dialogMAIN.holesMin.value(), self.dialogMAIN.holesMax.value()) # + #if self.dialogMAIN.plytkaPCB_elementy.isChecked(): + #partsError = self.addParts(self.getParts(), doc, groupBRD, self.dialogMAIN.gruboscPlytki.value(), self.dialogMAIN.plytkaPCB_elementyKolory.isChecked(), self.dialogMAIN.adjustParts.isChecked(), self.dialogMAIN.plytkaPCB_grupujElementy.isChecked(), self.dialogMAIN.partMinX.value(), self.dialogMAIN.partMinY.value(), self.dialogMAIN.partMinZ.value()) + #if self.dialogMAIN.plytkaPCB_plikER.isChecked(): + #self.generateErrorReport(partsError, filename) if self.dialogMAIN.plytkaPCB_elementy.isChecked(): - partsError = self.addParts(self.getParts(), doc, groupBRD, self.dialogMAIN.gruboscPlytki.value(), self.dialogMAIN.plytkaPCB_elementyKolory.isChecked(), self.dialogMAIN.adjustParts.isChecked(), self.dialogMAIN.plytkaPCB_grupujElementy.isChecked(), self.dialogMAIN.partMinX.value(), self.dialogMAIN.partMinY.value(), self.dialogMAIN.partMinZ.value()) + partsError = self.getParts(self.dialogMAIN.plytkaPCB_elementyKolory.isChecked(), self.dialogMAIN.adjustParts.isChecked(), self.dialogMAIN.plytkaPCB_grupujElementy.isChecked(), self.dialogMAIN.partMinX.value(), self.dialogMAIN.partMinY.value(), self.dialogMAIN.partMinZ.value()) if self.dialogMAIN.plytkaPCB_plikER.isChecked(): self.generateErrorReport(partsError, filename) - # dodatkowe warstwy grp = createGroup_Layers() for i in range(self.dialogMAIN.spisWarstw.rowCount()): @@ -702,5 +713,72 @@ def getPCB(self): (x, y, r, width) = self.gerCircleParameters(i, self.fileVersion) PCB.append(['Circle', x, y, r]) + ##### + if self.dialogMAIN.razenBiblioteki != "": + for i in self.projektBRD["elts"]: + if i["_t"] == "Footprint": + if not i['mirror']: + warst = 1 # top side + else: + warst = 0 # bottom side + + library = i['lib'] + package = i['part'] + X1 = self.setUnit(i['pos'][0], self.fileVersion) # punkt wzgledem ktorego dokonany zostanie obrot + Y1 = self.setUnit(i['pos'][1], self.fileVersion) * (-1) # punkt wzgledem ktorego dokonany zostanie obrot + ROT = i['angle'] * (-1) + + lineList = self.znajdzBiblioteke(library, package) + if not lineList: + continue + + try: + fileVersion = lineList["version"] + except: + fileVersion = None + + for j in lineList["elts"]: + try: + if j["_t"] == "Segment" and j["layer"] == 20: + (x1, y1, x2, y2, width) = self.getLineParameters(j, fileVersion) + x1 += X1 + y1 += Y1 + x2 += X1 + y2 += Y1 + + [x1, y1] = self.obrocPunkt2([x1, y1], [X1, Y1], ROT) + [x2, y2] = self.obrocPunkt2([x2, y2], [X1, Y1], ROT) + if warst == 0: + x1 = self.odbijWspolrzedne(x1, X1) + x2 = self.odbijWspolrzedne(x2, X1) + + PCB.append(['Line', x1, y1, x2, y2]) + elif j["_t"] == "Arc" and j["layer"] == 20 and j["ofsa"] == j["ofsb"]: + (x, y, r, width) = self.gerCircleParameters(j, fileVersion) + + [x, y] = self.obrocPunkt2([x, y], [X1, Y1], ROT) + if warst == 0: + x = self.odbijWspolrzedne(x, X1) + + PCB.append(['Circle', x, y, r]) + elif j["_t"] == "Arc" and j["layer"] == 20: + (x1, y1, x2, y2, curve, width) = self.getArcParameters(j, fileVersion) + x1 += X1 + y1 += Y1 + x2 += X1 + y2 += Y1 + + [x1, y1] = self.obrocPunkt2([x1, y1], [X1, Y1], ROT) + [x2, y2] = self.obrocPunkt2([x2, y2], [X1, Y1], ROT) + if warst == 0: + x1 = self.odbijWspolrzedne(x1, X1) + x2 = self.odbijWspolrzedne(x2, X1) + curve *= -1 + + PCB.append(['Arc', x1, y1, x2, y2, curve]) + wygenerujPada = False + except Exception, e: + FreeCAD.Console.PrintWarning(str(e) + "1\n") + pass # return [PCB, wygenerujPada] diff --git a/script/eagle/eagle_v5/scr/freecad.scr b/script/eagle/eagle_v5/scr/freecad.scr index 8e903c6..ccdefae 100644 --- a/script/eagle/eagle_v5/scr/freecad.scr +++ b/script/eagle/eagle_v5/scr/freecad.scr @@ -1,2 +1,3 @@ BRD: -MENU '[freecad.png] Open board in FreeCAD : Run freecad.ulp;' +MENU '[freecad.png] Open board in FreeCAD : Run freecad.ulp; | \ + [icons/Change.svg] Edit parameters : Run freecad-conf.ulp;' diff --git a/script/eagle/eagle_v5/ulp/freecad-conf.ulp b/script/eagle/eagle_v5/ulp/freecad-conf.ulp new file mode 100644 index 0000000..b47a1f4 --- /dev/null +++ b/script/eagle/eagle_v5/ulp/freecad-conf.ulp @@ -0,0 +1,45 @@ +#require 5.1001 + +board(B) { + int Result = dlgDialog("Path settings") + { + string data; + int nChars = fileread(data, path_ulp[0] + '/' + "freecad_pcb.conf"); + string a[]; + int n = strsplit(a, data, '\n'); + + string programPath = a[0]; + int userSoftware = strtol(a[1]); + + dlgHBoxLayout + { + dlgGridLayout + { + dlgCell(0, 0) dlgLabel("Path"); + dlgCell(0, 1) dlgStringEdit(programPath); + dlgCell(1, 0) dlgLabel("Software"); + dlgCell(1, 1) + dlgGroup("") + { + dlgRadioButton("&Linux", userSoftware); + dlgRadioButton("&Windows", userSoftware); + + }; + dlgCell(2, 1) dlgGridLayout { + dlgCell(0, 0) dlgPushButton("+Save") + { + dlgAccept(); + fileerror(); + output(path_ulp[0] + '/' + "freecad_pcb.conf", "wt") { + printf(programPath + '\n'); + printf("%d", userSoftware); + } + if (fileerror()) + exit(1); + } + dlgCell(0, 1) dlgPushButton("-Cancel") dlgReject(); + }; + } + } + }; +} diff --git a/script/eagle/eagle_v5/ulp/freecad.ulp b/script/eagle/eagle_v5/ulp/freecad.ulp index abe3f69..7a4d351 100644 --- a/script/eagle/eagle_v5/ulp/freecad.ulp +++ b/script/eagle/eagle_v5/ulp/freecad.ulp @@ -12,15 +12,6 @@ #usage "en: Export board from Eagle v5.xx to Eagle > v6.xx\n" "marmni " - - -////////// CONFIG - string programPath_WIN = "C:/Program Files (x86)/FreeCAD/bin/FreeCAD.exe"; - string programPath_LIN = "freecad"; - string systemUzytkownika = "linux"; // windows / linux -////////// - - //**************************************************************************** // ARRAYS //**************************************************************************** @@ -582,27 +573,34 @@ void exportToXML(string filePath) if (board) { + string data; + int nChars = fileread(data, path_ulp[0] + '/' + "freecad_pcb.conf"); + string a[]; + int n = strsplit(a, data, '\n'); + string programPath = a[0]; + int systemUzytkownika = strtol(a[1]); + //string systemUzytkownika = strlwr(" " + OS_SIGNATURE); // definicja systemu operacyjnego, bez spacji na poczatku skrypt sie sypie ;) string czyPlikIstnieje[]; string filePath = ""; - if (systemUzytkownika == "windows") + if (systemUzytkownika == 1) // windows filePath = "/home/mariusz/Pulpit/eagle_to_new.brd"; - else if (systemUzytkownika == "linux") + else if (systemUzytkownika == 0) filePath = "/tmp/eagleExportToFreeCAD.brd"; /////// if (filePath != "") { exportToXML(filePath); - if (systemUzytkownika == "windows") + if (systemUzytkownika == 1) // windows { - if (fileglob(czyPlikIstnieje, programPath_WIN) > 0) - system("cmd.exe /c START \"\" \"" + programPath_WIN + "\" \"" + filePath + "\""); + if (fileglob(czyPlikIstnieje, programPath) > 0) + system("cmd.exe /c START \"\" \"" + programPath + "\" \"" + filePath + "\""); else - dlgMessageBox("File path issue, incorrect path: " + programPath_WIN); + dlgMessageBox("File path issue, incorrect path: " + programPath); } - else if (systemUzytkownika == "linux") - system("\"" + programPath_LIN + "\" \"" + filePath + "\" &"); + else if (systemUzytkownika == 0) + system("\"" + programPath + "\" \"" + filePath + "\" &"); //else // dlgMessageBox("Operating system not recognized."); } diff --git a/script/eagle/eagle_v5/ulp/freecad_pcb.conf b/script/eagle/eagle_v5/ulp/freecad_pcb.conf new file mode 100644 index 0000000..3512116 --- /dev/null +++ b/script/eagle/eagle_v5/ulp/freecad_pcb.conf @@ -0,0 +1 @@ +FreeCAD \ No newline at end of file diff --git a/script/eagle/newer_versions/scr/freecad.scr b/script/eagle/newer_versions/scr/freecad.scr index 8e903c6..ccdefae 100644 --- a/script/eagle/newer_versions/scr/freecad.scr +++ b/script/eagle/newer_versions/scr/freecad.scr @@ -1,2 +1,3 @@ BRD: -MENU '[freecad.png] Open board in FreeCAD : Run freecad.ulp;' +MENU '[freecad.png] Open board in FreeCAD : Run freecad.ulp; | \ + [icons/Change.svg] Edit parameters : Run freecad-conf.ulp;' diff --git a/script/eagle/newer_versions/ulp/freecad-conf.ulp b/script/eagle/newer_versions/ulp/freecad-conf.ulp new file mode 100644 index 0000000..31026aa --- /dev/null +++ b/script/eagle/newer_versions/ulp/freecad-conf.ulp @@ -0,0 +1,35 @@ +#require 5.1001 + +board(B) { + int Result = dlgDialog("Path settings") + { + string data; + int nChars = fileread(data, path_ulp[0] + '/' + "freecad_pcb.conf"); + string a[]; + int n = strsplit(a, data, '\n'); + + string programPath = a[0]; + + dlgHBoxLayout + { + dlgGridLayout + { + dlgCell(0, 0) dlgLabel("Path"); + dlgCell(0, 1) dlgStringEdit(programPath); + dlgCell(1, 1) dlgGridLayout { + dlgCell(0, 0) dlgPushButton("+Save") + { + dlgAccept(); + fileerror(); + output(path_ulp[0] + '/' + "freecad_pcb.conf", "wt") { + printf(programPath + '\n'); + } + if (fileerror()) + exit(1); + } + dlgCell(0, 1) dlgPushButton("-Cancel") dlgReject(); + }; + } + } + }; +} diff --git a/script/eagle/newer_versions/ulp/freecad.ulp b/script/eagle/newer_versions/ulp/freecad.ulp index 5b201e1..07ec562 100644 --- a/script/eagle/newer_versions/ulp/freecad.ulp +++ b/script/eagle/newer_versions/ulp/freecad.ulp @@ -1,11 +1,12 @@ -#require 5.1001 +#require 6.1001 board(B) { - // CONFIG - string programPath_WIN = "C:/Program Files (x86)/FreeCAD/bin/FreeCAD.exe"; - string programPath_LIN = "freecad"; - /////// - + string data; + int nChars = fileread(data, path_ulp[0] + '/' + "freecad_pcb.conf"); + string a[]; + int n = strsplit(a, data, '\n'); + string programPath = a[0]; + ////// string filePath = B.name; // sciezka do aktualnego projektu string systemUzytkownika = strlwr(" " + OS_SIGNATURE); // definicja systemu operacyjnego, bez spacji na poczatku skrypt sie sypie ;) string czyPlikIstnieje[]; @@ -14,13 +15,13 @@ board(B) { if (fileglob(czyPlikIstnieje, filePath) > 0) if (strrstr(systemUzytkownika, "window") > 0) { - if (fileglob(czyPlikIstnieje, programPath_WIN) > 0) - system("cmd.exe /c START \"\" \"" + programPath_WIN + "\" \"" + filePath + "\""); + if (fileglob(czyPlikIstnieje, programPath) > 0) + system("cmd.exe /c START \"\" \"" + programPath + "\" \"" + filePath + "\""); else - dlgMessageBox("File path issue, incorrect path: " + programPath_WIN); + dlgMessageBox("File path issue, incorrect path: " + programPath); } else if (strrstr(systemUzytkownika, "linu") > 0) - system("\"" + programPath_LIN + "\" \"" + filePath + "\" &"); + system("\"" + programPath + "\" \"" + filePath + "\" &"); else dlgMessageBox("Operating system not recognized."); else diff --git a/script/eagle/newer_versions/ulp/freecad_pcb.conf b/script/eagle/newer_versions/ulp/freecad_pcb.conf new file mode 100644 index 0000000..e9e968e --- /dev/null +++ b/script/eagle/newer_versions/ulp/freecad_pcb.conf @@ -0,0 +1 @@ +FreeCAD