20#ifndef API_GENERATED_TABLE_UTILS_H
21#define API_GENERATED_TABLE_UTILS_H
31#include <google/protobuf/any.pb.h>
41template <
typename MSG>
44 google::protobuf::Any tableAny;
45 aTable.PCB_TABLE::Serialize( tableAny );
46 tableAny.UnpackTo( aMsg.mutable_table() );
50 auto* proto = aMsg.add_columns();
52 using ID = std::remove_cvref_t<
decltype( proto->id() )>;
53 using ALIGN = std::remove_cvref_t<
decltype( proto->align() )>;
55 proto->set_id(
static_cast<ID>( col.m_Id + 1 ) );
56 proto->set_heading( col.m_Heading.ToStdString() );
57 proto->set_align(
static_cast<ALIGN
>(
static_cast<int>( col.m_Align ) + 1 ) );
70 for(
const auto& [row, key] : aTable.
RowKeys() )
71 ( *aMsg.mutable_row_keys() )[row] = key;
80template <
typename MSG>
83 google::protobuf::Any tableAny;
84 tableAny.PackFrom( aMsg.table() );
86 if( !aTable.PCB_TABLE::Deserialize( tableAny ) )
94 std::vector<GENERATED_TABLE_COLUMN>& columns = aTable.
Columns();
97 for(
const auto& proto : aMsg.columns() )
99 const int wireId =
static_cast<int>( proto.id() );
108 const int id = wireId - 1;
113 const int align =
static_cast<int>( proto.align() );
120 col.
m_Heading = wxString::FromUTF8( proto.heading() );
125 kiapi::common::types::Distance width;
126 width.set_value_nm( std::clamp<int64_t>( proto.width().value_nm(), 0,
129 columns.push_back( col );
139 switch( aMsg.units() )
148 for(
const auto& [row, key] : aMsg.row_keys() )
void PackGeneratedTable(const PCB_GENERATED_TABLE &aTable, MSG &aMsg)
Pack what every generated table shares into its message.
bool UnpackGeneratedTable(const MSG &aMsg, PCB_GENERATED_TABLE &aTable)
The reverse of PackGeneratedTable.
constexpr EDA_IU_SCALE pcbIUScale
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
const GENERATED_TABLE_COLUMN_DEF * Find(int aId) const
bool Validate(std::vector< GENERATED_TABLE_COLUMN > &aColumns) const
Drop a column whose id the schema does not know and a column that repeats an id already kept,...
A table whose cell text is derived from the board and rebuilt whenever it goes stale.
const std::map< int, std::string > & RowKeys() const
What each generated row reports on, by table row.
void SetPrecision(int aPrecision)
Clamped.
std::vector< GENERATED_TABLE_COLUMN > & Columns()
virtual const GENERATED_TABLE_SCHEMA & Schema() const =0
GENERATED_TABLE_UNITS GetUnits() const
void SetUnits(GENERATED_TABLE_UNITS aUnits)
LSET DocumentationLayers()
Layers a drill chart or drill map may live on.
constexpr int GENERATED_TABLE_MAX_COLUMN_WIDTH
A column can be no wider than this.
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
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