From 79f80c4cd75a41f8363148abd4923dc54f816c9b Mon Sep 17 00:00:00 2001
From: Thomas Pointhuber <thomas.pointhuber@gmx.at>
Date: Sun, 6 Feb 2022 16:23:46 +0100
Subject: [PATCH] altium: Fix Reference and Description parsing of footprint

---
 pcbnew/plugins/altium/altium_pcb.cpp | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp
index 03829dc003..4cf9225265 100644
--- a/pcbnew/plugins/altium/altium_pcb.cpp
+++ b/pcbnew/plugins/altium/altium_pcb.cpp
@@ -685,8 +685,24 @@ FOOTPRINT* ALTIUM_PCB::ParseFootprint( const ALTIUM_COMPOUND_FILE& altiumLibFile
     LIB_ID fpID = AltiumToKiCadLibID( "", footprintName ); // TODO: library name
     footprint->SetFPID( fpID );
 
-    footprint->SetDescription( wxT( "Test Description for " ) + aFootprintName + wxT( " - " ) + footprintName );
-    footprint->SetReference( wxT( "UNK" ) ); // TODO: extract
+    std::string parametersStreamName = aFootprintName.ToStdString() + "\\Parameters";
+    const CFB::COMPOUND_FILE_ENTRY* parametersData =
+            altiumLibFile.FindStream( parametersStreamName );
+    if( parametersData != nullptr )
+    {
+        ALTIUM_PARSER                parametersReader( altiumLibFile, parametersData );
+        std::map<wxString, wxString> parameterProperties = parametersReader.ReadProperties();
+        wxString                     description =
+                ALTIUM_PARSER::ReadString( parameterProperties, wxT( "DESCRIPTION" ), wxT( "" ) );
+        footprint->SetDescription( description );
+    }
+    else
+    {
+        wxLogError( _( "File not found: '%s'." ), parametersStreamName );
+        footprint->SetDescription( wxT( "" ) );
+    }
+
+    footprint->SetReference( wxT( "REF**" ) );
     footprint->SetValue( footprintName );
     footprint->Reference().SetVisible( true ); // TODO: extract visibility information
     footprint->Value().SetVisible( true );
@@ -3414,4 +3430,4 @@ void ALTIUM_PCB::HelperPcpShapeAsFootprintKeepoutRegion( FOOTPRINT*       aFootp
 
     // TODO: zone->SetLocalCoord(); missing?
     aFootprint->Add( zone, ADD_MODE::APPEND );
-}
\ No newline at end of file
+}