26using namespace std::placeholders;
30 std::vector<LAYER_PRESET>* aPresetList ) :
35 m_presets( aPresetList )
37 wxASSERT( aPresetList );
43 nlohmann::json ret = nlohmann::json::array();
48 {
"name", preset.name },
49 {
"activeLayer", preset.activeLayer }
52 nlohmann::json layers = nlohmann::json::array();
55 layers.push_back(
static_cast<int>( layer ) );
57 js[
"layers"] = layers;
59 nlohmann::json renderLayers = nlohmann::json::array();
62 renderLayers.push_back(
static_cast<int>( layer ) );
64 js[
"renderLayers"] = renderLayers;
75 if( aJson.empty() || !aJson.is_array() )
80 for(
const nlohmann::json& preset : aJson )
82 if( preset.contains(
"name" ) )
86 if( preset.contains(
"activeLayer" ) &&
87 preset.at(
"activeLayer" ).is_number_integer() )
89 int active = preset.at(
"activeLayer" ).get<
int>();
95 if( preset.contains(
"layers" ) && preset.at(
"layers" ).is_array() )
99 for(
const nlohmann::json& layer : preset.at(
"layers" ) )
101 if( layer.is_number_integer() )
103 int layerNum = layer.get<
int>();
111 if( preset.contains(
"renderLayers" )
112 && preset.at(
"renderLayers" ).is_array() )
116 for(
const nlohmann::json& layer : preset.at(
"renderLayers" ) )
118 if( layer.is_number_integer() )
120 int layerNum = layer.get<
int>();
137 if( !aJson.is_object() || !aJson.contains(
"layers" ) )
140 std::vector<int> newLayers;
142 for(
const nlohmann::json& layer : aJson.at(
"layers" ) )
144 wxCHECK2( layer.is_number_integer(),
continue );
148 aJson[
"layers"] = newLayers;
157 m_viewports( aViewportList )
159 wxASSERT( aViewportList );
165 nlohmann::json ret = nlohmann::json::array();
169 nlohmann::json js = {
170 {
"name", viewport.name },
171 {
"x", viewport.rect.GetX() },
172 {
"y", viewport.rect.GetY() },
173 {
"w", viewport.rect.GetWidth() },
174 {
"h", viewport.rect.GetHeight() }
186 if( aJson.empty() || !aJson.is_array() )
191 for(
const nlohmann::json& viewport : aJson )
193 if( viewport.contains(
"name" ) )
195 VIEWPORT v( viewport.at(
"name" ).get<wxString>() );
197 if( viewport.contains(
"x" ) )
198 v.
rect.
SetX( viewport.at(
"x" ).get<
double>() );
200 if( viewport.contains(
"y" ) )
201 v.
rect.
SetY( viewport.at(
"y" ).get<
double>() );
203 if( viewport.contains(
"w" ) )
206 if( viewport.contains(
"h" ) )
216 std::vector<VIEWPORT3D>* aViewportList ) :
221 m_viewports( aViewportList )
223 wxASSERT( aViewportList );
229 nlohmann::json ret = nlohmann::json::array();
233 nlohmann::json js = {
234 {
"name", viewport.name },
235 {
"xx", viewport.matrix[0].x },
236 {
"xy", viewport.matrix[0].y },
237 {
"xz", viewport.matrix[0].z },
238 {
"xw", viewport.matrix[0].w },
239 {
"yx", viewport.matrix[1].x },
240 {
"yy", viewport.matrix[1].y },
241 {
"yz", viewport.matrix[1].z },
242 {
"yw", viewport.matrix[1].w },
243 {
"zx", viewport.matrix[2].x },
244 {
"zy", viewport.matrix[2].y },
245 {
"zz", viewport.matrix[2].z },
246 {
"zw", viewport.matrix[2].w },
247 {
"wx", viewport.matrix[3].x },
248 {
"wy", viewport.matrix[3].y },
249 {
"wz", viewport.matrix[3].z },
250 {
"ww", viewport.matrix[3].w }
262 if( aJson.empty() || !aJson.is_array() )
267 for(
const nlohmann::json& viewport : aJson )
269 if( viewport.contains(
"name" ) )
271 VIEWPORT3D v( viewport.at(
"name" ).get<wxString>() );
273 if( viewport.contains(
"xx" ) )
274 v.
matrix[0].x = viewport.at(
"xx" ).get<
double>();
276 if( viewport.contains(
"xy" ) )
277 v.
matrix[0].y = viewport.at(
"xy" ).get<
double>();
279 if( viewport.contains(
"xz" ) )
280 v.
matrix[0].z = viewport.at(
"xz" ).get<
double>();
282 if( viewport.contains(
"xw" ) )
283 v.
matrix[0].w = viewport.at(
"xw" ).get<
double>();
285 if( viewport.contains(
"yx" ) )
286 v.
matrix[1].x = viewport.at(
"yx" ).get<
double>();
288 if( viewport.contains(
"yy" ) )
289 v.
matrix[1].y = viewport.at(
"yy" ).get<
double>();
291 if( viewport.contains(
"yz" ) )
292 v.
matrix[1].z = viewport.at(
"yz" ).get<
double>();
294 if( viewport.contains(
"yw" ) )
295 v.
matrix[1].w = viewport.at(
"yw" ).get<
double>();
297 if( viewport.contains(
"zx" ) )
298 v.
matrix[2].x = viewport.at(
"zx" ).get<
double>();
300 if( viewport.contains(
"zy" ) )
301 v.
matrix[2].y = viewport.at(
"zy" ).get<
double>();
303 if( viewport.contains(
"zz" ) )
304 v.
matrix[2].z = viewport.at(
"zz" ).get<
double>();
306 if( viewport.contains(
"zw" ) )
307 v.
matrix[2].w = viewport.at(
"zw" ).get<
double>();
309 if( viewport.contains(
"wx" ) )
310 v.
matrix[3].x = viewport.at(
"wx" ).get<
double>();
312 if( viewport.contains(
"wy" ) )
313 v.
matrix[3].y = viewport.at(
"wy" ).get<
double>();
315 if( viewport.contains(
"wz" ) )
316 v.
matrix[3].z = viewport.at(
"wz" ).get<
double>();
318 if( viewport.contains(
"ww" ) )
319 v.
matrix[3].w = viewport.at(
"ww" ).get<
double>();
328 std::vector<LAYER_PAIR_INFO>& aLayerPairInfos ) :
333 m_layerPairInfos( aLayerPairInfos )
340 nlohmann::json ret = nlohmann::json::array();
344 const LAYER_PAIR& pair = pairInfo.GetLayerPair();
345 nlohmann::json js = {
348 {
"enabled", pairInfo.IsEnabled() },
351 if( pairInfo.GetName().has_value() )
353 js[
"name"] = pairInfo.GetName().value();
356 ret.push_back( std::move( js ) );
365 if( aJson.empty() || !aJson.is_array() )
370 for(
const nlohmann::json& pairJson : aJson )
372 if( pairJson.contains(
"topLayer" ) && pairJson.contains(
"bottomLayer" ) )
378 if( pairJson.contains(
"enabled" ) )
379 enabled = pairJson.at(
"enabled" ).get<
bool>();
381 std::optional<wxString>
name;
382 if( pairJson.contains(
"name" ) )
383 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)
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)
Retrieves 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:
A saved set of layers that are visible.
GAL_SET renderLayers
Render layers (e.g. object types) that are visible.
LSET layers
Board layers that are visible.
PCB_LAYER_ID activeLayer
Optional layer to set active when this preset is loaded.