Simplify dangling end stuff a bit and remove graphic lines from it.

This commit is contained in:
Jeff Young 2021-09-24 12:18:54 +01:00
parent d39f79b55b
commit 2d72ccb6ae
5 changed files with 60 additions and 108 deletions

View File

@ -312,41 +312,37 @@ bool SCH_BUS_WIRE_ENTRY::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aI
m_isDanglingStart = m_isDanglingEnd = true; m_isDanglingStart = m_isDanglingEnd = true;
// Wires and buses are stored in the list as a pair, start and end. This
// variable holds the start position from one iteration so it can be used
// when the end position is found.
wxPoint seg_start;
// Store the connection type and state for the start (0) and end (1) // Store the connection type and state for the start (0) and end (1)
bool has_wire[2] = { false }; bool has_wire[2] = { false };
bool has_bus[2] = { false }; bool has_bus[2] = { false };
for( const DANGLING_END_ITEM& each_item : aItemList ) for( unsigned ii = 0; ii < aItemList.size(); ii++ )
{ {
if( each_item.GetItem() == this ) DANGLING_END_ITEM& item = aItemList[ii];
if( item.GetItem() == this )
continue; continue;
switch( each_item.GetType() ) switch( item.GetType() )
{ {
case WIRE_START_END: case WIRE_END:
case WIRE_END_END: if( m_pos == item.GetPosition() )
if( m_pos == each_item.GetPosition() )
has_wire[0] = true; has_wire[0] = true;
else if( GetEnd() == each_item.GetPosition() ) else if( GetEnd() == item.GetPosition() )
has_wire[1] = true; has_wire[1] = true;
break; break;
case BUS_START_END: case BUS_END:
seg_start = each_item.GetPosition(); {
break; // The bus has created 2 DANGLING_END_ITEMs, one per end.
DANGLING_END_ITEM& nextItem = aItemList[++ii];
case BUS_END_END: if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), m_pos ) )
if( IsPointOnSegment( seg_start, each_item.GetPosition(), m_pos ) )
has_bus[0] = true; has_bus[0] = true;
else if( IsPointOnSegment( seg_start, each_item.GetPosition(), GetEnd() ) ) else if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), GetEnd() ) )
has_bus[1] = true; has_bus[1] = true;
}
break; break;
default: default:
@ -375,27 +371,27 @@ bool SCH_BUS_BUS_ENTRY::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aIt
m_isDanglingStart = m_isDanglingEnd = true; m_isDanglingStart = m_isDanglingEnd = true;
// Wires and buses are stored in the list as a pair, start and end. This for( unsigned ii = 0; ii < aItemList.size(); ii++ )
// variable holds the start position from one iteration so it can be used
// when the end position is found.
wxPoint seg_start;
for( const DANGLING_END_ITEM& each_item : aItemList )
{ {
if( each_item.GetItem() == this ) DANGLING_END_ITEM& item = aItemList[ii];
if( item.GetItem() == this )
continue; continue;
switch( each_item.GetType() ) switch( item.GetType() )
{ {
case BUS_START_END: case BUS_END:
seg_start = each_item.GetPosition(); {
break; // The bus has created 2 DANGLING_END_ITEMs, one per end.
case BUS_END_END: DANGLING_END_ITEM& nextItem = aItemList[++ii];
if( IsPointOnSegment( seg_start, each_item.GetPosition(), m_pos ) )
if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), m_pos ) )
m_isDanglingStart = false; m_isDanglingStart = false;
if( IsPointOnSegment( seg_start, each_item.GetPosition(), GetEnd() ) ) if( IsPointOnSegment( item.GetPosition(), nextItem.GetPosition(), GetEnd() ) )
m_isDanglingEnd = false; m_isDanglingEnd = false;
}
break; break;
default: default:
break; break;
} }

View File

@ -60,12 +60,8 @@ enum FIELDS_AUTOPLACED
enum DANGLING_END_T enum DANGLING_END_T
{ {
UNKNOWN = 0, UNKNOWN = 0,
GRAPHIC_START_END, WIRE_END,
GRAPHIC_END_END, BUS_END,
WIRE_START_END,
WIRE_END_END,
BUS_START_END,
BUS_END_END,
JUNCTION_END, JUNCTION_END,
PIN_END, PIN_END,
LABEL_END, LABEL_END,
@ -91,8 +87,8 @@ public:
m_parent = aItem; m_parent = aItem;
} }
DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition,
const wxPoint& aPosition, const EDA_ITEM* aParent ) const EDA_ITEM* aParent )
{ {
m_item = aItem; m_item = aItem;
m_type = aType; m_type = aType;
@ -128,17 +124,10 @@ public:
DANGLING_END_T GetType() const { return m_type; } DANGLING_END_T GetType() const { return m_type; }
private: private:
/// A pointer to the connectable object. EDA_ITEM* m_item; /// A pointer to the connectable object.
EDA_ITEM* m_item; wxPoint m_pos; /// The position of the connection point.
DANGLING_END_T m_type; /// The type of connection of #m_item.
/// The position of the connection point. const EDA_ITEM* m_parent; /// A pointer to the parent object (in the case of pins)
wxPoint m_pos;
/// The type of connection of #m_item.
DANGLING_END_T m_type;
/// A pointer to the parent object (in the case of pins)
const EDA_ITEM* m_parent;
}; };

