KiCad - Saving Customised Settings

Hi There,

I am not sure if this is the right place for this question and would appreciate hints where to post such things in the future.

I am working on a feature which requires to save some settings and rather than creating my own little settings file I would want to use KiCad’s internal setting system. Well, I have spend now roughly 6 hours to figure out how to do that but didn’t get anywhere.

Does anyone know how the settings manager works and how to save and access customised settings?

Cheers,
Andre

You don’t necessarily need to understand how settings manager works, just look at pcbnew_settings.h/cpp for example. Find the class defining settings for the app you want to add settings to, it will extend APP_SETTINGS_BASE and just add your params there.

Then you can get settings like this

SETTINGS_MANAGER& mgr          = Pgm().GetSettingsManager();
PCBNEW_SETTINGS*  app_settings = mgr.GetAppSettings<PCBNEW_SETTINGS>();

Thanks for the hint!

I just realised that settings for eeschema are actually to a degree hard coded.

Anyway, I managed to get it working for my case. Initially I wanted a std::map<wxString, std::map<wxString, wxString>> but it wouldn’t let me.

In the end I decided to use the PARAM_WXSTRING_MAP and a normal std::map<wxString, wxString> with the value being a Jason.dump() which I convert back and forth internally.

You can save arbitrary objects in settings, just use PARAM_LAMBDA and write custom conversion logic to/from json like this

1 Like

Good point.

I’ll see how I go with my current solution as it seems less code intensive at the moment.

Are you wanting to upstream this feature into the main codebase, or is it just for your use? If you want to get it in the main code, I would suggest joining the developer list (https://launchpad.net/~kicad-developers) and sending an email describing your feature and the work so far. It is good to do that early in the design process to get feedback and make sure work isn’t being duplicated. That is also the better place to ask questions about code and the objects in it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.