56 m_matchAll->SetLabel(
_(
"Change all symbols in schematic" ) );
57 SetTitle(
_(
"Change Symbols" ) );
62 m_matchById->SetLabel(
_(
"Change symbols matching library identifier:" ) );
89 bool selectReference =
false;
90 bool selectValue =
false;
94 selectReference = cfg->m_ChangeSymbols.updateReferences;
95 selectValue = cfg->m_ChangeSymbols.updateValues;
138 { wxID_CANCEL,
_(
"Close" ) } } );
238 wxString rawValue = aCtrl->GetValue();
240 wxString libName = rawValue.BeforeFirst(
':', &itemName );
252 if( frame->ShowModal( &newName,
this ) )
269 if( frame->ShowModal( &newName,
this ) )
287 std::set<wxString> fieldNames;
293 wxCHECK2( screen,
continue );
299 wxCHECK2( symbol,
continue );
301 if( !
isMatch( symbol, &instance ) )
306 if( !field.IsMandatory() && !field.IsPrivate() )
307 fieldNames.insert( field.GetName() );
316 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->
Flatten();
317 std::vector<SCH_FIELD*> orderedLibFields;
319 flattenedSymbol->GetFields( orderedLibFields );
321 for(
SCH_FIELD* libField : orderedLibFields )
323 if( !libField->IsMandatory() && !libField->IsPrivate() )
324 fieldNames.insert( libField->GetName() );
344 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->
Flatten();
345 std::vector<SCH_FIELD*> orderedLibFields;
347 flattenedSymbol->GetFields( orderedLibFields );
349 for(
SCH_FIELD* libField : orderedLibFields )
351 if( !libField->IsMandatory() && !libField->IsPrivate() )
352 fieldNames.insert( libField->GetName() );
359 wxArrayInt checkedItems;
360 wxArrayString checkedNames;
364 for(
int ii : checkedItems )
365 checkedNames.push_back(
m_fieldsBox->GetString( ii ) );
367 bool allChecked =
true;
369 for(
int ii = 0; ii < (int)
m_fieldsBox->GetCount(); ++ii )
379 auto isMandatoryField =
380 [&](
int listbox_idx )
391 for(
int ii = (
int)
m_fieldsBox->GetCount() - 1; ii >= 0; --ii )
393 if( isMandatoryField( ii ) )
399 for(
const wxString& fieldName : fieldNames )
411 for(
unsigned i = 0; i <
m_fieldsBox->GetCount(); ++i )
447 for(
unsigned ii = 0; ii <
m_fieldsBox->GetCount(); ++ii )
470 wxCHECK( frame,
false );
511 wxCHECK( frame,
false );
514 int matchesProcessed = 0;
525 std::map<SCH_SYMBOL*, SYMBOL_CHANGE_INFO> symbols;
531 wxCHECK2( screen,
continue );
538 wxCHECK2( symbol,
continue );
540 if( !
isMatch( symbol, &instance ) )
546 auto it = symbols.find( symbol );
548 if( it == symbols.end() )
552 info.m_Instances.emplace_back( instance );
553 info.m_LibId = newId;
554 symbols.insert( { symbol,
info } );
558 it->second.m_Instances.emplace_back( instance );
563 if( symbols.size() > 0 )
570 return matchesProcessed;
577 wxCHECK( !aSymbols.empty(), 0 );
579 int matchesProcessed = 0;
585 std::map<SCH_SYMBOL*, SYMBOL_CHANGE_INFO> symbols = aSymbols;
586 std::map<SCH_SYMBOL*, SYMBOL_CHANGE_INFO>::iterator it = symbols.begin();
590 while( it != symbols.end() )
594 wxCHECK2( symbol, ++it; continue );
596 if( !it->second.m_LibId.IsValid() )
599 msg << wxT(
": " ) <<
_(
"*** symbol lib id not valid ***" );
601 it = symbols.erase( it );
610 msg << wxT(
": " ) <<
_(
"*** symbol not found ***" );
612 it = symbols.erase( it );
616 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->
Flatten();
618 if( flattenedSymbol->GetUnitCount() < symbol->
GetUnit() )
621 msg << wxT(
": " ) <<
_(
"*** new symbol has too few units ***" );
623 it = symbols.erase( it );
632 std::set<wxString> usedRefs;
633 std::map<wxString, wxString> renamedRefs;
639 wxCHECK2( screen,
continue );
642 usedRefs.insert(
static_cast<SCH_SYMBOL*
>( item )->GetRef( &
path ) );
647 for(
const auto& [ symbol, symbol_change_info ] : symbols )
649 wxCHECK( symbol && !symbol_change_info.m_Instances.empty(), 0 );
651 SCH_SCREEN* screen = symbol_change_info.m_Instances[0].LastScreen();
653 wxCHECK( screen, 0 );
657 aCommit->
Modified( symbol, symbol_copy, screen );
660 for(
const auto& [ symbol, symbol_change_info ] : symbols )
663 wxString initialLibLinkName =
UnescapeString( symbol->GetLibId().Format() );
667 wxCHECK2( libSymbol,
continue );
669 if( symbol_change_info.m_LibId != symbol->GetLibId() )
670 symbol->SetLibId( symbol_change_info.m_LibId );
672 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->
Flatten();
673 SCH_SCREEN* screen = symbol_change_info.m_Instances[0].LastScreen();
678 std::vector<ASSOCIATED_FOOTPRINT> savedAssociations;
680 if( keepPinMaps && symbol->GetLibSymbolRef() )
682 savedPinMaps = symbol->GetLibSymbolRef()->GetPinMaps();
683 savedAssociations = symbol->GetLibSymbolRef()->GetAssociatedFootprints();
686 symbol->SetLibSymbol( flattenedSymbol.release() );
691 if( keepPinMaps && symbol->GetLibSymbolRef() )
693 symbol->GetLibSymbolRef()->SetPinMaps( savedPinMaps );
694 symbol->GetLibSymbolRef()->SetAssociatedFootprints( savedAssociations );
701 symbol->SetExcludedFromSim( symbol->GetLibSymbolRef()->GetExcludedFromSim() );
702 symbol->SetExcludedFromBOM( symbol->GetLibSymbolRef()->GetExcludedFromBOM() );
703 symbol->SetExcludedFromBoard( symbol->GetLibSymbolRef()->GetExcludedFromBoard() );
704 symbol->SetExcludedFromPosFiles( symbol->GetLibSymbolRef()->GetExcludedFromPosFiles() );
709 symbol->SetShowPinNames( symbol->GetLibSymbolRef()->GetShowPinNames() );
710 symbol->SetShowPinNumbers( symbol->GetLibSymbolRef()->GetShowPinNumbers() );
718 for(
int ii = (
int) symbol->GetFields().size() - 1; ii >= 0; ii-- )
720 SCH_FIELD& field = symbol->GetFields()[ii];
732 libField = symbol->GetLibSymbolRef()->GetField( field.
GetId() );
734 libField = symbol->GetLibSymbolRef()->GetField( field.
GetName() );
749 for(
const SCH_SHEET_PATH& instance : symbol_change_info.m_Instances )
751 wxString oldRef = symbol->GetRef( &instance );
754 auto renamed = renamedRefs.find( oldRef );
760 else if( renamed != renamedRefs.end()
764 ref = renamed->second;
768 ref.Printf( wxS(
"%s%d" ), prefix, number );
772 while( usedRefs.count( ref ) )
773 ref.Printf( wxS(
"%s%d" ), prefix, ++number );
775 usedRefs.insert( ref );
776 renamedRefs[oldRef] = ref;
780 symbol->SetRef( &instance, ref );
816 symbol->RemoveField( field.
GetName() );
820 std::vector<SCH_FIELD*> libFields;
821 symbol->GetLibSymbolRef()->GetFields( libFields );
825 if( libField->IsMandatory() )
831 if( !symbol->GetField( libField->GetName() ) )
837 schField->
SetVisible( libField->IsVisible() );
838 schField->
SetText( libField->GetText() );
839 schField->
SetTextPos( symbol->GetPosition() + libField->GetTextPos() );
840 schField->
SetPrivate( libField->IsPrivate() );
848 symbol->AutoplaceFields( screen, fieldsAutoplaced );
852 symbol->SetSchSymbolLibraryName( wxEmptyString );
860 symbol->AutoplaceFields( screen, fieldsAutoplaced );
864 for(
const SCH_SHEET_PATH& instance : symbol_change_info.m_Instances )
866 for(
SCH_PIN*
pin : symbol->GetPins( &instance ) )
868 if( !
pin->GetAlt().IsEmpty() )
875 || (
pin->GetAlt() ==
pin->GetBaseName() )
876 || (
pin->GetAlternates().count(
pin->GetAlt() ) == 0 ) )
878 pin->SetAlt( wxEmptyString );
886 for(
const SCH_SHEET_PATH& instance : symbol_change_info.m_Instances )
893 msg += wxS(
": OK" );
895 matchesProcessed +=1;
898 return matchesProcessed;
903 const wxString* aOldLibLinkName )
908 wxString oldLibLinkName;
910 if( aOldLibLinkName )
911 oldLibLinkName = *aOldLibLinkName;
917 wxCHECK( parent, msg );
924 if( !sheets.
HasPath( instance.m_Path ) )
927 if( references.IsEmpty() )
928 references = instance.m_Reference;
930 references += wxT(
" " ) + instance.m_Reference;
937 msg.Printf(
_(
"Update symbol %s from '%s' to '%s'" ),
944 msg.Printf(
_(
"Update symbols %s from '%s' to '%s'" ),
954 msg.Printf(
_(
"Change symbol %s from '%s' to '%s'" ),
961 msg.Printf(
_(
"Change symbols %s from '%s' to '%s'" ),
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
COMMIT & Modified(EDA_ITEM *aItem, EDA_ITEM *aCopy, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
wxCheckListBox * m_fieldsBox
STD_BITMAP_BUTTON * m_newIdBrowserButton
wxTextCtrl * m_specifiedValue
wxCheckBox * m_resetPinMapOverrides
DIALOG_CHANGE_SYMBOLS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Update Symbols from Library"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxCheckBox * m_removeExtraBox
wxCheckBox * m_resetCustomPower
wxRadioButton * m_matchBySelection
wxCheckBox * m_resetAlternatePin
wxCheckBox * m_resetFieldPositions
wxRadioButton * m_matchByValue
wxRadioButton * m_matchByReference
wxCheckBox * m_resetFieldEffects
wxCheckBox * m_resetFieldText
wxStaticBoxSizer * m_updateFieldsSizer
wxCheckBox * m_resetAttributes
wxTextCtrl * m_specifiedReference
wxGridBagSizer * m_matchSizer
WX_HTML_REPORT_PANEL * m_messagePanel
wxCheckBox * m_resetFieldVisibilities
wxTextCtrl * m_specifiedId
wxRadioButton * m_matchById
wxCheckBox * m_resetEmptyFields
wxBoxSizer * m_newIdSizer
wxCheckBox * m_resetPinTextVisibility
wxRadioButton * m_matchAll
STD_BITMAP_BUTTON * m_matchIdBrowserButton
void onNewLibIDKillFocus(wxFocusEvent &event) override
void onMatchBySelected(wxCommandEvent &aEvent) override
bool isMatch(SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aInstance)
std::map< FIELD_T, int > m_mandatoryFieldListIndexes
Index in the list control for each mandatory FIELD_T type.
void onOkButtonClicked(wxCommandEvent &aEvent) override
void selectAll(bool aSelect)
Select or deselect all fields in the listbox widget.
std::set< wxString > m_updateFields
Set of field names that should have values updated.
void onMatchById(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void launchMatchIdSymbolBrowser(wxCommandEvent &aEvent) override
void onMatchByReference(wxCommandEvent &aEvent) override
void onMatchByValue(wxCommandEvent &aEvent) override
~DIALOG_CHANGE_SYMBOLS() override
int processMatchingSymbols(SCH_COMMIT *aCommit)
DIALOG_CHANGE_SYMBOLS(SCH_EDIT_FRAME *aParent, SCH_SYMBOL *aSymbol, MODE aMode=MODE::UPDATE)
void checkAll(bool aCheck)
void onMatchTextKillFocus(wxFocusEvent &event) override
void onMatchIDKillFocus(wxFocusEvent &event) override
wxString getSymbolReferences(SCH_SYMBOL &aSymbol, const LIB_ID &aNewId, const wxString *aOldLibLinkName=nullptr)
void launchNewIdSymbolBrowser(wxCommandEvent &aEvent) override
void onMatchByAll(wxCommandEvent &aEvent) override
int processSymbols(SCH_COMMIT *aCommit, const std::map< SCH_SYMBOL *, SYMBOL_CHANGE_INFO > &aSymbols)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual VECTOR2I GetTextPos() const
virtual bool IsVisible() const
virtual void SetTextPos(const VECTOR2I &aPoint)
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
virtual void SetVisible(bool aVisible)
AUTOPLACE_FIELDS m_AutoplaceFields
EE_TYPE OfType(KICAD_T aType) const
void Update(const KIGFX::VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
bool IsValid() const
Check if this LID_ID is valid.
Define a library symbol object.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
A symbol-owned ordered set of named pin maps.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
EESCHEMA_SETTINGS * eeconfig() const
LIB_SYMBOL * GetLibSymbol(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
Load symbol from symbol library table.
Commit for the schematic and symbol editors.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
VECTOR2I GetPosition() const override
virtual const wxString & GetText() const override
Return the string associated with the text object.
void SetCanAutoplace(bool aCanPlace)
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetPosition(const VECTOR2I &aPosition) override
bool CanAutoplace() const
void SetText(const wxString &aText) override
void SetNameShown(bool aShown=true)
Base class for any item which can be embedded within the SCHEMATIC container class,...
void SetPrivate(bool aPrivate)
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
void IncludeVariantSymbols(const SCH_SYMBOL &aSymbol, bool aRefresh=false)
Include the alternate symbols that aSymbol's variants select in the library symbols.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
bool HasPath(const KIID_PATH &aPath) const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
const LIB_ID & GetLibId() const override
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
wxString getLibIdValue(const wxTextCtrl *aCtrl)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
wxString GetRefDesUnannotated(const wxString &aSource)
Return an unannotated refdes from either a prefix or an existing refdes.
int GetRefDesNumber(const wxString &aRefDes)
Get the numeric suffix from a refdes - e.g.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Collection of utility functions for component reference designators (refdes)
T * GetAppSettings(const char *aFilename)
std::vector< FAB_LAYER_COLOR > dummy
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Compare a string against wild card (* and ?) pattern using the usual rules.
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Per-instance override of the active pin map and a sparse delta on top.
A simple container for schematic symbol instance information.
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
VECTOR2< int32_t > VECTOR2I