diff --git a/common/api/api_enums.cpp b/common/api/api_enums.cpp index d03e066d7d..12fe941077 100644 --- a/common/api/api_enums.cpp +++ b/common/api/api_enums.cpp @@ -75,7 +75,6 @@ KICAD_T FromProtoEnum( types::KiCadObjectType aValue ) case types::KiCadObjectType::KOT_SCH_SHEET: return SCH_SHEET_T; case types::KiCadObjectType::KOT_SCH_PIN: return SCH_PIN_T; case types::KiCadObjectType::KOT_LIB_SYMBOL: return LIB_SYMBOL_T; - // case types::KiCadObjectType::KOT_LIB_PIN: return LIB_PIN_T; case types::KiCadObjectType::KOT_WSG_LINE: return WSG_LINE_T; case types::KiCadObjectType::KOT_WSG_RECT: return WSG_RECT_T; case types::KiCadObjectType::KOT_WSG_POLY: return WSG_POLY_T; @@ -135,7 +134,6 @@ types::KiCadObjectType ToProtoEnum( KICAD_T aValue ) case SCH_SHEET_T: return types::KiCadObjectType::KOT_SCH_SHEET; case SCH_PIN_T: return types::KiCadObjectType::KOT_SCH_PIN; case LIB_SYMBOL_T: return types::KiCadObjectType::KOT_LIB_SYMBOL; - // case LIB_PIN_T: return types::KiCadObjectType::KOT_LIB_PIN; case WSG_LINE_T: return types::KiCadObjectType::KOT_WSG_LINE; case WSG_RECT_T: return types::KiCadObjectType::KOT_WSG_RECT; case WSG_POLY_T: return types::KiCadObjectType::KOT_WSG_POLY; diff --git a/common/eda_item.cpp b/common/eda_item.cpp index 7a610a33b8..682e337882 100644 --- a/common/eda_item.cpp +++ b/common/eda_item.cpp @@ -396,7 +396,6 @@ static struct EDA_ITEM_DESC .Map( SCH_SCREEN_T, _HKI( "SCH Screen" ) ) .Map( LIB_SYMBOL_T, _HKI( "Symbol" ) ) - .Map( LIB_PIN_T, _HKI( "Pin" ) ) .Map( GERBER_LAYOUT_T, _HKI( "Gerber Layout" ) ) .Map( GERBER_DRAW_ITEM_T, _HKI( "Draw Item" ) ) diff --git a/common/gr_text.cpp b/common/gr_text.cpp index c90a5711d2..5fa8122da7 100644 --- a/common/gr_text.cpp +++ b/common/gr_text.cpp @@ -151,8 +151,13 @@ void GRPrintText( wxDC* aDC, const VECTOR2I& aPos, const COLOR4D& aColor, const if( !aFont ) aFont = KIFONT::FONT::GetFont(); - if( aWidth == 0 && aBold ) // Use default values if aWidth == 0 - aWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) ); + if( aWidth == 0 ) // Use default values if aWidth == 0 + { + if( aBold ) + aWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) ); + else + aWidth = GetPenSizeForNormal( std::min( aSize.x, aSize.y ) ); + } if( aWidth < 0 ) { diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index a3c994fd3f..7ace801cd1 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -353,7 +353,6 @@ set( EESCHEMA_SRCS generate_alias_info.cpp gfx_import_utils.cpp picksymbol.cpp - lib_pin.cpp lib_symbol.cpp libarch.cpp menubar.cpp diff --git a/eeschema/api/api_sch_utils.cpp b/eeschema/api/api_sch_utils.cpp index 62cb03db60..99faa38a99 100644 --- a/eeschema/api/api_sch_utils.cpp +++ b/eeschema/api/api_sch_utils.cpp @@ -18,7 +18,7 @@ * with this program. If not, see . */ -#include +#include #include #include #include @@ -41,10 +41,6 @@ std::unique_ptr CreateItemForType( KICAD_T aType, EDA_ITEM* aContainer ) { SCH_ITEM* parentSchItem = dynamic_cast( aContainer ); - LIB_SYMBOL* parentLibSymbol = nullptr; - - if( aContainer && aContainer->Type() == LIB_SYMBOL_T ) - parentLibSymbol = static_cast( aContainer ); switch( aType ) { @@ -83,13 +79,13 @@ std::unique_ptr CreateItemForType( KICAD_T aType, EDA_ITEM* aContainer case SCH_PIN_T: { - // TODO: constructing currently requires LIB_PIN and SCH_SYMBOL ptr, - // or SCH_SYMBOL and number+alt. Need to determine ideal default ctor. + if( aContainer && aContainer->Type() == LIB_SYMBOL_T ) + return std::make_unique( static_cast( aContainer ) ); + return nullptr; } case LIB_SYMBOL_T: return nullptr; // TODO: ctor currently requires non-null name - case LIB_PIN_T: return std::make_unique( parentLibSymbol ); default: return nullptr; diff --git a/eeschema/autoplace_fields.cpp b/eeschema/autoplace_fields.cpp index 4e460639e4..78a59e2cf2 100644 --- a/eeschema/autoplace_fields.cpp +++ b/eeschema/autoplace_fields.cpp @@ -53,10 +53,9 @@ #include #include -#include #include #include -#include +#include #include #include #include diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index 16aa9ebc8b..13c292dd37 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -654,9 +654,7 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco } else if( item->Type() == SCH_SHEET_T ) { - SCH_SHEET* sheet = static_cast( item ); - - for( SCH_SHEET_PIN* pin : sheet->GetPins() ) + for( SCH_SHEET_PIN* pin : static_cast( item )->GetPins() ) { if( pin->IsConnectivityDirty() ) { @@ -976,7 +974,7 @@ void CONNECTION_GRAPH::removeSubgraphs( std::set& aSubgrap for( auto it = m_net_name_to_code_map.begin(); it != m_net_name_to_code_map.end(); ) { - if( codes_to_remove.find( it->second ) != codes_to_remove.end() ) + if( codes_to_remove.contains( it->second ) ) it = m_net_name_to_code_map.erase( it ); else ++it; @@ -984,7 +982,7 @@ void CONNECTION_GRAPH::removeSubgraphs( std::set& aSubgrap for( auto it = m_bus_name_to_code_map.begin(); it != m_bus_name_to_code_map.end(); ) { - if( codes_to_remove.find( it->second ) != codes_to_remove.end() ) + if( codes_to_remove.contains( it->second ) ) it = m_bus_name_to_code_map.erase( it ); else ++it; @@ -1657,7 +1655,7 @@ void CONNECTION_GRAPH::processSubGraphs() { wxString new_name = create_new_name( connection ); - while( m_net_name_to_subgraphs_map.count( new_name ) ) + while( m_net_name_to_subgraphs_map.contains( new_name ) ) new_name = create_new_name( connection ); wxLogTrace( ConnTrace, @@ -2388,7 +2386,7 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph, boo { if( !candidate->m_strong_driver || candidate->m_hier_ports.empty() - || visited.count( candidate ) ) + || visited.contains( candidate ) ) { continue; } @@ -2425,7 +2423,7 @@ void CONNECTION_GRAPH::propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph, boo for( CONNECTION_SUBGRAPH* candidate : it->second ) { if( candidate->m_hier_pins.empty() - || visited.count( candidate ) + || visited.contains( candidate ) || candidate->m_driver_connection->Type() != aParent->m_driver_connection->Type() ) { continue; @@ -3470,7 +3468,7 @@ bool CONNECTION_GRAPH::ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph if( pin ) { ercItem->SetItems( pin, aSubgraph->m_no_connect ); - pos = pin->GetTransformedPosition(); + pos = pin->GetPosition(); } else { @@ -3586,7 +3584,7 @@ bool CONNECTION_GRAPH::ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph ercItem->SetItemsSheetPaths( sheet ); ercItem->SetItems( pin ); - SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetTransformedPosition() ); + SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() ); screen->Append( marker ); ok = false; @@ -3611,8 +3609,7 @@ bool CONNECTION_GRAPH::ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph ercItem->SetItemsSheetPaths( sheet ); ercItem->SetItems( testPin ); - SCH_MARKER* marker = new SCH_MARKER( ercItem, - testPin->GetTransformedPosition() ); + SCH_MARKER* marker = new SCH_MARKER( ercItem, testPin->GetPosition() ); screen->Append( marker ); ok = false; diff --git a/eeschema/dialogs/dialog_erc.h b/eeschema/dialogs/dialog_erc.h index 3bc539bbfa..c8883dd78c 100644 --- a/eeschema/dialogs/dialog_erc.h +++ b/eeschema/dialogs/dialog_erc.h @@ -26,11 +26,9 @@ #define _DIALOG_ERC_H_ #include -#include // For PINTYPE_COUNT definition #include #include -#include /** diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index 26c92bbae4..5afb397253 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -162,14 +162,10 @@ DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const * pinNumber pinName pinNumber pinName... * fpFilter fpFilter... */ - wxString netlist; - - std::vector pinList; - symbol->GetPins( pinList, 0, 1 ); // All units, but a single convert - + wxString netlist; wxArrayString pins; - for( LIB_PIN* pin : pinList ) + for( SCH_PIN* pin : symbol->GetPins( 0 /* all units */, 1 /* single bodyStyle */ ) ) pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() ); if( !pins.IsEmpty() ) diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index 8ece0263b3..d4bc958c85 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -23,8 +23,8 @@ #include "dialog_lib_edit_pin_table.h" #include "grid_tricks.h" -#include "lib_pin.h" -#include "pin_numbers.h" +#include +#include #include "pgm_base.h" #include #include @@ -155,7 +155,7 @@ public: return GetValue( m_rows[ aRow ], aCol, m_frame ); } - static wxString GetValue( const std::vector& pins, int aCol, + static wxString GetValue( const std::vector& pins, int aCol, EDA_DRAW_FRAME* aParentFrame ) { wxString fieldValue; @@ -163,7 +163,7 @@ public: if( pins.empty() ) return fieldValue; - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : pins ) { wxString val; @@ -292,7 +292,7 @@ public: break; } - std::vector pins = m_rows[ aRow ]; + std::vector pins = m_rows[ aRow ]; // If the NUMBER column is edited and the pins are grouped, renumber, and add or // remove pins based on the comma separated list of pins. @@ -316,8 +316,8 @@ public: else { // Create new pins - LIB_PIN* newPin = new LIB_PIN( this->m_symbol ); - LIB_PIN* last = pins.back(); + SCH_PIN* newPin = new SCH_PIN( this->m_symbol ); + SCH_PIN* last = pins.back(); newPin->SetNumber( pinName ); newPin->SetName( last->GetName() ); @@ -361,7 +361,7 @@ public: return; } - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : pins ) { switch( aCol ) { @@ -454,7 +454,7 @@ public: m_edited = true; } - static int findRow( const std::vector>& aRowSet, const wxString& aName ) + static int findRow( const std::vector>& aRowSet, const wxString& aName ) { for( size_t i = 0; i < aRowSet.size(); ++i ) { @@ -465,7 +465,7 @@ public: return -1; } - static bool compare( const std::vector& lhs, const std::vector& rhs, + static bool compare( const std::vector& lhs, const std::vector& rhs, int sortCol, bool ascending, EDA_DRAW_FRAME* parentFrame ) { wxString lhStr = GetValue( lhs, sortCol, parentFrame ); @@ -518,10 +518,10 @@ public: return res; } - void RebuildRows( const std::vector& aPins, bool groupByName, bool groupBySelection ) + void RebuildRows( const std::vector& aPins, bool groupByName, bool groupBySelection ) { WX_GRID* grid = dynamic_cast( GetView() ); - std::vector clear_flags; + std::vector clear_flags; clear_flags.reserve( aPins.size() ); @@ -529,7 +529,7 @@ public: { if( groupBySelection ) { - for( LIB_PIN* pin : aPins ) + for( SCH_PIN* pin : aPins ) pin->ClearTempFlags(); int firstSelectedRow; @@ -539,7 +539,7 @@ public: for( int ii = 0; ii < selectedRowCount; ++ii ) { - for( LIB_PIN* pin : m_rows[ firstSelectedRow + ii ] ) + for( SCH_PIN* pin : m_rows[ firstSelectedRow + ii ] ) { pin->SetFlags( CANDIDATE ); clear_flags.push_back( pin ); @@ -558,9 +558,9 @@ public: m_rows.clear(); if( groupBySelection ) - m_rows.emplace_back( std::vector() ); + m_rows.emplace_back( std::vector() ); - for( LIB_PIN* pin : aPins ) + for( SCH_PIN* pin : aPins ) { if( m_unitFilter == -1 || pin->GetUnit() == 0 || pin->GetUnit() == m_unitFilter ) { @@ -573,7 +573,7 @@ public: if( rowIndex < 0 ) { - m_rows.emplace_back( std::vector() ); + m_rows.emplace_back( std::vector() ); rowIndex = m_rows.size() - 1; } @@ -590,7 +590,7 @@ public: ascending = GetView()->IsSortOrderAscending(); } - for( std::vector& row : m_rows ) + for( std::vector& row : m_rows ) SortPins( row ); if( !groupBySelection ) @@ -605,32 +605,32 @@ public: GetView()->SelectRow( 0 ); } - for( LIB_PIN* pin : clear_flags ) + for( SCH_PIN* pin : clear_flags ) pin->ClearFlags( CANDIDATE ); } void SortRows( int aSortCol, bool ascending ) { std::sort( m_rows.begin(), m_rows.end(), - [ aSortCol, ascending, this ]( const std::vector& lhs, - const std::vector& rhs ) -> bool + [ aSortCol, ascending, this ]( const std::vector& lhs, + const std::vector& rhs ) -> bool { return compare( lhs, rhs, aSortCol, ascending, m_frame ); } ); } - void SortPins( std::vector& aRow ) + void SortPins( std::vector& aRow ) { std::sort( aRow.begin(), aRow.end(), - []( LIB_PIN* lhs, LIB_PIN* rhs ) -> bool + []( SCH_PIN* lhs, SCH_PIN* rhs ) -> bool { return PIN_NUMBERS::Compare( lhs->GetNumber(), rhs->GetNumber() ) < 0; } ); } - void AppendRow( LIB_PIN* aPin ) + void AppendRow( SCH_PIN* aPin ) { - std::vector row; + std::vector row; row.push_back( aPin ); m_rows.push_back( row ); @@ -641,9 +641,9 @@ public: } } - std::vector RemoveRow( int aRow ) + std::vector RemoveRow( int aRow ) { - std::vector removedRow = m_rows[ aRow ]; + std::vector removedRow = m_rows[ aRow ]; m_rows.erase( m_rows.begin() + aRow ); @@ -656,7 +656,7 @@ public: return removedRow; } - std::vector GetRowPins( int aRow ) + std::vector GetRowPins( int aRow ) { return m_rows[ aRow ]; } @@ -698,9 +698,9 @@ private: SYMBOL_EDIT_FRAME* m_frame; // Because the rows of the grid can either be a single pin or a group of pins, the - // data model is a 2D vector. If we're in the single pin case, each row's LIB_PINs + // data model is a 2D vector. If we're in the single pin case, each row's SCH_PINs // contains only a single pin. - std::vector> m_rows; + std::vector> m_rows; int m_unitFilter; // 0 to show pins for all units bool m_edited; @@ -709,7 +709,7 @@ private: LIB_SYMBOL* m_symbol; // Parent symbol that the pins belong to. std::unique_ptr m_eval; - std::map< std::pair, int>, wxString > m_evalOriginal; + std::map< std::pair, int>, wxString > m_evalOriginal; }; @@ -866,7 +866,7 @@ DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE() // This is our copy of the pins. If they were transferred to the part on an OK, then // m_pins will already be empty. - for( LIB_PIN* pin : m_pins ) + for( SCH_PIN* pin : m_pins ) delete pin; WINDOW_THAWER thawer( m_editFrame ); @@ -879,10 +879,10 @@ DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE() bool DIALOG_LIB_EDIT_PIN_TABLE::TransferDataToWindow() { // Make a copy of the pins for editing - std::vector pins = m_symbol->GetAllLibPins(); + std::vector pins = m_symbol->GetAllLibPins(); - for( LIB_PIN* pin : pins ) - m_pins.push_back( new LIB_PIN( *pin ) ); + for( SCH_PIN* pin : pins ) + m_pins.push_back( new SCH_PIN( *pin ) ); m_dataModel->RebuildRows( m_pins, m_cbGroup->GetValue(), false ); @@ -908,16 +908,14 @@ bool DIALOG_LIB_EDIT_PIN_TABLE::TransferDataFromWindow() return false; // Delete the part's pins - std::vector pins = m_symbol->GetAllLibPins(); + std::vector pins = m_symbol->GetAllLibPins(); - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : pins ) m_symbol->RemoveDrawItem( pin ); // Transfer our pins to the part - for( LIB_PIN* pin : m_pins ) - { + for( SCH_PIN* pin : m_pins ) m_symbol->AddDrawItem( pin ); - } m_pins.clear(); @@ -948,12 +946,12 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow( wxCommandEvent& event ) if( !m_grid->CommitPendingChanges() ) return; - LIB_PIN* newPin = new LIB_PIN( this->m_symbol ); + SCH_PIN* newPin = new SCH_PIN( this->m_symbol ); // Copy the settings of the last pin onto the new pin. if( m_pins.size() > 0 ) { - LIB_PIN* last = m_pins.back(); + SCH_PIN* last = m_pins.back(); newPin->SetOrientation( last->GetOrientation() ); newPin->SetType( last->GetType() ); @@ -991,7 +989,7 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow( wxCommandEvent& event ) } -void DIALOG_LIB_EDIT_PIN_TABLE::AddPin( LIB_PIN* pin ) +void DIALOG_LIB_EDIT_PIN_TABLE::AddPin( SCH_PIN* pin ) { m_pins.push_back( pin ); updateSummary(); @@ -1018,16 +1016,16 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow( wxCommandEvent& event ) m_grid->SetGridCursor( nextSelRow, m_grid->GetGridCursorCol() ); m_grid->SelectRow( nextSelRow ); - std::vector removedRow = m_dataModel->RemoveRow( curRow ); + std::vector removedRow = m_dataModel->RemoveRow( curRow ); - for( LIB_PIN* pin : removedRow ) + for( SCH_PIN* pin : removedRow ) m_pins.erase( std::find( m_pins.begin(), m_pins.end(), pin ) ); updateSummary(); } -void DIALOG_LIB_EDIT_PIN_TABLE::RemovePin( LIB_PIN* pin ) +void DIALOG_LIB_EDIT_PIN_TABLE::RemovePin( SCH_PIN* pin ) { m_pins.erase( std::find( m_pins.begin(), m_pins.end(), pin ) ); updateSummary(); @@ -1042,15 +1040,15 @@ void DIALOG_LIB_EDIT_PIN_TABLE::OnCellEdited( wxGridEvent& event ) void DIALOG_LIB_EDIT_PIN_TABLE::OnCellSelected( wxGridEvent& event ) { - LIB_PIN* pin = nullptr; + SCH_PIN* pin = nullptr; if( event.GetRow() >= 0 && event.GetRow() < m_dataModel->GetNumberRows() ) { - const std::vector& pins = m_dataModel->GetRowPins( event.GetRow() ); + const std::vector& pins = m_dataModel->GetRowPins( event.GetRow() ); if( pins.size() == 1 && m_editFrame->GetCurSymbol() ) { - for( LIB_PIN* candidate : m_editFrame->GetCurSymbol()->GetAllLibPins() ) + for( SCH_PIN* candidate : m_editFrame->GetCurSymbol()->GetAllLibPins() ) { if( candidate->GetNumber() == pins.at( 0 )->GetNumber() ) { @@ -1256,7 +1254,7 @@ void DIALOG_LIB_EDIT_PIN_TABLE::updateSummary() { PIN_NUMBERS pinNumbers; - for( LIB_PIN* pin : m_pins ) + for( SCH_PIN* pin : m_pins ) { if( pin->GetNumber().Length() ) pinNumbers.insert( pin->GetNumber() ); diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.h b/eeschema/dialogs/dialog_lib_edit_pin_table.h index 2069a658ab..937c25e09e 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.h +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.h @@ -23,8 +23,7 @@ #include "dialog_lib_edit_pin_table_base.h" -#include -#include +#include enum COL_ORDER { @@ -73,8 +72,8 @@ public: void OnUpdateUI( wxUpdateUIEvent& event ) override; void OnCancel( wxCommandEvent& event ) override; void OnClose( wxCloseEvent& event ) override; - void AddPin( LIB_PIN* pin ); - void RemovePin( LIB_PIN* pin ); + void AddPin( SCH_PIN* pin ); + void RemovePin( SCH_PIN* pin ); bool IsDisplayGrouped(); protected: @@ -87,7 +86,7 @@ protected: int m_originalColWidths[ COL_COUNT ]; std::bitset<64> m_columnsShown; LIB_SYMBOL* m_symbol; - std::vector m_pins; // a copy of the pins owned by me + std::vector m_pins; // a copy of the pins owned by me bool m_modified; ///< true when there are unsaved changes wxSize m_size; diff --git a/eeschema/dialogs/dialog_pin_properties.cpp b/eeschema/dialogs/dialog_pin_properties.cpp index 728bc61961..55bdc688b9 100644 --- a/eeschema/dialogs/dialog_pin_properties.cpp +++ b/eeschema/dialogs/dialog_pin_properties.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -36,7 +36,7 @@ #include #include -class ALT_PIN_DATA_MODEL : public wxGridTableBase, public std::vector +class ALT_PIN_DATA_MODEL : public wxGridTableBase, public std::vector { public: ALT_PIN_DATA_MODEL( EDA_UNITS aUserUnits ) @@ -99,7 +99,7 @@ public: } } - void AppendRow( const LIB_PIN::ALT& aAlt ) + void AppendRow( const SCH_PIN::ALT& aAlt ) { push_back( aAlt ); @@ -123,7 +123,7 @@ public: }; -DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES( SYMBOL_EDIT_FRAME* parent, LIB_PIN* aPin ) : +DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES( SYMBOL_EDIT_FRAME* parent, SCH_PIN* aPin ) : DIALOG_PIN_PROPERTIES_BASE( parent ), m_frame( parent ), m_pin( aPin ), @@ -138,7 +138,7 @@ DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES( SYMBOL_EDIT_FRAME* parent, LIB_PIN { // Creates a dummy pin to show on a panel, inside this dialog: m_dummyParent = new LIB_SYMBOL( *static_cast( m_pin->GetParentSymbol() ) ); - m_dummyPin = new LIB_PIN( *m_pin ); + m_dummyPin = new SCH_PIN( *m_pin ); m_dummyPin->SetParent( m_dummyParent ); m_dummyParent->SetShowPinNames( true ); m_dummyParent->SetShowPinNumbers( true ); @@ -306,7 +306,7 @@ bool DIALOG_PIN_PROPERTIES::TransferDataToWindow() m_checkApplyToAllParts->SetToolTip( commonUnitsToolTip ); - for( const std::pair& alt : m_pin->GetAlternates() ) + for( const std::pair& alt : m_pin->GetAlternates() ) m_alternatesDataModel->AppendRow( alt.second ); return true; @@ -364,10 +364,10 @@ bool DIALOG_PIN_PROPERTIES::TransferDataFromWindow() m_pin->SetUnit( m_checkApplyToAllParts->GetValue() ? 0 : m_frame->GetUnit() ); m_pin->SetVisible( m_checkShow->GetValue() ); - std::map& alternates = m_pin->GetAlternates(); + std::map& alternates = m_pin->GetAlternates(); alternates.clear(); - for( const LIB_PIN::ALT& alt : *m_alternatesDataModel ) + for( const SCH_PIN::ALT& alt : *m_alternatesDataModel ) alternates[ alt.m_Name ] = alt; return true; @@ -450,7 +450,7 @@ void DIALOG_PIN_PROPERTIES::OnAddAlternate( wxCommandEvent& event ) if( !m_alternatesGrid->CommitPendingChanges() ) return; - LIB_PIN::ALT newAlt; + SCH_PIN::ALT newAlt; newAlt.m_Name = wxEmptyString; newAlt.m_Type = m_pin->GetType(); newAlt.m_Shape = m_pin->GetShape(); diff --git a/eeschema/dialogs/dialog_pin_properties.h b/eeschema/dialogs/dialog_pin_properties.h index 14cf7dc88b..6f79bba94a 100644 --- a/eeschema/dialogs/dialog_pin_properties.h +++ b/eeschema/dialogs/dialog_pin_properties.h @@ -33,7 +33,7 @@ #include #include -#include +#include #include @@ -53,7 +53,7 @@ class ALT_PIN_DATA_MODEL; class DIALOG_PIN_PROPERTIES : public DIALOG_PIN_PROPERTIES_BASE { public: - DIALOG_PIN_PROPERTIES( SYMBOL_EDIT_FRAME* parent, LIB_PIN* aPin ); + DIALOG_PIN_PROPERTIES( SYMBOL_EDIT_FRAME* parent, SCH_PIN* aPin ); ~DIALOG_PIN_PROPERTIES() override; bool TransferDataToWindow() override; @@ -73,10 +73,10 @@ protected: private: SYMBOL_EDIT_FRAME* m_frame; - LIB_PIN* m_pin; + SCH_PIN* m_pin; LIB_SYMBOL* m_dummyParent; - LIB_PIN* m_dummyPin; // a working copy used to show changes + SCH_PIN* m_dummyPin; // a working copy used to show changes UNIT_BINDER m_posX; UNIT_BINDER m_posY; diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index 38866c7726..2584b4a53c 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -79,7 +79,7 @@ DIALOG_SIM_MODEL::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame { m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) ); - for( LIB_PIN* pin : aSymbol.GetAllLibPins() ) + for( SCH_PIN* pin : aSymbol.GetAllLibPins() ) { // De Morgan conversions are equivalences, not additional items to simulate if( !pin->GetParentSymbol()->HasAlternateBodyStyle() || pin->GetBodyStyle() < 2 ) @@ -87,7 +87,7 @@ DIALOG_SIM_MODEL::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame } std::sort( m_sortedPartPins.begin(), m_sortedPartPins.end(), - []( const LIB_PIN* lhs, const LIB_PIN* rhs ) + []( const SCH_PIN* lhs, const SCH_PIN* rhs ) { // We sort by StrNumCmp because SIM_MODEL_BASE sorts with it too. return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0; @@ -1064,7 +1064,7 @@ int DIALOG_SIM_MODEL::findSymbolPinRow( const wxString& aSymbolPinNumber ) co { for( int row = 0; row < static_cast( m_sortedPartPins.size() ); ++row ) { - LIB_PIN* pin = m_sortedPartPins[row]; + SCH_PIN* pin = m_sortedPartPins[row]; if( pin->GetNumber() == aSymbolPinNumber ) return row; @@ -1107,7 +1107,7 @@ const SIM_LIBRARY* DIALOG_SIM_MODEL::library() const template wxString DIALOG_SIM_MODEL::getSymbolPinString( int symbolPinIndex ) const { - LIB_PIN* pin = m_sortedPartPins.at( symbolPinIndex ); + SCH_PIN* pin = m_sortedPartPins.at( symbolPinIndex ); wxString pinNumber; wxString pinName; diff --git a/eeschema/dialogs/dialog_sim_model.h b/eeschema/dialogs/dialog_sim_model.h index 62184a37d9..daae964f62 100644 --- a/eeschema/dialogs/dialog_sim_model.h +++ b/eeschema/dialogs/dialog_sim_model.h @@ -130,7 +130,7 @@ private: wxString m_prevLibrary; const SIM_MODEL* m_prevModel; - std::vector m_sortedPartPins; //< Pins of the current part. + std::vector m_sortedPartPins; //< Pins of the current part. std::map m_curModelTypeOfDeviceType; SIM_MODEL::TYPE m_curModelType; diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 6a279efa81..a735de0600 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -100,7 +100,7 @@ public: for( const SCH_PIN& pin : *this ) { - LIB_PIN* lib_pin = pin.GetLibPin(); + SCH_PIN* lib_pin = pin.GetLibPin(); wxGridCellAttr* attr = nullptr; if( lib_pin->GetAlternates().empty() ) @@ -114,7 +114,7 @@ public: wxArrayString choices; choices.push_back( lib_pin->GetName() ); - for( const std::pair& alt : lib_pin->GetAlternates() ) + for( const std::pair& alt : lib_pin->GetAlternates() ) choices.push_back( alt.first ); attr = new wxGridCellAttr(); diff --git a/eeschema/dialogs/panel_eeschema_color_settings.cpp b/eeschema/dialogs/panel_eeschema_color_settings.cpp index 9cbd75949f..63c1aa058e 100644 --- a/eeschema/dialogs/panel_eeschema_color_settings.cpp +++ b/eeschema/dialogs/panel_eeschema_color_settings.cpp @@ -389,7 +389,7 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() addItem( comp_body ); - LIB_PIN* pin = new LIB_PIN( symbol ); + SCH_PIN* pin = new SCH_PIN( symbol ); pin->SetPosition( MILS_POINT( p.x - 300, p.y + 100 ) ); pin->SetLength( schIUScale.MilsToIU( 100 ) ); @@ -403,7 +403,7 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() endPointsByType.emplace_back( PIN_END, pin, mapLibItemPosition( pin->GetPosition() ) ); symbol->AddDrawItem( pin ); - pin = new LIB_PIN( symbol ); + pin = new SCH_PIN( symbol ); pin->SetPosition( MILS_POINT( p.x - 300, p.y - 100 ) ); pin->SetLength( schIUScale.MilsToIU( 100 ) ); @@ -417,7 +417,7 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() endPointsByType.emplace_back( PIN_END, pin, mapLibItemPosition( pin->GetPosition() ) ); symbol->AddDrawItem( pin ); - pin = new LIB_PIN( symbol ); + pin = new SCH_PIN( symbol ); pin->SetPosition( MILS_POINT( p.x + 300, p.y ) ); pin->SetLength( schIUScale.MilsToIU( 100 ) ); diff --git a/eeschema/dialogs/panel_setup_pinmap.h b/eeschema/dialogs/panel_setup_pinmap.h index debe3fb48c..8d22e43ab5 100644 --- a/eeschema/dialogs/panel_setup_pinmap.h +++ b/eeschema/dialogs/panel_setup_pinmap.h @@ -25,7 +25,7 @@ #ifndef _PANEL_SETUP_PINMAP_H_ #define _PANEL_SETUP_PINMAP_H_ -#include // For PINTYPE_COUNT definition +#include // For PINTYPE_COUNT definition #include #include "panel_setup_pinmap_base.h" diff --git a/eeschema/ee_collectors.cpp b/eeschema/ee_collectors.cpp index 1b4f57735a..a4194c7129 100644 --- a/eeschema/ee_collectors.cpp +++ b/eeschema/ee_collectors.cpp @@ -96,7 +96,7 @@ INSPECT_RESULT EE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) // Special selection rules apply to pins of different units when edited in synchronized // pins mode. Leave it to EE_SELECTION_TOOL::Selectable() to decide what to do with them. - if( schItem && schItem->Type() != LIB_PIN_T ) + if( schItem && schItem->Type() != SCH_PIN_T ) { if( m_Unit && schItem->GetUnit() && schItem->GetUnit() != m_Unit ) return INSPECT_RESULT::CONTINUE; diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index 9f015cc7df..c8243321e9 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include @@ -493,8 +493,7 @@ int ERC_TESTER::TestMissingUnits() for( int missing_unit : missing_units ) { - std::vector pins; - int bodyStyle = 0; + int bodyStyle = 0; for( size_t ii = 0; ii < refList.GetCount(); ++ii ) { @@ -505,9 +504,7 @@ int ERC_TESTER::TestMissingUnits() } } - libSymbol->GetPins( pins, missing_unit, bodyStyle ); - - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : libSymbol->GetPins( missing_unit, bodyStyle ) ) { switch( pin->GetType() ) { @@ -728,7 +725,7 @@ int ERC_TESTER::TestPinToPin() ERC_SCH_PIN_CONTEXT& refPin = *refIt; ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType(); - if( DrivenPinTypes.count( refType ) ) + if( DrivenPinTypes.contains( refType ) ) { // needsDriver will be the pin shown in the error report eventually, so try to // upgrade to a "better" pin if possible: something visible and only a power symbol @@ -762,9 +759,9 @@ int ERC_TESTER::TestPinToPin() ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType(); if( ispowerNet ) - hasDriver |= ( DrivingPowerPinTypes.count( testType ) != 0 ); + hasDriver |= DrivingPowerPinTypes.contains( testType ); else - hasDriver |= ( DrivingPinTypes.count( testType ) != 0 ); + hasDriver |= DrivingPinTypes.contains( testType ); PIN_ERROR erc = settings.GetPinMapValue( refType, testType ); @@ -782,8 +779,7 @@ int ERC_TESTER::TestPinToPin() ElectricalPinTypeGetText( refType ), ElectricalPinTypeGetText( testType ) ) ); - SCH_MARKER* marker = new SCH_MARKER( ercItem, - refPin.Pin()->GetTransformedPosition() ); + SCH_MARKER* marker = new SCH_MARKER( ercItem, refPin.Pin()->GetPosition() ); pinToScreenMap[refPin.Pin()]->Append( marker ); errors++; } @@ -802,8 +798,7 @@ int ERC_TESTER::TestPinToPin() ercItem->SetSheetSpecificPath( needsDriver.Sheet() ); ercItem->SetItemsSheetPaths( needsDriver.Sheet() ); - SCH_MARKER* marker = new SCH_MARKER( ercItem, - needsDriver.Pin()->GetTransformedPosition() ); + SCH_MARKER* marker = new SCH_MARKER( ercItem, needsDriver.Pin()->GetPosition() ); pinToScreenMap[needsDriver.Pin()]->Append( marker ); errors++; } @@ -860,8 +855,7 @@ int ERC_TESTER::TestMultUnitPinConflicts() ercItem->SetSheetSpecificPath( sheet ); ercItem->SetItemsSheetPaths( sheet, sheet ); - SCH_MARKER* marker = new SCH_MARKER( ercItem, - pin->GetTransformedPosition() ); + SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() ); sheet.LastScreen()->Append( marker ); errors += 1; } @@ -1159,7 +1153,7 @@ int ERC_TESTER::TestOffGridEndpoints() for( SCH_PIN* pin : symbol->GetPins( nullptr ) ) { - VECTOR2I pinPos = pin->GetTransformedPosition(); + VECTOR2I pinPos = pin->GetPosition(); if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 ) { diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index 48dbf4c099..77d8273d20 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -99,15 +99,10 @@ static wxString netList( LIB_SYMBOL* aSymbol ) * pinNumber pinName pinNumber pinName... * fpFilter fpFilter... */ - wxString netlist; - - std::vector pinList; - - aSymbol->GetPins( pinList, 0, 1 ); // All units, but a single convert - + wxString netlist; wxArrayString pins; - for( LIB_PIN* pin : pinList ) + for( SCH_PIN* pin : aSymbol->GetPins( 0 /* all units */, 1 /* single bodyStyle */ ) ) pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() ); if( !pins.IsEmpty() ) diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp deleted file mode 100644 index eb0d2b4754..0000000000 --- a/eeschema/lib_pin.cpp +++ /dev/null @@ -1,1707 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sch_painter.h" -#include "plotters/plotter.h" - - -// small margin in internal units between the pin text and the pin line -#define PIN_TEXT_MARGIN 4 - -const wxString LIB_PIN::GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType ) -{ - // These strings are the canonical name of the electrictal type - // Not translated, no space in name, only ASCII chars. - // to use when the string name must be known and well defined - // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h) - static const wxChar* msgPinElectricType[] = - { - wxT( "input" ), - wxT( "output" ), - wxT( "bidirectional" ), - wxT( "tri_state" ), - wxT( "passive" ), - wxT( "free" ), - wxT( "unspecified" ), - wxT( "power_in" ), - wxT( "power_out" ), - wxT( "open_collector" ), - wxT( "open_emitter" ), - wxT( "no_connect" ) - }; - - return msgPinElectricType[static_cast( aType )]; -} - - -/// Utility for getting the size of the 'internal' pin decorators (as a radius) -// i.e. the clock symbols (falling clock is actually external but is of -// the same kind) - -static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin ) -{ - const SCH_RENDER_SETTINGS* settings = static_cast( aSettings ); - - if( settings && settings->m_PinSymbolSize ) - return settings->m_PinSymbolSize; - - return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2; -} - -/// Utility for getting the size of the 'external' pin decorators (as a radius) -// i.e. the negation circle, the polarity 'slopes' and the nonlogic -// marker -static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin ) -{ - const SCH_RENDER_SETTINGS* settings = static_cast( aSettings ); - - if( settings && settings->m_PinSymbolSize ) - return settings->m_PinSymbolSize; - - return aPin.GetNumberTextSize() / 2; -} - - -LIB_PIN::LIB_PIN( SCH_ITEM* aParent ) : - SCH_ITEM( aParent, LIB_PIN_T, 0, 0 ), - m_orientation( PIN_ORIENTATION::PIN_RIGHT ), - m_shape( GRAPHIC_PINSHAPE::LINE ), - m_type( ELECTRICAL_PINTYPE::PT_UNSPECIFIED ), - m_attributes( 0 ) -{ - // Use the application settings for pin sizes if exists. - // pgm can be nullptr when running a shared lib from a script, not from a kicad appl - PGM_BASE* pgm = PgmOrNull(); - - if( pgm ) - { - auto* settings = pgm->GetSettingsManager().GetAppSettings(); - m_length = schIUScale.MilsToIU( settings->m_Defaults.pin_length ); - m_numTextSize = schIUScale.MilsToIU( settings->m_Defaults.pin_num_size ); - m_nameTextSize = schIUScale.MilsToIU( settings->m_Defaults.pin_name_size ); - } - else // Use hardcoded eeschema defaults: symbol_editor settings are not existing. - { - m_length = schIUScale.MilsToIU( DEFAULT_PIN_LENGTH ); - m_numTextSize = schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE ); - m_nameTextSize = schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE ); - } -} - - -LIB_PIN::LIB_PIN( SCH_ITEM* aParent, const wxString& aName, const wxString& aNumber, - PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, - int aNameTextSize, int aNumTextSize, int aBodyStyle, const VECTOR2I& aPos, - int aUnit ) : - SCH_ITEM( aParent, LIB_PIN_T, aUnit, aBodyStyle ), - m_position( aPos ), - m_length( aLength ), - m_orientation( aOrientation ), - m_shape( GRAPHIC_PINSHAPE::LINE ), - m_type( aPinType ), - m_attributes( 0 ), - m_numTextSize( aNumTextSize ), - m_nameTextSize( aNameTextSize ) -{ - SetName( aName ); - SetNumber( aNumber ); -} - - -bool LIB_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const -{ - BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ); - - return rect.Inflate( aAccuracy ).Contains( aPosition ); -} - - -bool LIB_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const -{ - if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) ) - return false; - - BOX2I sel = aRect; - - if ( aAccuracy ) - sel.Inflate( aAccuracy ); - - if( aContained ) - return sel.Contains( GetBoundingBox( false, false, false ) ); - - return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) ); -} - - -int LIB_PIN::GetPenWidth() const -{ - return 0; -} - - -wxString LIB_PIN::GetShownName() const -{ - if( m_name == wxS( "~" ) ) - return wxEmptyString; - else - return m_name; -} - - -VECTOR2I LIB_PIN::GetPinRoot() const -{ - switch( m_orientation ) - { - default: - case PIN_ORIENTATION::PIN_RIGHT: return VECTOR2I( m_position.x + m_length, -( m_position.y ) ); - case PIN_ORIENTATION::PIN_LEFT: return VECTOR2I( m_position.x - m_length, -( m_position.y ) ); - case PIN_ORIENTATION::PIN_UP: return VECTOR2I( m_position.x, -( m_position.y + m_length ) ); - case PIN_ORIENTATION::PIN_DOWN: return VECTOR2I( m_position.x, -( m_position.y - m_length ) ); - } -} - - -void LIB_PIN::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle, - const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) -{ - LIB_SYMBOL* part = dynamic_cast( GetParentSymbol() ); - - wxCHECK( part && aSettings, /* void */ ); - - /* Calculate pin orient taking in account the symbol orientation. */ - PIN_ORIENTATION orient = PinDrawOrient( aSettings->m_Transform ); - - /* Calculate the pin position */ - VECTOR2I pos1 = aSettings->TransformCoordinate( m_position ) + aOffset; - - if( IsVisible() || aSettings->m_ShowHiddenFields ) - { - printPinSymbol( aSettings, pos1, orient, aDimmed ); - - printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(), - aSettings->m_ShowPinNumbers || part->GetShowPinNumbers(), - aSettings->m_ShowPinNames || part->GetShowPinNames(), - aDimmed ); - - if( aSettings->m_ShowPinElectricalTypes ) - printPinElectricalTypeName( aSettings, pos1, orient, aDimmed ); - - if( aSettings->m_ShowConnectionPoints - && m_type != ELECTRICAL_PINTYPE::PT_NC - && m_type != ELECTRICAL_PINTYPE::PT_NIC ) - { - wxDC* DC = aSettings->GetPrintDC(); - COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN ); - - COLOR4D bg = aSettings->GetBackgroundColor(); - - if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) - bg = COLOR4D::WHITE; - - if( aDimmed ) - { - color.Desaturate( ); - color = color.Mix( bg, 0.5f ); - } - - GRCircle( DC, pos1, TARGET_PIN_RADIUS, 0, color ); - } - } -} - - -void LIB_PIN::printPinSymbol( const SCH_RENDER_SETTINGS* aSettings, const VECTOR2I& aPos, - PIN_ORIENTATION aOrient, bool aDimmed ) -{ - wxDC* DC = aSettings->GetPrintDC(); - int MapX1, MapY1, x1, y1; - int width = GetEffectivePenWidth( aSettings ); - int posX = aPos.x, posY = aPos.y, len = m_length; - COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN ); - COLOR4D bg = aSettings->GetBackgroundColor(); - - if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) - bg = COLOR4D::WHITE; - - if( !IsVisible() ) - bg = aSettings->GetLayerColor( LAYER_HIDDEN ); - - if( aDimmed ) - { - color.Desaturate( ); - color = color.Mix( bg, 0.5f ); - } - - MapX1 = MapY1 = 0; - x1 = posX; - y1 = posY; - - switch( aOrient ) - { - case PIN_ORIENTATION::PIN_UP: y1 = posY - len; MapY1 = 1; break; - case PIN_ORIENTATION::PIN_DOWN: y1 = posY + len; MapY1 = -1; break; - case PIN_ORIENTATION::PIN_LEFT: x1 = posX - len; MapX1 = 1; break; - case PIN_ORIENTATION::PIN_RIGHT: x1 = posX + len; MapX1 = -1; break; - } - - if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK ) - { - const int radius = externalPinDecoSize( aSettings, *this ); - GRCircle( DC, VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius, width, color ); - - GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ); - GRLineTo( DC, posX, posY, width, color ); - } - else - { - GRMoveTo( x1, y1 ); - GRLineTo( DC, posX, posY, width, color ); - } - - // Draw the clock shape (>)inside the symbol - if( m_shape == GRAPHIC_PINSHAPE::CLOCK - || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK - || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK - || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) - { - const int clock_size = internalPinDecoSize( aSettings, *this ); - if( MapY1 == 0 ) /* MapX1 = +- 1 */ - { - GRMoveTo( x1, y1 + clock_size ); - GRLineTo( DC, x1 - MapX1 * clock_size * 2, y1, width, color ); - GRLineTo( DC, x1, y1 - clock_size, width, color ); - } - else /* MapX1 = 0 */ - { - GRMoveTo( x1 + clock_size, y1 ); - GRLineTo( DC, x1, y1 - MapY1 * clock_size * 2, width, color ); - GRLineTo( DC, x1 - clock_size, y1, width, color ); - } - } - - // Draw the active low (or H to L active transition) - if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW - || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK - || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) - { - const int deco_size = externalPinDecoSize( aSettings, *this ); - if( MapY1 == 0 ) /* MapX1 = +- 1 */ - { - GRMoveTo( x1 + MapX1 * deco_size * 2, y1 ); - GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color ); - GRLineTo( DC, x1, y1, width, color ); - } - else /* MapX1 = 0 */ - { - GRMoveTo( x1, y1 + MapY1 * deco_size * 2 ); - GRLineTo( DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color ); - GRLineTo( DC, x1, y1, width, color ); - } - } - - if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */ - { - const int deco_size = externalPinDecoSize( aSettings, *this ); - if( MapY1 == 0 ) /* MapX1 = +- 1 */ - { - GRMoveTo( x1, y1 - deco_size * 2 ); - GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1, width, color ); - } - else /* MapX1 = 0 */ - { - GRMoveTo( x1 - deco_size * 2, y1 ); - GRLineTo( DC, x1, y1 + MapY1 * deco_size * 2, width, color ); - } - } - else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */ - { - const int deco_size = externalPinDecoSize( aSettings, *this ); - GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size ); - GRLineTo( DC, x1 + (MapX1 + MapY1) * deco_size, y1 + ( MapY1 - MapX1 ) * deco_size, width, - color ); - GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size ); - GRLineTo( DC, x1 + (MapX1 - MapY1) * deco_size, y1 + ( MapY1 + MapX1 ) * deco_size, width, - color ); - } - - if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol - { - const int deco_size = TARGET_PIN_RADIUS; - GRLine( DC, posX - deco_size, posY - deco_size, posX + deco_size, posY + deco_size, width, - color ); - GRLine( DC, posX + deco_size, posY - deco_size, posX - deco_size, posY + deco_size, width, - color ); - } -} - - -void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos, - PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, - bool aDrawPinName, bool aDimmed ) -{ - if( !aDrawPinName && !aDrawPinNum ) - return; - - KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false ); - wxString name = GetShownName(); - wxString number = GetShownNumber(); - VECTOR2I nameSize( m_nameTextSize, m_nameTextSize ); - VECTOR2I numSize( m_numTextSize, m_numTextSize ); - int nameWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, true ), - aSettings->GetDefaultPenWidth() ); - int numWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, true ), - aSettings->GetDefaultPenWidth() ); - int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + nameWidth; - int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numWidth; - - /* Get the num and name colors */ - COLOR4D nameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN ); - COLOR4D numColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN ); - COLOR4D bg = aSettings->GetBackgroundColor(); - - if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) - bg = COLOR4D::WHITE; - - if( !IsVisible() ) - bg = aSettings->GetLayerColor( LAYER_HIDDEN ); - - if( aDimmed ) - { - nameColor.Desaturate(); - numColor.Desaturate(); - nameColor = nameColor.Mix( bg, 0.5f ); - numColor = numColor.Mix( bg, 0.5f ); - } - - int x1 = aPinPos.x; - int y1 = aPinPos.y; - - switch( aPinOrient ) - { - case PIN_ORIENTATION::PIN_UP: y1 -= m_length; break; - case PIN_ORIENTATION::PIN_DOWN: y1 += m_length; break; - case PIN_ORIENTATION::PIN_LEFT: x1 -= m_length; break; - case PIN_ORIENTATION::PIN_RIGHT: x1 += m_length; break; - } - - if( name.IsEmpty() || m_nameTextSize == 0 ) - aDrawPinName = false; - - if( number.IsEmpty() || m_numTextSize == 0 ) - aDrawPinNum = false; - - auto printName = - [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign, - enum GR_TEXT_V_ALIGN_T vAlign ) - { - GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), nameColor, name, angle, - nameSize, hAlign, vAlign, nameWidth, false, false, font, GetFontMetrics() ); - }; - - auto printNum = - [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign, - enum GR_TEXT_V_ALIGN_T vAlign ) - { - GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), numColor, number, angle, - numSize, hAlign, vAlign, numWidth, false, false, font, GetFontMetrics() ); - }; - - if( aTextInside ) // Draw the text inside, but the pin numbers outside. - { - if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) - || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) - { - // It is an horizontal line - if( aDrawPinName ) - { - if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) - { - printName( x1 + aTextInside, y1, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); - } - else // Orient == PIN_LEFT - { - printName( x1 - aTextInside, y1, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); - } - } - - if( aDrawPinNum ) - { - printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - else /* Its a vertical line. */ - { - // Text is drawn from bottom to top (i.e. to negative value for Y axis) - if( aPinOrient == PIN_ORIENTATION::PIN_DOWN ) - { - if( aDrawPinName ) - { - printName( x1, y1 + aTextInside, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); - } - - if( aDrawPinNum ) - { - printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - else /* PIN_UP */ - { - if( aDrawPinName ) - { - printName( x1, y1 - aTextInside, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); - } - - if( aDrawPinNum ) - { - printNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - } - } - else /**** Draw num & text pin outside ****/ - { - if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) - || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) - { - /* Its an horizontal line. */ - if( aDrawPinName && aDrawPinNum ) - { - printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - - printNum( ( x1 + aPinPos.x ) / 2, y1 + num_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); - } - else if( aDrawPinName ) - { - printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - else if( aDrawPinNum ) - { - printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - else /* Its a vertical line. */ - { - if( aDrawPinName && aDrawPinNum ) - { - printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - - printNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); - } - else if( aDrawPinName ) - { - printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - else if( aDrawPinNum ) - { - printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - } -} - - -void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition, - PIN_ORIENTATION aOrientation, bool aDimmed ) -{ - wxDC* DC = aSettings->GetPrintDC(); - wxString typeName = GetElectricalTypeName(); - - // Use a reasonable (small) size to draw the text - int textSize = ( m_nameTextSize * 3 ) / 4; - - #define ETXT_MAX_SIZE schIUScale.mmToIU( 0.7 ) - - if( textSize > ETXT_MAX_SIZE ) - textSize = ETXT_MAX_SIZE; - - // Use a reasonable pen size to draw the text - int pensize = textSize/6; - - // Get a suitable color - COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PRIVATE_NOTES : LAYER_HIDDEN ); - COLOR4D bg = aSettings->GetBackgroundColor(); - - if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) - bg = COLOR4D::WHITE; - - if( !IsVisible() ) - bg = aSettings->GetLayerColor( LAYER_HIDDEN ); - - if( aDimmed ) - { - color.Desaturate( ); - color = color.Mix( bg, 0.5f ); - } - - VECTOR2I txtpos = aPosition; - int offset = schIUScale.mmToIU( 0.4 ); - GR_TEXT_H_ALIGN_T hjustify = GR_TEXT_H_ALIGN_LEFT; - EDA_ANGLE orient = ANGLE_HORIZONTAL; - KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false ); - - switch( aOrientation ) - { - case PIN_ORIENTATION::PIN_UP: - txtpos.y += offset; - orient = ANGLE_VERTICAL; - hjustify = GR_TEXT_H_ALIGN_RIGHT; - break; - - case PIN_ORIENTATION::PIN_DOWN: - txtpos.y -= offset; - orient = ANGLE_VERTICAL; - break; - - case PIN_ORIENTATION::PIN_LEFT: - txtpos.x += offset; - break; - - case PIN_ORIENTATION::PIN_RIGHT: - txtpos.x -= offset; - hjustify = GR_TEXT_H_ALIGN_RIGHT; - break; - } - - GRPrintText( DC, txtpos, color, typeName, orient, VECTOR2I( textSize, textSize ), hjustify, - GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font, GetFontMetrics() ); -} - - -void LIB_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition, - PIN_ORIENTATION aOrientation, bool aDimmed ) const -{ - int MapX1, MapY1, x1, y1; - SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter ); - COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN ); - COLOR4D bg = renderSettings->GetBackgroundColor(); - int penWidth = GetEffectivePenWidth( renderSettings ); - - if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() ) - bg = COLOR4D::WHITE; - - if( aDimmed ) - { - color.Desaturate( ); - color = color.Mix( bg, 0.5f ); - } - - aPlotter->SetColor( color ); - aPlotter->SetCurrentLineWidth( penWidth ); - - MapX1 = MapY1 = 0; - x1 = aPosition.x; y1 = aPosition.y; - - switch( aOrientation ) - { - case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - m_length; MapY1 = 1; break; - case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + m_length; MapY1 = -1; break; - case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - m_length; MapX1 = 1; break; - case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + m_length; MapX1 = -1; break; - } - - if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK ) - { - const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this ); - aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2, - FILL_T::NO_FILL, penWidth ); - - aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) ); - aPlotter->FinishTo( aPosition ); - } - else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK ) - { - const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this ); - if( MapY1 == 0 ) /* MapX1 = +- 1 */ - { - aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) ); - aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) ); - aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) ); - } - else /* MapX1 = 0 */ - { - aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) ); - aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) ); - aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) ); - } - - aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) ); - aPlotter->FinishTo( aPosition ); - } - else - { - aPlotter->MoveTo( VECTOR2I( x1, y1 ) ); - aPlotter->FinishTo( aPosition ); - } - - if( m_shape == GRAPHIC_PINSHAPE::CLOCK - || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK - || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) - { - const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this ); - if( MapY1 == 0 ) /* MapX1 = +- 1 */ - { - aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) ); - aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) ); - aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) ); - } - else /* MapX1 = 0 */ - { - aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) ); - aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) ); - aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) ); - } - } - - if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW - || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */ - { - const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this ); - - if( MapY1 == 0 ) /* MapX1 = +- 1 */ - { - aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) ); - aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) ); - aPlotter->FinishTo( VECTOR2I( x1, y1 ) ); - } - else /* MapX1 = 0 */ - { - aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) ); - aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) ); - aPlotter->FinishTo( VECTOR2I( x1, y1 ) ); - } - } - - if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */ - { - const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this ); - - if( MapY1 == 0 ) /* MapX1 = +- 1 */ - { - aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) ); - aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) ); - } - else /* MapX1 = 0 */ - { - aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) ); - aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) ); - } - } - else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */ - { - const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this ); - aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size, - y1 - ( MapY1 - MapX1 ) * deco_size ) ); - aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size, - y1 + ( MapY1 - MapX1 ) * deco_size ) ); - aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size, - y1 - ( MapY1 + MapX1 ) * deco_size ) ); - aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size, - y1 + ( MapY1 + MapX1 ) * deco_size ) ); - } - - if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol - { - const int deco_size = TARGET_PIN_RADIUS; - const int ex1 = aPosition.x; - const int ey1 = aPosition.y; - aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) ); - aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) ); - aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) ); - aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) ); - } -} - - -void LIB_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, - int aTextInside, bool aDrawPinNum, bool aDrawPinName, - bool aDimmed ) const -{ - RENDER_SETTINGS* settings = aPlotter->RenderSettings(); - KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false ); - wxString name = GetShownName(); - wxString number = GetShownNumber(); - - if( name.IsEmpty() || m_nameTextSize == 0 ) - aDrawPinName = false; - - if( number.IsEmpty() || m_numTextSize == 0 ) - aDrawPinNum = false; - - if( !aDrawPinNum && !aDrawPinName ) - return; - - int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, true ), - settings->GetDefaultPenWidth() ); - int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, true ), - settings->GetDefaultPenWidth() ); - int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth; - int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth; - - /* Get the num and name colors */ - COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM ); - COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM ); - COLOR4D bg = settings->GetBackgroundColor(); - - if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() ) - bg = COLOR4D::WHITE; - - if( aDimmed ) - { - nameColor.Desaturate( ); - numColor.Desaturate( ); - nameColor = nameColor.Mix( bg, 0.5f ); - numColor = numColor.Mix( bg, 0.5f ); - } - - int x1 = aPinPos.x; - int y1 = aPinPos.y; - - switch( aPinOrient ) - { - case PIN_ORIENTATION::PIN_UP: y1 -= m_length; break; - case PIN_ORIENTATION::PIN_DOWN: y1 += m_length; break; - case PIN_ORIENTATION::PIN_LEFT: x1 -= m_length; break; - case PIN_ORIENTATION::PIN_RIGHT: x1 += m_length; break; - } - - auto plotName = - [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify, - GR_TEXT_V_ALIGN_T vJustify ) - { - TEXT_ATTRIBUTES attrs; - attrs.m_StrokeWidth = namePenWidth; - attrs.m_Angle = angle; - attrs.m_Size = VECTOR2I( m_nameTextSize, m_nameTextSize ); - attrs.m_Halign = hJustify; - attrs.m_Valign = vJustify; - attrs.m_Multiline = false; - - aPlotter->PlotText( VECTOR2I( x, y ), nameColor, name, attrs, font, GetFontMetrics() ); - }; - - auto plotNum = - [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify, - GR_TEXT_V_ALIGN_T vJustify ) - { - TEXT_ATTRIBUTES attrs; - attrs.m_StrokeWidth = numPenWidth; - attrs.m_Angle = angle; - attrs.m_Size = VECTOR2I( m_numTextSize, m_numTextSize ); - attrs.m_Halign = hJustify; - attrs.m_Valign = vJustify; - attrs.m_Multiline = false; - - aPlotter->PlotText( VECTOR2I( x, y ), numColor, number, attrs, font, GetFontMetrics() ); - }; - - /* Draw the text inside, but the pin numbers outside. */ - if( aTextInside ) - { - if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) - || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) /* Its an horizontal line. */ - { - if( aDrawPinName ) - { - if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) - { - plotName( x1 + aTextInside, y1, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); - } - else // orient == PIN_LEFT - { - plotName( x1 - aTextInside, y1, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); - } - } - - if( aDrawPinNum ) - { - plotNum( ( x1 + aPinPos.x) / 2, y1 - num_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - else /* Its a vertical line. */ - { - if( aPinOrient == PIN_ORIENTATION::PIN_DOWN ) - { - if( aDrawPinName ) - { - plotName( x1, y1 + aTextInside, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); - } - - if( aDrawPinNum ) - { - plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - else /* PIN_UP */ - { - if( aDrawPinName ) - { - plotName( x1, y1 - aTextInside, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); - } - - if( aDrawPinNum ) - { - plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - } - } - else /* Draw num & text pin outside */ - { - if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) - || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) - { - /* Its an horizontal line. */ - if( aDrawPinName && aDrawPinNum ) - { - plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - - plotNum( ( x1 + aPinPos.x) / 2, y1 + num_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); - } - else if( aDrawPinName ) - { - plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - else if( aDrawPinNum ) - { - plotNum( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - else - { - /* Its a vertical line. */ - if( aDrawPinName && aDrawPinNum ) - { - plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - - plotNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); - } - else if( aDrawPinName ) - { - plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - else if( aDrawPinNum ) - { - plotNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, - GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); - } - } - } -} - - -PIN_ORIENTATION LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const -{ - PIN_ORIENTATION orient; - VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1 - - switch( m_orientation ) - { - case PIN_ORIENTATION::PIN_UP: end.y = 1; break; - case PIN_ORIENTATION::PIN_DOWN: end.y = -1; break; - case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break; - case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break; - } - - // = pos of end point, according to the symbol orientation. - end = aTransform.TransformCoordinate( end ); - orient = PIN_ORIENTATION::PIN_UP; - - if( end.x == 0 ) - { - if( end.y > 0 ) - orient = PIN_ORIENTATION::PIN_DOWN; - } - else - { - orient = PIN_ORIENTATION::PIN_RIGHT; - - if( end.x < 0 ) - orient = PIN_ORIENTATION::PIN_LEFT; - } - - return orient; -} - - -EDA_ITEM* LIB_PIN::Clone() const -{ - //return new LIB_PIN( *this ); - SCH_ITEM* newPin = new LIB_PIN( *this ); - wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle ); - return newPin; -} - - -int LIB_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const -{ - wxASSERT( aOther.Type() == LIB_PIN_T ); - - int retv = SCH_ITEM::compare( aOther, aCompareFlags ); - - if( retv ) - return retv; - - const LIB_PIN* tmp = (LIB_PIN*) &aOther; - - // When comparing units, we do not compare the part numbers. If everything else is - // identical, then we can just renumber the parts for the inherited symbol. - if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number ) - return m_number.Cmp( tmp->m_number ); - - int result = m_name.Cmp( tmp->m_name ); - - if( result ) - return result; - - if( m_position.x != tmp->m_position.x ) - return m_position.x - tmp->m_position.x; - - if( m_position.y != tmp->m_position.y ) - return m_position.y - tmp->m_position.y; - - if( m_length != tmp->m_length ) - return m_length - tmp->m_length; - - if( m_orientation != tmp->m_orientation ) - return static_cast( m_orientation ) - static_cast( tmp->m_orientation ); - - if( m_shape != tmp->m_shape ) - return static_cast( m_shape ) - static_cast( tmp->m_shape ); - - if( m_type != tmp->m_type ) - return static_cast( m_type ) - static_cast( tmp->m_type ); - - if( m_attributes != tmp->m_attributes ) - return m_attributes - tmp->m_attributes; - - if( m_numTextSize != tmp->m_numTextSize ) - return m_numTextSize - tmp->m_numTextSize; - - if( m_nameTextSize != tmp->m_nameTextSize ) - return m_nameTextSize - tmp->m_nameTextSize; - - if( m_alternates.size() != tmp->m_alternates.size() ) - return m_alternates.size() - tmp->m_alternates.size(); - - auto lhsItem = m_alternates.begin(); - auto rhsItem = tmp->m_alternates.begin(); - - while( lhsItem != m_alternates.end() ) - { - const ALT& lhsAlt = lhsItem->second; - const ALT& rhsAlt = rhsItem->second; - - retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name ); - - if( retv ) - return retv; - - if( lhsAlt.m_Type != rhsAlt.m_Type ) - return static_cast( lhsAlt.m_Type ) - static_cast( rhsAlt.m_Type ); - - if( lhsAlt.m_Shape != rhsAlt.m_Shape ) - return static_cast( lhsAlt.m_Shape ) - static_cast( rhsAlt.m_Shape ); - - ++lhsItem; - ++rhsItem; - } - - return 0; -} - -void LIB_PIN::ChangeLength( int aLength ) -{ - int lengthChange = m_length - aLength; - int offsetX = 0; - int offsetY = 0; - - switch( m_orientation ) - { - case PIN_ORIENTATION::PIN_RIGHT: - offsetX = lengthChange; - break; - case PIN_ORIENTATION::PIN_LEFT: - offsetX = -1 * lengthChange; - break; - case PIN_ORIENTATION::PIN_UP: - offsetY = lengthChange; - break; - case PIN_ORIENTATION::PIN_DOWN: - offsetY = -1 * lengthChange; - break; - } - - VECTOR2I offset = VECTOR2I( offsetX, offsetY ); - Move( offset ); - - m_length = aLength; -} - -void LIB_PIN::Move( const VECTOR2I& aOffset ) -{ - m_position += aOffset; -} - - -void LIB_PIN::MirrorHorizontally( int aCenter ) -{ - m_position.x -= aCenter; - m_position.x *= -1; - m_position.x += aCenter; - - if( m_orientation == PIN_ORIENTATION::PIN_RIGHT ) - m_orientation = PIN_ORIENTATION::PIN_LEFT; - else if( m_orientation == PIN_ORIENTATION::PIN_LEFT ) - m_orientation = PIN_ORIENTATION::PIN_RIGHT; -} - - -void LIB_PIN::MirrorVertically( int aCenter ) -{ - m_position.y -= aCenter; - m_position.y *= -1; - m_position.y += aCenter; - - if( m_orientation == PIN_ORIENTATION::PIN_UP ) - m_orientation = PIN_ORIENTATION::PIN_DOWN; - else if( m_orientation == PIN_ORIENTATION::PIN_DOWN ) - m_orientation = PIN_ORIENTATION::PIN_UP; -} - - -void LIB_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) -{ - EDA_ANGLE rot_angle = aRotateCCW ? -ANGLE_90 : ANGLE_90; - - RotatePoint( m_position, aCenter, rot_angle ); - - if( aRotateCCW ) - { - switch( m_orientation ) - { - case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_UP; break; - case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_LEFT; break; - case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break; - case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break; - } - } - else - { - switch( m_orientation ) - { - case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break; - case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break; - case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_UP; break; - case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_LEFT; break; - } - } -} - - -void LIB_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, - int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) -{ - if( aBackground ) - return; - - SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter ); - - if( !IsVisible() && !renderSettings->m_ShowHiddenPins ) - return; - - const SYMBOL* part = GetParentSymbol(); - PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform ); - VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset; - - PlotPinType( aPlotter, pos, orient, aDimmed ); - PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(), - part->GetShowPinNames(), aDimmed ); -} - - -void LIB_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) -{ - getSymbolEditorMsgPanelInfo( aFrame, aList ); - - aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) ); - aList.emplace_back( _( "Number" ), GetShownNumber() ); - aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( m_type ) ); - aList.emplace_back( _( "Style" ), PinShapeGetText( m_shape ) ); - - aList.emplace_back( _( "Style" ), IsVisible() ? _( "Yes" ) : _( "No" ) ); - - // Display pin length - aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( m_length, true ) ); - - aList.emplace_back( _( "Orientation" ), PinOrientationName( m_orientation ) ); - - VECTOR2I pinpos = GetPosition(); - pinpos.y = -pinpos.y; // Display coords are top to bottom; lib item coords are bottom to top - - aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( pinpos.x, true ) ); - aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( pinpos.y, true ) ); - - #if 0 // For debug purpose only - aList.emplace_back( _( "Flags" ), wxString::Format( "%8.8X", (long)GetFlags() ) ); - #endif -} - - -const BOX2I LIB_PIN::ViewBBox() const -{ - return GetBoundingBox( false, true, true ); -} - - -void LIB_PIN::ViewGetLayers( int aLayers[], int& aCount ) const -{ - aCount = 6; - aLayers[0] = LAYER_DANGLING; // We don't really show dangling vs non-dangling (since there - // are no connections in the symbol editor), but it's still - // a good visual indication of which end of the pin is which. - aLayers[1] = LAYER_DEVICE; - aLayers[2] = LAYER_SELECTION_SHADOWS; - aLayers[3] = LAYER_OP_CURRENTS; - aLayers[4] = LAYER_PINNAM; - aLayers[5] = LAYER_PINNUM; -} - - -void LIB_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText, - EXTENTS_CACHE* aCache ) const -{ - if( aCache->m_Font == aFont - && aCache->m_FontSize == aSize - && aCache->m_Extents != VECTOR2I() ) - { - return; - } - - aCache->m_Font = aFont; - aCache->m_FontSize = aSize; - - VECTOR2D fontSize( aSize, aSize ); - int penWidth = GetPenSizeForNormal( aSize ); - - aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false, - GetFontMetrics() ); -} - - -const BOX2I LIB_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber, - bool aIncludeElectricalType ) const -{ - EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - KIFONT::FONT* font = KIFONT::FONT::GetFont( cfg->m_Appearance.default_font ); - - BOX2I bbox; - VECTOR2I begin; - VECTOR2I end; - int pinNameOffset = 0; - int nameTextLength = 0; - int nameTextHeight = 0; - int numberTextLength = 0; - int numberTextHeight = 0; - int typeTextLength = 0; - bool includeName = aIncludeNameAndNumber && !GetShownName().IsEmpty(); - bool includeNumber = aIncludeNameAndNumber && !GetShownNumber().IsEmpty(); - bool includeType = aIncludeElectricalType; - int minsizeV = TARGET_PIN_RADIUS; - - if( !aIncludeLabelsOnInvisiblePins && !IsVisible() ) - { - includeName = false; - includeNumber = false; - includeType = false; - } - - if( const SYMBOL* parentSymbol = GetParentSymbol() ) - { - if( parentSymbol->GetShowPinNames() ) - pinNameOffset = parentSymbol->GetPinNameOffset(); - else - includeName = false; - - if( !parentSymbol->GetShowPinNumbers() ) - includeNumber = false; - } - - if( includeNumber ) - { - validateExtentsCache( font, m_numTextSize, GetShownNumber(), &m_numExtentsCache ); - numberTextLength = m_numExtentsCache.m_Extents.x; - numberTextHeight = m_numExtentsCache.m_Extents.y; - } - - if( includeName ) - { - validateExtentsCache( font, m_nameTextSize, GetShownName(), &m_nameExtentsCache ); - nameTextLength = m_nameExtentsCache.m_Extents.x + pinNameOffset; - nameTextHeight = m_nameExtentsCache.m_Extents.y + schIUScale.MilsToIU( PIN_TEXT_MARGIN ); - } - - if( includeType ) - { - double fontSize = std::max( m_nameTextSize * 3 / 4, schIUScale.mmToIU( 0.7 ) ); - double stroke = fontSize / 8.0; - VECTOR2I typeTextSize = font->StringBoundaryLimits( GetElectricalTypeName(), - VECTOR2D( fontSize, fontSize ), - KiROUND( stroke ), false, false, - GetFontMetrics() ); - - typeTextLength = typeTextSize.x + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + TARGET_PIN_RADIUS; - minsizeV = std::max( minsizeV, typeTextSize.y / 2 ); - } - - // First, calculate boundary box corners position - if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK ) - minsizeV = std::max( TARGET_PIN_RADIUS, externalPinDecoSize( nullptr, *this ) ); - - // Calculate topLeft & bottomRight corner positions for the default pin orientation (PIN_RIGHT) - if( pinNameOffset || !includeName ) - { - // pin name is inside the body (or invisible) - // pin number is above the line - begin.y = std::max( minsizeV, numberTextHeight ); - begin.x = std::min( -typeTextLength, m_length - ( numberTextLength / 2 ) ); - - end.x = m_length + nameTextLength; - end.y = std::min( -minsizeV, -nameTextHeight / 2 ); - } - else - { - // pin name is above pin line - // pin number is below line - begin.y = std::max( minsizeV, nameTextHeight ); - begin.x = -typeTextLength; - begin.x = std::min( begin.x, ( m_length - numberTextLength ) / 2 ); - begin.x = std::min( begin.x, ( m_length - nameTextLength ) / 2 ); - - end.x = m_length; - end.x = std::max( end.x, ( m_length + nameTextLength ) / 2 ); - end.x = std::max( end.x, ( m_length + numberTextLength ) / 2 ); - end.y = std::min( -minsizeV, -numberTextHeight ); - } - - // Now, calculate boundary box corners position for the actual pin orientation - PIN_ORIENTATION orient = PinDrawOrient( DefaultTransform ); - - /* Calculate the pin position */ - switch( orient ) - { - case PIN_ORIENTATION::PIN_UP: - // Pin is rotated and texts positions are mirrored - RotatePoint( begin, VECTOR2I( 0, 0 ), -ANGLE_90 ); - RotatePoint( end, VECTOR2I( 0, 0 ), -ANGLE_90 ); - break; - - case PIN_ORIENTATION::PIN_DOWN: - RotatePoint( begin, VECTOR2I( 0, 0 ), ANGLE_90 ); - RotatePoint( end, VECTOR2I( 0, 0 ), ANGLE_90 ); - begin.x = -begin.x; - end.x = -end.x; - break; - - case PIN_ORIENTATION::PIN_LEFT: - begin.x = -begin.x; - end.x = -end.x; - break; - - case PIN_ORIENTATION::PIN_RIGHT: - break; - } - - begin += m_position; - end += m_position; - - bbox.SetOrigin( begin ); - bbox.SetEnd( end ); - bbox.Normalize(); - bbox.Inflate( ( GetPenWidth() / 2 ) + 1 ); - - // Draw Y axis is reversed in schematic: - bbox.RevertYAxis(); - - return bbox; -} - - -BITMAPS LIB_PIN::GetMenuImage() const -{ - return ElectricalPinTypeGetBitmap( m_type ); -} - - -wxString LIB_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const -{ - return getItemDescription( aAlt ); -} - - -wxString LIB_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const -{ - return getItemDescription( nullptr ); -} - - -wxString LIB_PIN::getItemDescription( ALT* aAlt ) const -{ - // This code previously checked "m_name.IsEmpty()" to choose the correct - // formatting path, but that check fails if the pin is called "~" which is - // the default for an empty pin name. Instead we get the final display string - // that will be shown and check if it's empty. - - wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() ); - wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type ); - wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape ); - - if( IsVisible() ) - { - if ( !name.IsEmpty() ) - { - return wxString::Format( _( "Pin %s [%s, %s, %s]" ), - GetShownNumber(), - name, - electricalTypeName, - pinShapeName ); - } - else - { - return wxString::Format( _( "Pin %s [%s, %s]" ), - GetShownNumber(), - electricalTypeName, - pinShapeName ); - } - } - else - { - if( !name.IsEmpty() ) - { - return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ), - GetShownNumber(), - name, - electricalTypeName, - pinShapeName ); - } - else - { - return wxString::Format( _( "Hidden pin %s [%s, %s]" ), - GetShownNumber(), - electricalTypeName, - pinShapeName ); - } - } -} - - -bool LIB_PIN::operator==( const SCH_ITEM& aOther ) const -{ - if( aOther.Type() != LIB_PIN_T ) - return false; - - const LIB_PIN* other = static_cast( &aOther ); - - if( m_name != other->m_name ) - return false; - - if( m_number != other->m_number ) - return false; - - if( m_position != other->m_position ) - return false; - - if( m_length != other->m_length ) - return false; - - if( m_orientation != other->m_orientation ) - return false; - - if( m_shape != other->m_shape ) - return false; - - if( m_type != other->m_type ) - return false; - - if( m_attributes != other->m_attributes ) - return false; - - if( m_numTextSize != other->m_numTextSize ) - return false; - - if( m_nameTextSize != other->m_nameTextSize ) - return false; - - if( m_alternates.size() != other->m_alternates.size() ) - return false; - - auto lhsItem = m_alternates.begin(); - auto rhsItem = other->m_alternates.begin(); - - while( lhsItem != m_alternates.end() ) - { - if( rhsItem == other->m_alternates.end() ) - return false; - - const ALT& lhsAlt = lhsItem->second; - const ALT& rhsAlt = rhsItem->second; - - if( lhsAlt.m_Name != rhsAlt.m_Name ) - return false; - - if( lhsAlt.m_Type != rhsAlt.m_Type ) - return false; - - if( lhsAlt.m_Shape != rhsAlt.m_Shape ) - return false; - - ++lhsItem; - ++rhsItem; - } - - return rhsItem == other->m_alternates.end(); -} - - -double LIB_PIN::Similarity( const SCH_ITEM& aOther ) const -{ - if( aOther.m_Uuid == m_Uuid ) - return 1.0; - - if( aOther.Type() != LIB_PIN_T ) - return 0.0; - - const LIB_PIN* other = static_cast( &aOther ); - - double similarity = SimilarityBase( aOther ); - - if( m_name != other->m_name ) - similarity *= 0.9; - - if( m_number != other->m_number ) - similarity *= 0.9; - - if( m_position != other->m_position ) - similarity *= 0.9; - - if( m_length != other->m_length ) - similarity *= 0.9; - - if( m_orientation != other->m_orientation ) - similarity *= 0.9; - - if( m_shape != other->m_shape ) - similarity *= 0.9; - - if( m_type != other->m_type ) - similarity *= 0.9; - - if( m_attributes != other->m_attributes ) - similarity *= 0.9; - - if( m_numTextSize != other->m_numTextSize ) - similarity *= 0.9; - - if( m_nameTextSize != other->m_nameTextSize ) - similarity *= 0.9; - - if( m_alternates.size() != other->m_alternates.size() ) - similarity *= 0.9; - - return similarity; -} - - -std::ostream& LIB_PIN::operator<<( std::ostream& aStream ) -{ - aStream << "LIB_PIN:" << std::endl - << " Name: \"" << m_name << "\"" << std::endl - << " Number: \"" << m_number << "\"" << std::endl - << " Position: " << m_position << std::endl - << " Length: " << m_length << std::endl - << " Orientation: " << PinOrientationName( m_orientation ) << std::endl - << " Shape: " << PinShapeGetText( m_shape ) << std::endl - << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl - << " Name Text Size: " << m_nameTextSize << std::endl - << " Number Text Size: " << m_numTextSize << std::endl; - - return aStream; -} - - -#if defined(DEBUG) - -void LIB_PIN::Show( int nestLevel, std::ostream& os ) const -{ - NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() - << " num=\"" << m_number.mb_str() - << '"' << "/>\n"; - -// NestedSpace( nestLevel, os ) << "\n"; -} - -#endif - -void LIB_PIN::CalcEdit( const VECTOR2I& aPosition ) -{ - if( IsMoving() ) - SetPosition( aPosition ); -} - - -static struct LIB_PIN_DESC -{ - LIB_PIN_DESC() - { - auto& pinTypeEnum = ENUM_MAP::Instance(); - - if( pinTypeEnum.Choices().GetCount() == 0 ) - { - pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) ) - .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) ) - .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) ) - .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) ) - .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) ) - .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) ) - .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) ) - .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) ) - .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) ) - .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) ) - .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) ) - .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) ); - } - - auto& pinShapeEnum = ENUM_MAP::Instance(); - - if( pinShapeEnum.Choices().GetCount() == 0 ) - { - pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) ) - .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) ) - .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) ) - .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) ) - .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) ) - .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) ) - .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) ) - .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) ) - .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) ); - } - - auto& orientationEnum = ENUM_MAP::Instance(); - - if( orientationEnum.Choices().GetCount() == 0 ) - { - orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _( "Right" ) ) - .Map( PIN_ORIENTATION::PIN_LEFT, _( "Left" ) ) - .Map( PIN_ORIENTATION::PIN_UP, _( "Up" ) ) - .Map( PIN_ORIENTATION::PIN_DOWN, _( "Down" ) ); - } - - PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); - REGISTER_TYPE( LIB_PIN ); - propMgr.AddTypeCast( new TYPE_CAST ); - propMgr.InheritsAfter( TYPE_HASH( LIB_PIN ), TYPE_HASH( SCH_ITEM ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Pin Name" ), - &LIB_PIN::SetName, &LIB_PIN::GetName ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Pin Number" ), - &LIB_PIN::SetNumber, &LIB_PIN::GetNumber ) ); - - propMgr.AddProperty( new PROPERTY_ENUM( - _HKI( "Electrical Type" ), - &LIB_PIN::SetType, &LIB_PIN::GetType ) ); - - propMgr.AddProperty( new PROPERTY_ENUM( - _HKI( "Graphic Style" ), - &LIB_PIN::SetShape, &LIB_PIN::GetShape ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Position X" ), - &LIB_PIN::SetX, &LIB_PIN::GetX, PROPERTY_DISPLAY::PT_COORD ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Position Y" ), - &LIB_PIN::SetY, &LIB_PIN::GetY, PROPERTY_DISPLAY::PT_COORD ) ); - - propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Orientation" ), - &LIB_PIN::SetOrientation, &LIB_PIN::GetOrientation ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Length" ), - &LIB_PIN::SetLength, &LIB_PIN::GetLength, - PROPERTY_DISPLAY::PT_SIZE ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Name Text Size" ), - &LIB_PIN::SetNameTextSize, &LIB_PIN::GetNameTextSize, - PROPERTY_DISPLAY::PT_SIZE ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Number Text Size" ), - &LIB_PIN::SetNumberTextSize, &LIB_PIN::GetNumberTextSize, - PROPERTY_DISPLAY::PT_SIZE ) ); - - propMgr.AddProperty( new PROPERTY( _HKI( "Visible" ), - &LIB_PIN::SetVisible, &LIB_PIN::IsVisible ) ); - } -} _LIB_PIN_DESC; - - -ENUM_TO_WXANY( PIN_ORIENTATION ) -ENUM_TO_WXANY( GRAPHIC_PINSHAPE ) -ENUM_TO_WXANY( ELECTRICAL_PINTYPE ) diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h deleted file mode 100644 index bdf9f1e0b1..0000000000 --- a/eeschema/lib_pin.h +++ /dev/null @@ -1,336 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr - * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 2004-2024 KiCad Developers, see AUTHORS.txt for contributors. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - - -#ifndef CLASS_PIN_H -#define CLASS_PIN_H - -#include -#include - -// Circle diameter drawn at the active end of pins: -#define TARGET_PIN_RADIUS schIUScale.MilsToIU( 15 ) - -// Pin visibility flag bit: -#define PIN_INVISIBLE 1 // Set makes pin invisible - - -class LIB_PIN : public SCH_ITEM -{ -public: - struct ALT - { - wxString m_Name; - GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin - ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin. - }; - - LIB_PIN( SCH_ITEM* aParent ); - - LIB_PIN( SCH_ITEM* aParent, const wxString& aName, const wxString& aNumber, - PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, - int aNameTextSize, int aNumTextSize, int aConvert, const VECTOR2I& aPos, int aUnit ); - - // Do not create a copy constructor. The one generated by the compiler is adequate. - - ~LIB_PIN() { } - - wxString GetClass() const override - { - return wxT( "LIB_PIN" ); - } - - static inline bool ClassOf( const EDA_ITEM* aItem ) - { - return aItem && aItem->Type() == LIB_PIN_T; - } - - wxString GetFriendlyName() const override - { - return _( "Pin" ); - } - - PIN_ORIENTATION GetOrientation() const { return m_orientation; } - void SetOrientation( PIN_ORIENTATION aOrientation ) { m_orientation = aOrientation; } - - GRAPHIC_PINSHAPE GetShape() const { return m_shape; } - void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; } - - int GetLength() const { return m_length; } - void SetLength( int aLength ) { m_length = aLength; } - - /** - * Change the length of a pin and adjust its position based on orientation. - * - * @param aLength New length of pin - */ - void ChangeLength( int aLength ); - - ELECTRICAL_PINTYPE GetType() const { return m_type; } - void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; } - - wxString const GetCanonicalElectricalTypeName() const - { - return GetCanonicalElectricalTypeName( m_type ); - } - - wxString const GetElectricalTypeName() const - { - return ElectricalPinTypeGetText( m_type ); - } - - bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; } - void SetVisible( bool aVisible ) - { - if( aVisible ) - m_attributes &= ~PIN_INVISIBLE; - else - m_attributes |= PIN_INVISIBLE; - } - - const wxString& GetName() const { return m_name; } - wxString GetShownName() const; - void SetName( const wxString& aName ) - { - m_name = aName; - - // pin name string does not support spaces - m_name.Replace( wxT( " " ), wxT( "_" ) ); - m_nameExtentsCache.m_Extents = VECTOR2I(); - } - - const wxString& GetNumber() const { return m_number; } - wxString GetShownNumber() const { return m_number; } - void SetNumber( const wxString& aNumber ) - { - m_number = aNumber; - - // pin number string does not support spaces - m_number.Replace( wxT( " " ), wxT( "_" ) ); - m_numExtentsCache.m_Extents = VECTOR2I(); - } - - int GetNameTextSize() const { return m_nameTextSize; } - void SetNameTextSize( int aSize ) - { - m_nameTextSize = aSize; - m_nameExtentsCache.m_Extents = VECTOR2I(); - } - - int GetNumberTextSize() const { return m_numTextSize; } - void SetNumberTextSize( int aSize ) - { - m_numTextSize = aSize; - m_numExtentsCache.m_Extents = VECTOR2I(); - } - - std::map& GetAlternates() { return m_alternates; } - - ALT GetAlt( const wxString& aAlt ) { return m_alternates[ aAlt ]; } - - void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle, - const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override; - - /** - * Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), - * according to its orientation and the matrix transform (rot, mirror) \a aTransform. - * - * @param aTransform Transform matrix - */ - PIN_ORIENTATION PinDrawOrient( const TRANSFORM& aTransform ) const; - - // No, LIB_PINs don't really have operating poinst. But we draw SCH_PINs through their LIB_PIN - // counterparts, so here we are.... - const wxString& GetOperatingPoint() const { return m_operatingPoint; } - void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; } - -#if defined(DEBUG) - void Show( int nestLevel, std::ostream& os ) const override; -#endif - - bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override; - - bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override; - - void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; - - const BOX2I ViewBBox() const override; - - void ViewGetLayers( int aLayers[], int& aCount ) const override; - - /* Cannot use a default parameter here as it will not be compatible with the virtual. */ - const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, true ); } - - /** - * @param aIncludeLabelsOnInvisblePins - if false, do not include labels for invisible pins - * in the calculation. - */ - const BOX2I GetBoundingBox( bool aIncludeLabelsOnInvisblePins, bool aIncludeNameAndNumber, - bool aIncludeElectricalType ) const; - - /** - * Return whether this pin forms a global power connection: i.e., is part of a power symbol - * and of type POWER_IN, or is a legacy invisible global power pin on a symbol. - */ - bool IsGlobalPower() const - { - return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN - && ( !IsVisible() || GetParentSymbol()->IsPower() ); - } - - int GetPenWidth() const override; - - void Move( const VECTOR2I& aOffset ) override; - - VECTOR2I GetPosition() const override { return m_position; } - void SetPosition( const VECTOR2I& aPos ) override { m_position = aPos; } - - // For properties system - int GetX() const { return m_position.x; } - void SetX( int aX ) { m_position.x = aX; } - int GetY() const { return m_position.y; } - void SetY( int aY ) { m_position.y = aY; } - - VECTOR2I GetPinRoot() const; - - void MirrorHorizontally( int aCenter ) override; - void MirrorVertically( int aCenter ) override; - void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override; - - /** - * Plot the pin name and number. - * @param aTextInside - draw the names & numbers inside the symbol body (ie: in the opposite - * direction of \a aPinOrient). - */ - void PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, - int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const; - - void PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, - bool aDimmed ) const; - - void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, - int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override; - - BITMAPS GetMenuImage() const override; - - wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override; - wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const; - - EDA_ITEM* Clone() const override; - - void CalcEdit( const VECTOR2I& aPosition ) override; - - /** - * Return a string giving the electrical type of a pin. - * - * Can be used when a known, not translated name is needed (for instance in net lists) - * - * @param aType is the electrical type (see enum ELECTRICAL_PINTYPE ) - * @return The electrical name for a pin type (see enun MsgPinElectricType for names). - */ - static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType ); - - double Similarity( const SCH_ITEM& aItem ) const override; - - bool operator==( const SCH_ITEM& aItem ) const override; - bool operator!=( const SCH_ITEM& aItem ) const { return !operator==( aItem ); } - bool operator<( const LIB_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) < 0; } - bool operator>( const LIB_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) > 0; } - -protected: - wxString getItemDescription( ALT* aAlt ) const; - - struct EXTENTS_CACHE - { - KIFONT::FONT* m_Font = nullptr; - int m_FontSize = 0; - VECTOR2I m_Extents; - }; - - void validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText, - EXTENTS_CACHE* aCache ) const; - - /** - * Print the pin symbol without text. - * If \a aColor != 0, draw with \a aColor, else with the normal pin color. - */ - void printPinSymbol( const SCH_RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, - PIN_ORIENTATION aOrientation, bool aDimmed ); - - /** - * Put the pin number and pin text info, given the pin line coordinates. - * The line must be vertical or horizontal. - * If aDrawPinName == false the pin name is not printed. - * If aDrawPinNum = false the pin number is not printed. - * If aTextInside then the text is been put inside,otherwise all is drawn outside. - * Pin Name: substring between '~' is negated - */ - void printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos, - PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, - bool aDrawPinName, bool aDimmed ); - - /** - * Draw the electrical type text of the pin (only for the footprint editor) - */ - void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition, - PIN_ORIENTATION aOrientation, bool aDimmed ); - std::ostream& operator<<( std::ostream& aStream ); - -private: - /** - * @copydoc SCH_ITEM::compare() - * - * The pin specific sort order is as follows: - * - Pin number. - * - Pin name, case insensitive compare. - * - Pin horizontal (X) position. - * - Pin vertical (Y) position. - */ - int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override; - -protected: - VECTOR2I m_position; // Position of the pin. - int m_length; // Length of the pin. - PIN_ORIENTATION m_orientation; // Pin orientation (Up, Down, Left, Right) - GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin - ELECTRICAL_PINTYPE m_type; // Electrical type of the pin. - int m_attributes; // Set bit 0 to indicate pin is invisible. - wxString m_name; - wxString m_number; - int m_numTextSize; // Pin num and Pin name sizes - int m_nameTextSize; - - std::map m_alternates; // Map of alternate name to ALT structure - - wxString m_operatingPoint; // No, LIB_PINs don't really have simulation - // operating points. But we draw SCH_PINs through - // their LIB_PIN counterparts, so here we are.... - - mutable EXTENTS_CACHE m_numExtentsCache; - mutable EXTENTS_CACHE m_nameExtentsCache; -}; - - -#endif // CLASS_PIN_H diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index 0219d58cfb..928de88695 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -27,12 +27,11 @@ #include #include #include -#include #include #include #include -#include #include +#include #include #include @@ -293,7 +292,7 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aR aShapes.insert( &(*it) ); else if( it->Type() == SCH_FIELD_T ) aFields.insert( &(*it) ); - else if( it->Type() == LIB_PIN_T ) + else if( it->Type() == SCH_PIN_T ) aPins.insert( &(*it) ); } @@ -307,7 +306,7 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aR bShapes.insert( &(*it) ); else if( it->Type() == SCH_FIELD_T ) bFields.insert( &(*it) ); - else if( it->Type() == LIB_PIN_T ) + else if( it->Type() == SCH_PIN_T ) bPins.insert( &(*it) ); } @@ -346,8 +345,8 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aR { for( const SCH_ITEM* aPinItem : aPins ) { - const LIB_PIN* aPin = static_cast( aPinItem ); - const LIB_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(), + const SCH_PIN* aPin = static_cast( aPinItem ); + const SCH_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(), aPin->GetBodyStyle() ); if( !bPin ) @@ -754,7 +753,7 @@ void LIB_SYMBOL::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBo if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) ) continue; - if( item.Type() == LIB_PIN_T ) + if( item.Type() == SCH_PIN_T ) { item.Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed ); } @@ -980,8 +979,10 @@ void LIB_SYMBOL::AddDrawItem( SCH_ITEM* aItem, bool aSort ) } -void LIB_SYMBOL::GetPins( std::vector& aList, int aUnit, int aBodyStyle ) const +std::vector LIB_SYMBOL::GetPins( int aUnit, int aBodyStyle ) const { + std::vector pins; + /* Notes: * when aUnit == 0: no unit filtering * when aBodyStyle == 0: no body style filtering @@ -992,7 +993,7 @@ void LIB_SYMBOL::GetPins( std::vector& aList, int aUnit, int aBodyStyl LIB_SYMBOL_SPTR parent = m_parent.lock(); const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings; - for( const SCH_ITEM& item : drawItems[LIB_PIN_T] ) + for( const SCH_ITEM& item : drawItems[SCH_PIN_T] ) { // Unit filtering: if( aUnit && item.m_unit && ( item.m_unit != aUnit ) ) @@ -1002,35 +1003,29 @@ void LIB_SYMBOL::GetPins( std::vector& aList, int aUnit, int aBodyStyl if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) ) continue; - aList.push_back( (LIB_PIN*) &item ); + // TODO: get rid of const_cast. (It used to be a C-style cast so was less noticeable.) + pins.push_back( const_cast( static_cast( &item ) ) ); } + + return pins; } -std::vector LIB_SYMBOL::GetAllLibPins() const +std::vector LIB_SYMBOL::GetAllLibPins() const { - std::vector pinList; - - GetPins( pinList, 0, 0 ); - return pinList; + return GetPins( 0, 0 ); } int LIB_SYMBOL::GetPinCount() { - std::vector pinList; - - GetPins( pinList, 0 /* all units */, 1 /* single body style */ ); - return (int) pinList.size(); + return (int) GetPins( 0 /* all units */, 1 /* single body style */ ).size(); } -LIB_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aBodyStyle ) const +SCH_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aBodyStyle ) const { - std::vector pinList; - GetPins( pinList, aUnit, aBodyStyle ); - - for( LIB_PIN* pin : pinList ) + for( SCH_PIN* pin : GetPins( aUnit, aBodyStyle ) ) { if( aNumber == pin->GetNumber() ) return pin; @@ -1043,17 +1038,15 @@ LIB_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aBodyStyle bool LIB_SYMBOL::PinsConflictWith( const LIB_SYMBOL& aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength ) const { - std::vector thisPinList; - GetPins( thisPinList, /* aUnit */ 0, /* aBodyStyle */ 0 ); + std::vector thisPinList = GetAllLibPins(); - for( const LIB_PIN* eachThisPin : thisPinList ) + for( const SCH_PIN* eachThisPin : thisPinList ) { wxASSERT( eachThisPin ); - std::vector otherPinList; - aOtherPart.GetPins( otherPinList, /* aUnit */ 0, /* aBodyStyle */ 0 ); + std::vector otherPinList = aOtherPart.GetAllLibPins(); bool foundMatch = false; - for( const LIB_PIN* eachOtherPin : otherPinList ) + for( const SCH_PIN* eachOtherPin : otherPinList ) { wxASSERT( eachOtherPin ); @@ -1152,9 +1145,9 @@ const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aBodyStyle, bool aInc if( item.Type() == SCH_FIELD_T ) continue; - if( item.Type() == LIB_PIN_T ) + if( item.Type() == SCH_PIN_T ) { - const LIB_PIN& pin = static_cast( item ); + const SCH_PIN& pin = static_cast( item ); if( pin.IsVisible() ) { @@ -1441,9 +1434,9 @@ int LIB_SYMBOL::GetMaxPinNumber() const LIB_SYMBOL_SPTR parent = m_parent.lock(); const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings; - for( const SCH_ITEM& item : drawItems[LIB_PIN_T] ) + for( const SCH_ITEM& item : drawItems[SCH_PIN_T] ) { - const LIB_PIN* pin = static_cast( &item ); + const SCH_PIN* pin = static_cast( &item ); long currentPinNumber = 0; if( pin->GetNumber().ToLong( ¤tPinNumber ) ) @@ -1598,7 +1591,7 @@ void LIB_SYMBOL::SetHasAlternateBodyStyle( bool aHasAlternate, bool aDuplicatePi { std::vector tmp; // Temporarily store the duplicated pins here. - for( SCH_ITEM& item : m_drawings[ LIB_PIN_T ] ) + for( SCH_ITEM& item : m_drawings[ SCH_PIN_T ] ) { if( item.m_bodyStyle == 1 ) { @@ -1727,8 +1720,8 @@ bool LIB_SYMBOL::operator==( const LIB_SYMBOL& aOther ) const return false; } - const std::vector thisPinList = GetAllLibPins(); - const std::vector otherPinList = aOther.GetAllLibPins(); + const std::vector thisPinList = GetAllLibPins(); + const std::vector otherPinList = aOther.GetAllLibPins(); if( thisPinList.size() != otherPinList.size() ) return false; @@ -1777,12 +1770,12 @@ double LIB_SYMBOL::Similarity( const SCH_ITEM& aOther ) const similarity += max_similarity; } - for( const LIB_PIN* pin : GetAllLibPins() ) + for( const SCH_PIN* pin : GetAllLibPins() ) { totalItems += 1; double max_similarity = 0.0; - for( const LIB_PIN* otherPin : other.GetAllLibPins() ) + for( const SCH_PIN* otherPin : other.GetAllLibPins() ) { double temp_similarity = pin->Similarity( *otherPin ); max_similarity = std::max( max_similarity, temp_similarity ); diff --git a/eeschema/lib_symbol.h b/eeschema/lib_symbol.h index 002d55cd5c..8280d24daf 100644 --- a/eeschema/lib_symbol.h +++ b/eeschema/lib_symbol.h @@ -27,9 +27,9 @@ #ifndef LIB_SYMBOL_H #define LIB_SYMBOL_H -#include #include #include +#include #include #include #include @@ -39,13 +39,12 @@ class OUTPUTFORMATTER; class REPORTER; class SYMBOL_LIB; class LIB_SYMBOL; -class LIB_PIN; class TEST_LIB_SYMBOL_FIXTURE; typedef std::shared_ptr LIB_SYMBOL_SPTR; ///< shared pointer to LIB_SYMBOL typedef std::weak_ptr LIB_SYMBOL_REF; ///< weak pointer to LIB_SYMBOL -typedef MULTIVECTOR LIB_ITEMS_CONTAINER; +typedef MULTIVECTOR LIB_ITEMS_CONTAINER; typedef LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS; @@ -387,18 +386,17 @@ public: * Note pin objects are owned by the draw list of the symbol. Deleting any of the objects * will leave list in a unstable state and will likely segfault when the list is destroyed. * - * @param aList - Pin list to place pin object pointers into. * @param aUnit - Unit number of pins to collect. Set to 0 to get pins from any symbol unit. * @param aBodyStyle - Symbol alternate body style of pins to collect. Set to 0 to get pins * from any DeMorgan variant of symbol. */ - void GetPins( std::vector& aList, int aUnit = 0, int aBodyStyle = 0 ) const; + std::vector GetPins( int aUnit = 0, int aBodyStyle = 0 ) const; /** * Return a list of pin pointers for all units / converts. Used primarily for SPICE where * we want to treat all unit as a single part. */ - std::vector GetAllLibPins() const; + std::vector GetAllLibPins() const; /** * @return a count of pins for all units / converts. @@ -414,7 +412,7 @@ public: * required. * @return The pin object if found. Otherwise NULL. */ - LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aBodyStyle = 0 ) const; + SCH_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aBodyStyle = 0 ) const; /** * Return true if this symbol's pins do not match another symbol's pins. This is used to diff --git a/eeschema/netlist_exporters/netlist_exporter_allegro.cpp b/eeschema/netlist_exporters/netlist_exporter_allegro.cpp index cedf8d5ef2..3b2687e289 100644 --- a/eeschema/netlist_exporters/netlist_exporter_allegro.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_allegro.cpp @@ -124,7 +124,7 @@ bool NETLIST_EXPORTER_ALLEGRO::CompareSymbolRef( const wxString& aRefText1, } -bool NETLIST_EXPORTER_ALLEGRO::CompareLibPin( const LIB_PIN* aPin1, const LIB_PIN* aPin2 ) +bool NETLIST_EXPORTER_ALLEGRO::CompareLibPin( const SCH_PIN* aPin1, const SCH_PIN* aPin2 ) { // return "lhs < rhs" return StrNumCmp( aPin1->GetShownNumber(), aPin2->GetShownNumber(), true ) < 0; @@ -177,18 +177,10 @@ void NETLIST_EXPORTER_ALLEGRO::extractComponentsInfo() SCH_SYMBOL* symbol = findNextSymbol( item, &sheet ); if( !symbol || symbol->GetExcludedFromBoard() ) - { continue; - } - std::vector pinList; - pinList.clear(); - symbol->GetLibPins(pinList); - - if( !pinList.size() ) - { + if( symbol->GetLibPins().empty() ) continue; - } m_packageProperties.insert( std::pair( sheet.PathHumanReadable(), @@ -450,8 +442,7 @@ void NETLIST_EXPORTER_ALLEGRO::toAllegroPackages() fprintf( d, "PACKAGE '%s'\n", TO_UTF8( formatDevice( footprintText ) ) ); fprintf( d, "CLASS IC\n" ); - std::vector pinList; - sym->GetLibSymbolRef()->GetPins( pinList, 0, 0 ); + std::vector pinList = sym->GetLibSymbolRef()->GetAllLibPins(); /* * We must erase redundant Pins references in pinList @@ -584,7 +575,7 @@ wxString NETLIST_EXPORTER_ALLEGRO::formatText( wxString aString ) } -wxString NETLIST_EXPORTER_ALLEGRO::formatPin( const LIB_PIN& aPin ) +wxString NETLIST_EXPORTER_ALLEGRO::formatPin( const SCH_PIN& aPin ) { wxString pinName4Telesis = aPin.GetName() + wxString( "__" ) + aPin.GetNumber(); std::regex reg( "[^A-Za-z0-9_+?/-]" ); @@ -592,7 +583,7 @@ wxString NETLIST_EXPORTER_ALLEGRO::formatPin( const LIB_PIN& aPin ) } -wxString NETLIST_EXPORTER_ALLEGRO::formatFunction( wxString aName, std::vector aPinList ) +wxString NETLIST_EXPORTER_ALLEGRO::formatFunction( wxString aName, std::vector aPinList ) { aName.MakeUpper(); std::list pinNameList; diff --git a/eeschema/netlist_exporters/netlist_exporter_allegro.h b/eeschema/netlist_exporters/netlist_exporter_allegro.h index 18f3a29ec3..125822a449 100644 --- a/eeschema/netlist_exporters/netlist_exporter_allegro.h +++ b/eeschema/netlist_exporters/netlist_exporter_allegro.h @@ -67,13 +67,13 @@ public: static bool CompareSymbolRef( const wxString& aRefText1, const wxString& aRefText2 ); /** - * Compare two LIB_PIN* variables. + * Compare two SCH_PIN* variables. * * @param aPin1 * @param aPin2 * @return bool value */ - static bool CompareLibPin( const LIB_PIN* aPin1, const LIB_PIN* aPin2 ); + static bool CompareLibPin( const SCH_PIN* aPin1, const SCH_PIN* aPin2 ); private: void extractComponentsInfo(); @@ -132,7 +132,7 @@ private: * @param aPin * @return wxString */ - wxString formatPin( const LIB_PIN& aPin ); + wxString formatPin( const SCH_PIN& aPin ); /** * Generate the definition of a function in Telesis format, which consists of @@ -142,7 +142,7 @@ private: * @param aPinList * @return wxString */ - wxString formatFunction( wxString aName, std::vector aPinList ); + wxString formatFunction( wxString aName, std::vector aPinList ); /** * Look up a field for a component group, which may have mismatched case, or diff --git a/eeschema/netlist_exporters/netlist_exporter_base.h b/eeschema/netlist_exporters/netlist_exporter_base.h index 80dffea370..450e65fd6d 100644 --- a/eeschema/netlist_exporters/netlist_exporter_base.h +++ b/eeschema/netlist_exporters/netlist_exporter_base.h @@ -26,10 +26,8 @@ #ifndef NETLIST_EXPORTER_H #define NETLIST_EXPORTER_H -#include #include #include -#include #include /** @@ -91,10 +89,6 @@ struct PIN_INFO class NETLIST_EXPORTER_BASE { public: - /** - * @param aMasterList we take ownership of this here. - * @param aLibTable is the symbol library table of the project. - */ NETLIST_EXPORTER_BASE( SCHEMATIC_IFACE* aSchematic ) : m_schematic( aSchematic ) { diff --git a/eeschema/netlist_exporters/netlist_exporter_xml.cpp b/eeschema/netlist_exporters/netlist_exporter_xml.cpp index 4f823553b0..5780cdee7f 100644 --- a/eeschema/netlist_exporters/netlist_exporter_xml.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_xml.cpp @@ -41,7 +41,7 @@ #include -static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 ); +static bool sortPinsByNumber( SCH_PIN* aPin1, SCH_PIN* aPin2 ); bool NETLIST_EXPORTER_XML::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions, REPORTER& aReporter ) @@ -570,8 +570,6 @@ XNODE* NETLIST_EXPORTER_XML::makeLibraries() XNODE* NETLIST_EXPORTER_XML::makeLibParts() { XNODE* xlibparts = node( wxT( "libparts" ) ); // auto_ptr - - std::vector pinList; std::vector fieldList; m_libraries.clear(); @@ -621,8 +619,7 @@ XNODE* NETLIST_EXPORTER_XML::makeLibParts() } //----- show the pins here ------------------------------------ - pinList.clear(); - lcomp->GetPins( pinList, 0, 0 ); + std::vector pinList = lcomp->GetPins( 0, 0 ); /* * We must erase redundant Pins references in pinList @@ -633,6 +630,7 @@ XNODE* NETLIST_EXPORTER_XML::makeLibParts() * found more than once. */ sort( pinList.begin(), pinList.end(), sortPinsByNumber ); + for( int ii = 0; ii < (int)pinList.size()-1; ii++ ) { if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() ) @@ -647,6 +645,7 @@ XNODE* NETLIST_EXPORTER_XML::makeLibParts() XNODE* pins; xlibpart->AddChild( pins = node( wxT( "pins" ) ) ); + for( unsigned i=0; iType() == SCH_PIN_T ) { - SCH_PIN* pin = static_cast( item ); - SCH_SYMBOL* symbol = static_cast( pin->GetParentSymbol() ); + SCH_PIN* pin = static_cast( item ); + SCH_SYMBOL* symbol = dynamic_cast( pin->GetParentSymbol() ); if( !symbol || ( ( aCtl & GNL_OPT_BOM ) && symbol->GetExcludedFromBOM() ) @@ -755,7 +759,7 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl ) // Netlist ordering: Net name, then ref des, then pin name std::sort( net_record->m_Nodes.begin(), net_record->m_Nodes.end(), - []( const NET_NODE& a, const NET_NODE& b ) + []( const NET_NODE& a, const NET_NODE& b ) { wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet ); wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet ); @@ -852,7 +856,7 @@ XNODE* NETLIST_EXPORTER_XML::node( const wxString& aName, } -static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 ) +static bool sortPinsByNumber( SCH_PIN* aPin1, SCH_PIN* aPin2 ) { // return "lhs < rhs" return StrNumCmp( aPin1->GetShownNumber(), aPin2->GetShownNumber(), true ) < 0; diff --git a/eeschema/pin_type.cpp b/eeschema/pin_type.cpp index db69e07016..9ab418c875 100644 --- a/eeschema/pin_type.cpp +++ b/eeschema/pin_type.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "pgm_base.h" @@ -141,8 +141,11 @@ void InitTables() for( PIN_ORIENTATION orientation : magic_enum::enum_values() ) { - g_orientationIcons.push_back( PinOrientationGetBitmap( orientation ) ); - g_orientationNames.push_back( PinOrientationName( orientation ) ); + if( orientation != PIN_ORIENTATION::INHERIT ) + { + g_orientationIcons.push_back( PinOrientationGetBitmap( orientation ) ); + g_orientationNames.push_back( PinOrientationName( orientation ) ); + } } } diff --git a/eeschema/pin_type.h b/eeschema/pin_type.h index 0900c9ebcd..b437c1e7e9 100644 --- a/eeschema/pin_type.h +++ b/eeschema/pin_type.h @@ -47,7 +47,8 @@ enum class ELECTRICAL_PINTYPE PT_OPENEMITTER, ///< pin type open emitter PT_NC, ///< not connected (must be left open) - PT_LAST_OPTION = PT_NC ///< sentinel value, set to last usable enum option + PT_LAST_OPTION = PT_NC, ///< sentinel value, set to last usable enum option + PT_INHERIT }; #define ELECTRICAL_PINTYPES_TOTAL ( static_cast( ELECTRICAL_PINTYPE::PT_LAST_OPTION ) + 1 ) @@ -64,7 +65,8 @@ enum class GRAPHIC_PINSHAPE FALLING_EDGE_CLOCK, NONLOGIC, - LAST_OPTION = NONLOGIC ///< this is the sentinel value, must be set to last enum value + LAST_OPTION = NONLOGIC, ///< this is the sentinel value, must be set to last enum value + INHERIT }; #define GRAPHIC_PINSHAPES_TOTAL ( static_cast( GRAPHIC_PINSHAPE::LAST_OPTION ) + 1 ) @@ -77,6 +79,9 @@ enum class PIN_ORIENTATION { PIN_LEFT = 'L', PIN_UP = 'U', PIN_DOWN = 'D', + + LAST_OPTION = PIN_DOWN, + INHERIT = 'I' }; @@ -88,8 +93,8 @@ BITMAPS PinShapeGetBitmap( GRAPHIC_PINSHAPE shape ); wxString ElectricalPinTypeGetText( ELECTRICAL_PINTYPE ); BITMAPS ElectricalPinTypeGetBitmap( ELECTRICAL_PINTYPE ); -wxString PinOrientationName( PIN_ORIENTATION aPinOrientation ); -BITMAPS PinOrientationGetBitmap( PIN_ORIENTATION aPinOrientation ); +wxString PinOrientationName( PIN_ORIENTATION aOrientation ); +BITMAPS PinOrientationGetBitmap( PIN_ORIENTATION aOrientation ); PIN_ORIENTATION PinOrientationCode( size_t index ); int PinOrientationIndex( PIN_ORIENTATION code ); diff --git a/eeschema/sch_connection.cpp b/eeschema/sch_connection.cpp index 2241969993..415efbf034 100644 --- a/eeschema/sch_connection.cpp +++ b/eeschema/sch_connection.cpp @@ -321,16 +321,19 @@ bool SCH_CONNECTION::IsDriver() const case SCH_HIER_LABEL_T: case SCH_SHEET_PIN_T: case SCH_SHEET_T: - case LIB_PIN_T: return true; case SCH_PIN_T: { - const SCH_PIN* pin = static_cast( Parent() ); - const SCH_SYMBOL* symbol = static_cast( pin->GetParentSymbol() ); + const SCH_PIN* pin = static_cast( Parent() ); - // Only annotated symbols should drive nets. - return pin->IsGlobalPower() || symbol->IsAnnotated( &m_sheet ); + if( const SCH_SYMBOL* symbol = dynamic_cast( pin->GetParentSymbol() ) ) + { + // Only annotated symbols should drive nets. + return pin->IsGlobalPower() || symbol->IsAnnotated( &m_sheet ); + } + + return true; } default: diff --git a/eeschema/sch_io/altium/sch_io_altium.cpp b/eeschema/sch_io/altium/sch_io_altium.cpp index 86520d405a..16c7f1464e 100644 --- a/eeschema/sch_io/altium/sch_io_altium.cpp +++ b/eeschema/sch_io/altium/sch_io_altium.cpp @@ -37,8 +37,7 @@ #include #include -#include - +#include #include #include #include @@ -1202,7 +1201,7 @@ void SCH_IO_ALTIUM::ParsePin( const std::map& aProperties, symbol = libSymbolIt->second; } - LIB_PIN* pin = new LIB_PIN( symbol ); + SCH_PIN* pin = new SCH_PIN( symbol ); // Make sure that these are visible when initializing the symbol // This may be overriden by the file data but not by the pin defaults @@ -3213,7 +3212,7 @@ void SCH_IO_ALTIUM::ParsePowerPort( const std::map& aPropert libSymbol->SetLibId( libId ); // generate graphic - LIB_PIN* pin = new LIB_PIN( libSymbol ); + SCH_PIN* pin = new SCH_PIN( libSymbol ); libSymbol->AddDrawItem( pin, false ); pin->SetName( elem.text ); diff --git a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp index d37d586851..72ddbc1829 100644 --- a/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_io/cadstar/cadstar_sch_archive_loader.cpp @@ -143,7 +143,7 @@ CADSTAR_SCH_ARCHIVE_LOADER::loadLibPart( const CADSTAR_PART_ENTRY& aPart ) for( auto& [storedPinNum, termID] : m_symDefTerminalsMap[symbolID] ) { wxCHECK( termID > 0 && sym.m_Pins.size() >= size_t( termID ), nullptr ); - LIB_PIN* pin = kiSymDef->GetPin( storedPinNum ); + SCH_PIN* pin = kiSymDef->GetPin( storedPinNum ); size_t termIdx = size_t( termID ) - 1; // For now leave numerical pin number. Otherwise, when loading the @@ -234,7 +234,7 @@ CADSTAR_SCH_ARCHIVE_LOADER::loadLibPart( const CADSTAR_PART_ENTRY& aPart ) { for( const CADSTAR_PART_PIN& csPin : csPinVector ) { - std::unique_ptr pin = std::make_unique( retSym.get() ); + std::unique_ptr pin = std::make_unique( retSym.get() ); long pinNum = csPin.m_Identifier; pin->SetNumber( wxString::Format( "%ld", pinNum ) ); @@ -878,7 +878,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances() kiPart->SetShowPinNames( false ); kiPart->SetShowPinNumbers( false ); - std::vector pins = kiPart->GetAllLibPins(); + std::vector pins = kiPart->GetAllLibPins(); wxCHECK( pins.size() == 1, /*void*/ ); pins.at( 0 )->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN ); @@ -1652,7 +1652,7 @@ const LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSymdef( const SYMDEF_ID& aSymd TERMINAL term = termPair.second; wxString pinNum = wxString::Format( "%ld", term.ID ); wxString pinName = wxEmptyString; - std::unique_ptr pin = std::make_unique( kiSym.get() ); + std::unique_ptr pin = std::make_unique( kiSym.get() ); // Assume passive pin for now (we will set it later once we load the parts) pin->SetType( ELECTRICAL_PINTYPE::PT_PASSIVE ); @@ -1829,7 +1829,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolGateAndPartFields( const SYMDEF_ID& a for( auto&& [storedPinNum, termID] : m_symDefTerminalsMap[aSymdefID] ) { PART::DEFINITION::PIN csPin = getPartDefinitionPin( aCadstarPart, aGateID, termID ); - LIB_PIN* pin = kiSymDef->GetPin( storedPinNum ); + SCH_PIN* pin = kiSymDef->GetPin( storedPinNum ); wxString pinName = HandleTextOverbar( csPin.Label ); wxString pinNum = HandleTextOverbar( csPin.Name ); @@ -2132,7 +2132,7 @@ SCH_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol( const SYMBOL& aCads { TERMINAL_TO_PINNUM_MAP termNumMap = m_pinNumsMap.at( partGateIndex ); - std::map pinNumToLibPinMap; + std::map pinNumToLibPinMap; for( auto& term : termNumMap ) { @@ -2147,7 +2147,7 @@ SCH_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol( const SYMBOL& aCads if( aOldPinNum == aNewPinNum ) return; - LIB_PIN* libpin = pinNumToLibPinMap.at( aOldPinNum ); + SCH_PIN* libpin = pinNumToLibPinMap.at( aOldPinNum ); libpin->SetNumber( HandleTextOverbar( aNewPinNum ) ); }; @@ -3228,9 +3228,9 @@ LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart( const LIB_SYMBOL* aSym break; } - case KICAD_T::LIB_PIN_T: + case KICAD_T::SCH_PIN_T: { - LIB_PIN& pin = static_cast( item ); + SCH_PIN& pin = static_cast( item ); pin.SetPosition( scalePt( pin.GetPosition() ) ); pin.SetLength( scaleLen( pin.GetLength() ) ); @@ -3298,10 +3298,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins( LIB_SYMBOL* aSymbolToFix, int } } - std::vector pins; - aSymbolToFix->GetPins( pins, aGateNumber ); - - for( auto& pin : pins ) + for( SCH_PIN* pin : aSymbolToFix->GetPins( aGateNumber ) ) { auto setPinOrientation = [&]( const EDA_ANGLE& aAngle ) diff --git a/eeschema/sch_io/eagle/sch_io_eagle.cpp b/eeschema/sch_io/eagle/sch_io_eagle.cpp index 5fdc4649ef..84fe168567 100644 --- a/eeschema/sch_io/eagle/sch_io_eagle.cpp +++ b/eeschema/sch_io/eagle/sch_io_eagle.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -50,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -1967,10 +1967,7 @@ void SCH_IO_EAGLE::loadInstance( wxXmlNode* aInstanceNode ) symbol->SetLibSymbol( new LIB_SYMBOL( *libSymbol ) ); - std::vector pins; - symbol->GetLibPins( pins ); - - for( const LIB_PIN* pin : pins ) + for( const SCH_PIN* pin : symbol->GetLibPins() ) m_connPoints[symbol->GetPinPhysicalPosition( pin )].emplace( pin ); if( part->IsPower() ) @@ -2153,7 +2150,7 @@ bool SCH_IO_EAGLE::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptr pin( loadPin( aSymbol, currentNode, &ePin, aGateNumber ) ); + std::unique_ptr pin( loadPin( aSymbol, currentNode, &ePin, aGateNumber ) ); pincount++; pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI ); @@ -2192,7 +2189,7 @@ bool SCH_IO_EAGLE::loadSymbol( wxXmlNode* aSymbolNode, std::unique_ptrSetNumber( padname ); @@ -2429,10 +2426,10 @@ SCH_SHAPE* SCH_IO_EAGLE::loadSymbolPolyLine( wxXmlNode* aPolygonNode, int aGateN } -LIB_PIN* SCH_IO_EAGLE::loadPin( std::unique_ptr& aSymbol, wxXmlNode* aPin, +SCH_PIN* SCH_IO_EAGLE::loadPin( std::unique_ptr& aSymbol, wxXmlNode* aPin, EPIN* aEPin, int aGateNumber ) { - std::unique_ptr pin = std::make_unique( aSymbol.get() ); + std::unique_ptr pin = std::make_unique( aSymbol.get() ); pin->SetPosition( VECTOR2I( aEPin->x.ToSchUnits(), aEPin->y.ToSchUnits() ) ); pin->SetName( aEPin->name ); pin->SetUnit( aGateNumber ); @@ -3481,7 +3478,7 @@ const SEG* SCH_IO_EAGLE::SEG_DESC::LabelAttached( const SCH_TEXT* aLabel ) const // TODO could be used to place junctions, instead of IsJunctionNeeded() // (see SCH_EDIT_FRAME::importFile()) -bool SCH_IO_EAGLE::checkConnections( const SCH_SYMBOL* aSymbol, const LIB_PIN* aPin ) const +bool SCH_IO_EAGLE::checkConnections( const SCH_SYMBOL* aSymbol, const SCH_PIN* aPin ) const { wxCHECK( aSymbol && aPin, false ); @@ -3511,12 +3508,11 @@ void SCH_IO_EAGLE::addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScr int unit = aSymbol->GetUnit(); const wxString reference = aSymbol->GetField( REFERENCE_FIELD )->GetText(); - std::vector pins; - aSymbol->GetLibSymbolRef()->GetPins( pins ); - std::set missingUnits; + std::vector pins = aSymbol->GetLibSymbolRef()->GetAllLibPins(); + std::set missingUnits; // Search all units for pins creating implicit connections - for( const LIB_PIN* pin : pins ) + for( const SCH_PIN* pin : pins ) { if( pin->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN ) { @@ -3536,12 +3532,13 @@ void SCH_IO_EAGLE::addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScr switch( pin->GetOrientation() ) { - case PIN_ORIENTATION::PIN_LEFT: - netLabel->SetSpinStyle( SPIN_STYLE::RIGHT ); - break; + default: case PIN_ORIENTATION::PIN_RIGHT: netLabel->SetSpinStyle( SPIN_STYLE::LEFT ); break; + case PIN_ORIENTATION::PIN_LEFT: + netLabel->SetSpinStyle( SPIN_STYLE::RIGHT ); + break; case PIN_ORIENTATION::PIN_UP: netLabel->SetSpinStyle( SPIN_STYLE::UP ); break; diff --git a/eeschema/sch_io/eagle/sch_io_eagle.h b/eeschema/sch_io/eagle/sch_io_eagle.h index 286c1a1b25..fa708945f2 100644 --- a/eeschema/sch_io/eagle/sch_io_eagle.h +++ b/eeschema/sch_io/eagle/sch_io_eagle.h @@ -51,7 +51,7 @@ class SCH_FIELD; class STRING_UTF8_MAP; class LIB_SYMBOL; class SYMBOL_LIB; -class LIB_PIN; +class SCH_PIN; class wxXmlNode; @@ -156,7 +156,7 @@ private: SCH_SHAPE* loadSymbolRectangle( wxXmlNode* aRectNode, int aGateNumber ); SCH_SHAPE* loadSymbolPolyLine( wxXmlNode* aPolygonNode, int aGateNumber ); SCH_ITEM* loadSymbolWire( wxXmlNode* aWireNode, int aGateNumber ); - LIB_PIN* loadPin( std::unique_ptr& aSymbol, wxXmlNode*, EPIN* epin, + SCH_PIN* loadPin( std::unique_ptr& aSymbol, wxXmlNode*, EPIN* epin, int aGateNumber ); SCH_TEXT* loadSymbolText( wxXmlNode* aLibText, int aGateNumber ); void loadSymbolFrame( wxXmlNode* aFrameNode, std::vector& aLines ); @@ -181,7 +181,7 @@ private: wxFileName getLibFileName(); ///< Checks if there are other wires or pins at the position of the tested pin - bool checkConnections( const SCH_SYMBOL* aSymbol, const LIB_PIN* aPin ) const; + bool checkConnections( const SCH_SYMBOL* aSymbol, const SCH_PIN* aPin ) const; /** * Create net labels to emulate implicit connections in Eagle. diff --git a/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp b/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp index 62b00c4155..7512444b61 100644 --- a/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp +++ b/eeschema/sch_io/easyeda/sch_easyeda_parser.cpp @@ -845,7 +845,7 @@ void SCH_EASYEDA_PARSER::ParseSymbolShapes( LIB_SYMBOL* aSymbol } } - std::unique_ptr pin = std::make_unique( aSymbol ); + std::unique_ptr pin = std::make_unique( aSymbol ); pin->SetName( pinName ); pin->SetNumber( pinNumber ); @@ -1006,7 +1006,7 @@ std::pair SCH_EASYEDA_PARSER::MakePowerSymbol( const wxString ksymbol->SetShowPinNames( false ); ksymbol->SetShowPinNumbers( false ); - std::unique_ptr pin = std::make_unique( ksymbol.get() ); + std::unique_ptr pin = std::make_unique( ksymbol.get() ); pin->SetName( aNetname ); pin->SetNumber( wxS( "1" ) ); diff --git a/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp b/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp index de44d36fe6..f86f2edbfb 100644 --- a/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp +++ b/eeschema/sch_io/easyedapro/sch_easyedapro_parser.cpp @@ -709,7 +709,7 @@ EASYEDAPRO::SYM_INFO SCH_EASYEDAPRO_PARSER::ParseSymbol( const std::vector pin = std::make_unique( ksymbol ); + std::unique_ptr pin = std::make_unique( ksymbol ); pin->SetUnit( unitId ); @@ -1141,7 +1141,7 @@ void SCH_EASYEDAPRO_PARSER::ParseSchematic( SCHEMATIC* aSchematic, SCH_SHEET* aR ApplyAttrToField( fontStyles, schSym->GetField( VALUE_FIELD ), *globalNetAttr, false, true, compAttrs, schSym.get() ); - for( LIB_PIN* pin : schSym->GetAllLibPins() ) + for( SCH_PIN* pin : schSym->GetAllLibPins() ) pin->SetName( globalNetAttr->value ); } else diff --git a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp index 1350f6cf73..e2c0e4cc4b 100644 --- a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp +++ b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.cpp @@ -20,8 +20,9 @@ #include #include +#include #include -#include +#include #include #include #include @@ -1080,12 +1081,12 @@ SCH_SHAPE* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadRect( LINE_READER& aReader ) } -LIB_PIN* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPin( std::unique_ptr& aSymbol, +SCH_PIN* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPin( std::unique_ptr& aSymbol, LINE_READER& aReader ) { const char* line = aReader.Line(); - wxCHECK_MSG( strCompare( "X", line, &line ), nullptr, "Invalid LIB_PIN definition" ); + wxCHECK_MSG( strCompare( "X", line, &line ), nullptr, "Invalid SCH_PIN definition" ); wxString name; wxString number; @@ -1233,8 +1234,7 @@ LIB_PIN* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPin( std::unique_ptr& aS aReader.LineNumber(), pos ); } - - LIB_PIN* pin = new LIB_PIN( aSymbol.get(), + SCH_PIN* pin = new SCH_PIN( aSymbol.get(), ConvertToNewOverbarNotation( name ), ConvertToNewOverbarNotation( number ), orientation, @@ -1263,7 +1263,7 @@ LIB_PIN* SCH_IO_KICAD_LEGACY_LIB_CACHE::loadPin( std::unique_ptr& aS int flags = 0; - for( int j = tmp.size(); j > 0; ) + for( int j = (int) tmp.size(); j > 0; ) { switch( tmp[--j].GetValue() ) { @@ -1572,8 +1572,8 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::SaveSymbol( LIB_SYMBOL* aSymbol, OUTPUTFORMA { switch( item.Type() ) { - case LIB_PIN_T: - savePin( static_cast( &item ), aFormatter ); + case SCH_PIN_T: + savePin( static_cast( &item ), aFormatter ); break; case SCH_TEXT_T: @@ -1723,9 +1723,9 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::saveField( const SCH_FIELD* aField, } -void SCH_IO_KICAD_LEGACY_LIB_CACHE::savePin( const LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter ) +void SCH_IO_KICAD_LEGACY_LIB_CACHE::savePin( const SCH_PIN* aPin, OUTPUTFORMATTER& aFormatter ) { - wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." ); + wxCHECK_RET( aPin && aPin->Type() == SCH_PIN_T, "Invalid SCH_PIN object." ); int Etype; @@ -1784,7 +1784,7 @@ void SCH_IO_KICAD_LEGACY_LIB_CACHE::savePin( const LIB_PIN* aPin, OUTPUTFORMATTE aFormatter.Print( 0, "\n" ); - const_cast( aPin )->ClearFlags( IS_CHANGED ); + const_cast( aPin )->ClearFlags( IS_CHANGED ); } diff --git a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.h b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.h index 46ea2d3480..8e3aedcfe8 100644 --- a/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.h +++ b/eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy_lib_cache.h @@ -29,7 +29,8 @@ #include "sch_io/sch_io_lib_cache.h" class FILE_LINE_READER; -class LIB_PIN; +class SCH_PIN; +class SCH_FIELD; class SCH_SHAPE; class SCH_TEXT; class LINE_READER; @@ -77,7 +78,7 @@ private: static SCH_SHAPE* loadCircle( LINE_READER& aReader ); static SCH_TEXT* loadText( LINE_READER& aReader, int aMajorVersion, int aMinorVersion ); static SCH_SHAPE* loadRect( LINE_READER& aReader ); - static LIB_PIN* loadPin( std::unique_ptr& aSymbol, LINE_READER& aReader ); + static SCH_PIN* loadPin( std::unique_ptr& aSymbol, LINE_READER& aReader ); static SCH_SHAPE* loadPolyLine( LINE_READER& aReader ); static SCH_SHAPE* loadBezier( LINE_READER& aReader ); @@ -88,7 +89,7 @@ private: static void saveBezier( SCH_SHAPE* aBezier, OUTPUTFORMATTER& aFormatter ); static void saveCircle( SCH_SHAPE* aCircle, OUTPUTFORMATTER& aFormatter ); static void saveField( const SCH_FIELD* aField, OUTPUTFORMATTER& aFormatter ); - static void savePin( const LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter ); + static void savePin( const SCH_PIN* aPin, OUTPUTFORMATTER& aFormatter ); static void savePolyLine( SCH_SHAPE* aPolyLine, OUTPUTFORMATTER& aFormatter ); static void saveRectangle( SCH_SHAPE* aRectangle, OUTPUTFORMATTER& aFormatter ); static void saveText( const SCH_TEXT* aText, OUTPUTFORMATTER& aFormatter ); diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp index 7d55518161..a7c5fb7b05 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp @@ -39,6 +39,7 @@ #include // SYMBOL_ORIENTATION_T #include #include +#include #include #include #include @@ -49,7 +50,6 @@ #include #include #include -#include #include #include #include diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_common.h b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_common.h index 91ca964b78..8b12d8aac0 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_common.h +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_common.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp index 1bb9023d89..eab94fe6ac 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.cpp @@ -370,8 +370,8 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveSymbolDrawItem( SCH_ITEM* aItem, OUTPUTFO break; } - case LIB_PIN_T: - savePin( static_cast( aItem ), aFormatter, aNestLevel ); + case SCH_PIN_T: + savePin( static_cast( aItem ), aFormatter, aNestLevel ); break; case SCH_TEXT_T: @@ -419,10 +419,10 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::saveField( SCH_FIELD* aField, OUTPUTFORMATTER } -void SCH_IO_KICAD_SEXPR_LIB_CACHE::savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter, +void SCH_IO_KICAD_SEXPR_LIB_CACHE::savePin( SCH_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel ) { - wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." ); + wxCHECK_RET( aPin && aPin->Type() == SCH_PIN_T, "Invalid SCH_PIN object." ); aPin->ClearFlags( IS_CHANGED ); @@ -458,7 +458,7 @@ void SCH_IO_KICAD_SEXPR_LIB_CACHE::savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFor aPin->GetNumberTextSize() ).c_str() ); - for( const std::pair& alt : aPin->GetAlternates() ) + for( const std::pair& alt : aPin->GetAlternates() ) { aFormatter.Print( aNestLevel + 1, "(alternate %s %s %s)\n", aFormatter.Quotew( alt.second.m_Name ).c_str(), diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.h b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.h index 8f08f1e411..6cc8fe7a32 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.h +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_lib_cache.h @@ -25,7 +25,7 @@ #include "sch_io/sch_io_lib_cache.h" class FILE_LINE_READER; -class LIB_PIN; +class SCH_PIN; class SCH_TEXT; class SCH_TEXTBOX; class LINE_READER; @@ -65,7 +65,7 @@ private: static void saveSymbolDrawItem( SCH_ITEM* aItem, OUTPUTFORMATTER& aFormatter, int aNestLevel ); static void saveField( SCH_FIELD* aField, OUTPUTFORMATTER& aFormatter, int aNestLevel ); - static void savePin( LIB_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 ); + static void savePin( SCH_PIN* aPin, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 ); static void saveText( SCH_TEXT* aText, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 ); static void saveTextBox( SCH_TEXTBOX* aTextBox, OUTPUTFORMATTER& aFormatter, int aNestLevel = 0 ); diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp index 863a5d42e0..9b742750e5 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.cpp @@ -36,7 +36,7 @@ #include #include -#include +#include #include // KiROUND, Clamp #include #include @@ -1415,7 +1415,7 @@ SCH_SHAPE* SCH_IO_KICAD_SEXPR_PARSER::parseSymbolCircle() } -LIB_PIN* SCH_IO_KICAD_SEXPR_PARSER::parsePin() +SCH_PIN* SCH_IO_KICAD_SEXPR_PARSER::parsePin() { auto parseType = [&]( T token ) -> ELECTRICAL_PINTYPE { @@ -1470,7 +1470,7 @@ LIB_PIN* SCH_IO_KICAD_SEXPR_PARSER::parsePin() T token; wxString tmp; wxString error; - std::unique_ptr pin = std::make_unique( nullptr ); + std::unique_ptr pin = std::make_unique( nullptr ); pin->SetUnit( m_unit ); pin->SetBodyStyle( m_bodyStyle ); @@ -1592,7 +1592,7 @@ LIB_PIN* SCH_IO_KICAD_SEXPR_PARSER::parsePin() case T_alternate: { - LIB_PIN::ALT alt; + SCH_PIN::ALT alt; token = NextTok(); diff --git a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.h b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.h index 471d01c523..595c5b2a6b 100644 --- a/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.h +++ b/eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr_parser.h @@ -37,7 +37,7 @@ #include // For some default values -class LIB_PIN; +class SCH_PIN; class PAGE_INFO; class SCH_BITMAP; class SCH_BUS_WIRE_ENTRY; @@ -196,7 +196,7 @@ private: SCH_SHAPE* parseSymbolArc(); SCH_SHAPE* parseSymbolBezier(); SCH_SHAPE* parseSymbolCircle(); - LIB_PIN* parsePin(); + SCH_PIN* parsePin(); SCH_SHAPE* parseSymbolPolyLine(); SCH_SHAPE* parseSymbolRectangle(); SCH_TEXT* parseSymbolText(); diff --git a/eeschema/sch_io/ltspice/sch_io_ltspice_parser.cpp b/eeschema/sch_io/ltspice/sch_io_ltspice_parser.cpp index e5f53d410a..74cafecc23 100644 --- a/eeschema/sch_io/ltspice/sch_io_ltspice_parser.cpp +++ b/eeschema/sch_io/ltspice/sch_io_ltspice_parser.cpp @@ -308,7 +308,7 @@ void SCH_IO_LTSPICE_PARSER::CreateSymbol( LTSPICE_SCHEMATIC::LT_SYMBOL& aLtSymbo for( int j = 0; j < (int) aLtSymbol.Pins.size(); j++ ) { - LIB_PIN* pin = new LIB_PIN( aLibSymbol ); + SCH_PIN* pin = new SCH_PIN( aLibSymbol ); CreatePin( aLtSymbol, j, pin ); aLibSymbol->AddDrawItem( pin ); @@ -833,7 +833,7 @@ SCH_SYMBOL* SCH_IO_LTSPICE_PARSER::CreatePowerSymbol( const VECTOR2I& aOffset, lib_symbol->AddDrawItem( shape ); lib_symbol->SetPower(); - LIB_PIN* pin = new LIB_PIN( lib_symbol ); + SCH_PIN* pin = new SCH_PIN( lib_symbol ); pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN ); pin->SetPosition( ToInvertedKicadCoords( { 0, 0 } ) ); @@ -1272,7 +1272,7 @@ void SCH_IO_LTSPICE_PARSER::CreateRect( LTSPICE_SCHEMATIC::LT_SYMBOL& aLTSymbol, void SCH_IO_LTSPICE_PARSER::CreatePin( LTSPICE_SCHEMATIC::LT_SYMBOL& aLTSymbol, int aIndex, - LIB_PIN* aPin ) + SCH_PIN* aPin ) { LTSPICE_SCHEMATIC::LT_PIN& lt_pin = aLTSymbol.Pins[aIndex]; wxString device = aLTSymbol.Name.Lower(); diff --git a/eeschema/sch_io/ltspice/sch_io_ltspice_parser.h b/eeschema/sch_io/ltspice/sch_io_ltspice_parser.h index d42827a5e4..cca8c1e50c 100644 --- a/eeschema/sch_io/ltspice/sch_io_ltspice_parser.h +++ b/eeschema/sch_io/ltspice/sch_io_ltspice_parser.h @@ -35,7 +35,7 @@ class EDA_TEXT; -class LIB_PIN; +class SCH_PIN; class SCH_LABEL_BASE; class SCH_SYMBOL; class SCH_TEXT; @@ -252,7 +252,7 @@ public: /** * Create a pin from an asy file. */ - void CreatePin( LTSPICE_SCHEMATIC::LT_SYMBOL& aLTSymbol, int aIndex, LIB_PIN* aPin ); + void CreatePin( LTSPICE_SCHEMATIC::LT_SYMBOL& aLTSymbol, int aIndex, SCH_PIN* aPin ); /** * Create a symbol arc. diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 6b1d05fd6c..00108d7c80 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -88,7 +88,7 @@ std::vector SCH_PAINTER::g_ScaledSelectionTypes = { SCH_SHEET_PIN_T, LIB_SYMBOL_T, SCH_SYMBOL_T, SCH_SHEET_T, - LIB_PIN_T, SCH_PIN_T + SCH_PIN_T }; @@ -178,9 +178,9 @@ void SCH_PAINTER::draw( const EDA_ITEM* aItem, int aLayer, bool aDimmed ) case LIB_SYMBOL_T: draw( static_cast( aItem ), aLayer ); break; - case LIB_PIN_T: + case SCH_PIN_T: drawBoundingBox = false; - draw( static_cast( aItem ), aLayer, aDimmed ); + draw( static_cast( aItem ), aLayer, aDimmed ); break; case SCH_SYMBOL_T: draw( static_cast( aItem ), aLayer ); @@ -315,21 +315,13 @@ float SCH_PAINTER::getShadowWidth( bool aForHighlight ) const } -// A helper function to know if a EDA_ITEM is a member of a footprint -static bool IsItemFPMember( const EDA_ITEM* aItem ) -{ - return aItem->GetParent() && ( aItem->GetParent()->Type() == LIB_SYMBOL_T - || aItem->GetParent()->Type() == SCH_SYMBOL_T ); -} - - -COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDrawingShadows, +COLOR4D SCH_PAINTER::getRenderColor( const SCH_ITEM* aItem, int aLayer, bool aDrawingShadows, bool aDimmed ) const { COLOR4D color = m_schSettings.GetLayerColor( aLayer ); // Graphic items of a SYMBOL frequently use the LAYER_DEVICE layer color // (i.e. when no specific color is set) - bool isFpMember = IsItemFPMember( aItem ); + bool isSymbolChild = aItem->GetParentSymbol() != nullptr; if( aItem->Type() == SCH_LINE_T ) { @@ -360,21 +352,22 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND ) { - if( !isFpMember || shape->GetFillColor() != COLOR4D::UNSPECIFIED ) + if( !isSymbolChild || shape->GetFillColor() != COLOR4D::UNSPECIFIED ) color = shape->GetFillColor(); - if( isFpMember && shape->GetFillMode() == FILL_T::FILLED_SHAPE ) + + if( isSymbolChild && shape->GetFillMode() == FILL_T::FILLED_SHAPE ) color = shape->GetStroke().GetColor(); } else { - if( !isFpMember || shape->GetStroke().GetColor() != COLOR4D::UNSPECIFIED ) + if( !isSymbolChild || shape->GetStroke().GetColor() != COLOR4D::UNSPECIFIED ) color = shape->GetStroke().GetColor(); } // A filled shape means filled; if they didn't specify a fill colour then use the // border colour. if( color == COLOR4D::UNSPECIFIED ) - color = m_schSettings.GetLayerColor( isFpMember ? LAYER_DEVICE : LAYER_NOTES ); + color = m_schSettings.GetLayerColor( isSymbolChild ? LAYER_DEVICE : LAYER_NOTES ); } else if( aItem->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) { @@ -390,12 +383,12 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr if( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_NOTES_BACKGROUND ) color = textBox->GetFillColor(); - else if( !isFpMember || textBox->GetTextColor() != COLOR4D::UNSPECIFIED ) + else if( !isSymbolChild || textBox->GetTextColor() != COLOR4D::UNSPECIFIED ) color = textBox->GetTextColor(); } else if( const EDA_TEXT* otherTextItem = dynamic_cast( aItem ) ) { - if( !isFpMember || otherTextItem->GetTextColor() != COLOR4D::UNSPECIFIED ) + if( !isSymbolChild || otherTextItem->GetTextColor() != COLOR4D::UNSPECIFIED ) color = otherTextItem->GetTextColor(); } } @@ -424,8 +417,8 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr if( aDrawingShadows ) color = m_schSettings.GetLayerColor( LAYER_SELECTION_SHADOWS ); } - else if( aItem->IsSelected() - && ( aLayer == LAYER_DEVICE_BACKGROUND || aLayer == LAYER_SHEET_BACKGROUND ) ) + else if( aItem->IsSelected() && ( aLayer == LAYER_DEVICE_BACKGROUND + || aLayer == LAYER_SHEET_BACKGROUND ) ) { // Selected items will be painted over all other items, so make backgrounds translucent so // that non-selected overlapping objects are visible @@ -452,17 +445,11 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr } -float SCH_PAINTER::getLineWidth( const EDA_ITEM* aItem, bool aDrawingShadows ) const +float SCH_PAINTER::getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) const { wxCHECK( aItem, static_cast( schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS ) ) ); - int pen = 0; - - if( const SCH_ITEM* item = dynamic_cast( aItem ) ) - pen = item->GetEffectivePenWidth( &m_schSettings ); - else - UNIMPLEMENTED_FOR( aItem->GetClass() ); - + int pen = aItem->GetEffectivePenWidth( &m_schSettings ); float width = pen; if( aItem->IsBrightened() || aItem->IsSelected() ) @@ -475,7 +462,7 @@ float SCH_PAINTER::getLineWidth( const EDA_ITEM* aItem, bool aDrawingShadows ) c } -float SCH_PAINTER::getTextThickness( const EDA_ITEM* aItem ) const +float SCH_PAINTER::getTextThickness( const SCH_ITEM* aItem ) const { int pen = m_schSettings.GetDefaultPenWidth(); @@ -540,20 +527,21 @@ static bool isFieldsLayer( int aLayer ) void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, - const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics ) + const TEXT_ATTRIBUTES& aAttributes, + const KIFONT::METRICS& aFontMetrics ) { - KIFONT::FONT* font = aAttrs.m_Font; + KIFONT::FONT* font = aAttributes.m_Font; if( !font ) { - font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttrs.m_Bold, - aAttrs.m_Italic ); + font = KIFONT::FONT::GetFont( eeconfig()->m_Appearance.default_font, aAttributes.m_Bold, + aAttributes.m_Italic ); } m_gal->SetIsFill( font->IsOutline() ); m_gal->SetIsStroke( font->IsStroke() ); - font->Draw( m_gal, aText, aPosition, aAttrs, aFontMetrics ); + font->Draw( m_gal, aText, aPosition, aAttributes, aFontMetrics ); } @@ -620,8 +608,10 @@ void SCH_PAINTER::knockoutText( const wxString& aText, const VECTOR2D& aPosition void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition, const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics, - bool invertY ) + bool aInvertY ) { + bool invertY = aInvertY; + KIFONT::FONT* font = aAttrs.m_Font; if( !font ) @@ -812,7 +802,7 @@ bool SCH_PAINTER::setDeviceColors( const SCH_ITEM* aItem, int aLayer, bool aDimm } -int SCH_PAINTER::internalPinDecoSize( const LIB_PIN &aPin ) +int SCH_PAINTER::internalPinDecoSize( const SCH_PIN &aPin ) { if( m_schSettings.m_PinSymbolSize > 0 ) return m_schSettings.m_PinSymbolSize; @@ -823,7 +813,7 @@ int SCH_PAINTER::internalPinDecoSize( const LIB_PIN &aPin ) // Utility for getting the size of the 'external' pin decorators (as a radius) // i.e. the negation circle, the polarity 'slopes' and the nonlogic marker -int SCH_PAINTER::externalPinDecoSize( const LIB_PIN &aPin ) +int SCH_PAINTER::externalPinDecoSize( const SCH_PIN &aPin ) { if( m_schSettings.m_PinSymbolSize > 0 ) return m_schSettings.m_PinSymbolSize; @@ -849,7 +839,7 @@ void SCH_PAINTER::drawPinDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& } -void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ) +void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed ) { if( !isUnitAndConversionShown( aPin ) ) return; @@ -993,6 +983,7 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ) { switch( aPin->GetShape() ) { + default: case GRAPHIC_PINSHAPE::LINE: m_gal->DrawLine( p0, pos ); break; @@ -1091,22 +1082,17 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ) } } - const SYMBOL* libEntry = aPin->GetParentSymbol(); + if( drawingShadows && !eeconfig()->m_Selection.draw_selected_children ) + return; // Draw the labels - - if( libEntry->Type() == LIB_SYMBOL_T ) - { - if( drawingShadows && !eeconfig()->m_Selection.draw_selected_children ) - return; - } - - float penWidth = (float) m_schSettings.GetDefaultPenWidth(); - int textOffset = libEntry->GetPinNameOffset(); - float nameStrokeWidth = getLineWidth( aPin, false ); - float numStrokeWidth = getLineWidth( aPin, false ); - bool showPinNames = libEntry->GetShowPinNames(); - bool showPinNumbers = m_schSettings.m_ShowPinNumbers || libEntry->GetShowPinNumbers(); + const SYMBOL* symbol = aPin->GetParentSymbol(); + float penWidth = (float) m_schSettings.GetDefaultPenWidth(); + int textOffset = symbol->GetPinNameOffset(); + float nameStrokeWidth = getLineWidth( aPin, false ); + float numStrokeWidth = getLineWidth( aPin, false ); + bool showPinNames = symbol->GetShowPinNames(); + bool showPinNumbers = m_schSettings.m_ShowPinNumbers || symbol->GetShowPinNumbers(); nameStrokeWidth = Clamp_Text_PenSize( nameStrokeWidth, aPin->GetNameTextSize(), true ); numStrokeWidth = Clamp_Text_PenSize( numStrokeWidth, aPin->GetNumberTextSize(), true ); @@ -1245,12 +1231,12 @@ void SCH_PAINTER::draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ) else if( nonCached( aPin ) && renderTextAsBitmap ) { bitmapText( text[i], aPos, attrs ); - const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); + const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); } else { strokeText( text[i], aPos, attrs, aPin->GetFontMetrics() ); - const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); + const_cast( aPin )->SetFlags( IS_SHOWN_AS_BITMAP ); } }; @@ -1695,14 +1681,13 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed ) switch( aText->Type() ) { - case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break; - case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break; - case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break; - case SCH_DIRECTIVE_LABEL_T: aLayer = LAYER_NETCLASS_REFS; break; - case SCH_TEXT_T: - aLayer = IsItemFPMember( aText ) ? LAYER_DEVICE : LAYER_NOTES; - break; - default: aLayer = LAYER_NOTES; break; + case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break; + case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break; + case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break; + case SCH_DIRECTIVE_LABEL_T: aLayer = LAYER_NETCLASS_REFS; break; + case SCH_TEXT_T: aLayer = aText->GetParentSymbol() ? LAYER_DEVICE + : LAYER_NOTES; break; + default: aLayer = LAYER_NOTES; break; } COLOR4D color = getRenderColor( aText, aLayer, drawingShadows, aDimmed ); @@ -2259,13 +2244,11 @@ void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer ) : dummy(); bool invertY = true; - std::vector originalPins; - originalSymbol->GetPins( originalPins, unit, bodyStyle ); + std::vector originalPins = originalSymbol->GetPins( unit, bodyStyle ); // Copy the source so we can re-orient and translate it. - LIB_SYMBOL tempSymbol( *originalSymbol ); - std::vector tempPins; - tempSymbol.GetPins( tempPins, unit, bodyStyle ); + LIB_SYMBOL tempSymbol( *originalSymbol ); + std::vector tempPins = tempSymbol.GetPins( unit, bodyStyle ); tempSymbol.SetFlags( aSymbol->GetFlags() ); @@ -2296,7 +2279,7 @@ void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer ) for( unsigned i = 0; i < tempPins.size(); ++ i ) { SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] ); - LIB_PIN* tempPin = tempPins[ i ]; + SCH_PIN* tempPin = tempPins[ i ]; tempPin->ClearFlags(); tempPin->SetFlags( symbolPin->GetFlags() ); // SELECTED, HIGHLIGHTED, BRIGHTENED, @@ -2319,7 +2302,7 @@ void SCH_PAINTER::draw( const SCH_SYMBOL* aSymbol, int aLayer ) for( unsigned i = 0; i < tempPins.size(); ++i ) { SCH_PIN* symbolPin = aSymbol->GetPin( originalPins[ i ] ); - LIB_PIN* tempPin = tempPins[ i ]; + SCH_PIN* tempPin = tempPins[ i ]; symbolPin->ClearFlags(); tempPin->ClearFlags( IS_DANGLING ); // Clear this temporary flag diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 8529acc5cc..ee4f34efd8 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -33,7 +33,7 @@ #include -class LIB_PIN; +class SCH_PIN; class LIB_SYMBOL; class SCH_SYMBOL; class SCH_FIELD; @@ -80,7 +80,7 @@ public: private: void drawItemBoundingBox( const EDA_ITEM* aItem ); void draw( const EDA_ITEM*, int, bool aDimmed ); - void draw( const LIB_PIN* aPin, int aLayer, bool aDimmed ); + void draw( const SCH_PIN* aPin, int aLayer, bool aDimmed ); void draw( const LIB_SYMBOL* aSymbol, int, bool aDrawFields = true, int aUnit = 0, int aBodyStyle = 0, bool aDimmed = false ); void draw( const SCH_SYMBOL* aSymbol, int aLayer ); @@ -106,8 +106,8 @@ private: void drawDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor, int aWidth, bool aDangling, bool aDrawingShadows, bool aBrightened ); - int internalPinDecoSize( const LIB_PIN &aPin ); - int externalPinDecoSize( const LIB_PIN &aPin ); + int internalPinDecoSize( const SCH_PIN &aPin ); + int externalPinDecoSize( const SCH_PIN &aPin ); // Indicates the item is drawn on a non-cached layer in OpenGL bool nonCached( const EDA_ITEM* aItem ); @@ -115,11 +115,11 @@ private: bool isUnitAndConversionShown( const SCH_ITEM* aItem ) const; float getShadowWidth( bool aForHighlight ) const; - COLOR4D getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDrawingShadows, + COLOR4D getRenderColor( const SCH_ITEM* aItem, int aLayer, bool aDrawingShadows, bool aDimmed = false ) const; KIFONT::FONT* getFont( const EDA_TEXT* aText ) const; - float getLineWidth( const EDA_ITEM* aItem, bool aDrawingShadows ) const; - float getTextThickness( const EDA_ITEM* aItem ) const; + float getLineWidth( const SCH_ITEM* aItem, bool aDrawingShadows ) const; + float getTextThickness( const SCH_ITEM* aItem ) const; int getOperatingPointTextSize() const; diff --git a/eeschema/sch_pin.cpp b/eeschema/sch_pin.cpp index ca2d0fb436..f98d65688c 100644 --- a/eeschema/sch_pin.cpp +++ b/eeschema/sch_pin.cpp @@ -1,8 +1,10 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * + * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2015 Wayne Stambaugh * Copyright (C) 2018 CERN - * Copyright (C) 2019-2024 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software; you can redistribute it and/or @@ -15,58 +17,197 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #include -#include -#include -#include -#include -#include -#include +#include +#include #include -#include "string_utils.h" +#include +#include +#include +#include +#include +#include +#include "sch_painter.h" +#include "plotters/plotter.h" -SCH_PIN::SCH_PIN( LIB_PIN* aLibPin, SCH_SYMBOL* aParentSymbol ) : - SCH_ITEM( aParentSymbol, SCH_PIN_T ) + +// small margin in internal units between the pin text and the pin line +#define PIN_TEXT_MARGIN 4 + +const wxString SCH_PIN::GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType ) +{ + // These strings are the canonical name of the electrictal type + // Not translated, no space in name, only ASCII chars. + // to use when the string name must be known and well defined + // must have same order than enum ELECTRICAL_PINTYPE (see sch_pin.h) + static const wxChar* msgPinElectricType[] = + { + wxT( "input" ), + wxT( "output" ), + wxT( "bidirectional" ), + wxT( "tri_state" ), + wxT( "passive" ), + wxT( "free" ), + wxT( "unspecified" ), + wxT( "power_in" ), + wxT( "power_out" ), + wxT( "open_collector" ), + wxT( "open_emitter" ), + wxT( "no_connect" ) + }; + + return msgPinElectricType[static_cast( aType )]; +} + + +/// Utility for getting the size of the 'internal' pin decorators (as a radius) +// i.e. the clock symbols (falling clock is actually external but is of +// the same kind) + +static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin ) +{ + const SCH_RENDER_SETTINGS* settings = static_cast( aSettings ); + + if( settings && settings->m_PinSymbolSize ) + return settings->m_PinSymbolSize; + + return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2; +} + +/// Utility for getting the size of the 'external' pin decorators (as a radius) +// i.e. the negation circle, the polarity 'slopes' and the nonlogic +// marker +static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin ) +{ + const SCH_RENDER_SETTINGS* settings = static_cast( aSettings ); + + if( settings && settings->m_PinSymbolSize ) + return settings->m_PinSymbolSize; + + return aPin.GetNumberTextSize() / 2; +} + + +SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol ) : + SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ), + m_libPin( nullptr ), + m_position( { 0, 0 } ), + m_orientation( PIN_ORIENTATION::PIN_RIGHT ), + m_shape( GRAPHIC_PINSHAPE::LINE ), + m_type( ELECTRICAL_PINTYPE::PT_UNSPECIFIED ), + m_attributes( 0 ), + m_isDangling( true ) +{ + // Use the application settings for pin sizes if exists. + // pgm can be nullptr when running a shared lib from a script, not from a kicad appl + PGM_BASE* pgm = PgmOrNull(); + + if( pgm ) + { + auto* settings = pgm->GetSettingsManager().GetAppSettings(); + m_length = schIUScale.MilsToIU( settings->m_Defaults.pin_length ); + m_numTextSize = schIUScale.MilsToIU( settings->m_Defaults.pin_num_size ); + m_nameTextSize = schIUScale.MilsToIU( settings->m_Defaults.pin_name_size ); + } + else // Use hardcoded eeschema defaults: symbol_editor settings are not existing. + { + m_length = schIUScale.MilsToIU( DEFAULT_PIN_LENGTH ); + m_numTextSize = schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE ); + m_nameTextSize = schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE ); + } + + m_layer = LAYER_DEVICE; +} + + +SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol, const wxString& aName, const wxString& aNumber, + PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, + int aNameTextSize, int aNumTextSize, int aBodyStyle, const VECTOR2I& aPos, + int aUnit ) : + SCH_ITEM( aParentSymbol, SCH_PIN_T, aUnit, aBodyStyle ), + m_libPin( nullptr ), + m_position( aPos ), + m_length( aLength ), + m_orientation( aOrientation ), + m_shape( GRAPHIC_PINSHAPE::LINE ), + m_type( aPinType ), + m_attributes( 0 ), + m_numTextSize( aNumTextSize ), + m_nameTextSize( aNameTextSize ), + m_isDangling( true ) +{ + SetName( aName ); + SetNumber( aNumber ); + + m_layer = LAYER_DEVICE; +} + + +SCH_PIN::SCH_PIN( SCH_PIN* aLibPin, SCH_SYMBOL* aParentSymbol ) : + SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ), + m_libPin( aLibPin ), + m_orientation( PIN_ORIENTATION::INHERIT ), + m_shape( GRAPHIC_PINSHAPE::INHERIT ), + m_type( ELECTRICAL_PINTYPE::PT_INHERIT ), + m_isDangling( true ) { wxASSERT( aParentSymbol ); + + SetName( m_libPin->GetName() ); + SetNumber( m_libPin->GetNumber() ); + SetPosition( m_libPin->GetPosition() ); + m_layer = LAYER_PIN; - m_alt = wxEmptyString; - m_number = aLibPin->GetNumber(); - m_libPin = aLibPin; - SetPosition( aLibPin->GetPosition() ); - m_isDangling = true; } /** * Create a proxy pin from an alternate pin designation. - * The LIB_PIN data will be filled in when the pin is resolved (see SCH_SYMBOL::UpdatePins). + * The SCH_PIN data will be filled in when the pin is resolved (see SCH_SYMBOL::UpdatePins). */ SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt ) : - SCH_ITEM( aParentSymbol, SCH_PIN_T ) + SCH_ITEM( aParentSymbol, SCH_PIN_T ), + m_libPin( nullptr ), + m_length( 0 ), + m_orientation( PIN_ORIENTATION::INHERIT ), + m_shape( GRAPHIC_PINSHAPE::INHERIT ), + m_type( ELECTRICAL_PINTYPE::PT_INHERIT ), + m_attributes( 0 ), + m_number( aNumber ), + m_alt( aAlt ), + m_isDangling( true ) { wxASSERT( aParentSymbol ); + m_layer = LAYER_PIN; - m_alt = aAlt; - m_number = aNumber; - m_libPin = nullptr; - m_isDangling = true; } SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) : - SCH_ITEM( aPin ) + SCH_ITEM( aPin ), + m_libPin( aPin.m_libPin ), + m_position( aPin.m_position ), + m_length( aPin.m_length ), + m_orientation( aPin.m_orientation ), + m_shape( aPin.m_shape ), + m_type( aPin.m_type ), + m_attributes( aPin.m_attributes ), + m_numTextSize( aPin.m_numTextSize ), + m_nameTextSize( aPin.m_nameTextSize ), + m_isDangling( aPin.m_isDangling ) { + SetName( aPin.m_name ); + SetNumber( aPin.m_number ); + m_layer = aPin.m_layer; - m_alt = aPin.m_alt; - m_number = aPin.m_number; - m_libPin = aPin.m_libPin; - m_position = aPin.m_position; - m_isDangling = aPin.m_isDangling; } @@ -74,107 +215,43 @@ SCH_PIN& SCH_PIN::operator=( const SCH_PIN& aPin ) { SCH_ITEM::operator=( aPin ); - m_alt = aPin.m_alt; - m_number = aPin.m_number; m_libPin = aPin.m_libPin; + m_alt = aPin.m_alt; + m_name = aPin.m_name; + m_number = aPin.m_number; m_position = aPin.m_position; + m_length = aPin.m_length; + m_orientation = aPin.m_orientation; + m_shape = aPin.m_shape; + m_type = aPin.m_type; + m_attributes = aPin.m_attributes; + m_numTextSize = aPin.m_numTextSize; + m_nameTextSize = aPin.m_nameTextSize; m_isDangling = aPin.m_isDangling; return *this; } -bool SCH_PIN::IsVisible() const +VECTOR2I SCH_PIN::GetPosition() const { - wxCHECK( m_libPin, false ); - - return m_libPin->IsVisible(); -} - - -wxString SCH_PIN::GetName() const -{ - if( !m_alt.IsEmpty() ) - return m_alt; - - return m_libPin ? m_libPin->GetName() : wxString( "??" ); -} - - -wxString SCH_PIN::GetShownName() const -{ - wxString name = m_libPin ? m_libPin->GetName() : wxString( "??" ); - - if( !m_alt.IsEmpty() ) - name = m_alt; - - if( name == wxS( "~" ) ) - return wxEmptyString; + if( const SCH_SYMBOL* symbol = dynamic_cast( GetParentSymbol() ) ) + return symbol->GetTransform().TransformCoordinate( m_position ) + symbol->GetPosition(); else - return name; + return m_position; } - -wxString SCH_PIN::GetShownNumber() const +bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const { - if( m_number == wxS( "~" ) ) - return wxEmptyString; - else - return m_number; -} + bool isConnectableType_a = GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE + || GetType() == ELECTRICAL_PINTYPE::PT_NIC; + bool isConnectableType_b = aPin->GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE + || aPin->GetType() == ELECTRICAL_PINTYPE::PT_NIC; - -ELECTRICAL_PINTYPE SCH_PIN::GetType() const -{ - wxCHECK( m_libPin, ELECTRICAL_PINTYPE::PT_NC ); - - if( !m_alt.IsEmpty() ) - return m_libPin->GetAlt( m_alt ).m_Type; - - return m_libPin->GetType(); -} - - -GRAPHIC_PINSHAPE SCH_PIN::GetShape() const -{ - wxCHECK( m_libPin, GRAPHIC_PINSHAPE::LINE ); - - if( !m_alt.IsEmpty() ) - return m_libPin->GetAlt( m_alt ).m_Shape; - - return m_libPin->GetShape(); -} - - -PIN_ORIENTATION SCH_PIN::GetOrientation() const -{ - wxCHECK( m_libPin, PIN_ORIENTATION::PIN_RIGHT ); - - return m_libPin->GetOrientation(); -} - - -int SCH_PIN::GetLength() const -{ - wxCHECK( m_libPin, 0 ); - - return m_libPin->GetLength(); -} - - -const BOX2I SCH_PIN::ViewBBox() const -{ - return GetBoundingBox( false, true, true ); -} - - -void SCH_PIN::ViewGetLayers( int aLayers[], int& aCount ) const -{ - aCount = 4; - aLayers[0] = LAYER_DANGLING; - aLayers[1] = LAYER_DEVICE; - aLayers[2] = LAYER_SELECTION_SHADOWS; - aLayers[3] = LAYER_OP_CURRENTS; + return m_parent == aPin->GetParent() + && GetPosition() == aPin->GetPosition() + && GetName() == aPin->GetName() + && ( GetType() == aPin->GetType() || isConnectableType_a || isConnectableType_b ); } @@ -204,66 +281,1133 @@ bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) } -wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const +bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const { - LIB_PIN::ALT localStorage; - LIB_PIN::ALT* alt = nullptr; + // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has + // no pin number or name. Give it a floor. + if( Schematic() ) + aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 ); - if( !m_alt.IsEmpty() && m_libPin ) + BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ); + + return rect.Inflate( aAccuracy ).Contains( aPosition ); +} + + +bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const +{ + if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) ) + return false; + + BOX2I sel = aRect; + + if ( aAccuracy ) + sel.Inflate( aAccuracy ); + + if( aContained ) + return sel.Contains( GetBoundingBox( false, false, false ) ); + + return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) ); +} + + +wxString SCH_PIN::GetShownName() const +{ + if( !m_alt.IsEmpty() ) + return m_alt; + else if( m_libPin ) + return m_libPin->GetShownName(); + + if( m_name == wxS( "~" ) ) + return wxEmptyString; + else + return m_name; +} + + +wxString SCH_PIN::GetShownNumber() const +{ + if( m_number == wxS( "~" ) ) + return wxEmptyString; + else + return m_number; +} + + +VECTOR2I SCH_PIN::GetPinRoot() const +{ + int length = GetLength(); + + switch( GetOrientation() ) { - localStorage = m_libPin->GetAlt( m_alt ); - alt = &localStorage; + default: + case PIN_ORIENTATION::PIN_RIGHT: return VECTOR2I( m_position.x + length, -( m_position.y ) ); + case PIN_ORIENTATION::PIN_LEFT: return VECTOR2I( m_position.x - length, -( m_position.y ) ); + case PIN_ORIENTATION::PIN_UP: return VECTOR2I( m_position.x, -( m_position.y + length ) ); + case PIN_ORIENTATION::PIN_DOWN: return VECTOR2I( m_position.x, -( m_position.y - length ) ); + } +} + + +void SCH_PIN::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle, + const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) +{ + LIB_SYMBOL* part = dynamic_cast( GetParentSymbol() ); + + wxCHECK( part && aSettings, /* void */ ); + + /* Calculate pin orient taking in account the symbol orientation. */ + PIN_ORIENTATION orient = PinDrawOrient( aSettings->m_Transform ); + + /* Calculate the pin position */ + VECTOR2I pos1 = aSettings->TransformCoordinate( m_position ) + aOffset; + + if( IsVisible() || aSettings->m_ShowHiddenFields ) + { + printPinSymbol( aSettings, pos1, orient, aDimmed ); + + printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(), + aSettings->m_ShowPinNumbers || part->GetShowPinNumbers(), + aSettings->m_ShowPinNames || part->GetShowPinNames(), + aDimmed ); + + if( aSettings->m_ShowPinElectricalTypes ) + printPinElectricalTypeName( aSettings, pos1, orient, aDimmed ); + + if( aSettings->m_ShowConnectionPoints + && m_type != ELECTRICAL_PINTYPE::PT_NC + && m_type != ELECTRICAL_PINTYPE::PT_NIC ) + { + wxDC* DC = aSettings->GetPrintDC(); + COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN ); + + COLOR4D bg = aSettings->GetBackgroundColor(); + + if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) + bg = COLOR4D::WHITE; + + if( aDimmed ) + { + color.Desaturate( ); + color = color.Mix( bg, 0.5f ); + } + + GRCircle( DC, pos1, TARGET_PIN_RADIUS, 0, color ); + } + } +} + + +void SCH_PIN::printPinSymbol( const SCH_RENDER_SETTINGS* aSettings, const VECTOR2I& aPos, + PIN_ORIENTATION aOrientation, bool aDimmed ) +{ + wxDC* DC = aSettings->GetPrintDC(); + int MapX1, MapY1, x1, y1; + int width = GetEffectivePenWidth( aSettings ); + int posX = aPos.x; + int posY = aPos.y; + int len = GetLength(); + COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PIN : LAYER_HIDDEN ); + COLOR4D bg = aSettings->GetBackgroundColor(); + + if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) + bg = COLOR4D::WHITE; + + if( !IsVisible() ) + bg = aSettings->GetLayerColor( LAYER_HIDDEN ); + + if( aDimmed ) + { + color.Desaturate( ); + color = color.Mix( bg, 0.5f ); } - wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt ) : - wxString( wxS( "Undefined library pin." ) ); + MapX1 = MapY1 = 0; + x1 = posX; + y1 = posY; - const SCH_SYMBOL* symbol = static_cast( GetParentSymbol() ); + switch( aOrientation ) + { + case PIN_ORIENTATION::PIN_UP: y1 = posY - len; MapY1 = 1; break; + case PIN_ORIENTATION::PIN_DOWN: y1 = posY + len; MapY1 = -1; break; + case PIN_ORIENTATION::PIN_LEFT: x1 = posX - len; MapX1 = 1; break; + case PIN_ORIENTATION::PIN_RIGHT: x1 = posX + len; MapX1 = -1; break; + case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break; + } - return wxString::Format( "Symbol %s %s", - UnescapeString( symbol->GetField( REFERENCE_FIELD )->GetText() ), - itemDesc ); + if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK ) + { + const int radius = externalPinDecoSize( aSettings, *this ); + GRCircle( DC, VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius, width, color ); + + GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ); + GRLineTo( DC, posX, posY, width, color ); + } + else + { + GRMoveTo( x1, y1 ); + GRLineTo( DC, posX, posY, width, color ); + } + + // Draw the clock shape (>)inside the symbol + if( m_shape == GRAPHIC_PINSHAPE::CLOCK + || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK + || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK + || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) + { + const int clock_size = internalPinDecoSize( aSettings, *this ); + if( MapY1 == 0 ) /* MapX1 = +- 1 */ + { + GRMoveTo( x1, y1 + clock_size ); + GRLineTo( DC, x1 - MapX1 * clock_size * 2, y1, width, color ); + GRLineTo( DC, x1, y1 - clock_size, width, color ); + } + else /* MapX1 = 0 */ + { + GRMoveTo( x1 + clock_size, y1 ); + GRLineTo( DC, x1, y1 - MapY1 * clock_size * 2, width, color ); + GRLineTo( DC, x1 - clock_size, y1, width, color ); + } + } + + // Draw the active low (or H to L active transition) + if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW + || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK + || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) + { + const int deco_size = externalPinDecoSize( aSettings, *this ); + if( MapY1 == 0 ) /* MapX1 = +- 1 */ + { + GRMoveTo( x1 + MapX1 * deco_size * 2, y1 ); + GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color ); + GRLineTo( DC, x1, y1, width, color ); + } + else /* MapX1 = 0 */ + { + GRMoveTo( x1, y1 + MapY1 * deco_size * 2 ); + GRLineTo( DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color ); + GRLineTo( DC, x1, y1, width, color ); + } + } + + if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */ + { + const int deco_size = externalPinDecoSize( aSettings, *this ); + if( MapY1 == 0 ) /* MapX1 = +- 1 */ + { + GRMoveTo( x1, y1 - deco_size * 2 ); + GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1, width, color ); + } + else /* MapX1 = 0 */ + { + GRMoveTo( x1 - deco_size * 2, y1 ); + GRLineTo( DC, x1, y1 + MapY1 * deco_size * 2, width, color ); + } + } + else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */ + { + const int deco_size = externalPinDecoSize( aSettings, *this ); + GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size ); + GRLineTo( DC, x1 + (MapX1 + MapY1) * deco_size, y1 + ( MapY1 - MapX1 ) * deco_size, width, + color ); + GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size ); + GRLineTo( DC, x1 + (MapX1 - MapY1) * deco_size, y1 + ( MapY1 + MapX1 ) * deco_size, width, + color ); + } + + if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol + { + const int deco_size = TARGET_PIN_RADIUS; + GRLine( DC, posX - deco_size, posY - deco_size, posX + deco_size, posY + deco_size, width, + color ); + GRLine( DC, posX + deco_size, posY - deco_size, posX - deco_size, posY + deco_size, width, + color ); + } +} + + +void SCH_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, const VECTOR2I& aPinPos, + PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, + bool aDrawPinName, bool aDimmed ) +{ + if( !aDrawPinName && !aDrawPinNum ) + return; + + KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false ); + wxString name = GetShownName(); + wxString number = GetShownNumber(); + VECTOR2I nameSize( GetNameTextSize(), GetNameTextSize() ); + VECTOR2I numSize( GetNumberTextSize(), GetNumberTextSize() ); + int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ); + int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ); + + /* Get the num and name colors */ + COLOR4D nameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN ); + COLOR4D numColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN ); + COLOR4D bg = aSettings->GetBackgroundColor(); + + if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) + bg = COLOR4D::WHITE; + + if( !IsVisible() ) + bg = aSettings->GetLayerColor( LAYER_HIDDEN ); + + if( aDimmed ) + { + nameColor.Desaturate(); + numColor.Desaturate(); + nameColor = nameColor.Mix( bg, 0.5f ); + numColor = numColor.Mix( bg, 0.5f ); + } + + int x1 = aPinPos.x; + int y1 = aPinPos.y; + + switch( aPinOrient ) + { + case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break; + case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break; + case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break; + case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break; + case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxT( "aPinOrient must be resolved!" ) ); break; + } + + if( name.IsEmpty() || m_nameTextSize == 0 ) + aDrawPinName = false; + + if( number.IsEmpty() || m_numTextSize == 0 ) + aDrawPinNum = false; + + auto printName = + [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign, + enum GR_TEXT_V_ALIGN_T vAlign ) + { + GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), nameColor, name, angle, + nameSize, hAlign, vAlign, 0, false, false, font, GetFontMetrics() ); + }; + + auto printNum = + [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign, + enum GR_TEXT_V_ALIGN_T vAlign ) + { + GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), numColor, number, angle, + numSize, hAlign, vAlign, 0, false, false, font, GetFontMetrics() ); + }; + + if( aTextInside ) // Draw the text inside, but the pin numbers outside. + { + if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) + || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) + { + // It is an horizontal line + if( aDrawPinName ) + { + if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) + { + printName( x1 + aTextInside, y1, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); + } + else // Orient == PIN_LEFT + { + printName( x1 - aTextInside, y1, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); + } + } + + if( aDrawPinNum ) + { + printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + else /* Its a vertical line. */ + { + // Text is drawn from bottom to top (i.e. to negative value for Y axis) + if( aPinOrient == PIN_ORIENTATION::PIN_DOWN ) + { + if( aDrawPinName ) + { + printName( x1, y1 + aTextInside, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); + } + + if( aDrawPinNum ) + { + printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + else /* PIN_UP */ + { + if( aDrawPinName ) + { + printName( x1, y1 - aTextInside, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); + } + + if( aDrawPinNum ) + { + printNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + } + } + else /**** Draw num & text pin outside ****/ + { + if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) + || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) + { + /* Its an horizontal line. */ + if( aDrawPinName && aDrawPinNum ) + { + printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + + printNum( ( x1 + aPinPos.x ) / 2, y1 + num_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); + } + else if( aDrawPinName ) + { + printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + else if( aDrawPinNum ) + { + printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + else /* Its a vertical line. */ + { + if( aDrawPinName && aDrawPinNum ) + { + printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + + printNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); + } + else if( aDrawPinName ) + { + printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + else if( aDrawPinNum ) + { + printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + } +} + + +void SCH_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, + const VECTOR2I& aPosition, PIN_ORIENTATION aOrientation, + bool aDimmed ) +{ + wxDC* DC = aSettings->GetPrintDC(); + wxString typeName = GetElectricalTypeName(); + + // Use a reasonable (small) size to draw the text + int textSize = ( GetNameTextSize() * 3 ) / 4; + + #define ETXT_MAX_SIZE schIUScale.mmToIU( 0.7 ) + + if( textSize > ETXT_MAX_SIZE ) + textSize = ETXT_MAX_SIZE; + + // Use a reasonable pen size to draw the text + int pensize = textSize/6; + + // Get a suitable color + COLOR4D color = aSettings->GetLayerColor( IsVisible() ? LAYER_PRIVATE_NOTES : LAYER_HIDDEN ); + COLOR4D bg = aSettings->GetBackgroundColor(); + + if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() ) + bg = COLOR4D::WHITE; + + if( !IsVisible() ) + bg = aSettings->GetLayerColor( LAYER_HIDDEN ); + + if( aDimmed ) + { + color.Desaturate( ); + color = color.Mix( bg, 0.5f ); + } + + VECTOR2I txtpos = aPosition; + int offset = schIUScale.mmToIU( 0.4 ); + GR_TEXT_H_ALIGN_T hjustify = GR_TEXT_H_ALIGN_LEFT; + EDA_ANGLE orient = ANGLE_HORIZONTAL; + KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false ); + + switch( aOrientation ) + { + case PIN_ORIENTATION::PIN_UP: + txtpos.y += offset; + orient = ANGLE_VERTICAL; + hjustify = GR_TEXT_H_ALIGN_RIGHT; + break; + + case PIN_ORIENTATION::PIN_DOWN: + txtpos.y -= offset; + orient = ANGLE_VERTICAL; + break; + + case PIN_ORIENTATION::PIN_LEFT: + txtpos.x += offset; + break; + + case PIN_ORIENTATION::PIN_RIGHT: + txtpos.x -= offset; + hjustify = GR_TEXT_H_ALIGN_RIGHT; + break; + + case PIN_ORIENTATION::INHERIT: + wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); + break; + } + + GRPrintText( DC, txtpos, color, typeName, orient, VECTOR2I( textSize, textSize ), hjustify, + GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font, GetFontMetrics() ); +} + + +void SCH_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition, + PIN_ORIENTATION aOrientation, bool aDimmed ) const +{ + int MapX1, MapY1, x1, y1; + SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter ); + COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN ); + COLOR4D bg = renderSettings->GetBackgroundColor(); + int penWidth = GetEffectivePenWidth( renderSettings ); + int pinLength = GetLength(); + + if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() ) + bg = COLOR4D::WHITE; + + if( aDimmed ) + { + color.Desaturate( ); + color = color.Mix( bg, 0.5f ); + } + + aPlotter->SetColor( color ); + aPlotter->SetCurrentLineWidth( penWidth ); + + MapX1 = MapY1 = 0; + x1 = aPosition.x; y1 = aPosition.y; + + switch( aOrientation ) + { + case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - pinLength; MapY1 = 1; break; + case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + pinLength; MapY1 = -1; break; + case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - pinLength; MapX1 = 1; break; + case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + pinLength; MapX1 = -1; break; + case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break; + } + + if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK ) + { + const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this ); + aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2, + FILL_T::NO_FILL, penWidth ); + + aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) ); + aPlotter->FinishTo( aPosition ); + } + else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK ) + { + const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this ); + if( MapY1 == 0 ) /* MapX1 = +- 1 */ + { + aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) ); + aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) ); + aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) ); + } + else /* MapX1 = 0 */ + { + aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) ); + aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) ); + aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) ); + } + + aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) ); + aPlotter->FinishTo( aPosition ); + } + else + { + aPlotter->MoveTo( VECTOR2I( x1, y1 ) ); + aPlotter->FinishTo( aPosition ); + } + + if( m_shape == GRAPHIC_PINSHAPE::CLOCK + || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK + || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) + { + const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this ); + if( MapY1 == 0 ) /* MapX1 = +- 1 */ + { + aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) ); + aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) ); + aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) ); + } + else /* MapX1 = 0 */ + { + aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) ); + aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) ); + aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) ); + } + } + + if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW + || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */ + { + const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this ); + + if( MapY1 == 0 ) /* MapX1 = +- 1 */ + { + aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) ); + aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) ); + aPlotter->FinishTo( VECTOR2I( x1, y1 ) ); + } + else /* MapX1 = 0 */ + { + aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) ); + aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) ); + aPlotter->FinishTo( VECTOR2I( x1, y1 ) ); + } + } + + if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */ + { + const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this ); + + if( MapY1 == 0 ) /* MapX1 = +- 1 */ + { + aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) ); + aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) ); + } + else /* MapX1 = 0 */ + { + aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) ); + aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) ); + } + } + else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */ + { + const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this ); + aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size, + y1 - ( MapY1 - MapX1 ) * deco_size ) ); + aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size, + y1 + ( MapY1 - MapX1 ) * deco_size ) ); + aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size, + y1 - ( MapY1 + MapX1 ) * deco_size ) ); + aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size, + y1 + ( MapY1 + MapX1 ) * deco_size ) ); + } + + if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol + { + const int deco_size = TARGET_PIN_RADIUS; + const int ex1 = aPosition.x; + const int ey1 = aPosition.y; + aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) ); + aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) ); + aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) ); + aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) ); + } +} + + +void SCH_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, + int aTextInside, bool aDrawPinNum, bool aDrawPinName, + bool aDimmed ) const +{ + RENDER_SETTINGS* settings = aPlotter->RenderSettings(); + KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false ); + wxString name = GetShownName(); + wxString number = GetShownNumber(); + + if( name.IsEmpty() || m_nameTextSize == 0 ) + aDrawPinName = false; + + if( number.IsEmpty() || m_numTextSize == 0 ) + aDrawPinNum = false; + + if( !aDrawPinNum && !aDrawPinName ) + return; + + int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ); + int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ); + + /* Get the num and name colors */ + COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM ); + COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM ); + COLOR4D bg = settings->GetBackgroundColor(); + + if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() ) + bg = COLOR4D::WHITE; + + if( aDimmed ) + { + nameColor.Desaturate( ); + numColor.Desaturate( ); + nameColor = nameColor.Mix( bg, 0.5f ); + numColor = numColor.Mix( bg, 0.5f ); + } + + int x1 = aPinPos.x; + int y1 = aPinPos.y; + + switch( aPinOrient ) + { + case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break; + case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break; + case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break; + case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break; + case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aPinOrient must be resolved!" ) ); break; + } + + auto plotName = + [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify, + GR_TEXT_V_ALIGN_T vJustify ) + { + TEXT_ATTRIBUTES attrs; + attrs.m_Angle = angle; + attrs.m_Size = VECTOR2I( GetNameTextSize(), GetNameTextSize() ); + attrs.m_Halign = hJustify; + attrs.m_Valign = vJustify; + attrs.m_Multiline = false; + + aPlotter->PlotText( VECTOR2I( x, y ), nameColor, name, attrs, font, GetFontMetrics() ); + }; + + auto plotNum = + [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify, + GR_TEXT_V_ALIGN_T vJustify ) + { + TEXT_ATTRIBUTES attrs; + attrs.m_Angle = angle; + attrs.m_Size = VECTOR2I( GetNumberTextSize(), GetNumberTextSize() ); + attrs.m_Halign = hJustify; + attrs.m_Valign = vJustify; + attrs.m_Multiline = false; + + aPlotter->PlotText( VECTOR2I( x, y ), numColor, number, attrs, font, GetFontMetrics() ); + }; + + /* Draw the text inside, but the pin numbers outside. */ + if( aTextInside ) + { + if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) + || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) /* Its an horizontal line. */ + { + if( aDrawPinName ) + { + if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) + { + plotName( x1 + aTextInside, y1, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); + } + else // orient == PIN_LEFT + { + plotName( x1 - aTextInside, y1, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); + } + } + + if( aDrawPinNum ) + { + plotNum( ( x1 + aPinPos.x) / 2, y1 - num_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + else /* Its a vertical line. */ + { + if( aPinOrient == PIN_ORIENTATION::PIN_DOWN ) + { + if( aDrawPinName ) + { + plotName( x1, y1 + aTextInside, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER ); + } + + if( aDrawPinNum ) + { + plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + else /* PIN_UP */ + { + if( aDrawPinName ) + { + plotName( x1, y1 - aTextInside, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_CENTER ); + } + + if( aDrawPinNum ) + { + plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + } + } + else /* Draw num & text pin outside */ + { + if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT ) + || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) + { + /* Its an horizontal line. */ + if( aDrawPinName && aDrawPinNum ) + { + plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + + plotNum( ( x1 + aPinPos.x) / 2, y1 + num_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); + } + else if( aDrawPinName ) + { + plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + else if( aDrawPinNum ) + { + plotNum( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + else + { + /* Its a vertical line. */ + if( aDrawPinName && aDrawPinNum ) + { + plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + + plotNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_TOP ); + } + else if( aDrawPinName ) + { + plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + else if( aDrawPinNum ) + { + plotNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL, + GR_TEXT_H_ALIGN_CENTER, GR_TEXT_V_ALIGN_BOTTOM ); + } + } + } +} + + +PIN_ORIENTATION SCH_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const +{ + PIN_ORIENTATION orient; + VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1 + + switch( GetOrientation() ) + { + default: + case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break; + case PIN_ORIENTATION::PIN_UP: end.y = 1; break; + case PIN_ORIENTATION::PIN_DOWN: end.y = -1; break; + case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break; + } + + // = pos of end point, according to the symbol orientation. + end = aTransform.TransformCoordinate( end ); + orient = PIN_ORIENTATION::PIN_UP; + + if( end.x == 0 ) + { + if( end.y > 0 ) + orient = PIN_ORIENTATION::PIN_DOWN; + } + else + { + orient = PIN_ORIENTATION::PIN_RIGHT; + + if( end.x < 0 ) + orient = PIN_ORIENTATION::PIN_LEFT; + } + + return orient; +} + + +EDA_ITEM* SCH_PIN::Clone() const +{ + //return new SCH_PIN( *this ); + SCH_ITEM* newPin = new SCH_PIN( *this ); + wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle ); + return newPin; +} + + +int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const +{ + wxASSERT( aOther.Type() == SCH_PIN_T ); + + int retv = SCH_ITEM::compare( aOther, aCompareFlags ); + + if( retv ) + return retv; + + const SCH_PIN* tmp = (SCH_PIN*) &aOther; + + // When comparing units, we do not compare the part numbers. If everything else is + // identical, then we can just renumber the parts for the inherited symbol. + if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number ) + return m_number.Cmp( tmp->m_number ); + + int result = m_name.Cmp( tmp->m_name ); + + if( result ) + return result; + + if( m_position.x != tmp->m_position.x ) + return m_position.x - tmp->m_position.x; + + if( m_position.y != tmp->m_position.y ) + return m_position.y - tmp->m_position.y; + + if( m_length != tmp->m_length ) + return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 ); + + if( m_orientation != tmp->m_orientation ) + return static_cast( m_orientation ) - static_cast( tmp->m_orientation ); + + if( m_shape != tmp->m_shape ) + return static_cast( m_shape ) - static_cast( tmp->m_shape ); + + if( m_type != tmp->m_type ) + return static_cast( m_type ) - static_cast( tmp->m_type ); + + if( m_attributes != tmp->m_attributes ) + return m_attributes - tmp->m_attributes; + + if( m_numTextSize != tmp->m_numTextSize ) + return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 ); + + if( m_nameTextSize != tmp->m_nameTextSize ) + return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 ); + + if( m_alternates.size() != tmp->m_alternates.size() ) + return (int) m_alternates.size() - tmp->m_alternates.size(); + + auto lhsItem = m_alternates.begin(); + auto rhsItem = tmp->m_alternates.begin(); + + while( lhsItem != m_alternates.end() ) + { + const ALT& lhsAlt = lhsItem->second; + const ALT& rhsAlt = rhsItem->second; + + retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name ); + + if( retv ) + return retv; + + if( lhsAlt.m_Type != rhsAlt.m_Type ) + return static_cast( lhsAlt.m_Type ) - static_cast( rhsAlt.m_Type ); + + if( lhsAlt.m_Shape != rhsAlt.m_Shape ) + return static_cast( lhsAlt.m_Shape ) - static_cast( rhsAlt.m_Shape ); + + ++lhsItem; + ++rhsItem; + } + + return 0; +} + +void SCH_PIN::ChangeLength( int aLength ) +{ + int lengthChange = GetLength() - aLength; + int offsetX = 0; + int offsetY = 0; + + switch( m_orientation ) + { + default: + case PIN_ORIENTATION::PIN_RIGHT: + offsetX = lengthChange; + break; + case PIN_ORIENTATION::PIN_LEFT: + offsetX = -1 * lengthChange; + break; + case PIN_ORIENTATION::PIN_UP: + offsetY = lengthChange; + break; + case PIN_ORIENTATION::PIN_DOWN: + offsetY = -1 * lengthChange; + break; + } + + m_position += VECTOR2I( offsetX, offsetY ); + m_length = aLength; +} + + +void SCH_PIN::Move( const VECTOR2I& aOffset ) +{ + m_position += aOffset; +} + + +void SCH_PIN::MirrorHorizontally( int aCenter ) +{ + if( dynamic_cast( GetParentSymbol() ) ) + { + m_position.x -= aCenter; + m_position.x *= -1; + m_position.x += aCenter; + + if( m_orientation == PIN_ORIENTATION::PIN_RIGHT ) + m_orientation = PIN_ORIENTATION::PIN_LEFT; + else if( m_orientation == PIN_ORIENTATION::PIN_LEFT ) + m_orientation = PIN_ORIENTATION::PIN_RIGHT; + } +} + + +void SCH_PIN::MirrorVertically( int aCenter ) +{ + if( dynamic_cast( GetParentSymbol() ) ) + { + m_position.y -= aCenter; + m_position.y *= -1; + m_position.y += aCenter; + + if( m_orientation == PIN_ORIENTATION::PIN_UP ) + m_orientation = PIN_ORIENTATION::PIN_DOWN; + else if( m_orientation == PIN_ORIENTATION::PIN_DOWN ) + m_orientation = PIN_ORIENTATION::PIN_UP; + } +} + + +void SCH_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) +{ + if( dynamic_cast( GetParentSymbol() ) ) + { + EDA_ANGLE rot_angle = aRotateCCW ? -ANGLE_90 : ANGLE_90; + + RotatePoint( m_position, aCenter, rot_angle ); + + if( aRotateCCW ) + { + switch( GetOrientation() ) + { + default: + case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_UP; break; + case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_LEFT; break; + case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break; + case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break; + } + } + else + { + switch( GetOrientation() ) + { + default: + case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break; + case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break; + case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_UP; break; + case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_LEFT; break; + } + } + } +} + + +void SCH_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, + int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) +{ + if( aBackground ) + return; + + SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter ); + + if( !IsVisible() && !renderSettings->m_ShowHiddenPins ) + return; + + const SYMBOL* part = GetParentSymbol(); + PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform ); + VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset; + + PlotPinType( aPlotter, pos, orient, aDimmed ); + PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(), + part->GetShowPinNames(), aDimmed ); } void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) { - wxString msg; - SCH_SYMBOL* symbol = static_cast( GetParentSymbol() ); + wxString msg; + SYMBOL* symbol = GetParentSymbol(); - aList.emplace_back( _( "Type" ), _( "Pin" ) ); - - if( symbol->GetUnitCount() ) + if( dynamic_cast( symbol ) ) { - msg = m_libPin ? GetUnitDescription( m_libPin->GetUnit() ) : - wxString( "Undefined library pin." ); - aList.emplace_back( _( "Unit" ), msg ); + getSymbolEditorMsgPanelInfo( aFrame, aList ); + } + else + { + aList.emplace_back( _( "Type" ), _( "Pin" ) ); + + if( symbol->GetUnitCount() ) + { + msg = m_libPin ? GetUnitDescription( m_libPin->GetUnit() ) : + wxString( "Undefined library pin." ); + aList.emplace_back( _( "Unit" ), msg ); + } + + if( symbol->HasAlternateBodyStyle() ) + { + msg = m_libPin ? GetBodyStyleDescription( m_libPin->GetBodyStyle() ) : + wxString( "Undefined library pin." ); + aList.emplace_back( _( "Body Style" ), msg ); + } } - if( symbol->HasAlternateBodyStyle() ) - { - msg = m_libPin ? GetBodyStyleDescription( m_libPin->GetBodyStyle() ) : - wxString( "Undefined library pin." ); - aList.emplace_back( _( "Body Style" ), msg ); - } - - aList.emplace_back( _( "Name" ), GetShownName() ); + aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) ); aList.emplace_back( _( "Number" ), GetShownNumber() ); - aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) ); - aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) ); + aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( m_type ) ); + aList.emplace_back( _( "Style" ), PinShapeGetText( m_shape ) ); aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) ); - aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength() ), true ); + // Display pin length + aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength(), true ) ); - aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) ); + aList.emplace_back( _( "Orientation" ), PinOrientationName( m_orientation ) ); - SCH_EDIT_FRAME* schframe = dynamic_cast( aFrame ); - SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr; + if( dynamic_cast( symbol ) ) + { + VECTOR2I pinpos = GetPosition(); + pinpos.y = -pinpos.y; // Display coords are top to bottom; lib item coords are bottom to top - // Don't use GetShownText(); we want to see the variable references here - aList.emplace_back( symbol->GetRef( currentSheet ), - UnescapeString( symbol->GetField( VALUE_FIELD )->GetText() ) ); + aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( pinpos.x, true ) ); + aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( pinpos.y, true ) ); + } + else + { + SCH_EDIT_FRAME* schframe = dynamic_cast( aFrame ); + SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr; + SCH_SYMBOL* schsymbol = dynamic_cast( symbol ); + + // Don't use GetShownText(); we want to see the variable references here + aList.emplace_back( symbol->GetRef( currentSheet ), + UnescapeString( schsymbol->GetField( VALUE_FIELD )->GetText() ) ); + } #if defined(DEBUG) if( !IsConnectivityDirty() && dynamic_cast( aFrame ) ) @@ -277,28 +1421,6 @@ void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vectorGetType() == ELECTRICAL_PINTYPE::PT_PASSIVE - || aPin->GetType() == ELECTRICAL_PINTYPE::PT_NIC; - - return m_parent == aPin->GetParent() - && GetTransformedPosition() == aPin->GetTransformedPosition() - && GetName() == aPin->GetName() - && ( ( GetType() == aPin->GetType() ) - || isConnectableType_a || isConnectableType_b ); -} - - -bool SCH_PIN::IsGlobalPower() const -{ - wxCHECK( m_libPin, false ); - - return m_libPin->IsGlobalPower(); -} - void SCH_PIN::ClearDefaultNetName( const SCH_SHEET_PATH* aPath ) { std::lock_guard lock( m_netmap_mutex ); @@ -403,61 +1525,194 @@ wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoC } -VECTOR2I SCH_PIN::GetTransformedPosition() const +const BOX2I SCH_PIN::ViewBBox() const { - TRANSFORM t = static_cast( GetParentSymbol() )->GetTransform(); - return t.TransformCoordinate( GetLocalPosition() ) + GetParentSymbol()->GetPosition(); + return GetBoundingBox( false, true, true ); } -const BOX2I SCH_PIN::GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber, +void SCH_PIN::ViewGetLayers( int aLayers[], int& aCount ) const +{ + aCount = 6; + aLayers[0] = LAYER_DANGLING; + aLayers[1] = LAYER_DEVICE; + aLayers[2] = LAYER_SELECTION_SHADOWS; + aLayers[3] = LAYER_OP_CURRENTS; + aLayers[4] = LAYER_PINNAM; + aLayers[5] = LAYER_PINNUM; +} + + +void SCH_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText, + EXTENTS_CACHE* aCache ) const +{ + if( aCache->m_Font == aFont + && aCache->m_FontSize == aSize + && aCache->m_Extents != VECTOR2I() ) + { + return; + } + + aCache->m_Font = aFont; + aCache->m_FontSize = aSize; + + VECTOR2D fontSize( aSize, aSize ); + int penWidth = GetPenSizeForNormal( aSize ); + + aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false, + GetFontMetrics() ); +} + + +const BOX2I SCH_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber, bool aIncludeElectricalType ) const { - wxCHECK( m_libPin, BOX2I() ); + if( const SCH_SYMBOL* symbol = dynamic_cast( GetParentSymbol() ) ) + { + wxCHECK( m_libPin, BOX2I() ); - TRANSFORM t = static_cast( GetParentSymbol() )->GetTransform(); - BOX2I r = m_libPin->GetBoundingBox( aIncludeInvisiblePins, aIncludeNameAndNumber, + BOX2I r = m_libPin->GetBoundingBox( aIncludeLabelsOnInvisiblePins, aIncludeNameAndNumber, aIncludeElectricalType ); - r.RevertYAxis(); + r.RevertYAxis(); - r = t.TransformCoordinate( r ); - r.Offset( GetParentSymbol()->GetPosition() ); - r.Normalize(); + r = symbol->GetTransform().TransformCoordinate( r ); + r.Offset( symbol->GetPosition() ); + r.Normalize(); - return r; -} + return r; + } + EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); + KIFONT::FONT* font = KIFONT::FONT::GetFont( cfg->m_Appearance.default_font ); -bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const -{ - // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has - // no pin number or name. Give it a floor. - if( Schematic() ) - aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 ); + BOX2I bbox; + VECTOR2I begin; + VECTOR2I end; + int pinNameOffset = 0; + int nameTextLength = 0; + int nameTextHeight = 0; + int numberTextLength = 0; + int numberTextHeight = 0; + int typeTextLength = 0; + bool includeName = aIncludeNameAndNumber && !GetShownName().IsEmpty(); + bool includeNumber = aIncludeNameAndNumber && !GetShownNumber().IsEmpty(); + bool includeType = aIncludeElectricalType; + int minsizeV = TARGET_PIN_RADIUS; - BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ); - return rect.Inflate( aAccuracy ).Contains( aPosition ); -} + if( !aIncludeLabelsOnInvisiblePins && !IsVisible() ) + { + includeName = false; + includeNumber = false; + includeType = false; + } + if( const SYMBOL* parentSymbol = GetParentSymbol() ) + { + if( parentSymbol->GetShowPinNames() ) + pinNameOffset = parentSymbol->GetPinNameOffset(); + else + includeName = false; -bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const -{ - BOX2I sel = aRect; + if( !parentSymbol->GetShowPinNumbers() ) + includeNumber = false; + } - if( aAccuracy ) - sel.Inflate( aAccuracy ); + if( includeNumber ) + { + validateExtentsCache( font, GetNumberTextSize(), GetShownNumber(), &m_numExtentsCache ); + numberTextLength = m_numExtentsCache.m_Extents.x; + numberTextHeight = m_numExtentsCache.m_Extents.y; + } - if( aContained ) - return sel.Contains( GetBoundingBox( false, false, false ) ); + if( includeName ) + { + validateExtentsCache( font, GetNameTextSize(), GetShownName(), &m_nameExtentsCache ); + nameTextLength = m_nameExtentsCache.m_Extents.x + pinNameOffset; + nameTextHeight = m_nameExtentsCache.m_Extents.y + schIUScale.MilsToIU( PIN_TEXT_MARGIN ); + } - return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) ); -} + if( includeType ) + { + double fontSize = std::max( GetNameTextSize() * 3 / 4, schIUScale.mmToIU( 0.7 ) ); + double stroke = fontSize / 8.0; + VECTOR2I typeTextSize = font->StringBoundaryLimits( GetElectricalTypeName(), + VECTOR2D( fontSize, fontSize ), + KiROUND( stroke ), false, false, + GetFontMetrics() ); + typeTextLength = typeTextSize.x + schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + TARGET_PIN_RADIUS; + minsizeV = std::max( minsizeV, typeTextSize.y / 2 ); + } -EDA_ITEM* SCH_PIN::Clone() const -{ - return new SCH_PIN( *this ); + // First, calculate boundary box corners position + if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK ) + minsizeV = std::max( TARGET_PIN_RADIUS, externalPinDecoSize( nullptr, *this ) ); + + // Calculate topLeft & bottomRight corner positions for the default pin orientation (PIN_RIGHT) + if( pinNameOffset || !includeName ) + { + // pin name is inside the body (or invisible) + // pin number is above the line + begin.y = std::max( minsizeV, numberTextHeight ); + begin.x = std::min( -typeTextLength, GetLength() - ( numberTextLength / 2 ) ); + + end.x = GetLength() + nameTextLength; + end.y = std::min( -minsizeV, -nameTextHeight / 2 ); + } + else + { + // pin name is above pin line + // pin number is below line + begin.y = std::max( minsizeV, nameTextHeight ); + begin.x = -typeTextLength; + begin.x = std::min( begin.x, ( GetLength() - numberTextLength ) / 2 ); + begin.x = std::min( begin.x, ( GetLength() - nameTextLength ) / 2 ); + + end.x = GetLength(); + end.x = std::max( end.x, ( GetLength() + nameTextLength ) / 2 ); + end.x = std::max( end.x, ( GetLength() + numberTextLength ) / 2 ); + end.y = std::min( -minsizeV, -numberTextHeight ); + } + + // Now, calculate boundary box corners position for the actual pin orientation + switch( PinDrawOrient( DefaultTransform ) ) + { + case PIN_ORIENTATION::PIN_UP: + // Pin is rotated and texts positions are mirrored + RotatePoint( begin, VECTOR2I( 0, 0 ), -ANGLE_90 ); + RotatePoint( end, VECTOR2I( 0, 0 ), -ANGLE_90 ); + break; + + case PIN_ORIENTATION::PIN_DOWN: + RotatePoint( begin, VECTOR2I( 0, 0 ), ANGLE_90 ); + RotatePoint( end, VECTOR2I( 0, 0 ), ANGLE_90 ); + begin.x = -begin.x; + end.x = -end.x; + break; + + case PIN_ORIENTATION::PIN_LEFT: + begin.x = -begin.x; + end.x = -end.x; + break; + + default: + case PIN_ORIENTATION::PIN_RIGHT: + break; + } + + begin += m_position; + end += m_position; + + bbox.SetOrigin( begin ); + bbox.SetEnd( end ); + bbox.Normalize(); + bbox.Inflate( ( GetPenWidth() / 2 ) + 1 ); + + // Draw Y axis is reversed in schematic: + bbox.RevertYAxis(); + + return bbox; } @@ -492,46 +1747,272 @@ bool SCH_PIN::ConnectionPropagatesTo( const EDA_ITEM* aItem ) const } +BITMAPS SCH_PIN::GetMenuImage() const +{ + return ElectricalPinTypeGetBitmap( m_type ); +} + + +wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const +{ + return getItemDescription( aAlt ); +} + + +wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const +{ + if( m_libPin ) + { + SCH_PIN::ALT localStorage; + SCH_PIN::ALT* alt = nullptr; + + if( !m_alt.IsEmpty() ) + { + localStorage = m_libPin->GetAlt( m_alt ); + alt = &localStorage; + } + + wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt ) + : wxString( wxS( "Undefined library pin." ) ); + + const SCH_SYMBOL* symbol = static_cast( GetParentSymbol() ); + + return wxString::Format( "Symbol %s %s", + UnescapeString( symbol->GetField( REFERENCE_FIELD )->GetText() ), + itemDesc ); + } + + return getItemDescription( nullptr ); +} + + +wxString SCH_PIN::getItemDescription( ALT* aAlt ) const +{ + // This code previously checked "m_name.IsEmpty()" to choose the correct + // formatting path, but that check fails if the pin is called "~" which is + // the default for an empty pin name. Instead we get the final display string + // that will be shown and check if it's empty. + + wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() ); + wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type ); + wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape ); + + if( IsVisible() ) + { + if ( !name.IsEmpty() ) + { + return wxString::Format( _( "Pin %s [%s, %s, %s]" ), + GetShownNumber(), + name, + electricalTypeName, + pinShapeName ); + } + else + { + return wxString::Format( _( "Pin %s [%s, %s]" ), + GetShownNumber(), + electricalTypeName, + pinShapeName ); + } + } + else + { + if( !name.IsEmpty() ) + { + return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ), + GetShownNumber(), + name, + electricalTypeName, + pinShapeName ); + } + else + { + return wxString::Format( _( "Hidden pin %s [%s, %s]" ), + GetShownNumber(), + electricalTypeName, + pinShapeName ); + } + } +} + + bool SCH_PIN::operator==( const SCH_ITEM& aOther ) const { if( aOther.Type() != SCH_PIN_T ) return false; - const SCH_PIN& other = static_cast( aOther ); + const SCH_PIN* other = static_cast( &aOther ); - return *this == other; -} - - -bool SCH_PIN::operator==( const SCH_PIN& aOther ) const -{ - if( m_number != aOther.m_number ) + if( m_number != other->m_number ) return false; - if( m_position != aOther.m_position ) + if( m_position != other->m_position ) return false; - return m_libPin == aOther.m_libPin; + if( dynamic_cast( GetParentSymbol() ) ) + { + if( m_libPin != other->m_libPin ) + return false; + + if( m_alt != other->m_alt ) + return false; + } + + if( dynamic_cast( GetParentSymbol() ) ) + { + if( m_length != other->m_length ) + return false; + + if( m_orientation != other->m_orientation ) + return false; + + if( m_shape != other->m_shape ) + return false; + + if( m_type != other->m_type ) + return false; + + if( m_name != other->m_name ) + return false; + + if( m_attributes != other->m_attributes ) + return false; + + if( m_numTextSize != other->m_numTextSize ) + return false; + + if( m_nameTextSize != other->m_nameTextSize ) + return false; + + if( m_alternates.size() != other->m_alternates.size() ) + return false; + + auto lhsItem = m_alternates.begin(); + auto rhsItem = other->m_alternates.begin(); + + while( lhsItem != m_alternates.end() ) + { + if( rhsItem == other->m_alternates.end() ) + return false; + + const ALT& lhsAlt = lhsItem->second; + const ALT& rhsAlt = rhsItem->second; + + if( lhsAlt.m_Name != rhsAlt.m_Name ) + return false; + + if( lhsAlt.m_Type != rhsAlt.m_Type ) + return false; + + if( lhsAlt.m_Shape != rhsAlt.m_Shape ) + return false; + + ++lhsItem; + ++rhsItem; + } + + if( rhsItem != other->m_alternates.end() ) + return false; + } + + return true; } double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const { - if( m_Uuid == aOther.m_Uuid ) + if( aOther.m_Uuid == m_Uuid ) return 1.0; if( aOther.Type() != SCH_PIN_T ) return 0.0; - const SCH_PIN& other = static_cast( aOther ); + const SCH_PIN* other = static_cast( &aOther ); - if( m_number != other.m_number ) - return 0.0; + if( m_libPin ) + { + if( m_number != other->m_number ) + return 0.0; - if( m_position != other.m_position ) - return 0.0; + if( m_position != other->m_position ) + return 0.0; - return m_libPin ? m_libPin->Similarity( *other.m_libPin ) : 0.0; + return m_libPin->Similarity( *other->m_libPin ); + } + + double similarity = SimilarityBase( aOther ); + + if( m_name != other->m_name ) + similarity *= 0.9; + + if( m_number != other->m_number ) + similarity *= 0.9; + + if( m_position != other->m_position ) + similarity *= 0.9; + + if( m_length != other->m_length ) + similarity *= 0.9; + + if( m_orientation != other->m_orientation ) + similarity *= 0.9; + + if( m_shape != other->m_shape ) + similarity *= 0.9; + + if( m_type != other->m_type ) + similarity *= 0.9; + + if( m_attributes != other->m_attributes ) + similarity *= 0.9; + + if( m_numTextSize != other->m_numTextSize ) + similarity *= 0.9; + + if( m_nameTextSize != other->m_nameTextSize ) + similarity *= 0.9; + + if( m_alternates.size() != other->m_alternates.size() ) + similarity *= 0.9; + + return similarity; +} + + +std::ostream& SCH_PIN::operator<<( std::ostream& aStream ) +{ + aStream << "SCH_PIN:" << std::endl + << " Name: \"" << m_name << "\"" << std::endl + << " Number: \"" << m_number << "\"" << std::endl + << " Position: " << m_position << std::endl + << " Length: " << GetLength() << std::endl + << " Orientation: " << PinOrientationName( m_orientation ) << std::endl + << " Shape: " << PinShapeGetText( m_shape ) << std::endl + << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl + << " Name Text Size: " << GetNameTextSize() << std::endl + << " Number Text Size: " << GetNumberTextSize() << std::endl; + + return aStream; +} + + +#if defined(DEBUG) + +void SCH_PIN::Show( int nestLevel, std::ostream& os ) const +{ + NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() + << " num=\"" << m_number.mb_str() + << '"' << "/>\n"; + +// NestedSpace( nestLevel, os ) << "\n"; +} + +#endif + +void SCH_PIN::CalcEdit( const VECTOR2I& aPosition ) +{ + if( IsMoving() ) + SetPosition( aPosition ); } @@ -539,17 +2020,116 @@ static struct SCH_PIN_DESC { SCH_PIN_DESC() { + auto& pinTypeEnum = ENUM_MAP::Instance(); + + if( pinTypeEnum.Choices().GetCount() == 0 ) + { + pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) ) + .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) ) + .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) ) + .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) ) + .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) ) + .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) ) + .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) ) + .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) ) + .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) ) + .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) ) + .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) ) + .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) ); + } + + auto& pinShapeEnum = ENUM_MAP::Instance(); + + if( pinShapeEnum.Choices().GetCount() == 0 ) + { + pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) ) + .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) ) + .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) ) + .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) ) + .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) ) + .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) ) + .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) ) + .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) ) + .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) ); + } + + auto& orientationEnum = ENUM_MAP::Instance(); + + if( orientationEnum.Choices().GetCount() == 0 ) + { + orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _( "Right" ) ) + .Map( PIN_ORIENTATION::PIN_LEFT, _( "Left" ) ) + .Map( PIN_ORIENTATION::PIN_UP, _( "Up" ) ) + .Map( PIN_ORIENTATION::PIN_DOWN, _( "Down" ) ); + } + + auto isSymbolEditor = + []( INSPECTABLE* aItem ) -> bool + { + if( SCH_PIN* pin = dynamic_cast( aItem ) ) + return dynamic_cast( pin->GetParentSymbol() ) != nullptr; + + return false; + }; + PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); REGISTER_TYPE( SCH_PIN ); + propMgr.AddTypeCast( new TYPE_CAST ); propMgr.InheritsAfter( TYPE_HASH( SCH_PIN ), TYPE_HASH( SCH_ITEM ) ); propMgr.AddProperty( new PROPERTY( _HKI( "Pin Name" ), - NO_SETTER( SCH_PIN, wxString ), &SCH_PIN::GetName ) ); + &SCH_PIN::SetName, &SCH_PIN::GetName ) ) + .SetWriteableFunc( isSymbolEditor ); propMgr.AddProperty( new PROPERTY( _HKI( "Pin Number" ), - NO_SETTER( SCH_PIN, wxString ), &SCH_PIN::GetNumber ) ); + &SCH_PIN::SetNumber, &SCH_PIN::GetNumber ) ) + .SetWriteableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY_ENUM( + _HKI( "Electrical Type" ), + &SCH_PIN::SetType, &SCH_PIN::GetType ) ) + .SetWriteableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY_ENUM( + _HKI( "Graphic Style" ), + &SCH_PIN::SetShape, &SCH_PIN::GetShape ) ) + .SetWriteableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Position X" ), + &SCH_PIN::SetX, &SCH_PIN::GetX, PROPERTY_DISPLAY::PT_COORD ) ) + .SetAvailableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Position Y" ), + &SCH_PIN::SetY, &SCH_PIN::GetY, PROPERTY_DISPLAY::PT_COORD ) ) + .SetAvailableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY_ENUM( _HKI( "Orientation" ), + &SCH_PIN::SetOrientation, &SCH_PIN::GetOrientation ) ) + .SetWriteableFunc( isSymbolEditor ); propMgr.AddProperty( new PROPERTY( _HKI( "Length" ), - NO_SETTER( SCH_PIN, int ), &SCH_PIN::GetLength, PROPERTY_DISPLAY::PT_SIZE ) ); + &SCH_PIN::SetLength, &SCH_PIN::GetLength, + PROPERTY_DISPLAY::PT_SIZE ) ) + .SetWriteableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Name Text Size" ), + &SCH_PIN::SetNameTextSize, &SCH_PIN::GetNameTextSize, + PROPERTY_DISPLAY::PT_SIZE ) ) + .SetAvailableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Number Text Size" ), + &SCH_PIN::SetNumberTextSize, &SCH_PIN::GetNumberTextSize, + PROPERTY_DISPLAY::PT_SIZE ) ) + .SetAvailableFunc( isSymbolEditor ); + + propMgr.AddProperty( new PROPERTY( _HKI( "Visible" ), + &SCH_PIN::SetVisible, &SCH_PIN::IsVisible ) ) + .SetAvailableFunc( isSymbolEditor ); + } } _SCH_PIN_DESC; + + +ENUM_TO_WXANY( PIN_ORIENTATION ) +ENUM_TO_WXANY( GRAPHIC_PINSHAPE ) +ENUM_TO_WXANY( ELECTRICAL_PINTYPE ) diff --git a/eeschema/sch_pin.h b/eeschema/sch_pin.h index d84033b331..a94700a8d7 100644 --- a/eeschema/sch_pin.h +++ b/eeschema/sch_pin.h @@ -1,8 +1,10 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * + * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr + * Copyright (C) 2015 Wayne Stambaugh * Copyright (C) 2018 CERN - * Copyright (C) 2019-2024 KiCad Developers, see AUTHOR.txt for contributors. + * Copyright (C) 2004-2024 KiCad Developers, see AUTHOR.txt for contributors. * @author Jon Evans * * This program is free software; you can redistribute it and/or @@ -19,89 +21,352 @@ * with this program. If not, see . */ -#ifndef _SCH_PIN_CONNECTION_H -#define _SCH_PIN_CONNECTION_H +#ifndef SCH_PIN_H +#define SCH_PIN_H -#include +#include #include -#include - -#include -#include +#include +class LIB_SYMBOL; class SCH_SYMBOL; -class MSG_PANEL_ITEM; + +// Circle diameter drawn at the active end of pins: +#define TARGET_PIN_RADIUS schIUScale.MilsToIU( 15 ) + +// Pin visibility flag bit: +#define PIN_INVISIBLE 1 // Set makes pin invisible class SCH_PIN : public SCH_ITEM { public: - SCH_PIN( LIB_PIN* aLibPin, SCH_SYMBOL* aParentSymbol ); + struct ALT + { + wxString m_Name; + GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin + ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin. + }; + + SCH_PIN( LIB_SYMBOL* aParentSymbol ); + + SCH_PIN( LIB_SYMBOL* aParentSymbol, const wxString& aName, const wxString& aNumber, + PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, + int aNameTextSize, int aNumTextSize, int aConvert, const VECTOR2I& aPos, int aUnit ); + + SCH_PIN( SCH_PIN* aLibPin, SCH_SYMBOL* aParentSymbol ); SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt ); SCH_PIN( const SCH_PIN& aPin ); - SCH_PIN& operator=( const SCH_PIN& aPin ); + ~SCH_PIN() override { } - static inline bool ClassOf( const EDA_ITEM* aItem ) - { - return aItem && SCH_PIN_T == aItem->Type(); - } + SCH_PIN& operator=( const SCH_PIN& aPin ); wxString GetClass() const override { return wxT( "SCH_PIN" ); } - LIB_PIN* GetLibPin() const { return m_libPin; } + static bool ClassOf( const EDA_ITEM* aItem ) + { + return aItem && aItem->Type() == SCH_PIN_T; + } - void ClearDefaultNetName( const SCH_SHEET_PATH* aPath ); - wxString GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect = false ); + wxString GetFriendlyName() const override + { + return _( "Pin" ); + } + + SCH_PIN* GetLibPin() const { return m_libPin; } + void SetLibPin( SCH_PIN* aLibPin ) { m_libPin = aLibPin; } + + PIN_ORIENTATION GetOrientation() const + { + if( m_libPin ) + return m_libPin->GetOrientation(); + + return m_orientation; + } + + void SetOrientation( PIN_ORIENTATION aOrientation ) { m_orientation = aOrientation; } + + GRAPHIC_PINSHAPE GetShape() const + { + if( m_libPin ) + { + if( !m_alt.IsEmpty() ) + return m_libPin->GetAlt( m_alt ).m_Shape; + else + return m_libPin->GetShape(); + } + + return m_shape; + } + + void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; } + + int GetLength() const + { + if( m_libPin ) + return m_libPin->GetLength(); + else + wxCHECK_MSG( m_length.has_value(), 0, wxS( "lib pin must have length defined!" ) ); + + return m_length.value(); + } + + void SetLength( int aLength ) { m_length = aLength; } + + /** + * Change the length of a pin and adjust its position based on orientation. + * + * @param aLength New length of pin + */ + void ChangeLength( int aLength ); + + ELECTRICAL_PINTYPE GetType() const + { + if( m_libPin ) + { + if( !m_alt.IsEmpty() ) + return m_libPin->GetAlt( m_alt ).m_Type; + else + return m_libPin->GetType(); + } + + return m_type; + } + + void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; } + + wxString GetCanonicalElectricalTypeName() const + { + if( m_libPin ) + return m_libPin->GetCanonicalElectricalTypeName(); + + return GetCanonicalElectricalTypeName( m_type ); + } + + wxString GetElectricalTypeName() const + { + if( m_libPin ) + return m_libPin->GetElectricalTypeName(); + + return ElectricalPinTypeGetText( m_type ); + } + + bool IsVisible() const + { + if( m_libPin ) + return m_libPin->IsVisible(); + + return ( m_attributes & PIN_INVISIBLE ) == 0; + } + + void SetVisible( bool aVisible ) + { + if( aVisible ) + m_attributes &= ~PIN_INVISIBLE; + else + m_attributes |= PIN_INVISIBLE; + } + + const wxString& GetName() const + { + if( !m_alt.IsEmpty() ) + return m_alt; + else if( m_libPin ) + return m_libPin->GetName(); + + return m_name; + } + + wxString GetShownName() const; + + void SetName( const wxString& aName ) + { + m_name = aName; + + // pin name string does not support spaces + m_name.Replace( wxT( " " ), wxT( "_" ) ); + m_nameExtentsCache.m_Extents = VECTOR2I(); + } + + const wxString& GetNumber() const { return m_number; } + wxString GetShownNumber() const; + + void SetNumber( const wxString& aNumber ) + { + m_number = aNumber; + + // pin number string does not support spaces + m_number.Replace( wxT( " " ), wxT( "_" ) ); + m_numExtentsCache.m_Extents = VECTOR2I(); + } + + int GetNameTextSize() const + { + if( m_libPin ) + return m_libPin->GetNameTextSize(); + else + wxCHECK_MSG( m_nameTextSize.has_value(), 0, wxS( "lib pin must have sizes defined!" ) ); + + return m_nameTextSize.value(); + } + + void SetNameTextSize( int aSize ) + { + m_nameTextSize = aSize; + m_nameExtentsCache.m_Extents = VECTOR2I(); + } + + int GetNumberTextSize() const + { + if( m_libPin ) + return m_libPin->GetNumberTextSize(); + else + wxCHECK_MSG( m_numTextSize.has_value(), 0, wxS( "lib pin must have sizes defined!" ) ); + + return m_numTextSize.value(); + } + + void SetNumberTextSize( int aSize ) + { + m_numTextSize = aSize; + m_numExtentsCache.m_Extents = VECTOR2I(); + } + + std::map& GetAlternates() + { + if( m_libPin ) + return m_libPin->GetAlternates(); + + return m_alternates; + } + + ALT GetAlt( const wxString& aAlt ) + { + return GetAlternates()[ aAlt ]; + } wxString GetAlt() const { return m_alt; } void SetAlt( const wxString& aAlt ) { m_alt = aAlt; } + void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle, + const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override; + + /** + * Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), + * according to its orientation and the matrix transform (rot, mirror) \a aTransform. + * + * @param aTransform Transform matrix + */ + PIN_ORIENTATION PinDrawOrient( const TRANSFORM& aTransform ) const; + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ) const override; +#endif + + bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override; + + bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override; + + void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; + const BOX2I ViewBBox() const override; void ViewGetLayers( int aLayers[], int& aCount ) const override; - wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override; - void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; - - void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle, - const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override {} - - void Move( const VECTOR2I& aMoveVector ) override {} - - void MirrorHorizontally( int aCenter ) override {} - void MirrorVertically( int aCenter ) override {} - void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override {} - - VECTOR2I GetPosition() const override { return GetTransformedPosition(); } - const VECTOR2I GetLocalPosition() const { return m_position; } - void SetPosition( const VECTOR2I& aPosition ) override { m_position = aPosition; } - /* Cannot use a default parameter here as it will not be compatible with the virtual. */ - const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, false ); } + const BOX2I GetBoundingBox() const override + { + return GetBoundingBox( false, true, m_layer == LAYER_DEVICE ); + } /** - * @param aIncludeInvisibles - if false, do not include labels for invisible pins - * in the calculation. + * @param aIncludeLabelsOnInvisiblePins - if false, do not include labels for invisible pins + * in the calculation. */ - const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber, + const BOX2I GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber, bool aIncludeElectricalType ) const; - bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override; - bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override; + /** + * Return whether this pin forms a global power connection: i.e., is part of a power symbol + * and of type POWER_IN, or is a legacy invisible global power pin on a symbol. + */ + bool IsGlobalPower() const + { + return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN + && ( !IsVisible() || GetParentSymbol()->IsPower() ); + } + + int GetPenWidth() const override { return 0; } + + void Move( const VECTOR2I& aOffset ) override; + + VECTOR2I GetPosition() const override; + VECTOR2I GetLocalPosition() const { return m_position; } + void SetPosition( const VECTOR2I& aPos ) override { m_position = aPos; } + + // For properties system + int GetX() const { return m_position.x; } + void SetX( int aX ) { m_position.x = aX; } + int GetY() const { return m_position.y; } + void SetY( int aY ) { m_position.y = aY; } + + VECTOR2I GetPinRoot() const; + + void MirrorHorizontally( int aCenter ) override; + void MirrorVertically( int aCenter ) override; + void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override; + + /** + * Plot the pin name and number. + * @param aTextInside - draw the names & numbers inside the symbol body (ie: in the opposite + * direction of \a aPinOrient). + */ + void PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, + int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const; + + void PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, + bool aDimmed ) const; + + void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, + int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override; + + BITMAPS GetMenuImage() const override; + + wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override; + wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const; EDA_ITEM* Clone() const override; + void CalcEdit( const VECTOR2I& aPosition ) override; + + bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override; + + bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override; + + /** + * Return a string giving the electrical type of a pin. + * + * Can be used when a known, not translated name is needed (for instance in net lists) + * + * @param aType is the electrical type (see enum ELECTRICAL_PINTYPE ) + * @return The electrical name for a pin type (see enun MsgPinElectricType for names). + */ + static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType ); + bool IsConnectable() const override { return true; } bool HasConnectivityChanges( const SCH_ITEM* aItem, const SCH_SHEET_PATH* aInstance = nullptr ) const override; + void ClearDefaultNetName( const SCH_SHEET_PATH* aPath ); + wxString GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect = false ); + bool IsDangling() const override { if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC ) @@ -112,8 +377,6 @@ public: void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; } - void SetLibPin( LIB_PIN* aLibPin ) { m_libPin = aLibPin; } - /** * @param aPin Comparison Pin * @return True if aPin is stacked with this pin @@ -125,42 +388,6 @@ public: return m_isDangling && GetPosition() == aPos; } - /// @return the pin's position in global coordinates. - VECTOR2I GetTransformedPosition() const; - - bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override; - - bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override; - - /* - * While many of these are currently simply covers for the equivalent LIB_PIN methods, - * the new Eeschema file format will soon allow us to override them at the schematic level. - */ - bool IsVisible() const; - - wxString GetName() const; - wxString GetShownName() const; - - wxString GetNumber() const { return m_number; } - wxString GetShownNumber() const; - - void SetNumber( const wxString& aNumber ) { m_number = aNumber; } - - ELECTRICAL_PINTYPE GetType() const; - - wxString GetCanonicalElectricalTypeName() const - { - return LIB_PIN::GetCanonicalElectricalTypeName( GetType() ); - } - - GRAPHIC_PINSHAPE GetShape() const; - - PIN_ORIENTATION GetOrientation() const; - - int GetLength() const; - - bool IsGlobalPower() const; - bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override; const wxString& GetOperatingPoint() const { return m_operatingPoint; } @@ -169,27 +396,91 @@ public: double Similarity( const SCH_ITEM& aItem ) const override; bool operator==( const SCH_ITEM& aItem ) const override; - bool operator==( const SCH_PIN& aItem ) const; + bool operator!=( const SCH_ITEM& aItem ) const { return !operator==( aItem ); } + bool operator<( const SCH_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) < 0; } + bool operator>( const SCH_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) > 0; } - bool operator!=( const SCH_PIN& aRhs ) const { return !( *this == aRhs ); } +protected: + wxString getItemDescription( ALT* aAlt ) const; -#if defined(DEBUG) - void Show( int nestLevel, std::ostream& os ) const override {} -#endif + struct EXTENTS_CACHE + { + KIFONT::FONT* m_Font = nullptr; + int m_FontSize = 0; + VECTOR2I m_Extents; + }; + + void validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText, + EXTENTS_CACHE* aCache ) const; + + /** + * Print the pin symbol without text. + * If \a aColor != 0, draw with \a aColor, else with the normal pin color. + */ + void printPinSymbol( const SCH_RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, + PIN_ORIENTATION aOrientation, bool aDimmed ); + + /** + * Put the pin number and pin text info, given the pin line coordinates. + * The line must be vertical or horizontal. + * If aDrawPinName == false the pin name is not printed. + * If aDrawPinNum = false the pin number is not printed. + * If aTextInside then the text is been put inside,otherwise all is drawn outside. + * Pin Name: substring between '~' is negated + */ + void printPinTexts( const RENDER_SETTINGS* aSettings, const VECTOR2I& aPinPos, + PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, + bool aDrawPinName, bool aDimmed ); + + /** + * Draw the electrical type text of the pin (only for the footprint editor) + */ + void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, const VECTOR2I& aPosition, + PIN_ORIENTATION aOrientation, bool aDimmed ); + std::ostream& operator<<( std::ostream& aStream ); private: - LIB_PIN* m_libPin; + /** + * @copydoc SCH_ITEM::compare() + * + * The pin specific sort order is as follows: + * - Pin number. + * - Pin name, case insensitive compare. + * - Pin horizontal (X) position. + * - Pin vertical (Y) position. + */ + int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override; - wxString m_number; - wxString m_alt; - VECTOR2I m_position; - bool m_isDangling; +protected: + SCH_PIN* m_libPin; // The corresponding pin in the LIB_SYMBOL + // (nullptr for a pin *in* the LIB_SYMBOL) + + std::map m_alternates; // Map of alternate name to ALT structure + // (only valid for pins in LIB_SYMBOLS) + + VECTOR2I m_position; // Position of the pin. + std::optional m_length; // Length of the pin. + PIN_ORIENTATION m_orientation; // Pin orientation (Up, Down, Left, Right) + GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin + ELECTRICAL_PINTYPE m_type; // Electrical type of the pin. + int m_attributes; // Set bit 0 to indicate pin is invisible. + wxString m_name; + wxString m_number; + std::optional m_numTextSize; // Pin num and Pin name sizes + std::optional m_nameTextSize; + wxString m_alt; // The current alternate for an instance + + wxString m_operatingPoint; + + mutable EXTENTS_CACHE m_numExtentsCache; + mutable EXTENTS_CACHE m_nameExtentsCache; + + bool m_isDangling; /// The name that this pin connection will drive onto a net. std::recursive_mutex m_netmap_mutex; std::map> m_net_name_map; - - wxString m_operatingPoint; }; -#endif + +#endif // SCH_PIN_H \ No newline at end of file diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 0facc9ec9c..d5026266ec 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include #include @@ -1220,11 +1220,11 @@ void SCH_SCREEN::ClearDrawingState() } -LIB_PIN* SCH_SCREEN::GetPin( const VECTOR2I& aPosition, SCH_SYMBOL** aSymbol, +SCH_PIN* SCH_SCREEN::GetPin( const VECTOR2I& aPosition, SCH_SYMBOL** aSymbol, bool aEndPointOnly ) const { SCH_SYMBOL* candidate = nullptr; - LIB_PIN* pin = nullptr; + SCH_PIN* pin = nullptr; for( SCH_ITEM* item : Items().Overlapping( SCH_SYMBOL_T, aPosition ) ) { @@ -1237,10 +1237,7 @@ LIB_PIN* SCH_SCREEN::GetPin( const VECTOR2I& aPosition, SCH_SYMBOL** aSymbol, if( !candidate->GetLibSymbolRef() ) continue; - std::vector pins; - candidate->GetLibPins( pins ); - - for( LIB_PIN* test_pin : pins ) + for( SCH_PIN* test_pin : candidate->GetLibPins() ) { if( candidate->GetPinPhysicalPosition( test_pin ) == aPosition ) { @@ -1254,7 +1251,7 @@ LIB_PIN* SCH_SCREEN::GetPin( const VECTOR2I& aPosition, SCH_SYMBOL** aSymbol, } else { - pin = (LIB_PIN*) candidate->GetDrawItem( aPosition, LIB_PIN_T ); + pin = static_cast( candidate->GetDrawItem( aPosition, SCH_PIN_T ) ); if( pin ) break; diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 531a054e94..41b8eb8279 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -55,7 +55,7 @@ class BUS_ALIAS; class EDA_ITEM; class LIB_SYMBOL; -class LIB_PIN; +class SCH_PIN; class SCH_SYMBOL; class SCH_LINE; class SCH_LABEL_BASE; @@ -368,7 +368,7 @@ public: * point of the pin. * @return The pin item if found, otherwise NULL. */ - LIB_PIN* GetPin( const VECTOR2I& aPosition, SCH_SYMBOL** aSymbol = nullptr, + SCH_PIN* GetPin( const VECTOR2I& aPosition, SCH_SYMBOL** aSymbol = nullptr, bool aEndPointOnly = false ) const; /** diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 14f6226a5c..6a753dea34 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -312,7 +312,7 @@ void SCH_SYMBOL::UpdatePins() std::map altPinMap; std::map> pinUuidMap; std::set unassignedSchPins; - std::set unassignedLibPins; + std::set unassignedLibPins; for( const std::unique_ptr& pin : m_pins ) { @@ -331,9 +331,7 @@ void SCH_SYMBOL::UpdatePins() if( !m_part ) return; - std::vector pins = m_part->GetAllLibPins(); - - for( LIB_PIN* libPin : pins ) + for( SCH_PIN* libPin : m_part->GetAllLibPins() ) { // NW: Don't filter by unit: this data-structure is used for all instances, // some of which might have different units. @@ -367,7 +365,7 @@ void SCH_SYMBOL::UpdatePins() } // Add any pins that were not found in the symbol - for( LIB_PIN* libPin : unassignedLibPins ) + for( SCH_PIN* libPin : unassignedLibPins ) { SCH_PIN* pin = nullptr; @@ -503,18 +501,15 @@ void SCH_SYMBOL::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBo if( m_part ) { - std::vector libPins; - m_part->GetPins( libPins, m_unit, m_bodyStyle ); - - LIB_SYMBOL tempSymbol( *m_part ); - std::vector tempPins; - tempSymbol.GetPins( tempPins, m_unit, m_bodyStyle ); + std::vector libPins = m_part->GetPins( m_unit, m_bodyStyle ); + LIB_SYMBOL tempSymbol( *m_part ); + std::vector tempPins = tempSymbol.GetPins( m_unit, m_bodyStyle ); // Copy the pin info from the symbol to the temp pins for( unsigned i = 0; i < tempPins.size(); ++ i ) { SCH_PIN* symbolPin = GetPin( libPins[ i ] ); - LIB_PIN* tempPin = tempPins[ i ]; + SCH_PIN* tempPin = tempPins[ i ]; tempPin->SetName( symbolPin->GetShownName() ); tempPin->SetType( symbolPin->GetType() ); @@ -1108,25 +1103,25 @@ SCH_PIN* SCH_SYMBOL::GetPin( const wxString& aNumber ) const } -void SCH_SYMBOL::GetLibPins( std::vector& aPinsList ) const +std::vector SCH_SYMBOL::GetLibPins() const { if( m_part ) - m_part->GetPins( aPinsList, m_unit, m_bodyStyle ); + return m_part->GetPins( m_unit, m_bodyStyle ); + + return std::vector(); } -std::vector SCH_SYMBOL::GetAllLibPins() const +std::vector SCH_SYMBOL::GetAllLibPins() const { - std::vector pinList; - if( m_part ) - m_part->GetPins( pinList, 0, 0 ); + return m_part->GetAllLibPins(); - return pinList; + return std::vector(); } -SCH_PIN* SCH_SYMBOL::GetPin( LIB_PIN* aLibPin ) const +SCH_PIN* SCH_SYMBOL::GetPin( SCH_PIN* aLibPin ) const { auto it = m_pinMap.find( aLibPin ); @@ -2045,7 +2040,7 @@ void SCH_SYMBOL::GetEndPoints( std::vector & aItemList ) { for( std::unique_ptr& pin : m_pins ) { - LIB_PIN* lib_pin = pin->GetLibPin(); + SCH_PIN* lib_pin = pin->GetLibPin(); if( lib_pin && lib_pin->GetUnit() && m_unit && ( m_unit != lib_pin->GetUnit() ) ) continue; @@ -2109,9 +2104,9 @@ bool SCH_SYMBOL::UpdateDanglingState( std::vector& aItemListB } -VECTOR2I SCH_SYMBOL::GetPinPhysicalPosition( const LIB_PIN* Pin ) const +VECTOR2I SCH_SYMBOL::GetPinPhysicalPosition( const SCH_PIN* Pin ) const { - wxCHECK_MSG( Pin != nullptr && Pin->Type() == LIB_PIN_T, VECTOR2I( 0, 0 ), + wxCHECK_MSG( Pin != nullptr && Pin->Type() == SCH_PIN_T, VECTOR2I( 0, 0 ), wxT( "Cannot get physical position of pin." ) ); return m_transform.TransformCoordinate( Pin->GetPosition() ) + m_pos; @@ -2429,19 +2424,17 @@ void SCH_SYMBOL::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& if( m_part ) { - std::vector libPins; - m_part->GetPins( libPins, GetUnit(), GetBodyStyle() ); + std::vector libPins = m_part->GetPins( GetUnit(), GetBodyStyle() ); // Copy the source so we can re-orient and translate it. - LIB_SYMBOL tempSymbol( *m_part ); - std::vector tempPins; - tempSymbol.GetPins( tempPins, GetUnit(), GetBodyStyle() ); + LIB_SYMBOL tempSymbol( *m_part ); + std::vector tempPins = tempSymbol.GetPins( GetUnit(), GetBodyStyle() ); // Copy the pin info from the symbol to the temp pins for( unsigned i = 0; i < tempPins.size(); ++ i ) { SCH_PIN* symbolPin = GetPin( libPins[ i ] ); - LIB_PIN* tempPin = tempPins[ i ]; + SCH_PIN* tempPin = tempPins[ i ]; tempPin->SetName( symbolPin->GetShownName() ); tempPin->SetType( symbolPin->GetType() ); @@ -2544,21 +2537,18 @@ void SCH_SYMBOL::PlotPins( PLOTTER* aPlotter ) const TRANSFORM savedTransform = renderSettings->m_Transform; renderSettings->m_Transform = GetTransform(); - std::vector libPins; - m_part->GetPins( libPins, GetUnit(), GetBodyStyle() ); + std::vector libPins = m_part->GetPins( GetUnit(), GetBodyStyle() ); // Copy the source to stay const - LIB_SYMBOL tempSymbol( *m_part ); - std::vector tempPins; - tempSymbol.GetPins( tempPins, GetUnit(), GetBodyStyle() ); - - SCH_PLOT_OPTS plotOpts; + LIB_SYMBOL tempSymbol( *m_part ); + std::vector tempPins = tempSymbol.GetPins( GetUnit(), GetBodyStyle() ); + SCH_PLOT_OPTS plotOpts; // Copy the pin info from the symbol to the temp pins for( unsigned i = 0; i < tempPins.size(); ++ i ) { SCH_PIN* symbolPin = GetPin( libPins[ i ] ); - LIB_PIN* tempPin = tempPins[ i ]; + SCH_PIN* tempPin = tempPins[ i ]; tempPin->SetName( symbolPin->GetShownName() ); tempPin->SetType( symbolPin->GetType() ); @@ -2622,7 +2612,7 @@ bool SCH_SYMBOL::IsSymbolLikePowerGlobalLabel() const if( !GetLibSymbolRef() || !GetLibSymbolRef()->IsPower() ) return false; - std::vector pin_list = GetAllLibPins(); + std::vector pin_list = GetAllLibPins(); if( pin_list.size() != 1 ) return false; diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index 1704cbf49f..1c83c316c7 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -46,6 +46,7 @@ #include #include +#include #include #include #include // SCH_SYMBOL_INSTANCE @@ -55,7 +56,6 @@ struct PICKED_SYMBOL; class KIID_PATH; class SCH_SCREEN; -class LIB_PIN; class LIB_SYMBOL; class NETLIST_OBJECT_LIST; class SYMBOL_LIB; @@ -596,17 +596,18 @@ public: SCH_PIN* GetPin( const wxString& number ) const; /** - * Populate a vector with all the pins from the library object. + * Populate a vector with all the pins from the library object that match the current unit + * and bodyStyle. * * @param aPinsList is the list to populate with all of the pins. */ - void GetLibPins( std::vector& aPinsList ) const; + std::vector GetLibPins() const; /** - * @return a list of pin pointers for all units / converts. Used primarily for SPICE where + * @return a list of pin pointers for all units / bodyStyles. Used primarily for SPICE where * we want to treat all units together as a single SPICE element. */ - std::vector GetAllLibPins() const; + std::vector GetAllLibPins() const; /** * @return a count of pins for all units. @@ -614,9 +615,9 @@ public: size_t GetFullPinCount() { return m_part ? m_part->GetPinCount() : 0; } /** - * @return the SCH_PIN associated with a particular LIB_PIN. + * @return the instance SCH_PIN associated with a particular SCH_PIN from the LIB_SYMBOL. */ - SCH_PIN* GetPin( LIB_PIN* aLibPin ) const; + SCH_PIN* GetPin( SCH_PIN* aLibPin ) const; /** * Retrieve a list of the SCH_PINs for the given sheet path. @@ -718,7 +719,7 @@ public: std::vector& aItemListByPos, const SCH_SHEET_PATH* aPath = nullptr ) override; - VECTOR2I GetPinPhysicalPosition( const LIB_PIN* Pin ) const; + VECTOR2I GetPinPhysicalPosition( const SCH_PIN* Pin ) const; bool IsConnectable() const override { return true; } @@ -843,6 +844,12 @@ public: bool IsPower() const override; bool IsNormal() const override; + /* + * We don't currently support changing these at the schematic level. + */ + bool GetShowPinNames() const override { return m_part && m_part->GetShowPinNames(); } + bool GetShowPinNumbers() const override { return m_part && m_part->GetShowPinNumbers(); } + double Similarity( const SCH_ITEM& aOther ) const override; bool operator==( const SCH_ITEM& aOther ) const override; @@ -854,6 +861,7 @@ private: void Init( const VECTOR2I& pos = VECTOR2I( 0, 0 ) ); +private: VECTOR2I m_pos; LIB_ID m_lib_id; ///< Name and library the symbol was loaded from, i.e. 74xx:74LS00. wxString m_prefix; ///< C, R, U, Q etc - the first character(s) which typically @@ -877,8 +885,8 @@ private: ///< PROJECT's libraries. bool m_isInNetlist; ///< True if the symbol should appear in netlist - std::vector> m_pins; ///< a SCH_PIN for every LIB_PIN (all units) - std::unordered_map m_pinMap; ///< library pin pointer : SCH_PIN's index + std::vector> m_pins; ///< a SCH_PIN for every SCH_PIN (all units) + std::unordered_map m_pinMap; ///< library pin pointer : SCH_PIN's index // Defines the hierarchical path and reference of the symbol. This allows support for multiple // references to a single sub-sheet. diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index a822775afb..6559e99d51 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -34,7 +34,7 @@ class SCH_SHEET; class SCH_SCREEN; class LIB_SYMBOL; -class LIB_PIN; +class SCH_PIN; class SCH_BASE_FRAME; class DS_PROXY_VIEW_ITEM; diff --git a/eeschema/sim/sim_lib_mgr.cpp b/eeschema/sim/sim_lib_mgr.cpp index c2f6e8cdb7..916a81848a 100644 --- a/eeschema/sim/sim_lib_mgr.cpp +++ b/eeschema/sim/sim_lib_mgr.cpp @@ -153,7 +153,7 @@ void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath, REPORTER& aReporter } -SIM_MODEL& SIM_LIB_MGR::CreateModel( SIM_MODEL::TYPE aType, const std::vector& aPins, +SIM_MODEL& SIM_LIB_MGR::CreateModel( SIM_MODEL::TYPE aType, const std::vector& aPins, REPORTER& aReporter ) { m_models.push_back( SIM_MODEL::Create( aType, aPins, aReporter ) ); @@ -162,7 +162,7 @@ SIM_MODEL& SIM_LIB_MGR::CreateModel( SIM_MODEL::TYPE aType, const std::vector
  • & aPins, REPORTER& aReporter ) + const std::vector& aPins, REPORTER& aReporter ) { m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aReporter ) ); return *m_models.back(); @@ -170,7 +170,7 @@ SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel, SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel, - const std::vector& aPins, + const std::vector& aPins, const std::vector& aFields, REPORTER& aReporter ) { m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aFields, aReporter ) ); @@ -232,10 +232,10 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S storeInValue = true; } - std::vector sourcePins = aSymbol.GetAllLibPins(); + std::vector sourcePins = aSymbol.GetAllLibPins(); std::sort( sourcePins.begin(), sourcePins.end(), - []( const LIB_PIN* lhs, const LIB_PIN* rhs ) + []( const SCH_PIN* lhs, const SCH_PIN* rhs ) { return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0; } ); @@ -249,7 +249,7 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector& aFields, - const std::vector& aPins, bool aResolved, + const std::vector& aPins, bool aResolved, REPORTER& aReporter ) { std::string libraryPath = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::LIBRARY_FIELD ); @@ -270,7 +270,7 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector& aFiel SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath, const std::string& aBaseModelName, const std::vector& aFields, - const std::vector& aPins, + const std::vector& aPins, REPORTER& aReporter ) { wxString path; diff --git a/eeschema/sim/sim_lib_mgr.h b/eeschema/sim/sim_lib_mgr.h index ea2e441819..a09f9080e4 100644 --- a/eeschema/sim/sim_lib_mgr.h +++ b/eeschema/sim/sim_lib_mgr.h @@ -47,13 +47,13 @@ public: void SetLibrary( const wxString& aLibraryPath, REPORTER& aReporter ); - SIM_MODEL& CreateModel( SIM_MODEL::TYPE aType, const std::vector& aPins, + SIM_MODEL& CreateModel( SIM_MODEL::TYPE aType, const std::vector& aPins, REPORTER& aReporter ); - SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector& aPins, + SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector& aPins, REPORTER& aReporter ); - SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector& aPins, + SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector& aPins, const std::vector& aFields, REPORTER& aReporter ); // TODO: The argument can be made const. @@ -61,13 +61,13 @@ public: REPORTER& aReporter ); SIM_LIBRARY::MODEL CreateModel( const std::vector& aFields, - const std::vector& aPins, bool aResolved, + const std::vector& aPins, bool aResolved, REPORTER& aReporter ); SIM_LIBRARY::MODEL CreateModel( const wxString& aLibraryPath, const std::string& aBaseModelName, const std::vector& aFields, - const std::vector& aPins, REPORTER& aReporter ); + const std::vector& aPins, REPORTER& aReporter ); void SetModel( int aIndex, std::unique_ptr aModel ); diff --git a/eeschema/sim/sim_library_kibis.cpp b/eeschema/sim/sim_library_kibis.cpp index 7c857b23a6..b0e0804215 100644 --- a/eeschema/sim/sim_library_kibis.cpp +++ b/eeschema/sim/sim_library_kibis.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include void SIM_LIBRARY_KIBIS::ReadFile( const wxString& aFilePath, REPORTER& aReporter ) @@ -41,11 +41,11 @@ void SIM_LIBRARY_KIBIS::ReadFile( const wxString& aFilePath, REPORTER& aReporter return; } - LIB_PIN pinA( nullptr ); - LIB_PIN pinB( nullptr ); + SCH_PIN pinA( nullptr ); + SCH_PIN pinB( nullptr ); pinA.SetNumber( wxT( "1" ) ); pinB.SetNumber( wxT( "2" ) ); - std::vector pins = { &pinA, &pinB }; + std::vector pins = { &pinA, &pinB }; for( KIBIS_COMPONENT& kcomp : m_kibis.m_components ) { diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index d3e21fb7d1..ad535d51eb 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -421,7 +421,7 @@ TYPE SIM_MODEL::ReadTypeFromFields( const std::vector& aFields, REPOR void SIM_MODEL::ReadDataFields( const std::vector* aFields, - const std::vector& aPins ) + const std::vector& aPins ) { bool diffMode = GetFieldValue( aFields, SIM_LIBRARY_KIBIS::DIFF_FIELD ) == "1"; SwitchSingleEndedDiff( diffMode ); @@ -489,7 +489,7 @@ void SIM_MODEL::WriteFields( std::vector& aFields ) const } -std::unique_ptr SIM_MODEL::Create( TYPE aType, const std::vector& aPins, +std::unique_ptr SIM_MODEL::Create( TYPE aType, const std::vector& aPins, REPORTER& aReporter ) { std::unique_ptr model = Create( aType ); @@ -509,7 +509,7 @@ std::unique_ptr SIM_MODEL::Create( TYPE aType, const std::vector SIM_MODEL::Create( const SIM_MODEL* aBaseModel, - const std::vector& aPins, + const std::vector& aPins, REPORTER& aReporter ) { std::unique_ptr model; @@ -546,7 +546,7 @@ std::unique_ptr SIM_MODEL::Create( const SIM_MODEL* aBaseModel, std::unique_ptr SIM_MODEL::Create( const SIM_MODEL* aBaseModel, - const std::vector& aPins, + const std::vector& aPins, const std::vector& aFields, REPORTER& aReporter ) { @@ -594,7 +594,7 @@ std::unique_ptr SIM_MODEL::Create( const SIM_MODEL* aBaseModel, std::unique_ptr SIM_MODEL::Create( const std::vector& aFields, - const std::vector& aPins, + const std::vector& aPins, bool aResolved, REPORTER& aReporter ) { TYPE type = ReadTypeFromFields( aFields, aReporter ); @@ -980,7 +980,7 @@ SIM_MODEL::SIM_MODEL( TYPE aType, std::unique_ptr aSpiceGenerat } -void SIM_MODEL::createPins( const std::vector& aSymbolPins ) +void SIM_MODEL::createPins( const std::vector& aSymbolPins ) { // Default pin sequence: model pins are the same as symbol pins. // Excess model pins are set as Not Connected. @@ -1225,7 +1225,7 @@ bool SIM_MODEL::InferSimModel( T& aSymbol, std::vector* aFields, bool wxString library = GetFieldValue( aFields, SIM_LIBRARY_FIELD, aResolve ); wxString modelName = GetFieldValue( aFields, SIM_NAME_FIELD, aResolve ); wxString value = GetFieldValue( aFields, SIM_VALUE_FIELD, aResolve ); - std::vector pins = aSymbol.GetAllLibPins(); + std::vector pins = aSymbol.GetAllLibPins(); *aDeviceType = GetFieldValue( aFields, SIM_DEVICE_FIELD, aResolve ); *aModelType = GetFieldValue( aFields, SIM_DEVICE_SUBTYPE_FIELD, aResolve ); @@ -1527,7 +1527,7 @@ void SIM_MODEL::MigrateSimModel( T& aSymbol, const PROJECT* aProject ) }; auto generateDefaultPinMapFromSymbol = - []( const std::vector& sourcePins ) + []( const std::vector& sourcePins ) { wxString pinMap; @@ -1549,7 +1549,7 @@ void SIM_MODEL::MigrateSimModel( T& aSymbol, const PROJECT* aProject ) wxString prefix = aSymbol.GetPrefix(); SCH_FIELD* valueField = aSymbol.FindField( wxT( "Value" ) ); - std::vector sourcePins = aSymbol.GetAllLibPins(); + std::vector sourcePins = aSymbol.GetAllLibPins(); bool sourcePinsSorted = false; auto lazySortSourcePins = @@ -1558,7 +1558,7 @@ void SIM_MODEL::MigrateSimModel( T& aSymbol, const PROJECT* aProject ) if( !sourcePinsSorted ) { std::sort( sourcePins.begin(), sourcePins.end(), - []( const LIB_PIN* lhs, const LIB_PIN* rhs ) + []( const SCH_PIN* lhs, const SCH_PIN* rhs ) { return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0; } ); diff --git a/eeschema/sim/sim_model.h b/eeschema/sim/sim_model.h index 30b4630bc1..5a43eace12 100644 --- a/eeschema/sim/sim_model.h +++ b/eeschema/sim/sim_model.h @@ -30,9 +30,8 @@ #include #include -#include #include -#include +#include // Must be included after sch_field.h (exactly eda_shape.h) to avoid a colliding // declaration with a window header (under msys2) @@ -44,6 +43,7 @@ struct SPICE_ITEM; class SPICE_GENERATOR; class SIM_MODEL_SERIALIZER; class PROJECT; +class REPORTER; #define SIM_REFERENCE_FIELD wxT( "Reference" ) @@ -410,20 +410,20 @@ public: static TYPE ReadTypeFromFields( const std::vector& aFields, REPORTER& aReporter ); - static std::unique_ptr Create( TYPE aType, const std::vector& aPins, + static std::unique_ptr Create( TYPE aType, const std::vector& aPins, REPORTER& aReporter ); static std::unique_ptr Create( const SIM_MODEL* aBaseModel, - const std::vector& aPins, + const std::vector& aPins, REPORTER& aReporter ); static std::unique_ptr Create( const SIM_MODEL* aBaseModel, - const std::vector& aPins, + const std::vector& aPins, const std::vector& aFields, REPORTER& aReporter ); static std::unique_ptr Create( const std::vector& aFields, - const std::vector& aPins, + const std::vector& aPins, bool aResolved, REPORTER& aReporter ); static std::string GetFieldValue( const std::vector* aFields, @@ -446,7 +446,7 @@ public: SIM_MODEL& operator=(SIM_MODEL&& aOther ) = delete; void ReadDataFields( const std::vector* aFields, - const std::vector& aPins ); + const std::vector& aPins ); void WriteFields( std::vector& aFields ) const; @@ -529,7 +529,7 @@ protected: SIM_MODEL( TYPE aType, std::unique_ptr aSpiceGenerator, std::unique_ptr aSerializer ); - void createPins( const std::vector& aSymbolPins ); + void createPins( const std::vector& aSymbolPins ); virtual int doFindParam( const std::string& aParamName ) const; virtual void doSetParamValue( int aParamIndex, const std::string& aValue ); diff --git a/eeschema/symbol.h b/eeschema/symbol.h index 98a474d988..738a383524 100644 --- a/eeschema/symbol.h +++ b/eeschema/symbol.h @@ -121,13 +121,13 @@ public: * Set or clear the pin name visibility flag. */ void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; } - bool GetShowPinNames() const { return m_showPinNames; } + virtual bool GetShowPinNames() const { return m_showPinNames; } /** * Set or clear the pin number visibility flag. */ void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; } - bool GetShowPinNumbers() const { return m_showPinNumbers; } + virtual bool GetShowPinNumbers() const { return m_showPinNumbers; } /** * Set or clear the exclude from simulation flag. diff --git a/eeschema/symbol_checker.cpp b/eeschema/symbol_checker.cpp index 5076371960..2b59fb2f7d 100644 --- a/eeschema/symbol_checker.cpp +++ b/eeschema/symbol_checker.cpp @@ -28,7 +28,7 @@ #include // helper function to sort pins by pin num -static bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst ); +static bool sort_by_pin_number( const SCH_PIN* ref, const SCH_PIN* tst ); static void CheckLibSymbolGraphics( LIB_SYMBOL* aSymbol, std::vector& aMessages, EDA_DRAW_FRAME* aUnitsProvider ); @@ -70,8 +70,7 @@ void CheckLibSymbol( LIB_SYMBOL* aSymbol, std::vector& aMessages, aMessages.push_back( msg ); } - std::vector pinList; - aSymbol->GetPins( pinList ); + std::vector pinList = aSymbol->GetPins(); // Test for duplicates: // Sort pins by pin num, so 2 duplicate pins @@ -88,8 +87,8 @@ void CheckLibSymbol( LIB_SYMBOL* aSymbol, std::vector& aMessages, for( unsigned ii = 1; ii < pinList.size(); ii++ ) { - LIB_PIN* pin = pinList[ii - 1]; - LIB_PIN* next = pinList[ii]; + SCH_PIN* pin = pinList[ii - 1]; + SCH_PIN* next = pinList[ii]; if( pin->GetNumber() != next->GetNumber() ) continue; @@ -207,7 +206,7 @@ void CheckLibSymbol( LIB_SYMBOL* aSymbol, std::vector& aMessages, aMessages.push_back( msg ); } - LIB_PIN* pin = pinList[0]; + SCH_PIN* pin = pinList[0]; if( pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_IN && pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_OUT ) @@ -226,7 +225,7 @@ void CheckLibSymbol( LIB_SYMBOL* aSymbol, std::vector& aMessages, } - for( LIB_PIN* pin : pinList ) + for( SCH_PIN* pin : pinList ) { wxString pinName = pin->GetName(); @@ -408,7 +407,7 @@ void CheckLibSymbolGraphics( LIB_SYMBOL* aSymbol, std::vector& aMessag } -bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst ) +bool sort_by_pin_number( const SCH_PIN* ref, const SCH_PIN* tst ) { // Use number as primary key int test = ref->GetNumber().Cmp( tst->GetNumber() ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index c6681198a9..17d1566735 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1385,7 +1385,7 @@ void SYMBOL_EDIT_FRAME::FocusOnItem( SCH_ITEM* aItem ) if( m_symbol ) { - for( LIB_PIN* pin : m_symbol->GetAllLibPins() ) + for( SCH_PIN* pin : m_symbol->GetAllLibPins() ) { if( pin->m_Uuid == lastBrightenedItemID ) lastItem = pin; diff --git a/eeschema/tools/backannotate.cpp b/eeschema/tools/backannotate.cpp index 9a2c846a61..8f1d4789ed 100644 --- a/eeschema/tools/backannotate.cpp +++ b/eeschema/tools/backannotate.cpp @@ -593,10 +593,11 @@ static SPIN_STYLE orientLabel( SCH_PIN* aPin ) // Initial orientation from the pin switch( aPin->GetLibPin()->GetOrientation() ) { + default: + case PIN_ORIENTATION::PIN_RIGHT: spin = SPIN_STYLE::LEFT; break; case PIN_ORIENTATION::PIN_UP: spin = SPIN_STYLE::BOTTOM; break; case PIN_ORIENTATION::PIN_DOWN: spin = SPIN_STYLE::UP; break; case PIN_ORIENTATION::PIN_LEFT: spin = SPIN_STYLE::RIGHT; break; - case PIN_ORIENTATION::PIN_RIGHT: spin = SPIN_STYLE::LEFT; break; } // Reorient based on the actual symbol orientation now diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index 1b9b0cf7a2..8f486e7f25 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -345,7 +345,7 @@ TOOL_ACTION EE_ACTIONS::placeSymbolPin( TOOL_ACTION_ARGS() .Tooltip( _( "Add a pin" ) ) .Icon( BITMAPS::pin ) .Flags( AF_ACTIVATE ) - .Parameter( LIB_PIN_T ) ); + .Parameter( SCH_PIN_T ) ); TOOL_ACTION EE_ACTIONS::placeSymbolText( TOOL_ACTION_ARGS() .Name( "eeschema.SymbolDrawing.placeSymbolText" ) diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index 846813a068..6620d41896 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -364,7 +364,6 @@ GRID_HELPER_GRIDS EE_GRID_HELPER::GetItemGrid( const EDA_ITEM* aItem ) const switch( aItem->Type() ) { case LIB_SYMBOL_T: - case LIB_PIN_T: case SCH_SYMBOL_T: case SCH_PIN_T: case SCH_SHEET_PIN_T: diff --git a/eeschema/tools/ee_selection.cpp b/eeschema/tools/ee_selection.cpp index 880e86628d..263cd9ae49 100644 --- a/eeschema/tools/ee_selection.cpp +++ b/eeschema/tools/ee_selection.cpp @@ -65,11 +65,11 @@ EDA_ITEM* EE_SELECTION::GetTopLeftItem( bool onlyModules ) const for( EDA_ITEM* item : m_items ) { SCH_ITEM* sch_item = dynamic_cast( item ); - LIB_PIN* lib_pin = dynamic_cast( item ); + SCH_PIN* pin = dynamic_cast( item ); // Prefer connection points (which should remain on grid) - if( ( sch_item && sch_item->IsConnectable() ) || lib_pin ) + if( ( sch_item && sch_item->IsConnectable() ) || pin ) processItem( item, &topLeftConnectedItem, &topLeftConnectedPos ); processItem( item, &topLeftItem, &topLeftPos ); diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index e5f323a10d..13978de5ef 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -571,7 +571,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) m_selection = RequestSelection( { SCH_SHAPE_T, SCH_TEXT_T, SCH_TEXTBOX_T, - LIB_PIN_T, + SCH_PIN_T, SCH_FIELD_T } ); } } @@ -666,12 +666,13 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) switch( pin->GetOrientation() ) { - case PIN_ORIENTATION::PIN_LEFT: - stub = VECTOR2I( 1 * wireGrid.x, 0 ); - break; + default: case PIN_ORIENTATION::PIN_RIGHT: stub = VECTOR2I( -1 * wireGrid.x, 0 ); break; + case PIN_ORIENTATION::PIN_LEFT: + stub = VECTOR2I( 1 * wireGrid.x, 0 ); + break; case PIN_ORIENTATION::PIN_UP: stub = VECTOR2I( 0, 1 * wireGrid.y ); break; @@ -731,12 +732,13 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) switch( pin->GetOrientation() ) { - case PIN_ORIENTATION::PIN_LEFT: - label->SetSpinStyle( SPIN_STYLE::SPIN::RIGHT ); - break; + default: case PIN_ORIENTATION::PIN_RIGHT: label->SetSpinStyle( SPIN_STYLE::SPIN::LEFT ); break; + case PIN_ORIENTATION::PIN_LEFT: + label->SetSpinStyle( SPIN_STYLE::SPIN::RIGHT ); + break; case PIN_ORIENTATION::PIN_UP: label->SetSpinStyle( SPIN_STYLE::SPIN::BOTTOM ); break; @@ -1085,9 +1087,9 @@ void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I continue; } } - else if( item->Type() == LIB_PIN_T ) + else if( item->Type() == SCH_PIN_T ) { - if( !static_cast( item )->IsVisible() + if( !static_cast( item )->IsVisible() && !symbolEditorFrame->GetShowInvisiblePins() ) { collector.Remove( i ); @@ -1607,7 +1609,6 @@ bool EE_SELECTION_TOOL::itemPassesFilter( EDA_ITEM* aItem ) case SCH_PIN_T: case SCH_SHEET_PIN_T: - case LIB_PIN_T: if( !m_filter.pins ) return false; @@ -2438,6 +2439,15 @@ bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos, { const SCH_PIN* pin = static_cast( aItem ); + if( symEditFrame ) + { + if( pin->GetUnit() && pin->GetUnit() != symEditFrame->GetUnit() ) + return false; + + if( pin->GetBodyStyle() && pin->GetBodyStyle() != symEditFrame->GetBodyStyle() ) + return false; + } + if( !pin->IsVisible() && !m_frame->GetShowAllPins() ) return false; @@ -2481,7 +2491,6 @@ bool EE_SELECTION_TOOL::Selectable( const EDA_ITEM* aItem, const VECTOR2I* aPos, case SCH_SHAPE_T: case SCH_TEXT_T: case SCH_TEXTBOX_T: - case LIB_PIN_T: if( symEditFrame ) { const SCH_ITEM* sch_item = static_cast( aItem ); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index be785b4122..50dfe6dd0c 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -144,7 +144,7 @@ private: EE_SELECTION_TOOL* selTool = getToolManager()->GetTool(); EE_SELECTION& selection = selTool->GetSelection(); SCH_PIN* pin = dynamic_cast( selection.Front() ); - LIB_PIN* libPin = pin ? pin->GetLibPin() : nullptr; + SCH_PIN* libPin = pin ? pin->GetLibPin() : nullptr; Clear(); @@ -2054,6 +2054,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) break; case SCH_NO_CONNECT_T: + case SCH_PIN_T: break; default: // Unexpected item diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 33f43fdf5d..9c3a0a72b9 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -570,7 +570,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent ) { try { - LIB_PIN* pin = static_cast( item )->GetLibPin(); + SCH_PIN* pin = static_cast( item )->GetLibPin(); SCH_SYMBOL* symbol = static_cast( item->GetParent() ); wxString msg; @@ -2110,16 +2110,16 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) for( EDA_ITEM* item : selection.Items() ) { SCH_ITEM* sch_item = dynamic_cast( item ); - LIB_PIN* lib_pin = dynamic_cast( item ); + SCH_PIN* pin = dynamic_cast( item ); if( sch_item && sch_item->IsConnectable() ) { for( const VECTOR2I& pt : sch_item->GetConnectionPoints() ) processPt( pt ); } - else if( lib_pin ) + else if( pin ) { - processPt( lib_pin->GetPosition() ); + processPt( pin->GetPosition() ); } } diff --git a/eeschema/tools/symbol_editor_drawing_tools.cpp b/eeschema/tools/symbol_editor_drawing_tools.cpp index 8c6d6ad739..b5e61b0a58 100644 --- a/eeschema/tools/symbol_editor_drawing_tools.cpp +++ b/eeschema/tools/symbol_editor_drawing_tools.cpp @@ -81,7 +81,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) { KICAD_T type = aEvent.Parameter(); auto* settings = Pgm().GetSettingsManager().GetAppSettings(); - auto* pinTool = type == LIB_PIN_T ? m_toolMgr->GetTool() : nullptr; + auto* pinTool = type == SCH_PIN_T ? m_toolMgr->GetTool() : nullptr; if( m_inTwoClickPlace ) return 0; @@ -208,7 +208,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) switch( type ) { - case LIB_PIN_T: + case SCH_PIN_T: { item = pinTool->CreatePin( VECTOR2I( cursorPos.x, -cursorPos.y ), symbol ); g_lastPinWeakPtr = item; @@ -281,8 +281,8 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) switch( item->Type() ) { - case LIB_PIN_T: - pinTool->PlacePin( static_cast( item ) ); + case SCH_PIN_T: + pinTool->PlacePin( static_cast( item ) ); item->ClearEditFlags(); commit.Push( _( "Add Pin" ) ); break; @@ -830,15 +830,13 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent ) { SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool(); LIB_SYMBOL* symbol = m_frame->GetCurSymbol(); - LIB_PIN* sourcePin = nullptr; + SCH_PIN* sourcePin = nullptr; if( !symbol ) return 0; // See if we have a pin matching our weak ptr - std::vector pins = symbol->GetAllLibPins(); - - for( LIB_PIN* test : pins ) + for( SCH_PIN* test : symbol->GetAllLibPins() ) { if( (void*) test == g_lastPinWeakPtr ) { @@ -849,7 +847,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem( const TOOL_EVENT& aEvent ) if( sourcePin ) { - LIB_PIN* pin = pinTool->RepeatPin( sourcePin ); + SCH_PIN* pin = pinTool->RepeatPin( sourcePin ); g_lastPinWeakPtr = pin; m_toolMgr->RunAction( EE_ACTIONS::clearSelection ); diff --git a/eeschema/tools/symbol_editor_edit_tool.cpp b/eeschema/tools/symbol_editor_edit_tool.cpp index 20b203c404..a1c6d11a63 100644 --- a/eeschema/tools/symbol_editor_edit_tool.cpp +++ b/eeschema/tools/symbol_editor_edit_tool.cpp @@ -274,7 +274,7 @@ static std::vector nonFields = SCH_SHAPE_T, SCH_TEXT_T, SCH_TEXTBOX_T, - LIB_PIN_T + SCH_PIN_T }; @@ -298,9 +298,9 @@ int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) for( EDA_ITEM* item : items ) { - if( item->Type() == LIB_PIN_T ) + if( item->Type() == SCH_PIN_T ) { - LIB_PIN* curr_pin = static_cast( item ); + SCH_PIN* curr_pin = static_cast( item ); VECTOR2I pos = curr_pin->GetPosition(); toDelete.insert( curr_pin ); @@ -313,12 +313,7 @@ int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) got_unit[curr_pin->GetUnit()] = true; - int curr_bodyStyle = curr_pin->GetBodyStyle(); - ELECTRICAL_PINTYPE etype = curr_pin->GetType(); - wxString name = curr_pin->GetName(); - std::vector pins = symbol->GetAllLibPins(); - - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : symbol->GetAllLibPins() ) { if( got_unit[pin->GetUnit()] ) continue; @@ -326,13 +321,13 @@ int SYMBOL_EDITOR_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) if( pin->GetPosition() != pos ) continue; - if( pin->GetBodyStyle() != curr_bodyStyle ) + if( pin->GetBodyStyle() != curr_pin->GetBodyStyle() ) continue; - if( pin->GetType() != etype ) + if( pin->GetType() != curr_pin->GetType() ) continue; - if( pin->GetName() != name ) + if( pin->GetName() != curr_pin->GetName() ) continue; toDelete.insert( pin ); @@ -480,9 +475,9 @@ int SYMBOL_EDITOR_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) switch( item->Type() ) { - case LIB_PIN_T: + case SCH_PIN_T: if( SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool() ) - pinTool->EditPinProperties( (LIB_PIN*) item ); + pinTool->EditPinProperties( static_cast( item ) ); break; @@ -637,7 +632,7 @@ void SYMBOL_EDITOR_EDIT_TOOL::editSymbolProperties() } } -void SYMBOL_EDITOR_EDIT_TOOL::handlePinDuplication( LIB_PIN* aOldPin, LIB_PIN* aNewPin, +void SYMBOL_EDITOR_EDIT_TOOL::handlePinDuplication( SCH_PIN* aOldPin, SCH_PIN* aNewPin, int& aSymbolLastPinNumber ) { if( !aNewPin->GetNumber().IsEmpty() ) @@ -905,9 +900,9 @@ int SYMBOL_EDITOR_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) SCH_ITEM* oldItem = static_cast( selection.GetItem( ii ) ); SCH_ITEM* newItem = oldItem->Duplicate(); - if( newItem->Type() == LIB_PIN_T ) + if( newItem->Type() == SCH_PIN_T ) { - LIB_PIN* newPin = static_cast( newItem ); + SCH_PIN* newPin = static_cast( newItem ); if( !newPin->GetNumber().IsEmpty() ) newPin->SetNumber( wxString::Format( wxT( "%i" ), symbol->GetMaxPinNumber() + 1 ) ); diff --git a/eeschema/tools/symbol_editor_edit_tool.h b/eeschema/tools/symbol_editor_edit_tool.h index f498eabce0..d741d5152a 100644 --- a/eeschema/tools/symbol_editor_edit_tool.h +++ b/eeschema/tools/symbol_editor_edit_tool.h @@ -70,7 +70,7 @@ private: void editTextBoxProperties( SCH_ITEM* aItem ); void editFieldProperties( SCH_FIELD* aField ); void editSymbolProperties(); - void handlePinDuplication(LIB_PIN* aOldPin, LIB_PIN* aNewPin, int &aSymbolLastPinNumber ); + void handlePinDuplication(SCH_PIN* aOldPin, SCH_PIN* aNewPin, int &aSymbolLastPinNumber ); ///< Set up handlers for various events. void setTransitions() override; diff --git a/eeschema/tools/symbol_editor_move_tool.cpp b/eeschema/tools/symbol_editor_move_tool.cpp index d2e062e07a..eafb2c3063 100644 --- a/eeschema/tools/symbol_editor_move_tool.cpp +++ b/eeschema/tools/symbol_editor_move_tool.cpp @@ -179,23 +179,21 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM if( m_frame->SynchronizePins() && ( lib_item->GetEditFlags() & IS_PASTED ) == 0 ) { - std::set sync_pins; + std::set sync_pins; for( EDA_ITEM* sel_item : selection ) { lib_item = static_cast( sel_item ); - if( lib_item->Type() == LIB_PIN_T ) + if( lib_item->Type() == SCH_PIN_T ) { - LIB_PIN* cur_pin = static_cast( lib_item ); + SCH_PIN* cur_pin = static_cast( lib_item ); LIB_SYMBOL* symbol = m_frame->GetCurSymbol(); std::vector got_unit( symbol->GetUnitCount() + 1 ); got_unit[cur_pin->GetUnit()] = true; - std::vector pins = symbol->GetAllLibPins(); - - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : symbol->GetAllLibPins() ) { if( !got_unit[pin->GetUnit()] && pin->GetPosition() == cur_pin->GetPosition() @@ -211,7 +209,7 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM } } - for( LIB_PIN* pin : sync_pins ) + for( SCH_PIN* pin : sync_pins ) m_selectionTool->AddItemToSel( pin, true /*quiet mode*/ ); } @@ -322,13 +320,13 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM || evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) ) { - if( selection.GetSize() == 1 && selection.Front()->Type() == LIB_PIN_T ) + if( selection.GetSize() == 1 && selection.Front()->Type() == SCH_PIN_T ) { SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool(); try { - LIB_PIN* curr_pin = (LIB_PIN*) selection.Front(); + SCH_PIN* curr_pin = static_cast( selection.Front() ); if( pinTool->PlacePin( curr_pin ) ) { @@ -479,7 +477,7 @@ int SYMBOL_EDITOR_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent ) if( delta != VECTOR2I( 0, 0 ) ) doMoveItem( item, delta ); - if( LIB_PIN* pin = dynamic_cast( item ) ) + if( SCH_PIN* pin = dynamic_cast( item ) ) { int length = pin->GetLength(); int pinGrid; diff --git a/eeschema/tools/symbol_editor_pin_tool.cpp b/eeschema/tools/symbol_editor_pin_tool.cpp index 79e9bd043a..c6967c8d4b 100644 --- a/eeschema/tools/symbol_editor_pin_tool.cpp +++ b/eeschema/tools/symbol_editor_pin_tool.cpp @@ -103,7 +103,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::Init() return editor->IsSymbolEditable() && !editor->IsSymbolAlias(); }; - auto singlePinCondition = EE_CONDITIONS::Count( 1 ) && EE_CONDITIONS::OnlyTypes( { LIB_PIN_T } ); + auto singlePinCondition = EE_CONDITIONS::Count( 1 ) && EE_CONDITIONS::OnlyTypes( { SCH_PIN_T } ); CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); @@ -116,9 +116,9 @@ bool SYMBOL_EDITOR_PIN_TOOL::Init() } -bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin ) +bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( SCH_PIN* aPin ) { - LIB_PIN original_pin( *aPin ); + SCH_PIN original_pin( *aPin ); DIALOG_PIN_PROPERTIES dlg( m_frame, aPin ); SCH_COMMIT commit( m_frame ); LIB_SYMBOL* parentSymbol = static_cast( aPin->GetParentSymbol() ); @@ -131,9 +131,6 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin ) if( !aPin->IsNew() && m_frame->SynchronizePins() && parentSymbol ) { - std::vector pinList; - parentSymbol->GetPins( pinList ); - // a pin can have a unit id = 0 (common to all units) to unit count // So we need a buffer size = GetUnitCount()+1 to store a value in a vector // when using the unit id of a pin as index @@ -141,7 +138,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin ) got_unit[static_cast(aPin->GetUnit())] = true; - for( LIB_PIN* other : pinList ) + for( SCH_PIN* other : parentSymbol->GetPins() ) { if( other == aPin ) continue; @@ -209,14 +206,14 @@ bool SYMBOL_EDITOR_PIN_TOOL::EditPinProperties( LIB_PIN* aPin ) } -bool SYMBOL_EDITOR_PIN_TOOL::PlacePin( LIB_PIN* aPin ) +bool SYMBOL_EDITOR_PIN_TOOL::PlacePin( SCH_PIN* aPin ) { LIB_SYMBOL* symbol = m_frame->GetCurSymbol(); bool ask_for_pin = true; // Test for another pin in same position in other units - std::vector pins = symbol->GetAllLibPins(); + std::vector pins = symbol->GetAllLibPins(); - for( LIB_PIN* test : pins ) + for( SCH_PIN* test : pins ) { if( test == aPin || aPin->GetPosition() != test->GetPosition() || test->GetEditFlags() ) continue; @@ -265,7 +262,7 @@ bool SYMBOL_EDITOR_PIN_TOOL::PlacePin( LIB_PIN* aPin ) } // Put linked pins in new position, and clear flags - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : pins ) { if( ( pin->GetEditFlags() & IS_LINKED ) == 0 ) continue; @@ -284,11 +281,11 @@ bool SYMBOL_EDITOR_PIN_TOOL::PlacePin( LIB_PIN* aPin ) /* * Create a new pin. */ -LIB_PIN* SYMBOL_EDITOR_PIN_TOOL::CreatePin( const VECTOR2I& aPosition, LIB_SYMBOL* aSymbol ) +SCH_PIN* SYMBOL_EDITOR_PIN_TOOL::CreatePin( const VECTOR2I& aPosition, LIB_SYMBOL* aSymbol ) { aSymbol->ClearTempFlags(); - LIB_PIN* pin = new LIB_PIN( aSymbol ); + SCH_PIN* pin = new SCH_PIN( aSymbol ); pin->SetFlags( IS_NEW ); @@ -317,10 +314,10 @@ LIB_PIN* SYMBOL_EDITOR_PIN_TOOL::CreatePin( const VECTOR2I& aPosition, LIB_SYMBO } -void SYMBOL_EDITOR_PIN_TOOL::CreateImagePins( LIB_PIN* aPin ) +void SYMBOL_EDITOR_PIN_TOOL::CreateImagePins( SCH_PIN* aPin ) { int ii; - LIB_PIN* newPin; + SCH_PIN* newPin; // if "synchronize pins editing" option is off, do not create any similar pin for other // units and/or shapes: each unit is edited regardless other units or body @@ -340,7 +337,7 @@ void SYMBOL_EDITOR_PIN_TOOL::CreateImagePins( LIB_PIN* aPin ) if( ii == aPin->GetUnit() ) continue; - newPin = static_cast( aPin->Duplicate() ); + newPin = static_cast( aPin->Duplicate() ); // To avoid mistakes, gives this pin a new pin number because // it does no have the save pin number as the master pin @@ -373,15 +370,14 @@ int SYMBOL_EDITOR_PIN_TOOL::PushPinProperties( const TOOL_EVENT& aEvent ) { LIB_SYMBOL* symbol = m_frame->GetCurSymbol(); EE_SELECTION& selection = m_selectionTool->GetSelection(); - LIB_PIN* sourcePin = dynamic_cast( selection.Front() ); + SCH_PIN* sourcePin = dynamic_cast( selection.Front() ); if( !sourcePin ) return 0; saveCopyInUndoList( symbol, UNDO_REDO::LIBEDIT ); - std::vector pins = symbol->GetAllLibPins(); - for( LIB_PIN* pin : pins ) + for( SCH_PIN* pin : symbol->GetAllLibPins() ) { if( pin == sourcePin ) continue; @@ -409,9 +405,9 @@ int SYMBOL_EDITOR_PIN_TOOL::PushPinProperties( const TOOL_EVENT& aEvent ) // Create a new pin based on the previous pin with an incremented pin number. -LIB_PIN* SYMBOL_EDITOR_PIN_TOOL::RepeatPin( const LIB_PIN* aSourcePin ) +SCH_PIN* SYMBOL_EDITOR_PIN_TOOL::RepeatPin( const SCH_PIN* aSourcePin ) { - LIB_PIN* pin = (LIB_PIN*) aSourcePin->Duplicate(); + SCH_PIN* pin = static_cast( aSourcePin->Duplicate() ); VECTOR2I step; pin->ClearFlags(); @@ -421,10 +417,11 @@ LIB_PIN* SYMBOL_EDITOR_PIN_TOOL::RepeatPin( const LIB_PIN* aSourcePin ) switch( pin->GetOrientation() ) { + default: + case PIN_ORIENTATION::PIN_RIGHT: step.y = schIUScale.MilsToIU(-settings->m_Repeat.pin_step); break; case PIN_ORIENTATION::PIN_UP: step.x = schIUScale.MilsToIU(settings->m_Repeat.pin_step); break; case PIN_ORIENTATION::PIN_DOWN: step.x = schIUScale.MilsToIU(settings->m_Repeat.pin_step); break; case PIN_ORIENTATION::PIN_LEFT: step.y = schIUScale.MilsToIU(-settings->m_Repeat.pin_step); break; - case PIN_ORIENTATION::PIN_RIGHT: step.y = schIUScale.MilsToIU(-settings->m_Repeat.pin_step); break; } pin->Move( step ); diff --git a/eeschema/tools/symbol_editor_pin_tool.h b/eeschema/tools/symbol_editor_pin_tool.h index 13937363d5..31c9bed253 100644 --- a/eeschema/tools/symbol_editor_pin_tool.h +++ b/eeschema/tools/symbol_editor_pin_tool.h @@ -41,13 +41,13 @@ public: /// @copydoc TOOL_INTERACTIVE::Init() bool Init() override; - LIB_PIN* CreatePin( const VECTOR2I& aPosition, LIB_SYMBOL* aSymbol ); - LIB_PIN* RepeatPin( const LIB_PIN* aSourcePin ); + SCH_PIN* CreatePin( const VECTOR2I& aPosition, LIB_SYMBOL* aSymbol ); + SCH_PIN* RepeatPin( const SCH_PIN* aSourcePin ); - bool PlacePin( LIB_PIN* aPin ); - void CreateImagePins( LIB_PIN* aPin ); + bool PlacePin( SCH_PIN* aPin ); + void CreateImagePins( SCH_PIN* aPin ); - bool EditPinProperties( LIB_PIN* aPin ); + bool EditPinProperties( SCH_PIN* aPin ); int PushPinProperties( const TOOL_EVENT& aEvent ); private: diff --git a/eeschema/widgets/panel_symbol_chooser.cpp b/eeschema/widgets/panel_symbol_chooser.cpp index dc48db4ec6..68686ec74c 100644 --- a/eeschema/widgets/panel_symbol_chooser.cpp +++ b/eeschema/widgets/panel_symbol_chooser.cpp @@ -604,17 +604,11 @@ void PANEL_SYMBOL_CHOOSER::populateFootprintSelector( LIB_ID const& aLibId ) if( symbol != nullptr ) { - std::vector temp_pins; - SCH_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD ); - wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" ); + int pinCount = symbol->GetPins( 0 /* all units */, 1 /* single bodyStyle */ ).size(); + SCH_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD ); + wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" ); - // All units, but only a single De Morgan variant. - if( symbol->HasAlternateBodyStyle() ) - symbol->GetPins( temp_pins, 0, 1 ); - else - symbol->GetPins( temp_pins ); - - m_fp_sel_ctrl->FilterByPinCount( temp_pins.size() ); + m_fp_sel_ctrl->FilterByPinCount( pinCount ); m_fp_sel_ctrl->FilterByFootprintFilters( symbol->GetFPFilters(), true ); m_fp_sel_ctrl->SetDefaultFootprint( fp_name ); m_fp_sel_ctrl->UpdateList(); diff --git a/eeschema/widgets/pin_shape_combobox.cpp b/eeschema/widgets/pin_shape_combobox.cpp index 74ae31b76f..b6b3689ef1 100644 --- a/eeschema/widgets/pin_shape_combobox.cpp +++ b/eeschema/widgets/pin_shape_combobox.cpp @@ -29,7 +29,7 @@ #include "pin_shape_combobox.h" #include -#include +#include PinShapeComboBox::PinShapeComboBox( wxWindow* parent, wxWindowID id, diff --git a/eeschema/widgets/pin_type_combobox.cpp b/eeschema/widgets/pin_type_combobox.cpp index 686b9eac75..649f9843e6 100644 --- a/eeschema/widgets/pin_type_combobox.cpp +++ b/eeschema/widgets/pin_type_combobox.cpp @@ -29,7 +29,7 @@ #include "pin_type_combobox.h" #include -#include +#include PinTypeComboBox::PinTypeComboBox( wxWindow* parent, wxWindowID id, diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 5e510fe7f2..103b9cc440 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -150,7 +150,7 @@ enum KICAD_T SCH_FIELD_T, SCH_TEXT_T, SCH_TEXTBOX_T, - LIB_PIN_T, + SCH_PIN_T, // Schematic draw Items. The order of these items effects the sort order. // It is currently ordered to mimic the old Eeschema locate behavior where @@ -171,7 +171,6 @@ enum KICAD_T SCH_SYMBOL_T, SCH_SHEET_PIN_T, SCH_SHEET_T, - SCH_PIN_T, // Be prudent with these types: // they should be used only to locate a specific field type among SCH_FIELD_Ts @@ -409,7 +408,6 @@ constexpr bool IsEeschemaType( const KICAD_T aType ) case SCHEMATIC_T: case LIB_SYMBOL_T: - case LIB_PIN_T: return true; default: diff --git a/qa/tests/eeschema/lib_field_test_utils.h b/qa/tests/eeschema/lib_field_test_utils.h index cada2a6b75..59c290206b 100644 --- a/qa/tests/eeschema/lib_field_test_utils.h +++ b/qa/tests/eeschema/lib_field_test_utils.h @@ -32,6 +32,7 @@ #include #include +#include namespace BOOST_TEST_PRINT_NAMESPACE_OPEN diff --git a/qa/tests/eeschema/test_ee_item.cpp b/qa/tests/eeschema/test_ee_item.cpp index 975dec7ea6..78deba7e69 100644 --- a/qa/tests/eeschema/test_ee_item.cpp +++ b/qa/tests/eeschema/test_ee_item.cpp @@ -43,8 +43,7 @@ #include #include #include - -#include +#include #include @@ -53,7 +52,7 @@ class TEST_EE_ITEM_FIXTURE public: SCH_SHEET m_sheet; LIB_SYMBOL m_symbol; - LIB_PIN m_pin; + SCH_PIN m_pin; std::shared_ptr m_ercItem; TEST_EE_ITEM_FIXTURE() : @@ -113,10 +112,9 @@ public: "test aPin" ); case SCH_SHEET_T: return new SCH_SHEET(); - case LIB_PIN_T: return new LIB_PIN( &m_symbol ); + case SCH_PIN_T: return new SCH_PIN( &m_symbol ); case SCHEMATIC_T: - case SCH_PIN_T: case LIB_SYMBOL_T: return nullptr; default: diff --git a/qa/tests/eeschema/test_lib_part.cpp b/qa/tests/eeschema/test_lib_part.cpp index 6ea1a1fc64..12b13840d8 100644 --- a/qa/tests/eeschema/test_lib_part.cpp +++ b/qa/tests/eeschema/test_lib_part.cpp @@ -30,7 +30,8 @@ // Code under test #include -#include +#include +#include #include "lib_field_test_utils.h" @@ -425,9 +426,9 @@ BOOST_AUTO_TEST_CASE( Compare ) BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 ); m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_SHAPE_T].front() ); testPart.RemoveDrawItem( &testPart.GetDrawItems()[SCH_SHAPE_T].front() ); - m_part_no_data.AddDrawItem( new LIB_PIN( &m_part_no_data ) ); + m_part_no_data.AddDrawItem( new SCH_PIN( &m_part_no_data ) ); BOOST_CHECK( m_part_no_data.Compare( testPart, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) > 0 ); - m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[LIB_PIN_T].front() ); + m_part_no_data.RemoveDrawItem( &m_part_no_data.GetDrawItems()[SCH_PIN_T].front() ); // Footprint filter array comparison tests. wxArrayString footPrintFilters; @@ -529,7 +530,7 @@ BOOST_AUTO_TEST_CASE( GetUnitItems ) BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 1, 1 ).size() == 0 ); // A single unique unit with 1 pin common to all units and all body styles. - LIB_PIN* pin1 = new LIB_PIN( &m_part_no_data ); + SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data ); m_part_no_data.AddDrawItem( pin1 ); BOOST_CHECK( m_part_no_data.GetUnitDrawItems( 0, 0 ).size() == 1 ); @@ -543,7 +544,7 @@ BOOST_AUTO_TEST_CASE( GetUnitItems ) // Two unique units with pin 1 assigned to unit 1 and body style 1 and pin 2 assigned to // unit 2 and body style 1. - LIB_PIN* pin2 = new LIB_PIN( &m_part_no_data ); + SCH_PIN* pin2 = new SCH_PIN( &m_part_no_data ); m_part_no_data.SetUnitCount( 2 ); pin2->SetUnit( 2 ); pin2->SetBodyStyle( 2 ); @@ -571,7 +572,7 @@ BOOST_AUTO_TEST_CASE( GetUnitDrawItems ) BOOST_CHECK( m_part_no_data.GetUnitDrawItems().size() == 0 ); // A single unique unit with 1 pin common to all units and all body styles. - LIB_PIN* pin1 = new LIB_PIN( &m_part_no_data ); + SCH_PIN* pin1 = new SCH_PIN( &m_part_no_data ); pin1->SetNumber( "1" ); m_part_no_data.AddDrawItem( pin1 ); std::vector units = m_part_no_data.GetUnitDrawItems(); @@ -679,7 +680,7 @@ BOOST_AUTO_TEST_CASE( CopyConstructor ) BOOST_AUTO_TEST_CASE( IsPowerTest ) { std::unique_ptr symbol = std::make_unique( "power" ); - LIB_PIN* pin = new LIB_PIN( symbol.get() ); + SCH_PIN* pin = new SCH_PIN( symbol.get() ); pin->SetNumber( "1" ); pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN ); pin->SetVisible( false ); diff --git a/qa/tests/eeschema/test_sch_pin.cpp b/qa/tests/eeschema/test_sch_pin.cpp index 64cdc70da3..e9e690eaf0 100644 --- a/qa/tests/eeschema/test_sch_pin.cpp +++ b/qa/tests/eeschema/test_sch_pin.cpp @@ -36,7 +36,7 @@ public: { m_parent_part = new LIB_SYMBOL( "parent_part", nullptr ); - m_lib_pin = new LIB_PIN( m_parent_part ); + m_lib_pin = new SCH_PIN( m_parent_part ); m_parent_part->AddDrawItem( m_lib_pin ); // give the pin some kind of data we can use to test @@ -61,7 +61,7 @@ public: } LIB_SYMBOL* m_parent_part; - LIB_PIN* m_lib_pin; + SCH_PIN* m_lib_pin; SCH_SYMBOL* m_parent_symbol; SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us diff --git a/qa/tests/spice/test_sim_model_inference.cpp b/qa/tests/spice/test_sim_model_inference.cpp index dccad57967..1210036582 100644 --- a/qa/tests/spice/test_sim_model_inference.cpp +++ b/qa/tests/spice/test_sim_model_inference.cpp @@ -23,7 +23,8 @@ #include #include -#include +#include +#include class TEST_SIM_MODEL_INFERENCE { @@ -82,8 +83,8 @@ BOOST_AUTO_TEST_CASE( InferPassiveValues ) }; std::unique_ptr symbol = std::make_unique( "symbol", nullptr ); - symbol->AddDrawItem( new LIB_PIN( symbol.get() ) ); - symbol->AddDrawItem( new LIB_PIN( symbol.get() ) ); + symbol->AddDrawItem( new SCH_PIN( symbol.get() ) ); + symbol->AddDrawItem( new SCH_PIN( symbol.get() ) ); wxString deviceType; wxString modelType;