View File

@ -579,29 +579,11 @@ SCH_LINE* SCH_LINE::MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCh
void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList ) void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{ {
DANGLING_END_T startType, endType; if( IsConnectable() )
switch( GetLayer() )
{ {
case LAYER_WIRE: aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_start );
startType = WIRE_START_END; aItemList.emplace_back( IsBus() ? BUS_END : WIRE_END, this, m_end );
endType = WIRE_END_END;
break;
case LAYER_BUS:
startType = BUS_START_END;
endType = BUS_END_END;
break;
default:
startType = GRAPHIC_START_END;
endType = GRAPHIC_END_END;
break;
} }
DANGLING_END_ITEM item( startType, this, m_start );
aItemList.push_back( item );
DANGLING_END_ITEM item1( endType, this, m_end );
aItemList.push_back( item1 );
} }
@ -618,34 +600,26 @@ bool SCH_LINE::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
if( item.GetItem() == this ) if( item.GetItem() == this )
continue; continue;
if( ( IsWire() if( ( IsWire() && item.GetType() != BUS_END && item.GetType() != BUS_ENTRY_END )
&& ( item.GetType() == BUS_START_END || item.GetType() == BUS_END_END || ( IsBus() && item.GetType() != WIRE_END && item.GetType() != PIN_END ) )
|| item.GetType() == BUS_ENTRY_END ) ) {
|| ( IsBus() if( m_start == item.GetPosition() )
&& ( item.GetType() == WIRE_START_END || item.GetType() == WIRE_END_END m_startIsDangling = false;
|| item.GetType() == PIN_END ) )
|| ( IsGraphicLine()
&& ( item.GetType() != GRAPHIC_START_END && item.GetType() != GRAPHIC_END_END ) ) )
continue;
if( m_start == item.GetPosition() ) if( m_end == item.GetPosition() )
m_startIsDangling = false; m_endIsDangling = false;
if( m_end == item.GetPosition() ) if( !m_startIsDangling && !m_endIsDangling )
m_endIsDangling = false; break;
}
if( !m_startIsDangling && !m_endIsDangling )
break;
} }
if( IsBus() || IsGraphicLine() ) // We only use the bus dangling state for automatic line starting, so we don't care if it
{ // has changed or not (and returning true will result in extra work)
// Force unchanged return state for graphic lines and busses if( IsBus() )
previousStartState = m_startIsDangling; return false;
previousEndState = m_endIsDangling; else
} return previousStartState != m_startIsDangling || previousEndState != m_endIsDangling;
return ( previousStartState != m_startIsDangling ) || ( previousEndState != m_endIsDangling );
} }

View File

@ -1555,8 +1555,7 @@ bool SCH_SYMBOL::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
case PIN_END: case PIN_END:
case LABEL_END: case LABEL_END:
case SHEET_LABEL_END: case SHEET_LABEL_END:
case WIRE_START_END: case WIRE_END:
case WIRE_END_END:
case NO_CONNECT_END: case NO_CONNECT_END:
case JUNCTION_END: case JUNCTION_END:

View File

@ -486,22 +486,16 @@ bool SCH_TEXT::UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
break; break;
case BUS_START_END: case BUS_END:
m_connectionType = CONNECTION_TYPE::BUS; m_connectionType = CONNECTION_TYPE::BUS;
KI_FALLTHROUGH; KI_FALLTHROUGH;
case WIRE_START_END: case WIRE_END:
{ {
// These schematic items have created 2 DANGLING_END_ITEM one per end. But being DANGLING_END_ITEM& nextItem = aItemList[++ii];
// a paranoid programmer, I'll check just in case.
ii++;
wxCHECK_MSG( ii < aItemList.size(), previousState != m_isDangling,
wxT( "Dangling end type list overflow. Bad programmer!" ) );
int accuracy = 1; // We have rounding issues with an accuracy of 0 int accuracy = 1; // We have rounding issues with an accuracy of 0
DANGLING_END_ITEM & nextItem = aItemList[ii];
m_isDangling = !TestSegmentHit( GetTextPos(), item.GetPosition(), m_isDangling = !TestSegmentHit( GetTextPos(), item.GetPosition(),
nextItem.GetPosition(), accuracy ); nextItem.GetPosition(), accuracy );