From 26df39e71a2ecb36aadd0e57581a118eaf3f6d3c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 5 Jul 2021 10:51:15 +0100 Subject: [PATCH] Naming conventions. --- .../sch_plugins/altium/sch_altium_plugin.cpp | 368 ++++++++---------- .../sch_plugins/altium/sch_altium_plugin.h | 4 +- 2 files changed, 159 insertions(+), 213 deletions(-) diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index c17abf288b..9f7f74d3dc 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -41,7 +41,6 @@ #include #include -#include #include #include #include @@ -489,17 +488,17 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader THROW_IO_ERROR( "stream is not fully parsed" ); // assign LIB_SYMBOL -> COMPONENT - for( auto component : m_components ) + for( std::pair& symbol : m_symbols ) { - auto ksymbol = m_symbols.find( component.first ); + auto libSymbolIt = m_libSymbols.find( symbol.first ); - if( ksymbol == m_symbols.end() ) - THROW_IO_ERROR( "every component should have a symbol attached" ); + if( libSymbolIt == m_libSymbols.end() ) + THROW_IO_ERROR( "every symbol should have a symbol attached" ); - m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_SYMBOL( *( ksymbol->second ) ), - m_properties.get() ); + m_pi->SaveSymbol( getLibFileName().GetFullPath(), + new LIB_SYMBOL( *( libSymbolIt->second ) ), m_properties.get() ); - component.second->SetLibSymbol( ksymbol->second ); + symbol.second->SetLibSymbol( libSymbolIt->second ); } // Handle title blocks @@ -512,8 +511,8 @@ void SCH_ALTIUM_PLUGIN::ParseFileHeader( const CFB::CompoundFileReader& aReader m_altiumPortsCurrentSheet.clear(); - m_components.clear(); m_symbols.clear(); + m_libSymbols.clear(); // Otherwise we cannot save the imported sheet? 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 ) { if( file.filename.IsSameAs( aFilename ) ) - { return &file; - } if( file.filename.EndsWith( aFilename ) ) - { nonExactMatch = &file; - } } return nonExactMatch; @@ -569,7 +564,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex, ksymbol->SetName( name ); ksymbol->SetDescription( elem.componentdescription ); ksymbol->SetLibId( libId ); - m_symbols.insert( { aIndex, ksymbol } ); + m_libSymbols.insert( { aIndex, ksymbol } ); // each component has its own symbol for now SCH_SYMBOL* symbol = new SCH_SYMBOL(); @@ -583,7 +578,7 @@ void SCH_ALTIUM_PLUGIN::ParseComponent( int aIndex, 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& aPropertie { 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 m_reporter->Report( wxString::Format( _( "Pin has non-existent ownerindex %d." ), @@ -605,10 +600,9 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) return; - const auto& component = m_components.at( symbol->first ); - - LIB_PIN* pin = new LIB_PIN( symbol->second ); - symbol->second->AddDrawItem( pin ); + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); + LIB_PIN* pin = new LIB_PIN( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( pin ); pin->SetUnit( elem.ownerpartid ); @@ -648,9 +642,9 @@ void SCH_ALTIUM_PLUGIN::ParsePin( const std::map& aPropertie } // 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? - // pin->SetPosition( GetRelativePosition( elem.kicadLocation, component ) ); + // pin->SetPosition( GetRelativePosition( elem.kicadLocation, symbol ) ); switch( elem.electrical ) { @@ -806,9 +800,9 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert } 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 m_reporter->Report( wxString::Format( _( "Label has non-existent ownerindex %d." ), @@ -817,14 +811,13 @@ void SCH_ALTIUM_PLUGIN::ParseLabel( const std::map& aPropert return; } - const auto& component = m_components.at( symbol->first ); - - LIB_TEXT* text = new LIB_TEXT( symbol->second ); - symbol->second->AddDrawItem( text ); + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); + LIB_TEXT* text = new LIB_TEXT( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( text ); text->SetUnit( elem.ownerpartid ); - text->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, component ) ); + text->SetPosition( GetRelativePosition( elem.location + m_sheetOffset, symbol ) ); text->SetText( elem.text ); SetEdaTextJustification( text, elem.justification ); @@ -876,10 +869,9 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper // simulate bezier using line segments std::vector bezierPoints; std::vector polyPoints; + for( size_t j = i; j < elem.points.size() && j < i + 4; j++ ) - { bezierPoints.push_back( elem.points.at( j ) + m_sheetOffset ); - } BEZIER_POLY converter( bezierPoints ); converter.GetPoly( polyPoints ); @@ -900,9 +892,9 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper } 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 m_reporter->Report( wxString::Format( _( "Bezier has non-existent ownerindex %d." ), @@ -914,22 +906,22 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) 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 ) { if( i + 2 == elem.points.size() ) { // special case: single line - LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); - symbol->second->AddDrawItem( line ); + LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( line ); line->SetUnit( elem.ownerpartid ); for( size_t j = i; j < elem.points.size() && j < i + 2; j++ ) { line->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset, - component ) ); + symbol ) ); } line->SetWidth( elem.lineWidth ); @@ -937,15 +929,15 @@ void SCH_ALTIUM_PLUGIN::ParseBezier( const std::map& aProper else { // bezier always has maximum of 4 control points - LIB_BEZIER* bezier = new LIB_BEZIER( symbol->second ); - symbol->second->AddDrawItem( bezier ); + LIB_BEZIER* bezier = new LIB_BEZIER( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( bezier ); bezier->SetUnit( elem.ownerpartid ); for( size_t j = i; j < elem.points.size() && j < i + 4; j++ ) { bezier->AddPoint( GetRelativePosition( elem.points.at( j ) + m_sheetOffset, - component ) ); + symbol ) ); } bezier->SetWidth( elem.lineWidth ); @@ -986,8 +978,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map& aProp } else { - const auto& symbol = m_symbols.find( elem.ownerindex ); - if( symbol == m_symbols.end() ) + const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex ); + + if( libSymbolIt == m_libSymbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 m_reporter->Report( wxString::Format( _( "Polyline has non-existent ownerindex %d." ), @@ -999,16 +992,15 @@ void SCH_ALTIUM_PLUGIN::ParsePolyline( const std::map& aProp if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) return; - const auto& component = m_components.at( symbol->first ); - - LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); - symbol->second->AddDrawItem( line ); + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); + LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( line ); line->SetUnit( elem.ownerpartid ); for( wxPoint& point : elem.points ) { - line->AddPoint( GetRelativePosition( point + m_sheetOffset, component ) ); + line->AddPoint( GetRelativePosition( point + m_sheetOffset, symbol ) ); } line->SetWidth( elem.lineWidth ); @@ -1025,8 +1017,8 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map& aPrope // TODO: we cannot fill this polygon, only draw it for now for( size_t i = 0; i + 1 < elem.points.size(); i++ ) { - SCH_LINE* line = - new SCH_LINE( elem.points.at( i ) + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES ); + SCH_LINE* line = new SCH_LINE( elem.points.at( i ) + m_sheetOffset, + SCH_LAYER_ID::LAYER_NOTES ); line->SetEndPoint( elem.points.at( i + 1 ) + m_sheetOffset ); line->SetLineWidth( elem.lineWidth ); line->SetLineStyle( PLOT_DASH_TYPE::SOLID ); @@ -1036,8 +1028,8 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map& aPrope } // close polygon - SCH_LINE* line = - new SCH_LINE( elem.points.front() + m_sheetOffset, SCH_LAYER_ID::LAYER_NOTES ); + SCH_LINE* line = new SCH_LINE( elem.points.front() + m_sheetOffset, + SCH_LAYER_ID::LAYER_NOTES ); line->SetEndPoint( elem.points.back() + m_sheetOffset ); line->SetLineWidth( elem.lineWidth ); line->SetLineStyle( PLOT_DASH_TYPE::SOLID ); @@ -1047,9 +1039,9 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map& aPrope } 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 m_reporter->Report( wxString::Format( _( "Polygon has non-existent ownerindex %d." ), @@ -1061,17 +1053,16 @@ void SCH_ALTIUM_PLUGIN::ParsePolygon( const std::map& aPrope if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) return; - const auto& component = m_components.at( symbol->first ); - - LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); - symbol->second->AddDrawItem( line ); + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); + LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( line ); line->SetUnit( elem.ownerpartid ); 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 ); @@ -1129,9 +1120,9 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map& } 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 m_reporter->Report( wxString::Format( _( "Rounded rectangle has non-existent " @@ -1144,16 +1135,15 @@ void SCH_ALTIUM_PLUGIN::ParseRoundRectangle( const std::map& if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) return; - const auto& component = m_components.at( symbol->first ); - + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); // TODO: misses rounded edges - LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second ); - symbol->second->AddDrawItem( rect ); + LIB_RECTANGLE* rect = new LIB_RECTANGLE( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( rect ); rect->SetUnit( elem.ownerpartid ); - rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, component ) ); - rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, component ) ); + rect->SetPosition( GetRelativePosition( elem.topRight + m_sheetOffset, symbol ) ); + rect->SetEnd( GetRelativePosition( elem.bottomLeft + m_sheetOffset, symbol ) ); rect->SetWidth( elem.lineWidth ); if( !elem.isSolid ) @@ -1177,8 +1167,8 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map& aPropertie } else { - const auto& symbol = m_symbols.find( elem.ownerindex ); - if( symbol == m_symbols.end() ) + const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex ); + if( libSymbolIt == m_libSymbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 m_reporter->Report( wxString::Format( _( "Arc has non-existent ownerindex %d." ), @@ -1190,28 +1180,28 @@ void SCH_ALTIUM_PLUGIN::ParseArc( const std::map& aPropertie if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) 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 ) ) { - LIB_CIRCLE* circle = new LIB_CIRCLE( symbol->second ); - symbol->second->AddDrawItem( circle ); + LIB_CIRCLE* circle = new LIB_CIRCLE( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( circle ); 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->SetWidth( elem.lineWidth ); } else { - LIB_ARC* arc = new LIB_ARC( symbol->second ); - symbol->second->AddDrawItem( arc ); + LIB_ARC* arc = new LIB_ARC( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( arc ); arc->SetUnit( elem.ownerpartid ); // TODO: correct? - arc->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, component ) ); + arc->SetPosition( GetRelativePosition( elem.center + m_sheetOffset, symbol ) ); arc->SetRadius( elem.radius ); arc->SetFirstRadiusAngle( elem.startAngle * 10. ); arc->SetSecondRadiusAngle( elem.endAngle * 10. ); @@ -1237,9 +1227,9 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map& aProperti } 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 m_reporter->Report( wxString::Format( _( "Line has non-existent ownerindex %d." ), @@ -1251,15 +1241,14 @@ void SCH_ALTIUM_PLUGIN::ParseLine( const std::map& aProperti if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) return; - const auto& component = m_components.at( symbol->first ); - - LIB_POLYLINE* line = new LIB_POLYLINE( symbol->second ); - symbol->second->AddDrawItem( line ); + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); + LIB_POLYLINE* line = new LIB_POLYLINE( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( line ); line->SetUnit( elem.ownerpartid ); - line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, component ) ); - line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, component ) ); + line->AddPoint( GetRelativePosition( elem.point1 + m_sheetOffset, symbol ) ); + line->AddPoint( GetRelativePosition( elem.point2 + m_sheetOffset, symbol ) ); line->SetWidth( elem.lineWidth ); } @@ -1309,9 +1298,9 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map& aPro } 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 m_reporter->Report( wxString::Format( _( "Rectangle has non-existent ownerindex %d." ), @@ -1323,15 +1312,14 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map& aPro if( !IsComponentPartVisible( elem.ownerindex, elem.ownerpartdisplaymode ) ) return; - const auto& component = m_components.at( symbol->first ); - - LIB_RECTANGLE* rect = new LIB_RECTANGLE( symbol->second ); - symbol->second->AddDrawItem( rect ); + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); + LIB_RECTANGLE* rect = new LIB_RECTANGLE( libSymbolIt->second ); + libSymbolIt->second->AddDrawItem( rect ); rect->SetUnit( elem.ownerpartid ); - rect->SetPosition( GetRelativePosition( sheetTopRight, component ) ); - rect->SetEnd( GetRelativePosition( sheetBottomLeft, component ) ); + rect->SetPosition( GetRelativePosition( sheetTopRight, symbol ) ); + rect->SetEnd( GetRelativePosition( sheetBottomLeft, symbol ) ); rect->SetWidth( elem.lineWidth ); if( !elem.isSolid ) @@ -1344,8 +1332,8 @@ void SCH_ALTIUM_PLUGIN::ParseRectangle( const std::map& aPro } -void SCH_ALTIUM_PLUGIN::ParseSheetSymbol( - int aIndex, const std::map& aProperties ) +void SCH_ALTIUM_PLUGIN::ParseSheetSymbol( int aIndex, const std::map& 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& 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; - - const auto& symbol = m_powerSymbols.find( elem.text ); - if( symbol != m_powerSymbols.end() ) + if( powerSymbolIt != m_powerSymbols.end() ) { - ksymbol = symbol->second; // cache hit + libSymbol = powerSymbolIt->second; // cache hit } else { - ksymbol = new LIB_SYMBOL( wxEmptyString ); - ksymbol->SetPower(); - ksymbol->SetName( elem.text ); - ksymbol->GetReferenceField().SetText( "#PWR" ); - ksymbol->GetValueField().SetText( elem.text ); - ksymbol->GetValueField().SetVisible( true ); // TODO: why does this not work? - ksymbol->SetDescription( - wxString::Format( _( "Power symbol creates a global label with name '%s'" ), - elem.text ) ); - ksymbol->SetKeyWords( "power-flag" ); - ksymbol->SetLibId( libId ); + libSymbol = new LIB_SYMBOL( wxEmptyString ); + libSymbol->SetPower(); + libSymbol->SetName( elem.text ); + 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 " + "label with name '%s'" ), elem.text ) ); + libSymbol->SetKeyWords( "power-flag" ); + libSymbol->SetLibId( libId ); // generate graphic - LIB_PIN* pin = new LIB_PIN( ksymbol ); - ksymbol->AddDrawItem( pin ); + LIB_PIN* pin = new LIB_PIN( libSymbol ); + libSymbol->AddDrawItem( pin ); pin->SetName( elem.text ); pin->SetPosition( { 0, 0 } ); @@ -1679,52 +1665,52 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN ); 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! - m_pi->SaveSymbol( getLibFileName().GetFullPath(), ksymbol, m_properties.get() ); - m_powerSymbols.insert( { elem.text, ksymbol } ); + m_pi->SaveSymbol( getLibFileName().GetFullPath(), libSymbol, m_properties.get() ); + m_powerSymbols.insert( { elem.text, libSymbol } ); } SCH_SHEET_PATH sheetpath; m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath ); - // each component has its own symbol for now - SCH_SYMBOL* component = new SCH_SYMBOL(); - component->SetRef( &sheetpath, "#PWR?" ); - component->SetValue( elem.text ); - component->SetLibId( libId ); - component->SetLibSymbol( new LIB_SYMBOL( *ksymbol ) ); + // each symbol has its own powerSymbolIt for now + SCH_SYMBOL* symbol = new SCH_SYMBOL(); + symbol->SetRef( &sheetpath, "#PWR?" ); + symbol->SetValue( elem.text ); + symbol->SetLibId( libId ); + 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? 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 ) { 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->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_LEFT ); break; 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->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER ); break; 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->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_RIGHT ); break; 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->SetHorizJustify( EDA_TEXT_HJUSTIFY_T::GR_TEXT_HJUSTIFY_CENTER ); break; @@ -1733,7 +1719,7 @@ void SCH_ALTIUM_PLUGIN::ParsePowerPort( const std::map& aPro break; } - m_currentSheet->GetScreen()->Append( component ); + m_currentSheet->GetScreen()->Append( symbol ); } @@ -2006,63 +1992,28 @@ void SCH_ALTIUM_PLUGIN::ParseSheet( const std::map& aPropert PAGE_INFO pageInfo; bool isPortrait = m_altiumSheet->sheetOrientation == ASCH_SHEET_WORKSPACEORIENTATION::PORTRAIT; + switch( m_altiumSheet->sheetSize ) { default: - case ASCH_SHEET_SIZE::A4: - pageInfo.SetType( "A4", isPortrait ); - break; - case ASCH_SHEET_SIZE::A3: - pageInfo.SetType( "A3", isPortrait ); - break; - case ASCH_SHEET_SIZE::A2: - pageInfo.SetType( "A2", isPortrait ); - break; - case ASCH_SHEET_SIZE::A1: - pageInfo.SetType( "A1", isPortrait ); - break; - case ASCH_SHEET_SIZE::A0: - pageInfo.SetType( "A0", isPortrait ); - break; - case ASCH_SHEET_SIZE::A: - pageInfo.SetType( "A", 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; + case ASCH_SHEET_SIZE::A4: pageInfo.SetType( "A4", isPortrait ); break; + case ASCH_SHEET_SIZE::A3: pageInfo.SetType( "A3", isPortrait ); break; + case ASCH_SHEET_SIZE::A2: pageInfo.SetType( "A2", isPortrait ); break; + case ASCH_SHEET_SIZE::A1: pageInfo.SetType( "A1", isPortrait ); break; + case ASCH_SHEET_SIZE::A0: pageInfo.SetType( "A0", isPortrait ); break; + case ASCH_SHEET_SIZE::A: pageInfo.SetType( "A", 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 ); 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 ); @@ -2076,18 +2027,10 @@ void SetFieldOrientation( SCH_FIELD& aField, ASCH_RECORD_ORIENTATION aOrientatio switch( aOrientation ) { default: - case ASCH_RECORD_ORIENTATION::RIGHTWARDS: - aField.SetTextAngle( 0 ); - break; - case ASCH_RECORD_ORIENTATION::UPWARDS: - aField.SetTextAngle( 900 ); - break; - case ASCH_RECORD_ORIENTATION::LEFTWARDS: - aField.SetTextAngle( 1800 ); - break; - case ASCH_RECORD_ORIENTATION::DOWNWARDS: - aField.SetTextAngle( 2700 ); - break; + case ASCH_RECORD_ORIENTATION::RIGHTWARDS: aField.SetTextAngle( 0 ); break; + case ASCH_RECORD_ORIENTATION::UPWARDS: 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& aProp filenameField.SetPosition( elem.location + m_sheetOffset ); // 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 += KiCadSchematicFileExtension; @@ -2153,8 +2097,9 @@ void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map& aPr { ASCH_DESIGNATOR elem( aProperties ); - const auto& symbol = m_symbols.find( elem.ownerindex ); - if( symbol == m_symbols.end() ) + const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex ); + + if( libSymbolIt == m_libSymbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 m_reporter->Report( wxString::Format( _( "Designator has non-existent ownerindex %d." ), @@ -2163,14 +2108,13 @@ void SCH_ALTIUM_PLUGIN::ParseDesignator( const std::map& aPr return; } - const auto& component = m_components.at( symbol->first ); - + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); SCH_SHEET_PATH 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->SetVisible( true ); @@ -2230,29 +2174,31 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map& aPro } else { - const auto& symbol = m_symbols.find( elem.ownerindex ); - if( symbol == m_symbols.end() ) + const auto& libSymbolIt = m_libSymbols.find( elem.ownerindex ); + + if( libSymbolIt == m_libSymbols.end() ) { // TODO: e.g. can depend on Template (RECORD=39 return; } - const auto& component = m_components.at( symbol->first ); + SCH_SYMBOL* symbol = m_symbols.at( libSymbolIt->first ); // TODO: location not correct? const wxPoint position = elem.location + m_sheetOffset; SCH_FIELD* field = nullptr; + if( elem.name == "Comment" ) { - field = component->GetField( VALUE_FIELD ); + field = symbol->GetField( VALUE_FIELD ); field->SetPosition( position ); } else { - int fieldIdx = component->GetFieldCount(); + int fieldIdx = symbol->GetFieldCount(); 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 ); diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.h b/eeschema/sch_plugins/altium/sch_altium_plugin.h index 146a61d343..e5cc12b527 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.h +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.h @@ -155,9 +155,9 @@ private: wxPoint m_sheetOffset; std::unique_ptr m_altiumSheet; - std::map m_components; + std::map m_symbols; std::map m_sheets; - std::map m_symbols; // every component has its unique symbol + std::map m_libSymbols; // every symbol has its unique lib_symbol std::map m_powerSymbols; std::vector m_altiumStorage;