From 20b6d5e63665bcabefc9330e81ed10af50f06c4e Mon Sep 17 00:00:00 2001 From: Silas Fernandes Date: Sun, 20 Jan 2019 22:10:53 -0200 Subject: [PATCH] #GerberPanelizer: - Added option to use relative path to Gerbers folder based in *.gerberset file path; - Added option to remove mouse bite holes of instance; - Some simple improvements for better usability. #GerberLibrary: - Added dummy aperture when silk is processed by board clipping. #GerberViewer: - Changed library version to remove compilation error. --- .../Artwork Related/GerberArtWriter.cs | 7 + GerberLibrary/Core/GerberPanel.cs | 109 ++++++++- GerberPanelizer/GerberPanelize.cs | 5 + GerberPanelizer/InstanceDialog.Designer.cs | 218 +++++++++--------- GerberPanelizer/InstanceDialog.cs | 15 +- GerberPanelizer/InstanceDialog.resx | 2 +- GerberPanelizer/PanelProperties.Designer.cs | 134 ++++++----- GerberPanelizer/PanelProperties.cs | 2 + GerberViewer/GerberViewer.csproj | 14 +- 9 files changed, 323 insertions(+), 183 deletions(-) diff --git a/GerberLibrary/Artwork Related/GerberArtWriter.cs b/GerberLibrary/Artwork Related/GerberArtWriter.cs index 5a36259..40ded4f 100644 --- a/GerberLibrary/Artwork Related/GerberArtWriter.cs +++ b/GerberLibrary/Artwork Related/GerberArtWriter.cs @@ -2202,6 +2202,13 @@ public void Write(string p, double rectx = -1, double recty = -1) } } + if (Apts.Count == 0) { // Add dummy aperture + GerberApertureType Apt = new GerberApertureType(); + Apt.ID = 10; + Apt.SetCircle(0.00100076); + lines.Add(Apt.BuildGerber(GNF)); + } + foreach (var a in Polygons) { if (a.Vertices.Count > 2) diff --git a/GerberLibrary/Core/GerberPanel.cs b/GerberLibrary/Core/GerberPanel.cs index 4935f20..ca84e82 100644 --- a/GerberLibrary/Core/GerberPanel.cs +++ b/GerberLibrary/Core/GerberPanel.cs @@ -1347,7 +1347,7 @@ private void FindOutlineIntersections() // t.Errors.Add("inside a polygon!"); // t.Valid = false; } - if (TheSet.DoNotGenerateMouseBites == false) BuildDrillsForTabAndPolyLine(t, c, b.OffsetOutlines[i]); + if (!TheSet.DoNotGenerateMouseBites && !b.RemoveMouseBites) BuildDrillsForTabAndPolyLine(t, c, b.OffsetOutlines[i]); //bool inside = false; //bool newinside = false; @@ -1680,16 +1680,84 @@ public void SaveFile(string FileName) // Create a new file stream to write the serialized object to a file TextWriter WriteFileStream = new StreamWriter(FileName); - SerializerObj.Serialize(WriteFileStream, TheSet); + + if (TheSet.UseRelativePath) + { + GerberLayoutSet tempSet; + + using (MemoryStream Mems = new MemoryStream()) + { + XmlSerializer Serializer = new XmlSerializer(typeof(GerberLayoutSet)); + Serializer.Serialize(Mems, TheSet); + Mems.Seek(0, SeekOrigin.Begin); + tempSet = (GerberLayoutSet)Serializer.Deserialize(Mems); + } + + string pathBase = Path.GetDirectoryName(FileName); + + for (int i = 0; i < tempSet.Instances.Count; i++) + { + string a = tempSet.Instances[i].GerberPath; + + a = GetRelativePath(pathBase, a); + + tempSet.Instances[i].GerberPath = a; + } + + for (int i = 0; i < tempSet.LoadedOutlines.Count; i++) + { + string a = tempSet.LoadedOutlines[i]; + + a = GetRelativePath(pathBase, a); + + tempSet.LoadedOutlines[i] = a; + } + + SerializerObj.Serialize(WriteFileStream, tempSet); + } + else + SerializerObj.Serialize(WriteFileStream, TheSet); // Cleanup WriteFileStream.Close(); } - catch (Exception) + catch (Exception e) + { + } + } + + public static string GetRelativePath(string p_startPath, string p_fullDestinationPath) + { + string[] l_startPathParts = Path.GetFullPath(p_startPath).Trim(Path.DirectorySeparatorChar).Split(Path.DirectorySeparatorChar); + string[] l_destinationPathParts = p_fullDestinationPath.Split(Path.DirectorySeparatorChar); + + int l_sameCounter = 0; + while ((l_sameCounter < l_startPathParts.Length) && (l_sameCounter < l_destinationPathParts.Length) && l_startPathParts[l_sameCounter].Equals(l_destinationPathParts[l_sameCounter], StringComparison.InvariantCultureIgnoreCase)) + { + l_sameCounter++; + } + + if (l_sameCounter == 0) + { + return p_fullDestinationPath; // There is no relative link. + } + + System.Text.StringBuilder l_builder = new System.Text.StringBuilder(); + for (int i = l_sameCounter; i < l_startPathParts.Length; i++) + { + l_builder.Append(".." + Path.DirectorySeparatorChar); + } + + for (int i = l_sameCounter; i < l_destinationPathParts.Length; i++) { + l_builder.Append(l_destinationPathParts[i] + Path.DirectorySeparatorChar); } + + l_builder.Length--; + + return l_builder.ToString(); } public void RemoveInstance(AngledThing angledThing) @@ -1744,8 +1812,27 @@ public void LoadFile(string filename) GerberLayoutSet newset = (GerberLayoutSet)SerializerObj.Deserialize(ReadFileStream); if (newset != null) { - foreach (var a in newset.LoadedOutlines) + string path = Path.GetDirectoryName(filename); + for (int i = 0; i < newset.Instances.Count; i++) { + string a = newset.Instances[i].GerberPath; + if (!Path.IsPathRooted(a)) + { + a = Path.GetFullPath(path + Path.DirectorySeparatorChar + a); + a = a.TrimEnd(Path.DirectorySeparatorChar); + newset.Instances[i].GerberPath = a; + } + } + + for (int i = 0; i < newset.LoadedOutlines.Count; i++) + { + string a = newset.LoadedOutlines[i]; + if (!Path.IsPathRooted(a)) + { + a = Path.GetFullPath(path + Path.DirectorySeparatorChar + a); + a = a.TrimEnd(Path.DirectorySeparatorChar); + newset.LoadedOutlines[i] = a; + } AddGerberFolder(a, false); } TheSet = newset; @@ -1989,6 +2076,7 @@ public class GerberInstance : AngledThing { public string GerberPath; public bool Generated = false; + public bool RemoveMouseBites = false; [System.Xml.Serialization.XmlIgnore] public List TransformedOutlines = new List(); @@ -2080,6 +2168,7 @@ public class GerberLayoutSet public double Smoothing = 1; public double ExtraTabDrillDistance = 0; public bool ClipToOutlines = true; + public bool UseRelativePath = false; public string LastExportFolder = ""; public bool DoNotGenerateMouseBites = false; @@ -2102,7 +2191,7 @@ public List SaveTo(string OutputFolder, Dictionary 0) { - MasterBom.MergeBOM(InstanceBom, set, a.Center.X, a.Center.Y,0,0, a.Angle); + MasterBom.MergeBOM(InstanceBom, set, a.Center.X, a.Center.Y, 0, 0, a.Angle); } @@ -2148,7 +2237,7 @@ public List SaveTo(string OutputFolder, Dictionary SaveTo(string OutputFolder, Dictionary..\GerberProjects\packages\Triangle.0.0.6-Beta3\lib\net45\Triangle.dll True - - ..\GerberProjects\packages\DockPanelSuite.2.11.0\lib\net40\WeifenLuo.WinFormsUI.Docking.dll + + ..\GerberProjects\packages\DockPanelSuite.3.0.6\lib\net40\WeifenLuo.WinFormsUI.Docking.dll True - - ..\GerberProjects\packages\DockPanelSuite.ThemeVS2015.2.11.0\lib\net40\WeifenLuo.WinFormsUI.Docking.ThemeVS2015.dll + + ..\GerberProjects\packages\DockPanelSuite.ThemeVS2015.3.0.6\lib\net40\WeifenLuo.WinFormsUI.Docking.ThemeVS2015.dll True @@ -119,7 +119,9 @@ Resources.resx - + + Designer + SettingsSingleFileGenerator Settings.Designer.cs @@ -143,4 +145,4 @@ - + \ No newline at end of file