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;
538 int displayIdx = wxDisplay::GetFromWindow( aParent );
540 if( displayIdx == wxNOT_FOUND )
543 wxRect displayArea = wxDisplay( (
unsigned int) displayIdx ).GetClientArea();
544 wxSize dlgSize = GetSize();
545 int maxH = ( displayArea.height * 4 ) / 5;
547 if( dlgSize.y > maxH )
554 wxSize minSz = GetMinSize();
571 m_grid->PopEventHandler(
true );
587 if( aPad->
GetSize( aLayer ).
x != size_x )
590 if( aPad->
GetSize( aLayer ).
y != size_y )
637 m_grid->AutoSizeColumns();
660 dc.GetTextExtent( str, &w, &h );
661 maxWidth = std::max( maxWidth, w );
665 int padding = FromDIP( 30 );
674 wxSizeEvent sizeEvt( GetSize(), GetId() );
678 wxSizeEvent evt( sizeEvt );
683 if(
m_grid->GetNumberRows() > 0 )
685 m_grid->SetGridCursor( 0, 0 );
688 wxGridEvent ev(
m_grid->GetId(), wxEVT_GRID_SELECT_CELL,
m_grid, 0, 0, -1, -1,
true );
700 [
this, aRowId](
int aCol )
703 wxGridCellAttr* attr =
m_grid->GetOrCreateCellAttr( aRowId, aCol );
704 attr->SetEditor( cellEditor );
762 pad->ClearBrightened();
789 for(
PAD*
pad : livePads )
856 const wxString shape =
m_grid->GetCellValue( aRowId, aCol );
877 pos.
x =
m_grid->GetUnitValue( aRowId, aCol );
879 pos.
y =
m_grid->GetUnitValue( aRowId, aCol );
888 const wxString sizeValue =
m_grid->GetCellValue( aRowId, aCol );
893 const int size =
m_grid->GetUnitValue( aRowId, aCol );
905 aPad.
SetSize( aLayer, layerSize );
919 if( drillX > 0 || drillY > 0 )
936 const wxString lenStr =
m_grid->GetCellValue( aRowId, aCol );
938 if( lenStr.IsEmpty() )
948 const wxString delayStr =
m_grid->GetCellValue( aRowId, aCol );
950 if( delayStr.IsEmpty() )
959 wxFAIL_MSG( wxT(
"Invalid column index" ) );
967 if( !
m_grid->CommitPendingChanges() )
1008 const auto applyRowDataToPad =
1009 [&](
PAD& aPad,
int aRowId )
1011 for(
int col = 0; col <
m_grid->GetNumberCols(); ++col )
1022 applyRowDataToPad( *
pad, row );
1029 applyRowDataToPad( *
pad, row );
1042 commit.
Push(
_(
"Edit Pads" ) );
1060 int cols =
m_grid->GetNumberCols();
1062 std::vector<int> widths;
1063 widths.reserve( cols );
1065 for(
int c = 0; c < cols; ++c )
1067 int w =
m_grid->GetColSize( c );
1068 widths.push_back( w );
1075 for(
int w : widths )
1092 int cols =
m_grid->GetNumberCols();
1095 for(
int c = 0; c < cols; ++c )
1096 available +=
m_grid->GetColSize( c );
1099 int clientW =
m_grid->GetClientSize().x;
1102 available = clientW;
1106 for(
int c = 0; c < cols; ++c )
1115 m_grid->SetColSize( c, target );
1134 int row = aEvent.GetRow();
1135 int col = aEvent.GetCol();
1146 bool needCanvasRefresh =
true;
1154 if( drillsAreEditable )
1162 if( drillX > 0 || drillY > 0 )
1166 else if( !drillsWereEditable )
1170 const int defaultDrill =
pcbIUScale.mmToIU( 1.0 );
1171 target->
SetDrillSize( { defaultDrill, defaultDrill } );
1180 needCanvasRefresh =
false;
1189 if( needCanvasRefresh )
1199 base->GetCanvas()->ForceRefresh();
1207 int row = aEvent.GetRow();
1218 if(
pad->IsBrightened() )
1220 pad->ClearBrightened();
1232 pad->SetBrightened();
1248 int row =
m_grid->GetGridCursorRow();
1249 int col =
m_grid->GetGridCursorCol();
1256 wxGridCellEditor*
editor =
m_grid->GetCellEditor( row, col );
1285 if(
pad->GetNumber().Length() )
1289 const wxString summary = pinNumbers.
GetSummary();
1304 if( aRowId < 0 ||
static_cast<size_t>( aRowId ) >=
m_rowPads.size() )
1319 wxFileName fn(
m_footprint->GetFPID().GetLibItemName() );
1323 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1327 if( dlg.ShowModal() == wxID_CANCEL )
1330 filePath = dlg.GetPath();
1333 std::vector<PAD*> padsToExport;
1334 bool complexPadstacks =
false;
1340 complexPadstacks =
true;
1344 padsToExport.push_back(
pad );
1347 if( complexPadstacks )
1349 if( wxMessageBox(
_(
"Complex padstacks cannot be exported via CSV.\n\nThey will be skipped." ),
1350 _(
"Export Pad Table" ), wxOK | wxCANCEL | wxICON_WARNING,
this ) != wxOK )
1356 static const std::vector<COLS> exportCols {
1366 COLS::COL_P2D_LENGTH,
1367 COLS::COL_P2D_DELAY,
1373 std::vector<std::vector<wxString>>
table;
1374 table.reserve( padsToExport.size() + 1 );
1376 std::vector<wxString> header;
1377 header.reserve( exportCols.size() );
1379 for(
COLS col : exportCols )
1382 table.emplace_back( std::move( header ) );
1384 for(
PAD*
pad : padsToExport )
1386 std::vector<wxString>& row =
table.emplace_back();
1387 row.reserve( exportCols.size() );
1389 for(
COLS col : exportCols )
1390 row.emplace_back( formatter.
Format( *
pad, col ) );
1419 std::map<wxString, std::vector<PAD*>> padsByNumber;
1422 padsByNumber[
pad->GetNumber()].push_back(
pad );
1428 std::vector<std::unique_ptr<PAD>> createdPads;
1430 if( csvData && csvData->size() >= 2 )
1432 std::vector<COLS> headerCols;
1433 wxArrayString unknownHeaders;
1434 std::optional<size_t> numberColIdx;
1436 for(
const wxString& label : ( *csvData )[0] )
1440 if( col >= COLS::COL_COUNT )
1441 unknownHeaders.push_back( label );
1443 if( col == COLS::COL_NUMBER )
1444 numberColIdx = headerCols.size();
1446 headerCols.push_back( col );
1449 if( replaceAll && !numberColIdx.has_value() )
1451 wxString msg =
_(
"Imported pad data must include pad numbers." );
1452 wxMessageBox( msg,
_(
"Import error" ), wxOK | wxICON_ERROR,
this );
1456 if( !unknownHeaders.IsEmpty() )
1458 wxString msg = wxString::Format(
_(
"Unknown columns in data: %s. These columns will be ignored." ),
1465 int ret = wxMessageBox(
reporter.GetMessages(),
_(
"Errors" ), wxOK | wxCANCEL | wxICON_ERROR,
this );
1467 if( ret == wxCANCEL )
1471 for(
size_t i = 1; i < csvData->size(); ++i )
1473 const std::vector<wxString>& cols = ( *csvData )[i];
1477 std::unique_ptr<PAD> newPad;
1478 PAD* padToUpdate =
nullptr;
1480 const size_t numberCol = numberColIdx.value_or( cols.size() );
1482 if( replaceAll && numberCol < cols.size() && !cols[numberCol].IsEmpty() )
1484 auto bucketIt = padsByNumber.find( cols[numberCol] );
1486 if( bucketIt != padsByNumber.end() && !bucketIt->second.empty() )
1488 padToUpdate = bucketIt->second.front();
1489 bucketIt->second.erase( bucketIt->second.begin() );
1497 padToUpdate = newPad.get();
1500 size_t maxCol = std::min( headerCols.size(), cols.size() );
1502 for(
size_t j = 0; j < maxCol; ++j )
1504 if( headerCols[j] == COLS::COL_COUNT )
1507 fmt.
UpdatePad( *padToUpdate, cols[j], headerCols[j] );
1519 createdPads.push_back( std::move( newPad ) );
1523 if( !createdPads.empty() )
1527 std::vector<KIGFX::VIEW_ITEM*> viewPads;
1529 for(
const auto&
pad : createdPads )
1530 viewPads.push_back(
pad.get() );
1535 for( std::unique_ptr<PAD>&
pad : createdPads )
1544 for(
const auto& [number, pads] : padsByNumber )
1561 m_grid->CommitPendingChanges();
1572 int currentRows =
m_grid->GetNumberRows();
1573 int neededRows =
static_cast<int>(
m_rowPads.size() );
1575 if( neededRows > currentRows )
1576 m_grid->AppendRows( neededRows - currentRows );
1577 else if( neededRows < currentRows )
1578 m_grid->DeleteRows( neededRows, currentRows - neededRows );
1598 [&]() -> std::pair<int, int>
1600 PAD* newPad =
nullptr;
1606 newPad =
static_cast<PAD*
>(
m_rowPads.back()->Duplicate(
false,
nullptr ) );
1615 view->
Add( newPad );
1620 int row =
m_grid->GetNumberRows();
1645 if( row < 0 ||
static_cast<size_t>( row ) >=
m_rowPads.size() )
1650 pad->ClearBrightened();
1661 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.
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.