From 469c1c14ef3c6fce68af613a0d2ef6a96acfc82d Mon Sep 17 00:00:00 2001 From: Jonathan Warner Date: Tue, 28 Jan 2020 13:33:23 -0700 Subject: [PATCH] Eeschema: adjusted component sorting to work better --- eeschema/sch_bus_entry.cpp | 23 +++++++++++++++++++++++ eeschema/sch_bus_entry.h | 2 ++ eeschema/sch_field.cpp | 23 +++++++++++++++++++++++ eeschema/sch_field.h | 2 ++ eeschema/sch_line.cpp | 17 ++++++++++------- eeschema/sch_sheet.cpp | 17 +++++++++++++++++ eeschema/sch_sheet.h | 2 ++ eeschema/sch_text.cpp | 2 ++ 8 files changed, 81 insertions(+), 7 deletions(-) diff --git a/eeschema/sch_bus_entry.cpp b/eeschema/sch_bus_entry.cpp index 26608b4dd3..d2e59ab2d5 100644 --- a/eeschema/sch_bus_entry.cpp +++ b/eeschema/sch_bus_entry.cpp @@ -406,6 +406,29 @@ void SCH_BUS_ENTRY_BASE::GetMsgPanelInfo( EDA_UNITS aUnits, MSG_PANEL_ITEMS& aLi } +bool SCH_BUS_ENTRY_BASE::operator <( const SCH_ITEM& aItem ) const +{ + if( Type() != aItem.Type() ) + return Type() < aItem.Type(); + + auto component = static_cast( &aItem ); + + if( GetLayer() != component->GetLayer() ) + return GetLayer() < component->GetLayer(); + + if( GetPosition().x != component->GetPosition().x ) + return GetPosition().x < component->GetPosition().x; + + if( GetPosition().y != component->GetPosition().y ) + return GetPosition().y < component->GetPosition().y; + + if( m_End().x != component->m_End().x ) + return m_End().x < component->m_End().x; + + return m_End().y < component->m_End().y; +} + + bool SCH_BUS_WIRE_ENTRY::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { // Don't generate connections between bus entries and buses, since there is diff --git a/eeschema/sch_bus_entry.h b/eeschema/sch_bus_entry.h index 9e4a470687..9f76c27622 100644 --- a/eeschema/sch_bus_entry.h +++ b/eeschema/sch_bus_entry.h @@ -111,6 +111,8 @@ public: void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector& aList ) override; + bool operator <( const SCH_ITEM& aItem ) const override; + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index fdf1e85af0..52e19213b2 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -498,3 +498,26 @@ wxPoint SCH_FIELD::GetPosition() const return component->GetTransform().TransformCoordinate( pos ) + component->GetPosition(); } + + +bool SCH_FIELD::operator <( const SCH_ITEM& aItem ) const +{ + if( Type() != aItem.Type() ) + return Type() < aItem.Type(); + + auto field = static_cast( &aItem ); + + if( GetId() != field->GetId() ) + return GetId() < field->GetId(); + + if( GetText() != field->GetText() ) + return GetText() < field->GetText(); + + if( GetLibPosition().x != field->GetLibPosition().x ) + return GetLibPosition().x < field->GetLibPosition().x; + + if( GetLibPosition().y != field->GetLibPosition().y ) + return GetLibPosition().y < field->GetLibPosition().y; + + return GetName() < field->GetName(); +} diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index dc2920acb2..66781f8bee 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -201,6 +201,8 @@ public: EDA_ITEM* Clone() const override; + bool operator <( const SCH_ITEM& aItem ) const override; + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index a56b7f6760..d628bde484 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -692,16 +692,19 @@ bool SCH_LINE::operator <( const SCH_ITEM& aItem ) const auto line = static_cast( &aItem ); - if( GetLength() != line->GetLength() ) - return GetLength() < line->GetLength(); + if( GetLayer() != line->GetLayer() ) + return GetLayer() < line->GetLayer(); - if( m_start.x != line->m_start.x ) - return m_start.x < line->m_start.x; + if( GetStartPoint().x != line->GetStartPoint().x ) + return GetStartPoint().x < line->GetStartPoint().x; - if( m_start.y != line->m_start.y ) - return m_start.y < line->m_start.y; + if( GetStartPoint().y != line->GetStartPoint().y ) + return GetStartPoint().y < line->GetStartPoint().y; - return false; + if( GetEndPoint().x != line->GetEndPoint().x ) + return GetEndPoint().x < line->GetEndPoint().x; + + return GetEndPoint().y < line->GetEndPoint().y; } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 6d99795ae4..3339e7376c 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -971,6 +971,23 @@ SCH_SHEET& SCH_SHEET::operator=( const SCH_ITEM& aItem ) } +bool SCH_SHEET::operator <( const SCH_ITEM& aItem ) const +{ + if( Type() != aItem.Type() ) + return Type() < aItem.Type(); + + auto sheet = static_cast( &aItem ); + + if (m_name != sheet->m_name) + return m_name < sheet->m_name; + + if (m_fileName != sheet->m_fileName) + return m_fileName < sheet->m_fileName; + + return false; +} + + #if defined(DEBUG) void SCH_SHEET::Show( int nestLevel, std::ostream& os ) const diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index fa5e03f077..8d6df2366a 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -534,6 +534,8 @@ public: SCH_SHEET& operator=( const SCH_ITEM& aSheet ); + bool operator <( const SCH_ITEM& aItem ) const override; + void ViewGetLayers( int aLayers[], int& aCount ) const override; wxPoint GetPosition() const override { return m_pos; } diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 08fc0b5af1..92a6f15da2 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -270,6 +270,8 @@ bool SCH_TEXT::operator<( const SCH_ITEM& aItem ) const auto other = static_cast( &aItem ); + if( GetLayer() != other->GetLayer() ) + return GetLayer() < other->GetLayer(); if( GetPosition().x != other->GetPosition().x ) return GetPosition().x < other->GetPosition().x;