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() )
176 val =
pin->GetNumber();
180 val =
pin->GetName();
229 switch(
pin->GetConvert() )
250 if( fieldValue.length() )
251 fieldValue += wxT(
", " );
256 if( !fieldValue.Length() )
258 else if( val != fieldValue )
266 void SetValue(
int aRow,
int aCol,
const wxString &aValue )
override
271 wxString value = aValue;
282 if(
m_eval->Process( value ) )
300 wxStringTokenizer tokenizer( value,
"," );
303 while( tokenizer.HasMoreTokens() )
305 wxString pinName = tokenizer.GetNextToken();
308 pinName.Trim(
true ).Trim(
false );
310 if( i < pins.size() )
313 pins.at( i )->SetNumber( pinName );
344 pins.push_back( newPin );
351 while( pins.size() > i )
369 pin->SetNumber( value );
374 pin->SetName( value );
408 pin->GetPosition().y ) );
440 pin->SetConvert( 1 );
442 pin->SetConvert( 2 );
444 pin->SetConvert( 0 );
456 static int findRow(
const std::vector<LIB_PINS>& aRowSet,
const wxString& aName )
458 for(
size_t i = 0; i < aRowSet.size(); ++i )
460 if( aRowSet[ i ][ 0 ] && aRowSet[ i ][ 0 ]->GetName() == aName )
470 wxString lhStr =
GetValue( lhs, sortCol, parentFrame );
471 wxString rhStr =
GetValue( rhs, sortCol, parentFrame );
477 lhStr =
GetValue( lhs, sortCol, parentFrame );
478 rhStr =
GetValue( rhs, sortCol, parentFrame );
485 auto cmp = [ ascending ](
const auto a,
const auto b )
523 std::vector<LIB_PIN*> clear_flags;
525 clear_flags.reserve( aPins.size() );
529 if( groupBySelection )
532 pin->ClearTempFlags();
534 int firstSelectedRow;
535 int selectedRowCount;
539 for(
int ii = 0; ii < selectedRowCount; ++ii )
544 clear_flags.push_back(
pin );
551 grid->CommitPendingChanges(
true );
553 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
554 GetView()->ProcessTableMessage( msg );
559 if( groupBySelection )
570 else if( groupBySelection && (
pin->GetFlags() &
CANDIDATE ) )
576 rowIndex =
m_rows.size() - 1;
584 bool ascending =
true;
586 if( GetView() && GetView()->GetSortingColumn() != wxNOT_FOUND )
588 sortCol = GetView()->GetSortingColumn();
589 ascending = GetView()->IsSortOrderAscending();
595 if( !groupBySelection )
600 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
601 GetView()->ProcessTableMessage( msg );
603 if( groupBySelection )
604 GetView()->SelectRow( 0 );
614 [ aSortCol, ascending,
this ](
const LIB_PINS& lhs,
const LIB_PINS& rhs ) ->
bool
616 return compare( lhs, rhs, aSortCol, ascending, m_frame );
622 std::sort( aRow.begin(), aRow.end(),
625 return PIN_NUMBERS::Compare( lhs->GetNumber(), rhs->GetNumber() ) < 0;
632 row.push_back( aPin );
637 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
638 GetView()->ProcessTableMessage( msg );
650 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
651 GetView()->ProcessTableMessage( msg );
678 if( aValue == wxS(
"1" ) )
682 else if( aValue == wxS(
"0" ) )
688 wxFAIL_MSG( wxString::Format(
"string '%s' can't be converted to boolean correctly, "
689 "it will have been perceived as FALSE",
709 std::unique_ptr<NUMERIC_EVALUATOR>
m_eval;
717 m_editFrame( parent ),
727 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
743 wxGridCellAttr* attr;
745 attr =
new wxGridCellAttr;
746 attr->SetReadOnly(
true );
749 attr =
new wxGridCellAttr;
756 attr =
new wxGridCellAttr;
763 attr =
new wxGridCellAttr;
767 orientationNames ) );
771 attr =
new wxGridCellAttr;
772 wxArrayString unitNames;
781 attr =
new wxGridCellAttr;
782 wxArrayString demorganNames;
789 attr =
new wxGridCellAttr;
790 attr->SetRenderer(
new wxGridCellBoolRenderer() );
791 attr->SetEditor(
new wxGridCellBoolEditor() );
792 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
814 GetSizer()->SetSizeHints(
this);
845 m_grid->Connect( wxEVT_GRID_COL_SORT,
856 m_grid->Disconnect( wxEVT_GRID_COL_SORT,
863 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();
1009 int curRow =
m_grid->GetGridCursorRow();
1019 curRow = std::min( curRow,
m_grid->GetNumberRows() - 1 );
1020 m_grid->GoToCell( curRow,
m_grid->GetGridCursorCol() );
1021 m_grid->SetGridCursor( curRow,
m_grid->GetGridCursorCol() );
1022 m_grid->SelectRow( curRow );
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 OnColSort(wxGridEvent &aEvent)
void OnGroupSelected(wxCommandEvent &event) override
void OnClose(wxCloseEvent &event) override
void OnSize(wxSizeEvent &event) override
void RemovePin(LIB_PIN *pin)
PIN_TABLE_DATA_MODEL * m_dataModel
~DIALOG_LIB_EDIT_PIN_TABLE() override
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 AddPin(LIB_PIN *pin)
void OnCellEdited(wxGridEvent &event) override
DIALOG_LIB_EDIT_PIN_TABLE(SYMBOL_EDIT_FRAME *parent, LIB_SYMBOL *aSymbol)
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.
void SetShape(GRAPHIC_PINSHAPE aShape)
ELECTRICAL_PINTYPE GetType() const
void SetPosition(const VECTOR2I &aPos) override
void SetName(const wxString &aName)
void SetType(ELECTRICAL_PINTYPE aType)
PIN_ORIENTATION GetOrientation() const
VECTOR2I GetPosition() const override
void SetOrientation(PIN_ORIENTATION aOrientation)
GRAPHIC_PINSHAPE GetShape() const
void SetNumber(const wxString &aNumber)
const wxString & GetName() const
Define a library symbol object.
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
static wxString LetterSubReference(int aUnit, int aFirstId)
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
wxString GetUnitReference(int aUnit) override
Return an identifier for aUnit for symbols with units.
std::vector< LIB_PIN * > GetAllLibPins() const
Return a list of pin pointers for all units / converts.
int GetUnitCount() const override
For items with units, return the number of units.
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
PIN_TABLE_DATA_MODEL(SYMBOL_EDIT_FRAME *aFrame, DIALOG_LIB_EDIT_PIN_TABLE *aPinTable, LIB_SYMBOL *aSymbol)
void RebuildRows(const LIB_PINS &aPins, bool groupByName, bool groupBySelection)
void SetUnitFilter(int aFilter)
static wxString StringFromBool(bool aValue)
static wxString GetValue(const LIB_PINS &pins, int aCol, EDA_DRAW_FRAME *aParentFrame)
void AppendRow(LIB_PIN *aPin)
std::vector< LIB_PINS > m_rows
int GetNumberCols() override
static bool compare(const LIB_PINS &lhs, const LIB_PINS &rhs, int sortCol, bool ascending, EDA_DRAW_FRAME *parentFrame)
bool IsEmptyCell(int row, int col) override
static int findRow(const std::vector< LIB_PINS > &aRowSet, const wxString &aName)
DIALOG_LIB_EDIT_PIN_TABLE * m_pinTable
LIB_PINS GetRowPins(int aRow)
void SortPins(LIB_PINS &aRow)
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
std::map< std::pair< LIB_PINS, int >, wxString > m_evalOriginal
void onUnitsChanged(wxCommandEvent &aEvent)
static bool BoolFromString(wxString aValue)
LIB_PINS RemoveRow(int aRow)
wxString GetColLabelValue(int aCol) override
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
The symbol library editor main window.
void FocusOnItem(LIB_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
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
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.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
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...