22#include <wx/display.h>
23#include <wx/dcclient.h>
24#include <wx/filedlg.h>
26#include <wx/settings.h>
79 wxFAIL_MSG( wxT(
"Invalid pad shape" ) );
88 return _(
"Aperture" );
99 const auto isBackOnlyPad =
100 [](
const PAD&
pad ) ->
bool
102 const LSET layers =
pad.GetLayerSet();
119 if( isBackOnlyPad( aPad ) )
160 if( isBackOnlyPad( aPad ) )
189 bool aPreserveValues )
192 const wxColour drillTextColour = drillIsEditable ? aGrid.GetDefaultCellTextColour()
193 : wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT );
195 aGrid.SetReadOnly( aRowId, COLS::COL_DRILL_X, !drillIsEditable );
196 aGrid.SetReadOnly( aRowId, COLS::COL_DRILL_Y, !drillIsEditable );
197 aGrid.SetCellTextColour( aRowId, COLS::COL_DRILL_X, drillTextColour );
198 aGrid.SetCellTextColour( aRowId, COLS::COL_DRILL_Y, drillTextColour );
200 if( aPreserveValues )
204 aGrid.SetCellValue( aRowId, COLS::COL_DRILL_X, drill.
x > 0 ? aUnitsProvider.
StringFromValue( drill.
x,
true )
206 aGrid.SetCellValue( aRowId, COLS::COL_DRILL_Y, drill.
y > 0 ? aUnitsProvider.
StringFromValue( drill.
y,
true )
220 case COLS::COL_NUMBER:
return wxT(
"Number" );
221 case COLS::COL_TYPE:
return wxT(
"Type" );
222 case COLS::COL_SHAPE:
return wxT(
"Shape" );
223 case COLS::COL_POS_X:
return wxT(
"Pos X" );
224 case COLS::COL_POS_Y:
return wxT(
"Pos Y" );
225 case COLS::COL_SIZE_X:
return wxT(
"Size X" );
226 case COLS::COL_SIZE_Y:
return wxT(
"Size Y" );
227 case COLS::COL_DRILL_X:
return wxT(
"Drill X" );
228 case COLS::COL_DRILL_Y:
return wxT(
"Drill Y" );
229 case COLS::COL_P2D_LENGTH:
return wxT(
"Pad to die length" );
230 case COLS::COL_P2D_DELAY:
return wxT(
"Pad to die delay" );
232 wxFAIL_MSG( wxT(
"Invalid column index" ) );
233 return wxEmptyString;
240 for(
int i = 0; i < static_cast<int>( COLS::COL_COUNT ); i++ )
247 return COLS::COL_COUNT;
268 wxCHECK_MSG( aFieldId >= 0 && aFieldId <
static_cast<int>( COLS::COL_COUNT ), wxEmptyString,
269 wxT(
"Invalid column index" ) );
306 return wxEmptyString;
312 return wxEmptyString;
315 return wxEmptyString;
318 wxFAIL_MSG(
"Invalid column index" );
319 return wxEmptyString;
328 void UpdatePad(
PAD& aPad,
const wxString& aValue,
int aFieldId )
const
421 wxFAIL_MSG(
"Invalid column index" );
438 if(
m_grid->GetNumberRows() > 0 )
454 wxGridCellAttr* attr =
nullptr;
457 attr =
new wxGridCellAttr;
458 wxArrayString typeNames;
459 typeNames.push_back(
_(
"Through-hole" ) );
460 typeNames.push_back(
_(
"SMD" ) );
461 typeNames.push_back(
_(
"Connector" ) );
462 typeNames.push_back(
_(
"NPTH" ) );
463 typeNames.push_back(
_(
"Non-component" ) );
464 typeNames.push_back(
_(
"Aperture" ) );
468 attr =
new wxGridCellAttr;
480 attr =
new wxGridCellAttr;
484 attr =
new wxGridCellAttr;
488 attr =
new wxGridCellAttr;
492 attr =
new wxGridCellAttr;
497 attr =
new wxGridCellAttr;
502 attr =
new wxGridCellAttr;
527 m_grid->PushEventHandler( gridTricks );
528 m_grid->SetSelectionMode( wxGrid::wxGridSelectCells );
541 int displayIdx = wxDisplay::GetFromWindow( aParent );
543 if( displayIdx == wxNOT_FOUND )
546 wxRect displayArea = wxDisplay( (
unsigned int) displayIdx ).GetClientArea();
547 wxSize dlgSize = GetSize();
548 int maxH = ( displayArea.height * 4 ) / 5;
550 if( dlgSize.y > maxH )
557 wxSize minSz = GetMinSize();
574 m_grid->PopEventHandler(
true );
590 if( aPad->
GetSize( aLayer ).
x != size_x )
593 if( aPad->
GetSize( aLayer ).
y != size_y )
640 m_grid->AutoSizeColumns();
663 dc.GetTextExtent( str, &w, &h );
664 maxWidth = std::max( maxWidth, w );
668 int padding = FromDIP( 30 );
677 wxSizeEvent sizeEvt( GetSize(), GetId() );
681 wxSizeEvent evt( sizeEvt );
686 if(
m_grid->GetNumberRows() > 0 )
688 m_grid->SetGridCursor( 0, 0 );
691 wxGridEvent ev(
m_grid->GetId(), wxEVT_GRID_SELECT_CELL,
m_grid, 0, 0, -1, -1,
true );
703 [
this, aRowId](
int aCol )
706 wxGridCellAttr* attr =
m_grid->GetOrCreateCellAttr( aRowId, aCol );
707 attr->SetEditor( cellEditor );
765 pad->ClearBrightened();
792 for(
PAD*
pad : livePads )
859 const wxString shape =
m_grid->GetCellValue( aRowId, aCol );
880 pos.
x =
m_grid->GetUnitValue( aRowId, aCol );
882 pos.
y =
m_grid->GetUnitValue( aRowId, aCol );
891 const wxString sizeValue =
m_grid->GetCellValue( aRowId, aCol );
896 const int size =
m_grid->GetUnitValue( aRowId, aCol );
908 aPad.
SetSize( aLayer, layerSize );
922 if( drillX > 0 || drillY > 0 )
939 const wxString lenStr =
m_grid->GetCellValue( aRowId, aCol );
941 if( lenStr.IsEmpty() )
951 const wxString delayStr =
m_grid->GetCellValue( aRowId, aCol );
953 if( delayStr.IsEmpty() )
962 wxFAIL_MSG( wxT(
"Invalid column index" ) );
970 if( !
m_grid->CommitPendingChanges() )
1011 const auto applyRowDataToPad =
1012 [&](
PAD& aPad,
int aRowId )
1014 for(
int col = 0; col <
m_grid->GetNumberCols(); ++col )
1025 applyRowDataToPad( *
pad, row );
1032 applyRowDataToPad( *
pad, row );
1045 commit.
Push(
_(
"Edit Pads" ) );
1063 int cols =
m_grid->GetNumberCols();
1065 std::vector<int> widths;
1066 widths.reserve( cols );
1068 for(
int c = 0; c < cols; ++c )
1070 int w =
m_grid->GetColSize( c );
1071 widths.push_back( w );
1078 for(
int w : widths )
1095 int cols =
m_grid->GetNumberCols();
1098 for(
int c = 0; c < cols; ++c )
1099 available +=
m_grid->GetColSize( c );
1102 int clientW =
m_grid->GetClientSize().x;
1105 available = clientW;
1109 for(
int c = 0; c < cols; ++c )
1118 m_grid->SetColSize( c, target );
1137 int row = aEvent.GetRow();
1138 int col = aEvent.GetCol();
1149 bool needCanvasRefresh =
true;
1157 if( drillsAreEditable )
1165 if( drillX > 0 || drillY > 0 )
1169 else if( !drillsWereEditable )
1173 const int defaultDrill =
pcbIUScale.mmToIU( 1.0 );
1174 target->
SetDrillSize( { defaultDrill, defaultDrill } );
1183 needCanvasRefresh =
false;
1192 if( needCanvasRefresh )
1203 base->GetCanvas()->Refresh();
1211 int row = aEvent.GetRow();
1222 if(
pad->IsBrightened() )
1224 pad->ClearBrightened();
1236 pad->SetBrightened();
1252 int row =
m_grid->GetGridCursorRow();
1253 int col =
m_grid->GetGridCursorCol();
1260 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
1289 if(
pad->GetNumber().Length() )
1293 const wxString summary = pinNumbers.
GetSummary();
1308 if( aRowId < 0 ||
static_cast<size_t>( aRowId ) >=
m_rowPads.size() )
1323 wxFileName fn(
m_footprint->GetFPID().GetLibItemName() );
1327 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1331 if( dlg.ShowModal() == wxID_CANCEL )
1334 filePath = dlg.GetPath();
1337 std::vector<PAD*> padsToExport;
1338 bool complexPadstacks =
false;
1344 complexPadstacks =
true;
1348 padsToExport.push_back(
pad );
1351 if( complexPadstacks )
1353 if( wxMessageBox(
_(
"Complex padstacks cannot be exported via CSV.\n\nThey will be skipped." ),
1354 _(
"Export Pad Table" ), wxOK | wxCANCEL | wxICON_WARNING,
this ) != wxOK )
1360 static const std::vector<COLS> exportCols {
1370 COLS::COL_P2D_LENGTH,
1371 COLS::COL_P2D_DELAY,
1377 std::vector<std::vector<wxString>>
table;
1378 table.reserve( padsToExport.size() + 1 );
1380 std::vector<wxString> header;
1381 header.reserve( exportCols.size() );
1383 for(
COLS col : exportCols )
1386 table.emplace_back( std::move( header ) );
1388 for(
PAD*
pad : padsToExport )
1390 std::vector<wxString>& row =
table.emplace_back();
1391 row.reserve( exportCols.size() );
1393 for(
COLS col : exportCols )
1394 row.emplace_back( formatter.
Format( *
pad, col ) );
1423 std::map<wxString, std::vector<PAD*>> padsByNumber;
1426 padsByNumber[
pad->GetNumber()].push_back(
pad );
1432 std::vector<std::unique_ptr<PAD>> createdPads;
1434 if( csvData && csvData->size() >= 2 )
1436 std::vector<COLS> headerCols;
1437 wxArrayString unknownHeaders;
1438 std::optional<size_t> numberColIdx;
1440 for(
const wxString& label : ( *csvData )[0] )
1444 if( col >= COLS::COL_COUNT )
1445 unknownHeaders.push_back( label );
1447 if( col == COLS::COL_NUMBER )
1448 numberColIdx = headerCols.size();
1450 headerCols.push_back( col );
1453 if( replaceAll && !numberColIdx.has_value() )
1455 wxString msg =
_(
"Imported pad data must include pad numbers." );
1456 wxMessageBox( msg,
_(
"Import error" ), wxOK | wxICON_ERROR,
this );
1460 if( !unknownHeaders.IsEmpty() )
1462 wxString msg = wxString::Format(
_(
"Unknown columns in data: %s. These columns will be ignored." ),
1469 int ret = wxMessageBox(
reporter.GetMessages(),
_(
"Errors" ), wxOK | wxCANCEL | wxICON_ERROR,
this );
1471 if( ret == wxCANCEL )
1475 for(
size_t i = 1; i < csvData->size(); ++i )
1477 const std::vector<wxString>& cols = ( *csvData )[i];
1481 std::unique_ptr<PAD> newPad;
1482 PAD* padToUpdate =
nullptr;
1484 const size_t numberCol = numberColIdx.value_or( cols.size() );
1486 if( replaceAll && numberCol < cols.size() && !cols[numberCol].IsEmpty() )
1488 auto bucketIt = padsByNumber.find( cols[numberCol] );
1490 if( bucketIt != padsByNumber.end() && !bucketIt->second.empty() )
1492 padToUpdate = bucketIt->second.front();
1493 bucketIt->second.erase( bucketIt->second.begin() );
1501 padToUpdate = newPad.get();
1504 size_t maxCol = std::min( headerCols.size(), cols.size() );
1506 for(
size_t j = 0; j < maxCol; ++j )
1508 if( headerCols[j] == COLS::COL_COUNT )
1511 fmt.
UpdatePad( *padToUpdate, cols[j], headerCols[j] );
1523 createdPads.push_back( std::move( newPad ) );
1527 if( !createdPads.empty() )
1531 std::vector<KIGFX::VIEW_ITEM*> viewPads;
1533 for(
const auto&
pad : createdPads )
1534 viewPads.push_back(
pad.get() );
1539 for( std::unique_ptr<PAD>&
pad : createdPads )
1548 for(
const auto& [number, pads] : padsByNumber )
1565 m_grid->CommitPendingChanges();
1576 int currentRows =
m_grid->GetNumberRows();
1577 int neededRows =
static_cast<int>(
m_rowPads.size() );
1579 if( neededRows > currentRows )
1580 m_grid->AppendRows( neededRows - currentRows );
1581 else if( neededRows < currentRows )
1582 m_grid->DeleteRows( neededRows, currentRows - neededRows );
1602 [&]() -> std::pair<int, int>
1604 PAD* newPad =
nullptr;
1610 newPad =
static_cast<PAD*
>(
m_rowPads.back()->Duplicate(
false,
nullptr ) );
1619 view->
Add( newPad );
1624 int row =
m_grid->GetNumberRows();
1649 if( row < 0 ||
static_cast<size_t>( row ) >=
m_rowPads.size() )
1654 pad->ClearBrightened();
1665 m_grid->DeleteRows( row, 1 );
constexpr EDA_IU_SCALE pcbIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
wxButton * m_btnImportFromFile
DIALOG_FP_EDIT_PAD_TABLE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Pad Table"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxStaticText * m_pin_numbers_summary
STD_BITMAP_BUTTON * m_buttonDelete
STD_BITMAP_BUTTON * m_buttonAdd
wxRadioButton * m_rbReplaceExisting
wxButton * m_btnExportToFile
wxStaticText * m_duplicate_pins
wxStaticText * m_pin_count
void setPadFromGridCell(PAD &aPad, int aRowId, COLS aCol)
PAD * getPadForRow(int aRowId) const
void OnCellChanged(wxGridEvent &aEvent) override
DIALOG_FP_EDIT_PAD_TABLE(PCB_BASE_FRAME *aParent, FOOTPRINT *aFootprint)
void OnCharHook(wxKeyEvent &aEvent) override
void fillGridRow(int aRowId, PAD *aPad)
void CaptureOriginalPadState()
void OnSelectCell(wxGridEvent &aEvent) override
void InitColumnProportions()
void setRowNullableEditors(int aRowId) const
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
void restoreOriginalPadData()
void OnImportButtonClick(wxCommandEvent &aEvent) override
std::vector< PAD * > m_rowPads
bool m_accepted
Set when the changes are committed on OK.
void OnExportButtonClick(wxCommandEvent &aEvent) override
std::map< PAD *, PAD_SNAPSHOT > m_originalPads
void OnDeleteRow(wxCommandEvent &aEvent) override
std::vector< int > m_minColWidths
void OnSize(wxSizeEvent &aEvent) override
void restorePadFromSnapshot(PAD &aPad, const PAD_SNAPSHOT &aSnap) const
~DIALOG_FP_EDIT_PAD_TABLE() override
void OnCancel(wxCommandEvent &aEvent) override
void RestoreOriginalPadState()
std::vector< double > m_colProportions
std::unique_ptr< UNITS_PROVIDER > m_unitsProvider
void OnUpdateUI(wxUpdateUIEvent &aEvent) override
std::vector< PAD * > m_removedPads
void OnAddRow(wxCommandEvent &aEvent) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual void OnCharHook(wxKeyEvent &aEvt)
EDA_UNITS GetUserUnits() const
void ForceRefresh()
Force a redraw.
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
void EnableColumnBulkEdit(bool aEnable=true)
Apply an edit to every selected cell in the edited cell's column.
const VECTOR2D & GetGridSize() const
Return the grid size.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
void AddBatch(const std::vector< VIEW_ITEM * > &aItems)
Add a batch of items to the view, using bulk-loaded R-trees for initial population.
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
LSET is a set of PCB_LAYER_IDs.
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
LSET & FlipStandardLayers(int aCopperLayersCount=0)
Flip the layers in this set.
A singleton reporter that reports to nowhere.
void ForEachUniqueLayer(const std::function< void(PCB_LAYER_ID)> &aMethod) const
Runs the given callable for each active unique copper layer in this padstack, meaning F_Cu for MODE::...
@ NORMAL
Shape is the same on all layers.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
bool IsAperturePad() const
void SetAttribute(PAD_ATTRIB aAttribute)
static wxString ShowPadShape(PAD_SHAPE aShape)
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
PAD_ATTRIB GetAttribute() const
const wxString & GetNumber() const
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
VECTOR2I GetPosition() const override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
VECTOR2I GetDrillSize() const
void SetPadToDieDelay(int aDelay)
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
void SetNumber(const wxString &aNumber)
Set the pad number (note that it can be alphanumeric, such as the array reference "AA12").
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
int GetPadToDieDelay() const
void SetPadstack(const PADSTACK &aPadstack)
void SetPosition(const VECTOR2I &aPos) override
const PADSTACK & Padstack() const
void SetDrillSize(const VECTOR2I &aSize)
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
static LSET SMDMask()
layer set for a SMD pad on Front layer
void SetLayerSet(const LSET &aLayers) override
void SetPadToDieLength(int aLength)
int GetPadToDieLength() const
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
wxString GetDuplicates() const
Gets a formatted string of all the pins that have duplicate numbers.
void insert(value_type const &v)
wxString GetSummary() const
A pure virtual class used to derive REPORTER objects from.
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.
A wrapper for reporting to a wxString object.
static void UpdateDrillCells(WX_GRID &aGrid, UNITS_PROVIDER &aUnitsProvider, int aRowId, const PAD &aPad, bool aPreserveValues)
Update the drill size cells in the pad table for a given pad.
static COLS GetColTypeForString(const wxString &aStr)
static wxString GetPadTableColLabel(COLS aCol)
Get the label for a given column in the pin table.
static wxString GetPadTypeString(const PAD &aPad)
static PAD_SHAPE ShapeFromString(const wxString &shape)
static bool DrillsAreEditable(const PAD &aPad)
static wxString ShapeToString(PAD_SHAPE shape)
static void SetPadTypeFromString(PAD &aPad, const wxString &aType)
DIALOG_FP_EDIT_PAD_TABLE::COLS COLS
static COL_ORDER GetColTypeForString(const wxString &aStr)
static std::map< int, wxString > shapeNames
static const std::string CsvFileExtension
static wxString CsvTsvFileWildcard()
PCB_LAYER_ID
A quick note on layer IDs:
@ REPAINT
Item needs to be redrawn.
@ LAYERS
Layers have changed.
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
wxString GetPadAttributeString(PAD_ATTRIB aAttrib)
Get the human-readable string for a pad attribute.
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
void AccumulateDescriptions(wxString &aDesc, const T &aItemCollection)
Build a comma-separated list from a collection of wxStrings.
void WriteTableToFileOrClipboard(const wxString &aToFile, const std::vector< std::vector< wxString > > &aTable)
Write aTable as CSV to aToFile (if non-empty) or to the system clipboard.
std::optional< std::vector< std::vector< wxString > > > ReadTableFromFileOrClipboard(EDA_BASE_FRAME &aFrame, bool aFromFile)
Read a CSV/TSV table from a file selected via a dialog (aFromFile) or from the system clipboard.
DATABASE_CONNECTION dc(odbcBackend(cs))
IbisParser parser & reporter
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.