50#include <wx/clipbrd.h>
63 m_libEntry( aLibEntry ),
64 m_pinNameOffset( aParent, m_nameOffsetLabel, m_nameOffsetCtrl, m_nameOffsetUnits, true ),
65 m_delayedFocusCtrl( nullptr ),
66 m_delayedFocusGrid( nullptr ),
67 m_delayedFocusRow( -1 ),
68 m_delayedFocusColumn( -1 ),
69 m_delayedFocusPage( -1 ),
70 m_fpFilterTricks(
std::make_unique<
LISTBOX_TRICKS>( *this, *m_FootprintFilterListBox ) )
79 [&]( wxCommandEvent& aEvent )
83 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
86 std::vector<SCH_FIELD> fields;
96 std::vector<SCH_FIELD*> parentFields;
97 parent->GetFields( parentFields );
99 for(
size_t ii = 0; ii < parentFields.size(); ++ii )
107 for(
size_t jj = 0; jj <
m_fields->size(); ++jj )
156 m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
158 m_grid->Connect( wxEVT_GRID_CELL_CHANGED,
165 [&]( wxCommandEvent& aEvent )
167 wxCommandEvent cmdEvent( EDA_EVT_LISTBOX_DELETE );
173 [&]( wxCommandEvent& aEvent )
190 m_grid->GetParent()->Layout();
208 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
210 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGED,
215 m_grid->PopEventHandler(
true );
221 if( !wxDialog::TransferDataToWindow() )
224 std::set<wxString> defined;
227 defined.insert( field.GetName() );
235 if( !cfg->m_Drawing.field_names.IsEmpty() )
240 if( defined.count( templateFieldname.m_Name ) <= 0 )
243 field.
SetVisible( templateFieldname.m_Visible );
252 for(
size_t i = 0; i <
m_fields->size(); ++i )
256 m_fields->at( i ).SetPosition( pos );
261 m_grid->ProcessTableMessage( msg );
306 std::set<wxString> availablePins;
309 availablePins.insert(
pin->GetNumber() );
316 for(
const wxString& pinNumber :
group )
318 availablePins.erase( pinNumber );
319 groupTxt << pinNumber;
321 if( ++i <
group.size() )
328 for(
const wxString&
pin : availablePins )
334 wxArrayString symbolNames;
338 wxCHECK( !libName.empty(),
false );
344 [](
const wxString& a,
const wxString& b ) ->
int
360 if( selection == wxNOT_FOUND )
403 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
410 wxString fieldName = field.
GetName(
false );
412 if( fieldName.IsEmpty() && !field.
GetText().IsEmpty() )
432 if( parentName.IsEmpty() )
445 if( !
IsOK(
this,
_(
"Delete extra units from symbol?" ) ) )
451 if( !
IsOK(
this,
_(
"Delete alternate body style (De Morgan) from symbol?" ) ) )
461 if( !wxDialog::TransferDataFromWindow() )
470 if( newName.IsEmpty() )
472 wxMessageBox(
_(
"Symbol must have a name." ) );
478 if( oldName != newName )
486 msg.Printf(
_(
"Symbol name '%s' already in use in library '%s'." ),
493 opType = UNDO_REDO::LIB_RENAME;
500 std::vector<SCH_FIELD> fieldsToSave;
503 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
519 if( field.
GetText().IsEmpty() )
524 else if( fieldName.IsEmpty() )
529 fieldsToSave.push_back( field );
546 wxCHECK( newParent,
false );
602 std::set<wxString>&
group = jumpers.emplace_back();
604 while( tokenizer.HasMoreTokens() )
606 if( wxString token = tokenizer.GetNextToken(); !token.IsEmpty() )
607 group.insert( token );
627 wxPoint pos = aEvent.GetPosition();
628 wxPoint unscolled_pos =
m_grid->CalcUnscrolledPosition( pos );
629 int row =
m_grid->YToRow( unscolled_pos.y );
630 int col =
m_grid->XToCol( unscolled_pos.x );
639 wxString::Format(
_(
"This field is inherited from '%s'." ),
646 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
647 wxControl* control =
editor->GetControl();
649 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
658 else if( event.GetCol() ==
FDC_NAME )
660 wxString newName =
event.GetString();
662 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
664 if( i == event.GetRow() )
667 if( newName.CmpNoCase(
m_grid->GetCellValue( i,
FDC_NAME ) ) == 0 )
669 DisplayError(
this, wxString::Format(
_(
"The name '%s' is already in use." ), newName ) );
721 [&]() -> std::pair<int, int>
733 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
734 m_grid->ProcessTableMessage( msg );
747 if( row < m_fields->GetMandatoryRowCount() )
749 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
762 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
763 m_grid->ProcessTableMessage( msg );
809 std::vector<SCH_FIELD> fields;
812 fields.emplace_back( field );
820 for(
const SCH_FIELD& editedField : fields )
826 if( existingField.GetName() == editedField.GetName() )
829 existingField.SetText( editedField.GetText() );
837 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
838 m_grid->ProcessTableMessage( msg );
843 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
850 if( editedField.GetName() == existingField.
GetName() )
862 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
863 m_grid->ProcessTableMessage( msg );
875 wxCommandEvent
dummy;
901 filterLine.Replace( wxT(
" " ), wxT(
"_" ) );
913 wxArrayInt selections;
919 int idx = selections[0];
943 for(
int i = 2; i <
m_grid->GetNumberCols(); i++ )
944 fixedColsWidth +=
m_grid->GetColSize( i );
946 m_grid->SetColSize(
FDC_VALUE, std::max( 120, width - fixedColsWidth ) );
955 if(
m_grid->IsCellEditControlShown() )
957 int row =
m_grid->GetGridCursorRow();
958 int col =
m_grid->GetGridCursorCol();
962 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
975 if( !
m_grid->IsCellEditControlShown() )
1006 textEntry->SelectAll();
1028 auto new_size =
event.GetSize();
1116 wxArrayInt selections;
1119 if( !selections.empty() )
1127 for(
int idx : selections )
1131 if( ++i < selections.Count() )
1135 for(
int idx = (
int) selections.size() - 1; idx >= 0; --idx )
1148 wxArrayInt selections;
1151 if( !selections.empty() )
1156 for(
int idx : selections )
1160 while( tokenizer.HasMoreTokens() )
1162 if( wxString token = tokenizer.GetNextToken(); !token.IsEmpty() )
1167 for(
int idx = (
int) selections.size() - 1; idx >= 0; --idx )
1178 wxArrayInt selections;
1186 wxArrayInt selections;
constexpr EDA_IU_SCALE schIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Class DIALOG_LIB_SYMBOL_PROPERTIES_BASE.
STD_BITMAP_BUTTON * m_editFilterButton
wxBitmapButton * m_btnCreateJumperPinGroup
wxCheckBox * m_hasAlternateBodyStyles
wxButton * m_spiceFieldsButton
wxTextCtrl * m_KeywordCtrl
STD_BITMAP_BUTTON * m_bpAdd
wxListBox * m_listJumperPinGroups
wxButton * m_stdSizerButtonOK
wxBoxSizer * bSizerLowerBasicPanel
STD_BITMAP_BUTTON * m_bpDelete
wxCheckBox * m_PinsNameInsideButt
STD_BITMAP_BUTTON * m_deleteFilterButton
wxListBox * m_FootprintFilterListBox
wxComboBox * m_inheritanceSelectCombo
wxSpinCtrl * m_SelNumberOfUnits
wxCheckBox * m_ShowPinNumButt
wxCheckBox * m_OptionPower
wxCheckBox * m_excludeFromBoardCheckBox
wxCheckBox * m_cbDuplicatePinsAreJumpers
STD_BITMAP_BUTTON * m_bpMoveDown
wxButton * m_stdSizerButtonCancel
wxListBox * m_listAvailablePins
STD_BITMAP_BUTTON * m_addFilterButton
wxCheckBox * m_OptionLocalPower
wxCheckBox * m_excludeFromBomCheckBox
wxCheckBox * m_OptionPartsInterchangeable
wxCheckBox * m_excludeFromSimCheckBox
wxBitmapButton * m_btnRemoveJumperPinGroup
STD_BITMAP_BUTTON * m_bpMoveUp
wxTextCtrl * m_SymbolNameCtrl
wxStaticText * m_inheritsStaticText
wxCheckBox * m_ShowPinNameButt
void OnSymbolNameKillFocus(wxFocusEvent &event) override
std::unique_ptr< LISTBOX_TRICKS > m_fpFilterTricks
void OnPageChanging(wxNotebookEvent &event) override
wxString m_delayedErrorMessage
void OnSpinCtrlText(wxCommandEvent &event) override
FIELDS_GRID_TABLE * m_fields
WX_GRID * m_delayedFocusGrid
void OnSizeGrid(wxSizeEvent &event) override
std::set< wxString > m_addedTemplateFields
DIALOG_LIB_SYMBOL_PROPERTIES(SYMBOL_EDIT_FRAME *parent, LIB_SYMBOL *aLibEntry)
wxControl * m_delayedFocusCtrl
void OnGroupedPinListClick(wxCommandEvent &event) override
void OnUpdateUI(wxUpdateUIEvent &event) override
static LAST_LAYOUT m_lastLayout
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 OnGridCellChanged(wxGridEvent &event)
std::bitset< 64 > m_shownColumns
void OnMoveUp(wxCommandEvent &event) override
void OnAvailablePinsClick(wxCommandEvent &event) override
SYMBOL_EDIT_FRAME * m_Parent
void OnText(wxCommandEvent &event) override
void OnGridMotion(wxMouseEvent &event)
~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
bool TransferDataToWindow() override
void OnGridCellChanging(wxGridEvent &event)
void onPowerCheckBox(wxCommandEvent &aEvent) override
void OnBtnCreateJumperPinGroup(wxCommandEvent &event) override
void OnAddField(wxCommandEvent &event) override
void OnEditSpiceModel(wxCommandEvent &event) override
void OnSpinCtrl(wxSpinEvent &event) override
UNIT_BINDER m_pinNameOffset
void OnBtnRemoveJumperPinGroup(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void resetSize()
Clear the existing dialog size and position.
void EndQuasiModal(int retCode)
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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)
bool IsInherited(size_t aRow) const
SCH_FIELD * GetField(FIELD_T aFieldId)
int GetNumberRows() override
void push_back(const SCH_FIELD &field)
int GetMandatoryRowCount() const
bool EraseRow(size_t row)
void SetFieldInherited(size_t aRow, const SCH_FIELD &aParent)
int GetFieldRow(FIELD_T aFieldId)
const SCH_FIELD & ParentField(size_t row) const
void AddInheritedField(const SCH_FIELD &aParent)
void emplace_back(const SCH_FIELD &field)
void SwapRows(size_t a, size_t b)
A text control validator used for validating the text allowed in fields.
Define a library symbol object.
wxString GetKeyWords() const override
std::vector< SCH_PIN * > GetPins(int aUnit, int aBodyStyle) const
Return a list of pin object pointers from the draw item list.
bool IsPower() const override
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
bool UnitsLocked() const
Check whether symbol units are interchangeable.
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
void SetDuplicatePinNumbersAreJumpers(bool aEnabled)
void SetFields(const std::vector< SCH_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
bool HasAlternateBodyStyle() const override
Test if symbol has more than one body conversion type (DeMorgan).
void LockUnits(bool aLockUnits)
Set interchangeable the property for symbol units.
void SetParent(LIB_SYMBOL *aParent=nullptr)
wxString GetName() const override
void SetKeyWords(const wxString &aKeyWords)
SCH_FIELD & GetValueField()
Return reference to the value field.
bool IsLocalPower() const override
wxArrayString GetFPFilters() const
void SetFPFilters(const wxArrayString &aFilters)
void CopyFields(std::vector< SCH_FIELD > &aList)
Create a copy of the SCH_FIELDs, sorted in ordinal order.
void SetHasAlternateBodyStyle(bool aHasAlternate, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the symbol.
int GetUnitCount() const override
bool GetDuplicatePinNumbersAreJumpers() const
LIB_SYMBOL_REF & GetParent()
std::vector< std::set< wxString > > & JumperPinGroups()
Each jumper pin group is a set of pin numbers that should be treated as internally connected.
virtual void SetName(const wxString &aName)
EMBEDDED_FILES * GetLocalFiles()
bool TransferDataToWindow() override
void SetOrdinal(int aOrdinal)
VECTOR2I GetPosition() const override
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 SetPosition(const VECTOR2I &aPosition) override
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
wxString m_EditSymbolVisibleColumns
The symbol library editor main window.
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
wxString GetCurLib() const
The nickname of the current library being edited and empty string if none.
bool GetShowDeMorgan() const
bool IsSymbolFromLegacyLibrary() const
bool IsSymbolFromSchematic() const
void SaveCopyInUndoList(const wxString &aDescription, LIB_SYMBOL *aSymbol, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT)
Create a copy of the current symbol, and save it in the undo list.
SYMBOL_EDITOR_SETTINGS * GetSettings() const
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
void SetShowDeMorgan(bool show)
bool SymbolNameInUse(const wxString &aName, const wxString &aLibrary)
Return true if the symbol name is already in use in the specified library.
LIB_SYMBOL * GetSymbol(const wxString &aSymbolName, const wxString &aLibrary) const
Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there is no w...
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
void SetExcludedFromBoard(bool aExcludeFromBoard) override
Set or clear exclude from board netlist flag.
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
int GetPinNameOffset() const
virtual void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
bool GetExcludedFromBoard() const override
void SetExcludedFromBOM(bool aExcludeFromBOM) override
Set or clear the exclude from schematic bill of materials flag.
virtual bool GetShowPinNames() const
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
virtual bool GetShowPinNumbers() const
bool GetExcludedFromBOM() const override
bool GetExcludedFromSim() const override
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.
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
virtual void ChangeValue(int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion WITHOUT trigger...
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
void OnMoveRowUp(const std::function< void(int row)> &aMover)
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
void OnMoveRowDown(const std::function< void(int row)> &aMover)
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
std::bitset< 64 > GetShownColumns()
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
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.
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
Collection of utility functions for component reference designators (refdes)
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:...
constexpr int MilsToIU(int mils) const
Hold a name of a symbol's field, field value, and default visibility.
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
VECTOR2< int32_t > VECTOR2I