Skip to content

uia4j/uia-gerber-x2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UIA Gerber File Parser

The implementation of this API is based on Gerber Layer Format Specification - Revision 2024.05.

Current Progress

  • Gerber Layout File - All commands except AM could be written and read.

  • Gerber Job File - under development.

  • Text - Font Arial under testing.

Build

The project uses the ANTLR plugin to generate java files automatically, you need to add target/generated-sources/antlr4 in IDE build path list before building the source code.

Examples

  1. Reader

    GerberX2FileReader reader = new GerberX2FileReader(new GerberX2Visitor.Console());
    reader.run(Paths.get("samples/gerber1.gbr"));
  2. Writer

    // create a writer.
    GerberX2FileWriter writer = new GerberX2FileWriter(System.out);
    
    // set file comment.
    writer.setDescription("TEST1 - Region");
    
    // start to write (streaming)
    writer.start();
    
    // get the graphics object.
    CommonGraphics x2g = writer.getGraphics();
    
    // create a region at (0.1mm, 0.1mm)
    x2g.createRegion(writer.x(0.1), writer.y(0.1)) 
            .lineTo(writer.x(0.1), writer.y(0.5))   
            .lineTo(writer.x(0.4), null)
            .cwTo(writer.x(0.5), writer.y(0.4), null, writer.y(-0.1))
            .lineTo(writer.x(0.5), writer.y(0.1))
            .lineTo(writer.x(0.1), null);
    
    // change the polarity
    x2g.loadPolarity(false);
    
    // create a region  at (0.3mm, 0.3mm)
    x2g.createRegion(writer.x(0.3), writer.y(0.3))
            .lineTo(null, writer.y(0.4))
            .lineTo(writer.x(0.4), null)
            .lineTo(writer.x(0.4), writer.y(0.3))
            .lineTo(writer.x(0.3), null);
    
    // stop writing.
    writer.stop();
  3. Write text

    // create a writer.
    GerberX2FileWriter writer = new GerberX2FileWriter(System.out);
    writer.setXValuer(2, 6);
    writer.setYValuer(2, 6);
    
    // start to write (streaming)
    writer.start();
    
    // get the graphics object.
    CommonGraphics x2g = writer.getGraphics();
    
    // create a text graphics
    TextGraphics tg = g.createText();
    tg.text("Demo Info", writer.x(0.4), writer.y(0.4), 100);
    
    // stop writing.
    writer.stop();

    Sample

References

Copyright and License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.