/// <summary> /// Loads and processes the PNG bitmaps containing the bitmaps representing the top, drill and bottom layers. /// It generates bitmaps containing the copper layers with each available net highlighted and an HTML file to easily /// show all the found nets. /// </summary> /// <param name="topLayerFilename">Filename of the PNG file containing the top copper layer.</param> /// <param name="drillLayerFilename">Filename of the PNG file containing the drill layer.</param> /// <param name="bottomLayerFilename">Filename of the PNG file containing the bottom copper layer.</param> /// <param name="path">name of the project output. This is the name of the folder where bitmaps will be stored and the html will be path.HTML.</param> /// <param name="doHoles">True if holes should be drawn on copper layers.</param> /// <param name="doMirror">True if the bottom layer should be mirrored in the output file produced.</param> public static void ProcessDoubleLayerWithDrill(string topLayerFilename, string drillLayerFilename, string bottomLayerFilename, string path, bool doHoles, bool doMirror) { if (!File.Exists(topLayerFilename)) { Console.WriteLine($"The top layer file {topLayerFilename} was not found"); return; } if (!File.Exists(drillLayerFilename)) { Console.WriteLine($"The drill layer file {topLayerFilename} was not found"); return; } if (!File.Exists(bottomLayerFilename)) { Console.WriteLine($"The bottom layer file {topLayerFilename} was not found"); return; } var top = LoadAndScan(topLayerFilename); var drill = LoadAndScan(drillLayerFilename); var bottom = LoadAndScan(bottomLayerFilename); MonochromeBitmapAccessor topLayer = new MonochromeBitmapAccessor(topLayerFilename); MonochromeBitmapAccessor bottomLayer = new MonochromeBitmapAccessor(bottomLayerFilename); MonochromeBitmapAccessor drillLayer = new MonochromeBitmapAccessor(drillLayerFilename); DrillScanner drillScanner = new DrillScanner(drill); DrillConnector connector = new DrillConnector(top, bottom, drillScanner); connector.ComputeGlobalNet(); Directory.CreateDirectory(path); if (doHoles) { MonochromeBitmapAccessor drillPlane = new MonochromeBitmapAccessor(drillLayerFilename); Bitmap bitmap = drillPlane.Bitmap; for (int x = 0; x < drillPlane.Width; x++) { for (int y = 0; y < drillPlane.Height; y++) { if (drillPlane.PixelAt(x, y)) { topLayer.Bitmap.SetPixel(x, y, System.Drawing.Color.Black); bottomLayer.Bitmap.SetPixel(x, y, System.Drawing.Color.Black); } } } } // Generates the bitmaps with the highlighted segments. // Bottom layer is mirrored foreach (int key in connector.GetNets()) { RealBitmapGenerator topBitmap = new RealBitmapGenerator(topLayer.Bitmap); RealBitmapGenerator bottomBitmap = new RealBitmapGenerator(bottomLayer.Bitmap); foreach (var layerNet in connector.GetLayerNetsOfNet(key)) { if (layerNet.LayerId == LayerNet.TOPLAYER) { foreach (var segment in top.GetSegmentsOfNet(layerNet.NetId)) { topBitmap.DrawSegment(segment, 100); } } else { foreach (var segment in bottom.GetSegmentsOfNet(layerNet.NetId)) { bottomBitmap.DrawSegment(segment, 100); } } } int margin = 20; Bitmap full = new Bitmap( topBitmap.Width + bottomBitmap.Width + margin, topBitmap.Height); Graphics gr = Graphics.FromImage(full); gr.DrawImage( topBitmap.GetBitmap(), 0, 0, topBitmap.Width, topBitmap.Height); var bottomImage = (Bitmap)bottomBitmap.GetBitmap().Clone(); if (doMirror) { bottomImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); } gr.DrawImage( bottomImage, topBitmap.Width + margin, 0); full.Save(Path.Combine(path, $"Net_{key}.png")); } var options = new List <string>(); int line = 1; foreach (int netId in connector.GetNets()) { options.Add($"<option value=\"{path}/Net_{line}.png\">Net_{line}</option>"); line++; } File.WriteAllLines(path + ".html", GenerateHtml(path, options), Encoding.UTF8); }
/// <summary> /// Initializes a new instance of the <see cref="DrillConnector"/> class. /// This class builds the connection between nets on the top and bottom layers of the PCB by means /// of the drills layer. /// </summary> /// <param name="top">BitmapScanner of the top layer.</param> /// <param name="bottom">BitmapScanner of the bottom layer layer.</param> /// <param name="drill">DrillScanner of the drill layer.</param> public DrillConnector(BitmapScanner top, BitmapScanner bottom, DrillScanner drill) { this.top = top; this.bottom = bottom; this.drill = drill; }