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 0111a24ab7..1f96e090e7 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -1184,6 +1184,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(); @@ -1203,7 +1221,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; @@ -1231,7 +1249,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 fd47e53813..e46a1060b4 100644 --- a/eeschema/tools/sch_drawing_tools.h +++ b/eeschema/tools/sch_drawing_tools.h @@ -60,6 +60,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_HIERLABEL* importHierLabel( SCH_SHEET* aSheet );