40#include <wx/valtext.h>
77#define SetSortCodes( DirArray, Code ) \
79 SortYFirst = ( ( DirArray[Code] & SORTYFIRST ) != 0 ); \
80 DescendingFirst = ( ( DirArray[Code] & DESCENDINGFIRST ) != 0 ); \
81 DescendingSecond = ( ( DirArray[Code] & DESCENDINGSECOND ) != 0 ); \
103 m_footprints( aParentFrame->
GetBoard()->Footprints() )
127 wxArrayString gridslist;
144 button->SetValue(
false );
156 button->SetValue(
false );
217 EndDialog( wxID_OK );
225 if( aPrefix->GetValue().empty() )
228 char lastc = aPrefix->GetValue().Last();
230 if( isalnum( (
int) lastc ) )
233 if( std::string::npos != tmps.find( lastc ) )
236 tmps = aPrefix->GetValue();
239 aPrefix->AppendText( tmps );
244 unsigned int aStartRefDes )
246 unsigned int requiredLastRef = ( aStartRefDes == 0 ? 1 : aStartRefDes ) - 1;
300 ShowReport(
_(
"PCB annotation changes should be synchronized with schematic using "
313 aMessage.Printf(
_(
"\n%s footprints will be reannotated." ),
318 aMessage += wxString::Format(
_(
"\nAny reference types %s will not be annotated." ),
323 aMessage += wxString::Format(
_(
"\nLocked footprints will not be annotated" ) );
327 aMessage += wxString::Format(
_(
"\nFront footprints will start at %s" ),
336 aMessage += wxString::Format(
_(
"\nBack footprints will start at %s." ),
337 frontPlusOne ?
_(
"the last front footprint + 1" ) :
345 aMessage += wxString::Format(
_(
"\nFront footprints starting with '%s' will have "
346 "the prefix removed." ),
351 aMessage += wxString::Format(
_(
"\nFront footprints will have '%s' inserted as a "
361 aMessage += wxString::Format(
_(
"\nBack footprints starting with '%s' will have the "
367 aMessage += wxString::Format(
_(
"\nBack footprints will have '%s' inserted as a "
375 aMessage += wxString::Format(
_(
"\nPrior to sorting by %s, the coordinates of which will be "
376 "rounded to a %s, %s grid." ),
377 fpLocation ?
_(
"footprint location" )
378 :
_(
"reference designator location" ),
392 if( sortbuttons->GetValue() )
416 if( button->GetValue() )
436 rounder = aCoord % aGrid;
439 if( abs( rounder ) > ( aGrid / 2 ) )
440 aCoord += ( aCoord < 0 ? -aGrid : aGrid );
488 return wxString::Format( wxT(
"%s, %s" ),
496 wxStringTokenizer msgs( aMessage, wxT(
"\n" ) );
498 while( msgs.HasMoreTokens() )
510 message.Printf(
_(
"\n\nThere are %i types of reference designations\n"
511 "**********************************************************\n" ),
515 message += Type.RefDesType + ( 0 == ( i++ % 16 ) ? wxT(
"\n" ) : wxS(
" " ) );
522 excludes += exclude + wxS(
" " );
524 message += wxString::Format(
_(
"\nExcluding: %s from reannotation\n\n" ), excludes );
527 message +=
_(
"\n Change Array\n***********************\n" );
531 message += wxString::Format( wxT(
"%s -> %s %s %s\n" ),
532 change.OldRefDesString,
536 : wxString( wxT(
"" ) ) );
544 const std::vector<REFDES_INFO>& aFootprints )
546 wxString message = aMessage;
548 if( aFootprints.empty() )
549 message +=
_(
"\nNo footprints" );
555 message += wxString::Format(
_(
"\n*********** Sort on %s ***********" ),
556 fpLocations ?
_(
"Footprint Coordinates" )
557 :
_(
"Reference Designator Coordinates" ) );
559 message += wxString::Format(
_(
"\nSort Code %d" ),
m_sortCode );
563 message += wxString::Format(
_(
"\n%d %s UUID: [%s], X, Y: %s, Rounded X, Y, %s" ),
578 std::vector<REFDES_INFO> BadRefDes;
579 wxString message, badrefdes;
586 ShowReport(
_(
"Selected options resulted in errors! Change them and try again." ),
591 if( !BadRefDes.empty() )
593 message.Printf(
_(
"\nPCB has %d empty or invalid reference designations."
594 "\nRecommend running DRC with 'Test for parity between PCB and "
595 "schematic' checked.\n" ),
596 (
int) BadRefDes.size() );
600 badrefdes += wxString::Format(
_(
"\nRefDes: %s Footprint: %s:%s at %s on PCB." ),
602 mod.FPID.GetLibNickname().wx_str(),
603 mod.FPID.GetLibItemName().wx_str(),
608 message +=
_(
"Reannotate anyway?" );
620 if(
nullptr == newref )
623 commit.
Modify( footprint );
624 footprint->SetReference( newref->
NewRefDes );
628 commit.
Push( wxT(
"Geographic reannotation" ) );
648 std::vector<KIID> selected;
650 if( annotateSelected )
656 selected.push_back( item->m_Uuid );
665 if( (
' ' == thischar ) || (
',' == thischar ) )
673 if( !exclude.empty() )
682 fpData.
Uuid = footprint->m_Uuid;
684 fpData.
FPID = footprint->GetFPID();
685 fpData.
x = useModuleLocation ? footprint->GetPosition().x
686 : footprint->Reference().GetPosition().x;
687 fpData.
y = useModuleLocation ? footprint->GetPosition().y
688 : footprint->Reference().GetPosition().y;
691 fpData.
Front = footprint->GetLayer() ==
F_Cu;
700 firstnum = fpData.
RefDesString.find_first_of( wxT(
"0123456789" ) );
702 if( std::string::npos == firstnum )
718 if(( fpData.
Front && annotateBack ) ||
719 ( !fpData.
Front && annotateFront ) ||
720 ( footprint->IsLocked() && skipLocked ) )
725 if( annotateSelected )
729 for(
KIID sel : selected )
731 if( fpData.
Uuid == sel )
781 for(
size_t i = 0; i < changearraysize; i++ )
786 for(
size_t j = i + 1; j < changearraysize; j++ )
790 ShowReport( wxString::Format(
_(
"Duplicate instances of %s" ),
807 return ( 0 == errorcount );
812 std::vector<REFDES_INFO> excludedFootprints;
817 excludedFootprints.push_back( fpData );
823 excludedFootprints.push_back( fpData );
838 unsigned int aStartRefDes,
const wxString& aPrefix,
840 std::vector<REFDES_INFO>& aBadRefDes )
842 size_t prefixsize = aPrefix.size();
844 bool haveprefix = ( 0 != prefixsize );
845 bool addprefix = haveprefix & !aRemovePrefix;
846 aRemovePrefix &= haveprefix;
850 wxString logstring = ( aFootprints.front().Front ) ?
_(
"\n\nFront Footprints" )
851 :
_(
"\n\nBack Footprints" );
854 if( 0 != aStartRefDes )
865 change.
Uuid = fpData.Uuid;
866 change.
Action = fpData.Action;
869 change.
Front = fpData.Front;
871 if( fpData.RefDesString.IsEmpty() )
877 aBadRefDes.push_back( fpData );
883 prefixpresent = ( 0 == fpData.RefDesType.find( aPrefix ) );
885 if( addprefix && !prefixpresent )
886 fpData.RefDesType.insert( 0, aPrefix );
888 if( aRemovePrefix && prefixpresent )
889 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[]
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