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 }
53 nlohmann::json layers = nlohmann::json::array();
56 layers.push_back(
static_cast<int>( layer ) );
58 js[
"layers"] = layers;
60 nlohmann::json renderLayers = nlohmann::json::array();
68 js[
"renderLayers"] = renderLayers;
79 if( aJson.empty() || !aJson.is_array() )
84 for(
const nlohmann::json& preset : aJson )
86 if( preset.contains(
"name" ) )
90 if( preset.contains(
"activeLayer" ) &&
91 preset.at(
"activeLayer" ).is_number_integer() )
93 int active = preset.at(
"activeLayer" ).get<
int>();
99 if( preset.contains(
"layers" ) && preset.at(
"layers" ).is_array() )
103 for(
const nlohmann::json& layer : preset.at(
"layers" ) )
105 if( layer.is_number_integer() )
107 int layerNum = layer.get<
int>();
115 if( preset.contains(
"renderLayers" )
116 && preset.at(
"renderLayers" ).is_array() )
120 for(
const nlohmann::json& layer : preset.at(
"renderLayers" ) )
122 if( layer.is_string() )
124 std::string vs = layer.get<std::string>();
140 if( !aJson.is_object() || !aJson.contains(
"layers" ) )
143 std::vector<int> newLayers;
145 for(
const nlohmann::json& layer : aJson.at(
"layers" ) )
147 wxCHECK2( layer.is_number_integer(),
continue );
151 aJson[
"layers"] = newLayers;
153 if( aJson.contains(
"activeLayer" ) )
160 static constexpr int V8_GAL_LAYER_ID_START = 125;
162 if( !aJson.is_object() || !aJson.contains(
"renderLayers" ) )
165 std::vector<std::string> newLayers;
167 for(
const nlohmann::json& layer : aJson.at(
"renderLayers" ) )
169 wxCHECK2( layer.is_number_integer(),
continue );
176 aJson[
"renderLayers"] = newLayers;
185 m_viewports( aViewportList )
187 wxASSERT( aViewportList );
193 nlohmann::json ret = nlohmann::json::array();
197 nlohmann::json js = {
198 {
"name", viewport.name },
199 {
"x", viewport.rect.GetX() },
200 {
"y", viewport.rect.GetY() },
201 {
"w", viewport.rect.GetWidth() },
202 {
"h", viewport.rect.GetHeight() }
214 if( aJson.empty() || !aJson.is_array() )
219 for(
const nlohmann::json& viewport : aJson )
221 if( viewport.contains(
"name" ) )
223 VIEWPORT v( viewport.at(
"name" ).get<wxString>() );
225 if( viewport.contains(
"x" ) )
226 v.
rect.
SetX( viewport.at(
"x" ).get<
double>() );
228 if( viewport.contains(
"y" ) )
229 v.
rect.
SetY( viewport.at(
"y" ).get<
double>() );
231 if( viewport.contains(
"w" ) )
234 if( viewport.contains(
"h" ) )
244 std::vector<VIEWPORT3D>* aViewportList ) :
249 m_viewports( aViewportList )
251 wxASSERT( aViewportList );
257 nlohmann::json ret = nlohmann::json::array();
261 nlohmann::json js = {
262 {
"name", viewport.name },
263 {
"xx", viewport.matrix[0].x },
264 {
"xy", viewport.matrix[0].y },
265 {
"xz", viewport.matrix[0].z },
266 {
"xw", viewport.matrix[0].w },
267 {
"yx", viewport.matrix[1].x },
268 {
"yy", viewport.matrix[1].y },
269 {
"yz", viewport.matrix[1].z },
270 {
"yw", viewport.matrix[1].w },
271 {
"zx", viewport.matrix[2].x },
272 {
"zy", viewport.matrix[2].y },
273 {
"zz", viewport.matrix[2].z },
274 {
"zw", viewport.matrix[2].w },
275 {
"wx", viewport.matrix[3].x },
276 {
"wy", viewport.matrix[3].y },
277 {
"wz", viewport.matrix[3].z },
278 {
"ww", viewport.matrix[3].w }
290 if( aJson.empty() || !aJson.is_array() )
295 for(
const nlohmann::json& viewport : aJson )
297 if( viewport.contains(
"name" ) )
299 VIEWPORT3D v( viewport.at(
"name" ).get<wxString>() );
301 if( viewport.contains(
"xx" ) )
302 v.
matrix[0].x = viewport.at(
"xx" ).get<
double>();
304 if( viewport.contains(
"xy" ) )
305 v.
matrix[0].y = viewport.at(
"xy" ).get<
double>();
307 if( viewport.contains(
"xz" ) )
308 v.
matrix[0].z = viewport.at(
"xz" ).get<
double>();
310 if( viewport.contains(
"xw" ) )
311 v.
matrix[0].w = viewport.at(
"xw" ).get<
double>();
313 if( viewport.contains(
"yx" ) )
314 v.
matrix[1].x = viewport.at(
"yx" ).get<
double>();
316 if( viewport.contains(
"yy" ) )
317 v.
matrix[1].y = viewport.at(
"yy" ).get<
double>();
319 if( viewport.contains(
"yz" ) )
320 v.
matrix[1].z = viewport.at(
"yz" ).get<
double>();
322 if( viewport.contains(
"yw" ) )
323 v.
matrix[1].w = viewport.at(
"yw" ).get<
double>();
325 if( viewport.contains(
"zx" ) )
326 v.
matrix[2].x = viewport.at(
"zx" ).get<
double>();
328 if( viewport.contains(
"zy" ) )
329 v.
matrix[2].y = viewport.at(
"zy" ).get<
double>();
331 if( viewport.contains(
"zz" ) )
332 v.
matrix[2].z = viewport.at(
"zz" ).get<
double>();
334 if( viewport.contains(
"zw" ) )
335 v.
matrix[2].w = viewport.at(
"zw" ).get<
double>();
337 if( viewport.contains(
"wx" ) )
338 v.
matrix[3].x = viewport.at(
"wx" ).get<
double>();
340 if( viewport.contains(
"wy" ) )
341 v.
matrix[3].y = viewport.at(
"wy" ).get<
double>();
343 if( viewport.contains(
"wz" ) )
344 v.
matrix[3].z = viewport.at(
"wz" ).get<
double>();
346 if( viewport.contains(
"ww" ) )
347 v.
matrix[3].w = viewport.at(
"ww" ).get<
double>();
356 std::vector<LAYER_PAIR_INFO>& aLayerPairInfos ) :
361 m_layerPairInfos( aLayerPairInfos )
368 nlohmann::json ret = nlohmann::json::array();
372 const LAYER_PAIR& pair = pairInfo.GetLayerPair();
373 nlohmann::json js = {
376 {
"enabled", pairInfo.IsEnabled() },
379 if( pairInfo.GetName().has_value() )
381 js[
"name"] = pairInfo.GetName().value();
384 ret.push_back( std::move( js ) );
393 if( aJson.empty() || !aJson.is_array() )
398 for(
const nlohmann::json& pairJson : aJson )
400 if( pairJson.contains(
"topLayer" ) && pairJson.contains(
"bottomLayer" ) )
406 if( pairJson.contains(
"enabled" ) )
407 enabled = pairJson.at(
"enabled" ).get<
bool>();
409 std::optional<wxString>
name;
410 if( pairJson.contains(
"name" ) )
411 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.
LSET layers
Board layers that are visible.
PCB_LAYER_ID activeLayer
Optional layer to set active when this preset is loaded.