Replace pin mark/sweep with method that doesn't invalidate iterators.

Also removes some no-longer-used drawing code (the Draw() routines
are only used for printing with the modern eeschema canvas in place).
This commit is contained in:
Jeff Young 2019-04-04 12:07:07 +01:00
parent ec2c571abb
commit 95635804bf
9 changed files with 26 additions and 166 deletions

View File

@ -167,8 +167,6 @@ void SCH_BUS_ENTRY_BASE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
if( aColor != COLOR4D::UNSPECIFIED ) if( aColor != COLOR4D::UNSPECIFIED )
color = aColor; color = aColor;
else if( aPanel->GetScreen() && !aPanel->GetScreen()->m_IsPrinting && GetState( BRIGHTENED ) )
color = GetLayerColor( LAYER_BRIGHTENED );
else else
color = GetLayerColor( m_Layer ); color = GetLayerColor( m_Layer );
@ -177,17 +175,13 @@ void SCH_BUS_ENTRY_BASE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
GRLine( clipbox, aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y, GRLine( clipbox, aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
m_End().x + aOffset.x, m_End().y + aOffset.y, GetPenSize(), color ); m_End().x + aOffset.x, m_End().y + aOffset.y, GetPenSize(), color );
if( m_isDanglingStart )
// Draw pin targets if part is being dragged
bool dragging = aPanel->GetScreen()->GetCurItem() == this && aPanel->IsMouseCaptured();
if( m_isDanglingStart || dragging )
{ {
GRCircle( clipbox, aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y, GRCircle( clipbox, aDC, m_pos.x + aOffset.x, m_pos.y + aOffset.y,
TARGET_BUSENTRY_RADIUS, 0, color ); TARGET_BUSENTRY_RADIUS, 0, color );
} }
if( m_isDanglingEnd || dragging ) if( m_isDanglingEnd )
{ {
GRCircle( clipbox, aDC, m_End().x + aOffset.x, m_End().y + aOffset.y, GRCircle( clipbox, aDC, m_End().x + aOffset.x, m_End().y + aOffset.y,
TARGET_BUSENTRY_RADIUS, 0, color ); TARGET_BUSENTRY_RADIUS, 0, color );

View File

@ -368,54 +368,6 @@ static bool sort_by_libid( const SCH_COMPONENT* ref, SCH_COMPONENT* cmp )
} }
void SCH_COMPONENT::ResolveAll( const SCH_COLLECTOR& aComponents, PART_LIBS* aLibs )
{
// Usually, many components use the same part lib.
// to avoid too long calculation time the list of components is grouped
// and once the lib part is found for one member of a group, it is also
// set for all other members of this group
std::vector<SCH_COMPONENT*> cmp_list;
// build the cmp list.
for( int i = 0; i < aComponents.GetCount(); ++i )
{
SCH_COMPONENT* cmp = dynamic_cast<SCH_COMPONENT*>( aComponents[i] );
wxASSERT( cmp );
if( cmp ) // cmp == NULL should not occur.
cmp_list.push_back( cmp );
}
// sort it by lib part. Cmp will be grouped by same lib part.
std::sort( cmp_list.begin(), cmp_list.end(), sort_by_libid );
LIB_ID curr_libid;
for( unsigned ii = 0; ii < cmp_list.size (); ++ii )
{
SCH_COMPONENT* cmp = cmp_list[ii];
curr_libid = cmp->m_lib_id;
cmp->Resolve( aLibs );
cmp->UpdatePins();
// Propagate the m_part pointer to other members using the same lib_id
for( unsigned jj = ii+1; jj < cmp_list.size (); ++jj )
{
SCH_COMPONENT* next_cmp = cmp_list[jj];
if( curr_libid != next_cmp->m_lib_id )
break;
next_cmp->m_part = cmp->m_part;
next_cmp->UpdatePins();
ii = jj;
}
}
}
void SCH_COMPONENT::ResolveAll( const SCH_COLLECTOR& aComponents, SYMBOL_LIB_TABLE& aLibTable, void SCH_COMPONENT::ResolveAll( const SCH_COLLECTOR& aComponents, SYMBOL_LIB_TABLE& aLibTable,
PART_LIB* aCacheLib ) PART_LIB* aCacheLib )
{ {
@ -460,7 +412,7 @@ void SCH_COMPONENT::ResolveAll( const SCH_COLLECTOR& aComponents, SYMBOL_LIB_TAB
} }
void SCH_COMPONENT::UpdateAllPinCaches( const SCH_COLLECTOR& aComponents ) void SCH_COMPONENT::UpdatePins( const SCH_COLLECTOR& aComponents )
{ {
for( int i = 0; i < aComponents.GetCount(); ++i ) for( int i = 0; i < aComponents.GetCount(); ++i )
{ {
@ -476,8 +428,10 @@ void SCH_COMPONENT::UpdatePins( SCH_SHEET_PATH* aSheet )
{ {
if( PART_SPTR part = m_part.lock() ) if( PART_SPTR part = m_part.lock() )
{ {
std::set<LIB_PIN*> stalePins;
for( auto& it : m_pins ) for( auto& it : m_pins )
it.second.ClearFlags( BUSY ); stalePins.insert( it.first );
for( LIB_PIN* libPin = part->GetNextPin(); libPin; libPin = part->GetNextPin( libPin ) ) for( LIB_PIN* libPin = part->GetNextPin(); libPin; libPin = part->GetNextPin( libPin ) )
{ {
@ -495,14 +449,11 @@ void SCH_COMPONENT::UpdatePins( SCH_SHEET_PATH* aSheet )
if( aSheet ) if( aSheet )
m_pins.at( libPin ).InitializeConnection( *aSheet ); m_pins.at( libPin ).InitializeConnection( *aSheet );
m_pins.at( libPin ).SetFlags( BUSY ); stalePins.erase( libPin );
} }
for( auto& it : m_pins ) for( auto& stalePin : stalePins )
{ m_pins.erase( stalePin );
if( !( it.second.GetFlags() & BUSY ) )
m_pins.erase( it.first );
}
} }
} }
@ -564,8 +515,7 @@ int SCH_COMPONENT::GetUnitCount() const
void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, COLOR4D aColor, GR_DRAWMODE aDrawMode, COLOR4D aColor, bool aDrawPinText )
bool aDrawPinText )
{ {
auto opts = PART_DRAW_OPTIONS::Default(); auto opts = PART_DRAW_OPTIONS::Default();
opts.draw_mode = aDrawMode; opts.draw_mode = aDrawMode;
@ -599,7 +549,7 @@ void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOff
SCH_FIELD* field = GetField( REFERENCE ); SCH_FIELD* field = GetField( REFERENCE );
if( field->IsVisible() && !field->IsMoving() ) if( field->IsVisible() )
{ {
field->Draw( aPanel, aDC, aOffset, aDrawMode ); field->Draw( aPanel, aDC, aOffset, aDrawMode );
} }
@ -607,33 +557,8 @@ void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOff
for( int ii = VALUE; ii < GetFieldCount(); ii++ ) for( int ii = VALUE; ii < GetFieldCount(); ii++ )
{ {
field = GetField( ii ); field = GetField( ii );
if( field->IsMoving() )
continue;
field->Draw( aPanel, aDC, aOffset, aDrawMode ); field->Draw( aPanel, aDC, aOffset, aDrawMode );
} }
#if 0
// Only for testing purposes, draw the component bounding box
{
EDA_RECT boundingBox = GetBoundingBox();
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
#if 1
if( GetField( REFERENCE )->IsVisible() )
{
boundingBox = GetField( REFERENCE )->GetBoundingBox();
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
}
if( GetField( VALUE )->IsVisible() )
{
boundingBox = GetField( VALUE )->GetBoundingBox();
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
}
#endif
}
#endif
} }

View File

@ -195,8 +195,6 @@ public:
bool Resolve( SYMBOL_LIB_TABLE& aLibTable, PART_LIB* aCacheLib = NULL ); bool Resolve( SYMBOL_LIB_TABLE& aLibTable, PART_LIB* aCacheLib = NULL );
static void ResolveAll( const SCH_COLLECTOR& aComponents, PART_LIBS* aLibs );
static void ResolveAll( const SCH_COLLECTOR& aComponents, SYMBOL_LIB_TABLE& aLibTable, static void ResolveAll( const SCH_COLLECTOR& aComponents, SYMBOL_LIB_TABLE& aLibTable,
PART_LIB* aCacheLib = NULL ); PART_LIB* aCacheLib = NULL );
@ -207,7 +205,7 @@ public:
* *
* @param aComponents collector of components in screen * @param aComponents collector of components in screen
*/ */
static void UpdateAllPinCaches( const SCH_COLLECTOR& aComponents ); static void UpdatePins( const SCH_COLLECTOR& aComponents );
/** /**
* Updates the local cache of SCH_PIN_CONNECTION objects for each pin * Updates the local cache of SCH_PIN_CONNECTION objects for each pin

View File

@ -218,38 +218,6 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
DrawGraphicText( clipbox, aDC, textpos, color, GetFullyQualifiedText(), orient, GetTextSize(), DrawGraphicText( clipbox, aDC, textpos, color, GetFullyQualifiedText(), orient, GetTextSize(),
GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
lineWidth, IsItalic(), IsBold() ); lineWidth, IsItalic(), IsBold() );
// While moving: don't loose visual contact to which component this label belongs.
if ( IsWireImage() )
{
const wxPoint origin = parentComponent->GetPosition();
textpos = GetTextPos() - origin;
textpos = parentComponent->GetScreenCoord( textpos );
textpos += parentComponent->GetPosition();
GRLine( clipbox, aDC, origin, textpos, 2, DARKGRAY );
}
/* Enable this to draw the bounding box around the text field to validate
* the bounding box calculations.
*/
#if 0
// Draw boundary box:
GRRect( aPanel->GetClipBox(), aDC, boundaryBox, 0, BROWN );
// Draw the text anchor point
/* Calculate the text position, according to the component
* orientation/mirror */
textpos = m_Pos - parentComponent->GetPosition();
textpos = parentComponent->GetScreenCoord( textpos );
textpos += parentComponent->GetPosition();
const int len = 10;
GRLine( clipbox, aDC,
textpos.x - len, textpos.y, textpos.x + len, textpos.y, 0, BLUE );
GRLine( clipbox, aDC,
textpos.x, textpos.y - len, textpos.x, textpos.y + len, 0, BLUE );
#endif
} }

View File

@ -100,8 +100,6 @@ void SCH_JUNCTION::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffs
if( aColor != COLOR4D::UNSPECIFIED ) if( aColor != COLOR4D::UNSPECIFIED )
color = aColor; color = aColor;
else if( aPanel->GetScreen() && !aPanel->GetScreen()->m_IsPrinting && GetState( BRIGHTENED ) )
color = GetLayerColor( LAYER_BRIGHTENED );
else else
color = GetLayerColor( ( conn && conn->IsBus() ) ? LAYER_BUS : m_Layer ); color = GetLayerColor( ( conn && conn->IsBus() ) ? LAYER_BUS : m_Layer );

View File

@ -315,8 +315,6 @@ void SCH_LINE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
color = Color; color = Color;
else if( m_color != COLOR4D::UNSPECIFIED ) else if( m_color != COLOR4D::UNSPECIFIED )
color = m_color; color = m_color;
else if( panel->GetScreen() && !panel->GetScreen()->m_IsPrinting && GetState( BRIGHTENED ) )
color = GetLayerColor( LAYER_BRIGHTENED );
else else
color = GetLayerColor( m_Layer ); color = GetLayerColor( m_Layer );

View File

@ -508,7 +508,7 @@ void SCH_SCREEN::UpdateSymbolLinks( bool aForce )
// Resolving will update the pin caches but we must ensure that this happens // Resolving will update the pin caches but we must ensure that this happens
// even if the libraries don't change. // even if the libraries don't change.
else else
SCH_COMPONENT::UpdateAllPinCaches( c ); SCH_COMPONENT::UpdatePins( c );
} }
} }

