reworked color handling to improve mapping with Lightburn layers

This commit is contained in:
suks.ae 2022-06-05 11:17:50 +02:00 committed by Florian Festi
parent afce625c42
commit ce032e323f
1 changed files with 57 additions and 8 deletions

View File

@ -2,6 +2,7 @@ import math
import datetime
from affine import Affine
from boxes.extents import Extents
from boxes.Color import Color as bColor
try:
from xml.etree import cElementTree as ET
@ -733,6 +734,17 @@ class LBRN2Surface(Surface):
'monospaced' : 'Courier New'
}
lbrn2_colors=[
0, # Colors.OUTER_CUT (BLACK) --> Lightburn C00 (black)
1, # Colors.INNER_CUT (BLUE) --> Lightburn C01 (blue)
3, # Colors.ETCHING (GREEN) --> Lightburn C02 (green)
6, # Colors.ETCHING_DEEP (CYAN) --> Lightburn C06 (cyan)
30, # Colors.ANNOTATIONS (RED) --> Lightburn T1
7, # Colors.OUTER_CUT (MAGENTA) --> Lightburn C07 (magenta)
4, # Colors.OUTER_CUT (YELLOW) --> Lightburn C04 (yellow)
8, # Colors.OUTER_CUT (WHITE) --> Lightburn C08 (grey)
]
def finish(self, inner_corners="loop"):
if self.dbg: print("LBRN2 save")
extents = self._adjust_coordinates()
@ -746,6 +758,46 @@ class LBRN2Surface(Surface):
tree = ET.ElementTree(svg)
if self.dbg: print ("8", num)
cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="3") # green layer (ETCHING)
name = ET.SubElement(cs, "name", Value="Etch")
priority = ET.SubElement(cs, "priority", Value="0") # is cut first
cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="6") # cyan layer (ETCHING_DEEP)
name = ET.SubElement(cs, "name", Value="Deep Etch")
priority = ET.SubElement(cs, "priority", Value="1") # is cut second
cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="7") # magenta layer (MAGENTA)
name = ET.SubElement(cs, "name", Value="C07")
priority = ET.SubElement(cs, "priority", Value="2") # is cut third
cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="4") # yellow layer (YELLOW)
name = ET.SubElement(cs, "name", Value="C04")
priority = ET.SubElement(cs, "priority", Value="3") # is cut third
cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="8") # grey layer (WHITE)
name = ET.SubElement(cs, "name", Value="C08")
priority = ET.SubElement(cs, "priority", Value="4") # is cut fourth
cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="1") # blue layer (INNER_CUT)
name = ET.SubElement(cs, "name", Value="Inner Cut")
priority = ET.SubElement(cs, "priority", Value="5") # is cut fifth
cs = ET.SubElement(svg, "CutSetting", Type="Cut")
index = ET.SubElement(cs, "index", Value="0") # black layer (OUTER_CUT)
name = ET.SubElement(cs, "name", Value="Outer Cut")
priority = ET.SubElement(cs, "priority", Value="6") # is cut sixth
cs = ET.SubElement(svg, "CutSetting", Type="Tool")
index = ET.SubElement(cs, "index", Value="30") # T1 layer (ANNOTATIONS)
name = ET.SubElement(cs, "name", Value="T1") # tool layer do not support names
priority = ET.SubElement(cs, "priority", Value="7") # is not cut at all
for i, part in enumerate(self.parts):
if self.dbg: print ("7", num)
@ -759,9 +811,8 @@ class LBRN2Surface(Surface):
children.tail = "\n"
for j, path in enumerate(part.pathes):
Color = 2*int(path.params["rgb"][0])+4*int(path.params["rgb"][1])+int(path.params["rgb"][2])
if Color == 4: # 4 is yellow in Lightburn
Color = 3 # use green instead
myColor = self.lbrn2_colors[4*int(path.params["rgb"][0])+2*int(path.params["rgb"][1])+int(path.params["rgb"][2])]
p = []
x, y = 0, 0
C = ""
@ -788,7 +839,7 @@ class LBRN2Surface(Surface):
C, x, y = c[0:3]
if C == "M":
if self.dbg: print ("1", num)
sh = ET.SubElement(children, "Shape", Type="Path", CutIndex=str(Color))
sh = ET.SubElement(children, "Shape", Type="Path", CutIndex=str(myColor))
sh.text = "\n "
sh.tail = "\n"
vl = ET.SubElement(sh, "VertList")
@ -852,9 +903,7 @@ class LBRN2Surface(Surface):
f = self.fonts[font]
else:
f = params.get('font', 'Arial')
fontColor = 2*int(params['rgb'][0])+4*int(params['rgb'][1])+int(params['rgb'][2])
if fontColor == 4: # 4 is yellow in Lightburn
fontColor = 3 # use green instead
fontColor = self.lbrn2_colors[4*int(params["rgb"][0])+2*int(params["rgb"][1])+int(params["rgb"][2])]
#alignment can be left|middle|end
if params.get('align', 'left')=='middle':
@ -864,7 +913,7 @@ class LBRN2Surface(Surface):
hor = '2'
else:
hor = '0'
ver = 2 # vertical is always bottom, text is shifted in box class
ver = 1 # vertical is always bottom, text is shifted in box class
pos = text.find('%')
offs = 0