49#include <wx/clipbrd.h>
71 std::vector<const EMBEDDED_FILES*> inheritedEmbeddedFiles;
73 if( std::shared_ptr<LIB_SYMBOL> parent =
m_libEntry->GetParent().lock() )
77 inheritedEmbeddedFiles.push_back( parent->GetEmbeddedFiles() );
78 parent = parent->GetParent().lock();
82 m_embeddedFiles =
new PANEL_EMBEDDED_FILES( m_NoteBook, m_libEntry, 0, std::move( inheritedEmbeddedFiles ) );
83 m_NoteBook->AddPage( m_embeddedFiles,
_(
"Embedded Files" ) );
86 bPinMapPageSizer->Add( m_pinMapPanel, 1, wxEXPAND, 5 );
88 m_fields =
new FIELDS_GRID_TABLE(
this, aParent, m_grid, m_libEntry, { m_embeddedFiles->GetLocalFiles() } );
89 m_grid->SetTable( m_fields );
90 m_grid->OverrideMinSize( 1.0, 1.0 );
91 m_grid->PushEventHandler(
new FIELDS_GRID_TRICKS( m_grid,
this, { m_embeddedFiles->GetLocalFiles() },
92 [&]( wxCommandEvent& aEvent )
96 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
99 std::vector<SCH_FIELD> fields;
100 m_libEntry->CopyFields( fields );
105 if( std::shared_ptr<LIB_SYMBOL> parent = m_libEntry->GetParent().lock() )
106 addInheritedFields( parent );
108 m_grid->ShowHideColumns(
"0 1 2 3 4 5 6 7" );
112 m_unitNamesGrid->PushEventHandler(
new GRID_TRICKS( m_unitNamesGrid ) );
113 m_unitNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
115 m_bodyStyleNamesGrid->PushEventHandler(
new GRID_TRICKS( m_bodyStyleNamesGrid,
116 [
this]( wxCommandEvent& aEvent )
118 OnAddBodyStyle( aEvent );
120 m_bodyStyleNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
122 m_jumperGroupsGrid->SetupColumnAutosizer( 0 );
123 m_jumperGroupsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
125 m_jumperGroupsGrid->PushEventHandler(
new GRID_TRICKS( m_jumperGroupsGrid,
126 [
this]( wxCommandEvent& aEvent )
128 OnAddJumperGroup( aEvent );
149 SetupStandardButtons();
151 if( aParent->IsSymbolFromLegacyLibrary() && !aParent->IsSymbolFromSchematic() )
153 m_stdSizerButtonCancel->SetDefault();
154 m_stdSizerButtonOK->SetLabel(
_(
"Read Only" ) );
155 m_stdSizerButtonOK->Enable(
false );
165 m_deleteFilterButton->Bind( wxEVT_BUTTON,
166 [&]( wxCommandEvent& aEvent )
168 wxCommandEvent cmdEvent( EDA_EVT_LISTBOX_DELETE );
169 m_fpFilterTricks->ProcessEvent( cmdEvent );
173 m_FootprintFilterListBox->Bind( EDA_EVT_LISTBOX_CHANGED,
174 [&]( wxCommandEvent& aEvent )
191 m_grid->GetParent()->Layout();
192 syncControlStates( m_libEntry->IsDerived() );
195 finishDialogSettings();
204 for(
size_t page = 0; page <
m_NoteBook->GetPageCount(); ++page )
227 m_grid->PopEventHandler(
true );
236 if( std::shared_ptr<LIB_SYMBOL> ancestor = aParent->GetParent().lock() )
239 std::vector<SCH_FIELD*> parentFields;
240 aParent->GetFields( parentFields );
242 for(
SCH_FIELD* parentField : parentFields )
246 if( parentField->IsMandatory() )
249 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
258 m_fields->SetFieldInherited( ii, *parentField );
265 m_fields->AddInheritedField( *parentField );
272 if( !wxDialog::TransferDataToWindow() )
275 std::set<wxString> defined;
278 defined.insert( field.GetName() );
286 if( !cfg->m_Drawing.field_names.IsEmpty() )
291 if( defined.count( templateFieldname.m_Name ) <= 0 )
294 field.
SetVisible( templateFieldname.m_Visible );
305 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
306 m_grid->ProcessTableMessage( msg );
316 for(
int unit = 0; unit <
m_libEntry->GetUnitCount(); unit++ )
318 if(
m_libEntry->GetUnitDisplayNames().contains( unit + 1 ) )
365 wxArrayString tmp =
m_libEntry->GetFPFilters();
370 std::set<wxString> availablePins;
373 availablePins.insert(
pin->GetNumber() );
379 for(
const wxString& pinNumber :
group )
381 if( !groupTxt.IsEmpty() )
384 groupTxt << pinNumber;
394 wxArrayString symbolNames;
395 wxString libName =
m_libEntry->GetLibNickname();
397 if( !libName.empty() )
399 m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
403 [](
const wxString& a,
const wxString& b ) ->
int
409 if( symbolNames.Index(
m_libEntry->GetName() ) != wxNOT_FOUND )
414 wxArrayString descendants;
415 m_Parent->GetLibManager().GetDerivedSymbolNames(
m_libEntry->GetName(), libName, descendants );
417 for(
const wxString& descendant : descendants )
419 if( symbolNames.Index( descendant ) != wxNOT_FOUND )
420 symbolNames.Remove( descendant );
425 if( std::shared_ptr<LIB_SYMBOL> rootSymbol =
m_libEntry->GetParent().lock() )
430 if( selection != wxNOT_FOUND )
442 m_grid->SetMinVisibleRows(
this, 4 );
453 for(
size_t page = 0; page <
m_NoteBook->GetPageCount(); ++page )
457 targetPage = (int) page;
471 if( !
m_grid->CommitPendingChanges() )
495 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
502 wxString fieldName = field.
GetName(
false );
504 if( fieldName.IsEmpty() && !field.
GetText().IsEmpty() )
524 if( parentName.IsEmpty() )
534 std::set<wxString> seenSubRefs;
540 if( subRef.IsEmpty() )
543 if( !seenSubRefs.insert( subRef.Upper() ).second )
560 if( !
IsOK(
this,
_(
"Delete extra units from symbol?" ) ) )
564 int bodyStyleCount = 0;
592 if( bodyStyleCount < m_libEntry->GetBodyStyleCount() )
594 if( !
IsOK(
this,
_(
"Delete extra body styles from symbol?" ) ) )
604 if( !
m_grid->CommitPendingChanges()
616 if( newName.IsEmpty() )
618 wxMessageBox(
_(
"Symbol must have a name." ) );
624 if( oldName != newName )
626 wxString libName =
m_libEntry->GetLibNickname();
628 if( !libName.empty() &&
m_Parent->GetLibManager().SymbolNameInUse( newName, libName ) )
632 msg.Printf(
_(
"Symbol name '%s' already in use in library '%s'." ),
648 if( editingCurrentSymbol )
653 std::vector<SCH_FIELD> fieldsToSave;
656 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
675 if( field.
GetText().IsEmpty() )
680 else if( fieldName.IsEmpty() )
685 fieldsToSave.push_back( field );
694 wxString libName =
m_libEntry->GetLibNickname();
700 wxCHECK( newParent,
false );
720 m_libEntry->SetHasDeMorganBodyStyles(
false );
721 m_libEntry->SetBodyStyleCount( 1,
false,
false );
727 m_libEntry->SetBodyStyleCount( 2,
false,
true );
732 std::vector<wxString> bodyStyleNames;
740 m_libEntry->SetHasDeMorganBodyStyles(
false );
741 m_libEntry->SetBodyStyleCount( bodyStyleNames.size(),
true,
true );
742 m_libEntry->SetBodyStyleNames( bodyStyleNames );
753 m_libEntry->GetValueField().SetText( newName );
773 m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
784 std::set<wxString> availablePins;
787 availablePins.insert(
pin->GetNumber() );
789 std::vector<std::set<wxString>>& jumpers =
m_libEntry->JumperPinGroups();
794 wxStringTokenizer tokenizer(
m_jumperGroupsGrid->GetCellValue( ii, 0 ),
", \t\r\n", wxTOKEN_STRTOK );
795 std::set<wxString>&
group = jumpers.emplace_back();
797 while( tokenizer.HasMoreTokens() )
799 wxString token = tokenizer.GetNextToken();
801 if( token.IsEmpty() )
804 if( !availablePins.count( token ) )
807 msg.Printf(
_(
"Pin '%s' in jumper pin group %d does not exist in this symbol." ),
813 group.insert( token );
822 if( editingCurrentSymbol )
823 m_Parent->UpdateAfterSymbolProperties( &oldName );
844 wxPoint pos = aEvent.GetPosition();
845 wxPoint unscolled_pos =
m_grid->CalcUnscrolledPosition( pos );
846 int row =
m_grid->YToRow( unscolled_pos.y );
847 int col =
m_grid->XToCol( unscolled_pos.x );
849 if( row == wxNOT_FOUND || col == wxNOT_FOUND || !
m_fields->IsInherited( row ) )
855 m_grid->SetToolTip( wxString::Format(
_(
"This field is inherited from '%s'." ),
856 m_fields->ParentField( row ).GetName() ) );
862 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
863 wxControl* control =
editor->GetControl();
865 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
874 else if( event.GetCol() ==
FDC_NAME )
876 wxString newName =
event.GetString();
878 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
880 if( i == event.GetRow() )
885 DisplayError(
this, wxString::Format(
_(
"The name '%s' is already in use." ), newName ) );
937 [&]() -> std::pair<int, int>
949 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
950 m_grid->ProcessTableMessage( msg );
963 if( row < m_fields->GetMandatoryRowCount() )
965 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
966 m_fields->GetMandatoryRowCount() ) );
978 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
979 m_grid->ProcessTableMessage( msg );
991 return row >
m_fields->GetMandatoryRowCount();
1007 return row >=
m_fields->GetMandatoryRowCount();
1011 m_fields->SwapRows( row, row + 1 );
1021 [&]() -> std::pair<int, int>
1067 if( !
m_grid->CommitPendingChanges() )
1070 m_grid->ClearSelection();
1072 std::vector<SCH_FIELD> fields;
1075 fields.emplace_back( field );
1083 for(
const SCH_FIELD& editedField : fields )
1089 if( existingField.GetName() == editedField.GetName() )
1092 existingField.SetText( editedField.GetText() );
1099 m_fields->emplace_back( editedField );
1100 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1101 m_grid->ProcessTableMessage( msg );
1106 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
1113 if( editedField.GetName() == existingField.
GetName() )
1122 m_grid->ClearSelection();
1125 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
1126 m_grid->ProcessTableMessage( msg );
1138 wxCommandEvent
dummy;
1157 wxString filterLine;
1164 filterLine.Replace( wxT(
" " ), wxT(
"_" ) );
1176 wxArrayInt selections;
1182 int idx = selections[0];
1201 if(
m_grid->IsCellEditControlShown() )
1203 int row =
m_grid->GetGridCursorRow();
1204 int col =
m_grid->GetGridCursorCol();
1208 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
1215 std::bitset<64> shownColumns =
m_grid->GetShownColumns();
1221 if( !
m_grid->IsCellEditControlShown() )
1222 m_grid->SetGridWidthsDirty();
1252 textEntry->SelectAll();
1345 for(
int row =
m_unitNamesGrid->GetNumberRows() - needed; row < m_unitNamesGrid->GetNumberRows(); ++row )
1384 if( !
m_grid->CommitPendingChanges() )
1392 [&]() -> std::pair<int, int>
constexpr EDA_IU_SCALE schIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
WX_GRID * m_jumperGroupsGrid
STD_BITMAP_BUTTON * m_bpAddBodyStyle
wxButton * m_spiceFieldsButton
DIALOG_LIB_SYMBOL_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=ID_LIBEDIT_NOTEBOOK, const wxString &title=_("Library Symbol Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxTextCtrl * m_KeywordCtrl
WX_GRID * m_bodyStyleNamesGrid
wxBoxSizer * bSizerLowerBasicPanel
wxCheckBox * m_PinsNameInsideButt
wxRadioButton * m_radioSingle
wxListBox * m_FootprintFilterListBox
STD_BITMAP_BUTTON * m_bpMoveDownBodyStyle
wxStaticText * m_nameOffsetUnits
wxComboBox * m_inheritanceSelectCombo
STD_BITMAP_BUTTON * m_bpDeleteBodyStyle
wxCheckBox * m_ShowPinNumButt
wxCheckBox * m_OptionPower
wxRadioButton * m_radioDeMorgan
wxStaticText * m_nameOffsetLabel
wxCheckBox * m_excludeFromBoardCheckBox
wxCheckBox * m_cbDuplicatePinsAreJumpers
STD_BITMAP_BUTTON * m_bpMoveUpBodyStyle
WX_GRID * m_unitNamesGrid
wxCheckBox * m_OptionLocalPower
wxTextCtrl * m_nameOffsetCtrl
wxCheckBox * m_excludeFromPosFilesCheckBox
wxCheckBox * m_excludeFromBomCheckBox
wxSpinCtrl * m_unitSpinCtrl
wxCheckBox * m_OptionPartsInterchangeable
wxCheckBox * m_excludeFromSimCheckBox
wxRadioButton * m_radioCustom
wxTextCtrl * m_SymbolNameCtrl
wxStaticText * m_inheritsStaticText
wxCheckBox * m_ShowPinNameButt
void OnSymbolNameKillFocus(wxFocusEvent &event) override
void OnUnitSpinCtrlText(wxCommandEvent &event) override
std::unique_ptr< LISTBOX_TRICKS > m_fpFilterTricks
void OnPageChanging(wxNotebookEvent &event) override
wxString m_delayedErrorMessage
void OnBodyStyle(wxCommandEvent &event) override
FIELDS_GRID_TABLE * m_fields
WX_GRID * m_delayedFocusGrid
std::set< wxString > m_addedTemplateFields
DIALOG_LIB_SYMBOL_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_SYMBOL *aLibEntry)
wxControl * m_delayedFocusCtrl
void OnUpdateUI(wxUpdateUIEvent &event) override
static LAST_LAYOUT m_lastLayout
void OnBodyStyleMoveUp(wxCommandEvent &event) override
void OnCancelButtonClick(wxCommandEvent &event) override
PANEL_EMBEDDED_FILES * m_embeddedFiles
void OnEditFootprintFilter(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
bool TransferDataFromWindow() override
void OnCombobox(wxCommandEvent &event) override
void OnFpFilterDClick(wxMouseEvent &event) override
void OnUnitSpinCtrlEnter(wxCommandEvent &event) override
void OnAddBodyStyle(wxCommandEvent &event) override
void OnGridCellChanged(wxGridEvent &event)
std::bitset< 64 > m_shownColumns
void OnMoveUp(wxCommandEvent &event) override
void OnDeleteBodyStyle(wxCommandEvent &event) override
void OnAddJumperGroup(wxCommandEvent &event) override
SYMBOL_EDIT_FRAME * m_Parent
void OnText(wxCommandEvent &event) override
PANEL_SYMBOL_PIN_MAP * m_pinMapPanel
void OnGridMotion(wxMouseEvent &event)
void OnUnitSpinCtrlKillFocus(wxFocusEvent &event) override
~DIALOG_LIB_SYMBOL_PROPERTIES()
static int m_lastOpenedPage
void OnMoveDown(wxCommandEvent &event) override
void SelectPinMapPage()
Switch the notebook to the Pin Map page (issue #2282).
bool m_forcePinMapPage
When set by SelectPinMapPage(), TransferDataToWindow opens the Pin Map page instead of the remembered...
void OnAddFootprintFilter(wxCommandEvent &event) override
void syncControlStates(bool aIsAlias)
void OnCheckBox(wxCommandEvent &event) override
void OnSymbolNameText(wxCommandEvent &event) override
void OnBodyStyleMoveDown(wxCommandEvent &event) override
void OnRemoveJumperGroup(wxCommandEvent &event) override
bool TransferDataToWindow() override
void OnGridCellChanging(wxGridEvent &event)
void onPowerCheckBox(wxCommandEvent &aEvent) override
void OnAddField(wxCommandEvent &event) override
void OnEditSpiceModel(wxCommandEvent &event) override
void addInheritedFields(const std::shared_ptr< LIB_SYMBOL > &aParent)
UNIT_BINDER m_pinNameOffset
void OnUnitSpinCtrl(wxSpinEvent &event) override
void EndDialogShim(int aReturnCode)
A mode agnostic way to close a dialog.
EDA_BASE_FRAME * m_parentFrame
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual void SetVisible(bool aVisible)
void push_back(const SCH_FIELD &field)
A text control validator used for validating the text allowed in fields.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Define a library symbol object.
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
Composed widget that edits a symbol's named pin maps and the footprint each is bound to.
void SetOrdinal(int aOrdinal)
bool HasSameContent(const SCH_FIELD &aOther) const
Test if this field has the same name, content and presentation as another field, ignoring the owning ...
virtual const wxString & GetText() const override
Return the string associated with the text object.
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetName(const wxString &aName)
The symbol library editor main window.
void AddTemplateFieldNames(const wxString &aSerializedFieldNames)
Add a serialized list of template field names.
const std::vector< TEMPLATE_FIELDNAME > & GetTemplateFieldNames()
Return a template field name list for read only access.
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
Collection of utility functions for component reference designators (refdes)
T * GetAppSettings(const char *aFilename)
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
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:...
Hold a name of a symbol's field, field value, and default visibility.
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
@ 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".
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
VECTOR2< int32_t > VECTOR2I