From b01796cb84d2c52b40af2752c8a345f374f46a82 Mon Sep 17 00:00:00 2001 From: JamesJ <13408010-JamesJCode@users.noreply.gitlab.com> Date: Fri, 29 Mar 2024 20:00:05 +0000 Subject: [PATCH] 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. --- eeschema/sch_line.cpp | 41 ---------------------------- eeschema/sch_line.h | 8 ------ eeschema/tools/sch_drawing_tools.cpp | 22 +++++++++++++-- eeschema/tools/sch_drawing_tools.h | 3 ++ 4 files changed, 23 insertions(+), 51 deletions(-) diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index 96eb364c42..efdd9fb777 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -101,47 +101,6 @@ wxString SCH_LINE::GetFriendlyName() const } -wxString SCH_LINE::GetNetname( const SCH_SHEET_PATH& aSheet ) -{ - std::list checkedLines; - checkedLines.push_back(this); - return FindWireSegmentNetNameRecursive( this, checkedLines, aSheet ); -} - - -wxString SCH_LINE::FindWireSegmentNetNameRecursive( SCH_LINE *line, - std::list &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( 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( connected )->GetText(); - } - - } - return ""; -} - - EDA_ITEM* SCH_LINE::Clone() const { return new SCH_LINE( *this ); diff --git a/eeschema/sch_line.h b/eeschema/sch_line.h index 29337deb91..8c44cf46be 100644 --- a/eeschema/sch_line.h +++ b/eeschema/sch_line.h @@ -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& aScanTypes ) const override { if( SCH_ITEM::IsType( aScanTypes ) ) diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index f11f629556..726e1fdb43 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -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(); @@ -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; diff --git a/eeschema/tools/sch_drawing_tools.h b/eeschema/tools/sch_drawing_tools.h index 8c6db6bb87..1b4e3e8c6f 100644 --- a/eeschema/tools/sch_drawing_tools.h +++ b/eeschema/tools/sch_drawing_tools.h @@ -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 );