42#include <wx/valtext.h>
79#define SetSortCodes( DirArray, Code ) \
81 SortYFirst = ( ( DirArray[Code] & SORTYFIRST ) != 0 ); \
82 DescendingFirst = ( ( DirArray[Code] & DESCENDINGFIRST ) != 0 ); \
83 DescendingSecond = ( ( DirArray[Code] & DESCENDINGSECOND ) != 0 ); \
105 m_footprints( aParentFrame->
GetBoard()->Footprints() )
129 wxArrayString gridslist;
146 button->SetValue(
false );
158 button->SetValue(
false );
182 catch(
const std::runtime_error& e )
184 wxFAIL_MSG( e.what() );
233 EndDialog( wxID_OK );
241 if( aPrefix->GetValue().empty() )
244 char lastc = aPrefix->GetValue().Last();
246 if( isalnum( (
int) lastc ) )
249 if( tmps.find( lastc ) != std::string::npos )
252 tmps = aPrefix->GetValue();
255 aPrefix->AppendText( tmps );
260 unsigned int aStartRefDes )
262 unsigned int requiredLastRef = ( aStartRefDes == 0 ? 1 : aStartRefDes ) - 1;
316 ShowReport(
_(
"PCB annotation changes should be synchronized with schematic using "
329 aMessage.Printf(
_(
"\n%s footprints will be reannotated." ),
334 aMessage += wxString::Format(
_(
"\nAny reference types %s will not be annotated." ),
339 aMessage += wxString::Format(
_(
"\nLocked footprints will not be annotated" ) );
343 aMessage += wxString::Format(
_(
"\nFront footprints will start at %s" ),
352 aMessage += wxString::Format(
_(
"\nBack footprints will start at %s." ),
353 frontPlusOne ?
_(
"the last front footprint + 1" ) :
361 aMessage += wxString::Format(
_(
"\nFront footprints starting with '%s' will have "
362 "the prefix removed." ),
367 aMessage += wxString::Format(
_(
"\nFront footprints will have '%s' inserted as a "
377 aMessage += wxString::Format(
_(
"\nBack footprints starting with '%s' will have the "
383 aMessage += wxString::Format(
_(
"\nBack footprints will have '%s' inserted as a "
391 aMessage += wxString::Format(
_(
"\nPrior to sorting by %s, the coordinates of which will be "
392 "rounded to a %s, %s grid." ),
393 fpLocation ?
_(
"footprint location" )
394 :
_(
"reference designator location" ),
408 if( sortbuttons->GetValue() )
432 if( button->GetValue() )
452 rounder = aCoord % aGrid;
455 if( abs( rounder ) > ( aGrid / 2 ) )
456 aCoord += ( aCoord < 0 ? -aGrid : aGrid );
504 return wxString::Format( wxT(
"%s, %s" ),
512 wxStringTokenizer msgs( aMessage, wxT(
"\n" ) );
514 while( msgs.HasMoreTokens() )
526 message.Printf(
_(
"\n\nThere are %i types of reference designations\n"
527 "**********************************************************\n" ),
531 message += Type.RefDesType + ( 0 == ( i++ % 16 ) ? wxT(
"\n" ) : wxS(
" " ) );
538 excludes += exclude + wxS(
" " );
540 message += wxString::Format(
_(
"\nExcluding: %s from reannotation\n\n" ), excludes );
543 message +=
_(
"\n Change Array\n***********************\n" );
547 message += wxString::Format( wxT(
"%s -> %s %s %s\n" ),
548 change.OldRefDesString,
552 : wxString( wxT(
"" ) ) );
560 const std::vector<REFDES_INFO>& aFootprints )
562 wxString message = aMessage;
564 if( aFootprints.empty() )
565 message +=
_(
"\nNo footprints" );
571 message += wxString::Format(
_(
"\n*********** Sort on %s ***********" ),
572 fpLocations ?
_(
"Footprint Coordinates" )
573 :
_(
"Reference Designator Coordinates" ) );
575 message += wxString::Format(
_(
"\nSort Code %d" ),
m_sortCode );
579 message += wxString::Format(
_(
"\n%d %s UUID: [%s], X, Y: %s, Rounded X, Y, %s" ),
594 std::vector<REFDES_INFO> BadRefDes;
595 wxString message, badrefdes;
602 ShowReport(
_(
"Selected options resulted in errors! Change them and try again." ),
607 if( !BadRefDes.empty() )
609 message.Printf(
_(
"\nPCB has %d empty or invalid reference designations."
610 "\nRecommend running DRC with 'Test for parity between PCB and "
611 "schematic' checked.\n" ),
612 (
int) BadRefDes.size() );
616 badrefdes += wxString::Format(
_(
"\nRefDes: %s Footprint: %s:%s at %s on PCB." ),
618 mod.FPID.GetLibNickname().wx_str(),
619 mod.FPID.GetLibItemName().wx_str(),
624 message +=
_(
"Reannotate anyway?" );
636 if(
nullptr == newref )
639 commit.
Modify( footprint );
640 footprint->SetReference( newref->
NewRefDes );
644 commit.
Push(
_(
"Annotation" ) );
664 std::vector<KIID> selected;
666 if( annotateSelected )
672 selected.push_back( item->m_Uuid );
681 if( (
' ' == thischar ) || (
',' == thischar ) )
689 if( !exclude.empty() )
698 fpData.
Uuid = footprint->m_Uuid;
700 fpData.
FPID = footprint->GetFPID();
701 fpData.
x = useModuleLocation ? footprint->GetPosition().x
702 : footprint->Reference().GetPosition().x;
703 fpData.
y = useModuleLocation ? footprint->GetPosition().y
704 : footprint->Reference().GetPosition().y;
707 fpData.
Front = footprint->GetLayer() ==
F_Cu;
716 firstnum = fpData.
RefDesString.find_first_of( wxT(
"0123456789" ) );
718 if( std::string::npos == firstnum )
734 if(( fpData.
Front && annotateBack ) ||
735 ( !fpData.
Front && annotateFront ) ||
736 ( footprint->IsLocked() && skipLocked ) )
741 if( annotateSelected )
745 for(
KIID sel : selected )
747 if( fpData.
Uuid == sel )
797 for(
size_t i = 0; i < changearraysize; i++ )
802 for(
size_t j = i + 1; j < changearraysize; j++ )
806 ShowReport( wxString::Format(
_(
"Duplicate instances of %s" ),
823 return ( 0 == errorcount );
828 std::vector<REFDES_INFO> excludedFootprints;
833 excludedFootprints.push_back( fpData );
839 excludedFootprints.push_back( fpData );
854 unsigned int aStartRefDes,
const wxString& aPrefix,
856 std::vector<REFDES_INFO>& aBadRefDes )
858 size_t prefixsize = aPrefix.size();
860 bool haveprefix = ( 0 != prefixsize );
861 bool addprefix = haveprefix & !aRemovePrefix;
862 aRemovePrefix &= haveprefix;
866 wxString logstring = ( aFootprints.front().Front ) ?
_(
"\n\nFront Footprints" )
867 :
_(
"\n\nBack Footprints" );
870 if( 0 != aStartRefDes )
881 change.
Uuid = fpData.Uuid;
882 change.
Action = fpData.Action;
885 change.
Front = fpData.Front;
887 if( fpData.RefDesString.IsEmpty() )
893 aBadRefDes.push_back( fpData );
899 prefixpresent = ( fpData.RefDesType.find( aPrefix ) == 0 );
901 if( addprefix && !prefixpresent )
902 fpData.RefDesType.insert( 0, aPrefix );
904 if( aRemovePrefix && prefixpresent )
905 fpData.RefDesType.erase( 0, prefixsize );
constexpr EDA_IU_SCALE pcbIUScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
const FOOTPRINTS & Footprints() const
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Class DIALOG_BOARD_REANNOTATE_BASE.
wxTextCtrl * m_FrontRefDesStart
wxStaticBitmap * reannotate_left_up_bitmap
wxStaticBitmap * reannotate_down_right_bitmap
wxTextCtrl * m_ExcludeList
wxTextCtrl * m_FrontPrefix
WX_HTML_REPORT_PANEL * m_MessageWindow
wxTextCtrl * m_BackRefDesStart
wxStdDialogButtonSizer * m_sdbSizer
wxStaticText * m_SortGridText
wxButton * m_sdbSizerCancel
wxStaticBitmap * reannotate_right_up_bitmap
wxCheckBox * m_ExcludeLocked
wxRadioButton * m_AnnotateBack
wxStaticBitmap * reannotate_up_right_bitmap
wxRadioButton * m_AnnotateFront
wxRadioButton * m_AnnotateSelection
wxCheckBox * m_RemoveFrontPrefix
wxStaticBitmap * reannotate_right_down_bitmap
wxTextCtrl * m_BackPrefix
wxCheckBox * m_RemoveBackPrefix
wxChoice * m_locationChoice
wxStaticText * m_ExcludeListText
wxStaticBitmap * reannotate_up_left_bitmap
wxStaticBitmap * reannotate_down_left_bitmap
wxStaticBitmap * reannotate_left_down_bitmap
std::vector< REFDES_CHANGE > m_changeArray
std::vector< wxString > m_excludeArray
APP_SETTINGS_BASE * m_Config
bool BuildFootprintList(std::vector< REFDES_INFO > &aBadRefDes)
Build the footprint lists, sort it, filter for excludes, then build the change list.
std::vector< wxRadioButton * > m_scopeRadioButtons
void FilterBackPrefix(wxCommandEvent &event) override
REFDES_TYPE_STR * GetOrBuildRefDesInfo(const wxString &aRefDesPrefix, unsigned int aStartRefDes=0)
Get the structure representing the information currently held for aRefDesPrefix or create one if it d...
PCB_SELECTION m_selection
void LogFootprints(const wxString &aMessage, const std::vector< REFDES_INFO > &aFootprints)
Create a list of the footprints and their coordinates.
std::vector< REFDES_INFO > m_frontFootprints
std::vector< REFDES_TYPE_STR > m_refDesTypes
wxString CoordTowxString(int aX, int aY)
Convert coordinates to wxString.
void FilterPrefix(wxTextCtrl *aPrefix)
Check to make sure the prefix (if there is one) is properly constructed.
void BuildChangeArray(std::vector< REFDES_INFO > &aFootprints, unsigned int aStartRefDes, const wxString &aPrefix, bool aRemovePrefix, std::vector< REFDES_INFO > &aBadRefDes)
Scan through the footprint arrays and create the from -> to array.
~DIALOG_BOARD_REANNOTATE()
int RoundToGrid(int aCoord, int aGrid)
Round an int coordinate to a suitable grid.
wxString m_backPrefixString
void MakeSampleText(wxString &aMessage)
Make the text to summarize what is about to happen.
void BuildUnavailableRefsList()
Build list of unavailable references. E.g. unselected footprints or locked footprints.
wxString m_frontPrefixString
void LogChangePlan(void)
Create an audit trail of the changes.
void OnCloseClick(wxCommandEvent &event) override
REFDES_CHANGE * GetNewRefDes(FOOTPRINT *aFootprint)
bool ReannotateBoard(void)
Actually reannotate the board.
void InitValues(void)
Copy saved app settings to the dialog.
void ShowReport(const wxString &aMessage, SEVERITY aSeverity)
Break report into strings separated by and sent to the reporter.
std::vector< REFDES_INFO > m_backFootprints
DIALOG_BOARD_REANNOTATE(PCB_EDIT_FRAME *aParentFrame)
void OnApplyClick(wxCommandEvent &event) override
std::vector< wxRadioButton * > m_sortButtons
APP_SETTINGS_BASE * m_settings
void FilterFrontPrefix(wxCommandEvent &event) override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
A base class for most all the KiCad significant classes used in schematics and boards.
APP_SETTINGS_BASE * KifaceSettings() const
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...
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
DIALOG_REANNOTATE m_Reannotate
PCBNEW_SETTINGS * GetPcbNewSettings() const
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 #VIEW instance used in the panel.
The main frame for Pcbnew.
void OnModify() override
Must be called after a board change to set the modified flag.
bool Empty() const
Checks if there is anything selected.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
wxString & GetFileName(void)
void SetLazyUpdate(bool aLazyUpdate)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true,...
void SetFileName(const wxString &aReportFileName)
void Report(const wxString &aText, SEVERITY aSeverity, REPORTER::LOCATION aLocation=REPORTER::LOC_BODY)
Reports the string.
void Flush(bool aSort=false)
Set the visible severity filter.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
This file is part of the common library.
int BackDirectionsArray[]
int FrontDirectionsArray[]
static bool ModuleCompare(const REFDES_INFO &aA, const REFDES_INFO &aB)
Compare function to sort footprints.
#define SetSortCodes(DirArray, Code)
static bool ChangeArrayCompare(const REFDES_CHANGE &aA, const REFDES_CHANGE &aB)
Compare function used to compare ChangeArray element for sort.
wxString AnnotateString[]
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function DoubleValueFromString converts aTextValue to a double.
int GetRefDesNumber(const wxString &aRefDes)
Get the numeric suffix from a refdes - e.g.
Collection of utility functions for component reference designators (refdes)
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
std::vector< GRID > grids
wxString front_refdes_start
wxString back_refdes_start
wxString report_file_name
unsigned int LastUsedRefDes
std::set< unsigned int > UnavailableRefs
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint