51#include <wx/clipbrd.h>
73 std::vector<const EMBEDDED_FILES*> inheritedEmbeddedFiles;
75 if( std::shared_ptr<LIB_SYMBOL> parent =
m_libEntry->GetParent().lock() )
79 inheritedEmbeddedFiles.push_back( parent->GetEmbeddedFiles() );
80 parent = parent->GetParent().lock();
85 std::move( inheritedEmbeddedFiles ) );
86 m_NoteBook->AddPage( m_embeddedFiles,
_(
"Embedded Files" ) );
89 { m_embeddedFiles->GetLocalFiles() } );
90 m_grid->SetTable( m_fields );
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();
211 m_grid->PopEventHandler(
true );
220 if( std::shared_ptr<LIB_SYMBOL> ancestor = aParent->GetParent().lock() )
223 std::vector<SCH_FIELD*> parentFields;
224 aParent->GetFields( parentFields );
226 for(
SCH_FIELD* parentField : parentFields )
230 if( parentField->IsMandatory() )
233 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
242 m_fields->SetFieldInherited( ii, *parentField );
249 m_fields->AddInheritedField( *parentField );
256 if( !wxDialog::TransferDataToWindow() )
259 std::set<wxString> defined;
262 defined.insert( field.GetName() );
270 if( !cfg->m_Drawing.field_names.IsEmpty() )
275 if( defined.count( templateFieldname.m_Name ) <= 0 )
278 field.
SetVisible( templateFieldname.m_Visible );
289 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
290 m_grid->ProcessTableMessage( msg );
300 for(
int unit = 0; unit <
m_libEntry->GetUnitCount(); unit++ )
302 if(
m_libEntry->GetUnitDisplayNames().contains( unit + 1 ) )
348 wxArrayString tmp =
m_libEntry->GetFPFilters();
353 std::set<wxString> availablePins;
356 availablePins.insert(
pin->GetNumber() );
362 for(
const wxString& pinNumber :
group )
364 if( !groupTxt.IsEmpty() )
367 groupTxt << pinNumber;
377 wxArrayString symbolNames;
378 wxString libName =
m_Parent->GetCurLib();
381 wxCHECK( !libName.empty(),
false );
383 m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
387 [](
const wxString& a,
const wxString& b ) ->
int
393 if( symbolNames.Index(
m_libEntry->GetName() ) != wxNOT_FOUND )
398 if( std::shared_ptr<LIB_SYMBOL> rootSymbol =
m_libEntry->GetParent().lock() )
403 if( selection == wxNOT_FOUND )
422 if( !
m_grid->CommitPendingChanges() )
446 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
453 wxString fieldName = field.
GetName(
false );
455 if( fieldName.IsEmpty() && !field.
GetText().IsEmpty() )
475 if( parentName.IsEmpty() )
488 if( !
IsOK(
this,
_(
"Delete extra units from symbol?" ) ) )
492 int bodyStyleCount = 0;
511 if( bodyStyleCount == 0 )
517 if( bodyStyleCount < m_libEntry->GetBodyStyleCount() )
519 if( !
IsOK(
this,
_(
"Delete extra body styles from symbol?" ) ) )
529 if( !
m_grid->CommitPendingChanges()
541 if( newName.IsEmpty() )
543 wxMessageBox(
_(
"Symbol must have a name." ) );
549 if( oldName != newName )
551 wxString libName =
m_Parent->GetCurLib();
553 if(
m_Parent->GetLibManager().SymbolNameInUse( newName, libName ) )
557 msg.Printf(
_(
"Symbol name '%s' already in use in library '%s'." ),
571 std::vector<SCH_FIELD> fieldsToSave;
574 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
586 if( field.
GetText().IsEmpty() )
591 else if( fieldName.IsEmpty() )
596 fieldsToSave.push_back( field );
607 wxString libName =
m_Parent->GetCurLib();
613 wxCHECK( newParent,
false );
633 m_libEntry->SetHasDeMorganBodyStyles(
false );
634 m_libEntry->SetBodyStyleCount( 1,
false,
false );
640 m_libEntry->SetBodyStyleCount( 2,
false,
true );
645 std::vector<wxString> bodyStyleNames;
653 m_libEntry->SetHasDeMorganBodyStyles(
false );
654 m_libEntry->SetBodyStyleCount( bodyStyleNames.size(),
true,
true );
655 m_libEntry->SetBodyStyleNames( bodyStyleNames );
666 m_libEntry->GetValueField().SetText( newName );
685 m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
696 std::vector<std::set<wxString>>& jumpers =
m_libEntry->JumperPinGroups();
701 wxStringTokenizer tokenizer(
m_jumperGroupsGrid->GetCellValue( ii, 0 ),
", \t\r\n", wxTOKEN_STRTOK );
702 std::set<wxString>&
group = jumpers.emplace_back();
704 while( tokenizer.HasMoreTokens() )
706 if( wxString token = tokenizer.GetNextToken(); !token.IsEmpty() )
707 group.insert( token );
711 m_Parent->UpdateAfterSymbolProperties( &oldName );
732 wxPoint pos = aEvent.GetPosition();
733 wxPoint unscolled_pos =
m_grid->CalcUnscrolledPosition( pos );
734 int row =
m_grid->YToRow( unscolled_pos.y );
735 int col =
m_grid->XToCol( unscolled_pos.x );
737 if( row == wxNOT_FOUND || col == wxNOT_FOUND || !
m_fields->IsInherited( row ) )
743 m_grid->SetToolTip( wxString::Format(
_(
"This field is inherited from '%s'." ),
744 m_fields->ParentField( row ).GetName() ) );
750 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
751 wxControl* control =
editor->GetControl();
753 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
762 else if( event.GetCol() ==
FDC_NAME )
764 wxString newName =
event.GetString();
766 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
768 if( i == event.GetRow() )
771 if( newName.CmpNoCase(
m_grid->GetCellValue( i,
FDC_NAME ) ) == 0 )
773 DisplayError(
this, wxString::Format(
_(
"The name '%s' is already in use." ), newName ) );
825 [&]() -> std::pair<int, int>
837 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
838 m_grid->ProcessTableMessage( msg );
851 if( row < m_fields->GetMandatoryRowCount() )
853 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
854 m_fields->GetMandatoryRowCount() ) );
866 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
867 m_grid->ProcessTableMessage( msg );
879 return row >
m_fields->GetMandatoryRowCount();
895 return row >=
m_fields->GetMandatoryRowCount();
909 [&]() -> std::pair<int, int>
955 if( !
m_grid->CommitPendingChanges() )
960 std::vector<SCH_FIELD> fields;
963 fields.emplace_back( field );
971 for(
const SCH_FIELD& editedField : fields )
977 if( existingField.GetName() == editedField.GetName() )
980 existingField.SetText( editedField.GetText() );
987 m_fields->emplace_back( editedField );
988 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
989 m_grid->ProcessTableMessage( msg );
994 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
1001 if( editedField.GetName() == existingField.
GetName() )
1010 m_grid->ClearSelection();
1013 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
1014 m_grid->ProcessTableMessage( msg );
1026 wxCommandEvent
dummy;
1045 wxString filterLine;
1052 filterLine.Replace( wxT(
" " ), wxT(
"_" ) );
1064 wxArrayInt selections;
1070 int idx = selections[0];
1089 if(
m_grid->IsCellEditControlShown() )
1091 int row =
m_grid->GetGridCursorRow();
1092 int col =
m_grid->GetGridCursorCol();
1096 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
1103 std::bitset<64> shownColumns =
m_grid->GetShownColumns();
1109 if( !
m_grid->IsCellEditControlShown() )
1110 m_grid->SetGridWidthsDirty();
1140 textEntry->SelectAll();
1230 for(
int row =
m_unitNamesGrid->GetNumberRows() - needed; row < m_unitNamesGrid->GetNumberRows(); ++row )
1269 if( !
m_grid->CommitPendingChanges() )
1277 [&]() -> 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_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
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual const wxString & GetText() const
Return the string associated with the text object.
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)
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