Commit e7d2b9b4 authored by jean-pierre charras's avatar jean-pierre charras

Add the environment variable KYSYS3DMOD to define a default path for 3D models.

If it is not defined by user, it is set to a legacy 3D files path.
The default value needs to be fixed on MACOSX.
This change could be better, but it is compatible with environment variables and the old way ( defined search paths) to find 3D shape files.
3D shapes files names can  also include an environment variable definition, like libraries names.
However using KYSYS3DMOD in these names is not required.
If the 3D filename is a legacy name, KYSYS3DMOD is automatically used as default path.
parents 6a9771f2 fff54d75
......@@ -59,6 +59,39 @@ S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster,
}
}
const wxString S3D_MASTER::GetShape3DFullFilename()
{
wxString shapeName;
// Expand any environment variables embedded in footprint's m_Shape3DName field.
// To ensure compatibility with most of footprint's m_Shape3DName field,
// if the m_Shape3DName is not an absolute path the default path
// given by the environment variable KISYS3DMOD will be used
if( m_Shape3DName.StartsWith( wxT("${") ) )
shapeName = wxExpandEnvVars( m_Shape3DName );
else
shapeName = m_Shape3DName;
wxFileName fn( shapeName );
if( fn.IsAbsolute() || shapeName.StartsWith( wxT(".") ) )
return shapeName;
wxString default_path;
wxGetEnv( wxT( KISYS3DMOD ), &default_path );
if( default_path.IsEmpty() )
return shapeName;
if( !default_path.EndsWith( wxT("/") ) && !default_path.EndsWith( wxT("\\") ) )
default_path += wxT("/");
default_path += shapeName;
return default_path;
}
int S3D_MASTER::ReadData()
{
......@@ -67,8 +100,7 @@ int S3D_MASTER::ReadData()
return 1;
}
// Expand any environment variables embedded in footprint's m_Shape3DName field.
wxString filename = wxExpandEnvVars( m_Shape3DName );
wxString filename = GetShape3DFullFilename();
#ifdef __WINDOWS__
filename.Replace( wxT( "/" ), wxT( "\\" ) );
......
......@@ -144,6 +144,14 @@ public:
return m_Shape3DName;
}
/**
* Function GetShape3DFullFilename
* @return the full filename of the 3D shape,
* expanding environment variable (if any ) and/or adding default 3D path
* given by environment variable KISYS3DMOD
*/
const wxString GetShape3DFullFilename();
void SetShape3DName( const wxString& aShapeName );
};
......
......@@ -48,6 +48,9 @@
# include <GL/glu.h>
#endif
#define KISYS3DMOD "KISYS3DMOD"
#include <3d_struct.h>
class EDA_3D_CANVAS;
......
......@@ -1196,3 +1196,69 @@ bool EDA_APP::SetFootprintLibTablePath()
return false;
}
/**
* Function Set3DShapesPath
* attempts set the environment variable given by aKiSys3Dmod to a valid path.
* (typically "KISYS3DMOD" )
* If the environment variable is already set,
* then it left as is to respect the wishes of the user.
*
* The path is determined by attempting to find the path modules/packages3d
* files in kicad tree.
* This may or may not be the best path but it provides the best solution for
* backwards compatibility with the previous 3D shapes search path implementation.
*
* @note This must be called after #SetBinDir() is called at least on Windows.
* Otherwise, the kicad path is not known (Windows specific)
*
* @param aKiSys3Dmod = the value of environment variable, typically "KISYS3DMOD"
* @return false if the aKiSys3Dmod path is not valid.
*/
bool EDA_APP::Set3DShapesPath( const wxString& aKiSys3Dmod )
{
wxString path;
// Set the KISYS3DMOD environment variable for the current process,
// if it is not already defined in the user's environment and valid.
if( wxGetEnv( aKiSys3Dmod, &path ) && wxFileName::DirExists( path ) )
return true;
// Attempt to determine where the 3D shape libraries were installed using the
// legacy path:
// on Unix: /usr/local/kicad/share/modules/packages3d
// or /usr/share/kicad/modules/packages3d
// On Windows: bin../share/modules/packages3d
wxString relpath( wxT( "modules/packages3d" ) );
// Apple MacOSx
#ifdef __APPLE__
// TO DO
#elif defined(__UNIX__) // Linux and non-Apple Unix
path = wxT("/usr/local/kicad/share/") + relpath;
if( wxFileName::DirExists( path ) )
{
wxSetEnv( aKiSys3Dmod, path );
return true;
}
path = wxT("/usr/share/kicad/") + relpath;
if( wxFileName::DirExists( path ) )
{
wxSetEnv( aKiSys3Dmod, path );
return true;
}
#else // Windows
path = m_BinDir + wxT("../share/") + relpath;
if( wxFileName::DirExists( path ) )
{
wxSetEnv( aKiSys3Dmod, path );
return true;
}
#endif
return false;
}
......@@ -33,6 +33,7 @@
#include <confirm.h>
#include <gestfich.h>
#include <3d_viewer.h>
#include <cvpcb.h>
#include <zones.h>
#include <cvpcb_mainframe.h>
......@@ -102,6 +103,9 @@ bool EDA_APP::OnInit()
SetFootprintLibTablePath();
// Set 3D shape path from environment variable KISYS3DMOD
Set3DShapesPath( wxT(KISYS3DMOD) );
if( m_Checker && m_Checker->IsAnotherRunning() )
{
if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) )
......
......@@ -456,6 +456,26 @@ public:
*/
bool SetFootprintLibTablePath();
/**
* Function Set3DShapesPath
* attempts set the environment variable given by aKiSys3Dmod to a valid path.
* (typically "KISYS3DMOD" )
* If the environment variable is already set,
* then it left as is to respect the wishes of the user.
*
* The path is determined by attempting to find the path modules/packages3d
* files in kicad tree.
* This may or may not be the best path but it provides the best solution for
* backwards compatibility with the previous 3D shapes search path implementation.
*
* @note This must be called after #SetBinDir() is called at least on Windows.
* Otherwise, the kicad path is not known (Windows specific)
*
* @param aKiSys3Dmod = the value of environment variable, typically "KISYS3DMOD"
* @return false if the aKiSys3Dmod path is not valid.
*/
bool Set3DShapesPath( const wxString& aKiSys3Dmod );
const wxString& GetModuleLibraryNickname() { return m_module_nickname; }
void SetModuleLibraryNickname( const wxString& aNickname ) { m_module_nickname = aNickname; }
};
......
......@@ -1154,8 +1154,7 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule
if( !vrmlm->Is3DType( S3D_MASTER::FILE3D_VRML ) )
continue;
// expand environment variables
wxString fname = wxExpandEnvVars( vrmlm->GetShape3DName() );
wxString fname = vrmlm->GetShape3DFullFilename();
fname.Replace( wxT( "\\" ), wxT( "/" ) );
wxString source_fname = fname;
......
......@@ -42,6 +42,7 @@
#include <pcbcommon.h>
#include <colors_selection.h>
#include <gr_basic.h>
#include <3d_viewer.h>
#include <wx/stdpaths.h>
#include <wx/file.h>
......@@ -168,10 +169,10 @@ bool EDA_APP::OnInit()
bundledir.RemoveLastDir();
// Prepend in PYTHONPATH the content of the bundle libraries !
wxSetEnv("PYTHONPATH",((wxGetenv("PYTHONPATH") != NULL ) ? (wxString(wxGetenv("PYTHONPATH")) + ":") : wxString(""))
+ bundledir.GetPath() +
wxSetEnv("PYTHONPATH",((wxGetenv("PYTHONPATH") != NULL ) ? (wxString(wxGetenv("PYTHONPATH")) + ":") : wxString(""))
+ bundledir.GetPath() +
"/Frameworks/wxPython/lib/python2.6/site-packages/wx-3.0-osx_cocoa" );
#endif
#endif
#endif
// On linux and osx, 2 others paths are
// [HOME]/.kicad_plugins/
......@@ -233,6 +234,9 @@ bool EDA_APP::OnInit()
// Set any environment variables before loading FP_LIB_TABLE
SetFootprintLibTablePath();
// Set 3D shape path from environment variable KISYS3DMOD
Set3DShapesPath( wxT(KISYS3DMOD) );
frame = new PCB_EDIT_FRAME( NULL, wxT( "Pcbnew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
#ifdef KICAD_SCRIPTING
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment