diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index 6ffb39bf3b..222d0f37e3 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -72,8 +72,9 @@ PAD::PAD( FOOTPRINT* parent ) : m_padStack( this ) { VECTOR2I& drill = m_padStack.Drill().size; - VECTOR2I& size = m_padStack.Size( PADSTACK::ALL_LAYERS ); - size.x = size.y = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 60 ); // Default pad size 60 mils. + m_padStack.SetSize( { EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 60 ), + EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 60 ) }, + PADSTACK::ALL_LAYERS ); drill.x = drill.y = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 30 ); // Default drill size 30 mils. m_lengthPadToDie = 0; diff --git a/pcbnew/pad.h b/pcbnew/pad.h index 4d4ab33f9a..683f6ae130 100644 --- a/pcbnew/pad.h +++ b/pcbnew/pad.h @@ -260,7 +260,7 @@ public: void SetSize( PCB_LAYER_ID aLayer, const VECTOR2I& aSize ) { - m_padStack.Size( aLayer ) = aSize; + m_padStack.SetSize( aSize, aLayer ); SetDirty(); } const VECTOR2I& GetSize( PCB_LAYER_ID aLayer ) const { return m_padStack.Size( aLayer ); } @@ -270,10 +270,27 @@ public: // in the GUI when the padstack mode is set to anything other than NORMAL, but so that the code // compiles, these are set up to work with the front layer (in other words, assume the mode is // NORMAL, where F_Cu stores the whole padstack data) - void SetSizeX( const int aX ) { if( aX > 0 ) { m_padStack.Size( PADSTACK::ALL_LAYERS ).x = aX; SetDirty(); } } - int GetSizeX() const { return m_padStack.Size( PADSTACK::ALL_LAYERS ).x; } - void SetSizeY( const int aY ) { if( aY > 0 ) { m_padStack.Size( PADSTACK::ALL_LAYERS ).y = aY; SetDirty(); } } - int GetSizeY() const { return m_padStack.Size( PADSTACK::ALL_LAYERS ).y; } + void SetSizeX( const int aX ) + { + if( aX > 0 ) + { + m_padStack.SetSize( { aX, m_padStack.Size( PADSTACK::ALL_LAYERS ).y }, PADSTACK::ALL_LAYERS ); + SetDirty(); + } + } + + int GetSizeX() const { return m_padStack.Size( PADSTACK::ALL_LAYERS ).x; } + + void SetSizeY( const int aY ) + { + if( aY > 0 ) + { + m_padStack.SetSize( { m_padStack.Size( PADSTACK::ALL_LAYERS ).x, aY }, PADSTACK::ALL_LAYERS ); + SetDirty(); + } + } + + int GetSizeY() const { return m_padStack.Size( PADSTACK::ALL_LAYERS ).y; } void SetDelta( PCB_LAYER_ID aLayer, const VECTOR2I& aSize ) { diff --git a/pcbnew/padstack.cpp b/pcbnew/padstack.cpp index a2a99c16f4..3778c6496d 100644 --- a/pcbnew/padstack.cpp +++ b/pcbnew/padstack.cpp @@ -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( layer.shape() ), F_Cu ); SetAnchorShape( FromProtoEnum( 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 ); } diff --git a/pcbnew/padstack.h b/pcbnew/padstack.h index 02201e1ce2..f3f89655fc 100644 --- a/pcbnew/padstack.h +++ b/pcbnew/padstack.h @@ -338,7 +338,8 @@ public: PAD_SHAPE Shape( PCB_LAYER_ID aLayer ) const; void SetShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer ); - VECTOR2I& Size( PCB_LAYER_ID aLayer ); + // Setter rather than direct access to enforce only positive sizes + void SetSize( const VECTOR2I& aSize, PCB_LAYER_ID aLayer ); const VECTOR2I& Size( PCB_LAYER_ID aLayer ) const; PAD_DRILL_SHAPE DrillShape() const; diff --git a/pcbnew/pcb_io/altium/altium_pcb.cpp b/pcbnew/pcb_io/altium/altium_pcb.cpp index 74458dea36..bd579acf30 100644 --- a/pcbnew/pcb_io/altium/altium_pcb.cpp +++ b/pcbnew/pcb_io/altium/altium_pcb.cpp @@ -3136,17 +3136,19 @@ void ALTIUM_PCB::ConvertVias6ToFootprintItem( FOOTPRINT* aFootprint, const AVIA6 else if( aElem.viamode == ALTIUM_PAD_MODE::TOP_MIDDLE_BOTTOM ) { pad->Padstack().SetMode( PADSTACK::MODE::FRONT_INNER_BACK ); - pad->Padstack().Size( PADSTACK::INNER_LAYERS ) = - VECTOR2I( aElem.diameter_by_layer[1], aElem.diameter_by_layer[1] ); + pad->Padstack().SetSize( VECTOR2I( aElem.diameter_by_layer[1], aElem.diameter_by_layer[1] ), + PADSTACK::INNER_LAYERS ); } else { pad->Padstack().SetMode( PADSTACK::MODE::CUSTOM ); + int altiumIdx = 0; - for( int ii = 0; ii < 32; ++ii ) + for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, 32 ) ) { - VECTOR2I size( aElem.diameter_by_layer[ii], aElem.diameter_by_layer[ii] ); - pad->Padstack().Size( static_cast( F_Cu + ii ) ) = size; + pad->Padstack().SetSize( VECTOR2I( aElem.diameter_by_layer[altiumIdx], + aElem.diameter_by_layer[altiumIdx] ), layer ); + altiumIdx++; } } @@ -3388,7 +3390,7 @@ void ALTIUM_PCB::ConvertPads6ToFootprintItemOnCopper( FOOTPRINT* aFootprint, con { int altLayer = CopperLayerToOrdinal( aLayer ); - ps.Size( aLayer ) = aSize; + ps.SetSize( aSize, aLayer ); switch( aShape ) { diff --git a/pcbnew/pcb_track.cpp b/pcbnew/pcb_track.cpp index 98e4c42799..fc694115e9 100644 --- a/pcbnew/pcb_track.cpp +++ b/pcbnew/pcb_track.cpp @@ -311,7 +311,7 @@ double PCB_VIA::Similarity( const BOARD_ITEM& aOther ) const void PCB_VIA::SetWidth( int aWidth ) { - m_padStack.Size( PADSTACK::ALL_LAYERS ) = { aWidth, aWidth }; + m_padStack.SetSize( { aWidth, aWidth }, PADSTACK::ALL_LAYERS ); }