-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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; | ||
|
@@ -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 | ||
} | ||
|
@@ -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)); | ||
} | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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; //??? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
@@ -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()); | ||
} | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -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)) | ||
{ | ||
|
||
|
@@ -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 | ||
} | ||
|
@@ -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)); | ||
|
||
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -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(); | ||
|
||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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; | ||
|
@@ -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++) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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; | ||
|
@@ -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 | ||
} | ||
|