Naming conventions.

This commit is contained in:
Jeff Young 2021-07-05 10:51:15 +01:00
parent a92d337905
commit 26df39e71a
2 changed files with 159 additions and 213 deletions

View File

@ -41,7 +41,6 @@
#include <lib_rectangle.h> #include <lib_rectangle.h>
#include <lib_text.h> #include <lib_text.h>
#include <bus_alias.h>
#include <sch_bitmap.h> #include <sch_bitmap.h>
#include <sch_bus_entry.h> #include <sch_bus_entry.h>
#include <sch_symbol.h> #include <sch_symbol.h>
@ -489,17 +488,17 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader
THROW_IO_ERROR( "stream is not fully parsed" ); THROW_IO_ERROR( "stream is not fully parsed" );
// assign LIB_SYMBOL -> COMPONENT // assign LIB_SYMBOL -> COMPONENT
for( auto component : m_components ) for( std::pair<const int, SCH_SYMBOL*>& symbol : m_symbols )
{ {
auto ksymbol = m_symbols.find( component.first ); auto libSymbolIt = m_libSymbols.find( symbol.first );
if( ksymbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
THROW_IO_ERROR( "every component should have a symbol attached" ); THROW_IO_ERROR( "every symbol should have a symbol attached" );
m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_SYMBOL( *( ksymbol->second ) ), m_pi->SaveSymbol( getLibFileName().GetFullPath(),
m_properties.get() ); new LIB_SYMBOL( *( libSymbolIt->second ) ), m_properties.get() );
component.second->SetLibSymbol( ksymbol->second ); symbol.second->SetLibSymbol( libSymbolIt->second );
} }
// Handle title blocks // Handle title blocks
@ -512,8 +511,8 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader
m_altiumPortsCurrentSheet.clear(); m_altiumPortsCurrentSheet.clear();
m_components.clear();
m_symbols.clear(); m_symbols.clear();
m_libSymbols.clear();
// Otherwise we cannot save the imported sheet? // Otherwise we cannot save the imported sheet?
m_currentSheet->SetModified(); m_currentSheet->SetModified();
@ -538,14 +537,10 @@ const ASCH_STORAGE_FILE* SCH_ALTIUM_PLUGIN::GetFileFromStorage( const wxString&
for( const ASCH_STORAGE_FILE& file : m_altiumStorage ) for( const ASCH_STORAGE_FILE& file : m_altiumStorage )
{ {
if( file.filename.IsSameAs( aFilename ) ) if( file.filename.IsSameAs( aFilename ) )
{
return &file; return &file;
}
if( file.filename.EndsWith( aFilename ) ) if( file.filename.EndsWith( aFilename ) )
{
nonExactMatch = &file; nonExactMatch = &file;
}
} }
return nonExactMatch; return nonExactMatch;
@ -569,7 +564,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex,
ksymbol->SetName( name ); ksymbol->SetName( name );
ksymbol->SetDescription( elem.componentdescription ); ksymbol->SetDescription( elem.componentdescription );
ksymbol->SetLibId( libId ); ksymbol->SetLibId( libId );
m_symbols.insert( { aIndex, ksymbol } ); m_libSymbols.insert( { aIndex, ksymbol } );
// each component has its own symbol for now // each component has its own symbol for now
SCH_SYMBOL* symbol = new SCH_SYMBOL(); SCH_SYMBOL* symbol = new SCH_SYMBOL();
@ -583,7 +578,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex,
m_currentSheet->GetScreen()->Append( symbol ); m_currentSheet->GetScreen()->Append( symbol );
m_components.insert( { aIndex, symbol } ); m_symbols.insert( { aIndex, symbol } );
} }
@ -591,9 +586,9 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aPropertie
{ {
ASCH_PIN elem( aProperties ); ASCH_PIN elem( aProperties );
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Pin has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Pin has non-existent ownerindex %d." ),
@ -605,10 +600,9 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aPropertie
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
LIB_PIN* pin = new LIB_PIN( libSymbolIt->second );
LIB_PIN* pin = new LIB_PIN( symbol->second ); libSymbolIt->second->AddDrawItem( pin );
symbol->second->AddDrawItem( pin );
pin->SetUnit( elem.ownerpartid ); pin->SetUnit( elem.ownerpartid );
@ -648,9 +642,9 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map<wxString, wxString>& aPropertie
} }
// TODO: position can be sometimes off a little bit! // TODO: position can be sometimes off a little bit!
pin->SetPosition( GetRelativePosition( pinLocation + m_sheetOffset, component ) ); pin->SetPosition( GetRelativePosition( pinLocation + m_sheetOffset, symbol ) );
// TODO: the following fix is even worse for now? // TODO: the following fix is even worse for now?
// pin->SetPosition( GetRelativePosition( elem.kicadLocation, component ) ); // pin->SetPosition( GetRelativePosition( elem.kicadLocation, symbol ) );
switch( elem.electrical ) switch( elem.electrical )
{ {
@ -806,9 +800,9 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& aPropert
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Label has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Label has non-existent ownerindex %d." ),
@ -817,14 +811,13 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map<wxString, wxString>& aPropert
return; return;
} }
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
LIB_TEXT* text = new LIB_TEXT( libSymbolIt->second );
LIB_TEXT* text = new LIB_TEXT( symbol->second ); libSymbolIt->second->AddDrawItem( text );
symbol->second->AddDrawItem( text );
text->SetUnit( elem.ownerpartid ); text->SetUnit( elem.ownerpartid );
text->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, component ) ); text->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, symbol ) );
text->SetText( elem.text ); text->SetText( elem.text );
SetEdaTextJustification( text, elem.justification ); SetEdaTextJustification( text, elem.justification );
@ -876,10 +869,9 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
// simulate bezier using line segments // simulate bezier using line segments
std::vector<wxPoint> bezierPoints; std::vector<wxPoint> bezierPoints;
std::vector<wxPoint> polyPoints; std::vector<wxPoint> polyPoints;
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ ) for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
{
bezierPoints.push_back( elem.points.at( j ) + m_sheetOffset ); bezierPoints.push_back( elem.points.at( j ) + m_sheetOffset );
}
BEZIER_POLY converter( bezierPoints ); BEZIER_POLY converter( bezierPoints );
converter.GetPoly( polyPoints ); converter.GetPoly( polyPoints );
@ -900,9 +892,9 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Bezier has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Bezier has non-existent ownerindex %d." ),
@ -914,22 +906,22 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
for( size_t i = 0; i + 1 < elem.points.size(); i += 3 ) for( size_t i = 0; i + 1 < elem.points.size(); i += 3 )
{ {
if( i + 2 == elem.points.size() ) if( i + 2 == elem.points.size() )
{ {
// special case: single line // special case: single line
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second );
symbol->second->AddDrawItem( line ); libSymbolIt->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid ); line->SetUnit( elem.ownerpartid );
for( size_t j = i; j < elem.points.size() && j < i + 2; j++ ) for( size_t j = i; j < elem.points.size() && j < i + 2; j++ )
{ {
line->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset, line->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset,
component ) ); symbol ) );
} }
line->SetWidth( elem.lineWidth ); line->SetWidth( elem.lineWidth );
@ -937,15 +929,15 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map<wxString, wxString>& aProper
else else
{ {
// bezier always has maximum of 4 control points // bezier always has maximum of 4 control points
LIB_BEZIER* bezier = new LIB_BEZIER( symbol->second ); LIB_BEZIER* bezier = new LIB_BEZIER( libSymbolIt->second );
symbol->second->AddDrawItem( bezier ); libSymbolIt->second->AddDrawItem( bezier );
bezier->SetUnit( elem.ownerpartid ); bezier->SetUnit( elem.ownerpartid );
for( size_t j = i; j < elem.points.size() && j < i + 4; j++ ) for( size_t j = i; j < elem.points.size() && j < i + 4; j++ )
{ {
bezier->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset, bezier->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset,
component ) ); symbol ) );
} }
bezier->SetWidth( elem.lineWidth ); bezier->SetWidth( elem.lineWidth );
@ -986,8 +978,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map<wxString, wxString>& aProp
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() )
if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Polyline has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Polyline has non-existent ownerindex %d." ),
@ -999,16 +992,15 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map<wxString, wxString>& aProp
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second );
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); libSymbolIt->second->AddDrawItem( line );
symbol->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid ); line->SetUnit( elem.ownerpartid );
for( wxPoint& point : elem.points ) for( wxPoint& point : elem.points )
{ {
line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) );
} }
line->SetWidth( elem.lineWidth ); line->SetWidth( elem.lineWidth );
@ -1025,8 +1017,8 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
// TODO: we cannot fill this polygon, only draw it for now // TODO: we cannot fill this polygon, only draw it for now
for( size_t i = 0; i + 1 < elem.points.size(); i++ ) for( size_t i = 0; i + 1 < elem.points.size(); i++ )
{ {
SCH_LINE* line = SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset,
new SCH_LINE( elem.points.at( i ) + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES ); SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset ); line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset );
line->SetLineWidth( elem.lineWidth ); line->SetLineWidth( elem.lineWidth );
line->SetLineStyle( PLOT_DASH_TYPE::SOLID ); line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
@ -1036,8 +1028,8 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
} }
// close polygon // close polygon
SCH_LINE* line = SCH_LINE* line = new SCH_LINE( elem.points.front() + m_sheetOffset,
new SCH_LINE( elem.points.front() + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES ); SCH_LAYER_ID::LAYER_NOTES );
line->SetEndPoint( elem.points.back() + m_sheetOffset ); line->SetEndPoint( elem.points.back() + m_sheetOffset );
line->SetLineWidth( elem.lineWidth ); line->SetLineWidth( elem.lineWidth );
line->SetLineStyle( PLOT_DASH_TYPE::SOLID ); line->SetLineStyle( PLOT_DASH_TYPE::SOLID );
@ -1047,9 +1039,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Polygon has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Polygon has non-existent ownerindex %d." ),
@ -1061,17 +1053,16 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map<wxString, wxString>& aPrope
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second );
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); libSymbolIt->second->AddDrawItem( line );
symbol->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid ); line->SetUnit( elem.ownerpartid );
for( wxPoint& point : elem.points ) for( wxPoint& point : elem.points )
line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) );
line->AddPoint( GetRelativePosition( elem.points.front() + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( elem.points.front() + m_sheetOffset, symbol ) );
line->SetWidth( elem.lineWidth ); line->SetWidth( elem.lineWidth );
@ -1129,9 +1120,9 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map<wxString, wxString>&
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Rounded rectangle has non-existent " m_reporter->Report( wxString::Format( _( "Rounded rectangle has non-existent "
@ -1144,16 +1135,15 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map<wxString, wxString>&
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
// TODO: misses rounded edges // TODO: misses rounded edges
LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second ); LIB_RECTANGLE* rect = new LIB_RECTANGLE( libSymbolIt->second );
symbol->second->AddDrawItem( rect ); libSymbolIt->second->AddDrawItem( rect );
rect->SetUnit( elem.ownerpartid ); rect->SetUnit( elem.ownerpartid );
rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, component ) ); rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, symbol ) );
rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, component ) ); rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, symbol ) );
rect->SetWidth( elem.lineWidth ); rect->SetWidth( elem.lineWidth );
if( !elem.isSolid ) if( !elem.isSolid )
@ -1177,8 +1167,8 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map<wxString, wxString>& aPropertie
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Arc has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Arc has non-existent ownerindex %d." ),
@ -1190,28 +1180,28 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map<wxString, wxString>& aPropertie
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
if( elem.startAngle == 0 && ( elem.endAngle == 0 || elem.endAngle == 360 ) ) if( elem.startAngle == 0 && ( elem.endAngle == 0 || elem.endAngle == 360 ) )
{ {
LIB_CIRCLE* circle = new LIB_CIRCLE( symbol->second ); LIB_CIRCLE* circle = new LIB_CIRCLE( libSymbolIt->second );
symbol->second->AddDrawItem( circle ); libSymbolIt->second->AddDrawItem( circle );
circle->SetUnit( elem.ownerpartid ); circle->SetUnit( elem.ownerpartid );
circle->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) ); circle->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, symbol ) );
circle->SetRadius( elem.radius ); circle->SetRadius( elem.radius );
circle->SetWidth( elem.lineWidth ); circle->SetWidth( elem.lineWidth );
} }
else else
{ {
LIB_ARC* arc = new LIB_ARC( symbol->second ); LIB_ARC* arc = new LIB_ARC( libSymbolIt->second );
symbol->second->AddDrawItem( arc ); libSymbolIt->second->AddDrawItem( arc );
arc->SetUnit( elem.ownerpartid ); arc->SetUnit( elem.ownerpartid );
// TODO: correct? // TODO: correct?
arc->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) ); arc->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, symbol ) );
arc->SetRadius( elem.radius ); arc->SetRadius( elem.radius );
arc->SetFirstRadiusAngle( elem.startAngle * 10. ); arc->SetFirstRadiusAngle( elem.startAngle * 10. );
arc->SetSecondRadiusAngle( elem.endAngle * 10. ); arc->SetSecondRadiusAngle( elem.endAngle * 10. );
@ -1237,9 +1227,9 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map<wxString, wxString>& aProperti
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Line has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Line has non-existent ownerindex %d." ),
@ -1251,15 +1241,14 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map<wxString, wxString>& aProperti
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second );
LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); libSymbolIt->second->AddDrawItem( line );
symbol->second->AddDrawItem( line );
line->SetUnit( elem.ownerpartid ); line->SetUnit( elem.ownerpartid );
line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, symbol ) );
line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, component ) ); line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, symbol ) );
line->SetWidth( elem.lineWidth ); line->SetWidth( elem.lineWidth );
} }
@ -1309,9 +1298,9 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aPro
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() ) if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Rectangle has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Rectangle has non-existent ownerindex %d." ),
@ -1323,15 +1312,14 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aPro
if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) )
return; return;
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
LIB_RECTANGLE* rect = new LIB_RECTANGLE( libSymbolIt->second );
LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second ); libSymbolIt->second->AddDrawItem( rect );
symbol->second->AddDrawItem( rect );
rect->SetUnit( elem.ownerpartid ); rect->SetUnit( elem.ownerpartid );
rect->SetPosition( GetRelativePosition( sheetTopRight, component ) ); rect->SetPosition( GetRelativePosition( sheetTopRight, symbol ) );
rect->SetEnd( GetRelativePosition( sheetBottomLeft, component ) ); rect->SetEnd( GetRelativePosition( sheetBottomLeft, symbol ) );
rect->SetWidth( elem.lineWidth ); rect->SetWidth( elem.lineWidth );
if( !elem.isSolid ) if( !elem.isSolid )
@ -1344,8 +1332,8 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map<wxString, wxString>& aPro
} }
void SCH_ALTIUM_PLUGIN::ParseSheetSymbol( void SCH_ALTIUM_PLUGIN::ParseSheetSymbol( int aIndex, const std::map<wxString,
int aIndex, const std::map<wxString, wxString>& aProperties ) wxString>& aProperties )
{ {
ASCH_SHEET_SYMBOL elem( aProperties ); ASCH_SHEET_SYMBOL elem( aProperties );
@ -1643,33 +1631,31 @@ wxPoint HelperGeneratePowerPortGraphics( LIB_SYMBOL* aKsymbol, ASCH_POWER_PORT_S
void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map<wxString, wxString>& aProperties ) void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map<wxString, wxString>& aProperties )
{ {
ASCH_POWER_PORT elem( aProperties ); ASCH_POWER_PORT elem( aProperties );
LIB_ID libId = AltiumToKiCadLibID( getLibName(), elem.text );
LIB_SYMBOL* libSymbol = nullptr;
LIB_ID libId = AltiumToKiCadLibID( getLibName(), elem.text ); const auto& powerSymbolIt = m_powerSymbols.find( elem.text );
LIB_SYMBOL* ksymbol = nullptr; if( powerSymbolIt != m_powerSymbols.end() )
const auto& symbol = m_powerSymbols.find( elem.text );
if( symbol != m_powerSymbols.end() )
{ {
ksymbol = symbol->second; // cache hit libSymbol = powerSymbolIt->second; // cache hit
} }
else else
{ {
ksymbol = new LIB_SYMBOL( wxEmptyString ); libSymbol = new LIB_SYMBOL( wxEmptyString );
ksymbol->SetPower(); libSymbol->SetPower();
ksymbol->SetName( elem.text ); libSymbol->SetName( elem.text );
ksymbol->GetReferenceField().SetText( "#PWR" ); libSymbol->GetReferenceField().SetText( "#PWR" );
ksymbol->GetValueField().SetText( elem.text ); libSymbol->GetValueField().SetText( elem.text );
ksymbol->GetValueField().SetVisible( true ); // TODO: why does this not work? libSymbol->GetValueField().SetVisible( true ); // TODO: why does this not work?
ksymbol->SetDescription( libSymbol->SetDescription( wxString::Format( _( "Power powerSymbolIt creates a global "
wxString::Format( _( "Power symbol creates a global label with name '%s'" ), "label with name '%s'" ), elem.text ) );
elem.text ) ); libSymbol->SetKeyWords( "power-flag" );
ksymbol->SetKeyWords( "power-flag" ); libSymbol->SetLibId( libId );
ksymbol->SetLibId( libId );
// generate graphic // generate graphic
LIB_PIN* pin = new LIB_PIN( ksymbol ); LIB_PIN* pin = new LIB_PIN( libSymbol );
ksymbol->AddDrawItem( pin ); libSymbol->AddDrawItem( pin );
pin->SetName( elem.text ); pin->SetName( elem.text );
pin->SetPosition( { 0, 0 } ); pin->SetPosition( { 0, 0 } );
@ -1679,52 +1665,52 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map<wxString, wxString>& aPro
pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN ); pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
pin->SetVisible( false ); pin->SetVisible( false );
wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( ksymbol, elem.style, m_reporter ); wxPoint valueFieldPos = HelperGeneratePowerPortGraphics( libSymbol, elem.style, m_reporter );
ksymbol->GetValueField().SetPosition( valueFieldPos ); libSymbol->GetValueField().SetPosition( valueFieldPos );
// this has to be done after parsing the LIB_SYMBOL! // this has to be done after parsing the LIB_SYMBOL!
m_pi->SaveSymbol( getLibFileName().GetFullPath(), ksymbol, m_properties.get() ); m_pi->SaveSymbol( getLibFileName().GetFullPath(), libSymbol, m_properties.get() );
m_powerSymbols.insert( { elem.text, ksymbol } ); m_powerSymbols.insert( { elem.text, libSymbol } );
} }
SCH_SHEET_PATH sheetpath; SCH_SHEET_PATH sheetpath;
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath ); m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
// each component has its own symbol for now // each symbol has its own powerSymbolIt for now
SCH_SYMBOL* component = new SCH_SYMBOL(); SCH_SYMBOL* symbol = new SCH_SYMBOL();
component->SetRef( &sheetpath, "#PWR?" ); symbol->SetRef( &sheetpath, "#PWR?" );
component->SetValue( elem.text ); symbol->SetValue( elem.text );
component->SetLibId( libId ); symbol->SetLibId( libId );
component->SetLibSymbol( new LIB_SYMBOL( *ksymbol ) ); symbol->SetLibSymbol( new LIB_SYMBOL( *libSymbol ) );
SCH_FIELD* valueField = component->GetField( VALUE_FIELD ); SCH_FIELD* valueField = symbol->GetField( VALUE_FIELD );
// TODO: Why do I need to set those a second time? // TODO: Why do I need to set those a second time?
valueField->SetVisible( true ); valueField->SetVisible( true );
valueField->SetPosition( ksymbol->GetValueField().GetPosition() ); valueField->SetPosition( libSymbol->GetValueField().GetPosition() );
component->SetPosition( elem.location + m_sheetOffset ); symbol->SetPosition( elem.location + m_sheetOffset );
switch( elem.orientation ) switch( elem.orientation )
{ {
case ASCH_RECORD_ORIENTATION::RIGHTWARDS: case ASCH_RECORD_ORIENTATION::RIGHTWARDS:
component->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_90 ); symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_90 );
valueField->SetTextAngle( -900. ); valueField->SetTextAngle( -900. );
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT ); valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT );
break; break;
case ASCH_RECORD_ORIENTATION::UPWARDS: case ASCH_RECORD_ORIENTATION::UPWARDS:
component->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_180 ); symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_180 );
valueField->SetTextAngle( -1800. ); valueField->SetTextAngle( -1800. );
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER ); valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER );
break; break;
case ASCH_RECORD_ORIENTATION::LEFTWARDS: case ASCH_RECORD_ORIENTATION::LEFTWARDS:
component->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_270 ); symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_270 );
valueField->SetTextAngle( -2700. ); valueField->SetTextAngle( -2700. );
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_RIGHT ); valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_RIGHT );
break; break;
case ASCH_RECORD_ORIENTATION::DOWNWARDS: case ASCH_RECORD_ORIENTATION::DOWNWARDS:
component->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_0 ); symbol->SetOrientation( SYMBOL_ORIENTATION_T::SYM_ORIENT_0 );
valueField->SetTextAngle( 0. ); valueField->SetTextAngle( 0. );
valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER ); valueField->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER );
break; break;
@ -1733,7 +1719,7 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map<wxString, wxString>& aPro
break; break;
} }
m_currentSheet->GetScreen()->Append( component ); m_currentSheet->GetScreen()->Append( symbol );
} }
@ -2006,63 +1992,28 @@ void SCH_ALTIUM_PLUGIN::ParseSheet( const std::map<wxString, wxString>& aPropert
PAGE_INFO pageInfo; PAGE_INFO pageInfo;
bool isPortrait = m_altiumSheet->sheetOrientation == ASCH_SHEET_WORKSPACEORIENTATION::PORTRAIT; bool isPortrait = m_altiumSheet->sheetOrientation == ASCH_SHEET_WORKSPACEORIENTATION::PORTRAIT;
switch( m_altiumSheet->sheetSize ) switch( m_altiumSheet->sheetSize )
{ {
default: default:
case ASCH_SHEET_SIZE::A4: case ASCH_SHEET_SIZE::A4: pageInfo.SetType( "A4", isPortrait ); break;
pageInfo.SetType( "A4", isPortrait ); case ASCH_SHEET_SIZE::A3: pageInfo.SetType( "A3", isPortrait ); break;
break; case ASCH_SHEET_SIZE::A2: pageInfo.SetType( "A2", isPortrait ); break;
case ASCH_SHEET_SIZE::A3: case ASCH_SHEET_SIZE::A1: pageInfo.SetType( "A1", isPortrait ); break;
pageInfo.SetType( "A3", isPortrait ); case ASCH_SHEET_SIZE::A0: pageInfo.SetType( "A0", isPortrait ); break;
break; case ASCH_SHEET_SIZE::A: pageInfo.SetType( "A", isPortrait ); break;
case ASCH_SHEET_SIZE::A2: case ASCH_SHEET_SIZE::B: pageInfo.SetType( "B", isPortrait ); break;
pageInfo.SetType( "A2", isPortrait ); case ASCH_SHEET_SIZE::C: pageInfo.SetType( "C", isPortrait ); break;
break; case ASCH_SHEET_SIZE::D: pageInfo.SetType( "D", isPortrait ); break;
case ASCH_SHEET_SIZE::A1: case ASCH_SHEET_SIZE::E: pageInfo.SetType( "E", isPortrait ); break;
pageInfo.SetType( "A1", isPortrait ); case ASCH_SHEET_SIZE::LETTER: pageInfo.SetType( "USLetter", isPortrait ); break;
break; case ASCH_SHEET_SIZE::LEGAL: pageInfo.SetType( "USLegal", isPortrait ); break;
case ASCH_SHEET_SIZE::A0: case ASCH_SHEET_SIZE::TABLOID: pageInfo.SetType( "A3", isPortrait ); break;
pageInfo.SetType( "A0", isPortrait ); case ASCH_SHEET_SIZE::ORCAD_A: pageInfo.SetType( "A", isPortrait ); break;
break; case ASCH_SHEET_SIZE::ORCAD_B: pageInfo.SetType( "B", isPortrait ); break;
case ASCH_SHEET_SIZE::A: case ASCH_SHEET_SIZE::ORCAD_C: pageInfo.SetType( "C", isPortrait ); break;
pageInfo.SetType( "A", isPortrait ); case ASCH_SHEET_SIZE::ORCAD_D: pageInfo.SetType( "D", isPortrait ); break;
break; case ASCH_SHEET_SIZE::ORCAD_E: pageInfo.SetType( "E", isPortrait ); break;
case ASCH_SHEET_SIZE::B:
pageInfo.SetType( "B", isPortrait );
break;
case ASCH_SHEET_SIZE::C:
pageInfo.SetType( "C", isPortrait );
break;
case ASCH_SHEET_SIZE::D:
pageInfo.SetType( "D", isPortrait );
break;
case ASCH_SHEET_SIZE::E:
pageInfo.SetType( "E", isPortrait );
break;
case ASCH_SHEET_SIZE::LETTER:
pageInfo.SetType( "USLetter", isPortrait );
break;
case ASCH_SHEET_SIZE::LEGAL:
pageInfo.SetType( "USLegal", isPortrait );
break;
case ASCH_SHEET_SIZE::TABLOID:
pageInfo.SetType( "A3", isPortrait ); // TODO: use User
break;
case ASCH_SHEET_SIZE::ORCAD_A:
pageInfo.SetType( "A", isPortrait );
break;
case ASCH_SHEET_SIZE::ORCAD_B:
pageInfo.SetType( "B", isPortrait );
break;
case ASCH_SHEET_SIZE::ORCAD_C:
pageInfo.SetType( "C", isPortrait );
break;
case ASCH_SHEET_SIZE::ORCAD_D:
pageInfo.SetType( "D", isPortrait );
break;
case ASCH_SHEET_SIZE::ORCAD_E:
pageInfo.SetType( "E", isPortrait );
break;
} }
m_currentSheet->GetScreen()->SetPageSettings( pageInfo ); m_currentSheet->GetScreen()->SetPageSettings( pageInfo );
@ -2076,18 +2027,10 @@ void SetFieldOrientation( SCH_FIELD& aField, ASCH_RECORD_ORIENTATION aOrientatio
switch( aOrientation ) switch( aOrientation )
{ {
default: default:
case ASCH_RECORD_ORIENTATION::RIGHTWARDS: case ASCH_RECORD_ORIENTATION::RIGHTWARDS: aField.SetTextAngle( 0 ); break;
aField.SetTextAngle( 0 ); case ASCH_RECORD_ORIENTATION::UPWARDS: aField.SetTextAngle( 900 ); break;
break; case ASCH_RECORD_ORIENTATION::LEFTWARDS: aField.SetTextAngle( 1800 ); break;
case ASCH_RECORD_ORIENTATION::UPWARDS: case ASCH_RECORD_ORIENTATION::DOWNWARDS: aField.SetTextAngle( 2700 ); break;
aField.SetTextAngle( 900 );
break;
case ASCH_RECORD_ORIENTATION::LEFTWARDS:
aField.SetTextAngle( 1800 );
break;
case ASCH_RECORD_ORIENTATION::DOWNWARDS:
aField.SetTextAngle( 2700 );
break;
} }
} }
@ -2132,7 +2075,8 @@ void SCH_ALTIUM_PLUGIN::ParseFileName( const std::map<wxString, wxString>& aProp
filenameField.SetPosition( elem.location + m_sheetOffset ); filenameField.SetPosition( elem.location + m_sheetOffset );
// If last symbols are ".sChDoC", change them to ".kicad_sch" // If last symbols are ".sChDoC", change them to ".kicad_sch"
if( ( elem.text.Right( GetFileExtension().length() + 1 ).Lower() ) == ( "." + GetFileExtension().Lower() )) if( ( elem.text.Right( GetFileExtension().length() + 1 ).Lower() )
== ( "." + GetFileExtension().Lower() ) )
{ {
elem.text.RemoveLast( GetFileExtension().length() ); elem.text.RemoveLast( GetFileExtension().length() );
elem.text += KiCadSchematicFileExtension; elem.text += KiCadSchematicFileExtension;
@ -2153,8 +2097,9 @@ void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map<wxString, wxString>& aPr
{ {
ASCH_DESIGNATOR elem( aProperties ); ASCH_DESIGNATOR elem( aProperties );
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() )
if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
m_reporter->Report( wxString::Format( _( "Designator has non-existent ownerindex %d." ), m_reporter->Report( wxString::Format( _( "Designator has non-existent ownerindex %d." ),
@ -2163,14 +2108,13 @@ void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map<wxString, wxString>& aPr
return; return;
} }
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
SCH_SHEET_PATH sheetpath; SCH_SHEET_PATH sheetpath;
m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath ); m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath );
component->SetRef( &sheetpath, elem.text ); symbol->SetRef( &sheetpath, elem.text );
SCH_FIELD* refField = component->GetField( REFERENCE_FIELD ); SCH_FIELD* refField = symbol->GetField( REFERENCE_FIELD );
refField->SetPosition( elem.location + m_sheetOffset ); refField->SetPosition( elem.location + m_sheetOffset );
refField->SetVisible( true ); refField->SetVisible( true );
@ -2230,29 +2174,31 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map<wxString, wxString>& aPro
} }
else else
{ {
const auto& symbol = m_symbols.find( elem.ownerindex ); const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex );
if( symbol == m_symbols.end() )
if( libSymbolIt == m_libSymbols.end() )
{ {
// TODO: e.g. can depend on Template (RECORD=39 // TODO: e.g. can depend on Template (RECORD=39
return; return;
} }
const auto& component = m_components.at( symbol->first ); SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first );
// TODO: location not correct? // TODO: location not correct?
const wxPoint position = elem.location + m_sheetOffset; const wxPoint position = elem.location + m_sheetOffset;
SCH_FIELD* field = nullptr; SCH_FIELD* field = nullptr;
if( elem.name == "Comment" ) if( elem.name == "Comment" )
{ {
field = component->GetField( VALUE_FIELD ); field = symbol->GetField( VALUE_FIELD );
field->SetPosition( position ); field->SetPosition( position );
} }
else else
{ {
int fieldIdx = component->GetFieldCount(); int fieldIdx = symbol->GetFieldCount();
wxString fieldName = elem.name.IsSameAs( "Value", false ) ? "Altium_Value" : elem.name; wxString fieldName = elem.name.IsSameAs( "Value", false ) ? "Altium_Value" : elem.name;
field = component->AddField( { position, fieldIdx, component, fieldName } ); field = symbol->AddField( { position, fieldIdx, symbol, fieldName } );
} }
wxString kicadText = AltiumSpecialStringsToKiCadVariables( elem.text, stringReplacement ); wxString kicadText = AltiumSpecialStringsToKiCadVariables( elem.text, stringReplacement );

View File

@ -155,9 +155,9 @@ private:
wxPoint m_sheetOffset; wxPoint m_sheetOffset;
std::unique_ptr<ASCH_SHEET> m_altiumSheet; std::unique_ptr<ASCH_SHEET> m_altiumSheet;
std::map<int, SCH_SYMBOL*> m_components; std::map<int, SCH_SYMBOL*> m_symbols;
std::map<int, SCH_SHEET*> m_sheets; std::map<int, SCH_SHEET*> m_sheets;
std::map<int, LIB_SYMBOL*> m_symbols; // every component has its unique symbol std::map<int, LIB_SYMBOL*> m_libSymbols; // every symbol has its unique lib_symbol
std::map<wxString, LIB_SYMBOL*> m_powerSymbols; std::map<wxString, LIB_SYMBOL*> m_powerSymbols;
std::vector<ASCH_STORAGE_FILE> m_altiumStorage; std::vector<ASCH_STORAGE_FILE> m_altiumStorage;