Prevent setting negative pad sizes

This commit is contained in:
Jon Evans
2024-10-02 21:18:10 -04:00
parent 751627ec88
commit ed0a265aa6
6 changed files with 42 additions and 18 deletions
+6 -3
View File
@@ -144,7 +144,7 @@ bool PADSTACK::Deserialize( const google::protobuf::Any& aContainer )
if( padstack.layers_size() == 1 )
{
const PadStackLayer& layer = padstack.layers( 0 );
Size( ALL_LAYERS ) = kiapi::common::UnpackVector2( layer.size() );
SetSize( kiapi::common::UnpackVector2( layer.size() ), ALL_LAYERS );
SetLayerSet( kiapi::board::UnpackLayerSet( layer.layers() ) );
SetShape( FromProtoEnum<PAD_SHAPE>( layer.shape() ), F_Cu );
SetAnchorShape( FromProtoEnum<PAD_SHAPE>( layer.custom_anchor_shape() ), F_Cu );
@@ -836,9 +836,12 @@ void PADSTACK::SetShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer )
}
VECTOR2I& PADSTACK::Size( PCB_LAYER_ID aLayer )
void PADSTACK::SetSize( const VECTOR2I& aSize, PCB_LAYER_ID aLayer )
{
return CopperLayer( aLayer ).shape.size;
// File formats do not enforce that sizes are always positive, but KiCad requires it
VECTOR2I& size = CopperLayer( aLayer ).shape.size;
size.x = std::abs( aSize.x );
size.y = std::abs( aSize.y );
}