From cfa26fb706d75b16cf0cebd9bc6716ac695301ea Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sun, 25 Sep 2022 23:40:25 -0400 Subject: [PATCH] Fix footprint relative path resolution for idf/vrml export --- pcbnew/exporters/export_idf.cpp | 15 ++++++++++++++- pcbnew/exporters/exporter_vrml.cpp | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/pcbnew/exporters/export_idf.cpp b/pcbnew/exporters/export_idf.cpp index 7c99b2bb56..f560fa0a49 100644 --- a/pcbnew/exporters/export_idf.cpp +++ b/pcbnew/exporters/export_idf.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -275,6 +276,18 @@ static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD // Reference Designator std::string crefdes = TO_UTF8( aFootprint->Reference().GetShownText() ); + wxString libraryName = aFootprint->GetFPID().GetLibNickname(); + wxString footprintBasePath = wxEmptyString; + + if( aPcb->GetProject() ) + { + const FP_LIB_TABLE_ROW* fpRow = + aPcb->GetProject()->PcbFootprintLibs()->FindRow( libraryName, false ); + + if( fpRow ) + footprintBasePath = fpRow->GetFullURI( true ); + } + if( crefdes.empty() || !crefdes.compare( "~" ) ) { std::string cvalue = TO_UTF8( aFootprint->Value().GetShownText() ); @@ -411,7 +424,7 @@ static void idf_export_footprint( BOARD* aPcb, FOOTPRINT* aFootprint, IDF3_BOARD continue; } - idfFile.Assign( resolver->ResolvePath( sM->m_Filename, wxEmptyString ) ); + idfFile.Assign( resolver->ResolvePath( sM->m_Filename, footprintBasePath ) ); idfExt = idfFile.GetExt(); if( idfExt.Cmp( wxT( "idf" ) ) && idfExt.Cmp( wxT( "IDF" ) ) ) diff --git a/pcbnew/exporters/exporter_vrml.cpp b/pcbnew/exporters/exporter_vrml.cpp index a2326a5afa..2f88318366 100644 --- a/pcbnew/exporters/exporter_vrml.cpp +++ b/pcbnew/exporters/exporter_vrml.cpp @@ -33,6 +33,7 @@ #include "3d_cache/3d_info.h" #include "board.h" #include "board_design_settings.h" +#include #include "fp_shape.h" #include "footprint.h" #include "pad.h" @@ -993,6 +994,19 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream // file contains only the filename of 3D shapes to add to the full vrml scene wxCHECK( aFootprint, /* void */ ); + wxString libraryName = aFootprint->GetFPID().GetLibNickname(); + wxString footprintBasePath = wxEmptyString; + + if( m_board->GetProject() ) + { + const FP_LIB_TABLE_ROW* fpRow = + m_board->GetProject()->PcbFootprintLibs()->FindRow( libraryName, false ); + + if( fpRow ) + footprintBasePath = fpRow->GetFullURI( true ); + } + + // Export pad holes for( PAD* pad : aFootprint->Pads() ) ExportVrmlPadHole( pad ); @@ -1013,7 +1027,7 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream continue; } - SGNODE* mod3d = (SGNODE*) m_Cache3Dmodels->Load( sM->m_Filename, wxEmptyString ); + SGNODE* mod3d = (SGNODE*) m_Cache3Dmodels->Load( sM->m_Filename, footprintBasePath ); if( nullptr == mod3d ) {