Import HARNESS PORT as textboxes, preserving original formatting + typo fixes

This commit is contained in:
WhiteChairFromIkea 2022-08-09 22:21:36 +03:00 committed by Jeff Young
parent 81a2fed5c5
commit 5c9346902a
4 changed files with 111 additions and 30 deletions

View File

@ -426,7 +426,7 @@ ASCH_SIGNAL_HARNESS::ASCH_SIGNAL_HARNESS( const std::map<wxString, wxString>& aP
-ReadKiCadUnitFrac( aProps, "Y" + si ) );
}
indexinsheet = ALTIUM_PARSER::ReadInt( aProps, "INDEXINSHEET", 0 );
indexInSheet = ALTIUM_PARSER::ReadInt( aProps, "INDEXINSHEET", 0 );
color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
lineWidth = ReadKiCadUnitFrac( aProps, "LINEWIDTH" );
@ -587,6 +587,13 @@ ASCH_PORT::ASCH_PORT( const std::map<wxString, wxString>& aProps )
iotype = ReadEnum<ASCH_PORT_IOTYPE>( aProps, "IOTYPE", 0, 3, ASCH_PORT_IOTYPE::UNSPECIFIED );
style = ReadEnum<ASCH_PORT_STYLE>( aProps, "STYLE", 0, 7, ASCH_PORT_STYLE::NONE_HORIZONTAL );
areaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR", 0 );
color = ALTIUM_PARSER::ReadInt( aProps, "COLOR", 0 );
fontId = ALTIUM_PARSER::ReadInt( aProps, "TEXTFONTID", 0 );
textColor = ALTIUM_PARSER::ReadInt( aProps, "TEXTCOLOR", 0 );
alignment = ReadEnum<ASCH_TEXT_FRAME_ALIGNMENT>( aProps, "ALIGNMENT", 1, 3, ASCH_TEXT_FRAME_ALIGNMENT::LEFT );
}
@ -698,6 +705,8 @@ ASCH_SHEET_FONT::ASCH_SHEET_FONT( const std::map<wxString, wxString>& aProps, in
italic = ALTIUM_PARSER::ReadBool( aProps, "ITALIC" + sid, false );
bold = ALTIUM_PARSER::ReadBool( aProps, "BOLD" + sid, false );
underline = ALTIUM_PARSER::ReadBool( aProps, "UNDERLINE" + sid, false );
areaColor = ALTIUM_PARSER::ReadInt( aProps, "AREACOLOR" + sid, 0 );
}
VECTOR2I ASchSheetGetSize( ASCH_SHEET_SIZE aSheetSize )

View File

@ -425,7 +425,7 @@ struct ASCH_SIGNAL_HARNESS
std::vector<VECTOR2I> points;
int color;
int indexinsheet;
int indexInSheet;
int lineWidth;
explicit ASCH_SIGNAL_HARNESS( const std::map<wxString, wxString>& aProps );
@ -602,6 +602,12 @@ struct ASCH_PORT
VECTOR2I location;
int width;
int height;
int areaColor;
int color;
int textColor;
int fontId;
ASCH_TEXT_FRAME_ALIGNMENT alignment;
ASCH_PORT_IOTYPE iotype;
ASCH_PORT_STYLE style;

View File

