Commit 5a38d2b6 authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Rework on env. variable KISYS3DMOD. Until now, was used in different files...

Rework on env. variable KISYS3DMOD. Until now, was used in different files using different ways, so no consistency between files.
code cleanup.
parent f0391648
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ const wxString S3D_MASTER::GetShape3DFullFilename()
        return shapeName;

    wxString default_path;
    wxGetEnv( wxT( KISYS3DMOD ), &default_path );
    wxGetEnv( KISYS3DMOD, &default_path );

    if( default_path.IsEmpty() )
        return shapeName;
+7 −2
Original line number Diff line number Diff line
@@ -40,13 +40,18 @@
#include <3d_struct.h>
#include <info3d_visu.h>

#define KISYS3DMOD "KISYS3DMOD"
/// A variable name whose value holds the path of 3D shape files.
/// Currently an environment variable, eventually a project variable.
#define KISYS3DMOD wxT( "KISYS3DMOD" )

/// All 3D files are expected to be stored in LIB3D_FOLDER, or one of
/// its subdirectory.
#define LIB3D_FOLDER  wxT( "packages3d" )

class EDA_3D_CANVAS;
class PCB_BASE_FRAME;

#define KICAD_DEFAULT_3D_DRAWFRAME_STYLE    (wxDEFAULT_FRAME_STYLE | wxWANTS_CHARS)
#define LIB3D_PATH                          wxT( "packages3d" )


class EDA_3D_FRAME : public KIWAY_PLAYER
+109 −30
Original line number Diff line number Diff line
@@ -23,49 +23,128 @@
 */

/*
 * This file contains the global constants and variables used in the PCB
 * applications Pcbnew, CvPcb, and GervView.  The goal of this was to
 * unobfuscate the original header file design that made it very difficult
 * to figure out where these variables lived.  Ideally, they should be pushed
 * back into the application layer.
 * This file contains some functions used in the PCB
 * applications Pcbnew and CvPcb.
 */

#include <fctsys.h>
#include <pcbcommon.h>
#include <plot_common.h>
#include <pgm_base.h>
#include <kiface_i.h>

#include <pcbcommon.h>
#include <class_board.h>
#include <class_pad.h>
#include <class_zone_settings.h>
#include <class_board_design_settings.h>
#include <3d_viewer.h>

/**
 * attempts to 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"
 * @param aProcess = the current process
 * @return false if the aKiSys3Dmod path is not valid.
 */
bool Set3DShapesDefaultPath( const wxString& aKiSys3Dmod, const PGM_BASE* aProcess )
{
    wxString    path;

class MODULE;
    // 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;

#if 1
    // Try to find a valid path is standard KiCad paths
    SEARCH_STACK&   search = Kiface().KifaceSearch();
    path = search.FindValidPath( LIB3D_FOLDER );

DISPLAY_OPTIONS DisplayOpt;      // Display options for board items
    if( !path.IsEmpty() )
    {
        wxSetEnv( aKiSys3Dmod, path );
        return true;
    }
#endif

int    g_AnchorColor        = BLUE;
int    g_ModuleTextCMPColor = LIGHTGRAY;
int    g_ModuleTextCUColor  = MAGENTA;
int    g_ModuleTextNOVColor = DARKGRAY;
int    g_PadCUColor         = GREEN;
int    g_PadCMPColor        = RED;
    // 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/" ) );
    relpath += LIB3D_FOLDER;

// Apple MacOSx
#ifdef __WXMAC__
    path = wxT("/Library/Application Support/kicad/modules/packages3d/");

/**
 * Used in track creation, a list of track segments currently being created,
 * with the newest track at the end of the list, sorted by new-ness.  e.g. use
 * TRACK->Back() to get the next older track, TRACK->Next() to get the next
 * newer track.
 */
DLIST<TRACK> g_CurrentTrackList;
    if( wxFileName::DirExists( path ) )
    {
        wxSetEnv( aKiSys3Dmod, path );
        return true;
    }

    path = wxString( wxGetenv( wxT( "HOME" ) ) ) + wxT("/Library/Application Support/kicad/modules/packages3d/");

void AccumulateDescription( wxString &aDesc, const wxString &aItem )
    if( wxFileName::DirExists( path ) )
    {
    if( !aDesc.IsEmpty() )
        aDesc << wxT(", ");
    aDesc << aItem;
        wxSetEnv( aKiSys3Dmod, path );
        return true;
    }

#elif defined(__UNIX__)     // Linux and non-Apple Unix
    // Try the home directory:
    path.Empty();
    wxGetEnv( wxT("HOME"), &path );
    path += wxT("/kicad/share/") + relpath;

    if( wxFileName::DirExists( path ) )
    {
        wxSetEnv( aKiSys3Dmod, path );
        return true;
    }

    // Try the standard install path:
    path = wxT("/usr/local/kicad/share/") + relpath;

    if( wxFileName::DirExists( path ) )
    {
        wxSetEnv( aKiSys3Dmod, path );
        return true;
    }

    // Try the official distrib standard install path:
    path = wxT("/usr/share/kicad/") + relpath;

    if( wxFileName::DirExists( path ) )
    {
        wxSetEnv( aKiSys3Dmod, path );
        return true;
    }

#else   // Windows
    // On Windows, the install path is given by the path of executables
    wxFileName fn;
    fn.AssignDir( aProcess->GetExecutablePath() );
    fn.RemoveLastDir();
    path = fn.GetPathWithSep() + wxT("share/") + relpath;

    if( wxFileName::DirExists( path ) )
    {
        wxSetEnv( aKiSys3Dmod, path );
        return true;
    }
#endif

    return false;
}


+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@

#include <fctsys.h>
#include <macros.h>
#include <gr_basic.h>
#include <pgm_base.h>
#include <project.h>
#include <common.h>         // NAMELESS_PROJECT
+2 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@
#include <3d_viewer.h>


DISPLAY_OPTIONS DisplayOpt;      // General display options


BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME )
    EVT_CLOSE( DISPLAY_FOOTPRINTS_FRAME::OnCloseWindow )
Loading