Properly handle tildes at the end of bus vector names
Fixes: lp:1825532 * https://bugs.launchpad.net/kicad/+bug/1825532
This commit is contained in:
parent
ab3ada5200
commit
8c89847627
|
@ -271,15 +271,17 @@ void NETLIST_OBJECT::ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItem
|
||||||
if( conn.IsBusVectorLabel( bus_member ) )
|
if( conn.IsBusVectorLabel( bus_member ) )
|
||||||
{
|
{
|
||||||
wxString prefix;
|
wxString prefix;
|
||||||
|
std::vector<wxString> members;
|
||||||
long begin, end;
|
long begin, end;
|
||||||
|
|
||||||
conn.ParseBusVector( bus_member, &prefix, &begin, &end );
|
conn.ParseBusVector( bus_member, &prefix, members );
|
||||||
prefix = group_prefix + prefix;
|
prefix = group_prefix + prefix;
|
||||||
|
begin = conn.VectorStart();
|
||||||
|
end = conn.VectorEnd();
|
||||||
|
|
||||||
if( !self_set )
|
if( !self_set )
|
||||||
{
|
{
|
||||||
m_Label = prefix;
|
m_Label = members[0];
|
||||||
m_Label << begin;
|
|
||||||
m_Member = ( begin++ ) + ( member_offset++ );
|
m_Member = ( begin++ ) + ( member_offset++ );
|
||||||
|
|
||||||
self_set = true;
|
self_set = true;
|
||||||
|
@ -319,12 +321,14 @@ void NETLIST_OBJECT::ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItem
|
||||||
{
|
{
|
||||||
// Plain bus vector
|
// Plain bus vector
|
||||||
wxString prefix;
|
wxString prefix;
|
||||||
|
std::vector<wxString> members;
|
||||||
long begin, end;
|
long begin, end;
|
||||||
|
|
||||||
conn.ParseBusVector( m_Label, &prefix, &begin, &end );
|
conn.ParseBusVector( m_Label, &prefix, members );
|
||||||
|
begin = conn.VectorStart();
|
||||||
|
end = conn.VectorEnd();
|
||||||
|
|
||||||
m_Label = prefix;
|
m_Label = members[0];
|
||||||
m_Label << begin;
|
|
||||||
m_Member = begin;
|
m_Member = begin;
|
||||||
|
|
||||||
fillBusVector( aNetListItems, prefix, begin + 1, end, 0 );
|
fillBusVector( aNetListItems, prefix, begin + 1, end, 0 );
|
||||||
|
|
|
@ -57,9 +57,9 @@
|
||||||
* just USB_DP and USB_DN.
|
* just USB_DP and USB_DN.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static std::regex bus_label_re( "^([^[:space:]]+)(\\[[\\d]+\\.+[\\d]+\\])~*$" );
|
static std::regex bus_label_re( "^([^[:space:]]+)(\\[[\\d]+\\.+[\\d]+\\])(~?)$" );
|
||||||
|
|
||||||
static std::regex bus_group_label_re( "^([^[:space:]]+)?\\{((?:[^[:space:]]+(?:\\[[\\d]+\\.+[\\d]+\\])? ?)+)\\}~*$" );
|
static std::regex bus_group_label_re( "^([^[:space:]]+)?\\{((?:[^[:space:]]+(?:\\[[\\d]+\\.+[\\d]+\\])? ?)+)\\}$" );
|
||||||
|
|
||||||
|
|
||||||
SCH_CONNECTION::SCH_CONNECTION( SCH_ITEM* aParent, SCH_SHEET_PATH aPath ) :
|
SCH_CONNECTION::SCH_CONNECTION( SCH_ITEM* aParent, SCH_SHEET_PATH aPath ) :
|
||||||
|
@ -118,17 +118,18 @@ void SCH_CONNECTION::ConfigureFromLabel( wxString aLabel )
|
||||||
m_name = aLabel;
|
m_name = aLabel;
|
||||||
m_type = CONNECTION_BUS;
|
m_type = CONNECTION_BUS;
|
||||||
|
|
||||||
ParseBusVector( aLabel, &m_vector_prefix, &m_vector_start, &m_vector_end );
|
std::vector<wxString> members;
|
||||||
|
|
||||||
for( long i = m_vector_start; i <= m_vector_end; ++i )
|
ParseBusVector( aLabel, &m_vector_prefix, members );
|
||||||
|
long i = 0;
|
||||||
|
|
||||||
|
for( const auto& vector_member : members )
|
||||||
{
|
{
|
||||||
auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
|
auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
|
||||||
wxString name = m_vector_prefix;
|
|
||||||
name << i;
|
|
||||||
member->m_type = CONNECTION_NET;
|
member->m_type = CONNECTION_NET;
|
||||||
member->m_prefix = m_prefix;
|
member->m_prefix = m_prefix;
|
||||||
member->m_name = name;
|
member->m_name = vector_member;
|
||||||
member->m_vector_index = i;
|
member->m_vector_index = i++;
|
||||||
m_members.push_back( member );
|
m_members.push_back( member );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,28 +421,29 @@ bool SCH_CONNECTION::IsBusGroupLabel( const wxString& aLabel )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SCH_CONNECTION::ParseBusVector( wxString aVector, wxString* aName,
|
bool SCH_CONNECTION::ParseBusVector( wxString aBus, wxString* aName,
|
||||||
long* begin, long* end ) const
|
std::vector<wxString>& aMemberList ) const
|
||||||
{
|
{
|
||||||
auto ss_vector = std::string( aVector.mb_str() );
|
auto ss_vector = std::string( aBus.mb_str() );
|
||||||
std::smatch matches;
|
std::smatch matches;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if( !std::regex_match( ss_vector, matches, bus_label_re ) )
|
if( !std::regex_match( ss_vector, matches, bus_label_re ) )
|
||||||
{
|
return false;
|
||||||
wxFAIL_MSG( wxT( "<" ) + aVector + wxT( "> is not a valid bus vector." ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch( ... )
|
catch( ... )
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long begin = 0, end = 0;
|
||||||
*aName = wxString( matches[1] );
|
*aName = wxString( matches[1] );
|
||||||
wxString numberString( matches[2] );
|
wxString numberString( matches[2] );
|
||||||
|
|
||||||
|
// If we have three match groups, it means there was a tilde at the end of the vector
|
||||||
|
bool append_tilde = wxString( matches[3] ).IsSameAs( wxT( "~" ) );
|
||||||
|
|
||||||
// numberString will include the brackets, e.g. [5..0] so skip the first one
|
// numberString will include the brackets, e.g. [5..0] so skip the first one
|
||||||
size_t i = 1, len = numberString.Len();
|
size_t i = 1, len = numberString.Len();
|
||||||
wxString tmp;
|
wxString tmp;
|
||||||
|
@ -452,7 +454,7 @@ void SCH_CONNECTION::ParseBusVector( wxString aVector, wxString* aName,
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp.ToLong( begin );
|
tmp.ToLong( &begin );
|
||||||
|
|
||||||
while( i < len && numberString[i] == '.' )
|
while( i < len && numberString[i] == '.' )
|
||||||
i++;
|
i++;
|
||||||
|
@ -465,16 +467,29 @@ void SCH_CONNECTION::ParseBusVector( wxString aVector, wxString* aName,
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp.ToLong( end );
|
tmp.ToLong( &end );
|
||||||
|
|
||||||
if( *begin < 0 )
|
if( begin < 0 )
|
||||||
*begin = 0;
|
begin = 0;
|
||||||
|
|
||||||
if( *end < 0 )
|
if( end < 0 )
|
||||||
*end = 0;
|
end = 0;
|
||||||
|
|
||||||
if( *begin > *end )
|
if( begin > end )
|
||||||
std::swap( *begin, *end );
|
std::swap( begin, end );
|
||||||
|
|
||||||
|
for( long idx = begin; idx <= end; ++idx )
|
||||||
|
{
|
||||||
|
wxString str = *aName;
|
||||||
|
str << idx;
|
||||||
|
|
||||||
|
if( append_tilde )
|
||||||
|
str << '~';
|
||||||
|
|
||||||
|
aMemberList.emplace_back( str );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -262,13 +262,13 @@ public:
|
||||||
* Parses a bus vector (e.g. A[7..0]) into name, begin, and end.
|
* Parses a bus vector (e.g. A[7..0]) into name, begin, and end.
|
||||||
* Ensures that begin and end are positive and that end > begin.
|
* Ensures that begin and end are positive and that end > begin.
|
||||||
*
|
*
|
||||||
* @param vector is a bus vector label string
|
* @param aBus is a bus vector label string
|
||||||
* @param name output of the name portion of the label
|
* @param aName out is the bus name, e.g. "A"
|
||||||
* @param begin is the first entry in the vector
|
* @param aMemberList is a list of member strings, e.g. "A7", "A6", and so on
|
||||||
* @param end is the last entry in the vector
|
* @return true if aBus was successfully parsed
|
||||||
*/
|
*/
|
||||||
void ParseBusVector( wxString vector, wxString* name,
|
bool ParseBusVector( wxString aBus, wxString* aName,
|
||||||
long* begin, long* end ) const;
|
std::vector<wxString>& aMemberList ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a bus group label into the name and a list of components
|
* Parses a bus group label into the name and a list of components
|
||||||
|
|
Loading…
Reference in New Issue