Auto-fill new net global / local label names from connectivity

Currently, new global or local net labels are auto-filled with the
net name if the wire is driven by a global or local label. This
currently happens recursively within SCH_LINE. This fix moves this
to determining the driver from the connectivity graph, and removes
the determination from the SCH_LINE code where it does not belong.
This commit is contained in:
JamesJ 2024-03-29 20:00:05 +00:00 committed by Jon Evans
parent 9957c58c14
commit b01796cb84
4 changed files with 23 additions and 51 deletions

View File

@ -101,47 +101,6 @@ wxString SCH_LINE::GetFriendlyName() const
}
wxString SCH_LINE::GetNetname( const SCH_SHEET_PATH& aSheet )
{
std::list<const SCH_LINE *> checkedLines;
checkedLines.push_back(this);
return FindWireSegmentNetNameRecursive( this, checkedLines, aSheet );
}
wxString SCH_LINE::FindWireSegmentNetNameRecursive( SCH_LINE *line,
std::list<const SCH_LINE *> &checkedLines,
const SCH_SHEET_PATH& aSheet ) const
{
for ( auto connected : line->ConnectedItems( aSheet ) )
{
if( connected->Type() == SCH_LINE_T )
{
if( std::find(checkedLines.begin(), checkedLines.end(),
connected ) == checkedLines.end() )
{
SCH_LINE* connectedLine = static_cast<SCH_LINE*>( connected );
checkedLines.push_back( connectedLine );
wxString netName = FindWireSegmentNetNameRecursive( connectedLine, checkedLines,
aSheet );
if( !netName.IsEmpty() )
return netName;
}
}
else if( connected->Type() == SCH_LABEL_T
|| connected->Type() == SCH_GLOBAL_LABEL_T
|| connected->Type() == SCH_DIRECTIVE_LABEL_T)
{
return static_cast<SCH_TEXT*>( connected )->GetText();
}
}
return "";
}
EDA_ITEM* SCH_LINE::Clone() const
{
return new SCH_LINE( *this );

View File

@ -63,14 +63,6 @@ public:
wxString GetFriendlyName() const override;
/**
* @brief This function travel though all the connected wire segments
* to look for connected labels.
* @param aSheet - the sheet where the current wire segment is located
* @return returns the name of the wire if connected labels found, otherwise empty string
*/
wxString GetNetname(const SCH_SHEET_PATH &aSheet);
bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
{
if( SCH_ITEM::IsType( aScanTypes ) )

View File

@ -1197,6 +1197,24 @@ SCH_LINE* SCH_DRAWING_TOOLS::findWire( const VECTOR2I& aPosition )
}
wxString SCH_DRAWING_TOOLS::findWireLabelDriverName( SCH_LINE* aWire )
{
wxASSERT( aWire->IsWire() );
SCH_SHEET_PATH sheetPath = m_frame->GetCurrentSheet();
if( SCH_CONNECTION* wireConnection = aWire->Connection( &sheetPath ) )
{
SCH_ITEM* wireDriver = wireConnection->Driver();
if( wireDriver && wireDriver->IsType( { SCH_LABEL_T, SCH_GLOBAL_LABEL_T } ) )
return wireConnection->LocalName();
}
return wxEmptyString;
}
SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType )
{
SCHEMATIC* schematic = getModel<SCHEMATIC>();
@ -1216,7 +1234,7 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
textItem = labelItem;
if( SCH_LINE* wire = findWire( aPosition ) )
netName = wire->GetNetname( m_frame->GetCurrentSheet() );
netName = findWireLabelDriverName( wire );
break;
@ -1244,7 +1262,7 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
textItem = labelItem;
if( SCH_LINE* wire = findWire( aPosition ) )
netName = wire->GetNetname( m_frame->GetCurrentSheet() );
netName = findWireLabelDriverName( wire );
break;

View File

@ -66,6 +66,9 @@ public:
private:
SCH_LINE* findWire( const VECTOR2I& aPosition );
///< Gets the (global) label name driving this wire, if it is driven by a label
wxString findWireLabelDriverName( SCH_LINE* aWire );
SCH_TEXT* createNewText( const VECTOR2I& aPosition, int aType );
SCH_SHEET_PIN* createNewSheetPin( SCH_SHEET* aSheet, const VECTOR2I& aPosition );