From 239f0214ac2fec20ae4edb11fe6d11ec63c30389 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 8 Apr 2022 12:05:27 -0400 Subject: [PATCH] Eeschema: add support for default schematic symbol instance data. Prior to fixing the schematic file change churn do to instance data changing to the last selected sheet instance, the symbol instance data was set rather than empty. This change allows for users to set the default instance data which is used for every new instance of the schematic. ADDED: Default schematic symbol instance data (unit and reference, value, and footprint fields) can be set to be used as the default settings for all new instances of the schematic. Fixes https://gitlab.com/kicad/code/kicad/-/issues/11113 --- eeschema/dialogs/dialog_sheet_properties.cpp | 30 +++++--- eeschema/dialogs/dialog_symbol_properties.cpp | 17 ++++- .../dialogs/dialog_symbol_properties_base.cpp | 9 ++- .../dialogs/dialog_symbol_properties_base.fbp | 69 ++++++++++++++++++- .../dialogs/dialog_symbol_properties_base.h | 3 +- eeschema/sch_file_versions.h | 3 +- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 45 ++++++++++++ .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 30 ++++---- eeschema/sch_sheet_path.cpp | 34 +++++++++ eeschema/sch_sheet_path.h | 13 +++- eeschema/sch_symbol.cpp | 50 +++++++++++--- eeschema/sch_symbol.h | 21 +++++- eeschema/schematic.keywords | 1 + 13 files changed, 281 insertions(+), 44 deletions(-) diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index fbfd491f3a..75ae1d3f68 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -372,14 +372,27 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataFromWindow() m_sheet->SetBorderColor( m_borderSwatch->GetSwatchColor() ); m_sheet->SetBackgroundColor( m_backgroundSwatch->GetSwatchColor() ); - SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetFullHierarchy(); SCH_SHEET_PATH instance = m_frame->GetCurrentSheet(); instance.push_back( m_sheet ); if( m_sheet->IsNew() ) + { m_sheet->AddInstance( instance ); + if( filename_changed ) + { + // Set the symbol instance data to the default for all new sheets and sub-sheets. + SCH_SHEET_LIST newInstances( m_sheet ); + + for( SCH_SHEET_PATH& newInstance : newInstances ) + { + instance = m_frame->GetCurrentSheet() + newInstance; + instance.SetSymbolInstancesToDefault(); + } + } + } + m_sheet->SetPageNumber( instance, m_pageNumberTextCtrl->GetValue() ); m_frame->TestDanglingEnds(); @@ -448,7 +461,6 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena bool renameFile = false; bool loadFromFile = false; bool clearAnnotation = false; - bool restoreSheet = false; bool isExistingSheet = false; SCH_SCREEN* useScreen = nullptr; SCH_SCREEN* oldScreen = nullptr; @@ -533,7 +545,8 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena { if( m_sheet->GetScreenCount() > 1 ) { - if( !IsOK( this, wxString::Format( _( "Create new file '%s' with contents of '%s'?" ), + if( !IsOK( this, wxString::Format( _( "Create new file '%s' with contents " + "of '%s'?" ), sheetFileName.GetFullName(), m_sheet->GetFileName() ) + wxT( "\n\n" ) @@ -604,18 +617,16 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena // No need to check for valid library IDs if we are using an existing screen. if( m_frame->CheckSheetForRecursion( tmpSheet.get(), ¤tSheet ) ) - { - if( restoreSheet ) - currentSheet.LastScreen()->Append( m_sheet ); - return false; - } // It's safe to set the sheet screen now. m_sheet->SetScreen( useScreen ); + // currentSheet.LastScreen()->Append( m_sheet ); } else if( loadFromFile ) { + bool restoreSheet = false; + if( isExistingSheet ) { // Temporarily remove the sheet from the current schematic page so that recursion @@ -642,8 +653,7 @@ bool DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged( const wxString& aNewFilena if( restoreSheet ) currentSheet.LastScreen()->Append( m_sheet ); - // The full hiearchy needs to be reloaded because any sub-sheet that occurred on - // file load will have new SCH_SHEET object pointers. + // The full hierarchy needs to be reloaded because due to the addition of a new sheet. fullHierarchy = m_frame->Schematic().GetFullHierarchy(); fullHierarchy.UpdateSheetInstances( sheetInstances ); } diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index 1556681569..65725865bc 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 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 @@ -794,6 +794,18 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow() } } + if( m_cbMakeDefaultInstance->IsChecked() ) + { + SYMBOL_INSTANCE_REFERENCE defaultInstance; + + defaultInstance.m_Unit = unit_selection; + defaultInstance.m_Reference = m_fields->at( REFERENCE_FIELD ).GetText(); + defaultInstance.m_Value = m_fields->at( VALUE_FIELD ).GetText(); + defaultInstance.m_Footprint = m_fields->at( FOOTPRINT_FIELD ).GetText(); + + m_symbol->SetDefaultInstance( defaultInstance ); + } + currentScreen->Append( m_symbol ); GetParent()->TestDanglingEnds(); GetParent()->UpdateItem( m_symbol, false, true ); @@ -1017,7 +1029,8 @@ void DIALOG_SYMBOL_PROPERTIES::OnPinTableCellEdited( wxGridEvent& aEvent ) { int row = aEvent.GetRow(); - if( m_pinGrid->GetCellValue( row, COL_ALT_NAME ) == m_dataModel->GetValue( row, COL_BASE_NAME ) ) + if( m_pinGrid->GetCellValue( row, COL_ALT_NAME ) == + m_dataModel->GetValue( row, COL_BASE_NAME ) ) m_dataModel->SetValue( row, COL_ALT_NAME, wxEmptyString ); // These are just to get the cells refreshed diff --git a/eeschema/dialogs/dialog_symbol_properties_base.cpp b/eeschema/dialogs/dialog_symbol_properties_base.cpp index bbf7413888..9c1948a335 100644 --- a/eeschema/dialogs/dialog_symbol_properties_base.cpp +++ b/eeschema/dialogs/dialog_symbol_properties_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.0) +// C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -137,7 +137,12 @@ DIALOG_SYMBOL_PROPERTIES_BASE::DIALOG_SYMBOL_PROPERTIES_BASE( wxWindow* parent, m_cbAlternateSymbol = new wxCheckBox( sbGeneralProps->GetStaticBox(), wxID_ANY, _("Alternate symbol (De Morgan)"), wxDefaultPosition, wxDefaultSize, 0 ); m_cbAlternateSymbol->SetToolTip( _("Use the alternate shape of this symbol.\nFor gates, this is the \"De Morgan\" conversion") ); - gbSizer1->Add( m_cbAlternateSymbol, wxGBPosition( 1, 0 ), wxGBSpan( 1, 2 ), wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); + gbSizer1->Add( m_cbAlternateSymbol, wxGBPosition( 1, 0 ), wxGBSpan( 1, 2 ), wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 ); + + m_cbMakeDefaultInstance = new wxCheckBox( sbGeneralProps->GetStaticBox(), wxID_ANY, _("Default for all sheet instances"), wxDefaultPosition, wxDefaultSize, 0 ); + m_cbMakeDefaultInstance->SetToolTip( _("Check to make the unit and reference, value, and\nfootprint fields the default for all sheet instances\nof this symbol") ); + + gbSizer1->Add( m_cbMakeDefaultInstance, wxGBPosition( 2, 0 ), wxGBSpan( 1, 2 ), wxBOTTOM|wxLEFT|wxRIGHT, 5 ); m_orientationLabel = new wxStaticText( sbGeneralProps->GetStaticBox(), wxID_ANY, _("Angle:"), wxDefaultPosition, wxDefaultSize, 0 ); m_orientationLabel->Wrap( -1 ); diff --git a/eeschema/dialogs/dialog_symbol_properties_base.fbp b/eeschema/dialogs/dialog_symbol_properties_base.fbp index 19bce97f6c..6c0c368cc2 100644 --- a/eeschema/dialogs/dialog_symbol_properties_base.fbp +++ b/eeschema/dialogs/dialog_symbol_properties_base.fbp @@ -784,7 +784,7 @@ 5 2 0 - wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT + wxEXPAND|wxLEFT|wxRIGHT|wxTOP 1 1 @@ -848,6 +848,73 @@ OnCheckBox + + 5 + 2 + 0 + wxBOTTOM|wxLEFT|wxRIGHT + 2 + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Default for all sheet instances + + 0 + + + 0 + + 1 + m_cbMakeDefaultInstance + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Check to make the unit and reference, value, and footprint fields the default for all sheet instances of this symbol + + wxFILTER_NONE + wxDefaultValidator + + + + + + 5 1 diff --git a/eeschema/dialogs/dialog_symbol_properties_base.h b/eeschema/dialogs/dialog_symbol_properties_base.h index ac8d893ccf..e6d956ad02 100644 --- a/eeschema/dialogs/dialog_symbol_properties_base.h +++ b/eeschema/dialogs/dialog_symbol_properties_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.0) +// C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -56,6 +56,7 @@ class DIALOG_SYMBOL_PROPERTIES_BASE : public DIALOG_SHIM wxStaticText* m_unitLabel; wxChoice* m_unitChoice; wxCheckBox* m_cbAlternateSymbol; + wxCheckBox* m_cbMakeDefaultInstance; wxStaticText* m_orientationLabel; wxChoice* m_orientationCtrl; wxStaticText* m_mirrorLabel; diff --git a/eeschema/sch_file_versions.h b/eeschema/sch_file_versions.h index e90eac1aa5..3b524432eb 100644 --- a/eeschema/sch_file_versions.h +++ b/eeschema/sch_file_versions.h @@ -79,4 +79,5 @@ //#define SEXPR_SCHEMATIC_FILE_VERSION 20220124 // netclass_flag -> directive_label //#define SEXPR_SCHEMATIC_FILE_VERSION 20220126 // Text boxes //#define SEXPR_SCHEMATIC_FILE_VERSION 20220328 // Text box start/end -> at/size -#define SEXPR_SCHEMATIC_FILE_VERSION 20220331 // Text colors +//#define SEXPR_SCHEMATIC_FILE_VERSION 20220331 // Text colors +#define SEXPR_SCHEMATIC_FILE_VERSION 20220404 // Default schematic symbol instance data. diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 06846df1e9..21cf2b9261 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -2541,6 +2541,51 @@ SCH_SYMBOL* SCH_SEXPR_PARSER::parseSchematicSymbol() NeedRIGHT(); break; + case T_default_instance: + { + SYMBOL_INSTANCE_REFERENCE defaultInstance; + + for( token = NextTok(); token != T_RIGHT; token = NextTok() ) + { + if( token != T_LEFT ) + Expecting( T_LEFT ); + + token = NextTok(); + + switch( token ) + { + case T_reference: + NeedSYMBOL(); + defaultInstance.m_Reference = FromUTF8(); + NeedRIGHT(); + break; + + case T_unit: + defaultInstance.m_Unit = parseInt( "symbol unit" ); + NeedRIGHT(); + break; + + case T_value: + NeedSYMBOL(); + defaultInstance.m_Value = FromUTF8(); + NeedRIGHT(); + break; + + case T_footprint: + NeedSYMBOL(); + defaultInstance.m_Footprint = FromUTF8(); + NeedRIGHT(); + break; + + default: + Expecting( "path, unit, value or footprint" ); + } + } + + symbol->SetDefaultInstance( defaultInstance ); + break; + } + case T_property: // The field parent symbol must be set and its orientation must be set before // the field positions are set. diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index b49abccdfe..926d4d49c2 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -685,9 +685,9 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa m_out->Print( 0, ")" ); } - int unit = ( aSymbol->GetInstanceReferences().size() == 0 ) ? - aSymbol->GetUnit() : - aSymbol->GetInstanceReferences()[0].m_Unit; + // The symbol unit is always set to the default instance regardless of the sheet instance + // to prevent file churn. + int unit = aSymbol->GetDefaultInstance().m_Unit; m_out->Print( 0, " (unit %d)", unit ); @@ -706,6 +706,13 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSymbol->m_Uuid.AsString() ) ); + m_out->Print( aNestLevel + 1, + "(default_instance (reference %s) (unit %d) (value %s) (footprint %s))\n", + m_out->Quotew( aSymbol->GetDefaultInstance().m_Reference ).c_str(), + aSymbol->GetDefaultInstance().m_Unit, + m_out->Quotew( aSymbol->GetDefaultInstance().m_Value ).c_str(), + m_out->Quotew( aSymbol->GetDefaultInstance().m_Footprint ).c_str() ); + m_nextFreeFieldId = MANDATORY_FIELDS; for( SCH_FIELD& field : aSymbol->GetFields() ) @@ -713,26 +720,19 @@ void SCH_SEXPR_PLUGIN::saveSymbol( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPa int id = field.GetId(); wxString value = field.GetText(); - // The instance fields are always set to the first sheet instance of the project to - // schematic file changes when switching sheet instances with the current project - // schematic. It does not solve the problem for schematics shared between projects. + // The instance fields are always set to the default instance regardless of the + // sheet instance to prevent file churn. if( id == REFERENCE_FIELD ) { - field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ? - value : - aSymbol->GetInstanceReferences()[0].m_Reference ); + field.SetText( aSymbol->GetDefaultInstance().m_Reference ); } else if( id == VALUE_FIELD ) { - field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ? - value : - aSymbol->GetInstanceReferences()[0].m_Value ); + field.SetText( aSymbol->GetDefaultInstance().m_Value ); } else if( id == FOOTPRINT_FIELD ) { - field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ? - value : - aSymbol->GetInstanceReferences()[0].m_Footprint ); + field.SetText( aSymbol->GetDefaultInstance().m_Footprint ); } try diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 5eb16f6bff..23ac681c8d 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -115,6 +115,19 @@ SCH_SHEET_PATH& SCH_SHEET_PATH::operator=( const SCH_SHEET_PATH& aOther ) } +SCH_SHEET_PATH SCH_SHEET_PATH::operator+( const SCH_SHEET_PATH& aOther ) +{ + SCH_SHEET_PATH retv = *this; + + size_t size = aOther.size(); + + for( size_t i = 0; i < size; i++ ) + retv.push_back( aOther.at( i ) ); + + return retv; +} + + void SCH_SHEET_PATH::initFromOther( const SCH_SHEET_PATH& aOther ) { m_sheets = aOther.m_sheets; @@ -193,9 +206,17 @@ bool SCH_SHEET_PATH::IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) for( size_t i = 0; i < aSheetPathToTest.size(); ++i ) { if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid ) + { + wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is not within path '%s'.", + aSheetPathToTest.Path().AsString(), Path().AsString() ); + return false; + } } + wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is within path '%s'.", + aSheetPathToTest.Path().AsString(), Path().AsString() ); + return true; } @@ -374,6 +395,19 @@ void SCH_SHEET_PATH::AppendMultiUnitSymbol( SCH_MULTI_UNIT_REFERENCE_MAP& aRefLi } +void SCH_SHEET_PATH::SetSymbolInstancesToDefault() +{ + for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) ) + { + SCH_SYMBOL* symbol = static_cast( item ); + + wxCHECK2( symbol, continue ); + + symbol->SetInstanceToDefault( *this ); + } +} + + bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const { return m_current_hash == d1.GetCurrentHash(); diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index bf832b4ee4..f3ceb73fb5 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -3,7 +3,7 @@ * * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -134,6 +134,8 @@ public: SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& aOther ); + SCH_SHEET_PATH operator+( const SCH_SHEET_PATH& aOther ); + ~SCH_SHEET_PATH() = default; /// Forwarded method from std::vector @@ -215,8 +217,8 @@ public: int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const; /** - * Compare sheets by their page number. If the actual page number is equal, use virtual page numbers - * to compare. + * Compare sheets by their page number. If the actual page number is equal, use virtual page + * numbers to compare. * * @return -1 if aSheetPathToTest is greater than this (should appear later in the sort order) * 0 if aSheetPathToTest is equal to this @@ -336,6 +338,11 @@ public: void GetMultiUnitSymbols( SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols = true ) const; + /** + * Set all of the symbol instances in this sheet instance to the default symbol instance data. + */ + void SetSymbolInstancesToDefault(); + /** * Test the SCH_SHEET_PATH file names to check adding the sheet stored in the file * \a aSrcFileName to the sheet stored in file \a aDestFileName will cause a sheet diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index d9779baf70..d674b4c960 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -52,6 +52,7 @@ std::string toUTFTildaText( const wxString& txt ) if( (unsigned char) *it <= ' ' ) *it = '~'; } + return ret; } @@ -103,13 +104,14 @@ SCH_SYMBOL::SCH_SYMBOL() : SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, - const SCH_SHEET_PATH* aSheet, int unit, int convert, const VECTOR2I& pos ) : + const SCH_SHEET_PATH* aSheet, int aUnit, int aConvert, + const VECTOR2I& aPosition ) : SCH_ITEM( nullptr, SCH_SYMBOL_T ) { - Init( pos ); + Init( aPosition ); - m_unit = unit; - m_convert = convert; + m_unit = aUnit; + m_convert = aConvert; m_lib_id = aLibId; std::unique_ptr< LIB_SYMBOL > part; @@ -128,6 +130,12 @@ SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, m_prefix = UTIL::GetRefDesPrefix( m_part->GetReferenceField().GetText() ); + // Set initial default symbol instance data from library symbol and initial unit. + m_defaultInstance.m_Reference = m_prefix; + m_defaultInstance.m_Unit = aUnit; + m_defaultInstance.m_Value = m_part->GetValueField().GetText(); + m_defaultInstance.m_Footprint = m_part->GetFootprintField().GetText(); + if( aSheet ) { SetRef( aSheet, UTIL::GetRefDesUnannotated( m_prefix ) ); @@ -146,8 +154,8 @@ SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, SCH_SYMBOL::SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet, - const PICKED_SYMBOL& aSel, const VECTOR2I& pos ) : - SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos ) + const PICKED_SYMBOL& aSel, const VECTOR2I& aPosition ) : + SCH_SYMBOL( aSymbol, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, aPosition ) { // Set any fields that were modified as part of the symbol selection for( const std::pair& i : aSel.Fields ) @@ -188,6 +196,7 @@ SCH_SYMBOL::SCH_SYMBOL( const SCH_SYMBOL& aSymbol ) : m_fieldsAutoplaced = aSymbol.m_fieldsAutoplaced; m_schLibSymbolName = aSymbol.m_schLibSymbolName; + m_defaultInstance = aSymbol.m_defaultInstance; } @@ -215,6 +224,7 @@ void SCH_SYMBOL::Init( const VECTOR2I& pos ) } m_prefix = wxString( wxT( "U" ) ); + m_defaultInstance.m_Reference = m_prefix; m_isInNetlist = true; m_inBom = true; m_onBoard = true; @@ -935,6 +945,7 @@ void SCH_SYMBOL::SwapData( SCH_ITEM* aItem ) std::swap( m_instanceReferences, symbol->m_instanceReferences ); std::swap( m_schLibSymbolName, symbol->m_schLibSymbolName ); + std::swap( m_defaultInstance, symbol->m_defaultInstance ); } @@ -1108,8 +1119,8 @@ bool SCH_SYMBOL::ReplaceInstanceSheetPath( const KIID_PATH& aOldSheetPath, } wxLogTrace( traceSchSheetPaths, - "Could not find sheet path %s\n to replace with sheet path %s\n for symbol %s.", - aOldSheetPath.AsString(), aNewSheetPath.AsString(), m_Uuid.AsString() ); + "Could not find sheet path %s\n to replace with sheet path %s\n for symbol %s.", + aOldSheetPath.AsString(), aNewSheetPath.AsString(), m_Uuid.AsString() ); return false; } @@ -1780,6 +1791,7 @@ SCH_SYMBOL& SCH_SYMBOL::operator=( const SCH_ITEM& aItem ) m_transform = c->m_transform; m_instanceReferences = c->m_instanceReferences; + m_defaultInstance = c->m_defaultInstance; m_fields = c->m_fields; // std::vector's assignment operator @@ -1923,3 +1935,25 @@ bool SCH_SYMBOL::IsPointClickableAnchor( const VECTOR2I& aPos ) const return false; } + + +void SCH_SYMBOL::SetInstanceToDefault( const SCH_SHEET_PATH& aInstance ) +{ + KIID_PATH path = aInstance.Path(); + + for( SYMBOL_INSTANCE_REFERENCE& instance: m_instanceReferences ) + { + if( instance.m_Path == path ) + { + instance.m_Reference = m_defaultInstance.m_Reference; + instance.m_Unit = m_defaultInstance.m_Unit; + instance.m_Value = m_defaultInstance.m_Value; + instance.m_Footprint = m_defaultInstance.m_Footprint; + return; + } + } + + // It's a new instance so add it. + AddHierarchicalReference( path, m_defaultInstance.m_Reference, m_defaultInstance.m_Unit, + m_defaultInstance.m_Value, m_defaultInstance.m_Footprint ); +} diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index 8294115c0a..c75c481809 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -4,7 +4,7 @@ * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014 Dick Hollenbeck, dick@softplc.com * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -125,6 +125,15 @@ public: return m_instanceReferences; } + void SetDefaultInstance( const SYMBOL_INSTANCE_REFERENCE& aInstance ) + { + m_defaultInstance = aInstance; + } + + const SYMBOL_INSTANCE_REFERENCE& GetDefaultInstance() const { return m_defaultInstance; } + + void SetInstanceToDefault( const SCH_SHEET_PATH& aInstance ); + void ViewGetLayers( int aLayers[], int& aCount ) const override; /** @@ -710,6 +719,16 @@ private: // Defines the hierarchical path and reference of the symbol. This allows support // for multiple references to a single sub-sheet. std::vector m_instanceReferences; + + /** + * The default instance data for this symbol. + * + * This allows for setting the default data across all instances of this symbol. This + * means that any reuse of the symbol in the current schematic will initially use the + * default instance data. @see SYMBOL_INSTANCE_REFERENCE definition for the allowable + * instance settings. + */ + SYMBOL_INSTANCE_REFERENCE m_defaultInstance; }; #endif /* __SYMBOL_H__ */ diff --git a/eeschema/schematic.keywords b/eeschema/schematic.keywords index 4859613145..56ca7e46db 100644 --- a/eeschema/schematic.keywords +++ b/eeschema/schematic.keywords @@ -24,6 +24,7 @@ convert data date default +default_instance diameter diamond directive_label