mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 21:43:43 +00:00
API: Implement dimension serialization
This commit is contained in:
parent
d6df4dc341
commit
13625daeca
api/proto/board
common
pcbnew
qa/tests/api
@ -666,6 +666,53 @@ message CenterDimensionAttributes
|
||||
kiapi.common.types.Vector2 end = 2;
|
||||
}
|
||||
|
||||
enum DimensionUnitFormat
|
||||
{
|
||||
DUF_UNKNOWN = 0;
|
||||
DUF_NO_SUFFIX = 1;
|
||||
DUF_BARE_SUFFIX = 2;
|
||||
DUF_PAREN_SUFFIX = 3;
|
||||
}
|
||||
|
||||
enum DimensionArrowDirection
|
||||
{
|
||||
DAD_UNKNOWN = 0;
|
||||
DAD_INWARD = 1;
|
||||
DAD_OUTWARD = 2;
|
||||
}
|
||||
|
||||
enum DimensionPrecision
|
||||
{
|
||||
DP_UNKNOWN = 0;
|
||||
DP_FIXED_0 = 1; // No digits after decimal point
|
||||
DP_FIXED_1 = 2; // 1 digit after decimal point
|
||||
DP_FIXED_2 = 3; // 2 digits after decimal point
|
||||
DP_FIXED_3 = 4; // 3 digits after decimal point
|
||||
DP_FIXED_4 = 5; // 4 digits after decimal point
|
||||
DP_FIXED_5 = 6; // 5 digits after decimal point
|
||||
DP_SCALED_IN_2 = 7; // Precision depends on unit selection; 2 digits for inches, 0 for mils, 1 for mm
|
||||
DP_SCALED_IN_3 = 8; // Precision depends on unit selection; 3 digits for inches, 0 for mils, 2 for mm
|
||||
DP_SCALED_IN_4 = 9; // Precision depends on unit selection; 4 digits for inches, 1 for mils, 3 for mm
|
||||
DP_SCALED_IN_5 = 10; // Precision depends on unit selection; 5 digits for inches, 2 for mils, 4 for mm
|
||||
}
|
||||
|
||||
enum DimensionTextPosition
|
||||
{
|
||||
DTP_UNKNOWN = 0;
|
||||
DTP_OUTSIDE = 1;
|
||||
DTP_INLINE = 2;
|
||||
DTP_MANUAL = 3;
|
||||
}
|
||||
|
||||
enum DimensionUnit
|
||||
{
|
||||
DU_UNKNOWN = 0;
|
||||
DU_INCHES = 1;
|
||||
DU_MILS = 2;
|
||||
DU_MILLIMETERS = 3;
|
||||
DU_AUTOMATIC = 4;
|
||||
}
|
||||
|
||||
// A dimension in KiCad is a special type of text object.
|
||||
// To know the visual appearance of the dimension as rendered by KiCad, use GetTextAsShapes
|
||||
message Dimension
|
||||
@ -682,6 +729,22 @@ message Dimension
|
||||
LeaderDimensionAttributes leader = 8;
|
||||
CenterDimensionAttributes center = 9;
|
||||
}
|
||||
|
||||
bool override_text_enabled = 10;
|
||||
string override_text = 11;
|
||||
string prefix = 12;
|
||||
string suffix = 13;
|
||||
DimensionUnit unit = 14;
|
||||
DimensionUnitFormat unit_format = 15;
|
||||
DimensionArrowDirection arrow_direction = 16;
|
||||
DimensionPrecision precision = 17;
|
||||
bool suppress_trailing_zeroes = 18;
|
||||
|
||||
kiapi.common.types.Distance line_thickness = 19;
|
||||
kiapi.common.types.Distance arrow_length = 20;
|
||||
kiapi.common.types.Distance extension_offset = 21;
|
||||
DimensionTextPosition text_position = 22;
|
||||
bool keep_text_aligned = 23;
|
||||
}
|
||||
|
||||
message ReferenceImage
|
||||
|
@ -189,6 +189,7 @@ void EDA_TEXT::Serialize( google::protobuf::Any &aContainer ) const
|
||||
|
||||
text.set_text( GetText().ToStdString() );
|
||||
text.set_hyperlink( GetHyperlink().ToStdString() );
|
||||
PackVector2( *text.mutable_position(), GetTextPos() );
|
||||
|
||||
types::TextAttributes* attrs = text.mutable_attributes();
|
||||
|
||||
@ -211,8 +212,7 @@ void EDA_TEXT::Serialize( google::protobuf::Any &aContainer ) const
|
||||
attrs->set_mirrored( IsMirrored() );
|
||||
attrs->set_multiline( IsMultilineAllowed() );
|
||||
attrs->set_keep_upright( IsKeepUpright() );
|
||||
attrs->mutable_size()->set_x_nm( GetTextSize().x );
|
||||
attrs->mutable_size()->set_y_nm( GetTextSize().y );
|
||||
PackVector2( *attrs->mutable_size(), GetTextSize() );
|
||||
|
||||
aContainer.PackFrom( text );
|
||||
}
|
||||
@ -228,6 +228,7 @@ bool EDA_TEXT::Deserialize( const google::protobuf::Any &aContainer )
|
||||
|
||||
SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
|
||||
SetHyperlink( wxString( text.hyperlink().c_str(), wxConvUTF8 ) );
|
||||
SetTextPos( UnpackVector2( text.position() ) );
|
||||
|
||||
if( text.has_attributes() )
|
||||
{
|
||||
@ -240,7 +241,7 @@ bool EDA_TEXT::Deserialize( const google::protobuf::Any &aContainer )
|
||||
attrs.m_Mirrored = text.attributes().mirrored();
|
||||
attrs.m_Multiline = text.attributes().multiline();
|
||||
attrs.m_KeepUpright = text.attributes().keep_upright();
|
||||
attrs.m_Size = VECTOR2I( text.attributes().size().x_nm(), text.attributes().size().y_nm() );
|
||||
attrs.m_Size = UnpackVector2( text.attributes().size() );
|
||||
|
||||
if( !text.attributes().font_name().empty() )
|
||||
{
|
||||
|
@ -477,4 +477,178 @@ DIM_TEXT_BORDER FromProtoEnum( types::DimensionTextBorderStyle aValue )
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::DimensionUnitFormat ToProtoEnum( DIM_UNITS_FORMAT aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case DIM_UNITS_FORMAT::NO_SUFFIX: return types::DimensionUnitFormat::DUF_NO_SUFFIX;
|
||||
case DIM_UNITS_FORMAT::BARE_SUFFIX: return types::DimensionUnitFormat::DUF_BARE_SUFFIX;
|
||||
case DIM_UNITS_FORMAT::PAREN_SUFFIX: return types::DimensionUnitFormat::DUF_PAREN_SUFFIX;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::DimensionUnitFormat::DUF_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<DIM_UNITS_FORMAT>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
DIM_UNITS_FORMAT FromProtoEnum( types::DimensionUnitFormat aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::DimensionUnitFormat::DUF_NO_SUFFIX: return DIM_UNITS_FORMAT::NO_SUFFIX;
|
||||
case types::DimensionUnitFormat::DUF_BARE_SUFFIX: return DIM_UNITS_FORMAT::BARE_SUFFIX;
|
||||
case types::DimensionUnitFormat::DUF_PAREN_SUFFIX: return DIM_UNITS_FORMAT::PAREN_SUFFIX;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, DIM_UNITS_FORMAT::NO_SUFFIX,
|
||||
"Unhandled case in FromProtoEnum<types::DimensionUnitFormat>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::DimensionArrowDirection ToProtoEnum( DIM_ARROW_DIRECTION aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case DIM_ARROW_DIRECTION::INWARD: return types::DimensionArrowDirection::DAD_INWARD;
|
||||
case DIM_ARROW_DIRECTION::OUTWARD: return types::DimensionArrowDirection::DAD_OUTWARD;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::DimensionArrowDirection::DAD_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<DIM_ARROW_DIRECTION>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
DIM_ARROW_DIRECTION FromProtoEnum( types::DimensionArrowDirection aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::DimensionArrowDirection::DAD_INWARD: return DIM_ARROW_DIRECTION::INWARD;
|
||||
case types::DimensionArrowDirection::DAD_OUTWARD: return DIM_ARROW_DIRECTION::OUTWARD;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, DIM_ARROW_DIRECTION::OUTWARD,
|
||||
"Unhandled case in FromProtoEnum<types::DimensionArrowDirection>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::DimensionPrecision ToProtoEnum( DIM_PRECISION aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case DIM_PRECISION::X: return types::DimensionPrecision::DP_FIXED_0;
|
||||
case DIM_PRECISION::X_X: return types::DimensionPrecision::DP_FIXED_1;
|
||||
case DIM_PRECISION::X_XX: return types::DimensionPrecision::DP_FIXED_2;
|
||||
case DIM_PRECISION::X_XXX: return types::DimensionPrecision::DP_FIXED_3;
|
||||
case DIM_PRECISION::X_XXXX: return types::DimensionPrecision::DP_FIXED_4;
|
||||
case DIM_PRECISION::X_XXXXX: return types::DimensionPrecision::DP_FIXED_5;
|
||||
case DIM_PRECISION::V_VV: return types::DimensionPrecision::DP_SCALED_IN_2;
|
||||
case DIM_PRECISION::V_VVV: return types::DimensionPrecision::DP_SCALED_IN_3;
|
||||
case DIM_PRECISION::V_VVVV: return types::DimensionPrecision::DP_SCALED_IN_4;
|
||||
case DIM_PRECISION::V_VVVVV: return types::DimensionPrecision::DP_SCALED_IN_5;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::DimensionPrecision::DP_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<DIM_PRECISION>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
DIM_PRECISION FromProtoEnum( types::DimensionPrecision aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::DimensionPrecision::DP_FIXED_0: return DIM_PRECISION::X;
|
||||
case types::DimensionPrecision::DP_FIXED_1: return DIM_PRECISION::X_X;
|
||||
case types::DimensionPrecision::DP_FIXED_2: return DIM_PRECISION::X_XX;
|
||||
case types::DimensionPrecision::DP_FIXED_3: return DIM_PRECISION::X_XXX;
|
||||
case types::DimensionPrecision::DP_FIXED_4: return DIM_PRECISION::X_XXXX;
|
||||
case types::DimensionPrecision::DP_FIXED_5: return DIM_PRECISION::X_XXXXX;
|
||||
case types::DimensionPrecision::DP_SCALED_IN_2: return DIM_PRECISION::V_VV;
|
||||
case types::DimensionPrecision::DP_SCALED_IN_3: return DIM_PRECISION::V_VVV;
|
||||
case types::DimensionPrecision::DP_SCALED_IN_4: return DIM_PRECISION::V_VVVV;
|
||||
case types::DimensionPrecision::DP_SCALED_IN_5: return DIM_PRECISION::V_VVVVV;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, DIM_PRECISION::V_VV,
|
||||
"Unhandled case in FromProtoEnum<types::DimensionPrecision>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::DimensionTextPosition ToProtoEnum( DIM_TEXT_POSITION aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case DIM_TEXT_POSITION::OUTSIDE: return types::DimensionTextPosition::DTP_OUTSIDE;
|
||||
case DIM_TEXT_POSITION::INLINE: return types::DimensionTextPosition::DTP_INLINE;
|
||||
case DIM_TEXT_POSITION::MANUAL: return types::DimensionTextPosition::DTP_MANUAL;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::DimensionTextPosition::DTP_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<DIM_TEXT_POSITION>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
DIM_TEXT_POSITION FromProtoEnum( types::DimensionTextPosition aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::DimensionTextPosition::DTP_OUTSIDE: return DIM_TEXT_POSITION::OUTSIDE;
|
||||
case types::DimensionTextPosition::DTP_INLINE: return DIM_TEXT_POSITION::INLINE;
|
||||
case types::DimensionTextPosition::DTP_MANUAL: return DIM_TEXT_POSITION::MANUAL;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, DIM_TEXT_POSITION::OUTSIDE,
|
||||
"Unhandled case in FromProtoEnum<types::DimensionTextPosition>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
types::DimensionUnit ToProtoEnum( DIM_UNITS_MODE aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case DIM_UNITS_MODE::INCHES: return types::DimensionUnit::DU_INCHES;
|
||||
case DIM_UNITS_MODE::MILS: return types::DimensionUnit::DU_MILS;
|
||||
case DIM_UNITS_MODE::MILLIMETRES: return types::DimensionUnit::DU_MILLIMETERS;
|
||||
case DIM_UNITS_MODE::AUTOMATIC: return types::DimensionUnit::DU_AUTOMATIC;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, types::DimensionUnit::DU_UNKNOWN,
|
||||
"Unhandled case in ToProtoEnum<DIM_UNITS_MODE>");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
DIM_UNITS_MODE FromProtoEnum( types::DimensionUnit aValue )
|
||||
{
|
||||
switch( aValue )
|
||||
{
|
||||
case types::DimensionUnit::DU_INCHES: return DIM_UNITS_MODE::INCHES;
|
||||
case types::DimensionUnit::DU_MILS: return DIM_UNITS_MODE::MILS;
|
||||
case types::DimensionUnit::DU_MILLIMETERS: return DIM_UNITS_MODE::MILLIMETRES;
|
||||
case types::DimensionUnit::DU_AUTOMATIC: return DIM_UNITS_MODE::AUTOMATIC;
|
||||
|
||||
default:
|
||||
wxCHECK_MSG( false, DIM_UNITS_MODE::AUTOMATIC,
|
||||
"Unhandled case in FromProtoEnum<types::DimensionUnit>" );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Adding something new here? Add it to test_api_enums.cpp!
|
||||
|
@ -256,10 +256,11 @@ double PCB_DIMENSION_BASE::Similarity( const BOARD_ITEM& aOther ) const
|
||||
void PCB_DIMENSION_BASE::Serialize( google::protobuf::Any &aContainer ) const
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
kiapi::board::types::Dimension dimension;
|
||||
using namespace kiapi::board::types;
|
||||
Dimension dimension;
|
||||
|
||||
dimension.mutable_id()->set_value( m_Uuid.AsStdString() );
|
||||
dimension.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
|
||||
dimension.set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( GetLayer() ) );
|
||||
dimension.set_locked( IsLocked() ? types::LockedState::LS_LOCKED
|
||||
: types::LockedState::LS_UNLOCKED );
|
||||
|
||||
@ -268,7 +269,27 @@ void PCB_DIMENSION_BASE::Serialize( google::protobuf::Any &aContainer ) const
|
||||
any.UnpackTo( dimension.mutable_text() );
|
||||
|
||||
types::Text* text = dimension.mutable_text();
|
||||
PackVector2( *text->mutable_position(), GetPosition() );
|
||||
text->set_text( GetValueText() );
|
||||
|
||||
dimension.set_override_text_enabled( m_overrideTextEnabled );
|
||||
dimension.set_override_text( m_valueString.ToUTF8() );
|
||||
dimension.set_prefix( m_prefix.ToUTF8() );
|
||||
dimension.set_suffix( m_suffix.ToUTF8() );
|
||||
|
||||
dimension.set_unit( ToProtoEnum<DIM_UNITS_MODE, DimensionUnit>( GetUnitsMode() ) );
|
||||
dimension.set_unit_format(
|
||||
ToProtoEnum<DIM_UNITS_FORMAT, DimensionUnitFormat>( m_unitsFormat ) );
|
||||
dimension.set_arrow_direction(
|
||||
ToProtoEnum<DIM_ARROW_DIRECTION, DimensionArrowDirection>( m_arrowDirection ) );
|
||||
dimension.set_precision( ToProtoEnum<DIM_PRECISION, DimensionPrecision>( m_precision ) );
|
||||
dimension.set_suppress_trailing_zeroes( m_suppressZeroes );
|
||||
|
||||
dimension.mutable_line_thickness()->set_value_nm( m_lineThickness );
|
||||
dimension.mutable_arrow_length()->set_value_nm( m_arrowLength );
|
||||
dimension.mutable_extension_offset()->set_value_nm( m_extensionOffset );
|
||||
dimension.set_text_position(
|
||||
ToProtoEnum<DIM_TEXT_POSITION, DimensionTextPosition>( m_textPosition ) );
|
||||
dimension.set_keep_text_aligned( m_keepTextAligned );
|
||||
|
||||
aContainer.PackFrom( dimension );
|
||||
}
|
||||
@ -290,8 +311,24 @@ bool PCB_DIMENSION_BASE::Deserialize( const google::protobuf::Any &aContainer )
|
||||
any.PackFrom( dimension.text() );
|
||||
EDA_TEXT::Deserialize( any );
|
||||
|
||||
const types::Text& text = dimension.text();
|
||||
SetPosition( UnpackVector2( text.position() ) );
|
||||
SetOverrideTextEnabled( dimension.override_text_enabled() );
|
||||
SetOverrideText( wxString::FromUTF8( dimension.override_text() ) );
|
||||
SetPrefix( wxString::FromUTF8( dimension.prefix() ) );
|
||||
SetSuffix( wxString::FromUTF8( dimension.suffix() ) );
|
||||
|
||||
SetUnitsMode( FromProtoEnum<DIM_UNITS_MODE>( dimension.unit() ) );
|
||||
SetUnitsFormat( FromProtoEnum<DIM_UNITS_FORMAT>( dimension.unit_format() ) );
|
||||
SetArrowDirection( FromProtoEnum<DIM_ARROW_DIRECTION>( dimension.arrow_direction() ) );
|
||||
SetPrecision( FromProtoEnum<DIM_PRECISION>( dimension.precision() ) );
|
||||
SetSuppressZeroes( dimension.suppress_trailing_zeroes() );
|
||||
|
||||
SetLineThickness( dimension.line_thickness().value_nm() );
|
||||
SetArrowLength( dimension.arrow_length().value_nm() );
|
||||
SetExtensionOffset( dimension.extension_offset().value_nm() );
|
||||
SetTextPositionMode( FromProtoEnum<DIM_TEXT_POSITION>( dimension.text_position() ) );
|
||||
SetKeepTextAligned( dimension.keep_text_aligned() );
|
||||
|
||||
Update();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -771,6 +808,47 @@ EDA_ITEM* PCB_DIM_ALIGNED::Clone() const
|
||||
}
|
||||
|
||||
|
||||
void PCB_DIM_ALIGNED::Serialize( google::protobuf::Any &aContainer ) const
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
kiapi::board::types::Dimension dimension;
|
||||
|
||||
PCB_DIMENSION_BASE::Serialize( aContainer );
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
PackVector2( *dimension.mutable_aligned()->mutable_start(), m_start );
|
||||
PackVector2( *dimension.mutable_aligned()->mutable_end(), m_end );
|
||||
dimension.mutable_aligned()->mutable_height()->set_value_nm( m_height );
|
||||
dimension.mutable_aligned()->mutable_extension_height()->set_value_nm( m_extensionHeight );
|
||||
|
||||
aContainer.PackFrom( dimension );
|
||||
}
|
||||
|
||||
|
||||
bool PCB_DIM_ALIGNED::Deserialize( const google::protobuf::Any &aContainer )
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
|
||||
if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
|
||||
return false;
|
||||
|
||||
kiapi::board::types::Dimension dimension;
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
if( !dimension.has_aligned() )
|
||||
return false;
|
||||
|
||||
SetStart( UnpackVector2( dimension.aligned().start() ) );
|
||||
SetEnd( UnpackVector2( dimension.aligned().end() ) );
|
||||
SetHeight( dimension.aligned().height().value_nm());
|
||||
SetExtensionHeight( dimension.aligned().extension_height().value_nm() );
|
||||
|
||||
Update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PCB_DIM_ALIGNED::swapData( BOARD_ITEM* aImage )
|
||||
{
|
||||
wxASSERT( aImage->Type() == Type() );
|
||||
@ -950,6 +1028,53 @@ EDA_ITEM* PCB_DIM_ORTHOGONAL::Clone() const
|
||||
}
|
||||
|
||||
|
||||
void PCB_DIM_ORTHOGONAL::Serialize( google::protobuf::Any &aContainer ) const
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
kiapi::board::types::Dimension dimension;
|
||||
|
||||
PCB_DIMENSION_BASE::Serialize( aContainer );
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
PackVector2( *dimension.mutable_orthogonal()->mutable_start(), m_start );
|
||||
PackVector2( *dimension.mutable_orthogonal()->mutable_end(), m_end );
|
||||
dimension.mutable_orthogonal()->mutable_height()->set_value_nm( m_height );
|
||||
dimension.mutable_orthogonal()->mutable_extension_height()->set_value_nm( m_extensionHeight );
|
||||
|
||||
dimension.mutable_orthogonal()->set_alignment( m_orientation == DIR::VERTICAL
|
||||
? types::AxisAlignment::AA_Y_AXIS
|
||||
: types::AxisAlignment::AA_X_AXIS );
|
||||
aContainer.PackFrom( dimension );
|
||||
}
|
||||
|
||||
|
||||
bool PCB_DIM_ORTHOGONAL::Deserialize( const google::protobuf::Any &aContainer )
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
|
||||
if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
|
||||
return false;
|
||||
|
||||
kiapi::board::types::Dimension dimension;
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
if( !dimension.has_orthogonal() )
|
||||
return false;
|
||||
|
||||
SetStart( UnpackVector2( dimension.orthogonal().start() ) );
|
||||
SetEnd( UnpackVector2( dimension.orthogonal().end() ) );
|
||||
SetHeight( dimension.orthogonal().height().value_nm());
|
||||
SetExtensionHeight( dimension.orthogonal().extension_height().value_nm() );
|
||||
SetOrientation( dimension.orthogonal().alignment() == types::AxisAlignment::AA_Y_AXIS
|
||||
? DIR::VERTICAL
|
||||
: DIR::HORIZONTAL );
|
||||
|
||||
Update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PCB_DIM_ORTHOGONAL::swapData( BOARD_ITEM* aImage )
|
||||
{
|
||||
wxASSERT( aImage->Type() == Type() );
|
||||
@ -1162,6 +1287,47 @@ PCB_DIM_LEADER::PCB_DIM_LEADER( BOARD_ITEM* aParent ) :
|
||||
}
|
||||
|
||||
|
||||
void PCB_DIM_LEADER::Serialize( google::protobuf::Any &aContainer ) const
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
kiapi::board::types::Dimension dimension;
|
||||
|
||||
PCB_DIMENSION_BASE::Serialize( aContainer );
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
PackVector2( *dimension.mutable_leader()->mutable_start(), m_start );
|
||||
PackVector2( *dimension.mutable_leader()->mutable_end(), m_end );
|
||||
dimension.mutable_leader()->set_border_style(
|
||||
ToProtoEnum<DIM_TEXT_BORDER, kiapi::board::types::DimensionTextBorderStyle>(
|
||||
m_textBorder ) );
|
||||
|
||||
aContainer.PackFrom( dimension );
|
||||
}
|
||||
|
||||
|
||||
bool PCB_DIM_LEADER::Deserialize( const google::protobuf::Any &aContainer )
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
|
||||
if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
|
||||
return false;
|
||||
|
||||
kiapi::board::types::Dimension dimension;
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
if( !dimension.has_leader() )
|
||||
return false;
|
||||
|
||||
SetStart( UnpackVector2( dimension.leader().start() ) );
|
||||
SetEnd( UnpackVector2( dimension.leader().end() ) );
|
||||
SetTextBorder( FromProtoEnum<DIM_TEXT_BORDER>( dimension.leader().border_style() ) );
|
||||
|
||||
Update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
EDA_ITEM* PCB_DIM_LEADER::Clone() const
|
||||
{
|
||||
return new PCB_DIM_LEADER( *this );
|
||||
@ -1303,6 +1469,45 @@ PCB_DIM_RADIAL::PCB_DIM_RADIAL( BOARD_ITEM* aParent ) :
|
||||
}
|
||||
|
||||
|
||||
void PCB_DIM_RADIAL::Serialize( google::protobuf::Any &aContainer ) const
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
kiapi::board::types::Dimension dimension;
|
||||
|
||||
PCB_DIMENSION_BASE::Serialize( aContainer );
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
PackVector2( *dimension.mutable_radial()->mutable_center(), m_start );
|
||||
PackVector2( *dimension.mutable_radial()->mutable_radius_point(), m_end );
|
||||
dimension.mutable_radial()->mutable_leader_length()->set_value_nm( m_leaderLength );
|
||||
|
||||
aContainer.PackFrom( dimension );
|
||||
}
|
||||
|
||||
|
||||
bool PCB_DIM_RADIAL::Deserialize( const google::protobuf::Any &aContainer )
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
|
||||
if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
|
||||
return false;
|
||||
|
||||
kiapi::board::types::Dimension dimension;
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
if( !dimension.has_radial() )
|
||||
return false;
|
||||
|
||||
SetStart( UnpackVector2( dimension.radial().center() ) );
|
||||
SetEnd( UnpackVector2( dimension.radial().radius_point() ) );
|
||||
SetLeaderLength( dimension.radial().leader_length().value_nm() );
|
||||
|
||||
Update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
EDA_ITEM* PCB_DIM_RADIAL::Clone() const
|
||||
{
|
||||
return new PCB_DIM_RADIAL( *this );
|
||||
@ -1410,6 +1615,43 @@ PCB_DIM_CENTER::PCB_DIM_CENTER( BOARD_ITEM* aParent ) :
|
||||
}
|
||||
|
||||
|
||||
void PCB_DIM_CENTER::Serialize( google::protobuf::Any &aContainer ) const
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
kiapi::board::types::Dimension dimension;
|
||||
|
||||
PCB_DIMENSION_BASE::Serialize( aContainer );
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
PackVector2( *dimension.mutable_center()->mutable_center(), m_start );
|
||||
PackVector2( *dimension.mutable_center()->mutable_end(), m_end );
|
||||
|
||||
aContainer.PackFrom( dimension );
|
||||
}
|
||||
|
||||
|
||||
bool PCB_DIM_CENTER::Deserialize( const google::protobuf::Any &aContainer )
|
||||
{
|
||||
using namespace kiapi::common;
|
||||
|
||||
if( !PCB_DIMENSION_BASE::Deserialize( aContainer ) )
|
||||
return false;
|
||||
|
||||
kiapi::board::types::Dimension dimension;
|
||||
aContainer.UnpackTo( &dimension );
|
||||
|
||||
if( !dimension.has_center() )
|
||||
return false;
|
||||
|
||||
SetStart( UnpackVector2( dimension.center().center() ) );
|
||||
SetEnd( UnpackVector2( dimension.center().end() ) );
|
||||
|
||||
Update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
EDA_ITEM* PCB_DIM_CENTER::Clone() const
|
||||
{
|
||||
return new PCB_DIM_CENTER( *this );
|
||||
@ -1466,6 +1708,8 @@ void PCB_DIM_CENTER::updateGeometry()
|
||||
RotatePoint( arm, -ANGLE_90 );
|
||||
|
||||
m_shapes.emplace_back( new SHAPE_SEGMENT( center - arm, center + arm ) );
|
||||
|
||||
updateText();
|
||||
}
|
||||
|
||||
|
||||
|
@ -416,6 +416,9 @@ public:
|
||||
|
||||
~PCB_DIM_ALIGNED() = default;
|
||||
|
||||
void Serialize( google::protobuf::Any &aContainer ) const override;
|
||||
bool Deserialize( const google::protobuf::Any &aContainer ) override;
|
||||
|
||||
static inline bool ClassOf( const EDA_ITEM* aItem )
|
||||
{
|
||||
return aItem && aItem->Type() == PCB_DIM_ALIGNED_T;
|
||||
@ -514,6 +517,9 @@ public:
|
||||
|
||||
~PCB_DIM_ORTHOGONAL() = default;
|
||||
|
||||
void Serialize( google::protobuf::Any &aContainer ) const override;
|
||||
bool Deserialize( const google::protobuf::Any &aContainer ) override;
|
||||
|
||||
static inline bool ClassOf( const EDA_ITEM* aItem )
|
||||
{
|
||||
return aItem && aItem->Type() == PCB_DIM_ORTHOGONAL_T;
|
||||
@ -578,6 +584,9 @@ class PCB_DIM_RADIAL : public PCB_DIMENSION_BASE
|
||||
public:
|
||||
PCB_DIM_RADIAL( BOARD_ITEM* aParent );
|
||||
|
||||
void Serialize( google::protobuf::Any &aContainer ) const override;
|
||||
bool Deserialize( const google::protobuf::Any &aContainer ) override;
|
||||
|
||||
static inline bool ClassOf( const EDA_ITEM* aItem )
|
||||
{
|
||||
return aItem && aItem->Type() == PCB_DIM_RADIAL_T;
|
||||
@ -633,6 +642,9 @@ class PCB_DIM_LEADER : public PCB_DIMENSION_BASE
|
||||
public:
|
||||
PCB_DIM_LEADER( BOARD_ITEM* aParent );
|
||||
|
||||
void Serialize( google::protobuf::Any &aContainer ) const override;
|
||||
bool Deserialize( const google::protobuf::Any &aContainer ) override;
|
||||
|
||||
static inline bool ClassOf( const EDA_ITEM* aItem )
|
||||
{
|
||||
return aItem && aItem->Type() == PCB_DIM_LEADER_T;
|
||||
@ -680,6 +692,9 @@ class PCB_DIM_CENTER : public PCB_DIMENSION_BASE
|
||||
public:
|
||||
PCB_DIM_CENTER( BOARD_ITEM* aParent );
|
||||
|
||||
void Serialize( google::protobuf::Any &aContainer ) const override;
|
||||
bool Deserialize( const google::protobuf::Any &aContainer ) override;
|
||||
|
||||
static inline bool ClassOf( const EDA_ITEM* aItem )
|
||||
{
|
||||
return aItem && aItem->Type() == PCB_DIM_CENTER_T;
|
||||
|
@ -219,4 +219,29 @@ BOOST_AUTO_TEST_CASE( DimensionTextBorderStyle )
|
||||
testEnums<DIM_TEXT_BORDER, kiapi::board::types::DimensionTextBorderStyle>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( DimensionUnitFormat )
|
||||
{
|
||||
testEnums<DIM_UNITS_FORMAT, kiapi::board::types::DimensionUnitFormat>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( DimensionArrowDirection )
|
||||
{
|
||||
testEnums<DIM_ARROW_DIRECTION, kiapi::board::types::DimensionArrowDirection>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( DimensionPrecision )
|
||||
{
|
||||
testEnums<DIM_PRECISION, kiapi::board::types::DimensionPrecision>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( DimensionTextPosition )
|
||||
{
|
||||
testEnums<DIM_TEXT_POSITION, kiapi::board::types::DimensionTextPosition>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( DimensionUnit )
|
||||
{
|
||||
testEnums<DIM_UNITS_MODE, kiapi::board::types::DimensionUnit>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -48,7 +48,7 @@ struct PROTO_TEST_FIXTURE
|
||||
|
||||
|
||||
template<typename ProtoClass, typename KiCadClass, typename ParentClass>
|
||||
void testProtoFromKiCadObject( KiCadClass* aInput, ParentClass* aParent )
|
||||
void testProtoFromKiCadObject( KiCadClass* aInput, ParentClass* aParent, bool aStrict = true )
|
||||
{
|
||||
BOOST_TEST_CONTEXT( aInput->GetFriendlyName() << ": " << aInput->m_Uuid.AsStdString() )
|
||||
{
|
||||
@ -61,17 +61,20 @@ void testProtoFromKiCadObject( KiCadClass* aInput, ParentClass* aParent )
|
||||
BOOST_REQUIRE_MESSAGE( any.UnpackTo( &proto ),
|
||||
"Any message did not unpack into the requested type" );
|
||||
|
||||
KiCadClass output( *static_cast<KiCadClass*>( aInput->Clone() ) );
|
||||
// Not yet
|
||||
//KiCadClass output( aParent );
|
||||
std::unique_ptr<KiCadClass> output;
|
||||
|
||||
if( aStrict )
|
||||
output = std::make_unique<KiCadClass>( aParent );
|
||||
else
|
||||
output = std::make_unique<KiCadClass>( *static_cast<KiCadClass*>( aInput->Clone() ) );
|
||||
|
||||
bool deserializeResult = false;
|
||||
BOOST_REQUIRE_NO_THROW( deserializeResult = output.Deserialize( any ) );
|
||||
BOOST_REQUIRE_NO_THROW( deserializeResult = output->Deserialize( any ) );
|
||||
BOOST_REQUIRE_MESSAGE( deserializeResult, "Deserialize failed" );
|
||||
|
||||
// This round-trip checks that we can create an equivalent protobuf
|
||||
google::protobuf::Any outputAny;
|
||||
BOOST_REQUIRE_NO_THROW( output.Serialize( outputAny ) );
|
||||
BOOST_REQUIRE_NO_THROW( output->Serialize( outputAny ) );
|
||||
BOOST_TEST_MESSAGE( "Output: " << outputAny.Utf8DebugString() );
|
||||
|
||||
if( !( outputAny.SerializeAsString() == any.SerializeAsString() ) )
|
||||
@ -80,7 +83,7 @@ void testProtoFromKiCadObject( KiCadClass* aInput, ParentClass* aParent )
|
||||
}
|
||||
|
||||
// This round-trip checks that we can create an equivalent KiCad object
|
||||
if( !( output == *aInput ) )
|
||||
if( !( *output == *aInput ) )
|
||||
{
|
||||
BOOST_TEST_FAIL( "Round-tripped object does not match" );
|
||||
}
|
||||
@ -105,7 +108,10 @@ BOOST_FIXTURE_TEST_CASE( BoardTypes, PROTO_TEST_FIXTURE )
|
||||
break;
|
||||
|
||||
case PCB_VIA_T:
|
||||
testProtoFromKiCadObject<kiapi::board::types::Via>( track, m_board.get() );
|
||||
// Vias are not strict-checked at the moment because m_zoneLayerOverrides is not
|
||||
// currently exposed to the API
|
||||
// TODO(JE) enable strict when fixed
|
||||
testProtoFromKiCadObject<kiapi::board::types::Via>( track, m_board.get(), false );
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -114,7 +120,12 @@ BOOST_FIXTURE_TEST_CASE( BoardTypes, PROTO_TEST_FIXTURE )
|
||||
}
|
||||
|
||||
for( FOOTPRINT* footprint : m_board->Footprints() )
|
||||
testProtoFromKiCadObject<kiapi::board::types::FootprintInstance>( footprint, m_board.get() );
|
||||
{
|
||||
// Footprints not strict-checked at the moment because Footprint field is not in the proto
|
||||
// TODO(JE) enable strict when fixed
|
||||
testProtoFromKiCadObject<kiapi::board::types::FootprintInstance>( footprint, m_board.get(),
|
||||
false );
|
||||
}
|
||||
|
||||
for( ZONE* zone : m_board->Zones() )
|
||||
testProtoFromKiCadObject<kiapi::board::types::Zone>( zone, m_board.get() );
|
||||
@ -166,8 +177,11 @@ BOOST_FIXTURE_TEST_CASE( Padstacks, PROTO_TEST_FIXTURE )
|
||||
switch( track->Type() )
|
||||
{
|
||||
case PCB_VIA_T:
|
||||
// Vias are not strict-checked at the moment because m_zoneLayerOverrides is not
|
||||
// currently exposed to the API
|
||||
// TODO(JE) enable strict when fixed
|
||||
testProtoFromKiCadObject<kiapi::board::types::Via>( static_cast<PCB_VIA*>( track ),
|
||||
m_board.get() );
|
||||
m_board.get(), false );
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -176,7 +190,12 @@ BOOST_FIXTURE_TEST_CASE( Padstacks, PROTO_TEST_FIXTURE )
|
||||
}
|
||||
|
||||
for( FOOTPRINT* footprint : m_board->Footprints() )
|
||||
testProtoFromKiCadObject<kiapi::board::types::FootprintInstance>( footprint, m_board.get() );
|
||||
{
|
||||
// Footprints not strict-checked at the moment because Footprint field is not in the proto
|
||||
// TODO(JE) enable strict when fixed
|
||||
testProtoFromKiCadObject<kiapi::board::types::FootprintInstance>( footprint, m_board.get(),
|
||||
false );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user