From a17862d6466f571663b4b0ce0986d43c7bc18715 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 7 Jul 2021 17:53:30 +0100 Subject: [PATCH] Import Altium harness labels as text. One day we'll do better, but at least this way the user knows there's something they need to migrate manually. Fixes https://gitlab.com/kicad/code/kicad/issues/8748 --- .../sch_plugins/altium/altium_parser_sch.cpp | 1 + .../sch_plugins/altium/altium_parser_sch.h | 1 + .../sch_plugins/altium/sch_altium_plugin.cpp | 39 +++++++++++++------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.cpp b/eeschema/sch_plugins/altium/altium_parser_sch.cpp index 3775d9efcb..4ce0631ad8 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.cpp +++ b/eeschema/sch_plugins/altium/altium_parser_sch.cpp @@ -486,6 +486,7 @@ ASCH_PORT::ASCH_PORT( const std::map& aProperties ) -PropertiesReadKiCadUnitFrac( aProperties, "LOCATION.Y" ) ); name = ALTIUM_PARSER::PropertiesReadString( aProperties, "NAME", "" ); + harnessType = ALTIUM_PARSER::PropertiesReadString( aProperties, "HARNESSTYPE", "" ); width = PropertiesReadKiCadUnitFrac( aProperties, "WIDTH" ); height = PropertiesReadKiCadUnitFrac( aProperties, "HEIGHT" ); diff --git a/eeschema/sch_plugins/altium/altium_parser_sch.h b/eeschema/sch_plugins/altium/altium_parser_sch.h index 9410c2581b..2b9900ccd8 100644 --- a/eeschema/sch_plugins/altium/altium_parser_sch.h +++ b/eeschema/sch_plugins/altium/altium_parser_sch.h @@ -520,6 +520,7 @@ struct ASCH_PORT int ownerpartid; wxString name; + wxString harnessType; wxPoint location; int width; diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index 604f7624af..3341b6fbf1 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -1752,7 +1752,7 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro libSymbol->GetReferenceField().SetText( "#PWR" ); libSymbol->GetValueField().SetText( elem.text ); libSymbol->GetValueField().SetVisible( true ); // TODO: why does this not work? - libSymbol->SetDescription( wxString::Format( _( "Power powerSymbolIt creates a global " + libSymbol->SetDescription( wxString::Format( _( "Power symbol creates a global " "label with name '%s'" ), elem.text ) ); libSymbol->SetKeyWords( "power-flag" ); libSymbol->SetLibId( libId ); @@ -1829,9 +1829,9 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro void SCH_ALTIUM_PLUGIN::ParsePort( const ASCH_PORT& aElem ) { - // Get both connection points where we could connect to - wxPoint start = aElem.location + m_sheetOffset; - wxPoint end = start; + bool isHarness = !aElem.harnessType.IsEmpty(); + wxPoint start = aElem.location + m_sheetOffset; + wxPoint end = start; switch( aElem.style ) { @@ -1866,19 +1866,34 @@ void SCH_ALTIUM_PLUGIN::ParsePort( const ASCH_PORT& aElem ) || endIsWireTerminal || endIsBusTerminal; - if( !connectionFound ) + if( !isHarness && !connectionFound ) { - wxString msg = wxString::Format( _( "There is a port for '%s', but no connections to it." ), - aElem.name ); - m_reporter->Report( msg, RPT_SEVERITY_WARNING ); + m_reporter->Report( wxString::Format( _( "Port %s has no connections." ), aElem.name ), + RPT_SEVERITY_WARNING ); } // Select label position. In case both match, we will add a line later. - wxPoint position = ( startIsWireTerminal || startIsBusTerminal ) ? start : end; + wxPoint position = ( startIsWireTerminal || startIsBusTerminal ) ? start : end; + SCH_TEXT* label; - SCH_TEXT* const label = new SCH_GLOBALLABEL( position, aElem.name ); + if( isHarness ) + { + wxString name = _( "HARNESS: " ) + aElem.name; + + if( aElem.harnessType != aElem.name ) + name += wxString::Format( wxT( " (%s)" ), aElem.harnessType ); + + label = new SCH_TEXT( position, name ); + } // TODO: detect correct label type depending on sheet settings, etc. - // label = new SCH_HIERLABEL( elem.location + m_sheetOffset, elem.name ); + //{ + // label = new SCH_HIERLABEL( elem.location + m_sheetOffset, elem.name ); + //} + else + { + + label = new SCH_GLOBALLABEL( position, aElem.name ); + } switch( aElem.iotype ) { @@ -1924,7 +1939,7 @@ void SCH_ALTIUM_PLUGIN::ParsePort( const ASCH_PORT& aElem ) m_currentSheet->GetScreen()->Append( label ); // This is a hack, for the case both connection points are valid: add a small wire - if( ( startIsWireTerminal && endIsWireTerminal ) || !connectionFound ) + if( ( startIsWireTerminal && endIsWireTerminal ) ) { SCH_LINE* wire = new SCH_LINE( start, SCH_LAYER_ID::LAYER_WIRE ); wire->SetEndPoint( end );