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 ) )
76 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
80 [&]( wxCommandEvent& aEvent )
84 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
111 m_grid->Connect( wxEVT_GRID_CELL_CHANGING,
117 [&]( wxCommandEvent& aEvent )
119 wxCommandEvent cmdEvent( EDA_EVT_LISTBOX_DELETE );
125 [&]( wxCommandEvent& aEvent )
144 m_grid->GetParent()->Layout();
162 m_grid->Disconnect( wxEVT_GRID_CELL_CHANGING,
167 m_grid->PopEventHandler(
true );
173 if( !wxDialog::TransferDataToWindow() )
179 std::set<wxString> defined;
182 defined.insert( field.GetName() );
198 if( defined.count( templateFieldname.m_Name ) <= 0 )
201 field.
SetVisible( templateFieldname.m_Visible );
210 for(
size_t i = 0; i <
m_fields->size(); ++i )
214 m_fields->at( i ).SetPosition( pos );
219 m_grid->ProcessTableMessage( msg );
256 wxArrayString symbolNames;
260 wxCHECK( !libName.empty(),
false );
266 [](
const wxString& a,
const wxString& b ) ->
int
280 if( selection == wxNOT_FOUND )
319 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
326 wxString fieldName = field.
GetName(
false );
328 if( fieldName.IsEmpty() && !field.
GetText().IsEmpty() )
348 if( parentName.IsEmpty() )
362 if( !
IsOK(
this,
_(
"Delete extra units from symbol?" ) ) )
368 if( !
IsOK(
this,
_(
"Delete alternate body style (De Morgan) from symbol?" ) ) )
378 if( !wxDialog::TransferDataFromWindow() )
387 if( newName.IsEmpty() )
389 wxMessageBox(
_(
"Symbol must have a name." ) );
393 if( oldName != newName )
401 msg.Printf(
_(
"Symbol name '%s' already in use in library '%s'." ),
409 UNDO_REDO::LIB_RENAME );
418 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
422 m_fields->at( ii ).SetPosition( pos );
435 if( field.
GetText().IsEmpty() )
440 else if( fieldName.IsEmpty() )
460 wxCHECK( newParent,
false );
519 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
520 wxControl* control =
editor->GetControl();
522 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
531 else if( event.GetCol() ==
FDC_NAME )
533 wxString newName =
event.GetString();
535 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
537 if( i == event.GetRow() )
540 if( newName.CmpNoCase(
m_grid->GetCellValue( i,
FDC_NAME ) ) == 0 )
542 DisplayError(
this, wxString::Format(
_(
"The name '%s' is already in use." ),
591 int fieldID = (int)
m_fields->size();
601 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
602 m_grid->ProcessTableMessage( msg );
607 m_grid->EnableCellEditControl();
608 m_grid->ShowCellEditControl();
616 wxArrayInt selectedRows =
m_grid->GetSelectedRows();
618 if( selectedRows.empty() &&
m_grid->GetGridCursorRow() >= 0 )
619 selectedRows.push_back(
m_grid->GetGridCursorRow() );
621 if( selectedRows.empty() )
624 for(
int row : selectedRows )
626 if( row < m_fields->GetMandatoryRowCount() )
628 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
638 selectedRows.Sort( [](
int* first,
int* second ) {
return *second - *first; } );
640 for(
int row : selectedRows )
645 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
646 m_grid->ProcessTableMessage( msg );
648 if(
m_grid->GetNumberRows() > 0 )
650 m_grid->MakeCellVisible( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
651 m_grid->SetGridCursor( std::max( 0, row-1 ),
m_grid->GetGridCursorCol() );
664 int i =
m_grid->GetGridCursorRow();
673 m_grid->SetGridCursor( i - 1,
m_grid->GetGridCursorCol() );
690 int i =
m_grid->GetGridCursorRow();
699 m_grid->SetGridCursor( i + 1,
m_grid->GetGridCursorCol() );
716 std::vector<SCH_FIELD> fields;
719 fields.emplace_back( field );
727 for(
const SCH_FIELD& editedField : fields )
733 if( existingField.GetName() == editedField.GetName() )
736 existingField.SetText( editedField.GetText() );
743 m_fields->emplace_back( editedField );
744 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
745 m_grid->ProcessTableMessage( msg );
750 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
757 if( editedField.GetName() == existingField.
GetName() )
767 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
768 m_grid->ProcessTableMessage( msg );
780 wxCommandEvent
dummy;
806 filterLine.Replace( wxT(
" " ), wxT(
"_" ) );
818 wxArrayInt selections;
824 int idx = selections[0];
848 for(
int i = 2; i <
m_grid->GetNumberCols(); i++ )
849 fixedColsWidth +=
m_grid->GetColSize( i );
851 m_grid->SetColSize(
FDC_VALUE, std::max( 120, width - fixedColsWidth ) );
860 if(
m_grid->IsCellEditControlShown() )
862 int row =
m_grid->GetGridCursorRow();
863 int col =
m_grid->GetGridCursorCol();
867 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
880 if( !
m_grid->IsCellEditControlShown() )
911 textEntry->SelectAll();
933 auto new_size =
event.GetSize();
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
wxCheckBox * m_hasAlternateBodyStyles
wxButton * m_spiceFieldsButton
wxTextCtrl * m_KeywordCtrl
STD_BITMAP_BUTTON * m_bpAdd
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
STD_BITMAP_BUTTON * m_bpMoveDown
wxButton * m_stdSizerButtonCancel
STD_BITMAP_BUTTON * m_addFilterButton
wxCheckBox * m_excludeFromBomCheckBox
wxCheckBox * m_OptionPartsInterchangeable
wxCheckBox * m_excludeFromSimCheckBox
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 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
std::bitset< 64 > m_shownColumns
void OnMoveUp(wxCommandEvent &event) override
SYMBOL_EDIT_FRAME * m_Parent
void OnText(wxCommandEvent &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
bool TransferDataToWindow() override
void OnGridCellChanging(wxGridEvent &event)
void onPowerCheckBox(wxCommandEvent &aEvent) override
void OnAddField(wxCommandEvent &event) override
void OnEditSpiceModel(wxCommandEvent &event) override
void OnSpinCtrl(wxSpinEvent &event) override
UNIT_BINDER m_pinNameOffset
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)
int GetNumberRows() override
int GetMandatoryRowCount() const
A text control validator used for validating the text allowed in fields.
Define a library symbol object.
wxString GetKeyWords() const override
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 SetFields(const std::vector< SCH_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
SCH_FIELD & GetValueField() const
Return reference to the value field.
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)
wxArrayString GetFPFilters() const
void SetFPFilters(const wxArrayString &aFilters)
void CopyFields(std::vector< SCH_FIELD > &aList)
void SetHasAlternateBodyStyle(bool aHasAlternate, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the symbol.
int GetUnitCount() const override
LIB_SYMBOL_REF & GetParent()
virtual void SetName(const wxString &aName)
EMBEDDED_FILES * GetLocalFiles()
bool TransferDataToWindow() override
virtual SETTINGS_MANAGER & GetSettingsManager() const
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
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)
void SetText(const wxString &aText) override
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
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)
LIB_SYMBOL * GetAlias(const wxString &aAlias, 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...
bool SymbolExists(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol with a specific alias exists in library (either original one or buffered).
void GetSymbolNames(const wxString &aLibName, wxArrayString &aSymbolNames, SYMBOL_NAME_FILTER aFilter=SYMBOL_NAME_FILTER::ALL)
bool GetExcludedFromBoard() const
virtual void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
bool GetExcludedFromBOM() const
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.
virtual bool GetShowPinNames() const
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
virtual bool GetShowPinNumbers() const
bool GetExcludedFromSim() const override
void AddTemplateFieldNames(const wxString &aSerializedFieldNames)
Add a serialized list of template field names.
const TEMPLATE_FIELDNAMES & 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 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...
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
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 DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message 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.
PGM_BASE & Pgm()
The global program "get" accessor.
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.
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
VECTOR2< int32_t > VECTOR2I