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();
154 case COL_TYPE:
return _(
"Electrical Type" );
156 default: wxFAIL;
return wxEmptyString;
165 bool CanSetValueAs(
int aRow,
int aCol,
const wxString& aTypeName )
override
173 return GetValue( at( aRow ), aCol );
181 return wxEmptyString;
182 else if( aPin.
GetAlt().IsEmpty() )
194 default: wxFAIL;
return wxEmptyString;
198 wxGridCellAttr*
GetAttr(
int aRow,
int aCol, wxGridCellAttr::wxAttrKind aKind )
override
201 auto enhanceAttr = [
this, &aRow, &aCol,
202 &aKind]( wxGridCellAttr* aInputAttr ) -> wxGridCellAttr*
204 if( aInputAttr ==
nullptr )
207 wxGridCellAttr* attr = aInputAttr;
209 if( wxGridCellAttrProvider* provider = GetAttrProvider() )
211 wxGridCellAttr* providerAttr = provider->GetAttr( aRow, aCol, aKind );
215 attr =
new wxGridCellAttr;
216 attr->SetKind( wxGridCellAttr::Merged );
218 attr->MergeWith( aInputAttr );
219 aInputAttr->DecRef();
221 attr->MergeWith( providerAttr );
222 providerAttr->DecRef();
254 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
259 if( aValue == at( aRow ).GetLibPin()->GetName() )
260 at( aRow ).SetAlt( wxEmptyString );
262 at( aRow ).SetAlt( aValue );
280 wxString lhStr =
GetValue( lhs, sortCol );
281 wxString rhStr =
GetValue( rhs, sortCol );
295 auto cmp = [ ascending ](
const auto a,
const auto b )
312 res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
324 std::sort( begin(), end(),
325 [ aSortCol, ascending ](
const SCH_PIN& lhs,
const SCH_PIN& rhs ) ->
bool
327 return compare( lhs, rhs, aSortCol, ascending );
344 m_fieldsSize( 0, 0 ),
345 m_lastRequestedFieldsSize( 0, 0 ),
346 m_lastRequestedPinsSize( 0, 0 ),
347 m_editorShown( false ),
349 m_dataModel( nullptr )
367 [&]( wxCommandEvent& aEvent )
371 m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
386 m_pinTablePage->SetToolTip(
_(
"Alternate pin assignments are not available for De Morgan "
407 m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
411 wxToolTip::Enable(
true );
427 QueueEvent(
new wxCommandEvent( SYMBOL_DELAY_SELECTION ) );
428 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
441 cfg->m_Appearance.edit_symbol_width = GetSize().x;
442 cfg->m_Appearance.edit_symbol_height = GetSize().y;
471 if( !wxDialog::TransferDataToWindow() )
474 std::set<wxString> defined;
486 defined.insert( field.
GetName() );
492 GetParent()->Schematic().Settings().m_TemplateFieldNames.GetTemplateFieldNames() )
494 if( defined.count( templateFieldname.m_Name ) <= 0 )
497 field.
SetVisible( templateFieldname.m_Visible );
503 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->size() );
544 switch( orientation )
589 std::vector<SCH_FIELD> fields;
592 fields.emplace_back( field );
596 if( dialog.ShowModal() != wxID_OK )
600 for(
const SCH_FIELD& editedField : fields )
606 if( existingField.GetName() == editedField.GetName() )
609 existingField.SetText( editedField.GetText() );
616 m_fields->emplace_back( editedField );
617 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
623 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
630 if( editedField.GetName() == existingField.
GetName() )
640 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
670 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
681 wxString fieldName = field.
GetName(
false );
683 if( fieldName.IsEmpty() )
687 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
701 if( !wxDialog::TransferDataFromWindow() )
712 bool replaceOnCurrentScreen;
713 wxCHECK( currentScreen,
false );
763 for(
unsigned i = 0; i <
m_fields->size(); ++i )
775 for(
size_t ii = 0; ii <
m_fields->size(); ++ii )
780 if( fieldName.IsEmpty() && field.
GetText().IsEmpty() )
782 else if( fieldName.IsEmpty() )
785 fields.push_back( field );
812 src_pin->
SetAlt( model_pin.GetAlt() );
827 std::vector<SCH_SYMBOL*> otherUnits;
833 commit.
Modify( otherUnit, screen );
851 newField.
Offset( otherUnit->GetPosition() );
854 otherUnit->AddField( newField );
858 for(
size_t ii = otherUnit->GetFields().size() - 1; ii >
DATASHEET_FIELD; ii-- )
860 SCH_FIELD& otherField = otherUnit->GetFields().at( ii );
863 otherUnit->GetFields().erase( otherUnit->GetFields().begin() + ii );
869 otherUnit->SetDNP(
m_cbDNP->IsChecked() );
875 SCH_PIN* src_pin = otherUnit->GetPin( model_pin.GetNumber() );
878 src_pin->
SetAlt( model_pin.GetAlt() );
885 if( replaceOnCurrentScreen )
888 if( !commit.
Empty() )
889 commit.
Push(
_(
"Edit Symbol Properties" ) );
897 wxGridCellEditor*
editor =
m_fieldsGrid->GetCellEditor( event.GetRow(), event.GetCol() );
898 wxControl* control =
editor->GetControl();
900 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
903 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
904 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
907 else if( event.GetCol() ==
FDC_NAME )
909 wxString newName =
event.GetString();
911 for(
int i = 0; i <
m_fieldsGrid->GetNumberRows(); ++i )
913 if( i == event.GetRow() )
918 DisplayError(
this, wxString::Format(
_(
"Field name '%s' already in use." ),
921 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
922 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
935 QueueEvent(
new wxCommandEvent( SYMBOL_DELAY_SELECTION ) );
953 int fieldID = (int)
m_fields->size();
964 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
979 wxArrayInt selectedRows =
m_fieldsGrid->GetSelectedRows();
981 if( selectedRows.empty() &&
m_fieldsGrid->GetGridCursorRow() >= 0 )
982 selectedRows.push_back(
m_fieldsGrid->GetGridCursorRow() );
984 if( selectedRows.empty() )
987 for(
int row : selectedRows )
991 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
1001 selectedRows.Sort( [](
int* first,
int* second ) {
return *second - *first; } );
1003 for(
int row : selectedRows )
1008 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
1106 int row = aEvent.GetRow();
1124 int sortCol = aEvent.GetCol();
1131 ascending = !
m_pinGrid->IsSortOrderAscending();
1143 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_fieldsGrid );
1153 for(
int i = 2; i <
m_fieldsGrid->GetNumberCols(); i++ )
1156 m_fieldsGrid->SetColSize( 1, std::max( 120, fieldsWidth - fixedColsWidth ) );
1162 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_pinGrid );
1171 pinTblWidth -=
m_pinGrid->GetColSize( i );
1197 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1217 if( wxTextEntry* txt =
dynamic_cast<wxTextEntry*
>( cellEditor->GetControl() ) )
1220 cellEditor->DecRef();
1225 wxSize new_size =
event.GetSize();
1246 wxSize new_size =
event.GetSize();
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
bool Empty() const
Returns status of an item.
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.
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
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)
virtual void SetParent(EDA_ITEM *aParent)
EDA_ITEM_FLAGS GetFlags() const
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
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)
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)
These settings were stored in SCH_BASE_FRAME previously.
SCHEMATIC_SETTINGS & Settings() const
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
Revert the commit by restoring the modified items state.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
virtual void SetExcludedFromSim(bool aExclude)
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)
ALT GetAlt(const wxString &aAlt)
SCH_PIN * GetLibPin() const
const wxString & GetName() const
std::map< wxString, ALT > & GetAlternates()
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.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
int GetFieldCount() const
Return the number of fields in this symbol.
wxString SubReference(int aUnit, bool aAddSeparator=true) const
static bool IsReferenceStringValid(const wxString &aReferenceString)
Test for an acceptable reference string.
bool IsAnnotated(const SCH_SHEET_PATH *aSheet) const
Check if the symbol has a valid annotation (reference) for the given sheet path.
void SetValueFieldText(const wxString &aValue)
void SetBodyStyle(int aBodyStyle) override
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true, bool aCaseInsensitive=false)
Search for a SCH_FIELD with aFieldName.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
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
bool HasUnitDisplayName(int aUnit)
Return true if the given unit aUnit has a display name set.
int GetOrientation() const
Get the display symbol orientation.
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
wxString GetUnitDisplayName(int aUnit)
Return the display name for a given unit aUnit.
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.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
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()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
bool GetExcludedFromBoard() const
bool GetExcludedFromBOM() const
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
bool GetDNP() const
Set or clear the 'Do Not Populate' flaga.
virtual bool GetShowPinNames() const
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist flag.
virtual bool GetShowPinNumbers() const
bool GetExcludedFromSim() const override
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.
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.
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
void CollectOtherUnits(const wxString &aRef, int aUnit, const LIB_ID &aLibId, SCH_SHEET_PATH &aSheet, std::vector< SCH_SYMBOL * > *otherUnits)
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.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
Definition for symbol library class.
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".