39#include <wx/valtext.h>
76#define SetSortCodes( DirArray, Code ) \
78 SortYFirst = ( ( DirArray[Code] & SORTYFIRST ) != 0 ); \
79 DescendingFirst = ( ( DirArray[Code] & DESCENDINGFIRST ) != 0 ); \
80 DescendingSecond = ( ( DirArray[Code] & DESCENDINGSECOND ) != 0 ); \
102 m_footprints( aParentFrame->
GetBoard()->Footprints() )
126 wxArrayString gridslist;
143 button->SetValue(
false );
155 button->SetValue(
false );
216 EndDialog( wxID_OK );
224 if( aPrefix->GetValue().empty() )
227 char lastc = aPrefix->GetValue().Last();
229 if( isalnum( (
int) lastc ) )
232 if( std::string::npos != tmps.find( lastc ) )
235 tmps = aPrefix->GetValue();
238 aPrefix->AppendText( tmps );
243 unsigned int aStartRefDes )
245 unsigned int requiredLastRef = ( aStartRefDes == 0 ? 1 : aStartRefDes ) - 1;
299 ShowReport(
_(
"PCB annotation changes should be synchronized with schematic using "
312 aMessage.Printf(
_(
"\n%s footprints will be reannotated." ),
317 aMessage += wxString::Format(
_(
"\nAny reference types %s will not be annotated." ),
322 aMessage += wxString::Format(
_(
"\nLocked footprints will not be annotated" ) );
326 aMessage += wxString::Format(
_(
"\nFront footprints will start at %s" ),
335 aMessage += wxString::Format(
_(
"\nBack footprints will start at %s." ),
336 frontPlusOne ?
_(
"the last front footprint + 1" ) :
344 aMessage += wxString::Format(
_(
"\nFront footprints starting with '%s' will have "
345 "the prefix removed." ),
350 aMessage += wxString::Format(
_(
"\nFront footprints will have '%s' inserted as a "
360 aMessage += wxString::Format(
_(
"\nBack footprints starting with '%s' will have the "
366 aMessage += wxString::Format(
_(
"\nBack footprints will have '%s' inserted as a "
374 aMessage += wxString::Format(
_(
"\nPrior to sorting by %s, the coordinates of which will be "
375 "rounded to a %s, %s grid." ),
376 fpLocation ?
_(
"footprint location" )
377 :
_(
"reference designator location" ),
391 if( sortbuttons->GetValue() )
424 if( button->GetValue() )
444 rounder = aCoord % aGrid;
447 if( abs( rounder ) > ( aGrid / 2 ) )
448 aCoord += ( aCoord < 0 ? -aGrid : aGrid );
496 return wxString::Format( wxT(
"%s, %s" ),
504 wxStringTokenizer msgs( aMessage, wxT(
"\n" ) );
506 while( msgs.HasMoreTokens() )
518 message.Printf(
_(
"\n\nThere are %i types of reference designations\n"
519 "**********************************************************\n" ),
523 message += Type.RefDesType + ( 0 == ( i++ % 16 ) ? wxT(
"\n" ) : wxS(
" " ) );
530 excludes += exclude + wxS(
" " );
532 message += wxString::Format(
_(
"\nExcluding: %s from reannotation\n\n" ), excludes );
535 message +=
_(
"\n Change Array\n***********************\n" );
539 message += wxString::Format( wxT(
"%s -> %s %s %s\n" ),
540 change.OldRefDesString,
544 : wxString( wxT(
"" ) ) );
552 const std::vector<REFDES_INFO>& aFootprints )
554 wxString message = aMessage;
556 if( aFootprints.empty() )
557 message +=
_(
"\nNo footprints" );
563 message += wxString::Format(
_(
"\n*********** Sort on %s ***********" ),
564 fpLocations ?
_(
"Footprint Coordinates" )
565 :
_(
"Reference Designator Coordinates" ) );
567 message += wxString::Format(
_(
"\nSort Code %d" ),
m_sortCode );
571 message += wxString::Format(
_(
"\n%d %s UUID: [%s], X, Y: %s, Rounded X, Y, %s" ),
586 std::vector<REFDES_INFO> BadRefDes;
587 wxString message, badrefdes;
594 ShowReport(
_(
"Selected options resulted in errors! Change them and try again." ),
599 if( !BadRefDes.empty() )
601 message.Printf(
_(
"\nPCB has %d empty or invalid reference designations."
602 "\nRecommend running DRC with 'Test for parity between PCB and "
603 "schematic' checked.\n" ),
604 (
int) BadRefDes.size() );
608 badrefdes += wxString::Format(
_(
"\nRefDes: %s Footprint: %s:%s at %s on PCB." ),
610 mod.FPID.GetLibNickname().wx_str(),
611 mod.FPID.GetLibItemName().wx_str(),
616 message +=
_(
"Reannotate anyway?" );
628 if(
nullptr == newref )
631 commit.
Modify( footprint );
632 footprint->SetReference( newref->
NewRefDes );
636 commit.
Push( wxT(
"Geographic reannotation" ) );
656 std::vector<KIID> selected;
658 if( annotateSelected )
664 selected.push_back( item->m_Uuid );
673 if( (
' ' == thischar ) || (
',' == thischar ) )
681 if( !exclude.empty() )
690 fpData.
Uuid = footprint->m_Uuid;
692 fpData.
FPID = footprint->GetFPID();
693 fpData.
x = useModuleLocation ? footprint->GetPosition().x
694 : footprint->Reference().GetPosition().x;
695 fpData.
y = useModuleLocation ? footprint->GetPosition().y
696 : footprint->Reference().GetPosition().y;
699 fpData.
Front = footprint->GetLayer() ==
F_Cu;
708 firstnum = fpData.
RefDesString.find_first_of( wxT(
"0123456789" ) );
710 if( std::string::npos == firstnum )
726 if(( fpData.
Front && annotateBack ) ||
727 ( !fpData.
Front && annotateFront ) ||
728 ( footprint->IsLocked() && skipLocked ) )
733 if( annotateSelected )
737 for(
KIID sel : selected )
739 if( fpData.
Uuid == sel )
789 for(
size_t i = 0; i < changearraysize; i++ )
794 for(
size_t j = i + 1; j < changearraysize; j++ )
798 ShowReport( wxString::Format(
_(
"Duplicate instances of %s" ),
815 return ( 0 == errorcount );
820 std::vector<REFDES_INFO> excludedFootprints;
825 excludedFootprints.push_back( fpData );
831 excludedFootprints.push_back( fpData );
846 unsigned int aStartRefDes,
const wxString& aPrefix,
848 std::vector<REFDES_INFO>& aBadRefDes )
850 size_t prefixsize = aPrefix.size();
852 bool haveprefix = ( 0 != prefixsize );
853 bool addprefix = haveprefix & !aRemovePrefix;
854 aRemovePrefix &= haveprefix;
858 wxString logstring = ( aFootprints.front().Front ) ?
_(
"\n\nFront Footprints" )
859 :
_(
"\n\nBack Footprints" );
862 if( 0 != aStartRefDes )
873 change.
Uuid = fpData.Uuid;
874 change.
Action = fpData.Action;
877 change.
Front = fpData.Front;
879 if( fpData.RefDesString.IsEmpty() )
885 aBadRefDes.push_back( fpData );
891 prefixpresent = ( 0 == fpData.RefDesType.find( aPrefix ) );
893 if( addprefix && !prefixpresent )
894 fpData.RefDesType.insert( 0, aPrefix );
896 if( aRemovePrefix && prefixpresent )
897 fpData.RefDesType.erase( 0, prefixsize );
constexpr EDA_IU_SCALE pcbIUScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
FOOTPRINTS & Footprints()
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)
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[]
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< wxString > sizes
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