Short story:
- SETTINGS_MANAGER.GetColorSettings(“_builtin_classic”) crashes
import pcbnew
sm = pcbnew.GetSettingsManager()
cs = sm.GetColorSettings("_builtin_classic")
Produces:
terminate called after throwing an instance of 'std::out_of_range'
what(): _Map_base::at
Abortado
I think this is because the _builtin_classic is not yet defined. Because I can use any name found in ~/.config/kicad/7.0/colors/
Looking at the code I see COLOR_SETTINGS provides:
/**
* Constructs and returns a list of color settings objects based on the built-in color themes.
* These color settings are not backed by a file and cannot be modified by the user.
* This is expected to be called by SETTINGS_MANAGER which will take ownership of the objects
* and handle freeing them at the end of its lifetime.
* @return a list of pointers COLOR_SETTINGS objects containing the default color theme(s)
*/
static std::vector<COLOR_SETTINGS*> CreateBuiltinColorSettings();
And this is used by SETTINGS_MANAGER::loadAllColorSettings(). This member isn’t available from Python, but is used by SETTINGS_MANAGER::ReloadColorSettings(), which is available.
- SETTINGS_MANAGER::ReloadColorSettings() also crashes
import pcbnew
sm = pcbnew.GetSettingsManager()
cs = sm.ReloadColorSettings()
Produces:
/..../kicad/pcbnew/pcbnew.cpp(317): assert "process" failed in Pgm().
Segment violation
Am I missing something? I can currently compile KiCad 7 and I can do small changes to the SWIG stuff.
Long story
KiCad 7 can now really plot in color. KiCad 5/6 had a PLOT_CONTROLLER.SetColorMode(bool) that was quite useless. But now we have PCB_PLOT_PARAMS.SetBlackAndWhite(bool) that works.
But enabling colors from Python is useless because the default colors used by PCB_PLOT_PARAMS are useless (i.e. all layers white, so they are invisible).
But you can do:
sm = pcbnew.GetSettingsManager()
cs = sm.GetColorSettings()
po.SetColorSettings(cs)
po.SetBlackAndWhite(False)
And you get the user color settings. But in order to get some repeatable colors I wanted to use some of the built-in themes. Here is where I found that I couldn’t.
This isn’t high priority for me because KiBot can currently generate colored plots, but using a really complex method to decompose the layers in tracks, pads, vias, etc. giving correct colors to each part and then merging the resulting files. If the KiCad plotter can do it things will become much more simple.
P.S. Don’t tell me use the kicad-cli because I’m also doing various things that it can’t currently do, and I doubt it will ever do. One of the most relevant things is to render the solder mask similar to what you get in real life (positive and translucent)