42#include <wx/tokenzr.h>
43#include <wx/valtext.h>
80#define SetSortCodes( DirArray, Code ) \
82 g_SortYFirst = ( ( DirArray[Code] & SORTYFIRST ) != 0 ); \
83 g_DescendingFirst = ( ( DirArray[Code] & DESCENDINGFIRST ) != 0 ); \
84 g_DescendingSecond = ( ( DirArray[Code] & DESCENDINGSECOND ) != 0 ); \
91 _(
"(unannotated; not updated)" ),
115 { wxID_CANCEL,
_(
"Close" ) } } );
117 wxArrayString gridslist;
122 int gridIndex =
m_frame->config()->m_Window.grid.last_size_idx;
124 if( gridIndex >= 0 && gridIndex < (
int)
m_GridChoice->GetCount() )
140 EndDialog( wxID_OK );
148 if( !selection.
Empty() )
164 if( aPrefix->GetValue().empty() )
167 char lastc = aPrefix->GetValue().Last();
169 if( isalnum( (
int) lastc ) )
172 if( tmps.find( lastc ) != std::string::npos )
175 tmps = aPrefix->GetValue();
178 aPrefix->AppendText( tmps );
220 ShowReport(
_(
"PCB annotation changes should be synchronized with schematic using "
226 m_frame->GetCanvas()->Refresh();
237 rounder = aCoord % aGrid;
240 if( abs( rounder ) > ( aGrid / 2 ) )
241 aCoord += ( aCoord < 0 ? -aGrid : aGrid );
287 return wxT(
"<i>" ) +
_(
"unannotated footprint" ) + wxT(
"</i>" );
293 return wxT(
"<i>" ) +
_(
"unknown" ) + wxT(
"</i>" );
299 return wxString::Format( wxT(
"%s, %s" ),
300 m_frame->MessageTextFromValue( aX ),
301 m_frame->MessageTextFromValue( aY ) );
307 wxStringTokenizer msgs( aMessage,
"\n" );
309 while( msgs.HasMoreTokens() )
318 message =
_(
"Reference Designator Prefixes in Use" );
319 message += wxT(
"<br/>-------------------------------------------------------------<br/>" );
324 message +=
info.RefDesPrefix + ( ( i++ % 16 ) == 0 ? wxT(
"<br/>" ) : wxS(
" " ) );
326 message += wxT(
"<br/>" );
333 excludes += exclude + wxS(
" " );
335 message += wxString::Format(
_(
"(Excluding %s from reannotation.)" ), excludes );
340 message =
_(
"Change Log" );
341 message += wxT(
"<br/>-------------------------------------------------------------<br/>" );
347 message += wxString::Format( wxT(
"%s <i>%s</i><br/>" ),
348 change.OldRefDesString.IsEmpty() ?
empty_str() : change.OldRefDesString,
353 message += wxString::Format( wxT(
"%s -> %s<br/>" ),
354 change.OldRefDesString.IsEmpty() ?
empty_str() : change.OldRefDesString,
355 change.NewRefDes.IsEmpty() ?
empty_str() : change.NewRefDes );
365 wxString message = aFootprints.front().Front ?
_(
"Front Footprints" ) :
_(
"Back Footprints" );
369 message +=
_(
"(sorted by footprint location)" );
371 message +=
_(
"(sorted by reference designator location)" );
373 message += wxT(
"<br/>-------------------------------------------------------------" );
379 message += wxString::Format(
_(
"<br/>%d %s at %s (rounded to %s)" ),
381 fp.RefDesString.IsEmpty() ?
empty_str() : fp.RefDesString,
392 std::vector<REFDES_INFO> BadRefDes;
393 wxString message1, message2, badrefdes;
404 if( !BadRefDes.empty() )
406 message1.Printf(
_(
"PCB has %d empty or invalid reference designations." ), (
int) BadRefDes.size() );
407 message2.Printf(
_(
"You may wish to run DRC with 'Test for parity between PCB and schematic' checked." ) );
411 badrefdes += wxString::Format(
_(
"<br/> RefDes: %s; footprint: %s at %s on PCB." ),
412 mod.RefDesString.IsEmpty() ?
empty_str() : mod.RefDesString,
413 mod.FPID.IsValid() ? wxString( mod.FPID.Format().c_str() ) :
unknown_str(),
419 if( !
IsOK(
m_frame, message1 +
"\n" + message2 +
"\n \n" +
_(
"Reannotate anyway?" ) ) )
429 if(
nullptr == newref )
432 commit.
Modify( footprint );
433 footprint->SetReference( newref->
NewRefDes );
434 m_frame->GetCanvas()->GetView()->Update( footprint );
437 commit.
Push(
_(
"Annotation" ) );
461 wxStringTokenizer tokenizer(
m_ExcludeList->GetValue(),
", \t\r\n", wxTOKEN_STRTOK );
463 while( tokenizer.HasMoreTokens() )
471 fpData.
Uuid = footprint->m_Uuid;
473 fpData.
FPID = footprint->GetFPID();
474 fpData.
x = useFPLocation ? footprint->GetPosition().x
475 : footprint->Reference().GetPosition().x;
476 fpData.
y = useFPLocation ? footprint->GetPosition().y
477 : footprint->Reference().GetPosition().y;
480 fpData.
Front = footprint->GetLayer() ==
F_Cu;
489 firstnum = fpData.
RefDesString.find_first_of( wxT(
"0123456789" ) );
491 if( std::string::npos == firstnum )
501 if( excluded.EndsWith(
'*' ) )
516 if( footprint->IsLocked() && skipLocked )
518 else if( annotateSelected )
520 else if( annotateFront )
522 else if( annotateBack )
535 if( sortbuttons->GetValue() )
580 for(
size_t i = 0; i < changearraysize; i++ )
584 for(
size_t j = i + 1; j < changearraysize; j++ )
604 return ( errorcount == 0 );
609 std::vector<REFDES_INFO> excludedFootprints;
614 excludedFootprints.push_back( fpData );
620 excludedFootprints.push_back( fpData );
623 for(
const REFDES_INFO& fpData : excludedFootprints )
635 unsigned int aStartRefDes,
const wxString& aPrefix,
636 bool aRemovePrefix, std::vector<REFDES_INFO>& aBadRefDes )
638 size_t prefixsize = aPrefix.size();
640 bool haveprefix = ( 0 != prefixsize );
641 bool addprefix = haveprefix & !aRemovePrefix;
642 aRemovePrefix &= haveprefix;
648 if( aStartRefDes != 0 )
651 prefixInfo.LastUsedRefDes = aStartRefDes - 1;
658 change.
Uuid = fpData.Uuid;
659 change.
Action = fpData.Action;
662 change.
Front = fpData.Front;
664 if( fpData.RefDesString.IsEmpty() )
670 aBadRefDes.push_back( fpData );
676 prefixpresent = ( fpData.RefDesPrefix.find( aPrefix ) == 0 );
678 if( addprefix && !prefixpresent )
679 fpData.RefDesPrefix.insert( 0, aPrefix );
681 if( aRemovePrefix && prefixpresent )
682 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