public void FixEagleDrillExportIssues(ProgressLog Logger) { List<ParsedGerber> DrillFiles = new List<ParsedGerber>(); List<Tuple<double, ParsedGerber>> DrillFilesToReload = new List<Tuple<double, ParsedGerber>>(); Bounds BB = new Bounds(); foreach (var a in PLSs) { if (a.Layer == BoardLayer.Drill) { DrillFiles.Add(a); } else { BB.AddBox(a.BoundingBox); } } foreach (var a in DrillFiles) { var b = a.BoundingBox; if (b.Width() > BB.Width() * 1.5 || b.Height() > BB.Height() * 1.5) { var MaxRatio = Math.Max(b.Width() / BB.Width(), b.Height() / BB.Height()); if (Logger != null) Logger.AddString(String.Format("Note: Really large drillfile found({0})-fix your export scripts!", a.Name)); Console.WriteLine("Note: Really large drillfile found ({0})- fix your export scripts!", a.Name); DrillFilesToReload.Add(new Tuple<double, ParsedGerber>(MaxRatio, a)); } } foreach (var a in DrillFilesToReload) { PLSs.Remove(a.Item2); var scale = 1.0; if (Double.IsInfinity(a.Item1) || Double.IsNaN(a.Item1)) { Errors.Add("Drill file size reached infinity - ignoring it"); if (Logger != null) Logger.AddString("Drill file size reached infinity - ignoring it"); } else { var R = a.Item1; while (R >= 1.5) { R /= 10; scale /= 10; } AddFileToSet(a.Item2.Name, Logger, scale); } } BoundingBox = new Bounds(); foreach (var a in PLSs) { //Console.WriteLine("Progress: Adding board {6} to box::{0:N2},{1:N2} - {2:N2},{3:N2} -> {4:N2},{5:N2}", a.BoundingBox.TopLeft.X, a.BoundingBox.TopLeft.Y, a.BoundingBox.BottomRight.X, a.BoundingBox.BottomRight.Y, a.BoundingBox.Width(), a.BoundingBox.Height(), Path.GetFileName( a.Name)); //Console.WriteLine("adding box for {0}:{1},{2}", a.Name, a.BoundingBox.Width(), a.BoundingBox.Height()); BoundingBox.AddBox(a.BoundingBox); } }
void SetXY(int x, int y) { lastX = x; lastY = y; if (Document.Gerbers.Count == 0) { return; } // if (Cache == null) return; Bounds Bounds = new Bounds(); foreach (var a in Document.Gerbers.OrderBy(xx => xx.sortindex)) { Bounds.AddBox(a.File.BoundingBox); } Graphics G = Graphics.FromImage(new Bitmap(1, 1)); float S = GetScaleAndBuildTransform(G, Bounds); var M = G.Transform.Clone(); M.Invert(); PointF[] P = new PointF[1] { new PointF(x, y) }; M.TransformPoints(P); MainForm.SetMouseCoord(P[0].X, P[0].Y); }
private void apictureBox1_Paint(object sender, PaintEventArgs e) { var G2 = e.Graphics; Bounds Bounds = new Bounds(); foreach (var a in Document.Gerbers.OrderBy(x => x.sortindex)) { Bounds.AddBox(a.File.BoundingBox); } if (Cache == null) { Cache = new Bitmap(Width, Height); Graphics G = Graphics.FromImage(Cache); GerberImageCreator.ApplyAASettings(G); GraphicsGraphicsInterface GGI = new GraphicsGraphicsInterface(G); GGI.Clear(Document.Colors.BackgroundColor); // DrawGerbersToGraphicsInterface(Bounds, GGI); } G2.DrawImage(Cache, 0, 0); GerberImageCreator.ApplyAASettings(G2); { if (Document.CrossHairActive) { if (Document.Gerbers.Count > 0) { float S = GetScaleAndBuildTransform(G2, Bounds); Color DimensionColor = Color.FromArgb(255, 255, 200); Pen P = new Pen(DimensionColor, 1.0f / S); P.DashPattern = new float[2] { 2, 2 }; G2.DrawLine(P, (float)Bounds.TopLeft.X - 1000, Document.MouseY, (float)Bounds.BottomRight.X + 1000, Document.MouseY); G2.DrawLine(P, (float)Document.MouseX, (float)Bounds.TopLeft.Y - 1000, (float)Document.MouseX, (float)Bounds.BottomRight.Y + 1000); DrawLabel(G2, Bounds.ToString(), S, 12, Color.Beige, 0, 0, (float)Bounds.TopLeft.X, (float)Bounds.TopLeft.Y, false); DrawLabel(G2, String.Format("{0:N2}", Document.MouseX - Bounds.TopLeft.X), S, 12, DimensionColor, 5, 0, (float)Document.MouseX, (float)Bounds.TopLeft.Y, DisplaySide == BoardSide.Bottom); DrawLabel(G2, String.Format("{0:N2}", Document.MouseY - Bounds.TopLeft.Y), S, 12, DimensionColor, 0, -14, (float)Bounds.TopLeft.X, (float)Document.MouseY, DisplaySide == BoardSide.Bottom); //DrawUpsideDown(G2, String.Format("{0:N2}", Document.MouseX), S, 12, Color.Yellow, 5 / S + (float)Document.MouseX, (float)Bounds.TopLeft.Y); } } } }
public Bounds GetOutlineBoundingBox() { Bounds B = new Bounds(); int i = 0; foreach (var a in PLSs) { if (a.Layer == BoardLayer.Mill || a.Layer == BoardLayer.Outline) { B.AddBox(a.BoundingBox); i++; } } if (i == 0) return BoundingBox; return B; }
public void CheckRelativeBoundingBoxes(ProgressLog Logger) { List <ParsedGerber> DrillFiles = new List <ParsedGerber>(); List <ParsedGerber> DrillFilesToReload = new List <ParsedGerber>(); Bounds BB = new Bounds(); foreach (var a in PLSs) { if (a.Layer == BoardLayer.Drill) { DrillFiles.Add(a); } else { BB.AddBox(a.BoundingBox); } } foreach (var a in DrillFiles) { if (a.BoundingBox.Intersects(BB) == false) { Errors.Add(String.Format("Drill file {0} does not seem to touch the main bounding box!", Path.GetFileName(a.Name))); if (Logger != null) { Logger.AddString(String.Format("Drill file {0} does not seem to touch the main bounding box!", Path.GetFileName(a.Name))); } PLSs.Remove(a); } } BoundingBox = new Bounds(); foreach (var a in PLSs) { // Console.WriteLine("Progress: Adding board {6} to box::{0:N2},{1:N2} - {2:N2},{3:N2} -> {4:N2},{5:N2}", a.BoundingBox.TopLeft.X, a.BoundingBox.TopLeft.Y, a.BoundingBox.BottomRight.X, a.BoundingBox.BottomRight.Y, a.BoundingBox.Width(), a.BoundingBox.Height(), Path.GetFileName(a.Name)); //Console.WriteLine("adding box for {0}:{1},{2}", a.Name, a.BoundingBox.Width(), a.BoundingBox.Height()); BoundingBox.AddBox(a.BoundingBox); } }
public ParsedGerber AddBoardToSet(ProgressLog log, MemoryStream MS, string _originalfilename, bool forcezerowidth = false, bool precombinepolygons = false, double drillscaler = 1.0) { Streams[_originalfilename] = MS; try { // string[] filesplit = originalfilename.Split('.'); // string ext = filesplit[filesplit.Count() - 1].ToLower(); var FileType = Gerber.FindFileTypeFromStream(new StreamReader(MS), _originalfilename); MS.Seek(0, SeekOrigin.Begin); if (FileType == BoardFileType.Unsupported) { if (Gerber.ExtremelyVerbose) { Console.WriteLine("Warning: {1}: files with extension {0} are not supported!", Path.GetExtension(_originalfilename), Path.GetFileName(_originalfilename)); } return(null); } ParsedGerber PLS; GerberParserState State = new GerberParserState() { PreCombinePolygons = precombinepolygons }; if (FileType == BoardFileType.Drill) { if (Gerber.ExtremelyVerbose) { Console.WriteLine("Log: Drill file: {0}", _originalfilename); } PLS = PolyLineSet.LoadExcellonDrillFileFromStream(log, new StreamReader(MS), _originalfilename, false, drillscaler); MS.Seek(0, SeekOrigin.Begin); ExcellonFile EF = new ExcellonFile(); EF.Load(log, new StreamReader(MS), drillscaler); Excellons.Add(EF); } else { if (Gerber.ExtremelyVerbose) { Console.WriteLine("Log: Gerber file: {0}", _originalfilename); } BoardSide Side = BoardSide.Unknown; BoardLayer Layer = BoardLayer.Unknown; Gerber.DetermineBoardSideAndLayer(_originalfilename, out Side, out Layer); if (Layer == BoardLayer.Outline) { forcezerowidth = true; precombinepolygons = true; } State.PreCombinePolygons = precombinepolygons; PLS = PolyLineSet.LoadGerberFileFromStream(log, new StreamReader(MS), _originalfilename, forcezerowidth, false, State); MS.Seek(0, SeekOrigin.Begin); PLS.Side = State.Side; PLS.Layer = State.Layer; if (Layer == BoardLayer.Outline) { PLS.FixPolygonWindings(); } } PLS.CalcPathBounds(); BoundingBox.AddBox(PLS.BoundingBox); Console.WriteLine("Progress: Loaded {0}: {1:N1} x {2:N1} mm", Path.GetFileName(_originalfilename), PLS.BoundingBox.BottomRight.X - PLS.BoundingBox.TopLeft.X, PLS.BoundingBox.BottomRight.Y - PLS.BoundingBox.TopLeft.Y); PLSs.Add(PLS); // } // catch (Exception) // { // } return(PLS); } catch (Exception E) { while (E != null) { Console.WriteLine("Exception adding board: {0}", E.Message); E = E.InnerException; } } return(null); }
private void Render(PnPProcDoc D, Graphics G, bool after) { G.TranslateTransform(G.ClipBounds.Width / 2, G.ClipBounds.Height / 2); TheBox.Reset(); // TheBox.FitPoint(0, 0); TheBox.AddBox(D.Box); if (idx > -1) { var rd = pnp.selectedrefdes[idx % pnp.selectedrefdes.Count()]; BOMEntry.RefDesc refd = D.B.GetRefDes(rd); if (refd != null) { TheBox.Reset(); TheBox.FitPoint(refd.x - 10, refd.y - 10); TheBox.FitPoint(refd.x + 10, refd.y + 10); } } float S = (float)Math.Min(pictureBox1.Width / (TheBox.Width()), pictureBox1.Height / (TheBox.Height())); bool TopView = false; if (PostDisplay) { TopView = D.FlipBoard ? false : true; } var C = TheBox.Center(); G.ScaleTransform(S * 0.8f, -S * 0.8f); G.TranslateTransform((float)-C.X, (float)-C.Y); RenderLayerSets(G, S, BoardSide.Both, BoardLayer.Outline, Color.Gray, true); if (pnp.bottomsilkvisible) { RenderLayerSets(G, S, BoardSide.Bottom, BoardLayer.Silk, Color.White, true); } if (pnp.topsilkvisible) { RenderLayerSets(G, S, BoardSide.Top, BoardLayer.Silk, Color.DarkGray, true); } var B = D.B; if (after) { B = D.BPost; } int curpart = 0; foreach (var p in B.DeviceTree) { foreach (var pp in p.Value.Values) { var curcol = Helpers.RefractionNormalledMaxBrightnessAndSat(curpart / p.Value.Values.Count()); curpart++; foreach (var rf in pp.RefDes) { DrawMarker(curcol, G, rf, true, S, false, pnp.selectedrefdes.Contains(rf.NameOnBoard)); } } } }
private void Render(PnPProcDoc D, Graphics G, bool after) { TheBox.Reset(); TheBox.FitPoint(0, 0); if (after) { TheBox.AddBox(D.FixSet.BoundingBox); } else { TheBox.AddBox(D.Box); } //TheBox.FitPoint(-250, -250); //TheBox.FitPoint(250, 250); if (idx > -1) { var rd = pnp.selectedrefdes[idx % pnp.selectedrefdes.Count()]; BOMEntry.RefDesc refd = D.B.GetRefDes(rd); if (after) { refd = D.BPost.GetRefDes(rd); } if (refd != null) { TheBox.Reset(); TheBox.FitPoint(refd.x - zoomfac, refd.y - zoomfac); TheBox.FitPoint(refd.x + zoomfac, refd.y + zoomfac); } } var P = pictureBox1; var Bb = TheBox; float S = Helpers.SetupMatrixForExtends(G, P, Bb, 2); MarkPoint(G, Color.Blue, "zero", 0, 0, S); MarkPoint(G, Color.Green, "zero", (float)D.FixOffset.X, (float)D.FixOffset.Y, S); RenderParts(D, after, G, BoardSide.Bottom, S); RenderLayerSets(after, G, S, BoardSide.Both, BoardLayer.Outline, Color.FromArgb(210, 4, 20, 4), false); RenderLayerSets(after, G, S, BoardSide.Both, BoardLayer.Outline, Color.Gray, true); if (pnp.bottomsilkvisible) { RenderLayerSets(after, G, S, BoardSide.Bottom, BoardLayer.Silk, Color.FromArgb(160, 160, 160), false);; RenderLayerSets(after, G, S, BoardSide.Bottom, BoardLayer.SolderMask, Color.FromArgb(100, 100, 10), false); } if (pnp.topsilkvisible) { RenderLayerSets(after, G, S, BoardSide.Top, BoardLayer.Silk, Color.FromArgb(160, 160, 160), false); RenderLayerSets(after, G, S, BoardSide.Top, BoardLayer.SolderMask, Color.FromArgb(100, 100, 10), false); } RenderParts(D, after, G, BoardSide.Top, S); var B = D.B; if (after) { B = D.BPost; } int curpart = 0; List <string> AllNames = new List <string>(); foreach (var p in B.DeviceTree) { foreach (var pp in p.Value.Values) { AllNames.Add(pp.Combined()); } } AllNames.Sort(); Font F = new Font("Arial", 3); foreach (var p in B.DeviceTree) { foreach (var pp in p.Value.Values) { int idx = AllNames.IndexOf(pp.Combined()); var curcol = Helpers.RefractionNormalledMaxBrightnessAndSat(idx / (float)AllNames.Count()); foreach (var rf in pp.RefDes) { bool active = pnp.selectedrefdes.Contains(rf.NameOnBoard); DrawMarker(curcol, G, rf, true, S, false, active); if (active) { DrawText(G, rf.NameOnBoard, new PointF((float)rf.x, (float)rf.y), new RectangleF(0, 0, 50, 20)); } } } } }
private void Glcontrol1_Paint(object sender, PaintEventArgs e) { if (!glLoaded) { return; } Bounds Bounds = new Bounds(); foreach (var a in Document.Gerbers.OrderBy(x => x.sortindex)) { Bounds.AddBox(a.File.BoundingBox); } if (VBOCacheDirty) { VBOCache.Reset(); DrawGerbersToGraphicsInterface(Bounds, VBOCache); // VBOCache.DrawLine(new Pen(Color.White, 1), Bounds.TopLeft.ToF(), Bounds.BottomRight.ToF()); VBOCache.BuildVBO(); VBOCacheDirty = false; } GLGraphicsInterface GI = new GLGraphicsInterface(0, 0, Width, Height); glcontrol1.MakeCurrent(); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Disable(EnableCap.CullFace); GL.Ortho(0, glcontrol1.Width, glcontrol1.Height, 0, -100, 100); GL.LineWidth(1.0f); //GL.Scale(0.01, 0.01, 1); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.Viewport(0, 0, glcontrol1.Width, glcontrol1.Height); Matrix4 View = Matrix4.CreateOrthographicOffCenter(0, glcontrol1.Width, glcontrol1.Height, 0, -100, 100); // GI.Clear(Color.Yellow); GI.Clear(Document.Colors.BackgroundColor); // GGI.Clear(Document.Colors.BackgroundColor); float S = GetScaleAndBuildTransform(GI, Bounds); MainShader.Bind(); var M = GI.GetGlMatrix(); GL.Uniform1(MainShader.Uniforms["linescale"].address, 1.0f / S); GL.UniformMatrix4(MainShader.Uniforms["trans"].address, false, ref M); GL.UniformMatrix4(MainShader.Uniforms["view"].address, false, ref View); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); VBOCache.RenderVBO(MainShader); MainShader.UnBind(); //DrawGerbersToGraphicsInterface(Bounds, GI); { if (Document.CrossHairActive) { if (Document.Gerbers.Count > 0) { float S2 = GetScaleAndBuildTransform(GI, Bounds); Color DimensionColor = Color.FromArgb(255, 255, 200); Pen P = new Pen(DimensionColor, 1.0f); P.DashPattern = new float[2] { 2, 2 }; GI.DrawLine(P, (float)Bounds.TopLeft.X - 1000, Document.MouseY, (float)Bounds.BottomRight.X + 1000, Document.MouseY); GI.DrawLine(P, (float)Document.MouseX, (float)Bounds.TopLeft.Y - 1000, (float)Document.MouseX, (float)Bounds.BottomRight.Y + 1000); //DrawLabel(G2, String.Format("{0:N2}", Document.MouseX - Bounds.TopLeft.X), S, 12, DimensionColor, 5, 0, (float)Document.MouseX, (float)Bounds.TopLeft.Y, DisplaySide == BoardSide.Bottom); //DrawLabel(G2, String.Format("{0:N2}", Document.MouseY - Bounds.TopLeft.Y), S, 12, DimensionColor, 0, -14, (float)Bounds.TopLeft.X, (float)Document.MouseY, DisplaySide == BoardSide.Bottom); //DrawUpsideDown(G2, String.Format("{0:N2}", Document.MouseX), S, 12, Color.Yellow, 5 / S + (float)Document.MouseX, (float)Bounds.TopLeft.Y); } } } glcontrol1.SwapBuffers(); }