Show text item anchor locations in schematic.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17668
This commit is contained in:
Jeff Young 2024-05-25 21:39:51 +01:00
parent 9a1b3471fd
commit 34dbee0693
3 changed files with 74 additions and 98 deletions

View File

@ -32,6 +32,9 @@
///< The size of the rectangle indicating a connected, unselected wire end ///< The size of the rectangle indicating a connected, unselected wire end
#define UNSELECTED_END_SIZE 4 #define UNSELECTED_END_SIZE 4
///< The size of the rectangle indicating the anchor of a text object (including fields)
#define TEXT_ANCHOR_SIZE 8
///< The default pin len value when creating pins(can be changed in preference menu) ///< The default pin len value when creating pins(can be changed in preference menu)
#define DEFAULT_PIN_LENGTH 100 #define DEFAULT_PIN_LENGTH 100

View File

@ -440,8 +440,7 @@ COLOR4D SCH_PAINTER::getRenderColor( const SCH_ITEM* aItem, int aLayer, bool aDr
} }
else if( aItem->IsSelected() && aDrawingShadows ) else if( aItem->IsSelected() && aDrawingShadows )
{ {
if( aDrawingShadows ) color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS );
color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS );
} }
else if( aItem->IsSelected() && ( aLayer == LAYER_DEVICE_BACKGROUND else if( aItem->IsSelected() && ( aLayer == LAYER_DEVICE_BACKGROUND
|| aLayer == LAYER_SHEET_BACKGROUND || aLayer == LAYER_SHEET_BACKGROUND
@ -731,94 +730,6 @@ void SCH_PAINTER::draw( const LIB_SYMBOL* aSymbol, int aLayer, bool aDrawFields,
} }
bool SCH_PAINTER::setDeviceColors( const SCH_ITEM* aItem, int aLayer, bool aDimmed )
{
COLOR4D bg = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
const EDA_SHAPE* shape = dynamic_cast<const EDA_SHAPE*>( aItem );
switch( aLayer )
{
case LAYER_SELECTION_SHADOWS:
if( aItem->IsBrightened() || aItem->IsSelected() )
{
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( getLineWidth( aItem, true ) );
m_gal->SetStrokeColor( getRenderColor( aItem, LAYER_DEVICE, true, aDimmed ) );
m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, true, aDimmed ) );
return true;
}
return false;
case LAYER_NOTES_BACKGROUND:
case LAYER_DEVICE_BACKGROUND:
if( shape )
{
if( shape->GetFillMode() != FILL_T::FILLED_WITH_BG_BODYCOLOR )
{
return false; // FILLED_SHAPE and FILLED_WITH_COLOR rendered below on
// LAYER_NOTES or LAYER_DEVICE
}
m_gal->SetIsFill( true );
m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE_BACKGROUND, false, aDimmed ) );
m_gal->SetIsStroke( false );
return true;
}
return false;
case LAYER_NOTES:
case LAYER_PRIVATE_NOTES:
case LAYER_DEVICE:
m_gal->SetIsFill( shape && ( shape->GetFillMode() == FILL_T::FILLED_SHAPE
|| shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR ) );
if( shape && shape->GetFillMode() == FILL_T::FILLED_SHAPE )
{
m_gal->SetFillColor( getRenderColor( aItem, LAYER_DEVICE, false, aDimmed ) );
}
else if( shape && shape->GetFillMode() == FILL_T::FILLED_WITH_COLOR )
{
COLOR4D fillColour = shape->GetFillColor();
double transparency = aItem->GetForcedTransparency();
if( transparency > 0.0 )
fillColour = fillColour.WithAlpha( fillColour.a * ( 1.0 - transparency ) );
if( m_schSettings.m_OverrideItemColors )
{
fillColour = getRenderColor( aItem, LAYER_DEVICE_BACKGROUND, false, aDimmed );
}
else if( aDimmed )
{
fillColour = fillColour.Mix( bg, 0.5f );
fillColour.Desaturate();
}
m_gal->SetFillColor( fillColour );
}
if( aItem->GetPenWidth() >= 0 || !shape || !shape->IsFilled() )
{
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( getLineWidth( aItem, false ) );
m_gal->SetStrokeColor( getRenderColor( aItem, aLayer, false, aDimmed ) );
}
else
{
m_gal->SetIsStroke( false );
}
return true;
default:
return false;
}
}
int SCH_PAINTER::internalPinDecoSize( const SCH_PIN &aPin ) int SCH_PAINTER::internalPinDecoSize( const SCH_PIN &aPin )
{ {
if( m_schSettings.m_PinSymbolSize > 0 ) if( m_schSettings.m_PinSymbolSize > 0 )
@ -1336,6 +1247,31 @@ void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed )
} }
// Draw anchor indicating the anchor position of text objects, local labels, or fields.
void SCH_PAINTER::drawAnchor( const VECTOR2I& aPos, bool aDrawingShadows )
{
if( m_schSettings.IsPrinting() )
return;
// In order for the anchors to be visible but unobtrusive, their size must factor in the
// current zoom level.
const MATRIX3x3D& matrix = m_gal->GetScreenWorldMatrix();
int radius = KiROUND( std::fabs( matrix.GetScale().x * TEXT_ANCHOR_SIZE ) / 25 )
+ schIUScale.MilsToIU( TEXT_ANCHOR_SIZE );
COLOR4D color = aDrawingShadows ? m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS )
: m_schSettings.GetLayerColor( LAYER_SCHEMATIC_ANCHOR );
m_gal->SetStrokeColor( color );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth( false )
: m_schSettings.GetDanglingIndicatorThickness() );
m_gal->DrawLine( aPos - VECTOR2I( radius, 0 ), aPos + VECTOR2I( radius, 0 ) );
m_gal->DrawLine( aPos - VECTOR2I( 0, radius ), aPos + VECTOR2I( 0, radius ) );
}
// Draw the target (an open square) for a wire or label which has no connection or is // Draw the target (an open square) for a wire or label which has no connection or is
// being moved. // being moved.
void SCH_PAINTER::drawDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor, int aWidth, void SCH_PAINTER::drawDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor, int aWidth,
@ -1886,6 +1822,39 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed )
const_cast<SCH_TEXT*>( aText )->ClearFlags( IS_SHOWN_AS_BITMAP ); const_cast<SCH_TEXT*>( aText )->ClearFlags( IS_SHOWN_AS_BITMAP );
} }
} }
// Draw anchor
if( aText->IsSelected() )
{
bool showAnchor;
switch( aText->Type() )
{
case SCH_TEXT_T:
showAnchor = true;
break;
case SCH_LABEL_T:
// Don't clutter things up if we're already showing a dangling indicator
showAnchor = !static_cast<const SCH_LABEL*>( aText )->IsDangling();
break;
case SCH_DIRECTIVE_LABEL_T:
case SCH_HIER_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_SHEET_PIN_T:
// These all have shapes and so don't need anchors
showAnchor = false;
break;
default:
showAnchor = false;
break;
}
if( showAnchor )
drawAnchor( aText->GetPosition(), drawingShadows );
}
} }
@ -1943,7 +1912,8 @@ void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
} }
else else
{ {
strokeText( shownText, aTextBox->GetDrawPos(), attrs, aTextBox->GetFontMetrics() ); strokeText( shownText, aTextBox->GetDrawPos(), attrs,
aTextBox->GetFontMetrics() );
} }
}; };
@ -2444,14 +2414,18 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
} }
} }
// Draw the umbilical line // Draw anchor or umbilical line
if( aField->IsMoving() && m_schematic ) if( aField->IsMoving() && m_schematic )
{ {
VECTOR2I parentPos = aField->GetParentPosition(); VECTOR2I parentPos = aField->GetParentPosition();
m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() ); m_gal->SetLineWidth( m_schSettings.GetOutlineWidth() );
m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) ); m_gal->SetStrokeColor( getRenderColor( aField, LAYER_SCHEMATIC_ANCHOR, drawingShadows ) );
m_gal->DrawLine( bbox.Centre(), parentPos ); m_gal->DrawLine( aField->GetPosition(), parentPos );
}
else if( aField->IsSelected() )
{
drawAnchor( aField->GetPosition(), drawingShadows );
} }
} }

