Improve dangling pin drawing logic.

This commit is contained in:
Jeff Young 2018-09-09 21:14:00 +01:00
parent 268565ee41
commit 8e09aa554a
1 changed files with 87 additions and 101 deletions

View File

@ -23,8 +23,6 @@
*/
/// @ todo: this is work in progress. Cleanup will follow.
#include <sch_item_struct.h>
#include <lib_draw_item.h>
@ -67,21 +65,19 @@ SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() :
ImportLegacyColors( nullptr );
}
void SCH_RENDER_SETTINGS::ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSettings )
{
for( int layer = SCH_LAYER_ID_START; layer < SCH_LAYER_ID_END; layer ++)
{
m_layerColors[ layer ] = ::GetLayerColor( static_cast<SCH_LAYER_ID>( layer ) );
}
for( int layer = GAL_LAYER_ID_START; layer < GAL_LAYER_ID_END; layer ++)
{
m_layerColors[ layer ] = ::GetLayerColor( static_cast<SCH_LAYER_ID>( layer ) );
}
m_backgroundColor = ::GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
}
const COLOR4D& SCH_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
{
return m_layerColors[ aLayer ];
@ -138,37 +134,18 @@ SCH_PAINTER::SCH_PAINTER( GAL* aGal ) :
#define HANDLE_ITEM( type_id, type_name ) \
case type_id: \
draw( (type_name *) item, aLayer ); \
break;
case type_id: draw( (type_name *) item, aLayer ); break;
bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer )
{
auto item2 = static_cast<const EDA_ITEM*>( aItem );
auto item = const_cast<EDA_ITEM*>( item2 );
//printf("Import\n");
m_schSettings.ImportLegacyColors( nullptr );
//auto c =GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
//printf("bkgd %.02f %.02f %.02f %.02f\n", c.r, c.g, c.b, c.a);
//auto c2 = m_schSettings.GetLayerColor ( LAYER_SCHEMATIC_BACKGROUND );
//printf("bkgd2 %.02f %.02f %.02f %.02f\n", c2.r, c2.g, c2.b, c2.a);
m_gal->EnableDepthTest( false );
/* m_gal->SetLineWidth( 10 );
m_gal->SetIsFill( false );
m_gal->SetIsStroke (true);
m_gal->SetStrokeColor( COLOR4D(0.0, 0.0, 0.0, 1.0) );
m_gal->SetGlyphSize ( VECTOR2D(100,100) );
m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER );
m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER );
m_gal->StrokeText( wxT("Test"), VECTOR2D(0, 0), 0.0 );
*/
switch( item->Type() )
{
HANDLE_ITEM(LIB_ALIAS_T, LIB_ALIAS);
@ -294,7 +271,6 @@ void SCH_PAINTER::draw( LIB_ALIAS *aAlias, int aLayer )
}
static VECTOR2D mapCoords( const wxPoint& aCoord )
{
return VECTOR2D( aCoord.x, -aCoord.y );
@ -401,6 +377,9 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
default: color = m_schSettings.GetLayerColor( LAYER_FIELDS ); break;
}
if( aField->IsMoving() )
color = selectedBrightening( color );
if( !aField->IsVisible() )
{
if( m_schSettings.m_ShowHiddenText )
@ -408,10 +387,6 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
else
return;
}
else if( aField->IsMoving() )
{
color = selectedBrightening( color );
}
int linewidth = aField->GetPenSize();
@ -462,17 +437,16 @@ void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer )
COLOR4D color = m_schSettings.GetLayerColor( LAYER_NOTES );
if( aText->IsMoving() )
color = selectedBrightening( color );
if( !aText->IsVisible() )
{
if( m_schSettings.m_ShowHiddenText )
color = m_schSettings.GetLayerColor( LAYER_HIDDEN );
if( !m_schSettings.m_ShowHiddenText )
else
return;
}
else if( aText->IsMoving() )
{
color = selectedBrightening( color );
}
int w = aText->GetPenSize();
EDA_RECT bBox = aText->GetBoundingBox();
@ -498,15 +472,28 @@ static int InternalPinDecoSize( const LIB_PIN &aPin )
return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
}
/// Utility for getting the size of the 'external' pin decorators (as a radius)
// i.e. the negation circle, the polarity 'slopes' and the nonlogic
// marker
// Utility for getting the size of the 'external' pin decorators (as a radius)
// i.e. the negation circle, the polarity 'slopes' and the nonlogic marker
static int ExternalPinDecoSize( const LIB_PIN &aPin )
{
return aPin.GetNumberTextSize() / 2;
}
// Draw the target (an open circle) for a pin which has no connection or is being
// moved.
static void drawPinDanglingSymbol( GAL* aGal, const VECTOR2I& aPos, const COLOR4D& aColor )
{
aGal->SetIsStroke( true );
aGal->SetIsFill( false );
aGal->SetStrokeColor( aColor );
aGal->SetLineWidth ( 1.0 );
aGal->DrawCircle( aPos, TARGET_PIN_RADIUS );
}
void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMoving )
{
if( !isUnitAndConversionShown( aPin ) )
@ -516,20 +503,26 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMovin
isMoving = true;
COLOR4D color = m_schSettings.GetLayerColor( LAYER_PIN );
VECTOR2I pos = mapCoords( aPin->GetPosition() );
if( isMoving )
color = selectedBrightening( color );
if( !aPin->IsVisible() )
{
if( m_schSettings.m_ShowHiddenPins )
{
color = m_schSettings.GetLayerColor( LAYER_HIDDEN );
}
else
{
if( ( isDangling || isMoving ) && aPin->IsPowerConnection() )
drawPinDanglingSymbol( m_gal, pos, color );
if( !m_schSettings.m_ShowHiddenPins )
return;
}
else if( isMoving )
{
color = selectedBrightening( color );
}
VECTOR2I pos = mapCoords( aPin->GetPosition() );
VECTOR2I p0, dir;
int len = aPin->GetLength();
int width = aPin->GetPenSize();
@ -539,22 +532,18 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMovin
switch( orient )
{
case PIN_UP:
//printf("pinUp\n");
p0 = VECTOR2I( pos.x, pos.y - len );
dir = VECTOR2I(0, 1);
break;
case PIN_DOWN:
//printf("pinDown\n");
p0 = VECTOR2I( pos.x, pos.y + len );
dir = VECTOR2I(0, -1);
break;
case PIN_LEFT:
//printf("pinLeft\n");
p0 = VECTOR2I( pos.x - len, pos.y );
dir = VECTOR2I(1, 0);
break;
case PIN_RIGHT:
//printf("pinRight\n");
p0 = VECTOR2I( pos.x + len, pos.y );
dir = VECTOR2I(-1, 0);
break;
@ -591,9 +580,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMovin
}
else
{
//printf("DrawLPin\n");
m_gal->DrawLine( p0, pos );
//m_gal->DrawLine( p0, pos+dir.Perpendicular() * radius);
}
if( shape == PINSHAPE_CLOCK )
@ -653,10 +640,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMovin
}
if( ( isDangling || isMoving ) && ( aPin->IsVisible() || aPin->IsPowerConnection() ) )
{
m_gal->SetLineWidth ( 1.0 );
m_gal->DrawCircle( pos, TARGET_PIN_RADIUS );
}
drawPinDanglingSymbol( m_gal, pos, color );
// Draw the labels
@ -863,10 +847,16 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMovin
}
// Draw the target (an open square) for a wire or label which has no connection or is
// being moved.
static void drawDanglingSymbol( GAL* aGal, const wxPoint& aPos )
{
wxPoint radius( DANGLING_SYMBOL_SIZE, DANGLING_SYMBOL_SIZE );
aGal->SetIsStroke( true );
aGal->SetIsFill( false );
aGal->SetLineWidth ( 1.0 );
aGal->DrawRectangle( aPos - radius, aPos + radius );
}
@ -930,14 +920,14 @@ void SCH_PAINTER::draw( SCH_LINE *aLine, int aLayer )
break;
}
for( size_t i = 0; i < 100000; ++i )
for( size_t i = 0; i < 10000; ++i )
{
// Calculations MUST be done in doubles to keep from accumulating rounding
// errors as we go.
VECTOR2D next( start.x + strokes[ i % 4 ] * cos( theta ),
start.y + strokes[ i % 4 ] * sin( theta ) );
// Drawing each segment can be done rounded.
// Drawing each segment can be done rounded to ints.
wxPoint segStart( KiROUND( start.x ), KiROUND( start.y ) );
wxPoint segEnd( KiROUND( next.x ), KiROUND( next.y ) );
@ -970,17 +960,16 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer )
default: color = m_schSettings.GetLayerColor( LAYER_NOTES ); break;
}
if( aText->IsMoving() )
color = selectedBrightening( color );
if( !aText->IsVisible() )
{
if( m_schSettings.m_ShowHiddenText )
color = m_schSettings.GetLayerColor( LAYER_HIDDEN );
if( !m_schSettings.m_ShowHiddenText )
else
return;
}
else if( aText->IsMoving() )
{
color = selectedBrightening( color );
}
if( aText->IsDangling() )
drawDanglingSymbol( m_gal, aText->GetTextPos() );
@ -1039,8 +1028,6 @@ static void orientComponent( LIB_PART *part, int orientation )
}
}
//printf("orient %d %d %d\n", o.n_rots, o.mirror_x, o.mirror_y );
for( auto& item : part->GetDrawItems() )
{
for( int i = 0; i < o.n_rots; i++ )
@ -1109,17 +1096,16 @@ void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer )
default: color = m_schSettings.GetLayerColor( LAYER_FIELDS ); break;
}
if( aField->IsMoving() )
color = selectedBrightening( color );
if( !aField->IsVisible() )
{
if( m_schSettings.m_ShowHiddenText )
color = m_schSettings.GetLayerColor( LAYER_HIDDEN );
if( !m_schSettings.m_ShowHiddenText )
else
return;
}
else if( aField->IsMoving() )
{
color = selectedBrightening( color );
}
if( aField->IsVoid() )
return;