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

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

parent 6a9771f2
...@@ -59,6 +59,39 @@ S3D_MODEL_PARSER* S3D_MODEL_PARSER::Create( S3D_MASTER* aMaster, ...@@ -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() int S3D_MASTER::ReadData()
{ {
...@@ -67,8 +100,7 @@ int S3D_MASTER::ReadData() ...@@ -67,8 +100,7 @@ int S3D_MASTER::ReadData()
return 1; return 1;
} }
// Expand any environment variables embedded in footprint's m_Shape3DName field. wxString filename = GetShape3DFullFilename();
wxString filename = wxExpandEnvVars( m_Shape3DName );
#ifdef __WINDOWS__ #ifdef __WINDOWS__
filename.Replace( wxT( "/" ), wxT( "\\" ) ); filename.Replace( wxT( "/" ), wxT( "\\" ) );
......
...@@ -144,6 +144,14 @@ public: ...@@ -144,6 +144,14 @@ public:
return m_Shape3DName; 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 ); void SetShape3DName( const wxString& aShapeName );
}; };
......
...@@ -48,6 +48,9 @@ ...@@ -48,6 +48,9 @@
# include <GL/glu.h> # include <GL/glu.h>
#endif #endif
#define KISYS3DMOD "KISYS3DMOD"
#include <3d_struct.h> #include <3d_struct.h>
class EDA_3D_CANVAS; class EDA_3D_CANVAS;
......
...@@ -1196,3 +1196,69 @@ bool EDA_APP::SetFootprintLibTablePath() ...@@ -1196,3 +1196,69 @@ bool EDA_APP::SetFootprintLibTablePath()
return false; 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 @@ ...@@ -33,6 +33,7 @@
#include <confirm.h> #include <confirm.h>
#include <gestfich.h> #include <gestfich.h>
#include <3d_viewer.h>
#include <cvpcb.h> #include <cvpcb.h>
#include <zones.h> #include <zones.h>
#include <cvpcb_mainframe.h> #include <cvpcb_mainframe.h>
...@@ -102,6 +103,9 @@ bool EDA_APP::OnInit() ...@@ -102,6 +103,9 @@ bool EDA_APP::OnInit()
SetFootprintLibTablePath(); SetFootprintLibTablePath();
// Set 3D shape path from environment variable KISYS3DMOD
Set3DShapesPath( wxT(KISYS3DMOD) );
if( m_Checker && m_Checker->IsAnotherRunning() ) if( m_Checker && m_Checker->IsAnotherRunning() )
{ {
if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) ) if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) )
......
...@@ -456,6 +456,26 @@ public: ...@@ -456,6 +456,26 @@ public:
*/ */
bool SetFootprintLibTablePath(); 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; } const wxString& GetModuleLibraryNickname() { return m_module_nickname; }
void SetModuleLibraryNickname( const wxString& aNickname ) { m_module_nickname = aNickname; } 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 ...@@ -1154,8 +1154,7 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule
if( !vrmlm->Is3DType( S3D_MASTER::FILE3D_VRML ) ) if( !vrmlm->Is3DType( S3D_MASTER::FILE3D_VRML ) )
continue; continue;
// expand environment variables wxString fname = vrmlm->GetShape3DFullFilename();
wxString fname = wxExpandEnvVars( vrmlm->GetShape3DName() );
fname.Replace( wxT( "\\" ), wxT( "/" ) ); fname.Replace( wxT( "\\" ), wxT( "/" ) );
wxString source_fname = fname; wxString source_fname = fname;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <pcbcommon.h> #include <pcbcommon.h>
#include <colors_selection.h> #include <colors_selection.h>
#include <gr_basic.h> #include <gr_basic.h>
#include <3d_viewer.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/file.h> #include <wx/file.h>
...@@ -168,10 +169,10 @@ bool EDA_APP::OnInit() ...@@ -168,10 +169,10 @@ bool EDA_APP::OnInit()
bundledir.RemoveLastDir(); bundledir.RemoveLastDir();
// Prepend in PYTHONPATH the content of the bundle libraries ! // Prepend in PYTHONPATH the content of the bundle libraries !
wxSetEnv("PYTHONPATH",((wxGetenv("PYTHONPATH") != NULL ) ? (wxString(wxGetenv("PYTHONPATH")) + ":") : wxString("")) wxSetEnv("PYTHONPATH",((wxGetenv("PYTHONPATH") != NULL ) ? (wxString(wxGetenv("PYTHONPATH")) + ":") : wxString(""))
+ bundledir.GetPath() + + bundledir.GetPath() +
"/Frameworks/wxPython/lib/python2.6/site-packages/wx-3.0-osx_cocoa" ); "/Frameworks/wxPython/lib/python2.6/site-packages/wx-3.0-osx_cocoa" );
#endif #endif
#endif #endif
// On linux and osx, 2 others paths are // On linux and osx, 2 others paths are
// [HOME]/.kicad_plugins/ // [HOME]/.kicad_plugins/
...@@ -233,6 +234,9 @@ bool EDA_APP::OnInit() ...@@ -233,6 +234,9 @@ bool EDA_APP::OnInit()
// Set any environment variables before loading FP_LIB_TABLE // Set any environment variables before loading FP_LIB_TABLE
SetFootprintLibTablePath(); 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 ) ); frame = new PCB_EDIT_FRAME( NULL, wxT( "Pcbnew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
#ifdef KICAD_SCRIPTING #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