29#include <wx/tooltip.h>
30#include <wx/uiaction.h>
65 auto onFocus = [aWindowName]( wxFocusEvent& aEvent ) ->
void
67 wxWindow* window =
static_cast<wxWindow*
>( aEvent.GetEventObject() );
71 wxString controlName = window->GetName();
72 wxString controlLabel;
75 wxControl* ctrl =
dynamic_cast<wxControl*
>( window );
76 if( ctrl && !ctrl->GetLabel().empty() )
77 controlLabel = ctrl->GetLabel();
79 wxString windowInfo = aWindowName.empty() ? wxString(
"" ) : aWindowName + wxString(
": " );
81 if( aEvent.GetEventType() == wxEVT_SET_FOCUS )
83 wxLogTrace( wxS(
"FOCUS_DEBUG" ), wxS(
"%sFocus SET on: %s (name=%s, label=%s)" ),
85 window->GetClassInfo()->GetClassName(),
89 else if( aEvent.GetEventType() == wxEVT_KILL_FOCUS )
91 wxLogTrace( wxS(
"FOCUS_DEBUG" ), wxS(
"%sFocus LOST from: %s (name=%s, label=%s)" ),
93 window->GetClassInfo()->GetClassName(),
102 std::function<void( wxWindow* )> attachToTree = [&]( wxWindow* w ) ->
void
107 w->Bind( wxEVT_SET_FOCUS, onFocus );
108 w->Bind( wxEVT_KILL_FOCUS, onFocus );
111 for( wxWindow* child : w->GetChildren() )
112 attachToTree( child );
115 attachToTree( aWindow );
117 wxLogTrace( wxS(
"FOCUS_DEBUG" ), wxS(
"Focus debugging enabled for: %s" ), aWindowName );
169 wxGridCellAttr* attr =
nullptr;
173 attr =
new wxGridCellAttr;
174 attr->SetReadOnly(
true );
179 wxArrayString choices;
180 choices.push_back( lib_pin->
GetName() );
182 for(
const std::pair<const wxString, SCH_PIN::ALT>& alt : lib_pin->
GetAlternates() )
183 choices.push_back( alt.first );
185 attr =
new wxGridCellAttr();
217 case COL_TYPE:
return _(
"Electrical Type" );
219 default: wxFAIL;
return wxEmptyString;
228 bool CanSetValueAs(
int aRow,
int aCol,
const wxString& aTypeName )
override
236 return GetValue( at( aRow ), aCol );
244 return wxEmptyString;
245 else if( aPin.
GetAlt().IsEmpty() )
257 default: wxFAIL;
return wxEmptyString;
261 wxGridCellAttr*
GetAttr(
int aRow,
int aCol, wxGridCellAttr::wxAttrKind aKind )
override
288 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
295 if(
pin.GetLibPin() && aValue ==
pin.GetLibPin()->GetName() )
296 pin.SetAlt( wxEmptyString );
298 pin.SetAlt( aValue );
316 wxString lhStr =
GetValue( lhs, sortCol );
317 wxString rhStr =
GetValue( rhs, sortCol );
331 auto cmp = [ ascending ](
const auto a,
const auto b )
348 res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
360 std::sort( begin(),
end(),
361 [ aSortCol, ascending ](
const SCH_PIN& lhs,
const SCH_PIN& rhs ) ->
bool
363 return compare( lhs, rhs, aSortCol, ascending );
398 [&]( wxCommandEvent& aEvent )
402 m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
418 m_pinTablePage->SetToolTip(
_(
"Alternate pin assignments are not available for symbols with multiple "
426 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_symbol->GetRawPins() )
439 m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
446 wxToolTip::Enable(
true );
466 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
470 evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
481 GetSizer()->Fit(
this );
514 if( !wxDialog::TransferDataToWindow() )
520 std::optional<SCH_SYMBOL_VARIANT> variant =
m_symbol->GetVariant( sheetPath, variantName );
521 std::set<wxString> defined;
533 defined.insert( field.
GetName() );
541 if( defined.count( templateFieldname.m_Name ) <= 0 )
544 field.
SetVisible( templateFieldname.m_Visible );
550 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
560 for(
int ii = 1; ii <=
m_symbol->GetUnitCount(); ii++ )
574 if(
m_part->HasDeMorganBodyStyles() )
581 wxASSERT( (
int)
m_part->GetBodyStyleNames().size() ==
m_part->GetBodyStyleCount() );
583 for(
int ii = 0; ii <
m_part->GetBodyStyleCount(); ii++ )
608 switch( orientation )
662 std::vector<SCH_FIELD> fields;
665 fields.emplace_back( field );
673 for(
const SCH_FIELD& editedField : fields )
679 if( existingField.GetName() == editedField.GetName() )
682 existingField.SetText( editedField.GetText() );
689 m_fields->emplace_back( editedField );
690 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
696 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
703 if( editedField.GetName() == existingField.
GetName() )
715 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
741 for(
size_t i = 0; i <
m_fields->size(); ++i )
748 wxString fieldName = field.
GetName(
false );
750 if( fieldName.IsEmpty() )
754 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
768 if( !wxDialog::TransferDataFromWindow() )
784 bool replaceOnCurrentScreen;
786 wxCHECK( currentScreen,
false );
802 m_symbol->SetUnit( unit_selection );
805 m_symbol->SetBodyStyle( bodyStyle_selection );
831 field.Offset(
m_symbol->GetPosition() );
837 const wxString& fieldName = field.GetCanonicalName();
839 if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
841 else if( fieldName.IsEmpty() )
842 field.SetName(
_(
"untitled" ) );
854 wxString defaultText =
m_symbol->Schematic()->ConvertRefsToKIIDs( existingField->
GetText() );
855 tmp =
const_cast<SCH_FIELD*
>( existingField );
859 if( !currentVariant.IsEmpty() )
862 tmp->
SetText( defaultText, ¤tSheet );
864 wxString variantText =
m_symbol->Schematic()->ConvertRefsToKIIDs( field.GetText() );
865 tmp->
SetText( variantText, ¤tSheet, currentVariant );
869 if( !field.IsMandatory() )
877 m_symbol->SetDNP(
m_cbDNP->IsChecked(), ¤tSheet, currentVariant );
888 src_pin->
SetAlt( model_pin.GetAlt() );
894 m_symbol->SyncOtherUnits( currentSheet, commit,
nullptr );
896 if( replaceOnCurrentScreen )
899 if( !commit.
Empty() )
900 commit.
Push(
_(
"Edit Symbol Properties" ) );
908 wxGridCellEditor*
editor =
m_fieldsGrid->GetCellEditor( event.GetRow(), event.GetCol() );
909 wxControl* control =
editor->GetControl();
911 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
914 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
915 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
918 else if( event.GetCol() ==
FDC_NAME )
920 wxString newName =
event.GetString();
922 for(
int i = 0; i <
m_fieldsGrid->GetNumberRows(); ++i )
924 if( i == event.GetRow() )
929 DisplayError(
this, wxString::Format(
_(
"Field name '%s' already in use." ),
932 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
933 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
948 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
949 evt->SetClientData(
new VECTOR2I( aEvent.GetRow(), aEvent.GetCol() ) );
966 [&]() -> std::pair<int, int>
976 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
990 if( row < m_fields->GetMandatoryRowCount() )
992 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
993 m_fields->GetMandatoryRowCount() ) );
1004 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
1017 return row >
m_fields->GetMandatoryRowCount();
1021 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row - 1 ) );
1033 return row >=
m_fields->GetMandatoryRowCount();
1037 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row + 1 ) );
1074 int row = aEvent.GetRow();
1089 int sortCol = aEvent.GetCol();
1096 ascending = !
m_pinGrid->IsSortOrderAscending();
1108 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_pinGrid );
1117 pinTblWidth -=
m_pinGrid->GetColSize( i );
1120 if( pinTblWidth > 2 )
1130 std::bitset<64> shownColumns =
m_fieldsGrid->GetShownColumns();
1146 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1165 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1168 wxGridCellEditor* cellEditor =
m_fieldsGrid->GetCellEditor( loc->
x, loc->
y );
1170 if( wxTextEntry* txt =
dynamic_cast<wxTextEntry*
>( cellEditor->GetControl() ) )
1173 cellEditor->DecRef();
1180 wxSize new_size =
event.GetSize();
1225 int old_unit =
m_symbol->GetUnit();
1226 m_symbol->SetUnit( unit_selection );
1231 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_symbol->GetRawPins() )
1265 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 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
wxStaticText * m_libraryIDLabel
wxCheckBox * m_cbExcludeFromBom
wxChoice * m_orientationCtrl
STD_BITMAP_BUTTON * m_bpMoveDown
wxChoice * m_bodyStyleChoice
wxStaticText * m_unitLabel
wxCheckBox * m_cbExcludeFromSim
wxStaticText * m_bodyStyle
STD_BITMAP_BUTTON * m_bpAdd
wxCheckBox * m_cbExcludeFromPosFiles
STD_BITMAP_BUTTON * m_bpDelete
wxTextCtrl * m_tcLibraryID
wxButton * m_spiceFieldsButton
wxCheckBox * m_cbExcludeFromBoard
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
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
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
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 OnExchangeSymbol(wxCommandEvent &) override
virtual void onUpdateEditSymbol(wxUpdateUIEvent &event) override
virtual void SetParent(EDA_ITEM *aParent)
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.
static int Compare(const wxString &lhs, const wxString &rhs)
TEMPLATES m_TemplateFieldNames
Holds all the data relating to one schematic.
SCHEMATIC_SETTINGS & Settings() const
wxString ConvertKIIDsToRefs(const wxString &aSource) const
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.
SCHEMATIC & Schematic() const
void SetOrdinal(int aOrdinal)
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
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 & 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...
const std::vector< TEMPLATE_FIELDNAME > & GetTemplateFieldNames()
Return a 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.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
static void EnableFocusDebugging(wxWindow *aWindow, const wxString &aWindowName=wxEmptyString)
Debug helper to trap all SetFocus events on a window and its children.
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()
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.
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".
VECTOR2< int32_t > VECTOR2I