KiCad PCB EDA Suite
dialog_board_reannotate.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 (C) 2020 Brian Piccioni [email protected]
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Brian Piccioni <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef DIALOG_BOARD_REANNOTATE_H_
27 #define DIALOG_BOARD_REANNOTATE_H_
28 
29 #include <board.h>
30 #include <footprint.h>
32 #include <layer_ids.h>
34 #include <pcb_base_frame.h>
35 #include <pcb_edit_frame.h>
36 #include <project.h>
37 #include <wx_html_report_panel.h>
38 
39 #include <frame_type.h>
40 #include <tool/actions.h>
41 #include <tool/tool_manager.h>
43 
44 #define SORTXFIRST 0b000 // Sort on X
45 #define SORTYFIRST 0b100 // Sort on Y
46 #define ASCENDINGFIRST 0b000 // Sort low to high
47 #define DESCENDINGFIRST 0b010 // Sort high to low
48 #define ASCENDINGSECOND 0b000 // Sort low to high
49 #define DESCENDINGSECOND 0b001 // Sort high to low
50 
51 #define MINGRID 1000
52 #define MAXERROR 10
53 #define VALIDPREFIX "_-+=/\\" // Prefixs can be alpha or these symbols
54 
56 {
61 };
62 
64 {
69 };
70 
72 {
74  wxString NewRefDes; // The new reference designation (F_U21)
75  wxString OldRefDesString; // What the old refdes preamble + number was
76  bool Front; // True if on the front of the board
77  ActionCode Action; // Used to skip (if #, etc)
78 };
79 
80 struct RefDesInfo
81 {
83  bool Front; // True if on the front of the board
84  wxString RefDesString; // What its refdes is R1, C2
85  wxString RefDesType; // ie R, C, etc
86  int x, y; // The coordinates
87  int roundedx, roundedy; // The coordinates after rounding.
88  ActionCode Action; // Used to skip (if #, etc)
90 };
91 
93 {
94  wxString RefDesType;
95  unsigned int LastUsedRefDes;
96  std::set<unsigned int> UnavailableRefs;
97 };
98 
99 
101 {
102 public:
103  DIALOG_BOARD_REANNOTATE( PCB_EDIT_FRAME* aParentFrame );
105 
106 private:
107  std::vector<wxRadioButton*> m_sortButtons = {
108  m_Down_Right,
109  m_Right_Down,
110  m_Down_Left,
111  m_Left_Down,
112  m_Up_Right,
113  m_Right_Up,
114  m_Up_Left,
115  m_Left_Up
116  };
117 
118  std::vector<wxRadioButton*> AnnotateWhat = {
123  };
124 
125  std::vector<wxStaticBitmap*> Bitmaps = {
134  };
135 
136  void GetParameters( void );
137 
139  void InitValues( void );
140 
141  void OnApplyClick( wxCommandEvent& event ) override;
142  void OnCloseClick( wxCommandEvent& event ) override;
143  void FilterFrontPrefix( wxCommandEvent& event ) override;
144  void FilterBackPrefix( wxCommandEvent& event ) override;
145 
147  void ShowReport( const wxString& aMessage, SEVERITY aSeverity );
148 
150  void LogFootprints( const wxString& aMessage, const std::vector<RefDesInfo>& aFootprints );
151 
153  void LogChangePlan( void );
154 
157  bool ReannotateBoard( void );
158 
161  bool BuildFootprintList( std::vector<RefDesInfo>& aBadRefDes );
162 
165 
167  void BuildChangeArray( std::vector<RefDesInfo>& aFootprints, unsigned int aStartRefDes,
168  const wxString& aPrefix, bool aRemovePrefix,
169  std::vector<RefDesInfo>& aBadRefDes );
170 
172  RefDesChange* GetNewRefDes( FOOTPRINT* aFootprint );
173 
175  int RoundToGrid( int aCoord, int aGrid );
176 
179  wxString CoordTowxString( int aX, int aY );
180 
182  void MakeSampleText( wxString& aMessage );
183 
185  void FilterPrefix( wxTextCtrl* aPrefix );
186 
189  RefDesTypeStr* GetOrBuildRefDesInfo( const wxString& aRefDesPrefix, unsigned int aStartRefDes = 0 );
190 
192  FOOTPRINTS m_footprints;
194 
195  std::vector<RefDesChange> m_changeArray;
196  std::vector<RefDesInfo> m_frontFootprints;
197  std::vector<RefDesInfo> m_backFootprints;
198  std::vector<RefDesTypeStr> m_refDesTypes;
199  std::vector<wxString> m_excludeArray;
200 
205 
206  double m_sortGridx;
207  double m_sortGridy;
208 
211  wxString m_validPrefixes;
212 
214 
216 };
217 
218 #endif /* DIALOG_BOARD_REANNOTATECLASSES_H_ */
bool ReannotateBoard(void)
Actually reannotate the board.
std::vector< wxRadioButton * > m_sortButtons
Class DIALOG_BOARD_REANNOTATE_BASE.
void FilterPrefix(wxTextCtrl *aPrefix)
Check to make sure the prefix (if there is one) is properly constructed.
void FilterBackPrefix(wxCommandEvent &event) override
void LogFootprints(const wxString &aMessage, const std::vector< RefDesInfo > &aFootprints)
Create a list of the footprints and their coordinates.
bool BuildFootprintList(std::vector< RefDesInfo > &aBadRefDes)
Build the footprint lists, sort it, filter for excludes, then build the change list.
DIALOG_BOARD_REANNOTATE(PCB_EDIT_FRAME *aParentFrame)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
Classes used in Pcbnew, CvPcb and GerbView.
std::vector< wxString > m_excludeArray
void ShowReport(const wxString &aMessage, SEVERITY aSeverity)
Break report into strings separated by and sent to the reporter.
RefDesChange * GetNewRefDes(FOOTPRINT *aFootprint)
std::vector< RefDesChange > m_changeArray
Definition: kiid.h:44
unsigned int LastUsedRefDes
void OnApplyClick(wxCommandEvent &event) override
std::vector< RefDesInfo > m_backFootprints
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
std::vector< RefDesInfo > m_frontFootprints
void InitValues(void)
Copy saved app settings to the dialog.
int RoundToGrid(int aCoord, int aGrid)
Round an int coordinate to a suitable grid.
std::vector< RefDesTypeStr > m_refDesTypes
SEVERITY
void OnCloseClick(wxCommandEvent &event) override
std::set< unsigned int > UnavailableRefs
void BuildUnavailableRefsList()
Build list of unavailable references. E.g. unselected footprints or locked footprints.
void FilterFrontPrefix(wxCommandEvent &event) override
RefDesTypeStr * GetOrBuildRefDesInfo(const wxString &aRefDesPrefix, unsigned int aStartRefDes=0)
Get the structure representing the information currently held for aRefDesPrefix or create one if it d...
wxString CoordTowxString(int aX, int aY)
Convert coordinates to wxString.
void BuildChangeArray(std::vector< RefDesInfo > &aFootprints, unsigned int aStartRefDes, const wxString &aPrefix, bool aRemovePrefix, std::vector< RefDesInfo > &aBadRefDes)
Scan through the footprint arrays and create the from -> to array.
The main frame for Pcbnew.
std::vector< wxRadioButton * > AnnotateWhat
void LogChangePlan(void)
Create an audit trail of the changes.
std::vector< wxStaticBitmap * > Bitmaps
void MakeSampleText(wxString &aMessage)
Make the text to summarize what is about to happen.