diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 1648184e39..968d825a49 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -2179,6 +2179,26 @@ wxString FOOTPRINT::GetNextPadNumber( const wxString& aLastPadNumber ) const } +void FOOTPRINT::AutoPositionFields() +{ + // Auto-position reference and value + BOX2I bbox = GetBoundingBox( false, false ); + bbox.Inflate( pcbIUScale.mmToIU( 0.2 ) ); // Gap between graphics and text + + if( Reference().GetPosition() == VECTOR2I( 0, 0 ) ) + { + Reference().SetX( bbox.GetCenter().x ); + Reference().SetY( bbox.GetTop() - Reference().GetTextSize().y / 2 ); + } + + if( Value().GetPosition() == VECTOR2I( 0, 0 ) ) + { + Value().SetX( bbox.GetCenter().x ); + Value().SetY( bbox.GetBottom() + Value().GetTextSize().y / 2 ); + } +} + + void FOOTPRINT::IncrementReference( int aDelta ) { const wxString& refdes = GetReference(); diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index 61bf105dfa..9dfdd477ee 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -775,6 +775,11 @@ public: */ wxString GetNextPadNumber( const wxString& aLastPadName ) const; + /** + * Position Reference and Value fields at the top and bottom of footprint's bounding box. + */ + void AutoPositionFields(); + /** * Get the type of footprint * @return "SMD"/"Through hole"/"Other" based on attributes diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index 96ca3b4335..19dbe81501 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -761,20 +761,7 @@ FOOTPRINT* ALTIUM_PCB::ParseFootprint( const ALTIUM_COMPOUND_FILE& altiumLibFile } // Auto-position reference and value - BOX2I bbox = footprint.get()->GetBoundingBox( false, false ); - bbox.Inflate( pcbIUScale.mmToIU( 0.2 ) ); // Gap between graphics and text - - if( footprint->Reference().GetPosition() == VECTOR2I( 0, 0 ) ) - { - footprint->Reference().SetX( bbox.GetCenter().x ); - footprint->Reference().SetY( bbox.GetTop() - footprint->Reference().GetTextSize().y / 2 ); - } - - if( footprint->Value().GetPosition() == VECTOR2I( 0, 0 ) ) - { - footprint->Value().SetX( bbox.GetCenter().x ); - footprint->Value().SetY( bbox.GetBottom() + footprint->Value().GetTextSize().y / 2 ); - } + footprint->AutoPositionFields(); if( parser.HasParsingError() ) {