View File

@ -497,21 +497,10 @@ void SCH_SHEET::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
/* Draw text : SheetLabel */ /* Draw text : SheetLabel */
for( SCH_SHEET_PIN& sheetPin : m_pins ) for( SCH_SHEET_PIN& sheetPin : m_pins )
{
if( !sheetPin.IsMoving() )
sheetPin.Draw( aPanel, aDC, aOffset, aDrawMode, aColor ); sheetPin.Draw( aPanel, aDC, aOffset, aDrawMode, aColor );
} }
#if 0
// Only for testing purposes, draw the component bounding box
EDA_RECT boundingBox = GetBoundingBox();
GRRect( aPanel->GetClipBox(), aDC, boundingBox, 0, BROWN );
GRFilledCircle( aPanel->GetClipBox(), aDC, m_pos.x, m_pos.y, 10, 0, color, color );
#endif
}
const EDA_RECT SCH_SHEET::GetBoundingBox() const const EDA_RECT SCH_SHEET::GetBoundingBox() const
{ {
wxPoint end; wxPoint end;

View File

@ -316,8 +316,6 @@ void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset,
if( Color != COLOR4D::UNSPECIFIED ) if( Color != COLOR4D::UNSPECIFIED )
color = Color; color = Color;
else if( panel->GetScreen() && !panel->GetScreen()->m_IsPrinting && GetState( BRIGHTENED ) )
color = GetLayerColor( LAYER_BRIGHTENED );
else else
color = GetLayerColor( m_Layer ); color = GetLayerColor( m_Layer );
@ -334,14 +332,6 @@ void SCH_TEXT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& aOffset,
if( m_isDangling && panel) if( m_isDangling && panel)
DrawDanglingSymbol( panel, DC, GetTextPos() + aOffset, color ); DrawDanglingSymbol( panel, DC, GetTextPos() + aOffset, color );
// Enable these line to draw the bounding box (debug tests purposes only)
#if DRAW_BBOX
{
EDA_RECT BoundaryBox = GetBoundingBox();
GRRect( clipbox, DC, BoundaryBox, 0, BROWN );
}
#endif
} }