diff --git a/AutoPanelBuilder/AutoPanelBuilder.cs b/AutoPanelBuilder/AutoPanelBuilder.cs
index d8cf331..ffc0007 100644
--- a/AutoPanelBuilder/AutoPanelBuilder.cs
+++ b/AutoPanelBuilder/AutoPanelBuilder.cs
@@ -1,4 +1,5 @@
-using GerberLibrary.Core.Primitives;
+using GerberLibrary;
+using GerberLibrary.Core.Primitives;
using System;
using System.Collections.Generic;
using System.IO;
@@ -103,7 +104,7 @@ static void Main(string[] args)
{
foreach (var a in File.ReadAllLines(InputFile))
{
- var A = GP.AddGerberFolder(a);
+ var A = GP.AddGerberFolder(new StandardConsoleLog(), a);
GP.AddInstance(a, new GerberLibrary.Core.Primitives.PointD(0, 0));
}
}
@@ -122,7 +123,7 @@ static void Main(string[] args)
GerberLibrary.GerberArtWriter GAW2 = new GerberLibrary.GerberArtWriter();
GerberLibrary.GerberArtWriter GAW = new GerberLibrary.GerberArtWriter();
- GP.BuildAutoTabs(GAW, GAW2);
+ GP.BuildAutoTabs(new StandardConsoleLog(), GAW, GAW2);
string basepath = args[args.Count() - 1];
diff --git a/DirtyPCBs/DirtyPCB_BoardStats/DirtyPCB_BoardStats.cs b/DirtyPCBs/DirtyPCB_BoardStats/DirtyPCB_BoardStats.cs
index 6fe8661..c2c082e 100644
--- a/DirtyPCBs/DirtyPCB_BoardStats/DirtyPCB_BoardStats.cs
+++ b/DirtyPCBs/DirtyPCB_BoardStats/DirtyPCB_BoardStats.cs
@@ -6,6 +6,7 @@
using System.IO;
using Ionic.Zip;
using System.Web.Script.Serialization;
+using GerberLibrary;
namespace DirtyPCB_BoardStats
{
@@ -95,7 +96,7 @@ public void AddFile(GerberLibrary.ProgressLog log, MemoryStream L, string filena
if (Layer == GerberLibrary.Core.BoardLayer.Outline || Layer == GerberLibrary.Core.BoardLayer.Mill)
{
L.Seek(0, SeekOrigin.Begin);
- var G = GerberLibrary.PolyLineSet.LoadGerberFileFromStream(new StreamReader(L), filename);
+ var G = GerberLibrary.PolyLineSet.LoadGerberFileFromStream(new StandardConsoleLog(), new StreamReader(L), filename);
Box.AddBox(G.BoundingBox);
}
}
@@ -124,7 +125,7 @@ public void AddFile(GerberLibrary.ProgressLog log, string L)
GerberLibrary.Gerber.DetermineBoardSideAndLayer(L, out Side, out Layer);
if (Layer == GerberLibrary.Core.BoardLayer.Outline || Layer == GerberLibrary.Core.BoardLayer.Mill)
{
- var G = GerberLibrary.PolyLineSet.LoadGerberFile(L);
+ var G = GerberLibrary.PolyLineSet.LoadGerberFile(log, L);
Box.AddBox(G.BoundingBox);
}
}
diff --git a/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMerge.csproj b/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMerge.csproj
index 872c259..c4012a3 100644
--- a/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMerge.csproj
+++ b/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMerge.csproj
@@ -28,7 +28,7 @@
AnyCPU
pdbonly
true
- bin\Release\
+ ..\Build\BMPGerberMerger\
TRACE
prompt
4
diff --git a/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMergeForm.cs b/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMergeForm.cs
index 0dd7f4b..9d3a930 100644
--- a/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMergeForm.cs
+++ b/FitBitmapToOutlineAndMerge/FitBitmapToOutlineAndMergeForm.cs
@@ -80,7 +80,7 @@ void DoThread()
string OutlineFile = OutlineFileBox.Text;
ParsedGerber PLS = null;
- PLS = PolyLineSet.LoadGerberFile(OutlineFile);
+ PLS = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), OutlineFile);
string SilkFile = SilkFileTopBox.Text;
string BitmapFile = BitmapFileTopBox.Text;
@@ -186,7 +186,7 @@ private void OutlineFileBox_TextChanged(object sender, EventArgs e)
{
return;
}
- PLS = PolyLineSet.LoadGerberFile(OutlineFile);
+ PLS = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), OutlineFile);
sizebox.Text = String.Format("{0}x{1}mm", PLS.BoundingBox.Width(), PLS.BoundingBox.Height());
diff --git a/FrontPanelBuilder/FrontPanelBuilder.cs b/FrontPanelBuilder/FrontPanelBuilder.cs
index d8dfa6a..fc8861a 100644
--- a/FrontPanelBuilder/FrontPanelBuilder.cs
+++ b/FrontPanelBuilder/FrontPanelBuilder.cs
@@ -81,7 +81,7 @@ private static void ConvertFile(string a, bool back)
string f = basename + ".gko";
if (System.IO.File.Exists(f))
{
- PLS = PolyLineSet.LoadGerberFile(f);
+ PLS = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), f);
string bottomcopper = basename + "/bottomcopper.gbl";
diff --git a/GerberAnalyse/GerberAnalyse.cs b/GerberAnalyse/GerberAnalyse.cs
index c504905..8f00748 100644
--- a/GerberAnalyse/GerberAnalyse.cs
+++ b/GerberAnalyse/GerberAnalyse.cs
@@ -199,7 +199,7 @@ public void AddFile(ProgressLog log, MemoryStream L, string filename)
if (Layer == GerberLibrary.Core.BoardLayer.Outline || Layer == GerberLibrary.Core.BoardLayer.Mill)
{
L.Seek(0, SeekOrigin.Begin);
- var G = GerberLibrary.PolyLineSet.LoadGerberFileFromStream(new StreamReader(L), filename);
+ var G = GerberLibrary.PolyLineSet.LoadGerberFileFromStream(new StandardConsoleLog(), new StreamReader(L), filename);
Box.AddBox(G.BoundingBox);
}
}
@@ -228,12 +228,12 @@ public void AddFile(ProgressLog log, string L)
GerberLibrary.Gerber.DetermineBoardSideAndLayer(L, out Side, out Layer);
if (Layer == GerberLibrary.Core.BoardLayer.Outline || Layer == GerberLibrary.Core.BoardLayer.Mill)
{
- var G = GerberLibrary.PolyLineSet.LoadGerberFile(L);
+ var G = GerberLibrary.PolyLineSet.LoadGerberFile(log, L);
Box.AddBox(G.BoundingBox);
}
else
{
- var G = GerberLibrary.PolyLineSet.LoadGerberFile(L);
+ var G = GerberLibrary.PolyLineSet.LoadGerberFile(log, L);
}
}
break;
diff --git a/GerberLibrary/Artwork Related/FontSet.cs b/GerberLibrary/Artwork Related/FontSet.cs
index 2b51296..8be0cff 100644
--- a/GerberLibrary/Artwork Related/FontSet.cs
+++ b/GerberLibrary/Artwork Related/FontSet.cs
@@ -81,7 +81,26 @@ public void Write(string p)
writer.Close();
}
+ public double StringWidth(string text, double size= 1.0)
+ {
+ double W = 0;
+ double Scaler = size / CapsHeight; ;
+ for (int i = 0; i < text.Length; i++)
+ {
+ char t = text[i];
+ var R = GetChar(t);
+ if (R != null)
+ {
+ W += R.Advance * Scaler;
+ }
+ else
+ {
+ W += size;
+ }
+ }
+ return W;
+ }
public LineSet GetChar(char t)
{
foreach(var ls in TheChars)
diff --git a/GerberLibrary/Artwork Related/GerberArtWriter.cs b/GerberLibrary/Artwork Related/GerberArtWriter.cs
index 6fd2a71..432ecfc 100644
--- a/GerberLibrary/Artwork Related/GerberArtWriter.cs
+++ b/GerberLibrary/Artwork Related/GerberArtWriter.cs
@@ -43,7 +43,7 @@ public enum ArtLayerStyle
public class Functions
{
- public static void CreateArtLayersForFolder(string foldername, ArtLayerStyle Style)
+ public static void CreateArtLayersForFolder(ProgressLog log, string foldername, ArtLayerStyle Style)
{
if (Directory.Exists(foldername) == false) return;
@@ -91,53 +91,53 @@ public static void CreateArtLayersForFolder(string foldername, ArtLayerStyle Sty
if (outlinefile.Length > 0)
{
- if (bottomfile.Length > 0) WriteArtLayerFiles(outlinefile, bottomfile, bottomsilkfile, Style);
- if (topfile.Length > 0 && Style != ArtLayerStyle.PrototypeEdge) WriteArtLayerFiles(outlinefile, topfile, topsilkfile, Style);
+ if (bottomfile.Length > 0) WriteArtLayerFiles(log, outlinefile, bottomfile, bottomsilkfile, Style);
+ if (topfile.Length > 0 && Style != ArtLayerStyle.PrototypeEdge) WriteArtLayerFiles(log, outlinefile, topfile, topsilkfile, Style);
}
}
- public static void WriteArtLayerFiles(string outline, string paste, string silk, ArtLayerStyle Style)
+ public static void WriteArtLayerFiles(ProgressLog log, string outline, string paste, string silk, ArtLayerStyle Style)
{
BoardSide Side;
BoardLayer Layer;
Gerber.DetermineBoardSideAndLayer(paste, out Side, out Layer);
- DoArtLayer(outline, paste, Path.Combine(Path.GetDirectoryName(outline), Path.GetFileNameWithoutExtension(outline) + "_artlayer" + ((Side == BoardSide.Top) ? ".gto" : ".gbo")), Style, silk);
+ DoArtLayer(log, outline, paste, Path.Combine(Path.GetDirectoryName(outline), Path.GetFileNameWithoutExtension(outline) + "_artlayer" + ((Side == BoardSide.Top) ? ".gto" : ".gbo")), Style, silk);
}
- static void DoArtLayer(string outline, string soldermask, string target, ArtLayerStyle Style, string silk = "")
+ static void DoArtLayer(ProgressLog log, string outline, string soldermask, string target, ArtLayerStyle Style, string silk = "")
{
switch (Style)
{
case ArtLayerStyle.PrototypeEdge:
- ArtGenerator_ProtoEdge(outline, soldermask, target, silk);
+ ArtGenerator_ProtoEdge(log, outline, soldermask, target, silk);
break;
case ArtLayerStyle.OffsetCurves_GoldfishBoard:
- ArtGenerator_OffsetCurves(outline, soldermask, target, silk);
+ ArtGenerator_OffsetCurves(log, outline, soldermask, target, silk);
break;
case ArtLayerStyle.FlowField:
- ArtGenerator_FlowField(outline, soldermask, target, silk);
+ ArtGenerator_FlowField(log, outline, soldermask, target, silk);
break;
case ArtLayerStyle.CheckerField:
- ArtGenerator_CheckerField(outline, soldermask, target, silk);
+ ArtGenerator_CheckerField(log, outline, soldermask, target, silk);
break;
case ArtLayerStyle.Flower:
- ArtGenerator_Flower(outline, soldermask, target, silk);
+ ArtGenerator_Flower(log, outline, soldermask, target, silk);
break;
case ArtLayerStyle.ReactDiffuse:
- ArtGenerator_ReactDiffuse(outline, soldermask, target, silk);
+ ArtGenerator_ReactDiffuse(log, outline, soldermask, target, silk);
break;
}
}
- private static void ArtGenerator_ProtoEdge(string outline, string soldermask, string target, string silk)
+ private static void ArtGenerator_ProtoEdge(ProgressLog log, string outline, string soldermask, string target, string silk)
{
Polygons CombinedSoldermask = new Polygons();
- Console.WriteLine("combining outlines..");
+ log.AddString(String.Format("combining outlines.."));
- ParsedGerber Outline = PolyLineSet.LoadGerberFile(outline);
+ ParsedGerber Outline = PolyLineSet.LoadGerberFile(log, outline);
//Outline.FixPolygonWindings();
@@ -275,22 +275,22 @@ public class RD_Elem
public float G;
}
- private static void ArtGenerator_ReactDiffuse(string outline, string soldermask, string target, string silk)
+ private static void ArtGenerator_ReactDiffuse(ProgressLog log, string outline, string soldermask, string target, string silk)
{
if (TheBounceInterface == null) TheBounceInterface = new BasicBounce();
- Console.WriteLine("Artlayer {0} started: CheckerField", target);
+ log.AddString(String.Format("Artlayer {0} started: CheckerField", target));
ParsedGerber Outline ;
ParsedGerber SolderMask;
- Outline = PolyLineSet.LoadGerberFile(outline, true, false, new GerberParserState() { PreCombinePolygons = true});
+ Outline = PolyLineSet.LoadGerberFile(log, outline, true, false, new GerberParserState() { PreCombinePolygons = true});
Outline.FixPolygonWindings();
- SolderMask = PolyLineSet.LoadGerberFile(soldermask, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1});
+ SolderMask = PolyLineSet.LoadGerberFile(log, soldermask, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1});
SolderMask.FixPolygonWindings();
Polygons CombinedOutline = new Polygons();
Polygons CombinedSoldermask = new Polygons();
- Console.WriteLine("combining outlines..");
+ log.AddString(String.Format("combining outlines.."));
for (int i = 0; i < Outline.OutlineShapes.Count; i++)
{
@@ -303,7 +303,7 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
cp.Execute(ClipType.ctXor, CombinedOutline, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
}
- Console.WriteLine("removing paste curves..");
+ log.AddString(String.Format("removing paste curves.."));
if (true)
for (int i = 0; i < SolderMask.OutlineShapes.Count; i++)
{
@@ -325,15 +325,15 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
if (silk.Length > 0)
{
- Console.WriteLine("removing silk curves..");
+ log.AddString(String.Format("removing silk curves.."));
- ParsedGerber Silk = PolyLineSet.LoadGerberFile(silk, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
+ ParsedGerber Silk = PolyLineSet.LoadGerberFile(log, silk, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
//Silk.FixPolygonWindings();
- Console.WriteLine("building big polygon..");
+ log.AddString(String.Format("building big polygon.."));
{
Polygons clips = new Polygons();
@@ -349,7 +349,7 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
cp.Execute(ClipType.ctUnion, OriginalCombinedSilk, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
}
- Console.WriteLine("offsetting big polygon..");
+ log.AddString(String.Format("offsetting big polygon.."));
CombinedSilk = Clipper.OffsetPolygons(OriginalCombinedSilk, 1.0 * 100000.0f, JoinType.jtRound, 0.1 * 100000.0f);
{
@@ -383,7 +383,7 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
for (int i = 0; i < iW * iH; i++) { DistanceField[i] = DistMode ? 0 : 100000; AngleField[i] = 0; };
Graphics G = Graphics.FromImage(B);
G.Clear(Color.Black);
- Console.WriteLine("Rendering Base Bitmap");
+ log.AddString(String.Format("Rendering Base Bitmap"));
G.SmoothingMode = SmoothingMode.AntiAlias;
foreach (var a in CombinedOutline)
@@ -437,7 +437,7 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
B.Save(target + "_renderbase.png");
- Console.WriteLine("Calculating Distance Field");
+ log.AddString(String.Format("Calculating Distance Field"));
{
@@ -474,7 +474,7 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
}
}
}
- Console.WriteLine("Blurring Distance Field");
+ log.AddString(String.Format("Blurring Distance Field"));
double maxblurval = 0;
double minblurval = 100000000000;
@@ -534,7 +534,7 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
B.Save(target + "_renderbase_afterdistance.png");
- Console.WriteLine("Calculating DiffusePasses");
+ log.AddString(String.Format("Calculating DiffusePasses"));
{
int img = 0;
@@ -579,7 +579,7 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
for (int i = 0; i < 1; i++)
{
- Console.WriteLine("bounce {0}/{1}", i, totalbounce);
+ log.AddString(String.Format("bounce {0}/{1}", i, totalbounce));
TheBounceInterface.BounceN(1000, FieldA, FieldB, iW, iH, feedrate, killrate, DistanceFieldBlur);
@@ -690,9 +690,9 @@ private static void ArtGenerator_ReactDiffuse(string outline, string soldermask,
}
- Console.WriteLine("Converting to gerber..");
+ log.AddString(String.Format("Converting to gerber.."));
WriteBitmapToGerber(target, Outline, Res, B2, 128);
- Console.WriteLine("Done");
+ log.AddString(String.Format("Done"));
}
private static void SetF(RD_Elem[] FieldB, int x, int y, int iW, int iH, float p1, float p2)
@@ -711,22 +711,22 @@ static RD_Elem GetF(RD_Elem[] FieldA, int x, int y, int iW, int iH)
}
- private static void ArtGenerator_Flower(string outline, string soldermask, string target, string silk)
+ private static void ArtGenerator_Flower(ProgressLog log, string outline, string soldermask, string target, string silk)
{
- Console.WriteLine("Artlayer {0} started: CheckerField", target);
+ log.AddString(String.Format("Artlayer {0} started: CheckerField", target));
- ParsedGerber Outline = PolyLineSet.LoadGerberFile(outline, true, false, new GerberParserState() { PreCombinePolygons = true});
+ ParsedGerber Outline = PolyLineSet.LoadGerberFile(log, outline, true, false, new GerberParserState() { PreCombinePolygons = true});
Outline.FixPolygonWindings();
- ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(soldermask, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
+ ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(log, soldermask, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
SolderMask.FixPolygonWindings();
//Silk.FixPolygonWindings();
Polygons CombinedOutline = new Polygons();
Polygons CombinedSoldermask = new Polygons();
- Console.WriteLine("combining outlines..");
+ log.AddString(String.Format("combining outlines.."));
for (int i = 0; i < Outline.OutlineShapes.Count; i++)
{
@@ -739,7 +739,7 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
cp.Execute(ClipType.ctXor, CombinedOutline, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
}
- Console.WriteLine("removing paste curves..");
+ log.AddString(String.Format("removing paste curves.."));
if (true)
for (int i = 0; i < SolderMask.OutlineShapes.Count; i++)
{
@@ -758,15 +758,15 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
if (silk.Length > 0)
{
- Console.WriteLine("removing silk curves..");
+ log.AddString(String.Format("removing silk curves.."));
- ParsedGerber Silk = PolyLineSet.LoadGerberFile(silk, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
+ ParsedGerber Silk = PolyLineSet.LoadGerberFile(log, silk, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
//Silk.FixPolygonWindings();
Polygons CombinedSilk = new Polygons();
- Console.WriteLine("building big polygon..");
+ log.AddString(String.Format("building big polygon.."));
{
Polygons clips = new Polygons();
@@ -782,7 +782,7 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
cp.Execute(ClipType.ctUnion, CombinedSilk, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
}
- Console.WriteLine("offsetting big polygon..");
+ log.AddString(String.Format("offsetting big polygon.."));
CombinedSilk = Clipper.OffsetPolygons(CombinedSilk, 1.0 * 100000.0f, JoinType.jtRound, 0.1 * 100000.0f);
{
@@ -816,7 +816,7 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
for (int i = 0; i < iW * iH; i++) { DistanceField[i] = DistMode ? 0 : 100000; AngleField[i] = 0; };
Graphics G = Graphics.FromImage(B);
G.Clear(Color.Black);
- Console.WriteLine("Rendering Base Bitmap");
+ log.AddString(String.Format("Rendering Base Bitmap"));
// G.SmoothingMode = SmoothingMode.AntiAlias;
foreach (var a in CombinedOutline)
{
@@ -843,7 +843,7 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
}
B.Save(target + "_renderbase.png");
- Console.WriteLine("Calculating Distance Field");
+ log.AddString(String.Format("Calculating Distance Field"));
{
for (int x = 0; x < iW; x++)
@@ -880,7 +880,7 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
}
}
}
- Console.WriteLine("Blurring Distance Field");
+ log.AddString(String.Format("Blurring Distance Field"));
double maxblurval = 0;
double minblurval = 100000000000;
@@ -936,7 +936,7 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
B.Save(target + "_renderDistance.png");
}
- Console.WriteLine("Calculating Flower Field and Artwork");
+ log.AddString(String.Format("Calculating Flower Field and Artwork"));
GerberArtWriter GOW = new GerberArtWriter();
{
@@ -983,7 +983,7 @@ private static void ArtGenerator_Flower(string outline, string soldermask, strin
}
GOW.Write(target);
- Console.WriteLine("Done");
+ log.AddString(String.Format("Done"));
}
public class FlowerThing
@@ -1270,21 +1270,21 @@ void Branch(double x, double y, double initialdir, double count, int depth = 0)
}
- private static void ArtGenerator_CheckerField(string outline, string soldermask, string target, string silk)
+ private static void ArtGenerator_CheckerField(ProgressLog log, string outline, string soldermask, string target, string silk)
{
- Console.WriteLine("Artlayer {0} started: CheckerField", target);
+ log.AddString(String.Format("Artlayer {0} started: CheckerField", target));
- ParsedGerber Outline = PolyLineSet.LoadGerberFile(outline, true, false, new GerberParserState() { PreCombinePolygons = true });
+ ParsedGerber Outline = PolyLineSet.LoadGerberFile(log, outline, true, false, new GerberParserState() { PreCombinePolygons = true });
Outline.FixPolygonWindings();
- ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(soldermask, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1});
+ ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(log, soldermask, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1});
SolderMask.FixPolygonWindings();
//Silk.FixPolygonWindings();
Polygons CombinedOutline = new Polygons();
Polygons CombinedSoldermask = new Polygons();
- Console.WriteLine("combining outlines..");
+ log.AddString(String.Format("combining outlines.."));
for (int i = 0; i < Outline.OutlineShapes.Count; i++)
{
@@ -1297,7 +1297,7 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
cp.Execute(ClipType.ctXor, CombinedOutline, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
}
- Console.WriteLine("removing paste curves..");
+ log.AddString(String.Format("removing paste curves.."));
if (true)
for (int i = 0; i < SolderMask.OutlineShapes.Count; i++)
{
@@ -1316,15 +1316,15 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
if (silk.Length > 0)
{
- Console.WriteLine("removing silk curves..");
+ log.AddString(String.Format("removing silk curves.."));
- ParsedGerber Silk = PolyLineSet.LoadGerberFile(silk, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
+ ParsedGerber Silk = PolyLineSet.LoadGerberFile(log, silk, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
//Silk.FixPolygonWindings();
Polygons CombinedSilk = new Polygons();
- Console.WriteLine("building big polygon..");
+ log.AddString(String.Format("building big polygon.."));
{
Polygons clips = new Polygons();
@@ -1340,7 +1340,7 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
cp.Execute(ClipType.ctUnion, CombinedSilk, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
}
- Console.WriteLine("offsetting big polygon..");
+ log.AddString(String.Format("offsetting big polygon.."));
CombinedSilk = Clipper.OffsetPolygons(CombinedSilk, 1.0 * 100000.0f, JoinType.jtRound, 0.1 * 100000.0f);
{
@@ -1374,7 +1374,7 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
for (int i = 0; i < iW * iH; i++) { DistanceField[i] = DistMode ? 0 : 100000; AngleField[i] = 0; };
Graphics G = Graphics.FromImage(B);
G.Clear(Color.Black);
- Console.WriteLine("Rendering Base Bitmap");
+ log.AddString(String.Format("Rendering Base Bitmap"));
// G.SmoothingMode = SmoothingMode.AntiAlias;
foreach (var a in CombinedOutline)
{
@@ -1401,7 +1401,7 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
}
B.Save(target + "_renderbase.png");
- Console.WriteLine("Calculating Distance Field");
+ log.AddString(String.Format("Calculating Distance Field"));
{
for (int x = 0; x < iW; x++)
@@ -1438,7 +1438,7 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
}
}
}
- Console.WriteLine("Blurring Distance Field");
+ log.AddString(String.Format("Blurring Distance Field"));
double maxblurval = 0;
double minblurval = 100000000000;
@@ -1490,7 +1490,7 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
}
B.Save(target + "_renderDistance.png");
}
- Console.WriteLine("Calculating Angle Field and Artwork");
+ log.AddString(String.Format("Calculating Angle Field and Artwork"));
{
G.Clear(Color.Black);
@@ -1537,9 +1537,9 @@ private static void ArtGenerator_CheckerField(string outline, string soldermask,
B2.Save(target + "_artwork.png");
}
- Console.WriteLine("Converting to gerber..");
+ log.AddString(String.Format("Converting to gerber.."));
WriteBitmapToGerber(target, Outline, Res, B2);
- Console.WriteLine("Done");
+ log.AddString(String.Format("Done"));
}
@@ -1599,6 +1599,12 @@ public static void WriteBitmapToGerber(string target, ParsedGerber Outline, doub
double offL = ((startlevel - Math.Abs(threshold)) / 128.0) * 1.0 / ResX;
double offR = ((endlevel - Math.Abs(threshold)) / 128.0) * 1.0 / ResX;
+
+ if (invert == false)
+ {
+ offL = -offL;
+ offR = -offR;
+ }
// offL *= -1;
// offR *= -1;
pL.Add(sx / ResX + offL, ((double)y) / ResY);
@@ -1629,21 +1635,21 @@ public static void WriteBitmapToGerber(string target, ParsedGerber Outline, doub
}
- private static void ArtGenerator_FlowField(string outline, string soldermask, string target, string silk)
+ private static void ArtGenerator_FlowField(ProgressLog log, string outline, string soldermask, string target, string silk)
{
- Console.WriteLine("Artlayer {0} started: CheckerField", target);
+ log.AddString(String.Format("Artlayer {0} started: CheckerField", target));
- ParsedGerber Outline = PolyLineSet.LoadGerberFile(outline, true, false, new GerberParserState() { PreCombinePolygons = true});
+ ParsedGerber Outline = PolyLineSet.LoadGerberFile(log, outline, true, false, new GerberParserState() { PreCombinePolygons = true});
Outline.FixPolygonWindings();
- ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(soldermask, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
+ ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(log, soldermask, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
SolderMask.FixPolygonWindings();
//Silk.FixPolygonWindings();
Polygons CombinedOutline = new Polygons();
Polygons CombinedSoldermask = new Polygons();
- Console.WriteLine("combining outlines..");
+ log.AddString(String.Format("combining outlines.."));
for (int i = 0; i < Outline.OutlineShapes.Count; i++)
{
@@ -1656,7 +1662,7 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
cp.Execute(ClipType.ctXor, CombinedOutline, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
}
- Console.WriteLine("removing paste curves..");
+ log.AddString(String.Format("removing paste curves.."));
if (true)
for (int i = 0; i < SolderMask.OutlineShapes.Count; i++)
{
@@ -1675,15 +1681,15 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
if (silk.Length > 0)
{
- Console.WriteLine("removing silk curves..");
+ log.AddString(String.Format("removing silk curves.."));
- ParsedGerber Silk = PolyLineSet.LoadGerberFile(silk, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
+ ParsedGerber Silk = PolyLineSet.LoadGerberFile(log, silk, false, false, new GerberParserState() { PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
//Silk.FixPolygonWindings();
Polygons CombinedSilk = new Polygons();
- Console.WriteLine("building big polygon..");
+ log.AddString(String.Format("building big polygon.."));
{
Polygons clips = new Polygons();
@@ -1699,7 +1705,7 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
cp.Execute(ClipType.ctUnion, CombinedSilk, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
}
- Console.WriteLine("offsetting big polygon..");
+ log.AddString(String.Format("offsetting big polygon.."));
CombinedSilk = Clipper.OffsetPolygons(CombinedSilk, 1.0 * 100000.0f, JoinType.jtRound, 0.1 * 100000.0f);
{
@@ -1733,7 +1739,7 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
for (int i = 0; i < iW * iH; i++) { DistanceField[i] = DistMode ? 0 : 100000; AngleField[i] = 0; };
Graphics G = Graphics.FromImage(B);
G.Clear(Color.Black);
- Console.WriteLine("Rendering Base Bitmap");
+ log.AddString(String.Format("Rendering Base Bitmap"));
// G.SmoothingMode = SmoothingMode.AntiAlias;
foreach (var a in CombinedOutline)
{
@@ -1760,7 +1766,7 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
}
B.Save(target + "_renderbase.png");
- Console.WriteLine("Calculating Distance Field");
+ log.AddString(String.Format("Calculating Distance Field"));
{
for (int x = 0; x < iW; x++)
@@ -1797,7 +1803,7 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
}
}
}
- Console.WriteLine("Blurring Distance Field");
+ log.AddString(String.Format("Blurring Distance Field"));
double maxblurval = 0;
double minblurval = 100000000000;
@@ -1850,7 +1856,7 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
}
B.Save(target + "_renderDistance.png");
}
- Console.WriteLine("Calculating Angle Field and Artwork");
+ log.AddString(String.Format("Calculating Angle Field and Artwork"));
GerberArtWriter GOW = new GerberArtWriter();
{
@@ -1908,26 +1914,27 @@ private static void ArtGenerator_FlowField(string outline, string soldermask, st
GOW.Write(target);
- Console.WriteLine("Done");
+ log.AddString(String.Format("Done"));
}
- private static void ArtGenerator_OffsetCurves(string outline, string soldermask, string target, string silk)
+ private static void ArtGenerator_OffsetCurves(ProgressLog log, string outline, string soldermask, string target, string silk)
{
- Console.WriteLine("Artlayer {0} started: OffsetCurves", target);
+ log.PushActivity("ArtGenerator_OffsetCurves");
+ log.AddString(String.Format("Artlayer {0} started: OffsetCurves", target));
- ParsedGerber Outline = PolyLineSet.LoadGerberFile(outline, true, false, new GerberParserState() { PreCombinePolygons = true });
+ ParsedGerber Outline = PolyLineSet.LoadGerberFile(log, outline, true, false, new GerberParserState() { PreCombinePolygons = true });
Outline.FixPolygonWindings();
- ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(soldermask, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
+ ParsedGerber SolderMask = PolyLineSet.LoadGerberFile(log, soldermask, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius = 0.1 });
SolderMask.FixPolygonWindings();
//Silk.FixPolygonWindings();
Polygons CombinedOutline = new Polygons();
Polygons CombinedSoldermask = new Polygons();
- Console.WriteLine("combining outlines..");
+ log.AddString(String.Format("combining outlines.."));
for (int i = 0; i < Outline.OutlineShapes.Count; i++)
{
@@ -1940,7 +1947,7 @@ private static void ArtGenerator_OffsetCurves(string outline, string soldermask,
cp.Execute(ClipType.ctXor, CombinedOutline, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
}
- Console.WriteLine("removing paste curves..");
+ log.AddString(String.Format("removing paste curves.."));
if (true)
{
Polygons clips = new Polygons();
@@ -1958,15 +1965,15 @@ private static void ArtGenerator_OffsetCurves(string outline, string soldermask,
if (silk.Length > 0)
{
- Console.WriteLine("removing silk curves..");
+ log.AddString(String.Format("removing silk curves.."));
- ParsedGerber Silk = PolyLineSet.LoadGerberFile(silk, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius =0.1 });
+ ParsedGerber Silk = PolyLineSet.LoadGerberFile(log, silk, false, false, new GerberParserState() {PreCombinePolygons = false, MinimumApertureRadius =0.1 });
//Silk.FixPolygonWindings();
Polygons CombinedSilk = new Polygons();
- Console.WriteLine("building big polygon..");
+ log.AddString(String.Format("building big polygon.."));
{
Polygons clips = new Polygons();
@@ -1982,7 +1989,7 @@ private static void ArtGenerator_OffsetCurves(string outline, string soldermask,
cp.Execute(ClipType.ctUnion, CombinedSilk, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
}
- Console.WriteLine("offsetting big polygon..");
+ log.AddString(String.Format("offsetting big polygon.."));
CombinedSilk = Clipper.OffsetPolygons(CombinedSilk, 0.5 * 100000.0f, JoinType.jtRound, 0.1 * 100000.0f);
{
@@ -1996,14 +2003,14 @@ private static void ArtGenerator_OffsetCurves(string outline, string soldermask,
}
- Console.WriteLine("starting offsetcurves..");
+ log.AddString(String.Format("starting offsetcurves.."));
GerberArtWriter GOW = new GerberArtWriter();
double add = 0.5;
for (double i = 0.5; i < 15; i += add)
{
// if (add < (0.25)) add = (0.25 );
- Console.WriteLine("offset {0}", i);
+ log.AddString(String.Format("offset {0}", i));
CombinedOutline = Clipper.OffsetPolygons(CombinedOutline, -add * 100000.0f, JoinType.jtRound, 0.1 * 100000.0f);
foreach (var p in CombinedOutline)
@@ -2016,6 +2023,7 @@ private static void ArtGenerator_OffsetCurves(string outline, string soldermask,
}
GOW.Write(target);
+ log.PopActivity();
}
}
@@ -2088,7 +2096,7 @@ public static ArtSet Load(string p)
return new ArtSet();
}
- public Dictionary LoadFonts()
+ public Dictionary LoadFonts(ProgressLog log)
{
Dictionary R = new Dictionary();
foreach (var a in Fonts)
@@ -2101,7 +2109,7 @@ public Dictionary LoadFonts()
}
catch (Exception E)
{
- Console.WriteLine("Font file failed to load: {0} {1}: {2}", a.Name, a.FontFile, E.Message);
+ log.AddString(String.Format("Font file failed to load: {0} {1}: {2}", a.Name, a.FontFile, E.Message));
}
}
return R;
@@ -2121,6 +2129,88 @@ public class Graphic
public class GerberArtWriter
{
+ public void WriteImageToBounds(Bitmap B, Bounds sizeofbitmap, Bounds rectangletobindto)
+ {
+ RectangleF bmpr = new RectangleF((float)sizeofbitmap.TopLeft.X, (float)sizeofbitmap.TopLeft.Y, (float)sizeofbitmap.Width(), (float)sizeofbitmap.Height());
+ RectangleF contain = new RectangleF((float)rectangletobindto.TopLeft.X, (float)rectangletobindto.TopLeft.Y, (float)rectangletobindto.Width(), (float)rectangletobindto.Height());
+ RectangleF section = new RectangleF((float)sizeofbitmap.TopLeft.X, (float)sizeofbitmap.TopLeft.Y, (float)sizeofbitmap.Width(), (float)sizeofbitmap.Height());
+
+ int threshold = 128;
+ if (bmpr.IntersectsWith(contain) == false) return;
+
+
+ section.Intersect(contain);
+
+ float dpiscaler = bmpr.Width / B.Width;
+
+ int YPIXELS = (int)Math.Ceiling(contain.Height / dpiscaler);
+ int XPIXELS = (int)Math.Ceiling(contain.Width / dpiscaler);
+ Console.WriteLine("ART LAYER {0} {1} {2}", YPIXELS, XPIXELS, dpiscaler);
+ int ssx = (int)Math.Floor((contain.X - bmpr.X) / dpiscaler);
+ int ssy = (int)Math.Floor((contain.Y - bmpr.Y) / dpiscaler);
+
+ bool invert = false;
+
+ if (threshold < 0)
+ {
+ threshold = -threshold;
+ invert = true;
+ }
+ int startlevel = 0;
+ int endlevel;
+ for (int y = 0; y < YPIXELS; y++)
+ {
+ double sx = -1;
+ bool active = false;
+ for (int x = 0; x < XPIXELS; x++)
+ {
+ Color C = B.GetPixel(x + ssx, B.Height - 1 - (y + ssy));
+ if ((invert == false && C.R > threshold) || (invert == true && C.R < threshold))
+ {
+ if (active == false)
+ {
+ sx = x;
+ startlevel = C.R;
+ active = true;
+ }
+ }
+ else
+ {
+ if (active)
+ {
+ endlevel = C.R;
+ active = false;
+ PolyLine pL = new PolyLine(PolyLine.PolyIDs.Bitmap);
+
+ double offL = ((startlevel - Math.Abs(threshold)) / 128.0) * dpiscaler;
+ double offR = ((endlevel - Math.Abs(threshold)) / 128.0) * dpiscaler;
+ // offL *= -1;
+ // offR *= -1;
+ pL.Add(contain.X + sx * dpiscaler - offL, contain.Y + ((double)y) * dpiscaler);
+ pL.Add(contain.X + ((double)x) * dpiscaler+ offR, contain.Y + ((double)y) * dpiscaler);
+ // if (Outline != null) pL.Translate(Outline.BoundingBox.TopLeft.X, Outline.BoundingBox.TopLeft.Y);
+
+ pL.Translate(0, .50 * dpiscaler);
+
+ AddPolyLine(pL, 1.0 * dpiscaler);
+ }
+ }
+ }
+ if (active)
+ {
+ PolyLine pL = new PolyLine(PolyLine.PolyIDs.Bitmap);
+ double offL = ((startlevel - Math.Abs(threshold)) / 128.0) * .50 * dpiscaler;
+
+ pL.Add(contain.X + sx * dpiscaler + offL, contain.Y + ((double)y) * dpiscaler);
+ pL.Add(contain.X + (XPIXELS) * dpiscaler, contain.Y + ((double)y) * dpiscaler);
+
+ pL.Translate(0, .50 * dpiscaler);
+ AddPolyLine(pL, 1.0 * dpiscaler);
+ }
+
+ }
+ }
+
Dictionary> PolyLines = new Dictionary>();
Dictionary ApertureLookup = new Dictionary();
List Polygons = new List();
diff --git a/GerberLibrary/Artwork Related/GerberOutlineWriter.cs b/GerberLibrary/Artwork Related/GerberOutlineWriter.cs
index 22c5a8b..0244552 100644
--- a/GerberLibrary/Artwork Related/GerberOutlineWriter.cs
+++ b/GerberLibrary/Artwork Related/GerberOutlineWriter.cs
@@ -4,9 +4,11 @@
using QiHe.CodeLib;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
+using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Windows.Forms;
@@ -30,7 +32,7 @@ public class PCBWriterSet
public void AddBoardHole(PointD pos, double diameter)
{
PolyLine PL = new PolyLine();
- PL.MakeCircle(diameter/2.0, 20,pos.X, pos.Y);
+ PL.MakeCircle(diameter / 2.0, 20, pos.X, pos.Y);
Outline.AddPolyLine(PL, 0);
}
@@ -170,12 +172,54 @@ public void Fiducial(PointD pos, double copperdiameter = 1.0, double maskdiamete
}
- public void Label(FontSet fnt, PointD pos, string txt, double size, StringAlign alignment = StringAlign.CenterCenter, double strokewidth = 0.1, bool silk = true, bool copper = false, double angle = 0, bool backside = false)
+ public static byte[] GetHash(string inputString)
{
+ using (HashAlgorithm algorithm = SHA256.Create())
+ return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
+ }
+
+ public RectangleD Identicon(PointD center, double size, string thingtohash, bool top = true)
+ {
+ size *= 2;
+ var H = GetHash(thingtohash);
+
+ Int32 r = 0;
+ for(int i = 0;i> b) & 0x1) > 0 ? true : false;
+ if (fill)
+ {
+ PolyLine P1 = new PolyLine();
+ P1.MakePRectangle(size / 8, size / 8, (ix - 3.5) * size / 8 + center.X , (iy - 3.5) * size / 8 + center.Y);
+ TopSilk.AddPolyLine(P1,0.01);
+ }
+ }
+ }
+
+ return new RectangleD() { X = center.X - size / 2, Y = center.Y - size / 2, Height= size,Width = size };
+ }
+ public void Label(FontSet fnt, PointD pos, string txt, double size, StringAlign alignment = StringAlign.CenterCenter, double strokewidth = 0.1, bool silk = true, bool copper = false, double angle = 0, bool backside = false, bool identiconstart = false, bool identiconend = false)
+ {
+
+ var therect = new RectangleD(TopSilk.MeasureString(pos, fnt, txt, size, strokewidth, alignment, backside, angle));
if (!backside)
{
+
ArtExclusions.Add(new RectangleD(TopSilk.MeasureString(pos, fnt, txt, size, strokewidth, alignment, backside, angle)));
+
+// ArtExclusions.Add(Identicon(new PointD(therect.X - size * 0.7, therect.Y + therect.Height / 2), size, txt, true));
+
+
+
if (silk) TopSilk.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
if (copper) TopCopper.DrawString(pos, fnt, txt, size, strokewidth, alignment, backside, angle);
}
@@ -227,14 +271,18 @@ public void PositionAround(PolyLine pL)
public int sideholes = 6;
public double mmbetweentabs = 40;
+
+ public double MinMountHoleSpacingMM = 10;
+
+ public double MaxMountHoleSpacingMM = 40;
}
public static void MergeFrameIntoGerberSet(string FrameFolder, string OutlineFolder, string OutputFolder, FrameSettings FS, ProgressLog log, string basename)
{
log.PushActivity("MergeFrame");
GerberPanel PNL = new GerberPanel();
- PNL.AddGerberFolder(FrameFolder);
- PNL.AddGerberFolder(OutlineFolder);
+ PNL.AddGerberFolder(log, FrameFolder);
+ PNL.AddGerberFolder(log, OutlineFolder);
PNL.TheSet.ClipToOutlines = false;
@@ -242,7 +290,7 @@ public static void MergeFrameIntoGerberSet(string FrameFolder, string OutlineFol
var FrameInstance = PNL.AddInstance(FrameFolder, new PointD(0, 0));
var OutlineInstance = PNL.AddInstance(OutlineFolder, new PointD(0, 0));
- PNL.UpdateShape();
+ PNL.UpdateShape(log);
var BB = OutlineInstance.BoundingBox;
@@ -296,7 +344,7 @@ public static void MergeFrameIntoGerberSet(string FrameFolder, string OutlineFol
}
- PNL.UpdateShape();
+ PNL.UpdateShape(log);
Directory.CreateDirectory(OutputFolder);
PNL.SaveGerbersToFolder("MergedFrame", OutputFolder, log, true, false, true, basename);
@@ -365,16 +413,7 @@ public static List WriteSideEdgeFrame(PolyLine pl, FrameSettings FS, str
double mountholediameter = (double)FS.holeDiameter;
- if (FS.addHoles)
- {
- double side = LE / 2.0;
- double top = TE / 2.0;
-
- PCB.Drill(new PointD(side, top), mountholediameter,1);
- PCB.Drill(new PointD(OuterWidth - side, top), mountholediameter,1);
- PCB.Drill(new PointD(OuterWidth - side, OuterHeight - top), mountholediameter,1);
- PCB.Drill(new PointD(side, OuterHeight - top), mountholediameter,1);
- }
+
// board outline
PolyLine PL = new PolyLine(polyid++);
@@ -396,27 +435,77 @@ public static List WriteSideEdgeFrame(PolyLine pl, FrameSettings FS, str
{
PointD fiducialPoint = P.pos;
PCB.Fiducial(fiducialPoint, P.CopperDiameter, P.MaskDiameter, P.Top);
-
}
#endregion
string FrameTitle = FS.FrameTitle;
+ string FrameTopTitle = FrameTitle + " - Top";
+ string FrameBottomTitle = FrameTitle + " - Bottom";
+ double verticaltitleclearance = 0;
+ double horizontaltitleclearance = 0;
if (FrameTitle.Length > 0)
{
FontSet fnt = FontSet.Load("Font.xml");
+ horizontaltitleclearance = fnt.StringWidth(FrameBottomTitle, TE / 4)+ mountholediameter*2 + FS.topEdge;
+ verticaltitleclearance = fnt.StringWidth(FrameBottomTitle, TE / 4)+ mountholediameter*2 + FS.topEdge;
+
+ PCB.Label(fnt, new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FrameTopTitle, TE/4, StringAlign.CenterCenter,0.1, true,true,0);
+ PCB.Label(fnt, new PointD(OuterWidth - LE / 4, OuterHeight / 2), FrameTopTitle, TE / 4.0, StringAlign.CenterCenter,0.1, true, true,-90);
+ PCB.Label(fnt, new PointD(LE / 4, OuterHeight / 2), FrameTopTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true,true, 90);
+ PCB.Label(fnt, new PointD(OuterWidth / 2.0, TE - TE / 4.0), FrameTopTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true,true,0);
+
+
+ PCB.Label(fnt, new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FrameBottomTitle, TE / 4, StringAlign.CenterCenter, 0.1, true,true,0, true, true, true);
+ PCB.Label(fnt, new PointD(OuterWidth - LE / 4, OuterHeight / 2), FrameBottomTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, -90,true);
+ PCB.Label(fnt, new PointD(LE / 4, OuterHeight / 2), FrameBottomTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 90,true);
+ PCB.Label(fnt, new PointD(OuterWidth / 2.0, TE - TE / 4.0), FrameBottomTitle, TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 0,true);
+ }
+
+ if (FS.addHoles)
+ {
+ double side = LE / 2.0;
+ double top = TE / 2.0;
+
+ PCB.Drill(new PointD(side, top), mountholediameter, 1);
+ PCB.Drill(new PointD(OuterWidth - side, top), mountholediameter, 1);
+ PCB.Drill(new PointD(OuterWidth - side, OuterHeight - top), mountholediameter, 1);
+ PCB.Drill(new PointD(side, OuterHeight - top), mountholediameter, 1);
+
+ double dx = (OuterWidth - side) - side;
+ double dy = (OuterHeight - top) - top;
+
+ dx -= horizontaltitleclearance;
+ dy -= verticaltitleclearance;
+ dx /= 2;
+ dy /= 2;
- PCB.Label(fnt, new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FrameTitle + " - top", TE/4, StringAlign.CenterCenter,0.1, true,true,0);
- PCB.Label(fnt, new PointD(OuterWidth - LE / 4, OuterHeight / 2), FrameTitle + " - top", TE / 4.0, StringAlign.CenterCenter,0.1, true, true,-90);
- PCB.Label(fnt, new PointD(LE / 4, OuterHeight / 2), FrameTitle + " - top", TE / 4.0, StringAlign.CenterCenter, 0.1, true,true, 90);
- PCB.Label(fnt, new PointD(OuterWidth / 2.0, TE - TE / 4.0), FrameTitle + " - top", TE / 4.0, StringAlign.CenterCenter, 0.1, true,true,0);
+ int horiz = (int)Math.Ceiling((dx / 2) / FS.MaxMountHoleSpacingMM);
+ int vert = (int)Math.Ceiling((dy / 2) / FS.MaxMountHoleSpacingMM);
+ dx /= (float)horiz;
+ dy /= (float)vert;
- PCB.Label(fnt, new PointD(OuterWidth / 2.0, OuterHeight - TE / 4.0), FrameTitle + " - bottom", TE / 4, StringAlign.CenterCenter, 0.1, true,true,0, true);
- PCB.Label(fnt, new PointD(OuterWidth - LE / 4, OuterHeight / 2), FrameTitle + " - bottom", TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, -90,true);
- PCB.Label(fnt, new PointD(LE / 4, OuterHeight / 2), FrameTitle + " - bottom", TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 90,true);
- PCB.Label(fnt, new PointD(OuterWidth / 2.0, TE - TE / 4.0), FrameTitle + " - bottom", TE / 4.0, StringAlign.CenterCenter, 0.1, true, true, 0,true);
+ if (dx < FS.MinMountHoleSpacingMM) horiz = 0;
+ if (dy < FS.MinMountHoleSpacingMM) vert = 0;
+
+ for (int i =1;i<=horiz;i++)
+ {
+ PCB.Drill(new PointD(side + (dx)*i, top), mountholediameter, 1);
+ PCB.Drill(new PointD((OuterWidth- side) - (dx) * i, top), mountholediameter, 1);
+ PCB.Drill(new PointD(side + (dx) * i, OuterHeight - top), mountholediameter, 1);
+ PCB.Drill(new PointD((OuterWidth - side) - (dx) * i, OuterHeight- top), mountholediameter, 1);
+ }
+
+
+ for (int i = 1; i <= vert; i++)
+ {
+ PCB.Drill(new PointD(side, top + (dy) * i), mountholediameter, 1);
+ PCB.Drill(new PointD(side, (OuterHeight- top) - (dy) * i), mountholediameter, 1);
+ PCB.Drill(new PointD((OuterWidth - side), top + (dy) * i), mountholediameter, 1);
+ PCB.Drill(new PointD((OuterWidth - side), (OuterHeight - top) - (dy) * i), mountholediameter, 1);
+ }
}
PolyLine Left = new PolyLine();
@@ -434,7 +523,9 @@ public static List WriteSideEdgeFrame(PolyLine pl, FrameSettings FS, str
PCB.ArtInclusions.Add(Top);
PCB.ArtInclusions.Add(Bottom);
- PCB.CellularArt();
+
+
+ //PCB.CellularArt();
Files.AddRange(PCB.Write(Path.GetDirectoryName(basefile), Path.GetFileNameWithoutExtension(basefile),FS.offset)); ;
diff --git a/GerberLibrary/Core/BillOfMaterials.cs b/GerberLibrary/Core/BillOfMaterials.cs
index d2825b7..c834469 100644
--- a/GerberLibrary/Core/BillOfMaterials.cs
+++ b/GerberLibrary/Core/BillOfMaterials.cs
@@ -56,7 +56,7 @@ public string Combined()
return CombinedName;
}
// else
- return (Name + "_" + PackageName + "_" + Value).Replace(' ', '_');
+ return (Name + "_" + PackageName + "_" + Value).Replace(' ', '_').Replace(',','.');
}
public string DisplayLine()
@@ -242,12 +242,17 @@ public List SplitOverPolygons(List polygons)
{
if (p.PointInPoly(new Primitives.PointD(n.x, n.y)))
{
- Res[i].AddBOMItemInt(devicevalue.Value.PackageName, devicevalue.Value.Name, devicevalue.Value.Value, n.NameOnBoard, Ns[i], n.SourceBoard, n.x, n.y, n.angle, n.Side);
+
+ OptionalOut bom = new OptionalOut();
+
+ Res[i].AddBOMItemInt(devicevalue.Value.PackageName, devicevalue.Value.Name, devicevalue.Value.Value, n.NameOnBoard, Ns[i], n.SourceBoard, n.x, n.y, n.angle, n.Side, bom);
+ bom.Result.SetCombined(devicevalue.Value.Combined());
+
added++;
}
i++;
}
- if (added ==0 )
+ if (added == 0)
{
Console.WriteLine("part skipped for some reason: {0}", n.NameOnBoard);
}
@@ -290,18 +295,26 @@ public void RemoveIgnored(List toIgnore)
public string AddBOMItemExt(string package, string device, string value, string refdes, BOMNumberSet set, string SourceBoard, double x, double y, double angle, BoardSide side = BoardSide.Top)
{
string ID = GetID(package, device, refdes);
- return AddBOMItemInt(package, device, value, refdes, set, SourceBoard, x, y, angle , side);
+ return AddBOMItemInt(package, device, value, refdes, set, SourceBoard, x, y, angle, side);
}
- string AddBOMItemInt(string package, string device, string value, string refdes, BOMNumberSet set, string SourceBoard, double x, double y, double angle, BoardSide side = BoardSide.Top)
+ public class OptionalOut
+ {
+ public Type Result { get; set; }
+ }
+
+ string AddBOMItemInt(string package, string device, string value, string refdes, BOMNumberSet set, string SourceBoard, double x, double y, double angle, BoardSide side = BoardSide.Top, OptionalOut bom = null)
{
string ID = GetID(package, device, refdes);
-
+
if (DeviceTree.ContainsKey(ID) == false) DeviceTree[ID] = new Dictionary();
if (DeviceTree[ID].ContainsKey(value) == false) DeviceTree[ID][value] = new BOMEntry() { Name = device, Value = value, PackageName = package };
BOMEntry BE = DeviceTree[ID][value];
+
+ if (bom != null) { bom.Result = BE; };
+
return BE.AddRef(refdes, SourceBoard, set, x, y, angle, side);
@@ -327,7 +340,9 @@ public void MergeBOM(BOM B, BOMNumberSet set, double dx, double dy, double cx, d
double X = c.x;
double Y = c.y;
Helpers.Transform(dx, dy, cx, cy, angle, ref X, ref Y);
- AddBOMItemInt(b.Value.PackageName, b.Value.Name, b.Value.Value, c.OriginalName, set, c.SourceBoard, X, Y, (c.angle + angle) % 360, c.Side);
+ OptionalOut bom = new OptionalOut();
+ AddBOMItemInt(b.Value.PackageName, b.Value.Name, b.Value.Value, c.OriginalName, set, c.SourceBoard, X, Y, (c.angle + angle) % 360, c.Side, bom);
+ bom.Result.SetCombined(b.Value.Combined());
}
}
}
@@ -369,6 +384,46 @@ public int GetUniquePartCount(List ToIgnore)
return partcount;
}
+ public void LoadPrinted(string filename)
+ {
+ BOMNumberSet BS = new BOMNumberSet();
+ try
+ {
+ var L = File.ReadAllLines(filename);
+
+ //string Header = "Count,Name,Type,Package,Value,MfgPartNumber,RefDes";
+
+ int idxcount = 0;
+ int idxname = 1;
+ int idxtype = 2;
+ int idxpackage = 3;
+ int idxvalue = 4;
+ int idxmfg = 5;
+ int idxrefdes = 6;
+ var Hsplit = L[0].Split(',');
+
+
+
+ for (int l = 1; l < L.Count(); l++)
+ {
+ var lsplit = L[l].Split(',');
+ var refsplit = lsplit[idxrefdes].Split(' ');
+ foreach (var refdes in refsplit)
+ {
+ AddBOMItemInt(lsplit[idxpackage], lsplit[idxname], lsplit[idxvalue], refdes, BS, filename, 0, 0, 0);
+ }
+ }
+
+
+ }
+ catch (Exception)
+ {
+
+ }
+
+
+ }
+
public List PrintBOM(List IgnoreList, bool AddDefaultIgnoreList = true)
{
List ToIgnore;
@@ -405,6 +460,7 @@ public List PrintBOM(List IgnoreList, bool AddDefaultIgnoreList
{
L = L + String.Format("{0} ", c.NameOnBoard);
}
+
Lines.Add(new Tuple(b.Value.Name, b.Value.Value, L));
}
@@ -683,6 +739,7 @@ public static string MakePartNo(string partno, string value)
private static string MulticompThickFilmResistorPartno(string value)
{
+ value = value.Replace(',', '.');
var r = new Regex("RES_0603_1%_RES_0603_([^_]*)$");
Match m = r.Match(value);
if (m.Groups.Count != 2) return "";
@@ -735,38 +792,48 @@ public void SetPartno(string pattern, string partno)
}
}
- public void Remap(string basefolder)
+ public void Remap(ProgressLog log, string basefolder)
{
+ log.PushActivity("Remap");
+
var D = PartLibrary.CreatePassivesMapping();
File.WriteAllLines(Path.Combine(basefolder, "genmapping.txt"), (from i in D select i.Key + " " + i.Value).ToList());
var map = File.ReadAllLines(Path.Combine(basefolder, "bommapping.txt"));
-
+ log.AddString("Loaded bommapping!");
foreach (var l in map)
{
var A = l.Split(' ');
- if (A.Count() == 2)
+ if (A.Count() >= 2)
{
string from = A[0];
string to = A[1];
- RemapPair(from, to);
+ bool dooverride = false;
+ if (A.Count()> 2)
+ {
+ if (A[2] == "override" ){ dooverride = true; };
+ }
+ RemapPair(log, from, to, dooverride);
+ //Console.WriteLine("remapped {0} to {1}", from, to);
}
}
foreach (var l in D)
{
- RemapPair(l.Key, l.Value);
- }
+ RemapPair(log, l.Key, l.Value, false);
+ }
+ log.PopActivity();
}
- private void RemapPair(string from, string to)
+ private void RemapPair(ProgressLog log, string from, string to, bool overridevalue )
{
+ log.PushActivity("RemapPair");
if (from != to)
{
- var F = FindEntry(from);
- var T = FindEntry(to);
+ var F = FindEntry(from, overridevalue);
+ var T = FindEntry(to, overridevalue);
if (F != null)
{
if (T != null)
@@ -781,11 +848,12 @@ private void RemapPair(string from, string to)
}
else
{
- Console.WriteLine("From found, but no To: {0}", from);
+ log.AddString(String.Format("From found, but no To: {0}", from));
F.SetCombined(to);
}
}
}
+ log.PopActivity();
}
private void RemoveEntry(BOMEntry f)
@@ -799,7 +867,7 @@ private void RemoveEntry(BOMEntry f)
}
}
- private BOMEntry FindEntry(string q)
+ private BOMEntry FindEntry(string q, bool overridevalue = false)
{
foreach (var a in DeviceTree)
{
@@ -1094,14 +1162,14 @@ private void LoadUltiboard(string bOMFile, string centroids)
}
*/
- public void WriteJLCCSV(string BaseFolder, string Name)
+ public void WriteJLCCSV(string BaseFolder, string Name, bool ellagetoo = false)
{
List outlinesBOM = new List();
List OutlinesRotations = new List();
- outlinesBOM.Add("Comment,Designator,Footprint,LCSC Part #");
+ outlinesBOM.Add("Comment,Designator,Footprint,LCSC Part #,combinedname,name");
foreach (var ds in DeviceTree)
{
@@ -1120,7 +1188,13 @@ public void WriteJLCCSV(string BaseFolder, string Name)
{
V = v.MfgPartNumber;
}
- string line = String.Format("{0},{1},{2},{3}",V,refdescs,v.PackageName,v.MfgPartNumber);
+
+ string mfg = "";
+ if (v.MfgPartNumber != null)
+ {
+ mfg = v.MfgPartNumber.Replace(',', '.');
+ }
+ string line = String.Format("{0},{1},{2},{3},{4},{5}",V,refdescs,v.PackageName,mfg,v.Combined(), v.Name);
outlinesBOM.Add(line);
}
@@ -1149,7 +1223,33 @@ public void WriteJLCCSV(string BaseFolder, string Name)
}
File.WriteAllLines(BaseFolder + "\\" + Name + "_PNP.csv", outlinesPNP);
- foreach(var a in RotationOffsets)
+
+ List EllageoutlinesPNP = new List();
+ EllageoutlinesPNP.Add("Designator,Mid X mm,Mid Y mm,Layer,Rotation deg");
+ foreach (var ds in DeviceTree)
+ {
+
+ foreach (var v in ds.Value.Values)
+ {
+ foreach (var p in v.RefDes)
+ {
+ int angle = (int)((p.angle + 179 + 360 + GetRotationOffset(v.Combined())) % 360) -179;
+ string line = String.Format("{0},{1},{2},{3},{4}",
+ p.NameOnBoard,
+ p.x.ToString("F2").Replace(",", "."),
+ p.y.ToString("F2").Replace(",", "."),
+ p.Side == BoardSide.Top ? "T" : "B",
+ angle);
+ EllageoutlinesPNP.Add(line);
+
+ }
+ }
+ }
+
+ File.WriteAllLines(BaseFolder + "\\" + Name + "_Ellage_PNP.csv", EllageoutlinesPNP);
+
+
+ foreach (var a in RotationOffsets)
{
OutlinesRotations.Add(String.Format("{0} {1}", a.Key, a.Value));
}
@@ -1231,7 +1331,8 @@ public void LoadJLC(string bOMFile, string pnPFile)
}
BOMNumberSet Set = new BOMNumberSet();
-
+ var headers = bomlines[0].Split(',');
+
for (int i = 1; i < bomlines.Count(); i++)
{
var s = bomlines[i];
@@ -1255,8 +1356,21 @@ public void LoadJLC(string bOMFile, string pnPFile)
foreach (var rd_ in rd)
{
var S = positions[rd_.Trim()];
+ if (headers.Count() > 5)
+ {
+ OptionalOut Entr = new OptionalOut(); ;
+ string name = items[5];
+ string combined = items[4];
+ AddBOMItemInt(package, name, value, rd_, Set, bOMFile, S.x, S.y, S.angle, S.Side, Entr);
+ Entr.Result.SetCombined(combined);
+ //AddBOMItemExt(package, name, value, rd_, Set, bOMFile, S.x, S.y, S.angle, S.Side);
- AddBOMItemExt(package, "", value, rd_, Set, bOMFile, S.x, S.y, S.angle, S.Side);
+ }
+ else
+ {
+ AddBOMItemExt(package, "", value, rd_, Set, bOMFile, S.x, S.y, S.angle, S.Side);
+ }
+
}
diff --git a/GerberLibrary/Core/ExcellonFile.cs b/GerberLibrary/Core/ExcellonFile.cs
index 6cb6598..3f0eac0 100644
--- a/GerberLibrary/Core/ExcellonFile.cs
+++ b/GerberLibrary/Core/ExcellonFile.cs
@@ -42,9 +42,11 @@ public void Load(ProgressLog log, StreamReader stream, double drillscaler = 1.0)
public static void MergeAll(List Files, string output, ProgressLog Log)
{
+ Log.PushActivity("Excellon MergeAll");
if (Files.Count >= 2)
{
MultiMerge(Files[0], Files.Skip(1).ToList(), output, Log);
+ Log.PopActivity();
return;
}
@@ -52,14 +54,15 @@ public static void MergeAll(List Files, string output, ProgressLog Log)
{
if (Files.Count == 1)
{
- Console.WriteLine("Merging 1 file is copying... doing so...");
+ Log.AddString("Merging 1 file is copying... doing so...");
if (File.Exists(output)) File.Delete(output);
File.Copy(Files[0], output);
}
else
{
- Console.WriteLine("Need files to do anything??");
+ Log.AddString("Need files to do anything??");
}
+ Log.PopActivity();
return;
}
@@ -80,32 +83,36 @@ public static void MergeAll(List Files, string output, ProgressLog Log)
{
File.Delete(s);
}
+ Log.PopActivity();
}
private static void MultiMerge(string file1, List otherfiles, string output, ProgressLog Log)
{
+ Log.PushActivity("Excellon MultiMerge");
if (File.Exists(file1) == false)
{
- Console.WriteLine("{0} not found! stopping process!", file1);
+ Log.AddString(String.Format("{0} not found! stopping process!", file1));
+ Log.PopActivity();
return;
}
foreach (var otherfile in otherfiles)
{
if (File.Exists(otherfile) == false)
{
- Console.WriteLine("{0} not found! stopping process!", otherfile);
+ Log.AddString(String.Format("{0} not found! stopping process!", otherfile));
+ Log.PopActivity();
return;
}
}
- Console.WriteLine("*** Reading {0}:", file1);
+ Log.AddString(String.Format("Reading {0}:", file1));
ExcellonFile File1Parsed = new ExcellonFile();
File1Parsed.Load(Log, file1);
List OtherFilesParsed = new List();
foreach (var otherfile in otherfiles)
{
- Console.WriteLine("*** Reading {0}:", otherfile);
+ Log.AddString(String.Format("Reading {0}:", otherfile));
ExcellonFile OtherFileParsed = new ExcellonFile();
OtherFileParsed.Load(Log, otherfile);
OtherFilesParsed.Add(OtherFileParsed);
@@ -125,6 +132,8 @@ private static void MultiMerge(string file1, List otherfiles, string out
}
}
File1Parsed.Write(output, 0, 0, 0, 0);
+
+ Log.PopActivity();
}
private void AddToolWithHoles(ExcellonTool d)
@@ -165,21 +174,23 @@ public static void Merge(string file1, string file2, string outputfile, Progress
Log.PopActivity();
return;
}
+
if (File.Exists(file2) == false)
{
Log.AddString(String.Format("{0} not found! stopping process!", file2));
Log.PopActivity();
return;
}
- Log.AddString(String.Format("*** Merging {0} with {1}", file1, file2));
- Log.AddString(String.Format("*** Reading {0}:", file1));
+ Log.AddString(String.Format("Reading {0}:", file1));
ExcellonFile File1Parsed = new ExcellonFile();
File1Parsed.Load(Log, file1);
- Log.AddString(String.Format("*** Reading {0}:", file2));
+ Log.AddString(String.Format("Reading {0}:", file2));
ExcellonFile File2Parsed = new ExcellonFile();
File2Parsed.Load(Log, file2);
+ Log.AddString(String.Format("Merging {0} with {1}", file1, file2));
+
int MaxID = 0;
foreach (var D in File1Parsed.Tools)
{
@@ -561,9 +572,11 @@ bool ParseExcellon(List lines, double drillscaler,ProgressLog log )
public static void WriteContainedOnly(string inputfile, PolyLine Boundary, string outputfilename, ProgressLog Log)
{
+ Log.PushActivity("Excellon Clipper");
if (File.Exists(inputfile) == false)
{
- Console.WriteLine("{0} not found! stopping process!", Path.GetFileName(inputfile));
+ Log.AddString(String.Format("{0} not found! stopping process!", Path.GetFileName(inputfile)));
+ Log.PopActivity();
return;
}
Log.AddString(String.Format("Clipping {0} to {1}", Path.GetFileName(inputfile), Path.GetFileName(outputfilename)));
@@ -571,7 +584,7 @@ public static void WriteContainedOnly(string inputfile, PolyLine Boundary, strin
ExcellonFile EF = new ExcellonFile();
EF.Load(Log, inputfile);
EF.WriteContained(Boundary, outputfilename, Log);
-
+ Log.PopActivity();
}
private void WriteContained(PolyLine boundary, string outputfilename, ProgressLog log)
diff --git a/GerberLibrary/Core/Gerber.cs b/GerberLibrary/Core/Gerber.cs
index 0df495b..9e2c0bf 100644
--- a/GerberLibrary/Core/Gerber.cs
+++ b/GerberLibrary/Core/Gerber.cs
@@ -735,13 +735,13 @@ public static BoardFileType FindFileTypeFromStream(StreamReader l, string filena
}
- public static Bounds GetBoundingBox(List generatedFiles)
+ public static Bounds GetBoundingBox(ProgressLog log, List generatedFiles)
{
Bounds A = new Bounds();
foreach (var a in generatedFiles)
{
- ParsedGerber PLS = PolyLineSet.LoadGerberFile(a, State: new GerberParserState() { PreCombinePolygons = false });
+ ParsedGerber PLS = PolyLineSet.LoadGerberFile(log, a, State: new GerberParserState() { PreCombinePolygons = false });
A.AddBox(PLS.BoundingBox);
}
return A;
@@ -810,7 +810,7 @@ public static bool SaveDebugImage(string GerberFilename, string BitmapFilename,
}
else
{
- PLS = PolyLineSet.LoadGerberFile(GerberFilename, forcezero, Gerber.WriteSanitized, State);
+ PLS = PolyLineSet.LoadGerberFile(log, GerberFilename, forcezero, Gerber.WriteSanitized, State);
}
double WidthInMM = PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X;
@@ -922,7 +922,7 @@ public static bool SaveGerberFileToImageUnsafe(ProgressLog log, string GerberFil
}
else
{
- PLS = PolyLineSet.LoadGerberFile(GerberFilename, forcezero, Gerber.WriteSanitized, State);
+ PLS = PolyLineSet.LoadGerberFile(log, GerberFilename, forcezero, Gerber.WriteSanitized, State);
}
double WidthInMM = PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X;
diff --git a/GerberLibrary/Core/GerberMerger.cs b/GerberLibrary/Core/GerberMerger.cs
index d70d1a5..c3a4c4e 100644
--- a/GerberLibrary/Core/GerberMerger.cs
+++ b/GerberLibrary/Core/GerberMerger.cs
@@ -13,23 +13,26 @@ public static class GerberMerger
{
public static void MergeAll(List Files, string output, ProgressLog Log)
{
+ Log.PushActivity("Gerber MergeAll");
if (Files.Count > 2)
{
MultiMerge(Files[0], Files.Skip(1).ToList(), output, Log);
+ Log.PopActivity();
return;
}
if (Files.Count < 2)
{
if (Files.Count == 1)
{
- Console.WriteLine("Merging 1 file is copying... doing so...");
+ Log.AddString("Merging 1 file is copying... doing so...");
if (File.Exists(output)) File.Delete(output);
File.Copy(Files[0], output);
}
else
{
- Console.WriteLine("Need files to do anything??");
+ Log.AddString("Need files to do anything??");
}
+ Log.PopActivity();
return;
}
@@ -84,14 +87,16 @@ public static void MergeAll(List Files, string output, ProgressLog Log)
}
catch (Exception) { }
}
-
+ Log.PopActivity();
}
public static void MultiMerge(string file1, List filestomergein, string output, ProgressLog Log)
{
+ Log.PushActivity("Gerber MultiMerge");
if (File.Exists(file1) == false)
{
- Console.WriteLine("{0} not found! stopping process!", Path.GetFileName(file1));
+ Log.AddString(String.Format("{0} not found! stopping process!", Path.GetFileName(file1)));
+ Log.PopActivity();
return;
}
List OtherFiles = new List();
@@ -102,13 +107,14 @@ public static void MultiMerge(string file1, List filestomergein, string
{
if (File.Exists(otherfile) == false)
{
- Console.WriteLine("{0} not found! stopping process!", Path.GetFileName(otherfile));
+ Log.AddString(String.Format("{0} not found! stopping process!", Path.GetFileName(otherfile)));
+ Log.PopActivity();
return;
}
List OtherLines = File.ReadAllLines(otherfile).ToList();
OtherLines = PolyLineSet.SanitizeInputLines(OtherLines);
- ParsedGerber OtherFileParsed = PolyLineSet.ParseGerber274x(OtherLines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
+ ParsedGerber OtherFileParsed = PolyLineSet.ParseGerber274x(Log, OtherLines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
OtherFiles.Add(OtherFileParsed);
OtherFileParsed.OriginalLines = OtherLines;
MaxDigitsAfter = Math.Max(OtherFileParsed.State.CoordinateFormat.DigitsAfter, MaxDigitsAfter);
@@ -118,7 +124,7 @@ public static void MultiMerge(string file1, List filestomergein, string
List File1Lines = File.ReadAllLines(file1).ToList();
File1Lines = PolyLineSet.SanitizeInputLines(File1Lines);
- ParsedGerber File1Parsed = PolyLineSet.ParseGerber274x(File1Lines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
+ ParsedGerber File1Parsed = PolyLineSet.ParseGerber274x(Log, File1Lines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
@@ -271,14 +277,14 @@ public static void MultiMerge(string file1, List filestomergein, string
File1Parsed.State.CoordinateFormat.SetImperialMode();
}
// skip changing metric mode!
- Console.WriteLine("ignoring metric/imperial gcode: G{0}", GS.Get("G"));
+ Log.AddString(String.Format("ignoring metric/imperial gcode: G{0}", GS.Get("G")));
}
else
{
if (GS.Get("G") == 4)
{
- Console.WriteLine("skipping comment: {0}", CurrentLine);
+ Log.AddString(String.Format("skipping comment: {0}", CurrentLine));
}
else
{
@@ -386,14 +392,14 @@ public static void MultiMerge(string file1, List filestomergein, string
// TODO: set polarity back to "neutral" - or should each file do this at the start anyway?
if (Gerber.ShowProgress)
{
- Console.WriteLine("File 1 format: {0}", File1Parsed.State.CoordinateFormat);
+ Log.AddString(String.Format("File 1 format: {0}", File1Parsed.State.CoordinateFormat));
}
foreach (var otherfile in OtherFiles)
{
if (Gerber.ShowProgress)
{
- Console.WriteLine("File 2 format: {0}", otherfile.State.CoordinateFormat);
+ Log.AddString(String.Format("File 2 format: {0}", otherfile.State.CoordinateFormat));
}
OutputLines.Add("G04 next file*");
if (CurrentPolarity != "LPD") { OutputLines.Add("%LPD*%"); CurrentPolarity = "LPD"; }
@@ -588,14 +594,14 @@ public static void MultiMerge(string file1, List filestomergein, string
otherfile.State.CoordinateFormat.SetImperialMode();
}
- Console.WriteLine("ignoring metric/imperial gcode: G{0}", GS.Get("G"));
+ Log.AddString(String.Format("ignoring metric/imperial gcode: G{0}", GS.Get("G")));
// skip changing metric mode!
}
else
{
if (GS.Get("G") == 4)
{
- Console.WriteLine("skipping comment: {0}", CurrentLine);
+ Log.AddString(String.Format("skipping comment: {0}", CurrentLine));
}
else
{
@@ -617,6 +623,10 @@ public static void MultiMerge(string file1, List filestomergein, string
OutputLines.Add(Gerber.EOF);
Gerber.WriteAllLines(output, PolyLineSet.SanitizeInputLines(OutputLines));
+
+ Log.PopActivity();
+
+
}
internal static void MergeAllByFileType(List allFiles, string targetfolder,string combinedfilename, ProgressLog Logger)
@@ -730,28 +740,29 @@ private static void CheckAllApertures(ParsedGerber file1Parsed, List Fil
public static void Merge(string file1, string file2, string output, ProgressLog Log)
{
+ Log.PushActivity("Gerber Merge");
if (File.Exists(file1) == false)
{
- Console.WriteLine("{0} not found! stopping process!", Path.GetFileName(file1));
+ Log.AddString(String.Format("{0} not found! stopping process!", Path.GetFileName(file1)));
+ Log.PopActivity();
return;
}
if (File.Exists(file2) == false)
{
- Console.WriteLine("{0} not found! stopping process!", Path.GetFileName(file2));
+ Log.AddString(String.Format("{0} not found! stopping process!", Path.GetFileName(file2)));
+ Log.PopActivity();
return;
}
Log.AddString(String.Format("Merging {0} with {1} in to {2}", Path.GetFileName(file1), Path.GetFileName(file2), Path.GetFileName(output)));
- // Console.WriteLine("*** Reading {0}", Path.GetFileName( file1));
- List File1Lines = File.ReadAllLines(file1).ToList();
+ List File1Lines = File.ReadAllLines(file1).ToList();
File1Lines = PolyLineSet.SanitizeInputLines(File1Lines);
- ParsedGerber File1Parsed = PolyLineSet.ParseGerber274x(File1Lines, true,false, new GerberParserState(){ PreCombinePolygons = false, GenerateGeometry = false});
+ ParsedGerber File1Parsed = PolyLineSet.ParseGerber274x(Log, File1Lines, true,false, new GerberParserState(){ PreCombinePolygons = false, GenerateGeometry = false});
- // Console.WriteLine("*** Reading {0}", Path.GetFileName(file2));
List File2Lines = File.ReadAllLines(file2).ToList();
File2Lines = PolyLineSet.SanitizeInputLines(File2Lines);
- ParsedGerber File2Parsed = PolyLineSet.ParseGerber274x(File2Lines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
+ ParsedGerber File2Parsed = PolyLineSet.ParseGerber274x(Log, File2Lines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
CheckAllApertures(File1Parsed, File1Lines, Log);
CheckAllApertures(File2Parsed, File2Lines, Log);
@@ -759,9 +770,6 @@ public static void Merge(string file1, string file2, string output, ProgressLog
int ApertureOffset = 0;
if (File1Parsed.State.Apertures.Count > 0) ApertureOffset = File1Parsed.State.Apertures.Keys.Max() + 1;
-
-// Console.WriteLine("*** Writing {0}", output);
-
List OutputLines = new List();
GerberNumberFormat GNF = new GerberNumberFormat();
GNF.DigitsBefore = Math.Max(File1Parsed.State.CoordinateFormat.DigitsBefore, File2Parsed.State.CoordinateFormat.DigitsBefore);
@@ -905,14 +913,14 @@ public static void Merge(string file1, string file2, string output, ProgressLog
File1Parsed.State.CoordinateFormat.SetImperialMode();
}
// skip changing metric mode!
- Console.WriteLine("ignoring metric/imperial gcode: G{0}", GS.Get("G"));
+ Log.AddString(String.Format("ignoring metric/imperial gcode: G{0}", GS.Get("G")));
}
else
{
if (GS.Get("G") == 4)
{
- Console.WriteLine("skipping comment: {0}", CurrentLine);
+ Log.AddString(String.Format("skipping comment: {0}", CurrentLine));
}
else
{
@@ -1017,8 +1025,8 @@ public static void Merge(string file1, string file2, string output, ProgressLog
// TODO: set polarity back to "neutral" - or should each file do this at the start anyway?
if (Gerber.ShowProgress)
{
- Console.WriteLine("File 1 format: {0}", File1Parsed.State.CoordinateFormat);
- Console.WriteLine("File 2 format: {0}", File2Parsed.State.CoordinateFormat);
+ Log.AddString(String.Format("File 1 format: {0}", File1Parsed.State.CoordinateFormat));
+ Log.AddString(String.Format("File 2 format: {0}", File2Parsed.State.CoordinateFormat));
}
OutputLines.Add("G04 next file*");
@@ -1212,14 +1220,14 @@ public static void Merge(string file1, string file2, string output, ProgressLog
File2Parsed.State.CoordinateFormat.SetImperialMode();
}
- Console.WriteLine("ignoring metric/imperial gcode: G{0}", GS.Get("G"));
+ Log.AddString(String.Format("ignoring metric/imperial gcode: G{0}", GS.Get("G")));
// skip changing metric mode!
}
else
{
if (GS.Get("G") == 4)
{
- Console.WriteLine("skipping comment: {0}", CurrentLine);
+ Log.AddString(String.Format("skipping comment: {0}", CurrentLine));
}
else
{
@@ -1240,24 +1248,27 @@ public static void Merge(string file1, string file2, string output, ProgressLog
OutputLines.Add(Gerber.EOF);
Gerber.WriteAllLines(output, PolyLineSet.SanitizeInputLines(OutputLines));
+
+ Log.PopActivity();
}
public static void WriteContainedOnly(string inputfile,PolyLine Boundary, string outputfilename, ProgressLog Log)
{
+ Log.PushActivity("Gerber Clipper");
if (File.Exists(inputfile) == false)
{
- Console.WriteLine("{0} not found! stopping process!", Path.GetFileName(inputfile));
+ Log.AddString(String.Format("{0} not found! stopping process!", Path.GetFileName(inputfile)));
+ Log.PopActivity();
return;
}
Log.AddString(String.Format("Clipping {0} to {1}", Path.GetFileName(inputfile), Path.GetFileName(outputfilename)));
- // Console.WriteLine("*** Reading {0}", Path.GetFileName( file1));
List File1Lines = File.ReadAllLines(inputfile).ToList();
File1Lines = PolyLineSet.SanitizeInputLines(File1Lines);
- ParsedGerber File1Parsed = PolyLineSet.ParseGerber274x(File1Lines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
+ ParsedGerber File1Parsed = PolyLineSet.ParseGerber274x(Log, File1Lines, true, false, new GerberParserState() { PreCombinePolygons = false, GenerateGeometry = false });
CheckAllApertures(File1Parsed, File1Lines, Log);
@@ -1395,7 +1406,7 @@ public static void WriteContainedOnly(string inputfile,PolyLine Boundary, string
File1Parsed.State.CoordinateFormat.SetImperialMode();
}
// skip changing metric mode!
- Console.WriteLine("ignoring metric/imperial gcode: G{0}", GS.Get("G"));
+ Log.AddString(String.Format("ignoring metric/imperial gcode: G{0}", GS.Get("G")));
}
else
@@ -1514,7 +1525,7 @@ public static void WriteContainedOnly(string inputfile,PolyLine Boundary, string
// TODO: set polarity back to "neutral" - or should each file do this at the start anyway?
if (Gerber.ShowProgress)
{
- Console.WriteLine("File 1 format: {0}", File1Parsed.State.CoordinateFormat);
+ Log.AddString(String.Format("File 1 format: {0}", File1Parsed.State.CoordinateFormat));
}
OutputLines.Add("G04 next file*");
@@ -1527,6 +1538,8 @@ public static void WriteContainedOnly(string inputfile,PolyLine Boundary, string
OutputLines.Add(Gerber.EOF);
Gerber.WriteAllLines(outputfilename, PolyLineSet.SanitizeInputLines(OutputLines));
+
+ Log.PopActivity();
}
}
}
diff --git a/GerberLibrary/Core/GerberPanel.cs b/GerberLibrary/Core/GerberPanel.cs
index 7c6380f..a6c4df0 100644
--- a/GerberLibrary/Core/GerberPanel.cs
+++ b/GerberLibrary/Core/GerberPanel.cs
@@ -13,7 +13,7 @@
using Ionic.Zip;
using TriangleNet;
using TriangleNet.Geometry;
-
+using System.Threading.Tasks;
namespace GerberLibrary
{
@@ -22,6 +22,7 @@ public abstract class ProgressLog
public abstract void AddString(string text, float progress = -1);
public void PushActivity(string activitiy)
{
+ // AddString("Activity: " + activitiy);
ActivityStack.Add(activitiy);
}
public void PopActivity()
@@ -82,23 +83,23 @@ public GerberPanel(double width = 100, double height = 100)
GraphicsPath GP = new GraphicsPath();
Bitmap MMGrid = null;
- public List AddGerberFolder(string path, bool add = true, bool skipoutlines = false)
+ public List AddGerberFolder(ProgressLog log, string path, bool add = true, bool skipoutlines = false)
{
if (File.Exists(path) && (Path.GetExtension(path).ToLower() == ".zip" || Path.GetExtension(path).ToLower() == "zip"))
{
- return AddGerberZip(path, add);
+ return AddGerberZip(log, path, add);
}
List res = new List();
if (add) TheSet.LoadedOutlines.Add(path);
string foldername = Path.GetDirectoryName(path + Path.DirectorySeparatorChar);
- Console.WriteLine("adding folder {0}", foldername);
+ log.AddString(String.Format("adding folder {0}", foldername));
bool had = false;
if (Directory.Exists(Path.Combine(path, "ultiboard")))
{
- Console.WriteLine("found ultiboard folder {0}", foldername);
+ log.AddString(String.Format("found ultiboard folder {0}", foldername));
}
@@ -140,7 +141,7 @@ public List AddGerberFolder(string path, bool add = true, bool skipoutli
{
foreach (var a in outlinefiles)
{
- GerberOutlines[path] = new GerberOutline(a);
+ GerberOutlines[path] = new GerberOutline(log, a);
if (GerberOutlines[path].TheGerber.DisplayShapes.Count > 0) had = true;
}
@@ -148,7 +149,7 @@ public List AddGerberFolder(string path, bool add = true, bool skipoutli
{
foreach (var a in millfiles)
{
- GerberOutlines[path] = new GerberOutline(a);
+ GerberOutlines[path] = new GerberOutline(log, a);
if (GerberOutlines[path].TheGerber.DisplayShapes.Count > 0) had = true;
}
@@ -156,7 +157,7 @@ public List AddGerberFolder(string path, bool add = true, bool skipoutli
if (had == false)
{
// TODO: extract an outline from other layers? THIS IS DANGEROUS!
- Console.WriteLine("Warning: {0} has no outline available?", path);
+ log.AddString(String.Format("Warning: {0} has no outline available?", path));
}
else
{
@@ -166,7 +167,7 @@ public List AddGerberFolder(string path, bool add = true, bool skipoutli
return res;
}
- private List AddGerberZip(string path, bool add)
+ private List AddGerberZip(ProgressLog log, string path, bool add)
{
List res = new List();
Dictionary Files = new Dictionary();
@@ -186,7 +187,7 @@ private List AddGerberZip(string path, bool add)
if (add) TheSet.LoadedOutlines.Add(path);
string foldername = Path.GetDirectoryName(path + Path.DirectorySeparatorChar);
- Console.WriteLine("adding zip file {0}", foldername);
+ log.AddString(String.Format("adding zip file {0}", foldername));
bool had = false;
string[] FileNames = Files.Keys.ToArray();
@@ -225,7 +226,7 @@ private List AddGerberZip(string path, bool add)
foreach (var a in outlinefiles)
{
Files[a].Seek(0, SeekOrigin.Begin);
- GerberOutlines[path] = new GerberOutline(new StreamReader(Files[a]), a);
+ GerberOutlines[path] = new GerberOutline(log, new StreamReader(Files[a]), a);
if (GerberOutlines[path].TheGerber.DisplayShapes.Count > 0) had = true;
}
@@ -234,7 +235,7 @@ private List AddGerberZip(string path, bool add)
foreach (var a in millfiles)
{
Files[a].Seek(0, SeekOrigin.Begin);
- GerberOutlines[path] = new GerberOutline(new StreamReader(Files[a]), a);
+ GerberOutlines[path] = new GerberOutline(log, new StreamReader(Files[a]), a);
if (GerberOutlines[path].TheGerber.DisplayShapes.Count > 0) had = true;
}
@@ -242,7 +243,7 @@ private List AddGerberZip(string path, bool add)
if (had == false)
{
// TODO: extract an outline from other layers? THIS IS DANGEROUS!
- Console.WriteLine("{0} has no outline available?", path);
+ log.AddString(String.Format("{0} has no outline available?", path));
}
else
{
@@ -252,7 +253,7 @@ private List AddGerberZip(string path, bool add)
}
- public void BuildAutoTabs(GerberArtWriter GAW = null, GerberArtWriter GAW2 = null)
+ public void BuildAutoTabs(ProgressLog log, GerberArtWriter GAW = null, GerberArtWriter GAW2 = null)
{
if (TheSet.Instances.Count < 3) return;
List Vertes = new List();
@@ -273,7 +274,7 @@ public void BuildAutoTabs(GerberArtWriter GAW = null, GerberArtWriter GAW2 = nul
Vertes.Add(V);
}
}
- UpdateShape();
+ UpdateShape(log);
var M = new TriangleNet.Meshing.GenericMesher();
var R = M.Triangulate(Vertes);
@@ -409,9 +410,9 @@ public void BuildAutoTabs(GerberArtWriter GAW = null, GerberArtWriter GAW2 = nul
}
- UpdateShape();
+ UpdateShape(log);
RemoveAllTabs(true);
- UpdateShape();
+ UpdateShape(log);
}
public Dictionary GerberOutlines = new Dictionary();
@@ -513,7 +514,7 @@ public List GenerateNegativePolygon(double offsetinMM = 3, double retr
}
- public void UpdateShape()
+ public void UpdateShape(ProgressLog log)
{
CombinedOutline.Clear();
@@ -536,7 +537,7 @@ public void UpdateShape()
RemoveInstance("???_negative");
var Neg = GenerateNegativePolygon(TheSet.FillOffset, TheSet.Smoothing);
- var G = new GerberOutline("");
+ var G = new GerberOutline(log, "");
G.TheGerber.Name = "???_negative";
G.TheGerber.OutlineShapes = Neg;
G.TheGerber.DisplayShapes = Neg;
@@ -549,7 +550,7 @@ public void UpdateShape()
{
aa.Tabs.Clear();
}
- FindOutlineIntersections();
+ FindOutlineIntersections(log);
}
@@ -1346,7 +1347,7 @@ private void SplitPolyLineAndAddSegs(PolyLine PL)
FinalSegs.AddRange(Segs);
}
- private void FindOutlineIntersections()
+ private void FindOutlineIntersections(ProgressLog log)
{
GeneratedArcs.Clear();
DrillHoles.Clear();
@@ -1441,7 +1442,7 @@ private void FindOutlineIntersections()
}
CutUpOutlines();
- CombineGeneratedArcsAndCutlines();
+ CombineGeneratedArcsAndCutlines(log);
}
private static bool AddIntersectionsForTabAndPolyLine(BreakTab t, List Intersections, PolyLine PL)
@@ -1580,7 +1581,7 @@ private void BuildDrillsForTabAndPolyLine(BreakTab t, PolyLine PL, List FinalPolygonsWithTabs = new List();
- private void CombineGeneratedArcsAndCutlines()
+ private void CombineGeneratedArcsAndCutlines(ProgressLog log)
{
List SourceLines = new List();
foreach (var a in GeneratedArcs)
@@ -1594,7 +1595,7 @@ private void CombineGeneratedArcsAndCutlines()
SourceLines.Add(new PathDefWithClosed() { Vertices = l, Width = 0 });
}
}
- FinalPolygonsWithTabs = Helpers.LineSegmentsToPolygons(SourceLines, true);
+ FinalPolygonsWithTabs = Helpers.LineSegmentsToPolygons(log, SourceLines, true);
}
public List SaveOutlineTo(string p, string combinedfilename)
@@ -1669,16 +1670,23 @@ public List SaveGerbersToFolder(string BaseName, string targetfolder, Pr
FilesPerExt[ext].Add(s);
}
int count = 0;
- foreach (var a in FilesPerExt)
+ object finallock = new object();
+ Parallel.ForEach(FilesPerExt, (a) =>
{
- count++;
- Logger.AddString("merging *" + a.Key.ToLower(), ((float)count / (float)FilesPerExt.Keys.Count) * 0.5f + 0.3f);
+ lock (finallock)
+ {
+ count++;
+ Logger.AddString("merging *" + a.Key.ToLower(), ((float)count / (float)FilesPerExt.Keys.Count) * 0.5f + 0.3f);
+ }
switch (FileTypePerExt[a.Key])
{
case BoardFileType.Drill:
{
string Filename = Path.Combine(targetfolder, combinedfilename + a.Key);
- FinalFiles.Add(Filename);
+ lock (finallock)
+ {
+ FinalFiles.Add(Filename);
+ }
ExcellonFile.MergeAll(a.Value, Filename, Logger);
}
break;
@@ -1687,13 +1695,16 @@ public List SaveGerbersToFolder(string BaseName, string targetfolder, Pr
if (a.Key.ToLower() != ".gko")
{
string Filename = Path.Combine(targetfolder, combinedfilename + a.Key);
- FinalFiles.Add(Filename);
+ lock (finallock)
+ {
+ FinalFiles.Add(Filename);
+ }
GerberMerger.MergeAll(a.Value, Filename, Logger);
}
}
break;
}
- }
+ });
//Logger.AddString("Writing source material zipfile", 0.80f);
//string SeparateZipFile = Path.Combine(targetfolder, BaseName + ".separate_boards.zip");
@@ -1807,7 +1818,7 @@ public GerberInstance AddInstance(string path, PointD coord, bool generateTransf
return GI;
}
- public void LoadFile(string filename)
+ public void LoadFile(ProgressLog log, string filename)
{
XmlSerializer SerializerObj = new XmlSerializer(typeof(GerberLayoutSet));
FileStream ReadFileStream = null;
@@ -1821,7 +1832,7 @@ public void LoadFile(string filename)
{
foreach (var a in newset.LoadedOutlines)
{
- AddGerberFolder(a, false);
+ AddGerberFolder(log, a, false);
}
TheSet = newset;
}
@@ -2379,11 +2390,11 @@ public class GerberOutline
public ParsedGerber TheGerber;
- public GerberOutline(string filename)
+ public GerberOutline(ProgressLog log, string filename)
{
if (filename.Length > 0)
{
- TheGerber = PolyLineSet.LoadGerberFile(filename, true, false, new GerberParserState() { PreCombinePolygons = false });
+ TheGerber = PolyLineSet.LoadGerberFile(log, filename, true, false, new GerberParserState() { PreCombinePolygons = false });
TheGerber.FixPolygonWindings();
foreach (var a in TheGerber.OutlineShapes)
{
@@ -2396,10 +2407,10 @@ public GerberOutline(string filename)
}
}
- public GerberOutline(StreamReader sr, string originalfilename)
+ public GerberOutline(ProgressLog log, StreamReader sr, string originalfilename)
{
- TheGerber = PolyLineSet.LoadGerberFileFromStream(sr, originalfilename, true, false, new GerberParserState() { PreCombinePolygons = false });
+ TheGerber = PolyLineSet.LoadGerberFileFromStream(log, sr, originalfilename, true, false, new GerberParserState() { PreCombinePolygons = false });
TheGerber.FixPolygonWindings();
foreach (var a in TheGerber.OutlineShapes)
{
diff --git a/GerberLibrary/Core/GerberTransposer.cs b/GerberLibrary/Core/GerberTransposer.cs
index 7cafb22..8565b69 100644
--- a/GerberLibrary/Core/GerberTransposer.cs
+++ b/GerberLibrary/Core/GerberTransposer.cs
@@ -37,6 +37,7 @@ public GerberTransposer()
/// Degrees
public static void Transform(ProgressLog log, string sourcefile, string destfile, double DX, double DY, double DXp, double DYp, double AngleInDeg = 0)
{
+ log.PushActivity("Gerber Transform");
List lines = new List();
List outlines = new List();
@@ -61,14 +62,14 @@ public static void Transform(ProgressLog log, string sourcefile, string destfi
if (Gerber.WriteSanitized) Gerber.WriteAllLines(sourcefile + ".sanitized.txt", lines);
// PolyLineSet Parsed = new PolyLineSet("parsed gerber");
- ParsedGerber Parsed = PolyLineSet.ParseGerber274x(lines, true, false, new GerberParserState() { GenerateGeometry = false });
+ ParsedGerber Parsed = PolyLineSet.ParseGerber274x(log, lines, true, false, new GerberParserState() { GenerateGeometry = false });
if (Gerber.ShowProgress)
{
- Console.WriteLine("found apertures: ");
+ log.AddString("found apertures: ");
foreach (var a in Parsed.State.Apertures)
{
- Console.WriteLine(a.Value.ToString());
+ log.AddString(a.Value.ToString());
}
}
@@ -165,18 +166,18 @@ public static void Transform(ProgressLog log, string sourcefile, string destfi
GCC.Decode(lines[i], CoordinateFormat);
if (GCC.numbercommands.Count < 1)
{
- Console.WriteLine("Skipping bad aperture definition: {0}", lines[i]);
+ log.AddString(String.Format("Skipping bad aperture definition: {0}", lines[i]));
}
else
{
int ATID = (int)GCC.numbercommands[0];
var Aperture = Parsed.State.Apertures[ATID];
- if (Gerber.ShowProgress) Console.WriteLine("found " + Aperture.ToString());
+ if (Gerber.ShowProgress) log.AddString(String.Format("found " + Aperture.ToString()));
string gerb = Aperture.BuildGerber(CoordinateFormat, AngleInDeg);
if ((Aperture.ShapeType == GerberApertureShape.Compound || Aperture.ShapeType == GerberApertureShape.Macro) && Parsed.State.ApertureMacros[Aperture.MacroName].Written == false)
{
- Console.WriteLine("Macro type defined - skipping");
+ log.AddString(String.Format("Macro type defined - skipping"));
}
else
{
@@ -216,7 +217,7 @@ public static void Transform(ProgressLog log, string sourcefile, string destfi
outlines.Add(lines[i]);
if (lines[i].Contains("LNData"))
{
- Console.WriteLine(" heh");
+ log.AddString(String.Format(" heh"));
}
if (lines[i][0] == '%')
{
@@ -246,7 +247,7 @@ public static void Transform(ProgressLog log, string sourcefile, string destfi
}
}
moveswritten++;
- Console.WriteLine(" Pure D Code: {0}", lines[i]);
+ log.AddString(String.Format("Pure D Code: {0}", lines[i]));
}
else
if (GS.Has("X") || GS.Has("Y") || (GS.Has("D") && GS.Get("D") < 10))
@@ -309,7 +310,7 @@ public static void Transform(ProgressLog log, string sourcefile, string destfi
outlines.Add(GS.Rebuild(CoordinateFormat));
if (PureD)
{
- Console.WriteLine("pureD");
+ log.AddString(String.Format("pureD"));
}
}
@@ -334,8 +335,9 @@ public static void Transform(ProgressLog log, string sourcefile, string destfi
}
catch (Exception E)
{
- Console.WriteLine(E.Message);
+ log.AddString(String.Format(E.Message));
}
+ log.PopActivity();
}
public static void GetTransformedCoord(double DX, double DY, double DXp, double DYp, double Angle, double CA, double SA, GerberNumberFormat CoordinateFormat, bool translate, ref double X, ref double Y)
diff --git a/GerberLibrary/Core/Helpers.cs b/GerberLibrary/Core/Helpers.cs
index 5899a1e..6d4fd6c 100644
--- a/GerberLibrary/Core/Helpers.cs
+++ b/GerberLibrary/Core/Helpers.cs
@@ -208,13 +208,20 @@ public static Line TransFormLine(Line v, double dx, double dy, float cx, float c
}
- public static List LineSegmentsToPolygons(List input, bool joinclosest = true)
+ public static List LineSegmentsToPolygons(ProgressLog log, List input, bool joinclosest = true)
{
+ List LeftoverLines = new List();
+ if (input.Count == 0)
+ {
+ return LeftoverLines;
+ }
+
+
+ log.PushActivity("LineSegmentsToPolygons");
// return input;
List Paths = new List();
List FirstSweep = new List();
- List LeftoverLines = new List();
- if (input.Count == 0) return LeftoverLines;
+
try
{
foreach (var p in input)
@@ -226,7 +233,7 @@ public static List LineSegmentsToPolygons(List LineSegmentsToPolygons(List 0)
@@ -376,7 +383,7 @@ public static List LineSegmentsToPolygons(List LineSegmentsToPolygons(List 0)
{
startat = lasthigh;
- Merges = FindNextMerge(Paths, out lasthigh, startat);
+ Merges = FindNextMerge(log, Paths, out lasthigh, startat);
}
//return Paths;
@@ -405,7 +412,7 @@ public static List LineSegmentsToPolygons(List LineSegmentsToPolygons(List StripOverlaps(List Paths)
+ private static List StripOverlaps(ProgressLog log, List Paths)
{
List Res = new List();
QuadTreeNode Root = new QuadTreeNode();
@@ -562,8 +571,8 @@ private static List StripOverlaps(List Pat
else
{
Res.Add(Paths[i]);
- Console.WriteLine("{4}: {0} out of {1}/{2}/{3}", nearcount, max, Paths[i].Vertices.Count, (Paths[i].Vertices.Count * 90) / 100, i);
- Console.WriteLine("{0}: skipped!", i);
+ log.AddString(String.Format("{4}: {0} out of {1}/{2}/{3}", nearcount, max, Paths[i].Vertices.Count, (Paths[i].Vertices.Count * 90) / 100, i));
+ log.AddString(String.Format("{0}: skipped!", i));
}
}
}
@@ -598,7 +607,7 @@ public double y
}
}
- private static int FindNextMerge(List Paths, out int highestnomatch, int startat = 0)
+ private static int FindNextMerge(ProgressLog log, List Paths, out int highestnomatch, int startat = 0)
{
highestnomatch = 0;
QuadTreeNode Root = new QuadTreeNode();
@@ -676,7 +685,7 @@ private static int FindNextMerge(List Paths, out int highestn
Paths[endmatch].Vertices.AddRange(Paths[i].Vertices);
if (Paths[endmatch].Vertices.First() == Paths[endmatch].Vertices.Last())
{
- Console.WriteLine("closed path with {0} points during stage 3a", Paths[endmatch].Vertices.Count());
+ log.AddString(String.Format("closed path with {0} points during stage 3a", Paths[endmatch].Vertices.Count()));
Paths[endmatch].Closed = true;
}
Paths.Remove(Paths[i]);
@@ -690,7 +699,7 @@ private static int FindNextMerge(List Paths, out int highestn
Paths[i].Vertices.AddRange(Paths[startmatch].Vertices);
if (Paths[i].Vertices.First() == Paths[i].Vertices.Last())
{
- Console.WriteLine("closed path with {0} points during stage 3b", Paths[i].Vertices.Count());
+ log.AddString(String.Format("closed path with {0} points during stage 3b", Paths[i].Vertices.Count()));
Paths[i].Closed = true;
}
Paths.Remove(Paths[startmatch]);
diff --git a/GerberLibrary/Core/ImageCreator.cs b/GerberLibrary/Core/ImageCreator.cs
index ff05351..17aef69 100644
--- a/GerberLibrary/Core/ImageCreator.cs
+++ b/GerberLibrary/Core/ImageCreator.cs
@@ -11,6 +11,7 @@
using GerberLibrary.Core;
using GerberLibrary.Core.Primitives;
using Ionic.Zip;
+using TriangleNet;
namespace GerberLibrary
{
@@ -268,6 +269,7 @@ public ParsedGerber AddBoardToSet(MemoryStream MS, string _originalfilename, Pro
if (FileType == BoardFileType.Unsupported)
{
if (Gerber.ExtremelyVerbose) log.AddString(String.Format("Warning: {1}: files with extension {0} are not supported!", Path.GetExtension(_originalfilename), Path.GetFileName(_originalfilename)));
+ log.PopActivity();
return null;
}
@@ -302,7 +304,7 @@ public ParsedGerber AddBoardToSet(MemoryStream MS, string _originalfilename, Pro
{
State.IgnoreZeroWidth = true;
}
- PLS = PolyLineSet.LoadGerberFileFromStream(new StreamReader(MS), _originalfilename, forcezerowidth, false, State);
+ PLS = PolyLineSet.LoadGerberFileFromStream(log, new StreamReader(MS), _originalfilename, forcezerowidth, false, State);
MS.Seek(0, SeekOrigin.Begin);
PLS.Side = State.Side;
@@ -860,376 +862,386 @@ private void CheckRelativeBoundingBoxes(ProgressLog Logger)
Bitmap DrawBoard(double dpi, BoardSide CurrentLayer, BoardRenderColorSet Colors, string basefilename = null, ProgressLog Logger = null, bool ForceWhite = false)
{
- scale = dpi / 25.4d; // dpi
- var OutlineBoundingBox = GetOutlineBoundingBox();
+ if (Logger != null) Logger.PushActivity("DrawBoard");
+ try
+ {
+ scale = dpi / 25.4d; // dpi
+ var OutlineBoundingBox = GetOutlineBoundingBox();
- double bw = Math.Abs(OutlineBoundingBox.BottomRight.X - OutlineBoundingBox.TopLeft.X);
- double bh = Math.Abs(OutlineBoundingBox.BottomRight.Y - OutlineBoundingBox.TopLeft.Y);
- int width = (int)((bw * scale));
- int height = (int)((bh * scale));
+ double bw = Math.Abs(OutlineBoundingBox.BottomRight.X - OutlineBoundingBox.TopLeft.X);
+ double bh = Math.Abs(OutlineBoundingBox.BottomRight.Y - OutlineBoundingBox.TopLeft.Y);
+ int width = (int)((bw * scale));
+ int height = (int)((bh * scale));
- //if (width > scale * 100) width = (int)(scale * 100);
- //if (height > scale * 100) height = (int)(scale * 100);
+ //if (width > scale * 100) width = (int)(scale * 100);
+ //if (height > scale * 100) height = (int)(scale * 100);
- int w = width + 3;
- int h = height + 3;
- Bitmap _Final = new Bitmap(w, h, PixelFormat.Format32bppArgb);
+ int w = width + 3;
+ int h = height + 3;
+ Bitmap _Final = new Bitmap(w, h, PixelFormat.Format32bppArgb);
- Bitmap _BoardPlate = new Bitmap(w, h, PixelFormat.Format32bppArgb);
+ Bitmap _BoardPlate = new Bitmap(w, h, PixelFormat.Format32bppArgb);
- Bitmap _SilkMask = new Bitmap(w, h, PixelFormat.Format32bppArgb);
+ Bitmap _SilkMask = new Bitmap(w, h, PixelFormat.Format32bppArgb);
- System.Drawing.Drawing2D.Matrix TransformCopy = null;
- //Bitmap B = new Bitmap(width + 3, height + 3);
- {
- Graphics G = Graphics.FromImage(_Final);
- ApplyAASettings(G);
- G.Clear(Color.Transparent);
- G.TranslateTransform(0, h);
- G.ScaleTransform(1, -1);
-
- if (CurrentLayer == BoardSide.Bottom)
+ System.Drawing.Drawing2D.Matrix TransformCopy = null;
+ //Bitmap B = new Bitmap(width + 3, height + 3);
{
- G.TranslateTransform(w, 0);
- G.ScaleTransform(-1, 1);
- }
+ Graphics G = Graphics.FromImage(_Final);
+ ApplyAASettings(G);
+ G.Clear(Color.Transparent);
+ G.TranslateTransform(0, h);
+ G.ScaleTransform(1, -1);
- G.TranslateTransform(1, 1);
- G.ScaleTransform((float)scale, (float)scale);
- G.TranslateTransform((float)-OutlineBoundingBox.TopLeft.X, (float)-OutlineBoundingBox.TopLeft.Y);
- TransformCopy = G.Transform.Clone();
+ if (CurrentLayer == BoardSide.Bottom)
+ {
+ G.TranslateTransform(w, 0);
+ G.ScaleTransform(-1, 1);
+ }
- }
+ G.TranslateTransform(1, 1);
+ G.ScaleTransform((float)scale, (float)scale);
+ G.TranslateTransform((float)-OutlineBoundingBox.TopLeft.X, (float)-OutlineBoundingBox.TopLeft.Y);
+ TransformCopy = G.Transform.Clone();
- if (Logger != null) Logger.AddString("Drawing outline files");
- Bitmap _OutlineBase = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderBaseMaterialColor, BoardLayer.Outline, BoardSide.Both, basefilename, true, 1, true);
- if (Logger != null) Logger.AddString("Drawing mill files");
- Bitmap _OutlineMill = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderBaseMaterialColor, BoardLayer.Mill, BoardSide.Both, basefilename, true, 1, true);
+ }
+ if (Logger != null) Logger.AddString("Drawing outline files");
+ Bitmap _OutlineBase = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderBaseMaterialColor, BoardLayer.Outline, BoardSide.Both, basefilename, true, 1, true);
+ if (Logger != null) Logger.AddString("Drawing mill files");
+ Bitmap _OutlineMill = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderBaseMaterialColor, BoardLayer.Mill, BoardSide.Both, basefilename, true, 1, true);
- if (Logger != null) Logger.AddString("Drawing copper files");
- Bitmap _Copper = DrawIfExists(width, height, TransformCopy, Color.FromArgb(80, 80, 0), BoardLayer.Copper, CurrentLayer, basefilename, true);
- if (Logger != null) Logger.AddString("Drawing silk files");
- Bitmap _Silk = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderSilkColor, BoardLayer.Silk, CurrentLayer, basefilename, true, 0.2f);
+ if (Logger != null) Logger.AddString("Drawing copper files");
+ Bitmap _Copper = DrawIfExists(width, height, TransformCopy, Color.FromArgb(80, 80, 0), BoardLayer.Copper, CurrentLayer, basefilename, true);
- if (Logger != null) Logger.AddString("Drawing soldermask files");
- Bitmap _SolderMaskHoles = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderPadColor, BoardLayer.SolderMask, CurrentLayer, basefilename, true, 0.2f);
+ if (Logger != null) Logger.AddString("Drawing silk files");
+ Bitmap _Silk = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderSilkColor, BoardLayer.Silk, CurrentLayer, basefilename, true, 0.2f);
- if (Logger != null) Logger.AddString("Drawing drill files");
- Bitmap _DrillHoles = DrawIfExists(width, height, TransformCopy, Color.Black, BoardLayer.Drill, BoardSide.Both, basefilename, true, 1.0f);
+ if (Logger != null) Logger.AddString("Drawing soldermask files");
+ Bitmap _SolderMaskHoles = DrawIfExists(width, height, TransformCopy, Colors.BoardRenderPadColor, BoardLayer.SolderMask, CurrentLayer, basefilename, true, 0.2f);
- if (Gerber.SaveIntermediateImages == true)
- {
- Console.WriteLine("Progress: Writing intermediate images:");
- if (_Copper != null) { _Copper.Save(CurrentLayer.ToString() + "_copper.png"); Console.WriteLine("Progress: Copper"); }
- if (_SolderMaskHoles != null) { _SolderMaskHoles.Save(CurrentLayer.ToString() + "_soldermaskholes.png"); Console.WriteLine("Progress: SolderMask"); }
- if (_DrillHoles != null) { _DrillHoles.Save(CurrentLayer.ToString() + "_drill.png"); Console.WriteLine("Progress: Drill"); }
- if (_OutlineBase != null) { _OutlineBase.Save(CurrentLayer.ToString() + "_base.png"); Console.WriteLine("Progress: Base"); }
- if (_OutlineMill != null) { _OutlineMill.Save(CurrentLayer.ToString() + "_mill.png"); Console.WriteLine("Progress: Mill"); }
- }
+ if (Logger != null) Logger.AddString("Drawing drill files");
+ Bitmap _DrillHoles = DrawIfExists(width, height, TransformCopy, Color.Black, BoardLayer.Drill, BoardSide.Both, basefilename, true, 1.0f);
- //DrawIfExists(width, height, G, Color.Black, BoardLayer.Mill, BoardSide.Both, basefilename);
- //DrawIfExists(filename, width, height, G, Color.Blue, BoardLayer.Drill, BoardSide.Both, false);
- //DrawIfExists(width, height, G, Color.White, BoardLayer.Outline, BoardSide.Both, basefilename, false);
- //DrawIfExists(width, height, G, Color.White, BoardLayer.Mill, BoardSide.Both, basefilename, false);
+ if (Gerber.SaveIntermediateImages == true)
+ {
+ Console.WriteLine("Progress: Writing intermediate images:");
+ if (_Copper != null) { _Copper.Save(CurrentLayer.ToString() + "_copper.png"); Console.WriteLine("Progress: Copper"); }
+ if (_SolderMaskHoles != null) { _SolderMaskHoles.Save(CurrentLayer.ToString() + "_soldermaskholes.png"); Console.WriteLine("Progress: SolderMask"); }
+ if (_DrillHoles != null) { _DrillHoles.Save(CurrentLayer.ToString() + "_drill.png"); Console.WriteLine("Progress: Drill"); }
+ if (_OutlineBase != null) { _OutlineBase.Save(CurrentLayer.ToString() + "_base.png"); Console.WriteLine("Progress: Base"); }
+ if (_OutlineMill != null) { _OutlineMill.Save(CurrentLayer.ToString() + "_mill.png"); Console.WriteLine("Progress: Mill"); }
+ }
- //LockBitmap OutlineBase = new LockBitmap(_OutlineBase);
- //LockBitmap OutlineMill = new LockBitmap(_OutlineMill);
- //LockBitmap Copper = new LockBitmap(_Copper);
- //LockBitmap SolderMaskHoles = new LockBitmap(_SolderMaskHoles);
- //LockBitmap Silk = new LockBitmap(_Silk);
+ //DrawIfExists(width, height, G, Color.Black, BoardLayer.Mill, BoardSide.Both, basefilename);
+ //DrawIfExists(filename, width, height, G, Color.Blue, BoardLayer.Drill, BoardSide.Both, false);
+ //DrawIfExists(width, height, G, Color.White, BoardLayer.Outline, BoardSide.Both, basefilename, false);
+ //DrawIfExists(width, height, G, Color.White, BoardLayer.Mill, BoardSide.Both, basefilename, false);
- //LockBitmap Final = new LockBitmap(_Final);
- //LockBitmap SilkMask = new LockBitmap(_SilkMask);
+ //LockBitmap OutlineBase = new LockBitmap(_OutlineBase);
+ //LockBitmap OutlineMill = new LockBitmap(_OutlineMill);
+ //LockBitmap Copper = new LockBitmap(_Copper);
+ //LockBitmap SolderMaskHoles = new LockBitmap(_SolderMaskHoles);
+ //LockBitmap Silk = new LockBitmap(_Silk);
+
+ //LockBitmap Final = new LockBitmap(_Final);
+ //LockBitmap SilkMask = new LockBitmap(_SilkMask);
- {
{
- Graphics G = Graphics.FromImage(_BoardPlate);
+ {
+ Graphics G = Graphics.FromImage(_BoardPlate);
- ApplyAASettings(G);
- G.Clear(Color.Transparent);
+ ApplyAASettings(G);
+ G.Clear(Color.Transparent);
- if (_OutlineBase != null) G.DrawImage(_OutlineBase, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
- if (_OutlineMill != null) G.DrawImage(_OutlineMill, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
+ if (_OutlineBase != null) G.DrawImage(_OutlineBase, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
+ if (_OutlineMill != null) G.DrawImage(_OutlineMill, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
- if (Logger != null) Logger.AddString("Carving inner polygons from board");
+ if (Logger != null) Logger.AddString("Carving inner polygons from board");
- if (Gerber.SaveIntermediateImages == true) _BoardPlate.Save("00 Outlines before carve.png");
+ if (Gerber.SaveIntermediateImages == true) _BoardPlate.Save("00 Outlines before carve.png");
- CarveOutlineAndMillInnerPolygonsFromImage(basefilename, w, h, G, _BoardPlate, TransformCopy);
- if (Gerber.SaveIntermediateImages == true) _BoardPlate.Save("66 OutlinesCarved.png");
+ CarveOutlineAndMillInnerPolygonsFromImage(basefilename, w, h, G, _BoardPlate, TransformCopy);
+ if (Gerber.SaveIntermediateImages == true) _BoardPlate.Save("66 OutlinesCarved.png");
- G = Graphics.FromImage(_Final);
- ApplyAASettings(G);
- G.Clear(Color.Transparent);
-
- if (Logger != null) Logger.AddString("Carving drills from board");
+ G = Graphics.FromImage(_Final);
+ ApplyAASettings(G);
+ G.Clear(Color.Transparent);
- if (_DrillHoles != null)
- {
- LockBitmap DrillHoles = new LockBitmap(_DrillHoles);
- LockBitmap BoardPlate = new LockBitmap(_BoardPlate);
- BoardPlate.LockBits();
- DrillHoles.LockBits();
+ if (Logger != null) Logger.AddString("Carving drills from board");
- for (int x = 0; x < w; x++)
+ if (_DrillHoles != null)
{
- for (int y = 0; y < h; y++)
+ LockBitmap DrillHoles = new LockBitmap(_DrillHoles);
+ LockBitmap BoardPlate = new LockBitmap(_BoardPlate);
+ BoardPlate.LockBits();
+ DrillHoles.LockBits();
+
+ for (int x = 0; x < w; x++)
{
- int idx = (y * BoardPlate.Width + x) * 4;
- var O = BoardPlate.GetPixelIDX(idx);
- var Drill = DrillHoles.GetPixelIDX(idx);
- Color newC = O;
- if (Drill.A > 0)
+ for (int y = 0; y < h; y++)
{
- float OA = 1.0f - (Drill.A / 255.0f);
- float DA = O.A / 255.0f;
- newC = Color.FromArgb((byte)Math.Round((OA * DA) * 255.0f), O.R, O.G, O.B);
- BoardPlate.SetPixelIDX(idx, newC);
+ int idx = (y * BoardPlate.Width + x) * 4;
+ var O = BoardPlate.GetPixelIDX(idx);
+ var Drill = DrillHoles.GetPixelIDX(idx);
+ Color newC = O;
+ if (Drill.A > 0)
+ {
+ float OA = 1.0f - (Drill.A / 255.0f);
+ float DA = O.A / 255.0f;
+ newC = Color.FromArgb((byte)Math.Round((OA * DA) * 255.0f), O.R, O.G, O.B);
+ BoardPlate.SetPixelIDX(idx, newC);
+ }
}
}
+ BoardPlate.UnlockBits();
+ DrillHoles.UnlockBits();
}
- BoardPlate.UnlockBits();
- DrillHoles.UnlockBits();
- }
- G.DrawImage(_BoardPlate, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
+ G.DrawImage(_BoardPlate, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
- if (Gerber.SaveIntermediateImages == true) _BoardPlate.Save("BoardPlateAfterDrills.png");
- }
- if (Logger != null) Logger.AddString("Layering copper on board");
+ if (Gerber.SaveIntermediateImages == true) _BoardPlate.Save("BoardPlateAfterDrills.png");
+ }
+ if (Logger != null) Logger.AddString("Layering copper on board");
- if (_Copper != null)
- {
- LockBitmap Final = new LockBitmap(_Final);
- LockBitmap Copper = new LockBitmap(_Copper);
- Final.LockBits();
- Copper.LockBits();
- for (int x = 0; x < w; x++)
+ if (_Copper != null)
{
- for (int y = 0; y < h; y++)
+ LockBitmap Final = new LockBitmap(_Final);
+ LockBitmap Copper = new LockBitmap(_Copper);
+ Final.LockBits();
+ Copper.LockBits();
+ for (int x = 0; x < w; x++)
{
- int idx = (y * Copper.Width + x) * 4;
+ for (int y = 0; y < h; y++)
+ {
+ int idx = (y * Copper.Width + x) * 4;
- var O = Final.GetPixelIDX(idx);
- var C = Copper.GetPixelIDX(idx);
+ var O = Final.GetPixelIDX(idx);
+ var C = Copper.GetPixelIDX(idx);
- if (O.A > 0)
- {
- if (C.A > 0)
+ if (O.A > 0)
{
- Color CopperColor = Colors.BoardRenderPadColor;
- float A = (C.A / 255.0f);
- float IA = 1 - A;
- Color newDC = Color.FromArgb(O.A,
- (byte)Math.Round(CopperColor.R * A + O.R * IA),
- (byte)Math.Round(CopperColor.G * A + O.G * IA),
- (byte)Math.Round(CopperColor.B * A + O.B * IA));
- Final.SetPixelIDX(idx, newDC);
+ if (C.A > 0)
+ {
+ Color CopperColor = Colors.BoardRenderPadColor;
+ float A = (C.A / 255.0f);
+ float IA = 1 - A;
+ Color newDC = Color.FromArgb(O.A,
+ (byte)Math.Round(CopperColor.R * A + O.R * IA),
+ (byte)Math.Round(CopperColor.G * A + O.G * IA),
+ (byte)Math.Round(CopperColor.B * A + O.B * IA));
+ Final.SetPixelIDX(idx, newDC);
+ }
}
+ //G.DrawImage(Copper, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
}
- //G.DrawImage(Copper, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
}
- }
- Copper.UnlockBits();
- Final.UnlockBits();
- if (Gerber.SaveIntermediateImages == true) _Final.Save("FinalAfterCopper.png");
-
- }
- {
- Graphics G = Graphics.FromImage(_SilkMask);
- ApplyAASettings(G); G.Clear(Color.Transparent);
- G.DrawImage(_BoardPlate, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
- }
- if (Logger != null) Logger.AddString("Applying soldermask to board");
+ Copper.UnlockBits();
+ Final.UnlockBits();
+ if (Gerber.SaveIntermediateImages == true) _Final.Save("FinalAfterCopper.png");
- if (_SolderMaskHoles != null)
- {
- LockBitmap SolderMaskHoles = new LockBitmap(_SolderMaskHoles);
- SolderMaskHoles.LockBits();
- LockBitmap Final = new LockBitmap(_Final);
- Final.LockBits();
- LockBitmap Copper = null;
- if (_Copper != null)
+ }
{
- Copper = new LockBitmap(_Copper);
- Copper.LockBits();
+ Graphics G = Graphics.FromImage(_SilkMask);
+ ApplyAASettings(G); G.Clear(Color.Transparent);
+ G.DrawImage(_BoardPlate, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
}
- LockBitmap SilkMask = new LockBitmap(_SilkMask);
- SilkMask.LockBits();
- LockBitmap BoardPlate = new LockBitmap(_BoardPlate);
- BoardPlate.LockBits();
+ if (Logger != null) Logger.AddString("Applying soldermask to board");
-
- for (int x = 0; x < w; x++)
+ if (_SolderMaskHoles != null)
{
- for (int y = 0; y < h; y++)
+ LockBitmap SolderMaskHoles = new LockBitmap(_SolderMaskHoles);
+ SolderMaskHoles.LockBits();
+ LockBitmap Final = new LockBitmap(_Final);
+ Final.LockBits();
+ LockBitmap Copper = null;
+ if (_Copper != null)
{
+ Copper = new LockBitmap(_Copper);
+ Copper.LockBits();
+ }
+ LockBitmap SilkMask = new LockBitmap(_SilkMask);
+ SilkMask.LockBits();
+ LockBitmap BoardPlate = new LockBitmap(_BoardPlate);
+ BoardPlate.LockBits();
- int idx = (y * Final.Width + x) * 4;
- var O = Final.GetPixelIDX(idx);
- var Mask = SolderMaskHoles.GetPixelIDX(idx);
+ for (int x = 0; x < w; x++)
+ {
+ for (int y = 0; y < h; y++)
+ {
+ int idx = (y * Final.Width + x) * 4;
- if (Mask.A > 0)
- {
- var OSM = SilkMask.GetPixelIDX(idx);
+ var O = Final.GetPixelIDX(idx);
+ var Mask = SolderMaskHoles.GetPixelIDX(idx);
- float OA = 1.0f - (Mask.A / 255.0f);
- float DA = O.A / 255.0f;
- Color newDC = Color.FromArgb((byte)Math.Round((OA * DA) * 255.0f), O.R, O.G, O.B);
- SilkMask.SetPixelIDX(idx, newDC);
- }
+ if (Mask.A > 0)
+ {
+ var OSM = SilkMask.GetPixelIDX(idx);
- Color Cop = Color.Transparent;
+ float OA = 1.0f - (Mask.A / 255.0f);
+ float DA = O.A / 255.0f;
+ Color newDC = Color.FromArgb((byte)Math.Round((OA * DA) * 255.0f), O.R, O.G, O.B);
+ SilkMask.SetPixelIDX(idx, newDC);
+ }
- if (Copper != null) Cop = Copper.GetPixelIDX(idx);
- var BmP = BoardPlate.GetPixelIDX(idx);
- if (Cop.A > 0 && Mask.A > 0)
- {
+ Color Cop = Color.Transparent;
- Color SurfaceFinish = Colors.BoardRenderPadColor;
- Color BaseColor = O;
- float A = (Cop.A / 255.0f * Mask.A / 255.0f * (BmP.A / 255.0f)) * 0.85f;
- float IA = 1.0f - A;
- O = Color.FromArgb((byte)Math.Round(O.A * BmP.A / 255.0f),
+ if (Copper != null) Cop = Copper.GetPixelIDX(idx);
- (byte)Math.Round(SurfaceFinish.R * A + O.R * IA),
- (byte)Math.Round(SurfaceFinish.G * A + O.G * IA),
- (byte)Math.Round(SurfaceFinish.B * A + O.B * IA));
- }
+ var BmP = BoardPlate.GetPixelIDX(idx);
+ if (Cop.A > 0 && Mask.A > 0)
+ {
- Color newC = O;
- float OA2 = (Mask.A / 255.0f) * 0.9f + 0.1f;
- //float DA = O.A / 255.0f;
+ Color SurfaceFinish = Colors.BoardRenderPadColor;
+ Color BaseColor = O;
+ float A = (Cop.A / 255.0f * Mask.A / 255.0f * (BmP.A / 255.0f)) * 0.85f;
+ float IA = 1.0f - A;
+ O = Color.FromArgb((byte)Math.Round(O.A * BmP.A / 255.0f),
- float IOA = 1.0f - OA2;
+ (byte)Math.Round(SurfaceFinish.R * A + O.R * IA),
+ (byte)Math.Round(SurfaceFinish.G * A + O.G * IA),
+ (byte)Math.Round(SurfaceFinish.B * A + O.B * IA));
+ }
- Color S = Colors.BoardRenderColor;
+ Color newC = O;
+ float OA2 = (Mask.A / 255.0f) * 0.9f + 0.1f;
+ //float DA = O.A / 255.0f;
- if (Cop.A > 0)
- {
- S = MathHelpers.Interpolate(S, Colors.BoardRenderTraceColor, Cop.A / 255);
- }
+ float IOA = 1.0f - OA2;
- newC = Color.FromArgb(O.A,
- (byte)Math.Round(O.R * OA2 + S.R * IOA),
- (byte)Math.Round(O.G * OA2 + S.G * IOA),
- (byte)Math.Round(O.B * OA2 + S.B * IOA));
+ Color S = Colors.BoardRenderColor;
- Final.SetPixelIDX(idx, newC);
- }
- }
+ if (Cop.A > 0)
+ {
+ S = MathHelpers.Interpolate(S, Colors.BoardRenderTraceColor, Cop.A / 255);
+ }
- SolderMaskHoles.UnlockBits();
- Final.UnlockBits();
- if (Copper != null)
- {
+ newC = Color.FromArgb(O.A,
+ (byte)Math.Round(O.R * OA2 + S.R * IOA),
+ (byte)Math.Round(O.G * OA2 + S.G * IOA),
+ (byte)Math.Round(O.B * OA2 + S.B * IOA));
- Copper.UnlockBits();
- }
- SilkMask.UnlockBits();
- BoardPlate.UnlockBits();
+ Final.SetPixelIDX(idx, newC);
+ }
+ }
- if (Gerber.SaveIntermediateImages == true) _Final.Save("FinalAfterSoldermask.png");
+ SolderMaskHoles.UnlockBits();
+ Final.UnlockBits();
+ if (Copper != null)
+ {
- }
- if (Logger != null) Logger.AddString("Applying silkscreen to board");
+ Copper.UnlockBits();
+ }
+ SilkMask.UnlockBits();
+ BoardPlate.UnlockBits();
- if (_Silk != null)
- {
- LockBitmap Final = new LockBitmap(_Final);
- Final.LockBits();
+ if (Gerber.SaveIntermediateImages == true) _Final.Save("FinalAfterSoldermask.png");
- LockBitmap Copper = null;
- if (_Copper != null)
- {
- Copper = new LockBitmap(_Copper);
- Copper.LockBits();
}
- LockBitmap SilkMask = new LockBitmap(_SilkMask);
- SilkMask.LockBits();
- LockBitmap Silk = new LockBitmap(_Silk);
- Silk.LockBits();
- for (int y = 0; y < h; y++)
- {
- for (int x = 0; x < w; x++)
- {
- int idx = (y * Silk.Width + x) * 4;
+ if (Logger != null) Logger.AddString("Applying silkscreen to board");
+ if (_Silk != null)
+ {
+ LockBitmap Final = new LockBitmap(_Final);
+ Final.LockBits();
- var SilkPixel = Silk.GetPixelIDX(idx);
- float AS = SilkPixel.A / 255.0f;
- if (AS > 0)
+ LockBitmap Copper = null;
+ if (_Copper != null)
+ {
+ Copper = new LockBitmap(_Copper);
+ Copper.LockBits();
+ }
+ LockBitmap SilkMask = new LockBitmap(_SilkMask);
+ SilkMask.LockBits();
+ LockBitmap Silk = new LockBitmap(_Silk);
+ Silk.LockBits();
+ for (int y = 0; y < h; y++)
+ {
+ for (int x = 0; x < w; x++)
{
- var OutputPixel = Final.GetPixelIDX(idx);
- var Mask = SilkMask.GetPixelIDX(idx);
+ int idx = (y * Silk.Width + x) * 4;
+
- // float AO = O.A / 255.0f;
- float AM = (Mask.A / 255.0f) * (1 - AS);
- if (Mask.A < 255 && Copper != null)
+ var SilkPixel = Silk.GetPixelIDX(idx);
+ float AS = SilkPixel.A / 255.0f;
+ if (AS > 0)
{
- var CopperPixel = Copper.GetPixelIDX(idx);
- if (CopperPixel.A > 0)
+ var OutputPixel = Final.GetPixelIDX(idx);
+ var Mask = SilkMask.GetPixelIDX(idx);
+
+ // float AO = O.A / 255.0f;
+ float AM = (Mask.A / 255.0f) * (1 - AS);
+ if (Mask.A < 255 && Copper != null)
{
- AM = AM * (1 - (CopperPixel.A / 255.0f)) + 1 * (CopperPixel.A / 255.0f);
- // AM = 1;
+ var CopperPixel = Copper.GetPixelIDX(idx);
+ if (CopperPixel.A > 0)
+ {
+ AM = AM * (1 - (CopperPixel.A / 255.0f)) + 1 * (CopperPixel.A / 255.0f);
+ // AM = 1;
+ }
+ // O = Color.FromArgb(C.A, 200, 200);
}
- // O = Color.FromArgb(C.A, 200, 200);
- }
- float iAM = 1.0f - AM;
- Color newC = Color.FromArgb(OutputPixel.A,
- (byte)Math.Round(OutputPixel.R * AM + SilkPixel.R * iAM),
- (byte)Math.Round(OutputPixel.G * AM + SilkPixel.G * iAM),
- (byte)Math.Round(OutputPixel.B * AM + SilkPixel.B * iAM));
- Final.SetPixelIDX(idx, newC);
+ float iAM = 1.0f - AM;
+ Color newC = Color.FromArgb(OutputPixel.A,
+ (byte)Math.Round(OutputPixel.R * AM + SilkPixel.R * iAM),
+ (byte)Math.Round(OutputPixel.G * AM + SilkPixel.G * iAM),
+ (byte)Math.Round(OutputPixel.B * AM + SilkPixel.B * iAM));
+ Final.SetPixelIDX(idx, newC);
+ }
}
}
- }
- Final.UnlockBits();
+ Final.UnlockBits();
- if (Copper != null)
- {
- Copper.UnlockBits();
- }
- SilkMask.UnlockBits();
- Silk.UnlockBits();
+ if (Copper != null)
+ {
+ Copper.UnlockBits();
+ }
+ SilkMask.UnlockBits();
+ Silk.UnlockBits();
- if (Gerber.SaveIntermediateImages == true) _Final.Save("FinalAfterSilk.png");
+ if (Gerber.SaveIntermediateImages == true) _Final.Save("FinalAfterSilk.png");
- }
+ }
- if (_Copper != null && Gerber.GerberRenderBumpMapOutput)
- {
- ApplyBumpMapping(_Final, _Copper, w, h);
+ if (_Copper != null && Gerber.GerberRenderBumpMapOutput)
+ {
+ ApplyBumpMapping(_Final, _Copper, w, h);
+ }
+ // if (OutlineBase != null) G.DrawImage(OutlineBase, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
}
- // if (OutlineBase != null) G.DrawImage(OutlineBase, new Rectangle(0, 0, w, h), 0, 0, w, h, GraphicsUnit.Pixel);
- }
- if (ForceWhite)
- {
- LockBitmap Final = new LockBitmap(_Final);
- Final.LockBits();
- for (int y = 0; y < h; y++)
+ if (ForceWhite)
{
- for (int x = 0; x < w; x++)
+ LockBitmap Final = new LockBitmap(_Final);
+ Final.LockBits();
+ for (int y = 0; y < h; y++)
{
- int idx = (y * Final.Width + x) * 4;
+ for (int x = 0; x < w; x++)
+ {
+ int idx = (y * Final.Width + x) * 4;
- var C = Final.GetPixelIDX(idx);
- if (C.A == 0) Final.SetPixelIDX(idx, Color.White);
+ var C = Final.GetPixelIDX(idx);
+ if (C.A == 0) Final.SetPixelIDX(idx, Color.White);
+ }
}
- }
- Final.UnlockBits();
+ Final.UnlockBits();
+ }
+ if (Logger != null) Logger.PopActivity();
+ return _Final;
}
- return _Final;
+ catch(Exception)
+ {
+ if (Logger != null) Logger.PopActivity();
+ }
+ return null;
// return B;
}
@@ -1299,11 +1311,11 @@ void DrawXRayBoard(string ftop, string fbot, double dpi, BoardRenderColorSet Col
if (Gerber.SaveIntermediateImages == true)
{
- Console.WriteLine("Progress: Writing intermediate images:");
- if (_Copper != null) { _Copper.Save("xray_copper.png"); Console.WriteLine("Progress: Copper"); }
- if (_DrillHoles != null) { _DrillHoles.Save("xray_drill.png"); Console.WriteLine("Progress: Drill"); }
- if (_OutlineBase != null) { _OutlineBase.Save("xray_base.png"); Console.WriteLine("Progress: Base"); }
- if (_OutlineMill != null) { _OutlineMill.Save("xray_mill.png"); Console.WriteLine("Progress: Mill"); }
+ if (Logger != null) Logger.AddString("Writing intermediate images");
+ if (_Copper != null) { _Copper.Save("xray_copper.png"); if (Logger != null) Logger.AddString("Copper"); }
+ if (_DrillHoles != null) { _DrillHoles.Save("xray_drill.png"); if (Logger != null) Logger.AddString("Drill"); }
+ if (_OutlineBase != null) { _OutlineBase.Save("xray_base.png"); if (Logger != null) Logger.AddString("Base"); }
+ if (_OutlineMill != null) { _OutlineMill.Save("xray_mill.png"); if (Logger != null) Logger.AddString("Mill"); }
}
//DrawIfExists(width, height, G, Color.Black, BoardLayer.Mill, BoardSide.Both, basefilename);
diff --git a/GerberLibrary/Core/PolyLineSet.cs b/GerberLibrary/Core/PolyLineSet.cs
index 6a43be0..52e7577 100644
--- a/GerberLibrary/Core/PolyLineSet.cs
+++ b/GerberLibrary/Core/PolyLineSet.cs
@@ -362,7 +362,7 @@ public static ParsedGerber LoadExcellonDrillFile(ProgressLog log, string drillfi
}
- public static ParsedGerber LoadGerberFile(string gerberfile, bool forcezerowidth = false, bool writesanitized = false, GerberParserState State = null)
+ public static ParsedGerber LoadGerberFile(ProgressLog log, string gerberfile, bool forcezerowidth = false, bool writesanitized = false, GerberParserState State = null)
{
if (State == null) State = new GerberParserState();
@@ -370,20 +370,20 @@ public static ParsedGerber LoadGerberFile(string gerberfile, bool forcezerowidth
using (StreamReader sr = new StreamReader(gerberfile))
{
- return ProcessStream(gerberfile, forcezerowidth, writesanitized, State, sr);
+ return ProcessStream(log, gerberfile, forcezerowidth, writesanitized, State, sr);
}
}
- public static ParsedGerber LoadGerberFileFromStream(StreamReader sr, string originalfilename, bool forcezerowidth = false, bool writesanitized = false, GerberParserState State = null)
+ public static ParsedGerber LoadGerberFileFromStream(ProgressLog log, StreamReader sr, string originalfilename, bool forcezerowidth = false, bool writesanitized = false, GerberParserState State = null)
{
if (State == null) State = new GerberParserState();
Gerber.DetermineBoardSideAndLayer(originalfilename, out State.Side, out State.Layer);
- return ProcessStream(originalfilename, forcezerowidth, writesanitized, State, sr);
+ return ProcessStream(log, originalfilename, forcezerowidth, writesanitized, State, sr);
}
- public static ParsedGerber ParseGerber274x(List inputlines, bool parseonly, bool forcezerowidth = false, GerberParserState State = null)
+ public static ParsedGerber ParseGerber274x(ProgressLog log, List inputlines, bool parseonly, bool forcezerowidth = false, GerberParserState State = null)
{
if (State == null) State = new GerberParserState();
@@ -453,7 +453,7 @@ public static ParsedGerber ParseGerber274x(List inputlines, bool parseon
shapelist.Add(new PathDefWithClosed() { Vertices = State.NewThinShapes[i].Vertices, Width = State.NewThinShapes[i].Width });
}
- var shapeslinked = Helpers.LineSegmentsToPolygons(shapelist);
+ var shapeslinked = Helpers.LineSegmentsToPolygons(log, shapelist);
foreach (var a in shapeslinked)
{
@@ -1855,7 +1855,7 @@ private static void ParseGerber274_Lines(bool forcezerowidth, GerberParserState
}
}
- private static ParsedGerber ProcessStream(string gerberfile, bool forcezerowidth, bool writesanitized, GerberParserState State, StreamReader sr)
+ private static ParsedGerber ProcessStream(ProgressLog log, string gerberfile, bool forcezerowidth, bool writesanitized, GerberParserState State, StreamReader sr)
{
List lines = new List();
while (sr.EndOfStream == false)
@@ -1872,7 +1872,7 @@ private static ParsedGerber ProcessStream(string gerberfile, bool forcezerowidth
State.SanitizedFile = gerberfile + ".sanitized.gerber";
};
- var G = ParseGerber274x(lines, false, forcezerowidth, State); ;
+ var G = ParseGerber274x(log, lines, false, forcezerowidth, State); ;
G.Name = gerberfile;
return G;
}
diff --git a/GerberLibrary/Core/SickOfBeige.cs b/GerberLibrary/Core/SickOfBeige.cs
index 8b1bfa8..8af610a 100644
--- a/GerberLibrary/Core/SickOfBeige.cs
+++ b/GerberLibrary/Core/SickOfBeige.cs
@@ -160,7 +160,7 @@ public ParsedGerber AddBoardToSet(ProgressLog log, MemoryStream MS, string _orig
}
State.PreCombinePolygons = precombinepolygons;
- PLS = PolyLineSet.LoadGerberFileFromStream(new StreamReader(MS), _originalfilename, forcezerowidth, false, State);
+ PLS = PolyLineSet.LoadGerberFileFromStream(log, new StreamReader(MS), _originalfilename, forcezerowidth, false, State);
MS.Seek(0, SeekOrigin.Begin);
PLS.Side = State.Side;
diff --git a/GerberPanelizer/GerberPanelize.cs b/GerberPanelizer/GerberPanelize.cs
index 5f40e59..9a7a000 100644
--- a/GerberPanelizer/GerberPanelize.cs
+++ b/GerberPanelizer/GerberPanelize.cs
@@ -224,8 +224,8 @@ private void loadToolStripMenuItem_Click(object sender, EventArgs e)
public void LoadFile(string filename)
{
LoadedFile = filename;
- ThePanel.LoadFile(filename);
- ThePanel.UpdateShape();
+ ThePanel.LoadFile(new StandardConsoleLog(), filename);
+ ThePanel.UpdateShape(new StandardConsoleLog());
TV.BuildTree(this, ThePanel.TheSet);
ZoomToFit();
@@ -647,7 +647,7 @@ private void glControl1_Paint(object sender, PaintEventArgs e)
if (ShapeMarkedForUpdate && (AutoUpdate || ForceShapeUpdate))
{
//Console.WriteLine("updating shape..");
- ThePanel.UpdateShape(); // check if needed?
+ ThePanel.UpdateShape(new StandardConsoleLog()); // check if needed?
ShapeMarkedForUpdate = false;
ForceShapeUpdate = false;
}
@@ -742,7 +742,7 @@ public void glControl1_DragDrop(object sender, DragEventArgs e)
if (Directory.Exists(S) || (File.Exists(S) && (Path.GetExtension(S).ToLower() == ".zip" || Path.GetExtension(S).ToLower() == "zip")))
{
Console.WriteLine("Adding dropped folder: {0}", S);
- var R = ThePanel.AddGerberFolder(S);
+ var R = ThePanel.AddGerberFolder(new StandardConsoleLog(), S);
foreach (var s in R)
{
GerberInstance GI = new GerberInstance() { GerberPath = s };
@@ -809,7 +809,7 @@ private void insertBoardJoinToolStripMenuItem_Click_1(object sender, EventArgs e
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
- ThePanel.BuildAutoTabs();// GenerateTabLocations();
+ ThePanel.BuildAutoTabs(new StandardConsoleLog());// GenerateTabLocations();
Redraw(true);
}
@@ -829,7 +829,7 @@ private void addGerberFolderToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
- var R = ThePanel.AddGerberFolder(folderBrowserDialog1.SelectedPath);
+ var R = ThePanel.AddGerberFolder(new StandardConsoleLog(),folderBrowserDialog1.SelectedPath);
foreach (var s in R)
{
GerberInstance GI = new GerberInstance() { GerberPath = s };
@@ -911,7 +911,7 @@ private void generateSilkscreenLayerOffsetArtToolStripMenuItem_Click(object send
if (SelectedInstance.GetType() == typeof(GerberInstance))
{
string path = (SelectedInstance as GerberInstance).GerberPath;
- GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(path, GerberLibrary.ArtWork.ArtLayerStyle.CheckerField);
+ GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(new StandardConsoleLog(), path, GerberLibrary.ArtWork.ArtLayerStyle.CheckerField);
}
}
@@ -978,7 +978,7 @@ private void generateArtOffsetCurvesToolStripMenuItem_Click(object sender, Event
if (SelectedInstance.GetType() == typeof(GerberInstance))
{
string path = (SelectedInstance as GerberInstance).GerberPath;
- GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(path, GerberLibrary.ArtWork.ArtLayerStyle.OffsetCurves_GoldfishBoard);
+ GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(new StandardConsoleLog(), path, GerberLibrary.ArtWork.ArtLayerStyle.OffsetCurves_GoldfishBoard);
}
}
@@ -988,7 +988,7 @@ private void generateArtFieldLinesToolStripMenuItem_Click(object sender, EventAr
if (SelectedInstance.GetType() == typeof(GerberInstance))
{
string path = (SelectedInstance as GerberInstance).GerberPath;
- GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(path, GerberLibrary.ArtWork.ArtLayerStyle.FlowField);
+ GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(new StandardConsoleLog(), path, GerberLibrary.ArtWork.ArtLayerStyle.FlowField);
}
}
@@ -1004,7 +1004,7 @@ private void generateArtReactedBlobsToolStripMenuItem_Click(object sender, Event
if (SelectedInstance.GetType() == typeof(GerberInstance))
{
string path = (SelectedInstance as GerberInstance).GerberPath;
- GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(path, GerberLibrary.ArtWork.ArtLayerStyle.ReactDiffuse);
+ GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(new StandardConsoleLog(), path, GerberLibrary.ArtWork.ArtLayerStyle.ReactDiffuse);
}
}
@@ -1014,7 +1014,7 @@ private void generateArtPrototypeStripToolStripMenuItem_Click(object sender, Eve
if (SelectedInstance.GetType() == typeof(GerberInstance))
{
string path = (SelectedInstance as GerberInstance).GerberPath;
- GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(path, GerberLibrary.ArtWork.ArtLayerStyle.PrototypeEdge);
+ GerberLibrary.ArtWork.Functions.CreateArtLayersForFolder(new StandardConsoleLog(), path, GerberLibrary.ArtWork.ArtLayerStyle.PrototypeEdge);
}
}
@@ -1024,7 +1024,7 @@ private void ProcessButton_Click_1(object sender, EventArgs e)
{
if (ShapeMarkedForUpdate)
{
- ThePanel.UpdateShape(); ShapeMarkedForUpdate = false;
+ ThePanel.UpdateShape(new StandardConsoleLog()); ShapeMarkedForUpdate = false;
Redraw(false);
ProcessButton.Enabled = false;
}
@@ -1052,7 +1052,7 @@ void UpdateAutoProcessButton()
AutoUpdate = true;
if (ShapeMarkedForUpdate)
{
- ThePanel.UpdateShape(); ShapeMarkedForUpdate = false;
+ ThePanel.UpdateShape(new StandardConsoleLog()); ShapeMarkedForUpdate = false;
Redraw(false);
diff --git a/GerberPanelizer/GerberPanelizerParent.cs b/GerberPanelizer/GerberPanelizerParent.cs
index 006daa9..4d9dbe4 100644
--- a/GerberPanelizer/GerberPanelizerParent.cs
+++ b/GerberPanelizer/GerberPanelizerParent.cs
@@ -246,7 +246,7 @@ private void GerberPanelizerParent_DragDrop(object sender, DragEventArgs e)
childForm.glControl1_DragDrop(sender, e);
ActivePanelizeInstance = childForm;
childForm.ThePanel.MaxRectPack();
- childForm.ThePanel.BuildAutoTabs();
+ childForm.ThePanel.BuildAutoTabs(new GerberLibrary.StandardConsoleLog());
childForm.ZoomToFit();
childForm.Redraw(true);
diff --git a/GerberProjects/FrameCreatorTest/BigJigImage.png b/GerberProjects/FrameCreatorTest/BigJigImage.png
new file mode 100644
index 0000000..c0ee112
Binary files /dev/null and b/GerberProjects/FrameCreatorTest/BigJigImage.png differ
diff --git a/GerberProjects/FrameCreatorTest/FrameCreatorTest.cs b/GerberProjects/FrameCreatorTest/FrameCreatorTest.cs
index ba02bb0..1728fb5 100644
--- a/GerberProjects/FrameCreatorTest/FrameCreatorTest.cs
+++ b/GerberProjects/FrameCreatorTest/FrameCreatorTest.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -19,32 +20,37 @@ static void Main(string[] args)
Directory.CreateDirectory(Path.Combine(basepath, "outline"));
Directory.CreateDirectory(Path.Combine(basepath, "frame"));
+ Directory.CreateDirectory(Path.Combine(basepath, "imagetest"));
+
GerberFrameWriter.FrameSettings FS = new GerberFrameWriter.FrameSettings();
PolyLine PL = new PolyLine();
FS.FrameTitle = "Test Frame";
FS.RenderSample = false;
FS.margin = 3;
- PL.MakeRoundedRect(new PointD(10, 10), new PointD(200, 200), 7);
+ PL.MakeRoundedRect(new PointD(10, 10), new PointD(400, 300), 7);
FS.PositionAround(PL);
//FS.offset = new PointD(200, 200);
FS.RenderSample = true;
GerberArtWriter GAW = new GerberArtWriter();
GAW.AddPolyLine(PL);
+
GAW.Write("outline/outtestinside.gko");
+
+ Bitmap FrontPrint = (Bitmap)Bitmap.FromFile("BigJigImage.png");
+ Bounds FrontBound = new Bounds() { BottomRight = new PointD(220, 230), TopLeft = new PointD(-220, -230) , Valid = true};
+ PCBWriterSet s = new PCBWriterSet();
+ s.TopSilk.WriteImageToBounds(FrontPrint, FrontBound, new Bounds() { TopLeft = new PointD(-10, -10), BottomRight = new PointD(10, 10),Valid = true });
+ s.Write("imagetest", "test!");
- GerberFrameWriter.WriteSideEdgeFrame(PL, FS, "frame/outtest");
- GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "frame"), Path.Combine(basepath, "outline"), Path.Combine(basepath, "mergedoutput"),FS, new FrameCreatorTest(),"testframe");
-
-
- GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "SliceFrameOutline6"), Path.Combine(basepath, "Slice6"), Path.Combine(basepath, "slice6inframe"), FS, new FrameCreatorTest(),"slice6framed" );
-
-
+// GerberFrameWriter.WriteSideEdgeFrame(PL, FS, "frame/outtest");
+ // GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "frame"), Path.Combine(basepath, "outline"), Path.Combine(basepath, "mergedoutput"),FS, new FrameCreatorTest(),"testframe");
+// GerberFrameWriter.MergeFrameIntoGerberSet(Path.Combine(basepath, "SliceFrameOutline6"), Path.Combine(basepath, "Slice6"), Path.Combine(basepath, "slice6inframe"), FS, new FrameCreatorTest(),"slice6framed" );
+// PNL.SaveOutlineTo("panelized.gko", "panelcombinedgko.gko");
- // PNL.SaveOutlineTo("panelized.gko", "panelcombinedgko.gko");
}
public override void AddString(string text, float progress = -1)
diff --git a/GerberProjects/FrameCreatorTest/FrameCreatorTest.csproj b/GerberProjects/FrameCreatorTest/FrameCreatorTest.csproj
index 89e8e4b..49f84e6 100644
--- a/GerberProjects/FrameCreatorTest/FrameCreatorTest.csproj
+++ b/GerberProjects/FrameCreatorTest/FrameCreatorTest.csproj
@@ -35,6 +35,7 @@
+
diff --git a/GerberProjects/GerberProjects.sln b/GerberProjects/GerberProjects.sln
index f8c4c1f..bc9ef2a 100644
--- a/GerberProjects/GerberProjects.sln
+++ b/GerberProjects/GerberProjects.sln
@@ -85,6 +85,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpampCalculator", "OpampCal
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrameCreatorTest", "FrameCreatorTest\FrameCreatorTest.csproj", "{6DAC1D1F-8265-4DE3-B5A0-D39C3493B521}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MakeIcon", "..\MakeIcon\MakeIcon.csproj", "{D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -373,6 +375,14 @@ Global
{6DAC1D1F-8265-4DE3-B5A0-D39C3493B521}.Release|Any CPU.Build.0 = Release|Any CPU
{6DAC1D1F-8265-4DE3-B5A0-D39C3493B521}.Release|x86.ActiveCfg = Release|Any CPU
{6DAC1D1F-8265-4DE3-B5A0-D39C3493B521}.Release|x86.Build.0 = Release|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Debug|x86.Build.0 = Debug|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Release|x86.ActiveCfg = Release|Any CPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -413,6 +423,7 @@ Global
{8DDC4C62-0407-48CC-9261-C1DA33040C93} = {5B17443F-D48D-429E-83E3-2C7DCA8C6ED3}
{16EF10F9-DAC3-4496-98C8-0BFB5E1698E7} = {5B17443F-D48D-429E-83E3-2C7DCA8C6ED3}
{6DAC1D1F-8265-4DE3-B5A0-D39C3493B521} = {F705564A-6956-4675-A941-6ED916ADC0AD}
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2} = {F705564A-6956-4675-A941-6ED916ADC0AD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FF204A88-D467-4D27-816B-E8B2C30CA74F}
diff --git a/GerberSplitter/Program.cs b/GerberSplitter/Program.cs
index 78dee3c..6c6db2b 100644
--- a/GerberSplitter/Program.cs
+++ b/GerberSplitter/Program.cs
@@ -32,7 +32,7 @@ static void Slice(string slicefile, List inputgerbers)
var OutputFolder = Path.GetDirectoryName(slicefile) + @"\Output\" + Path.GetFileNameWithoutExtension(slicefile);
- ParsedGerber P = PolyLineSet.LoadGerberFile(slicefile);
+ ParsedGerber P = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), slicefile);
foreach (var l in P.Shapes)
{
diff --git a/GerberToDxf/GerberToDxf/Program.cs b/GerberToDxf/GerberToDxf/Program.cs
index fb325be..62e795c 100644
--- a/GerberToDxf/GerberToDxf/Program.cs
+++ b/GerberToDxf/GerberToDxf/Program.cs
@@ -16,7 +16,7 @@ class Program
static void ConvertFile(string from, string to, bool displayshapes, bool outlineshapes)
{
- ParsedGerber PLS = PolyLineSet.LoadGerberFile(from,true, State: new GerberParserState() { PreCombinePolygons = true });
+ ParsedGerber PLS = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), from,true, State: new GerberParserState() { PreCombinePolygons = true });
diff --git a/GerberToImage/GerberToImage.cs b/GerberToImage/GerberToImage.cs
index 33923da..7cbc484 100644
--- a/GerberToImage/GerberToImage.cs
+++ b/GerberToImage/GerberToImage.cs
@@ -20,6 +20,8 @@ enum Arguments
nonormal,
silk,
mask,
+ trace,
+ copper,
None
}
@@ -29,7 +31,7 @@ static void Main(string[] args)
if (args.Count() < 1)
{
Console.WriteLine("need files to render...");
- Console.WriteLine("GerberToImage [--dpi N] [--noxray] [--nopcb] [--silk black:white] [--mask yellow:green:red:black:white:blue]");
+ Console.WriteLine("GerberToImage [--dpi N] [--noxray] [--nopcb] [--silk color] [--trace color] [--copper color] [--mask color]");
return;
}
@@ -38,7 +40,9 @@ static void Main(string[] args)
bool xray = true;
bool normal = true;
string pcbcolor = "green";
- string silkcolor = "";
+ string silkcolor = "white";
+ string tracecolor = "auto";
+ string coppercolor = "gold";
List RestList = new List();
for (int i = 0; i < args.Count() ; i++)
{
@@ -48,11 +52,15 @@ static void Main(string[] args)
case Arguments.dpi: dpi = Int32.Parse(args[i]); NextArg = Arguments.None; break;
case Arguments.silk: silkcolor = args[i];NextArg = Arguments.None;break;
case Arguments.mask: pcbcolor = args[i]; NextArg = Arguments.None; break;
+ case Arguments.trace: tracecolor = args[i]; NextArg = Arguments.None; break;
+ case Arguments.copper: coppercolor= args[i]; NextArg = Arguments.None; break;
case Arguments.None:
switch (args[i].ToLower())
{
case "--dpi": NextArg = Arguments.dpi; break;
case "--silk": NextArg = Arguments.silk;break;
+ case "--trace": NextArg = Arguments.trace; break;
+ case "--copper": NextArg = Arguments.copper; break;
case "--mask": NextArg = Arguments.mask; break;
case "--noxray": xray = false; NextArg = Arguments.None; break;
case "--nopcb": normal = false; NextArg = Arguments.None; break;
@@ -118,51 +126,9 @@ static void Main(string[] args)
GIC.AddBoardsToSet(FileList,new StandardConsoleLog(), true);
BoardRenderColorSet colors = new BoardRenderColorSet();
+ if (pcbcolor == "") pcbcolor = "black";
+ colors.SetupColors(pcbcolor, silkcolor, tracecolor, coppercolor);
- switch(pcbcolor)
- {
- case "yellow": colors.BoardRenderColor = Gerber.ParseColor("yellow");
- colors.BoardRenderSilkColor = Gerber.ParseColor("white");
- break;
- case "green":
- colors.BoardRenderColor = Gerber.ParseColor("green");
- colors.BoardRenderSilkColor = Gerber.ParseColor("white");
- break;
- case "black":
- colors.BoardRenderColor = Gerber.ParseColor("black");
- colors.BoardRenderSilkColor = Gerber.ParseColor("white");
- break;
- case "white":
- colors.BoardRenderColor = Gerber.ParseColor("white");
- colors.BoardRenderSilkColor = Gerber.ParseColor("black");
- break;
- case "blue":
- colors.BoardRenderColor = Gerber.ParseColor("yellow");
- colors.BoardRenderSilkColor = Gerber.ParseColor("white");
- break;
- case "red":
- colors.BoardRenderColor = Gerber.ParseColor("red");
- colors.BoardRenderSilkColor = Gerber.ParseColor("white");
- break;
- }
-
- colors.BoardRenderTraceColor = colors.BoardRenderColor;
- if (silkcolor.Length > 0)
- {
- switch(silkcolor)
- {
- case "white":
- colors.BoardRenderSilkColor = Gerber.ParseColor("white");
- break;
-
- case "black":
- colors.BoardRenderSilkColor = Gerber.ParseColor("black");
- break;
-
-
- }
- }
- colors.BoardRenderPadColor = Gerber.ParseColor("silver");
GIC.SetColors(colors);
GIC.WriteImageFiles(TargetFileBaseName, dpi, false, xray, normal, new StandardConsoleLog());
diff --git a/GerberToOutline/GerberToOutline.cs b/GerberToOutline/GerberToOutline.cs
index a53463e..2497980 100644
--- a/GerberToOutline/GerberToOutline.cs
+++ b/GerberToOutline/GerberToOutline.cs
@@ -58,7 +58,7 @@ static void Main(string[] args)
}
State.PreCombinePolygons = precombinepolygons;
- PLS = PolyLineSet.LoadGerberFile(infile, forcezerowidth, false, State);
+ PLS = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), infile, forcezerowidth, false, State);
PLS.Side = State.Side;
PLS.Layer = State.Layer;
if (Layer == BoardLayer.Outline)
diff --git a/GerberViewer/LoadedStuff.cs b/GerberViewer/LoadedStuff.cs
index 5e26ded..8e12eea 100644
--- a/GerberViewer/LoadedStuff.cs
+++ b/GerberViewer/LoadedStuff.cs
@@ -69,7 +69,7 @@ public void AddFileStream(ProgressLog log, MemoryStream S, string origfilename,
State.PreCombinePolygons = precombinepolygons;
- PLS = PolyLineSet.LoadGerberFileFromStream(new StreamReader(S),origfilename, forcezerowidth, false, State);
+ PLS = PolyLineSet.LoadGerberFileFromStream(log, new StreamReader(S),origfilename, forcezerowidth, false, State);
S.Seek(0, SeekOrigin.Begin);
PLS.Side = Side;
diff --git a/ImageToGerber/FrontPanelImageToGerber.cs b/ImageToGerber/FrontPanelImageToGerber.cs
index 0d5b830..4d31e44 100644
--- a/ImageToGerber/FrontPanelImageToGerber.cs
+++ b/ImageToGerber/FrontPanelImageToGerber.cs
@@ -98,7 +98,7 @@ private static void ConvertFile(string a, bool back)
if (System.IO.File.Exists(f))
{
int polyid = 0;
- PLS = PolyLineSet.LoadGerberFile(f);
+ PLS = PolyLineSet.LoadGerberFile(new StandardConsoleLog(), f);
string bottomcopper= basename + "/bottomcopper.gbl";
diff --git a/MakeIcon/App.config b/MakeIcon/App.config
new file mode 100644
index 0000000..193aecc
--- /dev/null
+++ b/MakeIcon/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MakeIcon/MakeIcon.csproj b/MakeIcon/MakeIcon.csproj
new file mode 100644
index 0000000..5071f9d
--- /dev/null
+++ b/MakeIcon/MakeIcon.csproj
@@ -0,0 +1,59 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {D4D4DC84-983D-4B9E-8253-1F6D8AEE02E2}
+ Exe
+ MakeIcon
+ MakeIcon
+ v4.8
+ 512
+ true
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ pdbonly
+ true
+ ..\Build\CommandLineTools\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\GerberLibrary\bin\Release\GerberLibrary.dll
+
+
+
+
+
+
+
+
+
+
+ ..\Project_Utilities\TilingLibrary\bin\Release\TINRS-Artwork.dll
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/MakeIcon/Program.cs b/MakeIcon/Program.cs
new file mode 100644
index 0000000..18388a1
--- /dev/null
+++ b/MakeIcon/Program.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MakeIcon
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ if (args.Count() < 3)
+ {
+ Console.WriteLine("MakeIcon