View File

@ -24,8 +24,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#ifndef __SCH_PAINTER_H #ifndef SCH_PAINTER_H
#define __SCH_PAINTER_H #define SCH_PAINTER_H
#include <sch_render_settings.h> #include <sch_render_settings.h>
#include <sch_symbol.h> #include <sch_symbol.h>
@ -105,6 +105,7 @@ private:
bool aDrawingShadows, bool aBrightened ); bool aDrawingShadows, bool aBrightened );
void drawDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor, int aWidth, void drawDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor, int aWidth,
bool aDangling, bool aDrawingShadows, bool aBrightened ); bool aDangling, bool aDrawingShadows, bool aBrightened );
void drawAnchor( const VECTOR2I& aPos, bool aDrawingShadows );
int internalPinDecoSize( const SCH_PIN &aPin ); int internalPinDecoSize( const SCH_PIN &aPin );
int externalPinDecoSize( const SCH_PIN &aPin ); int externalPinDecoSize( const SCH_PIN &aPin );
@ -123,8 +124,6 @@ private:
int getOperatingPointTextSize() const; int getOperatingPointTextSize() const;
bool setDeviceColors( const SCH_ITEM* aItem, int aLayer, bool aDimmed );
void triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ); void triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c );
void strokeText( const wxString& aText, const VECTOR2D& aPosition, void strokeText( const wxString& aText, const VECTOR2D& aPosition,
const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ); const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics );
@ -148,4 +147,4 @@ private:
}; // namespace KIGFX }; // namespace KIGFX
#endif // __SCH_PAINTER_H #endif // SCH_PAINTER_H