KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_fp_edit_pad_table.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
23#include "string_utils.h"
24
25#include <memory>
26#include <vector>
27#include <pad.h>
28
29class PCB_BASE_FRAME;
30class FOOTPRINT;
31class UNITS_PROVIDER;
32
34{
35public:
36 // Column indices (after adding Type column)
52
53 DIALOG_FP_EDIT_PAD_TABLE( PCB_BASE_FRAME* aParent, FOOTPRINT* aFootprint );
55
56 bool TransferDataToWindow() override;
57 bool TransferDataFromWindow() override;
60
61private:
62 void OnSize( wxSizeEvent& aEvent ) override;
63 void OnCharHook( wxKeyEvent& aEvent ) override;
64 void OnCellChanged( wxGridEvent& aEvent ) override;
65 void OnSelectCell( wxGridEvent& aEvent ) override;
66 void OnUpdateUI( wxUpdateUIEvent& aEvent ) override;
67 void OnCancel( wxCommandEvent& aEvent ) override;
68 void OnExportButtonClick( wxCommandEvent& aEvent ) override;
69 void OnImportButtonClick( wxCommandEvent& aEvent ) override;
70 void OnAddRow( wxCommandEvent& aEvent ) override;
71 void OnDeleteRow( wxCommandEvent& aEvent ) override;
72
74
75 void updateSummary();
76 void setRowNullableEditors( int aRowId ) const;
77 void fillGridRow( int aRowId, PAD* aPad );
78
79 void setPadFromGridCell( PAD& aPad, int aRowId, COLS aCol );
81
82 PAD* getPadForRow( int aRowId ) const;
83
84private:
86
87 // Proportional resize support
88 std::vector<double> m_colProportions; // relative widths captured after init
89 std::vector<int> m_minColWidths; // initial (minimum) widths
90
107
108 void restorePadFromSnapshot( PAD& aPad, const PAD_SNAPSHOT& aSnap ) const;
109
110 // Comparison function to order the pads in the map
112 {
113 bool operator()( const PAD* a, const PAD* b ) const
114 {
115 const int cmpVal = StrNumCmp( a->GetNumber(), b->GetNumber() );
116
117 // First sort by alphanumeric ordering
118 if( cmpVal < 0 )
119 return true;
120
121 if( cmpVal > 0 )
122 return false;
123
124 // Sort by x and then y
125 if( a->GetCenter().x < b->GetCenter().x )
126 return true;
127
128 if( a->GetCenter().x > b->GetCenter().x )
129 return false;
130
131 if( a->GetCenter().y < b->GetCenter().y )
132 return true;
133
134 if( a->GetCenter().y > b->GetCenter().y )
135 return false;
136
137 // For degenerate pads, sort by raw pointer value
138 return a < b;
139 }
140 };
141
142 // Original pad data for cancel rollback, keyed by raw pointer: pad numbers
143 // can be edited in the grid, so no value-dependent ordering may be used for
144 // the key.
145 std::map<PAD*, PAD_SNAPSHOT> m_originalPads;
146
147 // Pads shown in the grid, ordered by pad number.
148 std::vector<PAD*> m_rowPads;
149
150 // Pads removed during the dialog session (by import, and later by row
151 // deletion), kept alive until the dialog is accepted or cancelled.
152 std::vector<PAD*> m_removedPads;
153
155 bool m_accepted = false;
156
158 std::unique_ptr<UNITS_PROVIDER> m_unitsProvider;
160};
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)
void setPadFromGridCell(PAD &aPad, int aRowId, COLS aCol)
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 OnSelectCell(wxGridEvent &aEvent) override
void setRowNullableEditors(int aRowId) const
void OnImportButtonClick(wxCommandEvent &aEvent) override
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
void OnSize(wxSizeEvent &aEvent) override
void restorePadFromSnapshot(PAD &aPad, const PAD_SNAPSHOT &aSnap) const
void OnCancel(wxCommandEvent &aEvent) override
std::vector< double > m_colProportions
std::unique_ptr< UNITS_PROVIDER > m_unitsProvider
void OnUpdateUI(wxUpdateUIEvent &aEvent) override
void OnAddRow(wxCommandEvent &aEvent) override
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
Definition padstack.h:156
Definition pad.h:61
const wxString & GetNumber() const
Definition pad.h:143
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pad.h:327
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
DIALOG_FP_EDIT_PAD_TABLE::COLS COLS
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition padstack.h:96
@ PTH
Plated through hole pad.
Definition padstack.h:97
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
Definition padstack.h:51
@ CHAMFERED_RECT
Definition padstack.h:59
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
bool operator()(const PAD *a, const PAD *b) const
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683