hypar-io / IFC-gen

Industry Foundation Classes (IFC) code generator.
MIT License
133 stars 34 forks source link

IFC-gen

Build Status

IFC-gen is an IFC code generator for IFC2X3 and IFC4. The code generator uses ANTLR to parse the Express.g4 grammar file and generate a parser. The parser is capable of reading the IFC object model as described in EXPRESS format in IFC4.exp or IFC2X3.exp. In addition, IFC-gen uses the STEP grammar described in STEP.g4 to generate a STEP parser whose generated files are output in the target language directory. The code generator is a dotnet core project containing an interface, ILanguageGenerator, which is implemented by classes which generate code.

Source files for each target language can be found in the directory corresponding to the language's name. For example, the source code for the C# IFC library generator can be found in the /lang/csharp folder. For per-language build instruction, please see the language folder's README.

Motivation

If you work in an architecture or engineering firm writing code, or a software startup that's trying to solve problems in AEC, where do you go to find a library that reads and writes building data in an industry-standard form? Maybe you've looked at the IFC schema and, like many before you, have decided that it's "too complex" or "too heavy" for your needs. Maybe you've even gone and built your own data model to describe building elements.

As more firms build their own data models to solve the same problem, we get further away from the vision of what IFC was supposed to be. By comparison, it would be as if every software company that makes a browser decided that they were going to create their own markup and styling languages such that the website you've designed to work in one, wouldn't work in any of the others. That's crazy. It seems to me that not speaking the same language is an impediment to technological progress in AEC.

IFC-gen was created to make generating IFC-compliant software libraries easy, and to ease the updating and testing of those libraries with new releases of the IFC specification. To achieve this goal, IFC-gen has code generation at its core. What do you want to build? A Python library? An Open API specification? A GraphQL schema? Creating a generator for any of these is as easy as providing a new implementation of ILanguageGenerator.

If IFC-gen isn't exactly what you're looking for, there are a few other great IFC related projects that you might want to check out:

Schemas

IFC-gen supports the IFC2X3 and IFC4 schemas. These are represented by the IFC2X3 and IFC4 branches in this repository. If you are contributing to this repository, your change will need to be applied to both branches, unless it is a change that can only be logically applied to one branch.

Why didn't we just build support for various schemas into one branch? Differences in the schema often require differences in the grammar, which in turn generates different parsers, etc. For consumers of libraries generated by IFC-gen, this will mean different versions of libraries to parse IFC data from different schemas. This is not ideal, but our experience has shown that it is preferrable to having one library that is meant to support every version of the schema ever. Additionally, we can use git tools to do things like diff the schemas to see exactly what has changed:

git diff IFC2X3..IFC4 -- schemas/IFC.exp

Road Map

Prerequisites

Building

For 'nix

To generate the parsers: make generate To generate language code: make <language>

For Windows

make.bat

Contributing

Check out issues marked help wanted.

Creating a Language Generator

Language generators implement the ILanguageGenerator interface. You can find implementations of ILanguageGenerator in /Generators. To create your own language generator do the following:

Debugging the Parser

Due to the size of the IFC schema, debugging the parser can be painful. I recommend creating a debug.exp in the root directory that contains only the entities that you are trying to debug, then using make debug_parser. This make step will generate the parser based on the debug schema, and will run IFC-gen outputting tokens to the console for debugging.