Fix 3D model resolution for older boards

Older boards use older 3d model environmental variables.  We need to
support both older environmental variables (if the user has them) as
well as updated environmental variables (if the user only has a single
3d model path)

This updated the environmental resolver to look first in the named
location and then substitute the new location if the old location is not
defined in the environment

Fixes https://gitlab.com/kicad/code/kicad/issues/10674
This commit is contained in:
Seth Hillbrand 2023-01-20 15:57:16 -08:00
parent ed0d57ddf6
commit d8ac53d7b4
1 changed files with 22 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include <kiplatform/app.h> #include <kiplatform/app.h>
#include <project.h> #include <project.h>
#include <common.h> #include <common.h>
#include <env_vars.h>
#include <reporter.h> #include <reporter.h>
#include <macros.h> #include <macros.h>
#include <mutex> #include <mutex>
@ -196,6 +197,27 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject )
strResult += tmp; strResult += tmp;
expanded = true; expanded = true;
} }
// Replace unmatched older variables with current 3d model locations
// If the user has the older model location defined, that will be matched
// first above. But if they do not, this will ensure that their board still
// displays correctly
else if( strVarName.Contains( "KISYS3DMOD") || strVarName.Matches( "KICAD*_3DMODEL_DIR" ) )
{
for( auto& var : ENV_VAR::GetPredefinedEnvVars() )
{
if( var.Matches( "KICAD*_3DMODEL_DIR" ) )
{
const auto value = ENV_VAR::GetEnvVar<wxString>( var );
if( !value )
continue;
strResult += *value;
expanded = true;
break;
}
}
}
else else
{ {
// variable doesn't exist => don't change anything // variable doesn't exist => don't change anything