Export PCB board to OpenEMS?


Try ‘mingw32-make’ instead of ‘make’


Thx @orsonmmz,
I have made some step further…

$ cmake -G “MinGW Makefiles” …/ -DTINYXML2_INCLUDE_DIR==…/…/…/…/…/…/mingw32/include/ -DTINYXML2_LIBRARY=…/…/…/…/mingw32/lib -DTCLAP_INCLUDE_DIR=…/…/tclap-1.2.1/include
– The C compiler identification is GNU 5.3.0
– The CXX compiler identification is GNU 5.3.0
– Check for working C compiler: C:/kicad-wb-1602/msys64/mingw64/bin/gcc.exe
– Check for working C compiler: C:/kicad-wb-1602/msys64/mingw64/bin/gcc.exe – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: C:/kicad-wb-1602/msys64/mingw64/bin/g++.exe
– Check for working CXX compiler: C:/kicad-wb-1602/msys64/mingw64/bin/g++.exe – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Boost version: 1.57.0
TinyXML2 include path: C:/kicad-wb-1602/msys64/mingw32/include
TinyXML2 lib path: C:/kicad-wb-1602/msys64/mingw32/lib
TCLAP include path: C:/kicad-wb-1602/msys64/home/userC/tclap-1.2.1/include
– Configuring done
– Generating done
– Build files have been written to: C:/kicad-wb-1602/msys64/home/userC/pcbmodelgen/build


$ mingw32-make all
Scanning dependencies of target pcbmodelgen
[ 12%] Building CXX object CMakeFiles/pcbmodelgen.dir/source/ems.cpp.obj
[ 25%] Building CXX object CMakeFiles/pcbmodelgen.dir/source/ems_prims.cpp.obj
[ 37%] Building CXX object CMakeFiles/pcbmodelgen.dir/source/kicadtoems_config.cpp.obj
[ 50%] Building CXX object CMakeFiles/pcbmodelgen.dir/source/kicadtoems_ui.cpp.obj
[ 62%] Building CXX object CMakeFiles/pcbmodelgen.dir/source/main.cpp.obj
[ 75%] Building CXX object CMakeFiles/pcbmodelgen.dir/source/srecs.cpp.obj
[ 87%] Building CXX object CMakeFiles/pcbmodelgen.dir/source/json/jsoncpp.cpp.obj
[100%] Linking CXX executable pcbmodelgen.exe
C:/kicad-wb-1602/msys64/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/5.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot find -ltinyxml2
collect2.exe: error: ld returned 1 exit status
CMakeFiles\pcbmodelgen.dir\build.make:258: recipe for target ‘pcbmodelgen.exe’ failed
mingw32-make[2]: *** [pcbmodelgen.exe] Error 1
CMakeFiles\Makefile2:66: recipe for target ‘CMakeFiles/pcbmodelgen.dir/all’ failed
mingw32-make[1]: *** [CMakeFiles/pcbmodelgen.dir/all] Error 2
Makefile:126: recipe for target ‘all’ failed
mingw32-make: *** [all] Error 2

Now my problem is the linker … it doesn’t find ‘tinyxml2’ lib, but the path seems fine

In Cmakelist.txt I have:

NAMES tinyxml2.h

NAMES tinyxml2

target_link_libraries(pcbmodelgen tinyxml2)


I think you need to change in CMakeLists.txt:

target_link_libraries(pcbmodelgen tinyxml2)
target_link_libraries(pcbmodelgen ${TINYXML2_LIBRARY})

and run cmake with path to library not only library directory.
I think I had it wrong in my initial CMakeLists.txt


my fault… I had a 32 lib instead of 64 lib…
here the cmake command I used

cmake -G “MinGW Makefiles” …/ -DTINYXML2_INCLUDE_DIR==…/…/…/…/…/…/mingw64/include/ -DTINYXML2_LIBRARY=…/…/…/…/mingw64/lib -DTCLAP_INCLUDE_DIR=…/…/tclap-1.2.1/include

and I attached the CMakelists.txt that is working for me :smiley:
CMakeLists.txt (2.5 KB)


it seems that dependencies are very little and it could be easily bundled with kicad itself…
may be it could be nice to add a Gui in kicad to select the json config file and then launch the ‘pcbmodelgen’ with parameters as it is done for kicad2step in the exporter
@orsonmmz what do you think?


