26#include <wx/tokenzr.h>
27#include <wx/valtext.h>
82#define SetSortCodes( DirArray, Code ) \
84 g_SortYFirst = ( ( DirArray[Code] & SORTYFIRST ) != 0 ); \
85 g_DescendingFirst = ( ( DirArray[Code] & DESCENDINGFIRST ) != 0 ); \
86 g_DescendingSecond = ( ( DirArray[Code] & DESCENDINGSECOND ) != 0 ); \
93 _(
"(unannotated; not updated)" ),
95 _(
"(unknown suffix; not updated)" )
102 size_t firstnum = aRefDes.find_first_of( wxS(
"0123456789" ) );
104 if( firstnum == wxString::npos )
108 aRefDes.Mid( firstnum, aRefDes.find_first_not_of( wxS(
"0123456789" ), firstnum ) - firstnum )
110 return static_cast<int>( number );
133 { wxID_CANCEL,
_(
"Close" ) } } );
135 wxArrayString gridslist;
140 int gridIndex =
m_frame->config()->m_Window.grid.last_size_idx;
142 if( gridIndex >= 0 && gridIndex < (
int)
m_GridChoice->GetCount() )
158 EndDialog( wxID_OK );
166 if( !selection.
Empty() )
182 if( aPrefix->GetValue().empty() )
185 char lastc = aPrefix->GetValue().Last();
187 if( isalnum( (
int) lastc ) )
190 if( tmps.find( lastc ) != std::string::npos )
193 tmps = aPrefix->GetValue();
196 aPrefix->AppendText( tmps );
238 ShowReport(
_(
"PCB annotation changes should be synchronized with schematic using "
244 m_frame->GetCanvas()->Refresh();
255 rounder = aCoord % aGrid;
258 if( abs( rounder ) > ( aGrid / 2 ) )
259 aCoord += ( aCoord < 0 ? -aGrid : aGrid );
305 return wxT(
"<i>" ) +
_(
"unannotated footprint" ) + wxT(
"</i>" );
311 return wxT(
"<i>" ) +
_(
"unknown" ) + wxT(
"</i>" );
317 return wxString::Format( wxT(
"%s, %s" ),
318 m_frame->MessageTextFromValue( aX ),
319 m_frame->MessageTextFromValue( aY ) );
325 wxStringTokenizer msgs( aMessage,
"\n" );
327 while( msgs.HasMoreTokens() )
336 message =
_(
"Reference Designator Prefixes in Use" );
337 message += wxT(
"<br/>-------------------------------------------------------------<br/>" );
342 message +=
info.RefDesPrefix + ( ( i++ % 16 ) == 0 ? wxT(
"<br/>" ) : wxS(
" " ) );
351 excludes += exclude + wxS(
" " );
353 message += wxString::Format(
_(
"(Excluding %s from reannotation.)" ), excludes );
359 message += wxT(
"<br/>-------------------------------------------------------------<br/>" );
365 message += wxString::Format( wxT(
"%s <i>%s</i><br/>" ),
366 change.OldRefDesString.IsEmpty() ?
empty_str() : change.OldRefDesString,
371 message += wxString::Format( wxT(
"%s -> %s<br/>" ),
372 change.OldRefDesString.IsEmpty() ?
empty_str() : change.OldRefDesString,
373 change.NewRefDes.IsEmpty() ?
empty_str() : change.NewRefDes );
383 wxString
message = aFootprints.front().Front ?
_(
"Front Footprints" ) :
_(
"Back Footprints" );
387 message +=
_(
"(sorted by footprint location)" );
389 message +=
_(
"(sorted by reference designator location)" );
391 message += wxT(
"<br/>-------------------------------------------------------------" );
397 message += wxString::Format(
_(
"<br/>%d %s at %s (rounded to %s)" ),
399 fp.RefDesString.IsEmpty() ?
empty_str() : fp.RefDesString,
410 std::vector<REFDES_INFO> BadRefDes;
411 wxString message1, message2, badrefdes;
422 if( !BadRefDes.empty() )
424 message1.Printf(
_(
"PCB has %d empty or invalid reference designations." ), (
int) BadRefDes.size() );
425 message2.Printf(
_(
"You may wish to run DRC with 'Test for parity between PCB and schematic' checked." ) );
429 badrefdes += wxString::Format(
_(
"<br/> RefDes: %s; footprint: %s at %s on PCB." ),
430 mod.RefDesString.IsEmpty() ?
empty_str() : mod.RefDesString,
431 mod.FPID.IsValid() ? wxString( mod.FPID.Format().c_str() ) :
unknown_str(),
437 if( !
IsOK(
m_frame, message1 +
"\n" + message2 +
"\n \n" +
_(
"Reannotate anyway?" ) ) )
444 return aChange.Action == UNKNOWN_SUFFIX_REFDES;
447 if( unknownSuffixes > 0 )
449 ShowReport( wxString::Format(
_(
"%d footprints keep their references because their sheet suffixes "
450 "could not be determined. Open the schematic editor and update the PCB "
451 "from it if needed before renumbering them." ),
462 if(
nullptr == newref )
465 commit.
Modify( footprint );
466 footprint->SetReference( newref->
NewRefDes );
467 m_frame->GetCanvas()->GetView()->Update( footprint );
470 commit.
Push(
_(
"Annotation" ) );
494 wxStringTokenizer tokenizer(
m_ExcludeList->GetValue(),
", \t\r\n", wxTOKEN_STRTOK );
496 while( tokenizer.HasMoreTokens() )
499 std::optional<SHEET_REF_SUFFIXES> suffixes;
510 const bool suffixMode =
511 m_frame->Prj().GetProjectFile().Get<
bool>(
"schematic.annotation.reused_sheet_suffixes" ).value_or(
false );
512 std::map<KIID, FOOTPRINT_REF_SPLIT> splits =
520 fpData.
Uuid = footprint->m_Uuid;
522 fpData.
FPID = footprint->GetFPID();
523 fpData.
x = useFPLocation ? footprint->GetPosition().x
524 : footprint->Reference().GetPosition().x;
525 fpData.
y = useFPLocation ? footprint->GetPosition().y
526 : footprint->Reference().GetPosition().y;
529 fpData.
Front = footprint->GetLayer() ==
F_Cu;
531 fpData.
Suffix = splits.at( footprint->m_Uuid ).Suffix;
532 fpData.
Representative = splits.at( footprint->m_Uuid ).Representative;
533 fpData.
Shared = splits.at( footprint->m_Uuid ).Shared;
534 fpData.
Held = footprint->IsLocked() && skipLocked;
542 firstnum = fpData.
RefDesString.find_first_of( wxT(
"0123456789" ) );
544 if( std::string::npos == firstnum )
554 if( excluded.EndsWith(
'*' ) )
572 const bool outOfScope = ( footprint->IsLocked() && skipLocked )
573 || ( annotateSelected && !footprint->IsSelected() )
574 || ( annotateFront && !fpData.
Front ) || ( annotateBack && fpData.
Front );
590 std::map<KIID, ACTION_CODE> groupActions;
591 std::set<KIID> scopedGroups;
592 std::set<KIID> heldGroups;
602 if(
info.Representative ==
info.Uuid )
603 groupActions[
info.Uuid] =
info.Action;
606 scopedGroups.insert(
info.Representative );
609 heldGroups.insert(
info.Representative );
620 if( heldGroups.count(
info.Representative ) )
622 else if( scopedGroups.count(
info.Representative ) )
625 info.Action = groupActions.at(
info.Representative );
635 if( sortbuttons->GetValue() )
678 if( change.Action ==
UPDATE_REFDES && change.Representative != change.Uuid )
679 change.NewRefDes =
m_newBases.at( change.Representative ) + change.Suffix;
689 for(
size_t i = 0; i < changearraysize; i++ )
693 for(
size_t j = i + 1; j < changearraysize; j++ )
713 return ( errorcount == 0 );
741 unsigned int aStartRefDes,
const wxString& aPrefix,
742 bool aRemovePrefix, std::vector<REFDES_INFO>& aBadRefDes )
744 size_t prefixsize = aPrefix.size();
746 bool haveprefix = ( 0 != prefixsize );
747 bool addprefix = haveprefix & !aRemovePrefix;
748 aRemovePrefix &= haveprefix;
754 if( aStartRefDes != 0 )
757 prefixInfo.LastUsedRefDes = aStartRefDes - 1;
764 change.
Uuid = fpData.Uuid;
765 change.
Action = fpData.Action;
768 change.
Front = fpData.Front;
769 change.
Suffix = fpData.Suffix;
772 if( fpData.RefDesString.IsEmpty() )
778 aBadRefDes.push_back( fpData );
791 prefixpresent = ( fpData.RefDesPrefix.find( aPrefix ) == 0 );
793 if( addprefix && !prefixpresent )
794 fpData.RefDesPrefix.insert( 0, aPrefix );
796 if( aRemovePrefix && prefixpresent )
797 fpData.RefDesPrefix.erase( 0, prefixsize );
802 std::vector<wxString> suffixes = { fpData.Suffix };
805 suffixes = it->second;
809 [&](
const wxString& aBase )
811 for(
const wxString& suffix : suffixes )
821 || clashes( refDesInfo->
RefDesPrefix + std::to_string( newRefDesNumber ) ) )
826 wxString base = refDesInfo->
RefDesPrefix + std::to_string( newRefDesNumber );
828 for(
const wxString& suffix : suffixes )
832 if( !suffix.IsEmpty() )
constexpr EDA_IU_SCALE pcbIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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.
std::map< KIID, std::vector< wxString > > m_groupSuffixes
void FilterBackPrefix(wxCommandEvent &event) override
std::map< KIID, wxString > m_newBases
std::set< wxString > m_takenRefs
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.
std::set< wxString > m_suffixedRefs
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 int refDesNumber(const wxString &aRefDes)
The number of a reference, which a sheet suffix may follow.
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.
@ MAIL_SCH_GET_REF_SUFFIXES
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.
std::optional< SHEET_REF_SUFFIXES > ParseRefSuffixes(const std::string &aPayload)
std::map< KIID, FOOTPRINT_REF_SPLIT > SplitRefSuffixes(const FOOTPRINTS &aFootprints, const SHEET_REF_SUFFIXES *aSuffixes, bool aSuffixMode)
Split each footprint reference into its base and sheet suffix.
Collection of utility functions for component reference designators (refdes)
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
Common grid settings, available to every frame.
unsigned int LastUsedRefDes
std::set< unsigned int > UnavailableRefs