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 );
339 pins.push_back( newPin );
346 while( pins.size() > i )
364 pin->SetNumber( value );
369 pin->SetName( value );
403 pin->GetPosition().y ) );
435 pin->SetConvert( 1 );
437 pin->SetConvert( 2 );
439 pin->SetConvert( 0 );
451 static int findRow(
const std::vector<LIB_PINS>& aRowSet,
const wxString& aName )
453 for(
size_t i = 0; i < aRowSet.size(); ++i )
455 if( aRowSet[ i ][ 0 ] && aRowSet[ i ][ 0 ]->GetName() == aName )
465 wxString lhStr =
GetValue( lhs, sortCol, parentFrame );
466 wxString rhStr =
GetValue( rhs, sortCol, parentFrame );
472 lhStr =
GetValue( lhs, sortCol, parentFrame );
473 rhStr =
GetValue( rhs, sortCol, parentFrame );
480 auto cmp = [ ascending ](
const auto a,
const auto b )
518 std::vector<LIB_PIN*> clear_flags;
520 clear_flags.reserve( aPins.size() );
524 if( groupBySelection )
527 pin->ClearTempFlags();
529 int firstSelectedRow;
530 int selectedRowCount;
534 for(
int ii = 0; ii < selectedRowCount; ++ii )
539 clear_flags.push_back(
pin );
546 grid->CommitPendingChanges(
true );
548 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0,
m_rows.size() );
549 GetView()->ProcessTableMessage( msg );
554 if( groupBySelection )
565 else if( groupBySelection && (
pin->GetFlags() &
CANDIDATE ) )
571 rowIndex =
m_rows.size() - 1;
579 bool ascending =
true;
581 if( GetView() && GetView()->GetSortingColumn() != wxNOT_FOUND )
583 sortCol = GetView()->GetSortingColumn();
584 ascending = GetView()->IsSortOrderAscending();
590 if( !groupBySelection )
595 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
m_rows.size() );
596 GetView()->ProcessTableMessage( msg );
598 if( groupBySelection )
599 GetView()->SelectRow( 0 );
609 [ aSortCol, ascending,
this ](
const LIB_PINS& lhs,
const LIB_PINS& rhs ) ->
bool
611 return compare( lhs, rhs, aSortCol, ascending, m_frame );
617 std::sort( aRow.begin(), aRow.end(),
620 return PIN_NUMBERS::Compare( lhs->GetNumber(), rhs->GetNumber() ) < 0;
627 row.push_back( aPin );
632 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, 1 );
633 GetView()->ProcessTableMessage( msg );
645 wxGridTableMessage msg(
this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, aRow, 1 );
646 GetView()->ProcessTableMessage( msg );
668 if( aValue == wxS(
"1" ) )
672 else if( aValue == wxS(
"0" ) )
678 wxFAIL_MSG( wxString::Format(
"string '%s' can't be converted to boolean correctly, "
679 "it will have been perceived as FALSE",
699 std::unique_ptr<NUMERIC_EVALUATOR>
m_eval;
707 m_editFrame( parent ),
717 m_grid->SetDefaultRowSize(
m_grid->GetDefaultRowSize() + 4 );
733 wxGridCellAttr* attr;
735 attr =
new wxGridCellAttr;
736 attr->SetReadOnly(
true );
739 attr =
new wxGridCellAttr;
746 attr =
new wxGridCellAttr;
753 attr =
new wxGridCellAttr;
757 orientationNames ) );
761 attr =
new wxGridCellAttr;
762 wxArrayString unitNames;
771 attr =
new wxGridCellAttr;
772 wxArrayString demorganNames;
779 attr =
new wxGridCellAttr;
780 attr->SetRenderer(
new wxGridCellBoolRenderer() );
781 attr->SetEditor(
new wxGridCellBoolEditor() );
782 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
804 GetSizer()->SetSizeHints(
this);
835 m_grid->Connect( wxEVT_GRID_COL_SORT,
846 m_grid->Disconnect( wxEVT_GRID_COL_SORT,
853 m_grid->PopEventHandler(
true );
913 int sortCol = aEvent.GetCol();
918 if(
m_grid->IsSortingBy( sortCol ) )
920 ascending = !
m_grid->IsSortOrderAscending();
958 m_pins.push_back( newPin );
962 m_grid->MakeCellVisible(
m_grid->GetNumberRows() - 1, 1 );
963 m_grid->SetGridCursor(
m_grid->GetNumberRows() - 1, 1 );
965 m_grid->EnableCellEditControl(
true );
966 m_grid->ShowCellEditControl();
989 int curRow =
m_grid->GetGridCursorRow();
999 curRow = std::min( curRow,
m_grid->GetNumberRows() - 1 );
1000 m_grid->GoToCell( curRow,
m_grid->GetGridCursorCol() );
1001 m_grid->SetGridCursor( curRow,
m_grid->GetGridCursorCol() );
1002 m_grid->SelectRow( curRow );
1034 m_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
1050 m_grid->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
1059 if( event.IsChecked() )
1087 wxGridUpdateLocker deferRepaintsTillLeavingScope;
1106 width -=
m_grid->GetColSize( i );
1118 wxSize new_size =
event.GetSize();
1140 if( !
m_grid->IsCellEditControlShown() )
1144 int firstSelectedRow;
1145 int selectedRowCount;
1165 int retval = wxID_CANCEL;
1184 EndDialog( retval );
1199 EndDialog( retval );
1211 if(
pin->GetNumber().Length() )
1216 m_pin_count->SetLabel( wxString::Format( wxT(
"%u" ), (
unsigned)
m_pins.size() ) );
constexpr EDA_IU_SCALE schIUScale
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
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
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.
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
int GetOrientation() const
void SetName(const wxString &aName)
void SetType(ELECTRICAL_PINTYPE aType)
VECTOR2I GetPosition() const override
GRAPHIC_PINSHAPE GetShape() const
void SetNumber(const wxString &aNumber)
const wxString & GetName() const
void SetOrientation(int aOrientation)
Define a library symbol object.
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
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
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
The symbol library editor main window.
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.
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aValue in internal units into a united string.
int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aTextValue in aUnits to internal units used by the frame.
EDA_UNITS GetUserUnits() const
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()
int PinOrientationIndex(int code)
const wxArrayString & PinTypeNames()
const wxArrayString & PinShapeNames()
const std::vector< BITMAPS > & PinShapeIcons()
const wxArrayString & PinOrientationNames()
int PinOrientationCode(int 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...