28#include <wx/translation.h>
42 true,
_HKI(
"Slot size" ) },
52 false,
_HKI(
"Operation" ) },
88 tmpl.
SetName( wxT(
"Default" ) );
98 js[
"name"] =
m_name.ToUTF8();
103 js[
"columns"] = nlohmann::json::array();
107 nlohmann::json entry;
109 entry[
"heading"] = col.m_Heading.ToUTF8();
111 entry[
"width"] = col.m_Width;
112 js[
"columns"].push_back( entry );
117 std::ofstream out( aPath.fn_str() );
122 *aError = wxString::Format(
_(
"Cannot write '%s'." ), aPath );
127 out << js.dump( 2 ) << std::endl;
134 *aError = wxString::Format(
_(
"Error writing '%s'." ), aPath );
139 catch(
const std::exception& e )
142 *aError = wxString::FromUTF8( e.what() );
159 std::ifstream in( aPath.fn_str() );
164 *aError = wxString::Format(
_(
"Cannot read '%s'." ), aPath );
172 if( !js.is_object() )
175 *aError =
_(
"Template is not a JSON object." );
180 if( js.contains(
"name" ) && js[
"name"].is_string() )
181 loaded.
m_name = wxString::FromUTF8( js[
"name"].get<std::string>() );
183 if( js.contains(
"version" ) && js[
"version"].is_number_integer() )
184 loaded.
m_version = js[
"version"].get<
int>();
186 if( js.contains(
"units" ) && js[
"units"].is_string() )
192 if( js.contains(
"precision" ) && js[
"precision"].is_number_integer() )
193 loaded.
m_precision = std::clamp( js[
"precision"].get<int>(), 0, 6 );
195 if( js.contains(
"show_totals" ) && js[
"show_totals"].is_boolean() )
198 if( js.contains(
"columns" ) && js[
"columns"].is_array() )
200 for(
const nlohmann::json& entry : js[
"columns"] )
202 if( !entry.is_object() || !entry.contains(
"id" ) || !entry[
"id"].is_string() )
208 wxString::FromUTF8( entry[
"id"].get<std::string>() ) );
216 if( entry.contains(
"heading" ) && entry[
"heading"].is_string() )
217 col.
m_Heading = wxString::FromUTF8( entry[
"heading"].get<std::string>() );
219 if( entry.contains(
"align" ) && entry[
"align"].is_string() )
225 if( entry.contains(
"width" ) && entry[
"width"].is_number_integer() )
226 col.
m_Width = entry[
"width"].get<
int>();
232 catch(
const std::exception& e )
235 *aError = wxString::FromUTF8( e.what() );
243 *aError =
_(
"Template has no usable columns." );
248 *
this = std::move( loaded );
bool SaveToFile(const wxString &aPath, wxString *aError) const
Read and write a template as JSON.
void SetName(const wxString &aName)
wxString m_name
Identify the template file to whoever opens it.
std::vector< GENERATED_TABLE_COLUMN > & Columns()
bool LoadFromFile(const wxString &aPath, wxString *aError)
GENERATED_TABLE_UNITS m_units
std::vector< GENERATED_TABLE_COLUMN > m_columns
static DRILL_CHART_TEMPLATE MakeDefault()
The columns one generator (the drill chart, a stackup table, ...) can produce, and the units and prec...
const char * Token(int aId) const
The file token for a known id, or a stable placeholder for one the schema does not recognize,...
std::vector< GENERATED_TABLE_COLUMN > Defaults() const
const GENERATED_TABLE_COLUMN_DEF * FindToken(const wxString &aToken) const
const GENERATED_TABLE_SCHEMA & DrillChartSchema()
Every column the drill chart schema knows how to build, in the order the schema lists them.
const GENERATED_TABLE_SCHEMA & DrillChartSchema()
Every column the drill chart schema knows how to build, in the order the schema lists them.
bool GeneratedTableUnitsFromToken(const wxString &aToken, GENERATED_TABLE_UNITS &aUnits)
const char * GeneratedTableUnitsToken(GENERATED_TABLE_UNITS aUnits)
Stable file tokens, independent of enum ordering so inserting a value later cannot change what an exi...
bool GeneratedTableAlignFromToken(const wxString &aToken, GENERATED_TABLE_ALIGN &aAlign)
const char * GeneratedTableAlignToken(GENERATED_TABLE_ALIGN aAlign)
Some functions to handle hotkeys in KiCad.
Which holes a chart reports on.
bool operator==(const DRILL_CHART_FILTER &aOther) const
The column a schema knows how to build, independent of whether any particular table shows it.
A column as a generated table actually carries it: what a row's cell in that column holds and how it ...
GENERATED_TABLE_ALIGN m_Align