44 #include <wx/msgdlg.h> 45 #include <wx/textdlg.h> 50 #define DISPLAY_NAME_COLUMN 0 51 #define SHOW_FIELD_COLUMN 1 52 #define GROUP_BY_COLUMN 2 53 #define CANONICAL_NAME_COLUMN 3 55 #define QUANTITY_COLUMN ( GetNumberCols() - 1 ) 58 #define COLUMN_MARGIN 5 60 #define COLUMN_MARGIN 15 74 wxDataViewListCtrl* aFieldsCtrl ) :
86 _(
"Browse for footprint" ) );
87 menu.AppendSeparator();
92 _(
"Show datasheet in browser" ) );
93 menu.AppendSeparator();
104 wxString fpid =
m_grid->GetCellValue(
m_grid->GetGridCursorRow(),
116 wxString datasheet_uri =
m_grid->GetCellValue(
m_grid->GetGridCursorRow(),
159 m_Refs.push_back( aFirstReference );
217 if( aFieldName == wxT(
"Value" ) )
219 else if( aFieldName == wxT(
"Footprint" ) )
276 wxCHECK( aRow < (
int)
m_rows.size(), std::vector<SCH_REFERENCE>() );
277 return m_rows[ aRow ].m_Refs;
282 std::vector<SCH_REFERENCE> references;
285 for(
const auto& ref :
group.m_Refs )
289 references.push_back( ref );
293 const KIID& symbolID = ref.GetSymbol()->m_Uuid;
301 if( &ref == &
group.m_Refs.front() )
311 std::sort( references.begin(), references.end(),
315 wxString r_ref(
r.GetRef() <<
r.GetRefNumber() );
316 return StrNumCmp( l_ref, r_ref,
true ) < 0;
319 auto logicalEnd = std::unique( references.begin(), references.end(),
328 wxString r_ref(
r.GetRef() <<
r.GetRefNumber() );
329 return l_ref == r_ref;
332 references.erase( logicalEnd, references.end() );
343 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override 351 for(
const auto& ref : rowGroup.
m_Refs )
352 m_dataStore[ ref.GetSymbol()->m_Uuid ][ fieldName ] = aValue;
361 if( lhGroup.
m_Refs.size() == 0 )
363 else if( rhGroup.
m_Refs.size() == 0 )
369 [ ascending ](
const auto a,
const auto b )
384 wxString lhRef = lhGroup.
m_Refs[ 0 ].GetRef() + lhGroup.
m_Refs[ 0 ].GetRefNumber();
385 wxString rhRef = rhGroup.
m_Refs[ 0 ].GetRef() + rhGroup.
m_Refs[ 0 ].GetRefNumber();
386 return local_cmp(
StrNumCmp( lhRef, rhRef,
true ), 0 );
394 void Sort(
int aColumn,
bool ascending )
423 wxDataViewListCtrl* fieldsCtrl )
425 bool matchFound =
false;
443 for(
int i =
REFERENCE_FIELD + 1; i < fieldsCtrl->GetItemCount(); ++i )
459 void RebuildRows( wxCheckBox* aGroupSymbolsBox, wxDataViewListCtrl* aFieldsCtrl )
465 static_cast<WX_GRID*>( GetView() )->CommitPendingChanges(
true );
467 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
468 GetView()->ProcessTableMessage( msg );
476 bool matchFound =
false;
487 row.m_Refs.push_back( ref );
490 else if ( aGroupSymbolsBox->GetValue() &&
groupMatch( ref, rowRef, aFieldsCtrl ) )
493 row.m_Refs.push_back( ref );
505 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
506 GetView()->ProcessTableMessage( msg );
512 std::vector<DATA_MODEL_ROW> children;
516 bool matchFound =
false;
523 if(
unitMatch( ref, child.m_Refs[ 0 ] ) )
526 child.m_Refs.push_back( ref );
535 if( children.size() < 2 )
538 std::sort( children.begin(), children.end(),
545 m_rows.insert(
m_rows.begin() + aRow + 1, children.begin(), children.end() );
547 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_INSERTED, aRow, children.size() );
548 GetView()->ProcessTableMessage( msg );
553 auto firstChild =
m_rows.begin() + aRow + 1;
554 auto afterLastChild = firstChild;
557 while( afterLastChild !=
m_rows.end() && afterLastChild->m_Flag ==
CHILD_ITEM )
564 m_rows.erase( firstChild, afterLastChild );
566 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow + 1, deleted );
567 GetView()->ProcessTableMessage( msg );
582 for(
size_t i = 0; i <
m_rows.size(); ++i )
594 for(
size_t i = 0; i <
m_rows.size(); ++i )
612 for(
const std::pair<wxString, wxString> srcData : fieldStore )
614 const wxString& srcName = srcData.first;
615 const wxString& srcValue = srcData.second;
618 if( !destField && !srcValue.IsEmpty() )
635 if( !srcValue.IsEmpty() )
644 destField->
SetText( srcValue );
689 wxSize defaultDlgSize = ConvertDialogToPixels( wxSize( 600, 300 ) );
696 m_fieldsCtrl->AppendTextColumn(
_(
"Field" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
697 m_fieldsCtrl->AppendToggleColumn(
_(
"Show" ), wxDATAVIEW_CELL_ACTIVATABLE, 0,
699 m_fieldsCtrl->AppendToggleColumn(
_(
"Group By" ), wxDATAVIEW_CELL_ACTIVATABLE, 0,
704 m_fieldsCtrl->AppendTextColumn(
_(
"Name" ), wxDATAVIEW_CELL_INERT, 0, wxALIGN_LEFT, 0 );
726 int nameColWidth = 0;
728 for(
int row = 0; row <
m_fieldsCtrl->GetItemCount(); ++row )
749 m_grid->UseNativeColHeader(
false );
753 m_grid->SetSelectionMode( wxGrid::wxGridSelectCells );
768 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
771 wxGridCellAttr* attr =
new wxGridCellAttr;
776 attr =
new wxGridCellAttr;
781 attr =
new wxGridCellAttr;
786 attr =
new wxGridCellAttr;
790 m_grid->AutoSizeColumns(
false );
792 for(
int col = 0; col <
m_grid->GetNumberCols(); ++col )
796 if(
m_grid->IsColShown( col ) )
804 m_grid->SetColSize( col, width );
809 int maxWidth = defaultDlgSize.x / 3;
811 if( col ==
m_grid->GetNumberCols() - 1 )
812 m_grid->SetColSize( col, std::min( std::max( 50, textWidth ), maxWidth ) );
814 m_grid->SetColSize( col, std::min( std::max( 100, textWidth ), maxWidth ) );
820 m_grid->SetGridCursor( 0, 1 );
826 SetSize( defaultDlgSize );
830 m_grid->Connect( wxEVT_GRID_COL_SORT,
838 m_grid->Disconnect( wxEVT_GRID_COL_SORT,
843 m_grid->PopEventHandler(
true );
851 if( !wxDialog::TransferDataFromWindow() )
859 if( selection.GetSize() == 1 )
878 if( ref.GetSymbol() == symbol )
887 m_grid->GoToCell( row, 1 );
902 if( !wxDialog::TransferDataFromWindow() )
921 const wxString& aCanonicalName,
922 bool defaultShow,
bool defaultSortBy )
926 wxVector<wxVariant> fieldsCtrlRow;
929 bool show = defaultShow;
930 bool sort_by = defaultSortBy;
932 std::string key( aCanonicalName.ToUTF8() );
941 fieldsCtrlRow.push_back( wxVariant( aDisplayName ) );
942 fieldsCtrlRow.push_back( wxVariant( show ) );
943 fieldsCtrlRow.push_back( wxVariant( sort_by ) );
944 fieldsCtrlRow.push_back( wxVariant( aCanonicalName ) );
952 std::set<wxString> userFieldNames;
959 userFieldNames.insert( symbol->
GetFields()[j].GetName() );
963 auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>(
Kiface().KifaceSettings() );
966 cfg->m_FieldEditorPanel.fields_show[
"Reference"] =
true;
968 AddField(
_(
"Reference" ), wxT(
"Reference" ),
true,
true );
969 AddField(
_(
"Value" ), wxT(
"Value" ),
true,
true );
970 AddField(
_(
"Footprint" ), wxT(
"Footprint" ),
true,
true );
971 AddField(
_(
"Datasheet" ), wxT(
"Datasheet" ),
true,
false );
973 for(
const wxString& fieldName : userFieldNames )
974 AddField( fieldName, fieldName,
true,
false );
980 if( userFieldNames.count( templateFieldname.m_Name ) == 0 )
981 AddField( templateFieldname.m_Name, templateFieldname.m_Name,
false,
false );
989 auto attr =
new wxGridCellAttr;
991 m_grid->SetColFormatCustom(
m_dataModel->GetColsCount() - 1, wxGRID_VALUE_STRING );
993 wxTextEntryDialog dlg(
this,
_(
"New field name:" ),
_(
"Add Field" ) );
995 if( dlg.ShowModal() != wxID_OK )
998 wxString fieldName = dlg.GetValue();
1000 if( fieldName.IsEmpty() )
1016 std::string key( fieldName.ToUTF8() );
1018 auto cfg = static_cast<EESCHEMA_SETTINGS*>(
Kiface().KifaceSettings() );
1019 cfg->m_FieldEditorPanel.fields_show[key] =
true;
1021 AddField( fieldName, fieldName,
true,
false );
1023 wxGridTableMessage msg(
m_dataModel, wxGRIDTABLE_NOTIFY_COLS_INSERTED,
1025 m_grid->ProcessTableMessage( msg );
1028 attr =
new wxGridCellAttr;
1029 attr->SetReadOnly();
1039 wxDataViewItem item =
event.GetItem();
1042 int col =
event.GetColumn();
1052 DisplayError(
this,
_(
"The Reference column cannot be hidden." ) );
1097 int sortCol = aEvent.GetCol();
1102 if(
m_grid->IsSortingBy( sortCol ) )
1105 ascending = !
m_grid->IsSortOrderAscending();
1127 int col = aEvent.GetRowOrCol();
1130 if(
m_grid->GetColSize( col ) )
1149 m_grid->ClearSelection();
1150 m_grid->SetGridCursor( event.GetRow(),
event.GetCol() );
1156 if( refs.size() == 1 )
1160 wxString
path = refs[0].GetPath();
1161 wxString reference = refs[0].GetRef() + refs[0].GetRefNumber();
Field Reference of part, i.e. "IC21".
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
void doPopupSelection(wxCommandEvent &event) override
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
void OnTableValueChanged(wxGridEvent &event) override
std::vector< wxString > m_fieldNames
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
void AddColumn(const wxString &aFieldName)
wxDataViewListCtrl * m_fieldsCtrl
DATA_MODEL_ROW(const SCH_REFERENCE &aFirstReference, GROUP_TYPE aType)
std::vector< SCH_REFERENCE > m_Refs
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Implementation of conversion functions that require both schematic and board internal units.
This file is part of the common library.
virtual ~DIALOG_SYMBOL_FIELDS_TABLE()
wxString GetValue(const DATA_MODEL_ROW &group, int aCol)
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
This file is part of the common library.
FIELDS_EDITOR_GRID_TRICKS(DIALOG_SHIM *aParent, WX_GRID *aGrid, wxDataViewListCtrl *aFieldsCtrl)
SCHEMATIC_SETTINGS & Settings() const
void OnSizeFieldList(wxSizeEvent &event) override
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
std::map< KIID, std::map< wxString, wxString > > m_dataStore
TEMPLATES m_TemplateFieldNames
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
void OnClose(wxCloseEvent &event) override
int GetDataWidth(int aCol)
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Schematic editor (Eeschema) main window.
static wxString Shorthand(std::vector< SCH_REFERENCE > aList)
Return a shorthand string representing all the references in the list.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
Open a document (file) with the suitable browser.
SCH_SYMBOL * GetSymbol() const
wxString GetRefNumber() const
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 OnColumnItemToggled(wxDataViewEvent &event) override
wxCheckBox * m_groupSymbolsBox
void CollapseRow(int aRow)
bool IsEmptyCell(int aRow, int aCol) override
void SetFootprint(const SCH_SHEET_PATH *sheet, const wxString &aFootprint)
SCH_REFERENCE_LIST m_symbolsList
wxString GetColLabelValue(int aCol) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
std::vector< SCH_REFERENCE > GetRowReferences(int aRow) const
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
PANEL_FIELD_EDITOR m_FieldEditorPanel
void AddField(const wxString &displayName, const wxString &aCanonicalName, bool defaultShow, bool defaultSortBy)
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetInstanceReferences()
void OnAddField(wxCommandEvent &event) override
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
WX_GRID * m_grid
I don't own the grid, but he owns me.
Handle actions specific to the schematic editor.
FIELDS_EDITOR_GRID_DATA_MODEL(SCH_EDIT_FRAME *aFrame, SCH_REFERENCE_LIST &aSymbolsList)
void OnTableCellClick(wxGridEvent &event) override
#define CANONICAL_NAME_COLUMN
bool TransferDataToWindow() override
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
void OnRegroupSymbols(wxCommandEvent &aEvent) override
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
void SyncView()
Mark all items for refresh.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
wxBitmapButton * m_bRefresh
int GetFieldCount() const
Return the number of fields in this symbol.
SCHEMATIC & Schematic() const
Definition for symbol library class.
EDA_ITEM * GetParent() const
void showPopupMenu(wxMenu &menu) override
void ExpandCollapseRow(int aRow)
bool unitMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef)
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool groupMatch(const SCH_REFERENCE &lhRef, const SCH_REFERENCE &rhRef, wxDataViewListCtrl *fieldsCtrl)
wxDataViewListCtrl * m_fieldsCtrl
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
void Sort(int aColumn, bool ascending)
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
std::map< std::string, int > column_widths
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
SCH_REFERENCE_LIST m_symbolsList
int GetNumberRows() override
DIALOG_SYMBOL_FIELDS_TABLE(SCH_EDIT_FRAME *parent)
wxString GetFieldText(const wxString &aFieldName, SCH_EDIT_FRAME *aFrame) const
Search for a field named aFieldName and returns text associated with this field.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
bool TransferDataFromWindow() override
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
void OnGroupSymbolsToggled(wxCommandEvent &event) override
void OnSaveAndContinue(wxCommandEvent &aEvent) override
void OnTableItemContextMenu(wxGridEvent &event) override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
void RebuildRows(wxCheckBox *aGroupSymbolsBox, wxDataViewListCtrl *aFieldsCtrl)
#define DISPLAY_NAME_COLUMN
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu)
Class DIALOG_SYMBOL_FIELDS_TABLE_BASE.
void SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
static bool cmp(const DATA_MODEL_ROW &lhGroup, const DATA_MODEL_ROW &rhGroup, FIELDS_EDITOR_GRID_DATA_MODEL *dataModel, int sortCol, bool ascending)
void OnCancel(wxCommandEvent &event) override
int ValueStringCompare(const wxString &strFWord, const wxString &strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
void OnTableColSize(wxGridSizeEvent &event) override
FIELDS_EDITOR_GRID_DATA_MODEL * m_dataModel
wxPoint GetPosition() const override
A base class for most all the KiCad significant classes used in schematics and boards.
#define SHOW_FIELD_COLUMN
void LoadFieldNames()
Construct the rows of m_fieldsCtrl and the columns of m_dataModel from a union of all field names in ...
Hold a name of a symbol's field, field value, and default visibility.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void SetValue(int aRow, int aCol, const wxString &aValue) override
SCH_EDIT_FRAME * m_parent
SCH_SHEET_PATH & GetCurrentSheet() const
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
wxSplitterWindow * m_splitterMainWindow
wxString GetValue(int aRow, int aCol) override
std::map< std::string, bool > fields_group_by
std::map< std::string, bool > fields_show
wxString GetCanonicalColLabel(int aCol)
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
void RemoveField(const wxString &aFieldName)
Remove a user field from the symbol.
const TEMPLATE_FIELDNAMES & GetTemplateFieldNames()
Return a template field name list for read only access.
std::vector< DATA_MODEL_ROW > m_rows
A helper to define a symbol's reference designator in a schematic.
void OnColSort(wxGridEvent &aEvent)
int GetNumberCols() override
KICAD_T Type() const
Returns the type of object.
Field Name Module PCB, i.e. "16DIP300".