KiCad PCB EDA Suite
Loading...
Searching...
No Matches
time_domain_parameters.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jon Evans <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <lset.h>
23#include <netclass.h>
24
27#include <nlohmann/json.hpp>
28#include <settings/parameters.h>
29
30
32
34 NESTED_SETTINGS( "time_domain_parameters", timeDomainParametersSchemaVersion, aParent,
35 aPath, false )
36{
37 auto saveViaOverrideConfigurationLine =
38 []( nlohmann::json& json_array, const DELAY_PROFILE_VIA_OVERRIDE_ENTRY& item )
39 {
40 const nlohmann::json item_json = { { "signal_layer_from", LSET::Name( item.m_SignalLayerFrom ) },
41 { "signal_layer_to", LSET::Name( item.m_SignalLayerTo ) },
42 { "via_layer_from", LSET::Name( item.m_ViaLayerFrom ) },
43 { "via_layer_to", LSET::Name( item.m_ViaLayerTo ) },
44 { "delay", item.m_Delay } };
45
46 json_array.push_back( item_json );
47 };
48
49 auto readViaOverrideConfigurationLine = []( const nlohmann::json& entry )
50 {
51 wxString signalLayerFromName = entry["signal_layer_from"];
52 int signalLayerFromId = LSET::NameToLayer( signalLayerFromName );
53
54 wxString signalLayerToName = entry["signal_layer_to"];
55 int signalLayerToId = LSET::NameToLayer( signalLayerToName );
56
57 wxString viaLayerFromName = entry["via_layer_from"];
58 int viaLayerFromId = LSET::NameToLayer( viaLayerFromName );
59
60 wxString viaLayerToName = entry["via_layer_to"];
61 int viaLayerToId = LSET::NameToLayer( viaLayerToName );
62
63 int delay = entry["delay"];
64
65 DELAY_PROFILE_VIA_OVERRIDE_ENTRY item{ static_cast<PCB_LAYER_ID>( signalLayerFromId ),
66 static_cast<PCB_LAYER_ID>( signalLayerToId ),
67 static_cast<PCB_LAYER_ID>( viaLayerFromId ),
68 static_cast<PCB_LAYER_ID>( viaLayerToId ), delay };
69
70 return item;
71 };
72
73 auto saveUserDefinedProfileConfigurationLine =
74 [&saveViaOverrideConfigurationLine]( nlohmann::json& json_array, const DELAY_PROFILE& item )
75 {
76 nlohmann::json layer_velocities = nlohmann::json::array();
77
78 for( const auto& [layerId, velocity] : item.m_LayerPropagationDelays )
79 {
80 nlohmann::json layer_json = { { "layer", LSET::Name( layerId ) }, { "delay", velocity } };
81 layer_velocities.push_back( layer_json );
82 }
83
84 nlohmann::json via_overrides = nlohmann::json::array();
85
86 for( const DELAY_PROFILE_VIA_OVERRIDE_ENTRY& viaOverride : item.m_ViaOverrides )
87 {
88 saveViaOverrideConfigurationLine( via_overrides, viaOverride );
89 }
90
91 const nlohmann::json item_json = { { "profile_name", item.m_ProfileName.ToUTF8() },
92 { "via_prop_delay", item.m_ViaPropagationDelay },
93 { "layer_delays", layer_velocities },
94 { "via_overrides", via_overrides } };
95
96 json_array.push_back( item_json );
97 };
98
99 auto readUserDefinedProfileConfigurationLine = [&readViaOverrideConfigurationLine]( const nlohmann::json& entry )
100 {
101 const wxString profileName = entry["profile_name"];
102 const int viaPropDelay = entry["via_prop_delay"];
103 std::map<PCB_LAYER_ID, int> traceDelays;
104
105 for( const nlohmann::json& layerEntry : entry["layer_delays"] )
106 {
107 if( !layerEntry.is_object() || !layerEntry.contains( "layer" ) )
108 continue;
109
110 wxString layerName = layerEntry["layer"];
111 int layerId = LSET::NameToLayer( layerName );
112 const int velocity = layerEntry["delay"];
113 traceDelays[static_cast<PCB_LAYER_ID>( layerId )] = velocity;
114 }
115
116 std::vector<DELAY_PROFILE_VIA_OVERRIDE_ENTRY> viaOverrides;
117
118 for( const nlohmann::json& viaEntry : entry["via_overrides"] )
119 {
120 if( !viaEntry.is_object() || !viaEntry.contains( "signal_layer_from" ) )
121 continue;
122
123 viaOverrides.push_back( readViaOverrideConfigurationLine( viaEntry ) );
124 }
125
126 DELAY_PROFILE item{ profileName, viaPropDelay, std::move( traceDelays ), std::move( viaOverrides ) };
127
128 return item;
129 };
130
131 m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>(
132 "delay_profiles_user_defined",
133 [&]() -> nlohmann::json
134 {
135 nlohmann::json ret = nlohmann::json::array();
136
137 for( const auto& entry : m_delayProfiles )
138 saveUserDefinedProfileConfigurationLine( ret, entry );
139
140 return ret;
141 },
142 [&]( const nlohmann::json& aJson )
143 {
144 if( !aJson.is_array() )
145 return;
146
148
149 for( const nlohmann::json& entry : aJson )
150 {
151 if( !entry.is_object() || !entry.contains( "profile_name" ) )
152 continue;
153
154 m_delayProfiles.emplace_back( readUserDefinedProfileConfigurationLine( entry ) );
155 }
156 },
157 {} ) );
158}
159
160
162{
163 // Release early before destroying members
164 if( m_parent )
165 {
167 m_parent = nullptr;
168 }
169}
170
171
173{
174 /*
175 if( !std::equal( std::begin( m_netClasses ), std::end( m_netClasses ),
176 std::begin( aOther.m_netClasses ) ) )
177 return false;
178
179 if( !std::equal( std::begin( m_netClassPatternAssignments ),
180 std::end( m_netClassPatternAssignments ),
181 std::begin( aOther.m_netClassPatternAssignments ) ) )
182 return false;
183
184 if( !std::equal( std::begin( m_netClassLabelAssignments ),
185 std::end( m_netClassLabelAssignments ),
186 std::begin( aOther.m_netClassLabelAssignments ) ) )
187 return false;
188
189
190 if( !std::equal( std::begin( m_netColorAssignments ), std::end( m_netColorAssignments ),
191 std::begin( aOther.m_netColorAssignments ) ) )
192 return false;
193 */
194
195 return true;
196}
Helper functions and common defines between schematic and PCB Archive files.
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
static int NameToLayer(wxString &aName)
Return the layer number from a layer name.
Definition: lset.cpp:117
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:188
NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
JSON_SETTINGS * m_parent
A pointer to the parent object to load and store from.
Like a normal param, but with custom getter and setter functions.
Definition: parameters.h:295
TIME_DOMAIN_PARAMETERS stores the configuration for time-domain tuning.
bool operator==(const TIME_DOMAIN_PARAMETERS &aOther) const
TIME_DOMAIN_PARAMETERS(JSON_SETTINGS *aParent, const std::string &aPath)
std::vector< DELAY_PROFILE > m_delayProfiles
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
Represents a single line in the time domain configuration via overrides configuration grid.
Represents a single line in the time domain configuration net class configuration grid.
constexpr int timeDomainParametersSchemaVersion