From e55bb9e748b2c7a02081b0d1c5c313ce990a26ef Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 24 Jul 2018 19:41:08 +0100 Subject: [PATCH] Increment references when creating an array. While it's not always correct, not doing so is pretty much always incorrect. Fixes: lp:1625964 * https://bugs.launchpad.net/kicad/+bug/1625964 --- pcbnew/array_creator.cpp | 6 +++++- pcbnew/class_module.cpp | 8 ++++++++ pcbnew/class_module.h | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index e1776c8dd6..94c9979ef4 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -79,9 +79,13 @@ void ARRAY_CREATOR::Invoke() } else { - // PCB items keep the same numbering new_item = getBoard()->Duplicate( item ); + // Incrementing the reference number won't always be correct, but leaving + // it the same is always incorrect. + if( new_item->Type() == PCB_MODULE_T ) + static_cast( new_item )->IncrementReference( ptN ); + // @TODO: we should merge zones. This is a bit tricky, because // the undo command needs saving old area, if it is merged. } diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 8676b69643..a59a48e468 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1346,6 +1346,14 @@ wxString MODULE::GetReferencePrefix() const } +void MODULE::IncrementReference( int aDelta ) +{ + SetReference( wxString::Format( wxT( "%s%i" ), + GetReferencePrefix(), + getTrailingInt( GetReference() ) + aDelta ) ); +} + + // Calculate the area of aPolySet, after fracturation, because // polygons with no hole are expected. static double polygonArea( SHAPE_POLY_SET& aPolySet ) diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 57ed6e0af5..6fe27d1256 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -473,7 +473,7 @@ public: } /** - * Function GetReference prefix + * Function GetReferencePrefix * Gets the alphabetic prefix of the module reference - e.g. * R1 -> R * IC34 -> IC @@ -481,6 +481,12 @@ public: */ wxString GetReferencePrefix() const; + /** + * Function IncrementReference + * Bumps the current reference by aDelta. + */ + void IncrementReference( int aDelta ); + /** * Function GetValue * @return const wxString& - the value text.