50#include <wx/clipbrd.h>
79 [&]( wxCommandEvent& aEvent )
83 m_grid->SetSelectionMode( wxGrid::wxGridSelectRows );
86 std::vector<SCH_FIELD> fields;
92 if( std::shared_ptr<LIB_SYMBOL> parent =
m_libEntry->GetParent().lock() )
95 m_grid->ShowHideColumns(
"0 1 2 3 4 5 6 7" );
103 [
this]( wxCommandEvent& aEvent )
113 [
this]( wxCommandEvent& aEvent )
153 [&]( wxCommandEvent& aEvent )
155 wxCommandEvent cmdEvent( EDA_EVT_LISTBOX_DELETE );
161 [&]( wxCommandEvent& aEvent )
178 m_grid->GetParent()->Layout();
198 m_grid->PopEventHandler(
true );
207 if( std::shared_ptr<LIB_SYMBOL> ancestor = aParent->GetParent().lock() )
210 std::vector<SCH_FIELD*> parentFields;
211 aParent->GetFields( parentFields );
213 for(
SCH_FIELD* parentField : parentFields )
217 if( parentField->IsMandatory() )
220 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
229 m_fields->SetFieldInherited( ii, *parentField );
236 m_fields->AddInheritedField( *parentField );
243 if( !wxDialog::TransferDataToWindow() )
246 std::set<wxString> defined;
249 defined.insert( field.GetName() );
257 if( !cfg->m_Drawing.field_names.IsEmpty() )
262 if( defined.count( templateFieldname.m_Name ) <= 0 )
265 field.
SetVisible( templateFieldname.m_Visible );
276 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
277 m_grid->ProcessTableMessage( msg );
287 for(
int unit = 0; unit <
m_libEntry->GetUnitCount(); unit++ )
289 if(
m_libEntry->GetUnitDisplayNames().contains( unit + 1 ) )
335 wxArrayString tmp =
m_libEntry->GetFPFilters();
340 std::set<wxString> availablePins;
343 availablePins.insert(
pin->GetNumber() );
349 for(
const wxString& pinNumber :
group )
351 if( !groupTxt.IsEmpty() )
354 groupTxt << pinNumber;
364 wxArrayString symbolNames;
365 wxString libName =
m_Parent->GetCurLib();
368 wxCHECK( !libName.empty(),
false );
370 m_Parent->GetLibManager().GetSymbolNames( libName, symbolNames );
374 [](
const wxString& a,
const wxString& b ) ->
int
380 if( symbolNames.Index(
m_libEntry->GetName() ) != wxNOT_FOUND )
385 if( std::shared_ptr<LIB_SYMBOL> rootSymbol =
m_libEntry->GetParent().lock() )
390 if( selection == wxNOT_FOUND )
409 if( !
m_grid->CommitPendingChanges() )
433 for(
int ii = 0; ii < (int)
m_fields->size(); ++ii )
440 wxString fieldName = field.
GetName(
false );
442 if( fieldName.IsEmpty() && !field.
GetText().IsEmpty() )
462 if( parentName.IsEmpty() )
475 if( !
IsOK(
this,
_(
"Delete extra units from symbol?" ) ) )
479 int bodyStyleCount = 0;
498 if( bodyStyleCount == 0 )
504 if( bodyStyleCount < m_libEntry->GetBodyStyleCount() )
506 if( !
IsOK(
this,
_(
"Delete extra body styles from symbol?" ) ) )
516 if( !
m_grid->CommitPendingChanges()
527 if( newName.IsEmpty() )
529 wxMessageBox(
_(
"Symbol must have a name." ) );
535 if( oldName != newName )
537 wxString libName =
m_Parent->GetCurLib();
539 if(
m_Parent->GetLibManager().SymbolNameInUse( newName, libName ) )
543 msg.Printf(
_(
"Symbol name '%s' already in use in library '%s'." ),
557 std::vector<SCH_FIELD> fieldsToSave;
560 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
572 if( field.
GetText().IsEmpty() )
577 else if( fieldName.IsEmpty() )
582 fieldsToSave.push_back( field );
593 wxString libName =
m_Parent->GetCurLib();
599 wxCHECK( newParent,
false );
619 m_libEntry->SetHasDeMorganBodyStyles(
false );
620 m_libEntry->SetBodyStyleCount( 1,
false,
false );
626 m_libEntry->SetBodyStyleCount( 2,
false,
true );
631 std::vector<wxString> bodyStyleNames;
639 m_libEntry->SetHasDeMorganBodyStyles(
false );
640 m_libEntry->SetBodyStyleCount( bodyStyleNames.size(),
true,
true );
641 m_libEntry->SetBodyStyleNames( bodyStyleNames );
652 m_libEntry->GetValueField().SetText( newName );
671 m_libEntry->SetPinNameOffset( offset == 0 ? 20 : offset );
682 std::vector<std::set<wxString>>& jumpers =
m_libEntry->JumperPinGroups();
687 wxStringTokenizer tokenizer(
m_jumperGroupsGrid->GetCellValue( ii, 0 ),
", \t\r\n", wxTOKEN_STRTOK );
688 std::set<wxString>&
group = jumpers.emplace_back();
690 while( tokenizer.HasMoreTokens() )
692 if( wxString token = tokenizer.GetNextToken(); !token.IsEmpty() )
693 group.insert( token );
697 m_Parent->UpdateAfterSymbolProperties( &oldName );
718 wxPoint pos = aEvent.GetPosition();
719 wxPoint unscolled_pos =
m_grid->CalcUnscrolledPosition( pos );
720 int row =
m_grid->YToRow( unscolled_pos.y );
721 int col =
m_grid->XToCol( unscolled_pos.x );
723 if( row == wxNOT_FOUND || col == wxNOT_FOUND || !
m_fields->IsInherited( row ) )
729 m_grid->SetToolTip( wxString::Format(
_(
"This field is inherited from '%s'." ),
730 m_fields->ParentField( row ).GetName() ) );
736 wxGridCellEditor*
editor =
m_grid->GetCellEditor( event.GetRow(), event.GetCol() );
737 wxControl* control =
editor->GetControl();
739 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
748 else if( event.GetCol() ==
FDC_NAME )
750 wxString newName =
event.GetString();
752 for(
int i = 0; i <
m_grid->GetNumberRows(); ++i )
754 if( i == event.GetRow() )
757 if( newName.CmpNoCase(
m_grid->GetCellValue( i,
FDC_NAME ) ) == 0 )
759 DisplayError(
this, wxString::Format(
_(
"The name '%s' is already in use." ), newName ) );
811 [&]() -> std::pair<int, int>
823 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
824 m_grid->ProcessTableMessage( msg );
837 if( row < m_fields->GetMandatoryRowCount() )
839 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
840 m_fields->GetMandatoryRowCount() ) );
852 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
853 m_grid->ProcessTableMessage( msg );
865 return row >
m_fields->GetMandatoryRowCount();
881 return row >=
m_fields->GetMandatoryRowCount();
895 [&]() -> std::pair<int, int>
941 if( !
m_grid->CommitPendingChanges() )
946 std::vector<SCH_FIELD> fields;
949 fields.emplace_back( field );
957 for(
const SCH_FIELD& editedField : fields )
963 if( existingField.GetName() == editedField.GetName() )
966 existingField.SetText( editedField.GetText() );
973 m_fields->emplace_back( editedField );
974 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
975 m_grid->ProcessTableMessage( msg );
980 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
987 if( editedField.GetName() == existingField.
GetName() )
999 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
1000 m_grid->ProcessTableMessage( msg );
1012 wxCommandEvent
dummy;
1031 wxString filterLine;
1038 filterLine.Replace( wxT(
" " ), wxT(
"_" ) );
1050 wxArrayInt selections;
1056 int idx = selections[0];
1075 if(
m_grid->IsCellEditControlShown() )
1077 int row =
m_grid->GetGridCursorRow();
1078 int col =
m_grid->GetGridCursorCol();
1082 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
1089 std::bitset<64> shownColumns =
m_grid->GetShownColumns();
1095 if( !
m_grid->IsCellEditControlShown() )
1096 m_grid->SetGridWidthsDirty();
1126 textEntry->SelectAll();
1216 for(
int row =
m_unitNamesGrid->GetNumberRows() - needed; row < m_unitNamesGrid->GetNumberRows(); ++row )
1255 if( !
m_grid->CommitPendingChanges() )
1263 [&]() -> std::pair<int, int>
constexpr EDA_IU_SCALE schIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
STD_BITMAP_BUTTON * m_editFilterButton
WX_GRID * m_jumperGroupsGrid
STD_BITMAP_BUTTON * m_bpAddBodyStyle
wxButton * m_spiceFieldsButton
STD_BITMAP_BUTTON * m_bpAddJumperGroup
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
STD_BITMAP_BUTTON * m_bpAdd
WX_GRID * m_bodyStyleNamesGrid
wxButton * m_stdSizerButtonOK
wxBoxSizer * bSizerLowerBasicPanel
STD_BITMAP_BUTTON * m_bpDelete
wxCheckBox * m_PinsNameInsideButt
wxRadioButton * m_radioSingle
STD_BITMAP_BUTTON * m_deleteFilterButton
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
STD_BITMAP_BUTTON * m_bpMoveDown
wxButton * m_stdSizerButtonCancel
WX_GRID * m_unitNamesGrid
STD_BITMAP_BUTTON * m_addFilterButton
wxCheckBox * m_OptionLocalPower
wxTextCtrl * m_nameOffsetCtrl
wxCheckBox * m_excludeFromBomCheckBox
STD_BITMAP_BUTTON * m_bpRemoveJumperGroup
wxSpinCtrl * m_unitSpinCtrl
wxCheckBox * m_OptionPartsInterchangeable
wxCheckBox * m_excludeFromSimCheckBox
wxRadioButton * m_radioCustom
STD_BITMAP_BUTTON * m_bpMoveUp
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 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)
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.
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
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.
bool IsSymbolFromLegacyLibrary() const
bool IsSymbolFromSchematic() const
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