/// <summary> /// process color map and generate gcode /// </summary> private void convertColorMap(float resol) { int toolNr, skipTooNr = 1; sbyte key; List <List <PointF> > outlineList;// = new List<List<Point>>(); PointF tmpP = new PointF(); float resoOutline = (float)resoDesired; string tmp = ""; int pathCount = 0; for (int index = 0; index < maxToolTableIndex; index++) // go through lists { toolTable.setIndex(index); // set index in class key = (sbyte)toolTable.indexToolNr(); // if tool-nr == known key go on if (colorMap.ContainsKey(key)) { toolNr = key; // use tool in palette order if (cbSkipToolOrder.Checked) { toolNr = skipTooNr++; // or start tool-nr at 1 } finalString.AppendLine("\r\n( +++++ Tool change +++++ )"); gcode.Tool(finalString, toolNr, toolTable.indexName()); // + svgPalette.pixelCount()); gcode.Comment(finalString, string.Format("{0} Id=\"{1}\" color=\"{2}\">", xmlMarker.figureStart, (++pathCount), toolTable.indexName())); gcode.reduceGCode = false; gcode.PenUp(finalString, " start "); // gcode.MoveToRapid(finalString, 0, 0); // move to start pos gcode.reduceGCode = true; tmp += toolTable.indexName() + "\r\n"; if (cBGCodeOutline.Checked) { int smoothCnt = (int)nUDGCodeOutlineSmooth.Value; if (!cBGCodeOutlineSmooth.Checked) { smoothCnt = 0; } outlineList = Vectorize.getPaths(resultToolNrArray, adjustedImage.Width, adjustedImage.Height, key, smoothCnt, (float)0.5 / resoOutline, cBGCodeOutlineShrink.Checked);// half pen-width in pixels int cnt = 0; float tmpY; foreach (List <PointF> path in outlineList) { if (path.Count > 0) { cnt++; tmpP = path[0]; tmpY = (adjustedImage.Height - 1) - tmpP.Y; // start point gcode.Comment(finalString, string.Format("{0} Nr=\"{1}\">", xmlMarker.contourStart, cnt)); gcode.MoveToRapid(finalString, tmpP.X * resoOutline, tmpY * resoOutline, ""); // move to start pos gcode.PenDown(finalString); // " contour "+cnt); foreach (PointF aP in path) { tmpY = (adjustedImage.Height - 1) - aP.Y; gcode.MoveTo(finalString, aP.X * resoOutline, tmpY * resoOutline); } tmpY = (adjustedImage.Height - 1) - tmpP.Y; gcode.PenUp(finalString, ""); gcode.Comment(finalString, string.Format("{0}>", xmlMarker.contourEnd)); } } shrink = 0.4f; // 0.8f; // shrink value in pixels! if (cBGCodeOutlineShrink.Checked) { shrink = resoOutline * resoFactor * 1.2f; // mm/px * factor * 1,6 } tmp += "\r\nTool Nr " + key + " Points: " + cnt + " \r\n" + Vectorize.logList.ToString(); } else { shrink = 0; } if (cBGCodeFill.Checked) { int factor = resoFactor; int start = factor / 2; // if (cBGCodeOutlineShrink.Checked) // start = factor; // if shrink, adapt start and stop posditions gcode.Comment(finalString, string.Format("{0}>", xmlMarker.fillStart)); if (shrink > 0) { int pos1, pos2, min, max, minO, maxO, center; int pxOffset = (int)(shrink / (float)resoDesired); for (int y = start; y < resultImage.Height; y += factor) // go through all lines { if (colorMap[key][y].Count > 1) { for (int k = 0; k < colorMap[key][y].Count; k += 2) { pos1 = colorMap[key][y][k]; pos2 = colorMap[key][y][k + 1]; min = Math.Min(pos1, pos2); max = Math.Max(pos1, pos2); minO = min + pxOffset; maxO = max - pxOffset; center = (min + max) / 2; if (minO < maxO) { colorMap[key][y][k] = minO; colorMap[key][y][k + 1] = maxO; } else if ((minO > max) || (maxO < min)) { colorMap[key][y][k] = -1; colorMap[key][y][k + 1] = -1; } else { colorMap[key][y][k] = center; colorMap[key][y][k + 1] = center; } } } } } for (int y = start; y < resultImage.Height; y += factor) // go through all lines { while (colorMap[key][y].Count > 1) // start at line 0 and check line by line { drawColorMap(resol, key, y, 0, true); } } gcode.Comment(finalString, string.Format("{0}>", xmlMarker.fillEnd)); } gcode.Comment(finalString, string.Format("{0}>", xmlMarker.figureEnd)); } } // System.Windows.Forms.Clipboard.SetText(tmp); }
/// <summary> /// process color map and generate gcode /// </summary> private void convertColorMap(float resol) { int toolNr, skipTooNr = 1; sbyte key; List <List <PointF> > outlineList;// = new List<List<Point>>(); PointF tmpP = new PointF(); float resoOutline = (float)resoDesired; string tmp = ""; for (int index = 0; index < maxToolTableIndex; index++) // go through lists { toolTable.setIndex(index); // set index in class key = (sbyte)toolTable.indexToolNr(); // if tool-nr == known key go on if (colorMap.ContainsKey(key)) { toolNr = key; // use tool in palette order if (cbSkipToolOrder.Checked) { toolNr = skipTooNr++; // or start tool-nr at 1 } finalString.AppendLine("\r\n( +++++ Tool change +++++ )"); gcode.Tool(finalString, toolNr, toolTable.indexName()); // + svgPalette.pixelCount()); gcode.reduceGCode = false; gcode.PenUp(finalString); gcode.MoveToRapid(finalString, 0, 0); // move to start pos gcode.reduceGCode = true; tmp += toolTable.indexName() + "\r\n"; if (cBGCodeOutline.Checked) { int smoothCnt = (int)nUDGCodeOutlineSmooth.Value; if (!cBGCodeOutlineSmooth.Checked) { smoothCnt = 0; } outlineList = Vectorize.getPaths(resultToolNrArray, adjustedImage.Width, adjustedImage.Height, key, smoothCnt); int cnt = 0; float tmpY; foreach (List <PointF> path in outlineList) { cnt++; tmpP = path[0]; tmpY = (adjustedImage.Height - 1) - tmpP.Y; // start point gcode.MoveToRapid(finalString, tmpP.X * resoOutline, tmpY * resoOutline); // move to start pos gcode.PenDown(finalString, " contour " + cnt); foreach (PointF aP in path) { tmpY = (adjustedImage.Height - 1) - aP.Y; gcode.MoveTo(finalString, aP.X * resoOutline, tmpY * resoOutline); } tmpY = (adjustedImage.Height - 1) - tmpP.Y; gcode.PenUp(finalString); } shrink = 0.8f; tmp += "\r\nTool Nr " + key + " Points: " + cnt + " \r\n" + Vectorize.logList.ToString(); } else { shrink = 0; } if (cBGCodeFill.Checked) { int factor = resoFactor; for (int y = factor / 2; y < resultImage.Height; y += factor) // go through all lines { while (colorMap[key][y].Count > 1) // start at line 0 and check line by line { drawColorMap(resol, key, y, 0, true); } } } } } // System.Windows.Forms.Clipboard.SetText(tmp); }