27using namespace std::placeholders;
31 std::vector<LAYER_PRESET>* aPresetList ) :
36 m_presets( aPresetList )
38 wxASSERT( aPresetList );
44 nlohmann::json ret = nlohmann::json::array();
49 {
"name", preset.name },
50 {
"activeLayer", preset.activeLayer },
51 {
"flipBoard", preset.flipBoard }
54 nlohmann::json layers = nlohmann::json::array();
57 layers.push_back(
static_cast<int>( layer ) );
59 js[
"layers"] = layers;
61 nlohmann::json renderLayers = nlohmann::json::array();
69 js[
"renderLayers"] = renderLayers;
80 if( aJson.empty() || !aJson.is_array() )
85 for(
const nlohmann::json& preset : aJson )
87 if( preset.contains(
"name" ) )
91 if( preset.contains(
"flipBoard" ) && preset.at(
"flipBoard" ).is_boolean() )
93 p.
flipBoard = preset.at(
"flipBoard" ).get<
bool>();
96 if( preset.contains(
"activeLayer" ) && preset.at(
"activeLayer" ).is_number_integer() )
98 int active = preset.at(
"activeLayer" ).get<
int>();
104 if( preset.contains(
"layers" ) && preset.at(
"layers" ).is_array() )
108 for(
const nlohmann::json& layer : preset.at(
"layers" ) )
110 if( layer.is_number_integer() )
112 int layerNum = layer.get<
int>();
120 if( preset.contains(
"renderLayers" ) && preset.at(
"renderLayers" ).is_array() )
124 for(
const nlohmann::json& layer : preset.at(
"renderLayers" ) )
126 if( layer.is_string() )
128 std::string vs = layer.get<std::string>();
144 if( !aJson.is_object() || !aJson.contains(
"layers" ) )
147 std::vector<int> newLayers;
149 for(
const nlohmann::json& layer : aJson.at(
"layers" ) )
151 wxCHECK2( layer.is_number_integer(),
continue );
155 aJson[
"layers"] = newLayers;
157 if( aJson.contains(
"activeLayer" ) )
164 static constexpr int V8_GAL_LAYER_ID_START = 125;
166 if( !aJson.is_object() || !aJson.contains(
"renderLayers" ) )
169 std::vector<std::string> newLayers;
171 for(
const nlohmann::json& layer : aJson.at(
"renderLayers" ) )
173 wxCHECK2( layer.is_number_integer(),
continue );
180 aJson[
"renderLayers"] = newLayers;
189 m_viewports( aViewportList )
191 wxASSERT( aViewportList );
197 nlohmann::json ret = nlohmann::json::array();
201 nlohmann::json js = {
202 {
"name", viewport.name },
203 {
"x", viewport.rect.GetX() },
204 {
"y", viewport.rect.GetY() },
205 {
"w", viewport.rect.GetWidth() },
206 {
"h", viewport.rect.GetHeight() }
218 if( aJson.empty() || !aJson.is_array() )
223 for(
const nlohmann::json& viewport : aJson )
225 if( viewport.contains(
"name" ) )
227 VIEWPORT v( viewport.at(
"name" ).get<wxString>() );
229 if( viewport.contains(
"x" ) )
230 v.
rect.
SetX( viewport.at(
"x" ).get<
double>() );
232 if( viewport.contains(
"y" ) )
233 v.
rect.
SetY( viewport.at(
"y" ).get<
double>() );
235 if( viewport.contains(
"w" ) )
238 if( viewport.contains(
"h" ) )
248 std::vector<VIEWPORT3D>* aViewportList ) :
253 m_viewports( aViewportList )
255 wxASSERT( aViewportList );
261 nlohmann::json ret = nlohmann::json::array();
265 nlohmann::json js = {
266 {
"name", viewport.name },
267 {
"xx", viewport.matrix[0].x },
268 {
"xy", viewport.matrix[0].y },
269 {
"xz", viewport.matrix[0].z },
270 {
"xw", viewport.matrix[0].w },
271 {
"yx", viewport.matrix[1].x },
272 {
"yy", viewport.matrix[1].y },
273 {
"yz", viewport.matrix[1].z },
274 {
"yw", viewport.matrix[1].w },
275 {
"zx", viewport.matrix[2].x },
276 {
"zy", viewport.matrix[2].y },
277 {
"zz", viewport.matrix[2].z },
278 {
"zw", viewport.matrix[2].w },
279 {
"wx", viewport.matrix[3].x },
280 {
"wy", viewport.matrix[3].y },
281 {
"wz", viewport.matrix[3].z },
282 {
"ww", viewport.matrix[3].w }
294 if( aJson.empty() || !aJson.is_array() )
299 for(
const nlohmann::json& viewport : aJson )
301 if( viewport.contains(
"name" ) )
303 VIEWPORT3D v( viewport.at(
"name" ).get<wxString>() );
305 if( viewport.contains(
"xx" ) )
306 v.
matrix[0].x = viewport.at(
"xx" ).get<
double>();
308 if( viewport.contains(
"xy" ) )
309 v.
matrix[0].y = viewport.at(
"xy" ).get<
double>();
311 if( viewport.contains(
"xz" ) )
312 v.
matrix[0].z = viewport.at(
"xz" ).get<
double>();
314 if( viewport.contains(
"xw" ) )
315 v.
matrix[0].w = viewport.at(
"xw" ).get<
double>();
317 if( viewport.contains(
"yx" ) )
318 v.
matrix[1].x = viewport.at(
"yx" ).get<
double>();
320 if( viewport.contains(
"yy" ) )
321 v.
matrix[1].y = viewport.at(
"yy" ).get<
double>();
323 if( viewport.contains(
"yz" ) )
324 v.
matrix[1].z = viewport.at(
"yz" ).get<
double>();
326 if( viewport.contains(
"yw" ) )
327 v.
matrix[1].w = viewport.at(
"yw" ).get<
double>();
329 if( viewport.contains(
"zx" ) )
330 v.
matrix[2].x = viewport.at(
"zx" ).get<
double>();
332 if( viewport.contains(
"zy" ) )
333 v.
matrix[2].y = viewport.at(
"zy" ).get<
double>();
335 if( viewport.contains(
"zz" ) )
336 v.
matrix[2].z = viewport.at(
"zz" ).get<
double>();
338 if( viewport.contains(
"zw" ) )
339 v.
matrix[2].w = viewport.at(
"zw" ).get<
double>();
341 if( viewport.contains(
"wx" ) )
342 v.
matrix[3].x = viewport.at(
"wx" ).get<
double>();
344 if( viewport.contains(
"wy" ) )
345 v.
matrix[3].y = viewport.at(
"wy" ).get<
double>();
347 if( viewport.contains(
"wz" ) )
348 v.
matrix[3].z = viewport.at(
"wz" ).get<
double>();
350 if( viewport.contains(
"ww" ) )
351 v.
matrix[3].w = viewport.at(
"ww" ).get<
double>();
360 std::vector<LAYER_PAIR_INFO>& aLayerPairInfos ) :
365 m_layerPairInfos( aLayerPairInfos )
372 nlohmann::json ret = nlohmann::json::array();
376 const LAYER_PAIR& pair = pairInfo.GetLayerPair();
377 nlohmann::json js = {
380 {
"enabled", pairInfo.IsEnabled() },
383 if( pairInfo.GetName().has_value() )
385 js[
"name"] = pairInfo.GetName().value();
388 ret.push_back( std::move( js ) );
397 if( aJson.empty() || !aJson.is_array() )
402 for(
const nlohmann::json& pairJson : aJson )
404 if( pairJson.contains(
"topLayer" ) && pairJson.contains(
"bottomLayer" ) )
410 if( pairJson.contains(
"enabled" ) )
411 enabled = pairJson.at(
"enabled" ).get<
bool>();
413 std::optional<wxString>
name;
414 if( pairJson.contains(
"name" ) )
415 name = pairJson.at(
"name" ).get<wxString>();
BASE_SET & reset(size_t pos)
BASE_SET & set(size_t pos)
constexpr void SetHeight(size_type val)
constexpr void SetWidth(size_type val)
constexpr void SetX(coord_type val)
constexpr void SetY(coord_type val)
All information about a layer pair as stored in the layer pair store.
PCB_LAYER_ID GetLayerA() const
PCB_LAYER_ID GetLayerB() const
Like a normal param, but with custom getter and setter functions.
nlohmann::json layerPairsToJson()
void jsonToLayerPairs(const nlohmann::json &aJson)
std::vector< LAYER_PAIR_INFO > & m_layerPairInfos
PARAM_LAYER_PAIRS(const std::string &aPath, std::vector< LAYER_PAIR_INFO > &m_layerPairInfos)
static void MigrateToV9Layers(nlohmann::json &aJson)
static void MigrateToNamedRenderLayers(nlohmann::json &aJson)
nlohmann::json presetsToJson()
PARAM_LAYER_PRESET(const std::string &aPath, std::vector< LAYER_PRESET > *aPresetList)
std::vector< LAYER_PRESET > * m_presets
void jsonToPresets(const nlohmann::json &aJson)
void jsonToViewports(const nlohmann::json &aJson)
PARAM_VIEWPORT3D(const std::string &aPath, std::vector< VIEWPORT3D > *aViewportList)
nlohmann::json viewportsToJson()
std::vector< VIEWPORT3D > * m_viewports
std::vector< VIEWPORT > * m_viewports
PARAM_VIEWPORT(const std::string &aPath, std::vector< VIEWPORT > *aViewportList)
nlohmann::json viewportsToJson()
void jsonToViewports(const nlohmann::json &aJson)
PCB_LAYER_ID BoardLayerFromLegacyId(int aLegacyId)
Retrieve a layer ID from an integer converted from a legacy (pre-V9) enum value.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
PCB_LAYER_ID
A quick note on layer IDs:
std::optional< VISIBILITY_LAYER > VisibilityLayerFromRenderLayer(GAL_LAYER_ID aLayerId)
std::string VisibilityLayerToString(VISIBILITY_LAYER aLayerId)
std::optional< GAL_LAYER_ID > RenderLayerFromVisbilityString(const std::string &aLayer)
A saved set of layers that are visible.
GAL_SET renderLayers
Render layers (e.g. object types) that are visible.
bool flipBoard
True if the flip board is enabled.
LSET layers
Board layers that are visible.
PCB_LAYER_ID activeLayer
Optional layer to set active when this preset is loaded.