kicad/common/gestfich.cpp

547 lines
16 KiB
C++
Raw Normal View History

2011-12-16 20:12:49 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file gestfich.cpp
* @brief Functions for file management
*/
2007-05-06 16:03:28 +00:00
// For compilers that support precompilation, includes "wx.h".
#include <fctsys.h>
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#include <pgm_base.h>
#include <confirm.h>
2007-05-06 16:03:28 +00:00
#include <common.h>
#include <macros.h>
#include <gestfich.h>
#include <wx/mimetype.h>
#include <wx/filename.h>
2012-01-26 19:48:45 +00:00
#include <wx/dir.h>
2007-05-06 16:03:28 +00:00
/* List of default paths used to locate help files and KiCad library files.
*
* Under windows, KiCad search its files from the binary path file (first
* argument when running "main") So for a standard install, default paths
* are not mandatory, but they exist, just in case.
* KiCad is often installed in c:/Program Files/kicad or c:/kicad (or d: or
* e: ... ) and the directory "share" has no meaning under windows.
*
* Under linux, the problem is more complex.
* In fact there are 3 cases:
* 1 - When released in a distribution:
* binaries are in /usr/bin, KiCad libs in /usr/share/kicad/ and doc in
* /usr/share/doc/kicad/
* 2 - When compiled by an user:
* binaries also can be in /usr/local/bin, KiCad libs in
* /usr/local/share/kicad/ and doc in /usr/local/share/doc/kicad/
* 3 - When in an "universal tarball" or build for a server:
* all files are in /usr/local/kicad
* This is mandatory when KiCad is installed on a server (in a school for
* instance) because one can export /usr/local/kicad and obviously the others
* paths cannot be used (cannot be mounted by the client, because they are
* already used).
*
* in cases 1 and 2 KiCad files cannot be found from the binary path.
* in case 3 KiCad files can be found from the binary path only if this is
* a KiCad binary file which is launched.
* But if an user creates a symbolic link to the actual binary file to run
* KiCad, the binary path is not good and the defaults paths must be used
*
* Note:
* KiCad uses first the bin path lo locate KiCad tree.
* if not found KiCad uses the environment variable KICAD to find its files
* and at last KiCad uses the default paths.
* So we can export (linux and windows) the variable KICAD:
* like export KICAD=/my_path/kicad if /my_path/kicad is not a default path
*/
2007-05-06 16:03:28 +00:00
wxString MakeReducedFileName( const wxString& fullfilename,
const wxString& default_path,
const wxString& default_ext )
2007-05-06 16:03:28 +00:00
{
2007-08-18 11:43:59 +00:00
wxString reduced_filename = fullfilename;
wxString Cwd, ext, path;
Cwd = default_path;
ext = default_ext;
path = wxPathOnly( reduced_filename ) + UNIX_STRING_DIR_SEP;
reduced_filename.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
2007-08-18 11:43:59 +00:00
if( Cwd.Last() != '/' )
Cwd += UNIX_STRING_DIR_SEP;
2007-08-18 11:43:59 +00:00
path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
2007-05-06 16:03:28 +00:00
#ifdef __WINDOWS__
2008-02-20 19:12:36 +00:00
// names are case insensitive under windows
2007-08-18 11:43:59 +00:00
path.MakeLower();
Cwd.MakeLower();
ext.MakeLower();
2007-05-06 16:03:28 +00:00
#endif
// if the path is "default_path" -> remove it
2007-08-18 11:43:59 +00:00
wxString root_path = path.Left( Cwd.Length() );
2007-08-18 11:43:59 +00:00
if( root_path == Cwd )
{
reduced_filename.Remove( 0, Cwd.Length() );
}
else // if the path is the current path -> change path to ./
2007-08-18 11:43:59 +00:00
{
Cwd = wxGetCwd() + UNIX_STRING_DIR_SEP;
2007-05-06 16:03:28 +00:00
#ifdef __WINDOWS__
2007-08-18 11:43:59 +00:00
Cwd.MakeLower();
2007-05-06 16:03:28 +00:00
#endif
2007-08-18 11:43:59 +00:00
Cwd.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
2007-08-18 11:43:59 +00:00
if( path == Cwd )
{ // the path is the current path -> path = "./"
2007-08-18 11:43:59 +00:00
reduced_filename.Remove( 0, Cwd.Length() );
wxString tmp = wxT( "./" ) + reduced_filename;
reduced_filename = tmp;
}
}
// remove extension if == default_ext:
2007-08-18 11:43:59 +00:00
if( !ext.IsEmpty() && reduced_filename.Contains( ext ) )
reduced_filename.Truncate( reduced_filename.Length() - ext.Length() );
return reduced_filename;
2007-05-06 16:03:28 +00:00
}
void AddDelimiterString( wxString& string )
2007-05-06 16:03:28 +00:00
{
2007-08-18 11:43:59 +00:00
wxString text;
if( !string.StartsWith( wxT( "\"" ) ) )
text = wxT( "\"" );
2007-08-18 11:43:59 +00:00
text += string;
2007-08-18 11:43:59 +00:00
if( (text.Last() != '"' ) || (text.length() <= 1) )
text += wxT( "\"" );
2007-08-18 11:43:59 +00:00
string = text;
2007-05-06 16:03:28 +00:00
}
bool EDA_DirectorySelector( const wxString& Title,
wxString& Path,
int flag,
wxWindow* Frame,
2007-08-18 11:43:59 +00:00
const wxPoint& Pos )
2007-05-06 16:03:28 +00:00
{
2007-08-18 11:43:59 +00:00
int ii;
bool selected = false;
2007-08-18 11:43:59 +00:00
wxDirDialog* DirFrame = new wxDirDialog( Frame,
wxString( Title ),
Path,
flag,
Pos );
2007-08-18 11:43:59 +00:00
ii = DirFrame->ShowModal();
2007-08-18 11:43:59 +00:00
if( ii == wxID_OK )
{
Path = DirFrame->GetPath();
selected = true;
2007-08-18 11:43:59 +00:00
}
DirFrame->Destroy();
return selected;
2007-05-06 16:03:28 +00:00
}
2007-08-18 11:43:59 +00:00
wxString EDA_FileSelector( const wxString& Title,
const wxString& Path,
const wxString& FileName,
const wxString& Ext,
const wxString& Mask,
wxWindow* Frame,
int flag,
const bool keep_working_directory,
2007-08-18 11:43:59 +00:00
const wxPoint& Pos )
2007-05-06 16:03:28 +00:00
{
2007-08-18 11:43:59 +00:00
wxString fullfilename;
wxString curr_cwd = wxGetCwd();
wxString defaultname = FileName;
wxString defaultpath = Path;
wxString dotted_Ext = wxT(".") + Ext;
2007-05-06 16:03:28 +00:00
#ifdef __WINDOWS__
defaultname.Replace( wxT( "/" ), wxT( "\\" ) );
defaultpath.Replace( wxT( "/" ), wxT( "\\" ) );
#endif
2007-08-18 11:43:59 +00:00
if( defaultpath.IsEmpty() )
defaultpath = wxGetCwd();
2007-05-06 16:03:28 +00:00
wxSetWorkingDirectory( defaultpath );
#if 0 && defined (DEBUG)
printf( "defaultpath=\"%s\" defaultname=\"%s\" Ext=\"%s\" Mask=\"%s\" flag=%d keep_working_directory=%d\n",
TO_UTF8( defaultpath ),
TO_UTF8( defaultname ),
TO_UTF8( Ext ),
TO_UTF8( Mask ),
flag,
keep_working_directory );
2008-02-20 19:12:36 +00:00
#endif
2007-08-18 11:43:59 +00:00
fullfilename = wxFileSelector( wxString( Title ),
defaultpath,
defaultname,
dotted_Ext,
Mask,
flag, // open mode wxFD_OPEN, wxFD_SAVE ..
Frame,
Pos.x, Pos.y );
2007-05-06 16:03:28 +00:00
2007-08-18 11:43:59 +00:00
if( keep_working_directory )
wxSetWorkingDirectory( curr_cwd );
2007-05-06 16:03:28 +00:00
2007-08-18 11:43:59 +00:00
return fullfilename;
2007-05-06 16:03:28 +00:00
}
2007-08-18 11:43:59 +00:00
wxString FindKicadFile( const wxString& shortname )
2007-05-06 16:03:28 +00:00
{
// Test the presence of the file in the directory shortname of
// the KiCad binary path.
wxString fullFileName = Pgm().GetExecutablePath() + shortname;
if( wxFileExists( fullFileName ) )
return fullFileName;
2007-08-18 11:43:59 +00:00
// Test the presence of the file in the directory shortname
// defined by the environment variable KiCad.
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
if( Pgm().IsKicadEnvVariableDefined() )
2007-08-18 11:43:59 +00:00
{
fullFileName = Pgm().GetKicadEnvVariable() + shortname;
if( wxFileExists( fullFileName ) )
return fullFileName;
2007-08-18 11:43:59 +00:00
}
// find binary file from possibilities list:
// /usr/local/kicad/linux or c:/kicad/winexe
// Path list for KiCad binary files
const static wxChar* possibilities[] = {
#ifdef __WINDOWS__
wxT( "c:/kicad/bin/" ),
wxT( "d:/kicad/bin/" ),
wxT( "c:/Program Files/kicad/bin/" ),
wxT( "d:/Program Files/kicad/bin/" ),
#else
wxT( "/usr/bin/" ),
wxT( "/usr/local/bin/" ),
wxT( "/usr/local/kicad/bin/" ),
#endif
};
for( unsigned i=0; i<DIM(possibilities); ++i )
{
fullFileName = possibilities[i] + shortname;
if( wxFileExists( fullFileName ) )
return fullFileName;
2007-08-18 11:43:59 +00:00
}
return shortname;
2007-05-06 16:03:28 +00:00
}
2007-08-18 11:43:59 +00:00
int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param,
wxProcess *callback )
2007-05-06 16:03:28 +00:00
{
wxString fullFileName;
2007-05-06 16:03:28 +00:00
fullFileName = FindKicadFile( ExecFile );
2007-05-06 16:03:28 +00:00
2012-01-26 19:48:45 +00:00
#ifdef __WXMAC__
if( wxFileExists( fullFileName ) || wxDir::Exists( fullFileName ) )
2012-01-26 19:48:45 +00:00
{
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
return ProcessExecute( Pgm().GetExecutablePath() + wxT( "/" )
+ ExecFile + wxT( " " )
+ param, wxEXEC_ASYNC, callback );
}
else
{
return ProcessExecute( wxT( "/usr/bin/open " ) + param, wxEXEC_ASYNC, callback );
2012-01-26 19:48:45 +00:00
}
#else
if( wxFileExists( fullFileName ) )
2007-08-18 11:43:59 +00:00
{
if( !param.IsEmpty() )
fullFileName += wxT( " " ) + param;
return ProcessExecute( fullFileName, wxEXEC_ASYNC, callback );
2007-08-18 11:43:59 +00:00
}
2012-01-26 19:48:45 +00:00
#endif
2007-08-18 11:43:59 +00:00
wxString msg;
msg.Printf( _( "Command <%s> could not found" ), GetChars( fullFileName ) );
2007-08-18 11:43:59 +00:00
DisplayError( frame, msg, 20 );
return -1;
2007-05-06 16:03:28 +00:00
}
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
wxString KicadDatasPath()
2007-05-06 16:03:28 +00:00
{
bool found = false;
2007-08-18 11:43:59 +00:00
wxString data_path;
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
if( Pgm().IsKicadEnvVariableDefined() ) // Path defined by the KICAD environment variable.
2007-08-18 11:43:59 +00:00
{
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
data_path = Pgm().GetKicadEnvVariable();
found = true;
2007-08-18 11:43:59 +00:00
}
else // Path of executables.
2007-08-18 11:43:59 +00:00
{
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
wxString tmp = Pgm().GetExecutablePath();
#ifdef __WINDOWS__
2007-08-18 11:43:59 +00:00
tmp.MakeLower();
#endif
2007-08-18 11:43:59 +00:00
if( tmp.Contains( wxT( "kicad" ) ) )
{
#ifdef __WINDOWS__
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
tmp = Pgm().GetExecutablePath();
#endif
2007-08-18 11:43:59 +00:00
if( tmp.Last() == '/' )
tmp.RemoveLast();
2007-08-18 11:43:59 +00:00
data_path = tmp.BeforeLast( '/' ); // id cd ../
data_path += UNIX_STRING_DIR_SEP;
// Old versions of KiCad use kicad/ as default for data
// and last versions kicad/share/
// So we search for kicad/share/ first
wxString old_path = data_path;
data_path += wxT( "share/" );
2007-08-18 11:43:59 +00:00
if( wxDirExists( data_path ) )
{
found = true;
}
else if( wxDirExists( old_path ) )
{
data_path = old_path;
found = true;
}
2007-08-18 11:43:59 +00:00
}
}
if( !found )
2007-08-18 11:43:59 +00:00
{
// find KiCad from possibilities list:
// /usr/local/kicad/ or c:/kicad/
const static wxChar* possibilities[] = {
#ifdef __WINDOWS__
wxT( "c:/kicad/share/" ),
wxT( "d:/kicad/share/" ),
wxT( "c:/kicad/" ),
wxT( "d:/kicad/" ),
wxT( "c:/Program Files/kicad/share/" ),
wxT( "d:/Program Files/kicad/share/" ),
wxT( "c:/Program Files/kicad/" ),
wxT( "d:/Program Files/kicad/" ),
#else
wxT( "/usr/share/kicad/" ),
wxT( "/usr/local/share/kicad/" ),
wxT( "/usr/local/kicad/share/" ), // default data path for "universal
// tarballs" and build for a server
// (new)
wxT( "/usr/local/kicad/" ), // default data path for "universal
// tarballs" and build for a server
// (old)
#endif
};
for( unsigned i=0; i<DIM(possibilities); ++i )
{
data_path = possibilities[i];
if( wxDirExists( data_path ) )
{
found = true;
break;
}
}
2007-08-18 11:43:59 +00:00
}
if( found )
2007-08-18 11:43:59 +00:00
{
data_path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
2007-08-18 11:43:59 +00:00
if( data_path.Last() != '/' )
data_path += UNIX_STRING_DIR_SEP;
}
else
{
2007-08-18 11:43:59 +00:00
data_path.Empty();
}
2007-08-18 11:43:59 +00:00
return data_path;
2007-05-06 16:03:28 +00:00
}
bool OpenPDF( const wxString& file )
{
2007-08-18 11:43:59 +00:00
wxString command;
wxString filename = file;
wxString type;
bool success = false;
2007-08-18 11:43:59 +00:00
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
Pgm().ReadPdfBrowserInfos();
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
if( !Pgm().UseSystemPdfBrowser() ) // Run the preferred PDF Browser
2007-08-18 11:43:59 +00:00
{
AddDelimiterString( filename );
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
command = Pgm().GetPdfBrowserName() + wxT( " " ) + filename;
2007-08-18 11:43:59 +00:00
}
else
{
wxFileType* filetype = NULL;
wxFileType::MessageParameters params( filename, type );
2008-06-29 18:51:38 +00:00
filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( wxT( "pdf" ) );
2007-08-18 11:43:59 +00:00
if( filetype )
success = filetype->GetOpenCommand( &command, params );
2007-08-18 11:43:59 +00:00
delete filetype;
2011-12-16 20:12:49 +00:00
2008-06-29 18:51:38 +00:00
#ifndef __WINDOWS__
2011-12-16 20:12:49 +00:00
// Bug ? under linux wxWidgets returns acroread as PDF viewer, even if
// it does not exist.
if( command.StartsWith( wxT( "acroread" ) ) ) // Workaround
2008-06-29 18:51:38 +00:00
success = false;
#endif
2011-12-16 20:12:49 +00:00
2008-06-29 18:51:38 +00:00
if( success && !command.IsEmpty() )
{
success = ProcessExecute( command );
if( success )
2008-07-08 18:45:06 +00:00
return success;
2008-06-29 18:51:38 +00:00
}
2008-07-08 18:45:06 +00:00
success = false;
command.clear();
2007-08-18 11:43:59 +00:00
if( !success )
{
#if !defined(__WINDOWS__)
2008-06-29 18:51:38 +00:00
AddDelimiterString( filename );
2011-12-16 20:12:49 +00:00
// here is a list of PDF viewers candidates
static const wxChar* tries[] =
2007-08-18 11:43:59 +00:00
{
wxT( "/usr/bin/evince" ),
wxT( "/usr/bin/okular" ),
2007-08-18 11:43:59 +00:00
wxT( "/usr/bin/gpdf" ),
2008-06-29 18:51:38 +00:00
wxT( "/usr/bin/konqueror" ),
wxT( "/usr/bin/kpdf" ),
wxT( "/usr/bin/xpdf" ),
wxT( "/usr/bin/open" ), // BSD and OSX file & dir opener
wxT( "/usr/bin/xdg-open" ), // Freedesktop file & dir opener
2007-08-18 11:43:59 +00:00
};
2008-02-20 19:12:36 +00:00
for( unsigned ii = 0; ii<DIM(tries); ii++ )
2007-08-18 11:43:59 +00:00
{
2008-06-29 18:51:38 +00:00
if( wxFileExists( tries[ii] ) )
2007-08-18 11:43:59 +00:00
{
command = tries[ii];
command += wxT( ' ' );
command += filename;
2008-06-29 18:51:38 +00:00
break;
2007-08-18 11:43:59 +00:00
}
}
2008-06-29 18:51:38 +00:00
#endif
2007-08-18 11:43:59 +00:00
}
}
if( !command.IsEmpty() )
2008-06-29 18:51:38 +00:00
{
success = ProcessExecute( command );
if( !success )
2008-06-29 18:51:38 +00:00
{
wxString msg;
msg.Printf( _( "Problem while running the PDF viewer\nCommand is '%s'" ),
GetChars( command ) );
2008-06-29 18:51:38 +00:00
DisplayError( NULL, msg );
}
}
else
{
wxString msg;
msg.Printf( _( "Unable to find a PDF viewer for <%s>" ), GetChars( filename ) );
2008-06-29 18:51:38 +00:00
DisplayError( NULL, msg );
success = false;
}
2008-06-29 18:51:38 +00:00
return success;
}
2007-08-18 11:43:59 +00:00
void OpenFile( const wxString& file )
{
2007-08-18 11:43:59 +00:00
wxString command;
wxString filename = file;
wxFileName CurrentFileName( filename );
wxString ext, type;
2007-08-18 11:43:59 +00:00
ext = CurrentFileName.GetExt();
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
2007-08-18 11:43:59 +00:00
bool success = false;
2007-08-18 11:43:59 +00:00
wxFileType::MessageParameters params( filename, type );
2007-08-18 11:43:59 +00:00
if( filetype )
success = filetype->GetOpenCommand( &command, params );
2007-08-18 11:43:59 +00:00
delete filetype;
2007-08-18 11:43:59 +00:00
if( success && !command.IsEmpty() )
2008-04-24 16:55:35 +00:00
ProcessExecute( command );
}
wxString QuoteFullPath( wxFileName& fn, wxPathFormat format )
{
return wxT( "\"" ) + fn.GetFullPath( format ) + wxT( "\"" );
}