26#include <wx/tooltip.h>
27#include <wx/uiaction.h>
107 wxGridCellAttr* attr =
nullptr;
111 attr =
new wxGridCellAttr;
112 attr->SetReadOnly(
true );
117 wxArrayString choices;
118 choices.push_back( lib_pin->
GetName() );
120 for(
const std::pair<const wxString, SCH_PIN::ALT>& alt : lib_pin->
GetAlternates() )
121 choices.push_back( alt.first );
123 attr =
new wxGridCellAttr();
155 case COL_TYPE:
return _(
"Electrical Type" );
157 default: wxFAIL;
return wxEmptyString;
166 bool CanSetValueAs(
int aRow,
int aCol,
const wxString& aTypeName )
override
174 return GetValue( at( aRow ), aCol );
182 return wxEmptyString;
183 else if( aPin.
GetAlt().IsEmpty() )
195 default: wxFAIL;
return wxEmptyString;
199 wxGridCellAttr*
GetAttr(
int aRow,
int aCol, wxGridCellAttr::wxAttrKind aKind )
override
226 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
233 if(
pin.GetLibPin() && aValue ==
pin.GetLibPin()->GetName() )
234 pin.SetAlt( wxEmptyString );
236 pin.SetAlt( aValue );
254 wxString lhStr =
GetValue( lhs, sortCol );
255 wxString rhStr =
GetValue( rhs, sortCol );
269 auto cmp = [ ascending ](
const auto a,
const auto b )
286 res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
298 std::sort( begin(),
end(),
299 [ aSortCol, ascending ](
const SCH_PIN& lhs,
const SCH_PIN& rhs ) ->
bool
301 return compare( lhs, rhs, aSortCol, ascending );
337 [&]( wxCommandEvent& aEvent )
341 m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
343 int minWidth = wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
345 for(
int ii = 0; ii <= 7; ++ii )
373 wxSizer* altPinDefsSizer =
m_pinGrid->GetContainingSizer();
380 altPinDefsSizer->AddStretchSpacer( 1 );
381 altPinDefsSizer->Add( hint, 0, wxALIGN_CENTER_HORIZONTAL );
382 altPinDefsSizer->AddStretchSpacer( 2 );
384 altPinDefsSizer->Layout();
391 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_symbol->GetRawPins() )
404 m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
411 wxToolTip::Enable(
true );
426 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
430 evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
437 if( !variantName.IsEmpty() )
439 SetTitle( GetTitle() + wxS(
" - " ) + variantName +
_(
" Design Variant" ) );
444 std::optional<SCH_SYMBOL_VARIANT> existingVariant =
445 aSymbol->
GetVariant( currentSheet, variantName );
447 bool hasVariantSymbol = existingVariant.has_value() && existingVariant->m_SymbolOverride.has_value();
460 GetSizer()->Fit(
this );
499 if( !wxDialog::TransferDataToWindow() )
505 std::optional<SCH_SYMBOL_VARIANT> variant =
m_symbol->GetVariant( sheetPath, variantName );
506 std::set<wxString> defined;
508 std::vector<SCH_FIELD*> orderedFields;
509 m_symbol->GetFields( orderedFields,
false );
512 for(
SCH_FIELD* srcField : orderedFields )
521 defined.insert( field.
GetName() );
529 if( defined.count( templateFieldname.m_Name ) <= 0 )
532 field.
SetVisible( templateFieldname.m_Visible );
538 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
548 for(
int ii = 1; ii <=
m_symbol->GetUnitCount(); ii++ )
562 if(
m_part->HasDeMorganBodyStyles() )
569 wxASSERT( (
int)
m_part->GetBodyStyleNames().size() ==
m_part->GetBodyStyleCount() );
571 for(
int ii = 0; ii <
m_part->GetBodyStyleCount(); ii++ )
596 switch( orientation )
620 switch(
m_symbol->GetPassthroughMode() )
652 for(
size_t page = 0; page <
m_notebook1->GetPageCount(); ++page )
656 targetPage = (int) page;
675 std::vector<SCH_FIELD> fields;
678 fields.emplace_back( field );
686 for(
const SCH_FIELD& editedField : fields )
692 if( existingField.GetName() == editedField.GetName() )
695 existingField.SetText( editedField.GetText() );
702 m_fields->emplace_back( editedField );
703 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
709 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
716 if( editedField.GetName() == existingField.
GetName() )
728 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
754 for(
size_t i = 0; i <
m_fields->size(); ++i )
761 wxString fieldName = field.
GetName(
false );
763 if( fieldName.IsEmpty() )
767 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
781 if( !wxDialog::TransferDataFromWindow() )
800 bool replaceOnCurrentScreen;
802 wxCHECK( currentScreen,
false );
825 m_symbol->SetUnit( unit_selection );
828 m_symbol->SetBodyStyle( bodyStyle_selection );
854 field.Offset(
m_symbol->GetPosition() );
860 const wxString& fieldName = field.GetUntranslatedName();
862 if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
864 else if( fieldName.IsEmpty() )
865 field.SetName(
_(
"untitled" ) );
867 if( !field.IsMandatory() )
880 wxString defaultText =
m_symbol->Schematic()->ConvertRefsToKIIDs( existingField->
GetText() );
881 tmp =
const_cast<SCH_FIELD*
>( existingField );
885 if( !currentVariant.IsEmpty() )
888 tmp->
SetText( defaultText, ¤tSheet );
890 wxString variantText =
m_symbol->Schematic()->ConvertRefsToKIIDs( field.GetText() );
891 tmp->
SetText( variantText, ¤tSheet, currentVariant );
896 for(
int ii = (
int)
m_symbol->GetFields().size() - 1; ii >= 0; ii-- )
907 if( editedField.GetName() == symbolField.
GetName() )
918 std::stable_sort(
m_symbol->GetFields().begin(),
m_symbol->GetFields().end(),
921 return lhs.GetOrdinal() < rhs.GetOrdinal();
924 if( currentVariant.IsEmpty() )
936 m_symbol->SetDNP(
m_cbDNP->IsChecked(), ¤tSheet, currentVariant );
952 for(
SCH_PIN* src_pin :
m_symbol->GetPinsByNumber( model_pin.GetNumber() ) )
953 src_pin->SetAlt( model_pin.GetAlt() );
959 m_symbol->SyncOtherUnits( currentSheet, commit,
nullptr, currentVariant );
961 if( replaceOnCurrentScreen )
964 if( !commit.
Empty() )
965 commit.
Push(
_(
"Edit Symbol Properties" ) );
973 wxGridCellEditor*
editor =
m_fieldsGrid->GetCellEditor( event.GetRow(), event.GetCol() );
974 wxControl* control =
editor->GetControl();
976 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
979 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
980 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
983 else if( event.GetCol() ==
FDC_NAME )
985 wxString newName =
event.GetString();
987 for(
int i = 0; i <
m_fieldsGrid->GetNumberRows(); ++i )
989 if( i == event.GetRow() )
994 DisplayErrorMessage(
this, wxString::Format(
_(
"Field name '%s' already in use." ), newName ) );
996 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
997 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
1012 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
1013 evt->SetClientData(
new VECTOR2I( aEvent.GetRow(), aEvent.GetCol() ) );
1030 [&]() -> std::pair<int, int>
1040 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1054 if( row < m_fields->GetMandatoryRowCount() )
1057 m_fields->GetMandatoryRowCount() ) );
1068 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
1081 return row >
m_fields->GetMandatoryRowCount();
1085 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row - 1 ) );
1097 return row >=
m_fields->GetMandatoryRowCount();
1101 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row + 1 ) );
1134 if( !
GetParent()->Schematic().GetCurrentVariant().IsEmpty() )
1150 int row = aEvent.GetRow();
1165 int sortCol = aEvent.GetCol();
1172 ascending = !
m_pinGrid->IsSortOrderAscending();
1184 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_pinGrid );
1193 pinTblWidth -=
m_pinGrid->GetColSize( i );
1196 if( pinTblWidth > 2 )
1206 std::bitset<64> shownColumns =
m_fieldsGrid->GetShownColumns();
1222 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1248 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1251 wxGridCellEditor* cellEditor =
m_fieldsGrid->GetCellEditor( loc->
x, loc->
y );
1253 if( wxTextEntry* txt =
dynamic_cast<wxTextEntry*
>( cellEditor->GetControl() ) )
1256 cellEditor->DecRef();
1263 wxSize new_size =
event.GetSize();
1299 int old_unit =
m_symbol->GetUnit();
1300 m_symbol->SetUnit( unit_selection );
1305 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_symbol->GetRawPins() )
1339 if( !
m_pinGrid->CommitPendingChanges() )
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 EndDialogShim(int aReturnCode)
A mode agnostic way to close a dialog.
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
wxStaticText * m_libraryIDLabel
wxCheckBox * m_cbExcludeFromBom
wxChoice * m_orientationCtrl
STD_BITMAP_BUTTON * m_bpMoveDown
wxBoxSizer * bPinMapPageSizer
wxChoice * m_bodyStyleChoice
wxStaticText * m_unitLabel
wxCheckBox * m_cbExcludeFromSim
wxStaticText * m_bodyStyle
STD_BITMAP_BUTTON * m_bpAdd
wxButton * m_changeSymbolBtn
wxCheckBox * m_cbExcludeFromPosFiles
STD_BITMAP_BUTTON * m_bpDelete
wxTextCtrl * m_tcLibraryID
wxButton * m_spiceFieldsButton
wxCheckBox * m_cbExcludeFromBoard
wxButton * m_clearVariantSymbolBtn
DIALOG_SYMBOL_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Symbol Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxCAPTION|wxCLOSE_BOX|wxDEFAULT_DIALOG_STYLE|wxMAXIMIZE_BOX|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU)
wxCheckBox * m_ShowPinNameButt
wxChoice * m_choicePassthrough
wxCheckBox * m_ShowPinNumButt
STD_BITMAP_BUTTON * m_bpMoveUp
void OnSizePinsGrid(wxSizeEvent &event) override
void OnPinTableCellEdited(wxGridEvent &event) override
void OnGridEditorShown(wxGridEvent &event) override
void OnClearVariantSymbol(wxCommandEvent &) 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
PANEL_SYMBOL_PIN_MAP * m_pinMapPanel
SCH_PIN_TABLE_DATA_MODEL * m_dataModel
void OnMoveDown(wxCommandEvent &event) override
FIELDS_GRID_TABLE * m_fields
SCH_EDIT_FRAME * GetParent()
std::bitset< 64 > m_shownColumns
void OnPinTableColSort(wxGridEvent &aEvent)
void OnMoveUp(wxCommandEvent &event) override
void OnDeleteField(wxCommandEvent &event) override
void OnAddField(wxCommandEvent &event) override
void OnGridEditorHidden(wxGridEvent &event) override
bool TransferDataToWindow() override
void AdjustPinsGridColumns()
~DIALOG_SYMBOL_PROPERTIES() override
PANEL_EMBEDDED_FILES * m_embeddedFiles
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 SelectPinMapPage()
Select the Pin Map page so the dialog opens directly on the pin-to-pad mapping editor (issue #2282).
void OnExchangeSymbol(wxCommandEvent &) override
virtual void onUpdateEditSymbol(wxUpdateUIEvent &event) override
virtual void SetParent(EDA_ITEM *aParent)
virtual 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.
A logical library item identifier and consists of various portions much like a URI.
Composed widget that edits a symbol's named pin maps and the footprint each is bound to.
static int Compare(const wxString &lhs, const wxString &rhs)
TEMPLATES m_TemplateFieldNames
Project and global field name templates shared by project editors.
virtual PROJECT_FILE & GetProjectFile() const
Holds all the data relating to one schematic.
wxString ConvertKIIDsToRefs(const wxString &aSource) const
void SyncLibSymbolPinMaps(const wxString &aSchLibSymbolName, const LIB_SYMBOL &aSource, SCH_COMMIT *aCommit)
PROJECT & Project() const
Return a reference to the project this schematic is part of.
wxString GetCurrentVariant() const
Return the current variant being edited.
SCH_SHEET_PATH & CurrentSheet() 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.
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
virtual const wxString & GetText() const override
Return the string associated with the text object.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
void SetText(const wxString &aText) override
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
const std::map< wxString, ALT > & GetAlternates() const
ALT GetAlt(const wxString &aAlt)
SCH_PIN * GetLibPin() const
const wxString & GetName() const
const wxString & GetBaseName() const
Get the name without any alternates.
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::optional< SCH_SYMBOL_VARIANT > GetVariant(const SCH_SHEET_PATH &aInstance, const wxString &aVariantName) const
const std::vector< TEMPLATE_FIELDNAME > & GetResolvedTemplateFieldNames()
Return the resolved project and global template field name list for read only access.
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
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_WANT_SET_VARIANT_SYMBOL
@ SYMBOL_PROPS_EDIT_LIBRARY_SYMBOL
@ SYMBOL_PROPS_WANT_CLEAR_VARIANT_SYMBOL
std::uint32_t EDA_ITEM_FLAGS
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
KICOMMON_API wxFont GetControlFont(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()
#define NO_PIN_FUNCTIONS_WITH_MULTIPLE_BODY_STYLES
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
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.
bool FieldNamesAreDuplicates(const wxString &aLhs, const wxString &aRhs, std::initializer_list< FIELD_T > aMandatoryFields)
Test whether two field names should be treated as duplicates for the purposes of field name uniquenes...
wxString GetUserFieldName(int aFieldNdx, TRANSLATION aTranslation)
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
VECTOR2< int32_t > VECTOR2I