Tighten up schematic label bounding boxes

Margins were being added in more places than necessary

Fixes https://gitlab.com/kicad/code/kicad/-/issues/7689
This commit is contained in:
Jon Evans 2021-02-24 17:14:39 -05:00
parent d384316335
commit 92cc88f87c
4 changed files with 31 additions and 11 deletions

View File

@ -151,6 +151,8 @@ static const wxChar SmallDrillMarkSize[] = wxT( "SmallDrillMarkSize" );
static const wxChar HotkeysDumper[] = wxT( "HotkeysDumper" );
static const wxChar DrawBoundingBoxes[] = wxT( "DrawBoundingBoxes" );
} // namespace KEYS
@ -252,6 +254,7 @@ ADVANCED_CFG::ADVANCED_CFG()
m_SkipBoundingBoxOnFpLoad = false;
m_SmallDrillMarkSize = 0.35;
m_HotkeysDumper = false;
m_DrawBoundingBoxes = false;
loadFromConfigFile();
}
@ -342,6 +345,9 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::HotkeysDumper,
&m_HotkeysDumper, false ) );
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::DrawBoundingBoxes,
&m_DrawBoundingBoxes, false ) );
wxConfigLoadSetups( &aCfg, configParams );
for( PARAM_CFG* param : configParams )

View File

@ -193,6 +193,21 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer )
#endif
if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
{
BOX2I box = item->GetBoundingBox();
if( item->Type() == SCH_COMPONENT_T )
box = static_cast<const SCH_COMPONENT*>( item )->GetBodyBoundingBox();
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
COLOR4D( 0.2, 0.2, 0.2, 1 ) );
m_gal->SetLineWidth( Mils2iu( 3 ) );
m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
}
switch( item->Type() )
{
HANDLE_ITEM( LIB_PART_T, LIB_PART );

View File

@ -792,9 +792,8 @@ bool SCH_LABEL::IsType( const KICAD_T aScanTypes[] ) const
const EDA_RECT SCH_LABEL::GetBoundingBox() const
{
EDA_RECT rect = GetTextBox();
int margin = GetTextOffset();
rect.Inflate( margin );
rect.Offset( 0, -GetTextOffset() );
if( GetTextAngle() != 0.0 )
{
@ -1291,10 +1290,10 @@ const EDA_RECT SCH_GLOBALLABEL::GetBoundingBox() const
int y = GetTextPos().y;
int penWidth = GetEffectiveTextPenWidth();
int margin = GetTextOffset();
int height = ( (GetTextHeight() * 15) / 10 ) + penWidth + 2 * margin;
int height = ( ( GetTextHeight() * 15 ) / 10 ) + penWidth + margin;
int length = LenSize( GetShownText(), penWidth )
+ height // add height for triangular shapes
+ 2 * margin;
- margin; // margin added to height not needed here
int dx, dy;
@ -1304,7 +1303,6 @@ const EDA_RECT SCH_GLOBALLABEL::GetBoundingBox() const
case LABEL_SPIN_STYLE::LEFT:
dx = -length;
dy = height;
x += margin;
y -= height / 2;
break;
@ -1312,13 +1310,11 @@ const EDA_RECT SCH_GLOBALLABEL::GetBoundingBox() const
dx = height;
dy = -length;
x -= height / 2;
y += margin;
break;
case LABEL_SPIN_STYLE::RIGHT:
dx = length;
dy = height;
x -= margin;
y -= height / 2;
break;
@ -1326,7 +1322,6 @@ const EDA_RECT SCH_GLOBALLABEL::GetBoundingBox() const
dx = height;
dy = length;
x -= height / 2;
y -= margin;
break;
}
@ -1457,10 +1452,9 @@ const EDA_RECT SCH_HIERLABEL::GetBoundingBox() const
int x = GetTextPos().x;
int y = GetTextPos().y;
int height = GetTextHeight() + penWidth + 2 * margin;
int height = GetTextHeight() + penWidth + margin;
int length = LenSize( GetShownText(), penWidth )
+ height // add height for triangular shapes
+ 2 * margin;
+ height; // add height for triangular shapes
int dx, dy;

View File

@ -160,6 +160,11 @@ public:
*/
bool m_HotkeysDumper;
/**
* Draw GAL bounding boxes in painters
*/
bool m_DrawBoundingBoxes;
private:
ADVANCED_CFG();