Browse Source

FOOTPRINT: add a method to auto-position Reference and Value.

newinvert
Alex Shvartzkop 2 years ago
parent
commit
e498f1b9a0
  1. 20
      pcbnew/footprint.cpp
  2. 5
      pcbnew/footprint.h
  3. 15
      pcbnew/plugins/altium/altium_pcb.cpp

20
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();

5
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

15
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() )
{

Loading…
Cancel
Save