CADence.GerberParser.Core 1.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package CADence.GerberParser.Core --version 1.0.0
                    
NuGet\Install-Package CADence.GerberParser.Core -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CADence.GerberParser.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CADence.GerberParser.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CADence.GerberParser.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CADence.GerberParser.Core --version 1.0.0
                    
#r "nuget: CADence.GerberParser.Core, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CADence.GerberParser.Core@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CADence.GerberParser.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CADence.GerberParser.Core&version=1.0.0
                    
Install as a Cake Tool

Library Documentation

Overview

This library is a comprehensive solution for working with Gerber files and layers in PCB design. Currently, it supports 274-x. It provides a set of classes to manage various types of PCB layers, including copper layers, solder masks, silkscreen, and substrate. These layers are processed with the help of parsers and factories, which simplifies data manipulation, performing geometric calculations, and creating the final design.

Installation

To use this library, add the project to your C# solution. .NET Core 6 or later is required.

Getting Started

1. Initializing the Parser

To use the library, you need to initialize the DI containers, obtain the service for parsing the archive, get the factory service, and initialize the layers. For example:

ServiceCollectionExtensions.Initial();

Then:

List<ILayer> layers;
// path - path to the PCB data archive
using (var stream = new MemoryStream(File.ReadAllBytes(path)))
{
    var reader = ServiceCollectionExtensions.GetService<IReader>();
    var data = reader.ParseArchive(stream, Path.GetFileName(path));
    var fabric = ServiceCollectionExtensions.GetService<ILayerFabric>();
    layers = await fabric.GetLayers(data);
}

2. Creating SVG

After obtaining the layers, you can generate SVG files (back layer, front layer), for example:

var svgWriter = ServiceCollectionExtensions.GetService<IWriter>();
// layers - list of layers
// 2 - scale
// true - back layer, false - front layer
// outputPathBack - path to save the file 
svgWriter.Execute(layers, 2, true, outputPathBack);
svgWriter.Execute(layers, 2, false, outputPathFront);

This will generate SVG files and save them to the specified paths.

3. Calculating the Distance Between PCB Objects

You can calculate the distance between a hole and a pad, as well as the distance between copper traces. To do this, set the flag to true:

ExecuteAccuracy.SetExecute(true);

After that, obtain the layers with the required interface, then execute the distance calculation method:

var coppers = layers.OfType<ICopper>().ToList();
var box = CalculateAccuracyHelper.Execute(await coppers[0].GetAccuracy(),
                                          await coppers[1].GetAccuracy());
⚠️ Attention!
  • Due to the nature of the Clipper2 library and the limitations of floating-point precision (double), calculated distances may have a margin of error ranging from 0.5% to 10%, particularly in complex scenarios. Please take this into account when working with strict design constraints.
  • For simple boards (e.g., Board 1), the accuracy class is calculated quite reliably, with minor deviations typically between 0.3% and 1%.
  • For more complex boards (Board 2 to Board 5), the error margin can increase up to 10%. This is primarily due to how Clipper2 handles intricate geometry: such boards often consist of multiple sub-boards embedded within a single layout, which can lead to precision loss during boolean operations and distance calculations.

PCB Layer Previews

Board 1

<img src="svgs/outputBack1.svg" width="650"/> <img src="svgs/outputFront1.svg" width="650"/>

Board 2

<img src="svgs/outputBack2.svg" width="650"/> <img src="svgs/outputFront2.svg" width="650"/>

Board 3

<img src="svgs/outputBack3.svg" width="650"/> <img src="svgs/outputFront3.svg" width="650"/>

Board 4

<img src="svgs/outputBack4.svg" width="650"/> <img src="svgs/outputFront4.svg" width="650"/>

Board 5

<img src="svgs/outputBack5.svg" width="650"/> <img src="svgs/outputFront5.svg" width="650"/>

Nuget

📦 NuGet: CADence.Core
📦 NuGet: CADence.Abstractions

Conclusion

This library provides a powerful and flexible way to work with Gerber files and their layers. It combines parsing, rendering, and precision calculation into a simple and convenient API. Following the provided examples, you can quickly integrate it into your project and start working efficiently with PCB layers.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.