I do not want to sound grumpy, but what I would really love is to make the exporter integrated in KiCad, not as an external executable (the same applies to the STEP exporter). I think this could be done without tclap, and using wxXml instead of TinyXML2, meaning there are no new dependencies.
Do not get me wrong, I think the idea is fantastic, especially that we have been thinking about adding EM simulator to KiCad for some time already. I also realize it is much faster to develop a tool outside KiCad and most likely this is the reason why @jcyrax has chosen this path. Still, I encourage to transform the tool to make it a part of KiCad, I can lend a hand if necessary.
I think you should also advertise the tool on the developers mailing list, this might be a huge benefit for the KiCad users. Well done @jcyrax, thank you for contributing to the KiCad community!


Well kicad nightly includes a step exporter. But kicad stepup will always be a bit more powerful because it has the full power of freecad behind it.

Something similar applies here. In open source there is generally the tendency to have multiple specialized tools for one job. and an easy way to transfer data between them. (This is one of the core ideas behind Linux. -> see command line pipe-lining)


I think @orsonmmz is refering to the “integrated” exporter is a seperate program being ran from inside Kicad


@orsonmmz I agree, the integration would be the logical step. I wrote external tool because I needed it fast. Also, openEMS in practice can be used only with scripts. So nice GUI export will not get you very far. You need to write simulation script, add ports etc.


I meant integrating pcbmodelgen in KiCad source code, so there is no need to launch another tool. I am familiar with the Unix way and often appreciate it, but here IMHO it is not as elegant as it could be when integrated in the source code (e.g. see the code checking whether there is kicad2step executable present).

In my imaginary, perfect world there is a clean and stable API and all exporters are compiled to shared libraries, possibly out of KiCad source tree. Due to limited manpower we take decisions that get us faster to the goal, but not always through the most elegant solutions, therefore executing external tools is also acceptable. You asked me what I think, you get what I think;)


Sure, I realize that. Your program in the current form is already very useful, therefore I am grateful for your effort.

Launching openEMS from KiCad to get the simulation results is what I find justified. I think there is no easy way to interact with it using an API, as we do e.g. with ngspice. Then, even if we could receive raw results from openEMS, then we would need to render them - that would be another big job. Exporting an XML file + simulation script should be doable with the libraries we already have. One more advantage of having the exporter integrated is you do not need to write a .kicad_pcb parser to extract the data. With the frequently modified file format it might be a serious task to keep it up-to-date.

Signal integrity with PCBNew layouts

In general, the problem with external tools becomes an issue with general user knowledge of even their mere existence. In the other direction you run into bloat and possible raising bugs in some other code. Would a plugin manager maybe be a good compromise?


A new KiCad Developer wants to go all the way :smiley:


Makes my head hurt to just read what he wants to do. :wink: This is the kind of thing that happens though because Kicad has reached ‘critical mass’ so to speak. I may not code but I’d like to think that helping new users keeps adding to that mass.


Absolutely! You concentrating on helping new users allows those of us that program to push the envelope on that front while you’re covering this one!

Thank you!


This is amazing, every few months I check if any new open source field solvers have been developed to easily analyze a routed board. I’ll happily help test this out!


Having no experience in implementation of FEM, just using it sporadically, would it be smarter to implement electric and magnetics FEM solver in FreeCAD using calculix? You could even couple it with thermal solver.

Obviously the first step would have to be to realize step export of coper layers from Kicad to FreeCAD.


I think the best direction is to go trough FreeCAD, because at some point you will need other geometry in simulation domain. Lets say enclosures etc. I don’t think implementing design of geometry in KiCAD would be practical if its already done in FreeCAD.

I see the future as:
1)export PCB to FreeCAD (include copper etc)
2)create simulation domain and meshes and anything you need and export to OpenEMS or other tool
3)run simulation in dedicated tool


I don’t think the developer of this plugin will read this forum. If you want to give input you might want to contact him via the mailing list.


Hi Janis, I agree very much…
Instead of exporting PCB to FreeCAD, the easiest option is to import PCB, tacks and pads in FreeCAD.
This would probably be a more feasible route, because it could be done entirely in python from FC and it will be based only on KiCad pcbnew file format.
FreeCAD is in fact the right environment for meshing and mechanical manipulation.

This is in fact what I did with StepUp to convert PCB and 3D models to STEP inside FreeCAD.