Handle justification when hit-testing fields.
This steals the algo used in SCH_PAINTER to get the right coords for the text. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15722
This commit is contained in:
parent
89f444c38b
commit
6fbbf981f0
|
@ -906,7 +906,8 @@ void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControl
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
|
std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangulate,
|
||||||
bool aUseTextRotation ) const
|
const BOX2I& aBBox,
|
||||||
|
const EDA_ANGLE& aAngle ) const
|
||||||
{
|
{
|
||||||
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
|
std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
|
||||||
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
KIGFX::GAL_DISPLAY_OPTIONS empty_opts;
|
||||||
|
@ -918,12 +919,12 @@ std::shared_ptr<SHAPE_COMPOUND> EDA_TEXT::GetEffectiveTextShape( bool aTriangula
|
||||||
|
|
||||||
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
|
std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = nullptr;
|
||||||
|
|
||||||
if( aUseTextRotation )
|
if( aBBox.GetWidth() )
|
||||||
{
|
{
|
||||||
attrs.m_Angle = GetDrawRotation();
|
drawPos = aBBox.GetCenter();
|
||||||
|
attrs.m_Halign = GR_TEXT_H_ALIGN_CENTER;
|
||||||
if( font->IsOutline() )
|
attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER;
|
||||||
cache = GetRenderCache( font, shownText, VECTOR2I() );
|
attrs.m_Angle = aAngle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1769,7 +1769,17 @@ BOX2I SCH_SYMBOL::doGetBoundingBox( bool aIncludePins, bool aIncludeFields ) con
|
||||||
|
|
||||||
BOX2I SCH_SYMBOL::GetBodyBoundingBox() const
|
BOX2I SCH_SYMBOL::GetBodyBoundingBox() const
|
||||||
{
|
{
|
||||||
return doGetBoundingBox( false, false );
|
try
|
||||||
|
{
|
||||||
|
return doGetBoundingBox( false, false );
|
||||||
|
}
|
||||||
|
catch( const boost::bad_pointer& exc )
|
||||||
|
{
|
||||||
|
// This may be overkill and could be an assertion but we are more likely to
|
||||||
|
// find any boost pointer container errors this way.
|
||||||
|
wxLogError( wxT( "Boost bad pointer exception '%s' occurred." ), exc.what() );
|
||||||
|
return BOX2I();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1354,6 +1354,7 @@ void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const
|
||||||
}
|
}
|
||||||
|
|
||||||
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
|
||||||
|
SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( item );
|
||||||
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( item );
|
||||||
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
|
||||||
|
|
||||||
|
@ -1361,36 +1362,32 @@ void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const
|
||||||
{
|
{
|
||||||
dist = KiROUND( DistanceLinePoint( line->GetStartPoint(), line->GetEndPoint(), pos ) );
|
dist = KiROUND( DistanceLinePoint( line->GetStartPoint(), line->GetEndPoint(), pos ) );
|
||||||
}
|
}
|
||||||
else if( text )
|
else if( field )
|
||||||
{
|
{
|
||||||
if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( text ) )
|
BOX2I box = field->GetBoundingBox();
|
||||||
|
EDA_ANGLE orient = field->GetTextAngle();
|
||||||
|
|
||||||
|
if( field->GetParent() && field->GetParent()->Type() == SCH_SYMBOL_T )
|
||||||
{
|
{
|
||||||
if( field->GetParent() && field->GetParent()->Type() == SCH_SYMBOL_T )
|
if( static_cast<SCH_SYMBOL*>( field->GetParent() )->GetTransform().y1 )
|
||||||
{
|
{
|
||||||
symbol = static_cast<SCH_SYMBOL*>( field->GetParent() );
|
if( orient.IsHorizontal() )
|
||||||
|
orient = ANGLE_VERTICAL;
|
||||||
VECTOR2I relPos = pos - symbol->GetPosition();
|
else
|
||||||
relPos = symbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
|
orient = ANGLE_HORIZONTAL;
|
||||||
pos = relPos + symbol->GetPosition();
|
|
||||||
|
|
||||||
poss = SEG( pos, pos );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
field->GetEffectiveTextShape( false, box, orient )->Collide( poss, INT_MAX / 2,
|
||||||
|
&dist );
|
||||||
|
}
|
||||||
|
else if( text )
|
||||||
|
{
|
||||||
text->GetEffectiveTextShape( false )->Collide( poss, INT_MAX / 2, &dist );
|
text->GetEffectiveTextShape( false )->Collide( poss, INT_MAX / 2, &dist );
|
||||||
}
|
}
|
||||||
else if( symbol )
|
else if( symbol )
|
||||||
{
|
{
|
||||||
try
|
bbox = symbol->GetBodyBoundingBox();
|
||||||
{
|
|
||||||
bbox = symbol->GetBodyBoundingBox();
|
|
||||||
}
|
|
||||||
catch( const boost::bad_pointer& exc )
|
|
||||||
{
|
|
||||||
// This may be overkill and could be an assertion but we are more likely to
|
|
||||||
// find any boost pointer container errors this way.
|
|
||||||
wxLogError( wxT( "Boost bad pointer exception '%s' occurred." ), exc.what() );
|
|
||||||
}
|
|
||||||
|
|
||||||
SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
|
SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() );
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,8 @@ public:
|
||||||
* false to build a list of shape for a not rotated text ("native" shapes).
|
* false to build a list of shape for a not rotated text ("native" shapes).
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<SHAPE_COMPOUND> GetEffectiveTextShape( bool aTriangulate = true,
|
std::shared_ptr<SHAPE_COMPOUND> GetEffectiveTextShape( bool aTriangulate = true,
|
||||||
bool aUseTextRotation = true ) const;
|
const BOX2I& aBBox = BOX2I(),
|
||||||
|
const EDA_ANGLE& aAngle = ANGLE_0 ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if \a aPoint is within the bounds of this object.
|
* Test if \a aPoint is within the bounds of this object.
|
||||||
|
|
Loading…
Reference in New Issue