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 defined( GetClassName ) && defined( __MINGW32__ )
85 if( aEvent.GetEventType() == wxEVT_SET_FOCUS )
87 wxLogTrace( wxS(
"FOCUS_DEBUG" ), wxS(
"%sFocus SET on: %s (name=%s, label=%s)" ),
89 window->GetClassInfo()->GetClassName(),
93 else if( aEvent.GetEventType() == wxEVT_KILL_FOCUS )
95 wxLogTrace( wxS(
"FOCUS_DEBUG" ), wxS(
"%sFocus LOST from: %s (name=%s, label=%s)" ),
97 window->GetClassInfo()->GetClassName(),
106 std::function<void( wxWindow* )> attachToTree = [&]( wxWindow* w ) ->
void
111 w->Bind( wxEVT_SET_FOCUS, onFocus );
112 w->Bind( wxEVT_KILL_FOCUS, onFocus );
115 for( wxWindow* child : w->GetChildren() )
116 attachToTree( child );
119 attachToTree( aWindow );
121 wxLogTrace( wxS(
"FOCUS_DEBUG" ), wxS(
"Focus debugging enabled for: %s" ), aWindowName );
173 wxGridCellAttr* attr =
nullptr;
177 attr =
new wxGridCellAttr;
178 attr->SetReadOnly(
true );
183 wxArrayString choices;
184 choices.push_back( lib_pin->
GetName() );
186 for(
const std::pair<const wxString, SCH_PIN::ALT>& alt : lib_pin->
GetAlternates() )
187 choices.push_back( alt.first );
189 attr =
new wxGridCellAttr();
221 case COL_TYPE:
return _(
"Electrical Type" );
223 default: wxFAIL;
return wxEmptyString;
232 bool CanSetValueAs(
int aRow,
int aCol,
const wxString& aTypeName )
override
240 return GetValue( at( aRow ), aCol );
248 return wxEmptyString;
249 else if( aPin.
GetAlt().IsEmpty() )
261 default: wxFAIL;
return wxEmptyString;
265 wxGridCellAttr*
GetAttr(
int aRow,
int aCol, wxGridCellAttr::wxAttrKind aKind )
override
292 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
299 if(
pin.GetLibPin() && aValue ==
pin.GetLibPin()->GetName() )
300 pin.SetAlt( wxEmptyString );
302 pin.SetAlt( aValue );
320 wxString lhStr =
GetValue( lhs, sortCol );
321 wxString rhStr =
GetValue( rhs, sortCol );
335 auto cmp = [ ascending ](
const auto a,
const auto b )
352 res = cmp( lhStr.CmpNoCase( rhStr ), 0 );
364 std::sort( begin(),
end(),
365 [ aSortCol, ascending ](
const SCH_PIN& lhs,
const SCH_PIN& rhs ) ->
bool
367 return compare( lhs, rhs, aSortCol, ascending );
402 [&]( wxCommandEvent& aEvent )
406 m_fieldsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
422 m_pinTablePage->SetToolTip(
_(
"Alternate pin assignments are not available for symbols with multiple "
430 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_symbol->GetRawPins() )
443 m_pinGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
450 wxToolTip::Enable(
true );
468 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
472 evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
484 GetSizer()->Fit(
this );
517 if( !wxDialog::TransferDataToWindow() )
523 std::optional<SCH_SYMBOL_VARIANT> variant =
m_symbol->GetVariant( sheetPath, variantName );
524 std::set<wxString> defined;
536 defined.insert( field.
GetName() );
544 if( defined.count( templateFieldname.m_Name ) <= 0 )
547 field.
SetVisible( templateFieldname.m_Visible );
553 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_fields->GetNumberRows() );
563 for(
int ii = 1; ii <=
m_symbol->GetUnitCount(); ii++ )
577 if(
m_part->HasDeMorganBodyStyles() )
584 wxASSERT( (
int)
m_part->GetBodyStyleNames().size() ==
m_part->GetBodyStyleCount() );
586 for(
int ii = 0; ii <
m_part->GetBodyStyleCount(); ii++ )
611 switch( orientation )
652 GetSizer()->SetSizeHints(
this );
655 wxSize curSize = GetSize();
658 SetSize( wxSize( curSize.x,
minSize.y ) );
671 std::vector<SCH_FIELD> fields;
674 fields.emplace_back( field );
682 for(
const SCH_FIELD& editedField : fields )
688 if( existingField.GetName() == editedField.GetName() )
691 existingField.SetText( editedField.GetText() );
698 m_fields->emplace_back( editedField );
699 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
705 for(
int ii = (
int)
m_fields->size() - 1; ii >= 0; --ii )
712 if( editedField.GetName() == existingField.
GetName() )
724 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, ii, 1 );
750 for(
size_t i = 0; i <
m_fields->size(); ++i )
757 wxString fieldName = field.
GetName(
false );
759 if( fieldName.IsEmpty() )
763 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
777 if( !wxDialog::TransferDataFromWindow() )
793 bool replaceOnCurrentScreen;
795 wxCHECK( currentScreen,
false );
811 m_symbol->SetUnit( unit_selection );
814 m_symbol->SetBodyStyle( bodyStyle_selection );
840 field.Offset(
m_symbol->GetPosition() );
846 const wxString& fieldName = field.GetCanonicalName();
848 if( fieldName.IsEmpty() && field.GetText().IsEmpty() )
850 else if( fieldName.IsEmpty() )
851 field.SetName(
_(
"untitled" ) );
863 wxString defaultText =
m_symbol->Schematic()->ConvertRefsToKIIDs( existingField->
GetText() );
864 tmp =
const_cast<SCH_FIELD*
>( existingField );
868 if( !currentVariant.IsEmpty() )
871 tmp->
SetText( defaultText, ¤tSheet );
873 wxString variantText =
m_symbol->Schematic()->ConvertRefsToKIIDs( field.GetText() );
874 tmp->
SetText( variantText, ¤tSheet, currentVariant );
878 if( !field.IsMandatory() )
882 if( currentVariant.IsEmpty() )
894 m_symbol->SetDNP(
m_cbDNP->IsChecked(), ¤tSheet, currentVariant );
905 src_pin->
SetAlt( model_pin.GetAlt() );
911 m_symbol->SyncOtherUnits( currentSheet, commit,
nullptr, currentVariant );
913 if( replaceOnCurrentScreen )
916 if( !commit.
Empty() )
917 commit.
Push(
_(
"Edit Symbol Properties" ) );
925 wxGridCellEditor*
editor =
m_fieldsGrid->GetCellEditor( event.GetRow(), event.GetCol() );
926 wxControl* control =
editor->GetControl();
928 if( control && control->GetValidator() && !control->GetValidator()->Validate( control ) )
931 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
932 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
935 else if( event.GetCol() ==
FDC_NAME )
937 wxString newName =
event.GetString();
939 for(
int i = 0; i <
m_fieldsGrid->GetNumberRows(); ++i )
941 if( i == event.GetRow() )
946 DisplayError(
this, wxString::Format(
_(
"Field name '%s' already in use." ),
949 wxCommandEvent *evt =
new wxCommandEvent( SYMBOL_DELAY_FOCUS );
950 evt->SetClientData(
new VECTOR2I( event.GetRow(), event.GetCol() ) );
965 wxCommandEvent* evt =
new wxCommandEvent( SYMBOL_DELAY_SELECTION );
966 evt->SetClientData(
new VECTOR2I( aEvent.GetRow(), aEvent.GetCol() ) );
983 [&]() -> std::pair<int, int>
993 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
1007 if( row < m_fields->GetMandatoryRowCount() )
1009 DisplayError(
this, wxString::Format(
_(
"The first %d fields are mandatory." ),
1010 m_fields->GetMandatoryRowCount() ) );
1021 wxGridTableMessage msg(
m_fields, wxGRIDTABLE_NOTIFY_ROWS_DELETED, row, 1 );
1034 return row >
m_fields->GetMandatoryRowCount();
1038 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row - 1 ) );
1050 return row >=
m_fields->GetMandatoryRowCount();
1054 std::swap( *(
m_fields->begin() + row ), *(
m_fields->begin() + row + 1 ) );
1091 int row = aEvent.GetRow();
1106 int sortCol = aEvent.GetCol();
1113 ascending = !
m_pinGrid->IsSortOrderAscending();
1125 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_pinGrid );
1134 pinTblWidth -=
m_pinGrid->GetColSize( i );
1137 if( pinTblWidth > 2 )
1147 std::bitset<64> shownColumns =
m_fieldsGrid->GetShownColumns();
1163 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1189 wxCHECK_RET( loc, wxT(
"Missing focus cell location" ) );
1192 wxGridCellEditor* cellEditor =
m_fieldsGrid->GetCellEditor( loc->
x, loc->
y );
1194 if( wxTextEntry* txt =
dynamic_cast<wxTextEntry*
>( cellEditor->GetControl() ) )
1197 cellEditor->DecRef();
1204 wxSize new_size =
event.GetSize();
1240 int old_unit =
m_symbol->GetUnit();
1241 m_symbol->SetUnit( unit_selection );
1246 for(
const std::unique_ptr<SCH_PIN>&
pin :
m_symbol->GetRawPins() )
1280 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 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
const int minSize
Push and Shove router track width and via size dialog.
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