48#include <wx/clipbrd.h>
70 std::vector<const EMBEDDED_FILES*> inheritedEmbeddedFiles;
72 if( std::shared_ptr<LIB_SYMBOL> parent =
m_libEntry->GetParent().lock() )
76 inheritedEmbeddedFiles.push_back( parent->GetEmbeddedFiles() );
77 parent = parent->GetParent().lock();
81 m_embeddedFiles =
new PANEL_EMBEDDED_FILES( m_NoteBook, m_libEntry, 0, std::move( inheritedEmbeddedFiles ) );
82 m_NoteBook->AddPage( m_embeddedFiles,
_(
"Embedded Files" ) );
85 bPinMapPageSizer->Add( m_pinMapPanel, 1, wxEXPAND, 5 );
87 m_fields =
new FIELDS_GRID_TABLE(
this, aParent, m_grid, m_libEntry, { m_embeddedFiles->GetLocalFiles() } );
88 m_grid->SetTable( m_fields );
89 m_grid->OverrideMinSize( 1.0, 1.0 );
90 m_grid->PushEventHandler(
new FIELDS_GRID_TRICKS( m_grid,
this, { m_embeddedFiles->GetLocalFiles() },
91 [&]( wxCommandEvent& aEvent )
95 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
98 std::vector<SCH_FIELD> fields;
99 m_libEntry->CopyFields( fields );
104 if( std::shared_ptr<LIB_SYMBOL> parent = m_libEntry->GetParent().lock() )
105 addInheritedFields( parent );
107 m_grid->ShowHideColumns(
"0 1 2 3 4 5 6 7" );
111 m_unitNamesGrid->PushEventHandler(
new GRID_TRICKS( m_unitNamesGrid ) );
112 m_unitNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
114 m_bodyStyleNamesGrid->PushEventHandler(
new GRID_TRICKS( m_bodyStyleNamesGrid,
115 [
this]( wxCommandEvent& aEvent )
117 OnAddBodyStyle( aEvent );
119 m_bodyStyleNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
121 m_jumperGroupsGrid->SetupColumnAutosizer( 0 );
122 m_jumperGroupsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
124 m_jumperGroupsGrid->PushEventHandler(
new GRID_TRICKS( m_jumperGroupsGrid,
125 [
this]( wxCommandEvent& aEvent )
127 OnAddJumperGroup( aEvent );
148 SetupStandardButtons();
150 if( aParent->IsSymbolFromLegacyLibrary() && !aParent->IsSymbolFromSchematic() )
152 m_stdSizerButtonCancel->SetDefault();
153 m_stdSizerButtonOK->SetLabel(
_(
"Read Only" ) );
154 m_stdSizerButtonOK->Enable(
false );
164 m_deleteFilterButton->Bind( wxEVT_BUTTON,
165 [&]( wxCommandEvent& aEvent )
167 wxCommandEvent cmdEvent( EDA_EVT_LISTBOX_DELETE );
168 m_fpFilterTricks->ProcessEvent( cmdEvent );
172 m_FootprintFilterListBox->Bind( EDA_EVT_LISTBOX_CHANGED,
173 [&]( wxCommandEvent& aEvent )
190 m_grid->GetParent()->Layout();
191 syncControlStates( m_libEntry->IsDerived() );
194 finishDialogSettings();
203 for(
size_t page = 0; page <
m_NoteBook->GetPageCount(); ++page )
226 m_grid->PopEventHandler(
true );
235 if( std::shared_ptr<LIB_SYMBOL> ancestor = aParent->GetParent().lock() )
238 std::vector<SCH_FIELD*> parentFields;
239 aParent->GetFields( parentFields );
241 for(
SCH_FIELD* parentField : parentFields )
245 if( parentField->IsMandatory() )
248 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
257 m_fields->SetFieldInherited( ii, *parentField );
264 m_fields->AddInheritedField( *parentField );
271 if( !wxDialog::TransferDataToWindow() )
274 std::set<wxString> defined;
277 defined.insert( field.GetName() );
285 if( !cfg->m_Drawing.field_names.IsEmpty() )
290 if( defined.count( templateFieldname.m_Name ) <= 0 )
293 field.
SetVisible( templateFieldname.m_Visible );
304 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
305 m_grid->ProcessTableMessage( msg );
315 for(
int unit = 0; unit <
m_libEntry->GetUnitCount(); unit++ )
317 if(
m_libEntry->GetUnitDisplayNames().contains( unit + 1 ) )
364 wxArrayString tmp =
m_libEntry->GetFPFilters();
369 std::set<wxString> availablePins;
372 availablePins.insert(
pin->GetNumber() );
378 for(
const wxString& pinNumber :
group )
380 if( !groupTxt.IsEmpty() )
383 groupTxt << pinNumber;
393 wxArrayString symbolNames;
394 wxString libName =
m_libEntry->GetLibNickname();
396 if( !libName.empty() )
398 m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
402 [](
const wxString& a,
const wxString& b ) ->
int
408 if( symbolNames.Index(
m_libEntry->GetName() ) != wxNOT_FOUND )
413 wxArrayString descendants;
414 m_Parent->GetLibManager().GetDerivedSymbolNames(
m_libEntry->GetName(), libName, descendants );
416 for(
const wxString& descendant : descendants )
418 if( symbolNames.Index( descendant ) != wxNOT_FOUND )
419 symbolNames.Remove( descendant );
424 if( std::shared_ptr<LIB_SYMBOL> rootSymbol =
m_libEntry->GetParent().lock() )
429 if( selection != wxNOT_FOUND )
441 m_grid->SetMinVisibleRows(
this, 4 );
452 for(
size_t page = 0; page <
m_NoteBook->GetPageCount(); ++page )
456 targetPage = (int) page;
470 if( !
m_grid->CommitPendingChanges() )
494 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
501 wxString fieldName = field.
GetName(
false );
503 if( fieldName.IsEmpty() && !field.
GetText().IsEmpty() )
523 if( parentName.IsEmpty() )
533 std::set<wxString> seenSubRefs;
539 if( subRef.IsEmpty() )
542 if( !seenSubRefs.insert( subRef.Upper() ).second )
559 if( !
IsOK(
this,
_(
"Delete extra units from symbol?" ) ) )
563 int bodyStyleCount = 0;
591 if( bodyStyleCount < m_libEntry->GetBodyStyleCount() )
593 if( !
IsOK(
this,
_(
"Delete extra body styles from symbol?" ) ) )
603 if( !
m_grid->CommitPendingChanges()
615 if( newName.IsEmpty() )
617 wxMessageBox(
_(
"Symbol must have a name." ) );
623 if( oldName != newName )
625 wxString libName =
m_libEntry->GetLibNickname();
627 if( !libName.empty() &&
m_Parent->GetLibManager().SymbolNameInUse( newName, libName ) )
631 msg.Printf(
_(
"Symbol name '%s' already in use in library '%s'." ),
647 if( editingCurrentSymbol )
652 std::vector<SCH_FIELD> fieldsToSave;
655 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
674 if( field.
GetText().IsEmpty() )
679 else if( fieldName.IsEmpty() )
684 fieldsToSave.push_back( field );
693 wxString libName =
m_libEntry->GetLibNickname();
699 wxCHECK( newParent,
false );
719 m_libEntry->SetHasDeMorganBodyStyles(
false );
720 m_libEntry->SetBodyStyleCount( 1,
false,
false );
726 m_libEntry->SetBodyStyleCount( 2,
false,
true );
731 std::vector<wxString> bodyStyleNames;
739 m_libEntry->SetHasDeMorganBodyStyles(
false );
740 m_libEntry->SetBodyStyleCount( bodyStyleNames.size(),
true,
true );
741 m_libEntry->SetBodyStyleNames( bodyStyleNames );
752 m_libEntry->GetValueField().SetText( newName );
772 m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
783 std::set<wxString> availablePins;
786 availablePins.insert(
pin->GetNumber() );
788 std::vector<std::set<wxString>>& jumpers =
m_libEntry->JumperPinGroups();
793 wxStringTokenizer tokenizer(
m_jumperGroupsGrid->GetCellValue( ii, 0 ),
", \t\r\n", wxTOKEN_STRTOK );
794 std::set<wxString>&
group = jumpers.emplace_back();
796 while( tokenizer.HasMoreTokens() )
798 wxString token = tokenizer.GetNextToken();
800 if( token.IsEmpty() )
803 if( !availablePins.count( token ) )
806 msg.Printf(
_(
"Pin '%s' in jumper pin group %d does not exist in this symbol." ),
812 group.insert( token );
821 if( editingCurrentSymbol )
822 m_Parent->UpdateAfterSymbolProperties( &oldName );
843 wxPoint pos = aEvent.GetPosition();
844 wxPoint unscolled_pos =
m_grid->CalcUnscrolledPosition( pos );
845 int row =
m_grid->YToRow( unscolled_pos.y );
846 int col =
m_grid->XToCol( unscolled_pos.x );
848 if( row == wxNOT_FOUND || col == wxNOT_FOUND || !
m_fields->IsInherited( row ) )
854 m_grid->SetToolTip( wxString::Format(
_(
"This field is inherited from '%s'." ),
855 m_fields->ParentField( row ).GetName() ) );
861 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
862 wxControl* control =
editor->GetControl();
864 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
873 else if( event.GetCol() ==
FDC_NAME )
875 wxString newName =
event.GetString();
877 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
879 if( i == event.GetRow() )
882 if( newName.CmpNoCase(
m_grid->GetCellValue( i,
FDC_NAME ) ) == 0 )
884 DisplayError(
this, wxString::Format(
_(
"The name '%s' is already in use." ), newName ) );
936 [&]() -> std::pair<int, int>
948 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
949 m_grid->ProcessTableMessage( msg );
962 if( row < m_fields->GetMandatoryRowCount() )
964 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
965 m_fields->GetMandatoryRowCount() ) );
977 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
978 m_grid->ProcessTableMessage( msg );
990 return row >
m_fields->GetMandatoryRowCount();
1006 return row >=
m_fields->GetMandatoryRowCount();
1010 m_fields->SwapRows( row, row + 1 );
1020 [&]() -> std::pair<int, int>
1066 if( !
m_grid->CommitPendingChanges() )
1069 m_grid->ClearSelection();
1071 std::vector<SCH_FIELD> fields;
1074 fields.emplace_back( field );
1082 for(
const SCH_FIELD& editedField : fields )
1088 if( existingField.GetName() == editedField.GetName() )
1091 existingField.SetText( editedField.GetText() );
1098 m_fields->emplace_back( editedField );
1099 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1100 m_grid->ProcessTableMessage( msg );
1105 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
1112 if( editedField.GetName() == existingField.
GetName() )
1121 m_grid->ClearSelection();
1124 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
1125 m_grid->ProcessTableMessage( msg );
1137 wxCommandEvent
dummy;
1156 wxString filterLine;
1163 filterLine.Replace( wxT(
" " ), wxT(
"_" ) );
1175 wxArrayInt selections;
1181 int idx = selections[0];
1200 if(
m_grid->IsCellEditControlShown() )
1202 int row =
m_grid->GetGridCursorRow();
1203 int col =
m_grid->GetGridCursorCol();
1207 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
1214 std::bitset<64> shownColumns =
m_grid->GetShownColumns();
1220 if( !
m_grid->IsCellEditControlShown() )
1221 m_grid->SetGridWidthsDirty();
1251 textEntry->SelectAll();
1344 for(
int row =
m_unitNamesGrid->GetNumberRows() - needed; row < m_unitNamesGrid->GetNumberRows(); ++row )
1383 if( !
m_grid->CommitPendingChanges() )
1391 [&]() -> 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 EndQuasiModal(int retCode)
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.
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