30#include <wx/tokenzr.h>
31#include <wx/valtext.h>
83#define SetSortCodes( DirArray, Code ) \
85 g_SortYFirst = ( ( DirArray[Code] & SORTYFIRST ) != 0 ); \
86 g_DescendingFirst = ( ( DirArray[Code] & DESCENDINGFIRST ) != 0 ); \
87 g_DescendingSecond = ( ( DirArray[Code] & DESCENDINGSECOND ) != 0 ); \
94 _(
"(unannotated; not updated)" ),
118 { wxID_CANCEL,
_(
"Close" ) } } );
120 wxArrayString gridslist;
125 int gridIndex =
m_frame->config()->m_Window.grid.last_size_idx;
127 if( gridIndex >= 0 && gridIndex < (
int)
m_GridChoice->GetCount() )
143 EndDialog( wxID_OK );
151 if( !selection.
Empty() )
167 if( aPrefix->GetValue().empty() )
170 char lastc = aPrefix->GetValue().Last();
172 if( isalnum( (
int) lastc ) )
175 if( tmps.find( lastc ) != std::string::npos )
178 tmps = aPrefix->GetValue();
181 aPrefix->AppendText( tmps );
223 ShowReport(
_(
"PCB annotation changes should be synchronized with schematic using "
229 m_frame->GetCanvas()->Refresh();
240 rounder = aCoord % aGrid;
243 if( abs( rounder ) > ( aGrid / 2 ) )
244 aCoord += ( aCoord < 0 ? -aGrid : aGrid );
290 return wxT(
"<i>" ) +
_(
"unannotated footprint" ) + wxT(
"</i>" );
296 return wxT(
"<i>" ) +
_(
"unknown" ) + wxT(
"</i>" );
302 return wxString::Format( wxT(
"%s, %s" ),
303 m_frame->MessageTextFromValue( aX ),
304 m_frame->MessageTextFromValue( aY ) );
310 wxStringTokenizer msgs( aMessage,
"\n" );
312 while( msgs.HasMoreTokens() )
321 message =
_(
"Reference Designator Prefixes in Use" );
322 message += wxT(
"<br/>-------------------------------------------------------------<br/>" );
327 message +=
info.RefDesPrefix + ( ( i++ % 16 ) == 0 ? wxT(
"<br/>" ) : wxS(
" " ) );
329 message += wxT(
"<br/>" );
336 excludes += exclude + wxS(
" " );
338 message += wxString::Format(
_(
"(Excluding %s from reannotation.)" ), excludes );
343 message =
_(
"Change Log" );
344 message += wxT(
"<br/>-------------------------------------------------------------<br/>" );
350 message += wxString::Format( wxT(
"%s <i>%s</i><br/>" ),
351 change.OldRefDesString.IsEmpty() ?
empty_str() : change.OldRefDesString,
356 message += wxString::Format( wxT(
"%s -> %s<br/>" ),
357 change.OldRefDesString.IsEmpty() ?
empty_str() : change.OldRefDesString,
358 change.NewRefDes.IsEmpty() ?
empty_str() : change.NewRefDes );
368 wxString message = aFootprints.front().Front ?
_(
"Front Footprints" ) :
_(
"Back Footprints" );
372 message +=
_(
"(sorted by footprint location)" );
374 message +=
_(
"(sorted by reference designator location)" );
376 message += wxT(
"<br/>-------------------------------------------------------------" );
382 message += wxString::Format(
_(
"<br/>%d %s at %s (rounded to %s)" ),
384 fp.RefDesString.IsEmpty() ?
empty_str() : fp.RefDesString,
395 std::vector<REFDES_INFO> BadRefDes;
396 wxString message1, message2, badrefdes;
407 if( !BadRefDes.empty() )
409 message1.Printf(
_(
"PCB has %d empty or invalid reference designations." ), (
int) BadRefDes.size() );
410 message2.Printf(
_(
"You may wish to run DRC with 'Test for parity between PCB and schematic' checked." ) );
414 badrefdes += wxString::Format(
_(
"<br/> RefDes: %s; footprint: %s at %s on PCB." ),
415 mod.RefDesString.IsEmpty() ?
empty_str() : mod.RefDesString,
416 mod.FPID.IsValid() ? wxString( mod.FPID.Format().c_str() ) :
unknown_str(),
422 if( !
IsOK(
m_frame, message1 +
"\n" + message2 +
"\n \n" +
_(
"Reannotate anyway?" ) ) )
432 if(
nullptr == newref )
435 commit.
Modify( footprint );
436 footprint->SetReference( newref->
NewRefDes );
437 m_frame->GetCanvas()->GetView()->Update( footprint );
440 commit.
Push(
_(
"Annotation" ) );
464 wxStringTokenizer tokenizer(
m_ExcludeList->GetValue(),
", \t\r\n", wxTOKEN_STRTOK );
466 while( tokenizer.HasMoreTokens() )
474 fpData.
Uuid = footprint->m_Uuid;
476 fpData.
FPID = footprint->GetFPID();
477 fpData.
x = useFPLocation ? footprint->GetPosition().x
478 : footprint->Reference().GetPosition().x;
479 fpData.
y = useFPLocation ? footprint->GetPosition().y
480 : footprint->Reference().GetPosition().y;
483 fpData.
Front = footprint->GetLayer() ==
F_Cu;
492 firstnum = fpData.
RefDesString.find_first_of( wxT(
"0123456789" ) );
494 if( std::string::npos == firstnum )
504 if( excluded.EndsWith(
'*' ) )
519 if( footprint->IsLocked() && skipLocked )
521 else if( annotateSelected )
523 else if( annotateFront )
525 else if( annotateBack )
538 if( sortbuttons->GetValue() )
583 for(
size_t i = 0; i < changearraysize; i++ )
587 for(
size_t j = i + 1; j < changearraysize; j++ )
607 return ( errorcount == 0 );
612 std::vector<REFDES_INFO> excludedFootprints;
617 excludedFootprints.push_back( fpData );
623 excludedFootprints.push_back( fpData );
626 for(
const REFDES_INFO& fpData : excludedFootprints )
638 unsigned int aStartRefDes,
const wxString& aPrefix,
639 bool aRemovePrefix, std::vector<REFDES_INFO>& aBadRefDes )
641 size_t prefixsize = aPrefix.size();
643 bool haveprefix = ( 0 != prefixsize );
644 bool addprefix = haveprefix & !aRemovePrefix;
645 aRemovePrefix &= haveprefix;
651 if( aStartRefDes != 0 )
654 prefixInfo.LastUsedRefDes = aStartRefDes - 1;
661 change.
Uuid = fpData.Uuid;
662 change.
Action = fpData.Action;
665 change.
Front = fpData.Front;
667 if( fpData.RefDesString.IsEmpty() )
673 aBadRefDes.push_back( fpData );
679 prefixpresent = ( fpData.RefDesPrefix.find( aPrefix ) == 0 );
681 if( addprefix && !prefixpresent )
682 fpData.RefDesPrefix.insert( 0, aPrefix );
684 if( aRemovePrefix && prefixpresent )
685 fpData.RefDesPrefix.erase( 0, prefixsize );
constexpr EDA_IU_SCALE pcbIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
wxTextCtrl * m_FrontRefDesStart
wxStaticBitmap * reannotate_left_up_bitmap
DIALOG_BOARD_REANNOTATE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Geographical Reannotation"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxStaticBitmap * reannotate_down_right_bitmap
wxTextCtrl * m_ExcludeList
wxTextCtrl * m_FrontPrefix
WX_HTML_REPORT_PANEL * m_MessageWindow
wxTextCtrl * m_BackRefDesStart
wxStaticText * m_SortGridText
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
bool BuildFootprintList(std::vector< REFDES_INFO > &aBadRefDes)
Build the footprint lists, sort it, filter for excludes, then build the change list.
void FilterBackPrefix(wxCommandEvent &event) override
std::vector< REFDES_INFO > m_frontFootprints
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.
void LogFootprints(const std::vector< REFDES_INFO > &aFootprints)
Create a list of the footprints and their coordinates.
int RoundToGrid(int aCoord, int aGrid)
Round an int coordinate to a suitable grid.
REFDES_PREFIX_INFO * GetOrBuildRefDesInfo(const wxString &aRefDesPrefix, int aStartRefDes=1)
Get the structure representing the information currently held for aRefDesPrefix or create one if it d...
void BuildUnavailableRefsList()
Build list of unavailable references. E.g. unselected footprints or locked footprints.
bool TransferDataToWindow() override
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 ShowReport(const wxString &aMessage, SEVERITY aSeverity)
Break report into strings separated by and sent to the reporter.
std::vector< REFDES_INFO > m_backFootprints
std::vector< REFDES_PREFIX_INFO > m_refDesPrefixInfos
DIALOG_BOARD_REANNOTATE(PCB_EDIT_FRAME *aParentFrame)
void OnApplyClick(wxCommandEvent &event) override
std::vector< wxRadioButton * > m_sortButtons
void FilterFrontPrefix(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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.
The main frame for Pcbnew.
bool Empty() const
Checks if there is anything selected.
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[]
#define SetSortCodes(DirArray, Code)
static bool ChangeArrayCompare(const REFDES_CHANGE &aA, const REFDES_CHANGE &aB)
Compare function used to compare ChangeArray element for sort.
static bool FootprintCompare(const REFDES_INFO &aA, const REFDES_INFO &aB)
Compare function to sort footprints.
KICOMMON_API long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue in aUnits to internal units used by the application.
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.
Common grid settings, available to every frame.
unsigned int LastUsedRefDes
std::set< unsigned int > UnavailableRefs