Eeschema: Make auto-decrementing net labels stop at zero

CHANGED: If you set the auto-increment value to a negative number,
created a net label and hit the insert key, when the name got below zero,
the net labels tried to go negative but created bad labels instead.
Now the code caps decrementing at zero,  warns users when it has
happened, and explains why.

Fixes https://gitlab.com/kicad/code/kicad/issues/6537
This commit is contained in:
Peter Montgomery 2020-12-04 12:48:32 +00:00 committed by jean-pierre charras
parent 2f3ca60c5e
commit 821128cb8e
4 changed files with 31 additions and 11 deletions

View File

@ -51,15 +51,18 @@
using KIGFX::SCH_RENDER_SETTINGS;
void IncrementLabelMember( wxString& name, int aIncrement )
bool IncrementLabelMember( wxString& name, int aIncrement )
{
int ii, nn;
long number = 0;
ii = name.Len() - 1; nn = 0;
ii = name.Len() - 1;
nn = 0;
// No number found, but simply repeating the same label is valid
if( !wxIsdigit( name.GetChar( ii ) ) )
return;
return true;
while( ii >= 0 && wxIsdigit( name.GetChar( ii ) ) )
{
@ -67,14 +70,23 @@ void IncrementLabelMember( wxString& name, int aIncrement )
nn++;
}
ii++; /* digits are starting at ii position */
ii++; /* digits are starting at ii position */
wxString litt_number = name.Right( nn );
if( litt_number.ToLong( &number ) )
{
number += aIncrement;
name.Remove( ii ); name << number;
// Don't let result go below zero
if( number > -1 )
{
name.Remove( ii );
name << number;
return true;
}
}
return false;
}
@ -149,11 +161,15 @@ EDA_ITEM* SCH_TEXT::Clone() const
}
void SCH_TEXT::IncrementLabel( int aIncrement )
bool SCH_TEXT::IncrementLabel( int aIncrement )
{
wxString text = GetText();
IncrementLabelMember( text, aIncrement );
SetText(text );
bool ReturnVal = IncrementLabelMember( text, aIncrement );
if( ReturnVal )
SetText( text );
return ReturnVal;
}

View File

@ -221,7 +221,7 @@ public:
*
* @param aIncrement = the increment value to add to the number ending the text.
*/
void IncrementLabel( int aIncrement );
bool IncrementLabel( int aIncrement );
/**
* Set a spin or rotation angle, along with specific horizontal and vertical justification

View File

@ -80,7 +80,7 @@ static int GetLastPinNumSize()
}
extern void IncrementLabelMember( wxString& name, int aIncrement );
extern bool IncrementLabelMember( wxString& name, int aIncrement );
LIB_PIN_TOOL::LIB_PIN_TOOL() :

View File

@ -904,7 +904,11 @@ int SCH_EDIT_TOOL::RepeatDrawItem( const TOOL_EVENT& aEvent )
if( dynamic_cast<SCH_TEXT*>( newItem ) )
{
SCH_TEXT* text = static_cast<SCH_TEXT*>( newItem );
text->IncrementLabel( cfg->m_Drawing.repeat_label_increment );
// If incrementing tries to go below zero, tell user why the value is repeated
if( !text->IncrementLabel( cfg->m_Drawing.repeat_label_increment ) )
m_frame->ShowInfoBarMsg( _( "Label value cannot go below zero" ) );
}
newItem->Move( wxPoint( Mils2iu( cfg->m_Drawing.default_repeat_offset_x ),