Skip to content

Commit

Permalink
Version 1.7.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
svenhb authored Jan 24, 2024
1 parent 450e392 commit dc47a8f
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 38 deletions.
24 changes: 19 additions & 5 deletions GRBL-Plotter/GCodeCreation/Graphic2GCode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* GRBL-Plotter. Another GCode sender for GRBL.
This file is part of the GRBL-Plotter application.
Copyright (C) 2019-2023 Sven Hasemann contact: [email protected]
Copyright (C) 2019-2024 Sven Hasemann contact: [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -44,6 +44,8 @@ You should have received a copy of the GNU General Public License
* 2023-09-14 f:CreateGCode add CollectionStart /-End Tags
* 2023-11-03 l:357 f:CreateGCode (figure) add proforma figure-tag if not figureEnable
* 2023-11-27 l:465 f:ProcessPathObject call subroutine only if needed
* 2024-01-03 l:360 f:CreateGCode check if (completeGraphic.Count > 0)
* 2024-01-07 l:393 f:CreateGCode if (useToolTable) also adapt width/diameter issue #370
*/

using System;
Expand Down Expand Up @@ -286,7 +288,9 @@ internal static bool CreateGCode(List<Graphic.GroupObject> completeGraphic, List
if (Properties.Settings.Default.importGCToolDefNrUse)
toolToUse = (int)Properties.Settings.Default.importGCToolDefNr;
string toolColor = ToolTable.GetToolColor(toolToUse);
double toolWidth = ToolTable.GetToolDiameter(toolToUse); // 2024-01-07 #370
pathObject.Info.GroupAttributes[(int)GroupOption.ByColor] = toolColor;
pathObject.Info.GroupAttributes[(int)GroupOption.ByWidth] = string.Format("{0:0.000}",toolWidth); // 2024-01-07 #370
}
ProcessPathObject(pathObject, graphicInfo, -1, ""); // create Dot or Path GCode, but no tool change
}
Expand Down Expand Up @@ -352,12 +356,18 @@ internal static bool CreateGCode(List<Graphic.PathObject> completeGraphic, List<
int toolNr;
string toolName;
string toolColor;
double toolWidth;
if (completeGraphic == null) return false;

if (!graphicInfo.FigureEnable) // proforma figure tag
{
string figColor = string.Format(" PenColor=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByColor]);
string figWidth = string.Format(" PenWidth=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByWidth]);
string figColor = " PenColor=\"blue\"";
string figWidth = " PenWidth=\"0.999\"";
if (completeGraphic.Count > 0)
{
figColor = string.Format(" PenColor=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByColor]);
figWidth = string.Format(" PenWidth=\"{0}\"", completeGraphic[0].Info.GroupAttributes[(int)GroupOption.ByWidth]);
}
Gcode.Comment(gcodeString, string.Format("{0} Id=\"{1}\" {2} {3}>", XmlMarker.FigureStart, 0, figColor, figWidth));
}

Expand All @@ -379,9 +389,13 @@ internal static bool CreateGCode(List<Graphic.PathObject> completeGraphic, List<

toolName = ToolTable.GetToolName(toolToUse);
toolColor = ToolTable.GetToolColor(toolToUse); // 2021-08-26 before toolNr
toolWidth = ToolTable.GetToolDiameter(toolToUse); // 2024-01-07 #370

if (useToolTable) // 2021-08-26 #217
{
pathObject.Info.GroupAttributes[(int)GroupOption.ByColor] = toolColor;
pathObject.Info.GroupAttributes[(int)GroupOption.ByWidth] = string.Format("{0:0.000}", toolWidth); // 2024-01-07 #370
}

if (logEnable) Logger.Trace("CreateGCode2 toolNr:{0} name:{1}", toolToUse, toolName);
// add tool change after <Figure tag
Expand Down Expand Up @@ -442,7 +456,7 @@ private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInfo
}
else if (graphicInfo.OptionZFromWidth)
{
// dotCounter++;
// dotCounter++;
double newZ = CalculateZFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.OptZ);
if (logEnable) Logger.Trace("---Dot OptionZFromWidth: RangeMin:{0:0.00} RangeMax:{1:0.00} DotData.Z:{2:0.00} -> setZ:{3:0.00}", graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.OptZ, newZ);
newZ = Math.Max(origZ, newZ); // don't go deeper than set Z
Expand All @@ -451,7 +465,7 @@ private static void ProcessPathObject(PathObject pathObject, Graphic.GraphicInfo
}
if (graphicInfo.OptionSFromWidth)
{
// dotCounter++;
// dotCounter++;
double newS = CalculateSFromRange(graphicInfo.PenWidthMin, graphicInfo.PenWidthMax, DotData.OptZ);
if (logEnable) Logger.Trace("--ProcessPathObject: penWidth:{0:0.00} -> setS:{1:0.00}", DotData.OptZ, newS);
Gcode.GcodePwmDown = Gcode.GcodeSpindleSpeed = (float)newS; //???
Expand Down
3 changes: 2 additions & 1 deletion GRBL-Plotter/GCodeCreation/Graphic2GCodeRelated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,8 @@ public static void PenUp(StringBuilder gcodeValue, string cmto)
gcodeValue.AppendFormat(" {0}\r\n", comment); //(" (PU)"); // mark pen up
}

private static double lastx, lasty, lastz;
private static double lastx, lasty;
public static double lastz;
private static float lastg, lastf;
public static void SetLastxyz(double lx, double ly, double lz)
{ lastx = lx; lasty = ly; lastz = lz; }
Expand Down
32 changes: 23 additions & 9 deletions GRBL-Plotter/GCodeCreation/GraphicCollectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,30 @@ public static void CleanUp()
{
Logger.Trace("---- CleanUp() before WorkingSet: {0} kb Total Memory: {1:N0} kb", System.Environment.WorkingSet / 1024, GC.GetTotalMemory(false) / 1024);
Graphic2GCode.CleanUp();
completeGraphic = null;
finalPathList = null;
tileGraphicAll = null;
groupedGraphic = null;
headerInfo = null;
headerMessage = null;
backgroundWorker = null; // will be set by GCodeFromxxx
backgroundEvent = null;
GCode = null;
ClearList(completeGraphic); // = null;
ClearList(finalPathList); // = null;
ClearList(tileGraphicAll); // = null;
ClearList(groupedGraphic); // = null;
headerInfo.Clear(); // = null;
headerMessage.Clear(); // = null;
//backgroundWorker = null; // will be set by GCodeFromxxx
//backgroundEvent = null;
GCode.Clear(); // = null;
GC.Collect();
Logger.Trace("---- CleanUp() after WorkingSet: {0} kb Total Memory: {1:N0} kb", System.Environment.WorkingSet / 1024, GC.GetTotalMemory(true) / 1024);
}
private static void ClearList(List<PathObject> lista)
{
lista.Clear();
int identificador = GC.GetGeneration(lista);
GC.Collect(identificador, GCCollectionMode.Forced);
}
private static void ClearList(List<GroupObject> lista)
{
lista.Clear();
int identificador = GC.GetGeneration(lista);
GC.Collect(identificador, GCCollectionMode.Forced);
}

#region notifications
public static bool SizeOk()
Expand Down Expand Up @@ -700,6 +712,8 @@ public static void SetHeaderMessage(string txt)
// 1st-digit: 1-Import, 2-CollectData, 3-Gernerate GCode
// 2nd-digit: 1-SVG, 2-DXF, 3-HPGL,
if (logProperties) Logger.Trace("Set HeaderMessage '{0}'", txt);
if (headerMessage == null)
return;
if (headerMessage.Count > 0)
{
for (int i = 0; i < headerMessage.Count; i++) // don't add if already existing
Expand Down
44 changes: 30 additions & 14 deletions GRBL-Plotter/GCodeCreation/GraphicGenerateHatchFill.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* GRBL-Plotter. Another GCode sender for GRBL.
This file is part of the GRBL-Plotter application.
Copyright (C) 2015-2023 Sven Hasemann contact: [email protected]
Copyright (C) 2015-2024 Sven Hasemann contact: [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -23,11 +23,13 @@ You should have received a copy of the GNU General Public License
* 2023-01-15 line 90 bug-fix in log-output
* 2023-08-14 l:48 f: ShrinkPaths Hatch fill extension: shrink enveloping path , delete enveloping path (Vers 1.7.0.1)
* 2023-11-07 l:369 f:ClipLineByPolygone if distance is too small, delete both intersection point
* 2023-12-29 l:113 f:HatchFill do correct copy from tmpPath2 to tmpPath
*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;

namespace GrblPlotter
Expand Down Expand Up @@ -96,19 +98,23 @@ internal static void HatchFill(List<PathObject> graphicToFill)
{ Logger.Trace("no dim"); continue; }

// collect paths of same id, process if id changes
if (logModification && (index < (maxObject - 1))) Logger.Trace(" Add to PathData ID:{0} nextIsSameHatch:{1} max:{2} index:{3} id_now:{4} id_next:{5} fill:{6}", PathData.Info.Id, nextIsSameHatch, maxObject, index, graphicToFill[index].Info.Id, graphicToFill[index + 1].Info.Id, fill);
if (logModification && (index < (maxObject - 1))) Logger.Trace(" Add to PathData1 ID:{0} nextIsSameHatch:{1} max:{2} index:{3} id_now:{4} id_next:{5} fill:{6} inset2:{7} tmpPath.count:{8}", PathData.Info.Id, nextIsSameHatch, maxObject, index, graphicToFill[index].Info.Id, graphicToFill[index + 1].Info.Id, fill, inset2, tmpPath.Count);
if (nextIsSameHatch)
{
indexToDelete.Add(index);
continue;
}

//if (logModification && (index < (maxObject - 1))) Logger.Trace(" Add to PathData2 ID:{0} nextIsSameHatch:{1} max:{2} index:{3} id_now:{4} id_next:{5} fill:{6} inset2:{7} tmpPath.count:{8}", PathData.Info.Id, nextIsSameHatch, maxObject, index, graphicToFill[index].Info.Id, graphicToFill[index + 1].Info.Id, fill, inset2, tmpPath.Count);

if (inset2)
{
if (!ShrinkPaths(tmpPath, insetVal))
if (!ShrinkPaths(tmpPath, insetVal))
{
ShrinkPaths(tmpPath2, -insetVal);
tmpPath = tmpPath2; // collect paths
tmpPath.Clear();
foreach (PathObject tmp in tmpPath2)
tmpPath.Add(tmp.Copy());
}
}

Expand All @@ -122,9 +128,15 @@ internal static void HatchFill(List<PathObject> graphicToFill)

// process single hatch lines - shorten to match inside polygone
finalPattern.Clear();
//if (logModification && (index < (maxObject - 1))) Logger.Trace(" Add to PathData3 hatchPattern count:{0} tmpPath count:{1}", hatchPattern.Count, tmpPath.Count);

foreach (Point[] hatchLine in hatchPattern)
{ ClipLineByPolygone(hatchLine[0], hatchLine[1], tmpPath, finalPattern); }
{
//Logger.Trace(" 0:{0} 1:{1} ", hatchLine[0], hatchLine[1]);
ClipLineByPolygone(hatchLine[0], hatchLine[1], tmpPath, finalPattern);
}

//if (logModification && (index < (maxObject - 1))) Logger.Trace(" Add to PathData4 finalPattern count:{0} tmpPath count:{1}", finalPattern.Count, tmpPath.Count);

// add processed hatch lines to final graphic
AddLinesToGraphic(finalPattern, PathData);
Expand Down Expand Up @@ -279,7 +291,7 @@ private static void ClipLineByPolygone(Point p1, Point p2, List<PathObject> path
for (int k = 1; k < ipath.Path.Count; k++)
{
p4 = ipath.Path[k].MoveTo;
intersect = CalculateIntersection(p1, p2, p3, p4);
intersect = CalculateIntersection(p1, p2, p3, p4); // p1/p2 = hatch line, p3/p4 = part of object path return intersection 0-1 or -1 if no intersection
if ((0.0 <= intersect) && (intersect <= 1.0))
{

Expand Down Expand Up @@ -338,7 +350,7 @@ private static void ClipLineByPolygone(Point p1, Point p2, List<PathObject> path
}
else
d_and_a.Add(new IntersectionInfo(intersect, 123456.0, 123456.0));// # Mark for complete hatch excision, hatch is parallel to segment
}
}// shrink
else
d_and_a.Add(new IntersectionInfo(intersect, 0, 0));// # zero length to be removed from hatch
}
Expand All @@ -348,8 +360,9 @@ private static void ClipLineByPolygone(Point p1, Point p2, List<PathObject> path
}
//# Return now if there were no intersections
if (d_and_a.Count == 0)
{
return;

}
// d_and_a.sort() - by s
d_and_a.Sort((x, y) => x.s.CompareTo(y.s));

Expand All @@ -359,20 +372,23 @@ private static void ClipLineByPolygone(Point p1, Point p2, List<PathObject> path

for (int i=1; i < d_and_a.Count; i++)
{
//Logger.Trace(" s1:{0:0.000} slast:{1:0.000} diff:{2:0.000}", d_and_a[i].s , last.s, Math.Abs(d_and_a[i].s - last.s));
if ((Math.Abs(d_and_a[i].s - last.s)) > 0.0000000001)
{
d_and_a[i_last] = last = d_and_a[i]; // different positions - take over
i_last++;
}
else
{
d_and_a[--i_last] = last = d_and_a[i]; // same positions - skip both 2023-11-07
}
d_and_a[--i_last] = last = d_and_a[i]; // same positions - skip both 2023-11-07
}
}

d_and_a = d_and_a.GetRange(0, i_last);
d_and_a = d_and_a.GetRange(0, i_last); // correct size
if (d_and_a.Count < 2)
{
return;
}


int j = 0;
Expand All @@ -396,7 +412,7 @@ private static void ClipLineByPolygone(Point p1, Point p2, List<PathObject> path
f_length_to_be_removed_from_pt1 = d_and_a[j].s2;
f_length_to_be_removed_from_pt2 = d_and_a[j + 1].s1;
if ((f_initial_hatch_length - (f_length_to_be_removed_from_pt1 + f_length_to_be_removed_from_pt2)) <= f_min_allowed_hatch_length)
{ } // # Just don't insert it into the hatch list
{ Logger.Trace("Just don't insert"); } // # Just don't insert it into the hatch list
else
{
Point pt1 = RelativeControlPointPosition(f_length_to_be_removed_from_pt1, x2 - x1, y2 - y1, x1, y1);
Expand Down Expand Up @@ -441,7 +457,7 @@ private static Point RelativeControlPointPosition(double distance, double f_delt
private static bool ShrinkPaths(List<PathObject> paths, double distance)
{
// Check dimension before and after shrink, to decide if distance must be inverteed
Logger.Info(" ShrinkPaths count:{0} distance:{1}", paths.Count, distance);
if (logModification) Logger.Info(" ShrinkPaths count:{0} distance:{1}", paths.Count, distance);
Dimensions dimBefore = new Dimensions();
Dimensions dimAfter = new Dimensions();

Expand All @@ -453,7 +469,7 @@ private static bool ShrinkPaths(List<PathObject> paths, double distance)
}
double dx = dimBefore.dimx - dimAfter.dimx;
double dy = dimBefore.dimy - dimAfter.dimy;
Logger.Info(" ShrinkPaths dx:{0:0.00} dy:{1:0.00}", dx, dy);
if (logModification) Logger.Info(" ShrinkPaths dx:{0:0.00} dy:{1:0.00}", dx, dy);
return ((dx > 0) || (dy > 0));
}
private static void ShrinkPath(PathObject path, double distance)
Expand Down
15 changes: 14 additions & 1 deletion GRBL-Plotter/GCodeCreation/ToolTable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* GRBL-Plotter. Another GCode sender for GRBL.
This file is part of the GRBL-Plotter application.
Copyright (C) 2015-2023 Sven Hasemann contact: [email protected]
Copyright (C) 2015-2024 Sven Hasemann contact: [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
* 2022-07-29 Init add try catch
* 2023-03-03 add xmlAtrribute
* 2023-03-08 l:87 f:ToolProp add WriteAttributes ReadAttributes for XML data
* 2024-01-07 l:181 f:GetToolDiameter needed to fix issue #370
*/

using System;
Expand Down Expand Up @@ -177,6 +178,18 @@ public static string GetToolColor(int index)
return "000000"; // return black
}

public static double GetToolDiameter(int index)
{
foreach (ToolProp tool in toolTableArray)
{
if (index == tool.Toolnr)
{
return tool.Diameter;
}
}
return 1.23;
}

public static int GetIndexByToolNR(int toolNr)
{
for (int i = 0; i < toolTableArray.Count; i++)
Expand Down
18 changes: 10 additions & 8 deletions GRBL-Plotter/GCodeCreation/XmlMarker.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* GRBL-Plotter. Another GCode sender for GRBL.
This file is part of the GRBL-Plotter application.
Copyright (C) 2019-2023 Sven Hasemann contact: [email protected]
Copyright (C) 2019-2024 Sven Hasemann contact: [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -28,6 +28,7 @@ You should have received a copy of the GNU General Public License
* 2023-07-03 l:338 f:GetAttributeValue check if remaining length is enough
* 2023-07-31 new functions FindInsertPositionFigure/Group/Next
* 2023-11-15 add figurePenColorAnyCount
* 2024-01-14 l:452 f:FinishFigure change check if (tmpFigure.PenColor.Contains("none"))
*/

using System;
Expand Down Expand Up @@ -445,13 +446,14 @@ public static void FinishFigure(int lineEnd)
{
tmpFigure.LineEnd = lineEnd;
tmpFigure.MyIndex = listFigures.Count;

if (tmpFigure.PenColor != "")
figurePenColorAnyCount++;

if (tmpFigure.PenColor.Contains("none"))
figurePenColorNoneCount++;


if (!string.IsNullOrEmpty(tmpFigure.PenColor))
{
figurePenColorAnyCount++;

if (tmpFigure.PenColor.Contains("none"))
figurePenColorNoneCount++;
}
listFigures.Add(tmpFigure);
footer.LineStart = footer.LineEnd = Math.Max(footer.LineStart, lineEnd); // highest block-line = start of footer
}
Expand Down

0 comments on commit dc47a8f

Please sign in to comment.