@ -48,6 +48,7 @@
#include <sch_label.h>
#include <sch_sheet.h>
#include <sch_sheet_pin.h>
#include <sch_textbox.h>
#include <bezier_curves.h>
#include <compoundfilereader.h>
@ -394,6 +395,10 @@ void SCH_ALTIUM_PLUGIN::ParseAdditional( const ALTIUM_COMPOUND_FILE& aAltiumSchF
}
}
// Handle harness Ports
for( const ASCH_PORT& port : m_altiumHarnessPortsCurrentSheet )
ParseHarnessPort( port );
if( reader.HasParsingError() )
THROW_IO_ERROR( "stream was not parsed correctly!" );
@ -1499,8 +1504,13 @@ void SCH_ALTIUM_PLUGIN::ParseHarnessConnector( int aIndex, const std::map<wxStri
/* aSize */ elem.size );
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
sheet->SetBackgroundColor( GetColorFromInt( elem.areaColor ) );
sheet->SetBorderColor( GetColorFromInt( elem.color ) );
// Harness ports are drawn the same colors as harness connectors, discarding properties, found in Altium's file,
// so keep color settings for use in harness ports
m_harnessConnectorBackgroundColor = GetColorFromInt( elem.areaColor );
m_harnessConnectorBorderColor = GetColorFromInt( elem.color );
sheet->SetBackgroundColor( m_harnessConnectorBackgroundColor );
sheet->SetBorderColor( m_harnessConnectorBorderColor );
sheet->SetScreen( screen );
@ -1520,8 +1530,7 @@ void SCH_ALTIUM_PLUGIN::ParseHarnessConnector( int aIndex, const std::map<wxStri
else
{
// I have no clue if this situation can ever exist
m_reporter->Report(
_( "Harness connector, belonging to the part is not currently supported." ),
m_reporter->Report( _( "Harness connector, belonging to the part is not currently supported." ),
RPT_SEVERITY_ERROR );
}
}
@ -1535,7 +1544,7 @@ void SCH_ALTIUM_PLUGIN::ParseHarnessEntry( const std::map<wxString, wxString>& a
if( sheetIt == m_sheets.end() )
{
m_reporter->Report( wxString::Format( _( "Harness entry's paren (%d) not found." ),
m_reporter->Report( wxString::Format( _( "Harness entry's parent (%d) not found." ),
SCH_ALTIUM_PLUGIN::m_harnessEntryParent ),
RPT_SEVERITY_ERROR );
return;
@ -1599,12 +1608,11 @@ void SCH_ALTIUM_PLUGIN::ParseHarnessType( const std::map<wxString, wxString>& aP
SetTextPositioning( &sheetNameField, ASCH_LABEL_JUSTIFICATION::BOTTOM_LEFT, ASCH_RECORD_ORIENTATION::RIGHTWARDS );
sheetNameField.SetTextColor( GetColorFromInt( elem.color ) );
m_reporter->Report(
wxString::Format( _( "Altium's Harness Connector (%s) was imported as "
m_reporter->Report( wxString::Format( _( "Altium's Harness Connector (%s) was imported as "
"Hierarchical sheet. Please review imported schematic, as "
"KiCad does natively support these Altium elements." ),
elem.text ),
RPT_SEVERITY_WARNING );
"KiCad does not natively support these Altium elements." ),
elem.text ),
RPT_SEVERITY_WARNING );
}
@ -2059,9 +2067,73 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map<wxString, wxString>& aPro
}
void SCH_ALTIUM_PLUGIN::ParseHarnessPort( const ASCH_PORT& aElem )
{
SCH_TEXTBOX* textBox = new SCH_TEXTBOX();
textBox->SetText( aElem.name );
textBox->SetTextColor( GetColorFromInt( aElem.textColor ) );
int height = aElem.height;
if( height <= 0 )
height = Mils2iu( 100 ); // chose default 50 grid
textBox->SetStartX( ( aElem.location + m_sheetOffset ).x );
textBox->SetStartY( ( aElem.location + m_sheetOffset ).y - ( height / 2 ) );
textBox->SetEndX( ( aElem.location + m_sheetOffset ).x + ( aElem.width ) );
textBox->SetEndY( ( aElem.location + m_sheetOffset ).y + ( height / 2 ) );
textBox->SetFillColor( m_harnessConnectorBackgroundColor );
textBox->SetFilled( true );
textBox->SetStroke( STROKE_PARAMS( 2, PLOT_DASH_TYPE::DEFAULT, m_harnessConnectorBorderColor ) );
switch( aElem.alignment )
{
default:
case ASCH_TEXT_FRAME_ALIGNMENT::LEFT:
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
break;
case ASCH_TEXT_FRAME_ALIGNMENT::CENTER:
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
break;
case ASCH_TEXT_FRAME_ALIGNMENT::RIGHT:
textBox->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
break;
}
size_t fontId = static_cast<int>( aElem.fontId );
if( m_altiumSheet && fontId > 0 && fontId <= m_altiumSheet->fonts.size() )
{
const ASCH_SHEET_FONT& font = m_altiumSheet->fonts.at( fontId - 1 );
textBox->SetItalic( font.italic );
textBox->SetBold( font.bold );
textBox->SetTextSize( { font.size / 2, font.size / 2 } );
//textBox->SetFont( //how to set font, we have a font mane here: ( font.fontname );
}
textBox->SetFlags( IS_NEW );
m_currentSheet->GetScreen()->Append( textBox );
m_reporter->Report( wxString::Format( _( "Altium's Harness port (%s) was imported as "
"Text box. Please review imported schematic, as "
"KiCad does not natively support these Altium elements." ),
aElem.name ),
RPT_SEVERITY_WARNING );
}
void SCH_ALTIUM_PLUGIN::ParsePort( const ASCH_PORT& aElem )
{
bool isHarness = !aElem.harnessType.IsEmpty();
if( !aElem.harnessType.IsEmpty() )
{
// Parse harness ports after "Additional" compound section is parsed
m_altiumHarnessPortsCurrentSheet.emplace_back( aElem );
return;
}
VECTOR2I start = aElem.location + m_sheetOffset;
VECTOR2I end = start;
@ -2098,7 +2170,7 @@ void SCH_ALTIUM_PLUGIN::ParsePort( const ASCH_PORT& aElem )
|| endIsWireTerminal
|| endIsBusTerminal;
if( !isHarness && !connectionFound )
if( !connectionFound )
{
m_reporter->Report( wxString::Format( _( "Port %s has no connections." ), aElem.name ),
RPT_SEVERITY_WARNING );
@ -2108,26 +2180,13 @@ void SCH_ALTIUM_PLUGIN::ParsePort( const ASCH_PORT& aElem )
VECTOR2I position = ( startIsWireTerminal || startIsBusTerminal ) ? start : end;
SCH_LABEL_BASE* label;
if( isHarness )
{
label = new SCH_DIRECTIVE_LABEL( position );
std::vector<SCH_FIELD>& fields = label->GetFields();
fields.emplace_back( SCH_FIELD( { 0, 0 }, 0, label, wxT( "Harness" ) ) );
fields[0].SetText( aElem.harnessType );
fields[0].SetVisible( true );
}
// TODO: detect correct label type depending on sheet settings, etc.
//{
// label = new SCH_HIERLABEL( elem.location + m_sheetOffset, elem.name );
//}
else
{
label = new SCH_GLOBALLABEL( position, aElem.name );
}
label = new SCH_GLOBALLABEL( position, aElem.name );
switch( aElem.iotype )
{
default:

View File

@ -125,6 +125,7 @@ private:
void ParseHarnessConnector( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParseHarnessEntry( const std::map<wxString, wxString>& aProperties );
void ParseHarnessType( const std::map<wxString, wxString>& aProperties );
void ParseHarnessPort( const ASCH_PORT& aElem );
void ParseRectangle( const std::map<wxString, wxString>& aProperties );
void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
@ -172,9 +173,15 @@ private:
std::map<int, ASCH_SYMBOL> m_altiumComponents;
std::map<int, int> m_altiumImplementationList;
std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
std::vector<ASCH_PORT> m_altiumHarnessPortsCurrentSheet; // parse harness ports after "FileHeader" was parsed, in 2nd run
int m_harnessOwnerIndexOffset; // Add offset to all harness ownerIndex'es after parsing FileHeader
int m_harnessEntryParent; // used to identify harness connector for harness entry element
// Harness ports are drawn the same colors as harness connectors, discarding port local
// settings found in altium's file, so keep color settings to draw harness ports correctly
COLOR4D m_harnessConnectorBackgroundColor;
COLOR4D m_harnessConnectorBorderColor;
};
#endif // _SCH_ALTIUM_PLUGIN_H_