From db0f31054b0f644c121192fc62c7d89d4f457212 Mon Sep 17 00:00:00 2001 From: leyghisbb Date: Fri, 21 Aug 2020 12:40:38 +0200 Subject: [PATCH] Added strip line extension, fixed some inx files --- extensions/fablabchemnitz_ai_eps_output.inx | 4 +- .../fablabchemnitz_gcode_input_gcode.inx | 4 +- extensions/fablabchemnitz_gcode_input_nc.inx | 4 +- extensions/fablabchemnitz_gpx_input.inx | 4 +- extensions/fablabchemnitz_input_stl.inx | 4 +- extensions/fablabchemnitz_lyz_export.inx | 4 +- extensions/fablabchemnitz_lyz_export_zip.inx | 4 +- ...fablabchemnitz_papercraft_unfold_ascii.inx | 4 +- ...ablabchemnitz_papercraft_unfold_binary.inx | 4 +- extensions/fablabchemnitz_strip_line.inx | 18 ++ extensions/fablabchemnitz_strip_line.py | 231 ++++++++++++++++++ 11 files changed, 267 insertions(+), 18 deletions(-) create mode 100644 extensions/fablabchemnitz_strip_line.inx create mode 100644 extensions/fablabchemnitz_strip_line.py diff --git a/extensions/fablabchemnitz_ai_eps_output.inx b/extensions/fablabchemnitz_ai_eps_output.inx index 7c211542..f7352d62 100644 --- a/extensions/fablabchemnitz_ai_eps_output.inx +++ b/extensions/fablabchemnitz_ai_eps_output.inx @@ -5,8 +5,8 @@ .eps application/eps - <_filetypename>Encapsulated PostScript - AI compatible (*.eps) - <_filetypetooltip>Adobe Illustrator 7 compatible EPS + Encapsulated PostScript - AI compatible (*.eps) + Adobe Illustrator 7 compatible EPS + \ No newline at end of file diff --git a/extensions/fablabchemnitz_strip_line.py b/extensions/fablabchemnitz_strip_line.py new file mode 100644 index 00000000..a5fd2f2d --- /dev/null +++ b/extensions/fablabchemnitz_strip_line.py @@ -0,0 +1,231 @@ +#!/usr/bin/env python3 + +import math +import codecs +import inkex +from inkex.paths import Path +from geometry.Circle import Circle +from geometry.Vertex import Vertex +from geometry.Triangle import Triangle +from geometry.Plus import Plus +from geometry.Minus import Minus +from lxml import etree + +ALL=".//" + +def fixTo360(radian): + if radian <0: + return math.pi*2.0+radian + return radian + +def widenDir(start,end): + d21x = end.x - start.x; + d21y = end.y - start.y; + return fixTo360(-math.atan2(d21x, d21y)); + +def lineDir(start,end): + d21x = end.x - start.x; + d21y = end.y - start.y; + #inkex.errormsg("d21y "+str(d21y)+" d21x "+str(d21x)+" d21y/d21x"+str(d21y/d21x)) + rad=math.atan2(d21y, d21x); + #inkex.errormsg(u"Line direction"+str(math.degrees(rad))) + return fixTo360(rad) + +#radianmath.pi/2.0: #I want you to be +-90 (forward direction) + return invert(radian) + return radian + +def fixOver90(radian): + if math.fabs(radian)0: + radY=invert(radY) + + lineRad=lineDir(start,end) + + printRadian(fp,u"lineRad:",lineRad) + adjustedRad=radY + printRadian(fp,u"diffRad:",diffRad) + squareRad=lineDir(start,end) + #printRadian(u"squareRad",squareRad) + printRadian(fp,u"Drawing angle after conversion:",radY) + v.set(LEFT) + #1〜√2 I want you to be in the range + coef=(1+0.41421356237*math.fabs(math.sin(diffRad*0.5))) + fp.write("coef="+str(coef)) + v.x*=coef + v.rotate(adjustedRad) + flag = False + outVertexArray.append([start+v,flag]) + v.set(RIGHT) + v.x*=coef + v.rotate(adjustedRad) + flag = True + outVertexArray.append([start+v,flag]) + lastRad=originalRad; + lastUsedRad=adjustedRad + fp.write("\n") + #The last round + fp.write(str(i)+u"Th vertex") + adjustedRad=originalRad + printRadian(fp,u"Last drawing angle:",originalRad) + v.set(LEFT) + v.rotate(adjustedRad) + flag = False# if originalRad< 0 else False + outVertexArray.append([end+v,flag]) + v.set(RIGHT) + v.rotate(adjustedRad) + flag = True# if originalRad< 0 else False + outVertexArray.append([end+v,flag]) + fp.close() + return outVertexArray + +class StripLineEffect(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.arg_parser.add_argument("--linewidth", type=int, default="10", help="Line thickness") + self.arg_parser.add_argument("--logfilename", default="10", help="Log file name") + + def effect(self): + linewidth=self.options.linewidth + # Get the main root element SVG + svg = self.document.getroot() + pathlist=svg.findall(ALL+"{"+inkex.NSS['svg']+"}path") + + for path in pathlist: + if path == None: + inkex.errormsg("Please write the path! !") + #Get vertex coordinates of path + vals=Path(path.get('d')).to_arrays() + bone=[] + for cmd,vert in vals: + #Sometimes there is an empty, so countermeasures against it + if len(vert) != 0: + bone.append(Vertex(vert[0],vert[1])) + outVertexArray=stripline(bone,linewidth,self.options.logfilename) + + pointer=0 + for t in range(len(outVertexArray)-2): + tri=Triangle(outVertexArray[pointer][0],outVertexArray[pointer+1][0],outVertexArray[pointer+2][0]) + + stripstr=tri.toSVG() + color2="blue" + if outVertexArray[pointer][1]: + color="blue" + else: + color="red" + pointer+=1 + attributes={"points":stripstr, + "style":"fill:"+color2+";stroke:"+color2+";stroke-width:"+str(linewidth/3),"fill-opacity":"0.5"} + pth =etree.Element("polygon",attributes) + svg.append(pth) + pointer=0 + #Draw a point indicating +- + for t in range(len(outVertexArray)): + + if outVertexArray[pointer][1]: + point=Plus(outVertexArray[pointer][0].x,outVertexArray[pointer][0].y,linewidth/3) + color="blue" + else: + point=Minus(outVertexArray[pointer][0].x,outVertexArray[pointer][0].y,linewidth/3) + color="red" + if pointer==0: + color="#6f0018"#Dark red + point.appendToSVG(color,svg) + #svg.append(Circle.toSVG(outVertexArray[pointer][0].x,outVertexArray[pointer][0].y,linewidth/3,color,0)) + pointer+=1 + pointer=0 + pathstr="M " + for t in range(len(outVertexArray)): + pathstr+=str(outVertexArray[pointer][0].x)+" "+str(outVertexArray[pointer][0].y)+" " + pointer+=1 + + att3={"d":pathstr,"r":"1","fill":"none","stroke-width":"1","stroke":"white"} + pt=etree.Element("path",att3) + +StripLineEffect().run() \ No newline at end of file