Fix issues with new overbar syntax

- Update sch text help (~~ no longer gets converted to single ~)
- Update Eagle importer to correctly handle new overbar syntax
- Update CADSTAR importer to correctly handle new overbar syntax
This commit is contained in:
Roberto Fernandez Bautista 2021-09-01 19:24:42 +01:00
parent 130958e48e
commit 0aa37d1173
6 changed files with 37 additions and 15 deletions

View File

@ -31,6 +31,7 @@
#include <eda_item.h>
#include <eda_text.h>
#include <macros.h>
#include <string_utils.h>
#include <trigo.h>
// Ratio derived from CADSTAR default font. See doxygen comment in cadstar_archive_parser.h
@ -2546,6 +2547,16 @@ std::vector<CADSTAR_ARCHIVE_PARSER::CUTOUT> CADSTAR_ARCHIVE_PARSER::ParseAllChil
}
wxString CADSTAR_ARCHIVE_PARSER::HandleTextOverbar( wxString aCadstarString )
{
wxString escapedText = aCadstarString;
escapedText.Replace( wxT( "'" ), wxT( "~" ) );
return ConvertToNewOverbarNotation( escapedText );
}
void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem )
{
if( !aKiCadTextItem->GetText().IsEmpty() )

View File

@ -1368,6 +1368,13 @@ public:
static std::vector<CUTOUT> ParseAllChildCutouts(
XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false );
/**
* @brief Convert a string with CADSTAR overbar characters to equivalent in KiCad
* @param aCadstarString Input string
* @return KiCad string with overbar characters
*/
static wxString HandleTextOverbar( wxString aCadstarString );
/**
* Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR. Assumes that the
* provided text element has been initialised with a position and orientation.

View File

@ -41,10 +41,9 @@ wxString escapeName( const wxString& aNetName )
{
wxString ret( aNetName );
ret.Replace( "~", "~~" );
ret.Replace( "!", "~" );
return ret;
return ConvertToNewOverbarNotation( ret );
}

View File

@ -680,7 +680,10 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses()
m_busesMap.insert( { bus.ID, kiBusAlias } );
SCH_LABEL* label = new SCH_LABEL();
label->SetText( wxT( "{" ) + bus.Name + wxT( "}" ) );
wxString busname = HandleTextOverbar( bus.Name );
label->SetText( wxT( "{" ) + busname + wxT( "}" ) );
label->SetVisible( true );
screen->Append( label );
@ -730,6 +733,9 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses()
bus.BusLabel.Alignment,
bus.BusLabel.Justification );
// Re-set bus name as it might have been "double-escaped" after applyTextSettings
label->SetText( wxT( "{" ) + busname + wxT( "}" ) );
// Note orientation of the bus label will be determined in loadNets
// (the position of the wire will determine how best to place the bus label)
}
@ -750,6 +756,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
if( netName.IsEmpty() )
netName = wxString::Format( "$%ld", net.SignalNum );
netName = HandleTextOverbar( netName );
for( std::pair<NETELEMENT_ID, NET_SCH::SYM_TERM> terminalPair : net.Terminals )
{
@ -1236,8 +1243,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
{
PART::DEFINITION::PIN csPin = getPartDefinitionPin( *aCadstarPart, aGateID, term.ID );
pinName = csPin.Label;
pinNum = csPin.Name;
pinName = HandleTextOverbar( csPin.Label );
pinNum = HandleTextOverbar( csPin.Name );
if( pinNum.IsEmpty() )
{
@ -1667,7 +1674,7 @@ SCH_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol( const SYMBOL& aCads
return;
LIB_PIN* libpin = pinNumToLibPinMap.at( aOldPinNum );
libpin->SetNumber( aNewPinNum );
libpin->SetNumber( HandleTextOverbar( aNewPinNum ) );
};
//Older versions of Cadstar used pin numbers
@ -2460,10 +2467,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT
int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO );
int textWidth = getKiCadLength( textCode.Width );
// In Cadstar the overbar token is "'" whereas in KiCad it is "~"
wxString escapedText = aKiCadTextItem->GetText();
escapedText.Replace( wxT( "~" ), wxT( "~~" ) );
escapedText.Replace( wxT( "'" ), wxT( "~" ) );
// Ensure we have no Cadstar overbar characters
wxString escapedText = HandleTextOverbar( aKiCadTextItem->GetText() );
aKiCadTextItem->SetText( escapedText );
// The width is zero for all non-cadstar fonts. Using a width equal to 2/3 the height seems

View File

@ -1989,7 +1989,7 @@ LIB_TEXT* SCH_EAGLE_PLUGIN::loadSymbolText(
std::replace( text.begin(), text.end(), '\n', '_' );
std::replace( text.begin(), text.end(), '\r', '_' );
libtext->SetText( text.IsEmpty() ? "~~" : text );
libtext->SetText( text.IsEmpty() ? "~" : text );
loadTextAttributes( libtext.get(), etext );
return libtext.release();

View File

@ -31,12 +31,12 @@
<td></td>
</tr>
<tr>
<td> &nbsp;<br><samp>~{overbar}</samp><br> &nbsp;<br><samp>~{CLK}</samp><br> &nbsp;<br><samp>~~</samp> </td>
<td> &nbsp;<br><samp>~{overbar}</samp><br> &nbsp;<br><samp>~{CLK}</samp></td>
<td></td>
<td> <samp><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u></samp><br> <samp>overbar</samp><br> <samp><u>&nbsp;&nbsp;&nbsp;</u></samp><br> <samp>CLK</samp><br> <samp>&nbsp;</samp><br> <samp>~</samp> </td>
<td> <samp><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</u></samp><br> <samp>overbar</samp><br> <samp><u>&nbsp;&nbsp;&nbsp;</u></samp><br> <samp>CLK</samp></td>
</tr>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td>&nbsp;<br><samp>${variable}</samp></td>