29#include <wx/tooltip.h>
104 wxGridCellAttr* attr =
nullptr;
108 attr =
new wxGridCellAttr;
109 attr->SetReadOnly(
true );
114 wxArrayString choices;
115 choices.push_back( lib_pin->
GetName() );
117 for(
const std::pair<const wxString, SCH_PIN::ALT>& alt : lib_pin->
GetAlternates() )
118 choices.push_back( alt.first );
120 attr =
new wxGridCellAttr();
152 case COL_TYPE:
return _(
"Electrical Type" );
154 default: wxFAIL;
return wxEmptyString;
163 bool CanSetValueAs(
int aRow,
int aCol,
const wxString& aTypeName )
override
171 return GetValue( at( aRow ), aCol );
179 return wxEmptyString;
180 else if( aPin.
GetAlt().IsEmpty() )
192 default: wxFAIL;
return wxEmptyString;
196 wxGridCellAttr*
GetAttr(
int aRow,
int aCol, wxGridCellAttr::wxAttrKind aKind )
override
223 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
228 if( aValue == at( aRow ).GetLibPin()->GetName() )
229 at( aRow ).SetAlt( wxEmptyString );
231 at( aRow ).SetAlt( aValue );
249 wxString lhStr =
GetValue( lhs, sortCol );
250 wxString rhStr =
GetValue( rhs, sortCol );
264 auto cmp = [ ascending ](
const auto a,
const auto b )
281 res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
293 std::sort( begin(),
end(),
294 [ aSortCol, ascending ](
const SCH_PIN& lhs,
const SCH_PIN& rhs ) ->
bool
296 return compare( lhs, rhs, aSortCol, ascending );
312 m_fieldsSize( 0, 0 ),
313 m_lastRequestedFieldsSize( 0, 0 ),
314 m_lastRequestedPinsSize( 0, 0 ),
315 m_editorShown( false ),
317 m_dataModel( nullptr )
332 [&]( wxCommandEvent& aEvent )
336 m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
351 m_pinTablePage->SetToolTip(
_(
"Alternate pin assignments are not available for De Morgan symbols." ) );
371 m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
378 wxToolTip::Enable(
true );
393 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
396 evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
409 cfg->m_Appearance.edit_symbol_width = GetSize().x;
410 cfg->m_Appearance.edit_symbol_height = GetSize().y;
438 if( !wxDialog::TransferDataToWindow() )
441 std::set<wxString> defined;
453 defined.insert( field.
GetName() );
459 GetParent()->Schematic().Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
461 if( defined.count( templateFieldname.m_Name ) <= 0 )
464 field.
SetVisible( templateFieldname.m_Visible );
506 switch( orientation )
553 std::vector<SCH_FIELD> fields;
556 fields.emplace_back( field );
564 for(
const SCH_FIELD& editedField : fields )
570 if( existingField.GetName() == editedField.GetName() )
573 existingField.SetText( editedField.GetText() );
581 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
587 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
594 if( editedField.GetName() == existingField.
GetName() )
606 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
632 for(
size_t i = 0; i <
m_fields->size(); ++i )
639 wxString fieldName = field.
GetName(
false );
641 if( fieldName.IsEmpty() )
645 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
659 if( !wxDialog::TransferDataFromWindow() )
670 bool replaceOnCurrentScreen;
671 wxCHECK( currentScreen,
false );
729 const wxString& fieldName = field.GetCanonicalName();
731 if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
733 else if( fieldName.IsEmpty() )
734 field.SetName(
_(
"untitled" ) );
736 fields.push_back( field );
743 if( !field.IsMandatory() )
744 field.SetOrdinal( ordinal++ );
771 src_pin->
SetAlt( model_pin.GetAlt() );
779 if( replaceOnCurrentScreen )
782 if( !commit.
Empty() )
783 commit.
Push(
_(
"Edit Symbol Properties" ) );
791 wxGridCellEditor*
editor =
m_fieldsGrid->GetCellEditor( event.GetRow(), event.GetCol() );
792 wxControl* control =
editor->GetControl();
794 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
797 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
798 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
801 else if( event.GetCol() ==
FDC_NAME )
803 wxString newName =
event.GetString();
805 for(
int i = 0; i <
m_fieldsGrid->GetNumberRows(); ++i )
807 if( i == event.GetRow() )
812 DisplayError(
this, wxString::Format(
_(
"Field name '%s' already in use." ),
815 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
816 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
828 if(
m_fields->at( aEvent.GetRow() ).GetId() == FIELD_T::REFERENCE
831 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
832 evt->SetClientData(
new VECTOR2I( aEvent.GetRow(), aEvent.GetCol() ) );
849 [&]() -> std::pair<int, int>
859 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
873 if( row < m_fields->GetMandatoryRowCount() )
875 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
887 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
904 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row - 1 ) );
920 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row + 1 ) );
957 int row = aEvent.GetRow();
972 int sortCol = aEvent.GetCol();
979 ascending = !
m_pinGrid->IsSortOrderAscending();
991 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_fieldsGrid );
1001 for(
int i = 2; i <
m_fieldsGrid->GetNumberCols(); i++ )
1004 m_fieldsGrid->SetColSize( 1, std::max( 120, fieldsWidth - fixedColsWidth ) );
1010 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_pinGrid );
1019 pinTblWidth -=
m_pinGrid->GetColSize( i );
1022 if( pinTblWidth > 2 )
1048 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1067 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1070 wxGridCellEditor* cellEditor =
m_fieldsGrid->GetCellEditor( loc->
x, loc->
y );
1072 if( wxTextEntry* txt =
dynamic_cast<wxTextEntry*
>( cellEditor->GetControl() ) )
1075 cellEditor->DecRef();
1080 wxSize new_size =
event.GetSize();
1101 wxSize new_size =
event.GetSize();
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
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
Class DIALOG_SYMBOL_PROPERTIES_BASE.
wxStaticText * m_libraryIDLabel
wxCheckBox * m_cbExcludeFromBom
wxChoice * m_orientationCtrl
STD_BITMAP_BUTTON * m_bpMoveDown
wxStaticText * m_unitLabel
wxCheckBox * m_cbExcludeFromSim
STD_BITMAP_BUTTON * m_bpAdd
STD_BITMAP_BUTTON * m_bpDelete
wxTextCtrl * m_tcLibraryID
wxCheckBox * m_cbAlternateSymbol
wxButton * m_spiceFieldsButton
wxCheckBox * m_cbExcludeFromBoard
wxCheckBox * m_ShowPinNameButt
wxCheckBox * m_ShowPinNumButt
STD_BITMAP_BUTTON * m_bpMoveUp
void OnSizePinsGrid(wxSizeEvent &event) override
void OnPinTableCellEdited(wxGridEvent &event) override
void OnGridEditorShown(wxGridEvent &event) override
void OnUpdateUI(wxUpdateUIEvent &event) override
wxSize m_lastRequestedPinsSize
void OnEditSymbol(wxCommandEvent &) override
void OnCancelButtonClick(wxCommandEvent &event) override
bool TransferDataFromWindow() override
virtual void onUpdateEditLibrarySymbol(wxUpdateUIEvent &event) override
SCH_PIN_TABLE_DATA_MODEL * m_dataModel
void OnMoveDown(wxCommandEvent &event) override
FIELDS_GRID_TABLE * m_fields
void OnSizeFieldsGrid(wxSizeEvent &event) override
SCH_EDIT_FRAME * GetParent()
std::bitset< 64 > m_shownColumns
void OnPinTableColSort(wxGridEvent &aEvent)
void OnMoveUp(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
void OnInitDlg(wxInitDialogEvent &event) override
void OnAddField(wxCommandEvent &event) override
void OnGridEditorHidden(wxGridEvent &event) override
bool TransferDataToWindow() override
void AdjustPinsGridColumns()
~DIALOG_SYMBOL_PROPERTIES() override
void OnUnitChoice(wxCommandEvent &event) override
void OnEditSpiceModel(wxCommandEvent &event) override
void OnPageChanging(wxNotebookEvent &event) override
DIALOG_SYMBOL_PROPERTIES(SCH_EDIT_FRAME *aParent, SCH_SYMBOL *aSymbol)
void HandleDelayedFocus(wxCommandEvent &event)
void HandleDelayedSelection(wxCommandEvent &event)
void OnCheckBox(wxCommandEvent &event) override
void OnGridCellChanging(wxGridEvent &event)
void OnEditLibrarySymbol(wxCommandEvent &) override
void OnUpdateSymbol(wxCommandEvent &) override
void AdjustFieldsGridColumns()
wxSize m_lastRequestedFieldsSize
void OnExchangeSymbol(wxCommandEvent &) override
virtual void onUpdateEditSymbol(wxUpdateUIEvent &event) override
EDA_ITEM_FLAGS GetEditFlags() const
void SetFlags(EDA_ITEM_FLAGS aMask)
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
EDA_ITEM_FLAGS GetFlags() const
const EDA_ANGLE & GetTextAngle() const
virtual const wxString & GetText() const
Return the string associated with the text object.
void Offset(const VECTOR2I &aOffset)
virtual void SetVisible(bool aVisible)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
SCH_FIELD * GetField(FIELD_T aFieldId)
int GetNumberRows() override
void push_back(const SCH_FIELD &field)
int GetMandatoryRowCount() const
void emplace_back(const SCH_FIELD &field)
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
APP_SETTINGS_BASE * KifaceSettings() const
A logical library item identifier and consists of various portions much like a URI.
bool IsPower() const override
bool HasAlternateBodyStyle() const override
Test if symbol has more than one body conversion type (DeMorgan).
static int Compare(const wxString &lhs, const wxString &rhs)
wxString ConvertKIIDsToRefs(const wxString &aSource) const
wxString ConvertRefsToKIIDs(const wxString &aSource) const
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCHEMATIC & Schematic() const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetText(const wxString &aText) override
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
virtual void SetUnit(int aUnit)
bool IsEmptyCell(int row, int col) override
wxGridCellAttr * m_typeAttr
wxString GetValue(int aRow, int aCol) override
std::vector< wxGridCellAttr * > m_nameAttrs
int GetNumberCols() override
static bool compare(const SCH_PIN &lhs, const SCH_PIN &rhs, int sortCol, bool ascending)
void SortRows(int aSortCol, bool ascending)
~SCH_PIN_TABLE_DATA_MODEL()
wxGridCellAttr * m_shapeAttr
SCH_PIN_TABLE_DATA_MODEL()
int GetNumberRows() override
bool CanSetValueAs(int aRow, int aCol, const wxString &aTypeName) override
static wxString GetValue(const SCH_PIN &aPin, int aCol)
wxGridCellAttr * m_readOnlyAttr
wxString GetColLabelValue(int aCol) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind) override
void SetAlt(const wxString &aAlt)
Set the name of the alternate pin.
const std::map< wxString, ALT > & GetAlternates() const
ALT GetAlt(const wxString &aAlt)
SCH_PIN * GetLibPin() const
const wxString & GetName() const
const wxString & GetNumber() const
GRAPHIC_PINSHAPE GetShape() const
ELECTRICAL_PINTYPE GetType() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
wxString GetUnitDisplayName(int aUnit, bool aLabel) const override
Return the display name for a given unit aUnit.
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
void SetShowPinNumbers(bool aShow) override
Set or clear the pin number visibility flag.
void SetValueFieldText(const wxString &aValue)
void SetBodyStyle(int aBodyStyle) override
void SetShowPinNames(bool aShow) override
Set or clear the pin name visibility flag.
void SyncOtherUnits(const SCH_SHEET_PATH &aSourceSheet, SCH_COMMIT &aCommit, PROPERTY_BASE *aProperty)
Keep fields other than the reference, include/exclude flags, and alternate pin assignments in sync in...
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
void SetFootprintFieldText(const wxString &aFootprint)
VECTOR2I GetPosition() const override
const LIB_ID & GetLibId() const override
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
int GetUnitCount() const override
Return the number of units per package of the symbol.
int GetOrientation() const override
Get the display symbol orientation.
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
void SetExcludedFromBoard(bool aExcludeFromBoard) override
Set or clear exclude from board netlist flag.
void SetDNP(bool aDNP) override
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation 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
bool GetDNP() const override
Set or clear the 'Do Not Populate' flag.
virtual bool GetShowPinNumbers() const
bool GetExcludedFromBOM() const override
bool GetExcludedFromSim() const override
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
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.
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.
wxDEFINE_EVENT(SYMBOL_DELAY_FOCUS, wxCommandEvent)
@ SYMBOL_PROPS_EDIT_SCHEMATIC_SYMBOL
@ SYMBOL_PROPS_WANT_EXCHANGE_SYMBOL
@ SYMBOL_PROPS_WANT_UPDATE_SYMBOL
@ SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL
std::uint32_t EDA_ITEM_FLAGS
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
KICOMMON_API void SelectReferenceNumber(wxTextEntry *aTextEntry)
Select the number (or "?") in a reference for ease of editing.
const std::vector< BITMAPS > & PinTypeIcons()
const wxArrayString & PinTypeNames()
const wxArrayString & PinShapeNames()
const std::vector< BITMAPS > & PinShapeIcons()
std::vector< SCH_FIELD > SCH_FIELDS
A container for several SCH_FIELD items.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
wxString UnescapeString(const wxString &aSource)
Hold a name of a symbol's field, field value, and default visibility.
Definition for symbol library class.
wxString GetUserFieldName(int aFieldNdx, bool aTranslateForHI)
VECTOR2< int32_t > VECTOR2I