41#include <wx/tokenzr.h>
44#define UNITS_ALL _( "ALL" )
45#define DEMORGAN_ALL _( "ALL" )
46#define DEMORGAN_STD _( "Standard" )
47#define DEMORGAN_ALT _( "Alternate" )
52 wxGridCellCoordsArray topLeft = aGrid->GetSelectionBlockTopLeft();
53 wxGridCellCoordsArray botRight = aGrid->GetSelectionBlockBottomRight();
55 wxArrayInt cols = aGrid->GetSelectedCols();
56 wxArrayInt rows = aGrid->GetSelectedRows();
58 if( topLeft.Count() && botRight.Count() )
60 *aRowStart = topLeft[0].GetRow();
61 *aRowCount = botRight[0].GetRow() - *aRowStart + 1;
63 else if( cols.Count() )
66 *aRowCount = aGrid->GetNumberRows();
68 else if( rows.Count() )
71 *aRowCount = rows.Count();
75 *aRowStart = aGrid->GetGridCursorRow();
76 *aRowCount = *aRowStart >= 0 ? 1 : 0;
105 GetView()->ForceRefresh();
122 case COL_TYPE:
return _(
"Electrical Type" );
133 default: wxFAIL;
return wxEmptyString;
144 wxGrid*
grid = GetView();
146 if(
grid->GetGridCursorRow() == aRow &&
grid->GetGridCursorCol() == aCol
147 &&
grid->IsCellEditControlShown() )
158 static wxString
GetValue(
const std::vector<SCH_PIN*>& pins,
int aCol,
177 val =
pin->GetNumber();
181 val =
pin->GetName();
230 switch(
pin->GetBodyStyle() )
232 case BODY_STYLE::BASE:
235 case BODY_STYLE::DEMORGAN:
251 if( fieldValue.length() )
252 fieldValue += wxT(
", " );
257 if( !fieldValue.Length() )
259 else if( val != fieldValue )
267 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
272 wxString value = aValue;
283 if(
m_eval->Process( value ) )
295 std::vector<SCH_PIN*> pins =
m_rows[ aRow ];
301 wxStringTokenizer tokenizer( value,
"," );
304 while( tokenizer.HasMoreTokens() )
306 wxString pinName = tokenizer.GetNextToken();
309 pinName.Trim(
true ).Trim(
false );
311 if( i < pins.size() )
314 pins.at( i )->SetNumber( pinName );
345 pins.push_back( newPin );
352 while( pins.size() > i )
370 pin->SetNumber( value );
375 pin->SetName( value );
409 pin->GetPosition().y ) );
441 pin->SetBodyStyle( 1 );
443 pin->SetBodyStyle( 2 );
445 pin->SetBodyStyle( 0 );
457 static int findRow(
const std::vector<std::vector<SCH_PIN*>>& aRowSet,
const wxString& aName )
459 for(
size_t i = 0; i < aRowSet.size(); ++i )
461 if( aRowSet[ i ][ 0 ] && aRowSet[ i ][ 0 ]->GetName() == aName )
468 static bool compare(
const std::vector<SCH_PIN*>& lhs,
const std::vector<SCH_PIN*>& rhs,
471 wxString lhStr =
GetValue( lhs, sortCol, parentFrame );
472 wxString rhStr =
GetValue( rhs, sortCol, parentFrame );
478 lhStr =
GetValue( lhs, sortCol, parentFrame );
479 rhStr =
GetValue( rhs, sortCol, parentFrame );
486 auto cmp = [ ascending ](
const auto a,
const auto b )
521 void RebuildRows(
const std::vector<SCH_PIN*>& aPins,
bool groupByName,
bool groupBySelection )
524 std::vector<SCH_PIN*> clear_flags;
526 clear_flags.reserve( aPins.size() );
530 if( groupBySelection )
533 pin->ClearTempFlags();
535 int firstSelectedRow;
536 int selectedRowCount;
540 for(
int ii = 0; ii < selectedRowCount; ++ii )
545 clear_flags.push_back(
pin );
552 grid->CommitPendingChanges(
true );
554 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
555 GetView()->ProcessTableMessage( msg );
560 if( groupBySelection )
561 m_rows.emplace_back( std::vector<SCH_PIN*>() );
571 else if( groupBySelection && (
pin->GetFlags() &
CANDIDATE ) )
576 m_rows.emplace_back( std::vector<SCH_PIN*>() );
577 rowIndex =
m_rows.size() - 1;
585 bool ascending =
true;
587 if( GetView() && GetView()->GetSortingColumn() != wxNOT_FOUND )
589 sortCol = GetView()->GetSortingColumn();
590 ascending = GetView()->IsSortOrderAscending();
593 for( std::vector<SCH_PIN*>& row :
m_rows )
596 if( !groupBySelection )
601 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, (
int)
m_rows.size() );
602 GetView()->ProcessTableMessage( msg );
604 if( groupBySelection )
605 GetView()->SelectRow( 0 );
615 [ aSortCol, ascending,
this ](
const std::vector<SCH_PIN*>& lhs,
616 const std::vector<SCH_PIN*>& rhs ) ->
bool
618 return compare( lhs, rhs, aSortCol, ascending, m_frame );
624 std::sort( aRow.begin(), aRow.end(),
627 return PIN_NUMBERS::Compare( lhs->GetNumber(), rhs->GetNumber() ) < 0;
633 std::vector<SCH_PIN*> row;
634 row.push_back( aPin );
639 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
640 GetView()->ProcessTableMessage( msg );
646 std::vector<SCH_PIN*> removedRow =
m_rows[ aRow ];
652 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
653 GetView()->ProcessTableMessage( msg );
680 if( aValue == wxS(
"1" ) )
684 else if( aValue == wxS(
"0" ) )
690 wxFAIL_MSG( wxString::Format(
"string '%s' can't be converted to boolean correctly, "
691 "it will have been perceived as FALSE",
703 std::vector<std::vector<SCH_PIN*>>
m_rows;
711 std::unique_ptr<NUMERIC_EVALUATOR>
m_eval;
719 m_editFrame( parent ),
729 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
745 wxGridCellAttr* attr;
747 attr =
new wxGridCellAttr;
748 attr->SetReadOnly(
true );
751 attr =
new wxGridCellAttr;
758 attr =
new wxGridCellAttr;
765 attr =
new wxGridCellAttr;
769 orientationNames ) );
773 attr =
new wxGridCellAttr;
774 wxArrayString unitNames;
783 attr =
new wxGridCellAttr;
784 wxArrayString demorganNames;
791 attr =
new wxGridCellAttr;
792 attr->SetRenderer(
new wxGridCellBoolRenderer() );
793 attr->SetEditor(
new wxGridCellBoolEditor() );
794 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
816 GetSizer()->SetSizeHints(
this);
847 m_grid->Connect( wxEVT_GRID_COL_SORT,
858 m_grid->Disconnect( wxEVT_GRID_COL_SORT,
865 m_grid->PopEventHandler(
true );
928 int sortCol = aEvent.GetCol();
933 if(
m_grid->IsSortingBy( sortCol ) )
935 ascending = !
m_grid->IsSortOrderAscending();
978 m_pins.push_back( newPin );
982 m_grid->MakeCellVisible(
m_grid->GetNumberRows() - 1, 1 );
983 m_grid->SetGridCursor(
m_grid->GetNumberRows() - 1, 1 );
985 m_grid->EnableCellEditControl(
true );
986 m_grid->ShowCellEditControl();
1008 int curRow =
m_grid->GetGridCursorRow();
1014 int nextSelRow = std::max( curRow-1, 0 );
1015 m_grid->GoToCell( nextSelRow,
m_grid->GetGridCursorCol() );
1016 m_grid->SetGridCursor( nextSelRow,
m_grid->GetGridCursorCol() );
1017 m_grid->SelectRow( nextSelRow );
1053 if( candidate->GetNumber() == pins.at( 0 )->GetNumber() )
1082 m_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
1098 m_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
1107 if( event.IsChecked() )
1135 wxGridUpdateLocker deferRepaintsTillLeavingScope;
1154 width -=
m_grid->GetColSize( i );
1166 wxSize new_size =
event.GetSize();
1188 if( !
m_grid->IsCellEditControlShown() )
1192 int firstSelectedRow;
1193 int selectedRowCount;
1213 int retval = wxID_CANCEL;
1232 EndDialog( retval );
1247 EndDialog( retval );
1259 if(
pin->GetNumber().Length() )
1264 m_pin_count->SetLabel( wxString::Format( wxT(
"%u" ), (
unsigned)
m_pins.size() ) );
constexpr EDA_IU_SCALE schIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Class DIALOG_LIB_EDIT_PIN_TABLE_BASE.
STD_BITMAP_BUTTON * m_refreshButton
wxStaticText * m_pin_numbers_summary
BITMAP_BUTTON * m_divider1
wxButton * m_ButtonsCancel
STD_BITMAP_BUTTON * m_addButton
wxStaticText * m_pin_count
wxStaticText * m_duplicate_pins
wxCheckBox * m_cbFilterByUnit
STD_BITMAP_BUTTON * m_deleteButton
BITMAP_BUTTON * m_divider2
wxButton * m_groupSelected
bool m_modified
true when there are unsaved changes
void OnRebuildRows(wxCommandEvent &event) override
int m_originalColWidths[COL_COUNT]
void OnCancel(wxCommandEvent &event) override
void OnUpdateUI(wxUpdateUIEvent &event) override
void RemovePin(SCH_PIN *pin)
void OnColSort(wxGridEvent &aEvent)
void OnGroupSelected(wxCommandEvent &event) override
void OnClose(wxCloseEvent &event) override
void OnSize(wxSizeEvent &event) override
PIN_TABLE_DATA_MODEL * m_dataModel
~DIALOG_LIB_EDIT_PIN_TABLE() override
void AddPin(SCH_PIN *pin)
void OnCellSelected(wxGridEvent &event) override
bool TransferDataToWindow() override
void OnAddRow(wxCommandEvent &event) override
void OnDeleteRow(wxCommandEvent &event) override
SYMBOL_EDIT_FRAME * m_editFrame
std::bitset< 64 > m_columnsShown
void OnCellEdited(wxGridEvent &event) override
DIALOG_LIB_EDIT_PIN_TABLE(SYMBOL_EDIT_FRAME *parent, LIB_SYMBOL *aSymbol)
std::vector< SCH_PIN * > m_pins
bool TransferDataFromWindow() override
void OnFilterCheckBox(wxCommandEvent &event) override
void OnFilterChoice(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
bool IsQuasiModal() const
void EndQuasiModal(int retCode)
The base class for create windows for drawing purpose.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Define a library symbol object.
bool IsMulti() const override
static wxString LetterSubReference(int aUnit, int aFirstId)
std::vector< SCH_PIN * > GetAllLibPins() const
Return a list of pin pointers for all units / converts.
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
wxString GetUnitReference(int aUnit) override
Return an identifier for aUnit for symbols with units.
int GetUnitCount() const override
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
virtual SETTINGS_MANAGER & GetSettingsManager() const
wxString GetDuplicates() const
Gets a formatted string of all the pins that have duplicate numbers.
static int Compare(const wxString &lhs, const wxString &rhs)
void insert(value_type const &v)
wxString GetSummary() const
static bool compare(const std::vector< SCH_PIN * > &lhs, const std::vector< SCH_PIN * > &rhs, int sortCol, bool ascending, EDA_DRAW_FRAME *parentFrame)
PIN_TABLE_DATA_MODEL(SYMBOL_EDIT_FRAME *aFrame, DIALOG_LIB_EDIT_PIN_TABLE *aPinTable, LIB_SYMBOL *aSymbol)
void RebuildRows(const std::vector< SCH_PIN * > &aPins, bool groupByName, bool groupBySelection)
void SetUnitFilter(int aFilter)
static int findRow(const std::vector< std::vector< SCH_PIN * > > &aRowSet, const wxString &aName)
std::map< std::pair< std::vector< SCH_PIN * >, int >, wxString > m_evalOriginal
static wxString StringFromBool(bool aValue)
std::vector< std::vector< SCH_PIN * > > m_rows
int GetNumberCols() override
bool IsEmptyCell(int row, int col) override
DIALOG_LIB_EDIT_PIN_TABLE * m_pinTable
std::vector< SCH_PIN * > GetRowPins(int aRow)
static wxString GetValue(const std::vector< SCH_PIN * > &pins, int aCol, EDA_DRAW_FRAME *aParentFrame)
void AppendRow(SCH_PIN *aPin)
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
void SetValue(int aRow, int aCol, const wxString &aValue) override
wxString GetValue(int aRow, int aCol) override
void SortRows(int aSortCol, bool ascending)
SYMBOL_EDIT_FRAME * m_frame
int GetNumberRows() override
void onUnitsChanged(wxCommandEvent &aEvent)
static bool BoolFromString(wxString aValue)
wxString GetColLabelValue(int aCol) override
std::vector< SCH_PIN * > RemoveRow(int aRow)
void SortPins(std::vector< SCH_PIN * > &aRow)
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void SetUnit(int aUnit)
void SetNumber(const wxString &aNumber)
void SetOrientation(PIN_ORIENTATION aOrientation)
void SetName(const wxString &aName)
void SetPosition(const VECTOR2I &aPos) override
const wxString & GetName() const
PIN_ORIENTATION GetOrientation() const
void SetShape(GRAPHIC_PINSHAPE aShape)
VECTOR2I GetPosition() const override
void SetType(ELECTRICAL_PINTYPE aType)
GRAPHIC_PINSHAPE GetShape() const
ELECTRICAL_PINTYPE GetType() const
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
The symbol library editor main window.
void FocusOnItem(SCH_ITEM *aItem)
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
bool GetShowDeMorgan() const
SYMBOL_EDITOR_SETTINGS * GetSettings() const
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
EDA_UNITS GetUserUnits() const
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aTextValue in aUnits to internal units used by the frame.
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.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
This file is part of the common library.
void getSelectedArea(WX_GRID *aGrid, int *aRowStart, int *aRowCount)
#define CANDIDATE
flag indicating that the structure is connected
static std::map< int, wxString > shapeNames
PGM_BASE & Pgm()
The global Program "get" accessor.
const std::vector< BITMAPS > & PinTypeIcons()
const wxArrayString & PinTypeNames()
int PinOrientationIndex(PIN_ORIENTATION code)
const wxArrayString & PinShapeNames()
const std::vector< BITMAPS > & PinShapeIcons()
const wxArrayString & PinOrientationNames()
PIN_ORIENTATION PinOrientationCode(size_t index)
const std::vector< BITMAPS > & PinOrientationIcons()
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
constexpr int MilsToIU(int mils) const
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
VECTOR2< int32_t > VECTOR2I