47#include <wx/clipbrd.h>
69 std::vector<const EMBEDDED_FILES*> inheritedEmbeddedFiles;
71 if( std::shared_ptr<LIB_SYMBOL> parent =
m_libEntry->GetParent().lock() )
75 inheritedEmbeddedFiles.push_back( parent->GetEmbeddedFiles() );
76 parent = parent->GetParent().lock();
80 m_embeddedFiles =
new PANEL_EMBEDDED_FILES( m_NoteBook, m_libEntry, 0, std::move( inheritedEmbeddedFiles ) );
81 m_NoteBook->AddPage( m_embeddedFiles,
_(
"Embedded Files" ) );
83 m_fields =
new FIELDS_GRID_TABLE(
this, aParent, m_grid, m_libEntry, { m_embeddedFiles->GetLocalFiles() } );
84 m_grid->SetTable( m_fields );
85 m_grid->OverrideMinSize( 1.0, 1.0 );
86 m_grid->PushEventHandler(
new FIELDS_GRID_TRICKS( m_grid,
this, { m_embeddedFiles->GetLocalFiles() },
87 [&]( wxCommandEvent& aEvent )
91 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
94 std::vector<SCH_FIELD> fields;
95 m_libEntry->CopyFields( fields );
100 if( std::shared_ptr<LIB_SYMBOL> parent = m_libEntry->GetParent().lock() )
101 addInheritedFields( parent );
103 m_grid->ShowHideColumns(
"0 1 2 3 4 5 6 7" );
107 m_unitNamesGrid->PushEventHandler(
new GRID_TRICKS( m_unitNamesGrid ) );
108 m_unitNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
110 m_bodyStyleNamesGrid->PushEventHandler(
new GRID_TRICKS( m_bodyStyleNamesGrid,
111 [
this]( wxCommandEvent& aEvent )
113 OnAddBodyStyle( aEvent );
115 m_bodyStyleNamesGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
117 m_jumperGroupsGrid->SetupColumnAutosizer( 0 );
118 m_jumperGroupsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
120 m_jumperGroupsGrid->PushEventHandler(
new GRID_TRICKS( m_jumperGroupsGrid,
121 [
this]( wxCommandEvent& aEvent )
123 OnAddJumperGroup( aEvent );
144 SetupStandardButtons();
146 if( aParent->IsSymbolFromLegacyLibrary() && !aParent->IsSymbolFromSchematic() )
148 m_stdSizerButtonCancel->SetDefault();
149 m_stdSizerButtonOK->SetLabel(
_(
"Read Only" ) );
150 m_stdSizerButtonOK->Enable(
false );
160 m_deleteFilterButton->Bind( wxEVT_BUTTON,
161 [&]( wxCommandEvent& aEvent )
163 wxCommandEvent cmdEvent( EDA_EVT_LISTBOX_DELETE );
164 m_fpFilterTricks->ProcessEvent( cmdEvent );
168 m_FootprintFilterListBox->Bind( EDA_EVT_LISTBOX_CHANGED,
169 [&]( wxCommandEvent& aEvent )
186 m_grid->GetParent()->Layout();
187 syncControlStates( m_libEntry->IsDerived() );
190 finishDialogSettings();
206 m_grid->PopEventHandler(
true );
215 if( std::shared_ptr<LIB_SYMBOL> ancestor = aParent->GetParent().lock() )
218 std::vector<SCH_FIELD*> parentFields;
219 aParent->GetFields( parentFields );
221 for(
SCH_FIELD* parentField : parentFields )
225 if( parentField->IsMandatory() )
228 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
237 m_fields->SetFieldInherited( ii, *parentField );
244 m_fields->AddInheritedField( *parentField );
251 if( !wxDialog::TransferDataToWindow() )
254 std::set<wxString> defined;
257 defined.insert( field.GetName() );
265 if( !cfg->m_Drawing.field_names.IsEmpty() )
270 if( defined.count( templateFieldname.m_Name ) <= 0 )
273 field.
SetVisible( templateFieldname.m_Visible );
284 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
285 m_grid->ProcessTableMessage( msg );
295 for(
int unit = 0; unit <
m_libEntry->GetUnitCount(); unit++ )
297 if(
m_libEntry->GetUnitDisplayNames().contains( unit + 1 ) )
344 wxArrayString tmp =
m_libEntry->GetFPFilters();
349 std::set<wxString> availablePins;
352 availablePins.insert(
pin->GetNumber() );
358 for(
const wxString& pinNumber :
group )
360 if( !groupTxt.IsEmpty() )
363 groupTxt << pinNumber;
373 wxArrayString symbolNames;
374 wxString libName =
m_libEntry->GetLibNickname();
376 if( !libName.empty() )
378 m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
382 [](
const wxString& a,
const wxString& b ) ->
int
388 if( symbolNames.Index(
m_libEntry->GetName() ) != wxNOT_FOUND )
393 wxArrayString descendants;
394 m_Parent->GetLibManager().GetDerivedSymbolNames(
m_libEntry->GetName(), libName, descendants );
396 for(
const wxString& descendant : descendants )
398 if( symbolNames.Index( descendant ) != wxNOT_FOUND )
399 symbolNames.Remove( descendant );
404 if( std::shared_ptr<LIB_SYMBOL> rootSymbol =
m_libEntry->GetParent().lock() )
409 if( selection != wxNOT_FOUND )
427 if( !
m_grid->CommitPendingChanges() )
451 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
458 wxString fieldName = field.
GetName(
false );
460 if( fieldName.IsEmpty() && !field.
GetText().IsEmpty() )
480 if( parentName.IsEmpty() )
490 std::set<wxString> seenSubRefs;
496 if( subRef.IsEmpty() )
499 if( !seenSubRefs.insert( subRef.Upper() ).second )
516 if( !
IsOK(
this,
_(
"Delete extra units from symbol?" ) ) )
520 int bodyStyleCount = 0;
548 if( bodyStyleCount < m_libEntry->GetBodyStyleCount() )
550 if( !
IsOK(
this,
_(
"Delete extra body styles from symbol?" ) ) )
560 if( !
m_grid->CommitPendingChanges()
572 if( newName.IsEmpty() )
574 wxMessageBox(
_(
"Symbol must have a name." ) );
580 if( oldName != newName )
582 wxString libName =
m_libEntry->GetLibNickname();
584 if( !libName.empty() &&
m_Parent->GetLibManager().SymbolNameInUse( newName, libName ) )
588 msg.Printf(
_(
"Symbol name '%s' already in use in library '%s'." ),
604 if( editingCurrentSymbol )
609 std::vector<SCH_FIELD> fieldsToSave;
612 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
631 if( field.
GetText().IsEmpty() )
636 else if( fieldName.IsEmpty() )
641 fieldsToSave.push_back( field );
650 wxString libName =
m_libEntry->GetLibNickname();
656 wxCHECK( newParent,
false );
676 m_libEntry->SetHasDeMorganBodyStyles(
false );
677 m_libEntry->SetBodyStyleCount( 1,
false,
false );
683 m_libEntry->SetBodyStyleCount( 2,
false,
true );
688 std::vector<wxString> bodyStyleNames;
696 m_libEntry->SetHasDeMorganBodyStyles(
false );
697 m_libEntry->SetBodyStyleCount( bodyStyleNames.size(),
true,
true );
698 m_libEntry->SetBodyStyleNames( bodyStyleNames );
709 m_libEntry->GetValueField().SetText( newName );
729 m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
740 std::set<wxString> availablePins;
743 availablePins.insert(
pin->GetNumber() );
745 std::vector<std::set<wxString>>& jumpers =
m_libEntry->JumperPinGroups();
750 wxStringTokenizer tokenizer(
m_jumperGroupsGrid->GetCellValue( ii, 0 ),
", \t\r\n", wxTOKEN_STRTOK );
751 std::set<wxString>&
group = jumpers.emplace_back();
753 while( tokenizer.HasMoreTokens() )
755 wxString token = tokenizer.GetNextToken();
757 if( token.IsEmpty() )
760 if( !availablePins.count( token ) )
763 msg.Printf(
_(
"Pin '%s' in jumper pin group %d does not exist in this symbol." ),
769 group.insert( token );
773 if( editingCurrentSymbol )
774 m_Parent->UpdateAfterSymbolProperties( &oldName );
795 wxPoint pos = aEvent.GetPosition();
796 wxPoint unscolled_pos =
m_grid->CalcUnscrolledPosition( pos );
797 int row =
m_grid->YToRow( unscolled_pos.y );
798 int col =
m_grid->XToCol( unscolled_pos.x );
800 if( row == wxNOT_FOUND || col == wxNOT_FOUND || !
m_fields->IsInherited( row ) )
806 m_grid->SetToolTip( wxString::Format(
_(
"This field is inherited from '%s'." ),
807 m_fields->ParentField( row ).GetName() ) );
813 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
814 wxControl* control =
editor->GetControl();
816 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
825 else if( event.GetCol() ==
FDC_NAME )
827 wxString newName =
event.GetString();
829 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
831 if( i == event.GetRow() )
834 if( newName.CmpNoCase(
m_grid->GetCellValue( i,
FDC_NAME ) ) == 0 )
836 DisplayError(
this, wxString::Format(
_(
"The name '%s' is already in use." ), newName ) );
888 [&]() -> std::pair<int, int>
900 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
901 m_grid->ProcessTableMessage( msg );
914 if( row < m_fields->GetMandatoryRowCount() )
916 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
917 m_fields->GetMandatoryRowCount() ) );
929 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
930 m_grid->ProcessTableMessage( msg );
942 return row >
m_fields->GetMandatoryRowCount();
958 return row >=
m_fields->GetMandatoryRowCount();
972 [&]() -> std::pair<int, int>
1018 if( !
m_grid->CommitPendingChanges() )
1021 m_grid->ClearSelection();
1023 std::vector<SCH_FIELD> fields;
1026 fields.emplace_back( field );
1034 for(
const SCH_FIELD& editedField : fields )
1040 if( existingField.GetName() == editedField.GetName() )
1043 existingField.SetText( editedField.GetText() );
1050 m_fields->emplace_back( editedField );
1051 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1052 m_grid->ProcessTableMessage( msg );
1057 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
1064 if( editedField.GetName() == existingField.
GetName() )
1073 m_grid->ClearSelection();
1076 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
1077 m_grid->ProcessTableMessage( msg );
1089 wxCommandEvent
dummy;
1108 wxString filterLine;
1115 filterLine.Replace( wxT(
" " ), wxT(
"_" ) );
1127 wxArrayInt selections;
1133 int idx = selections[0];
1152 if(
m_grid->IsCellEditControlShown() )
1154 int row =
m_grid->GetGridCursorRow();
1155 int col =
m_grid->GetGridCursorCol();
1159 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
1166 std::bitset<64> shownColumns =
m_grid->GetShownColumns();
1172 if( !
m_grid->IsCellEditControlShown() )
1173 m_grid->SetGridWidthsDirty();
1203 textEntry->SelectAll();
1296 for(
int row =
m_unitNamesGrid->GetNumberRows() - needed; row < m_unitNamesGrid->GetNumberRows(); ++row )
1335 if( !
m_grid->CommitPendingChanges() )
1343 [&]() -> 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
void OnGridMotion(wxMouseEvent &event)
void OnUnitSpinCtrlKillFocus(wxFocusEvent &event) override
~DIALOG_LIB_SYMBOL_PROPERTIES()
static int m_lastOpenedPage
void OnMoveDown(wxCommandEvent &event) override
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)
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