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
|
2017-06-07 16:41:04 +00:00
|
|
|
* Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-16 20:12:49 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file gestfich.cpp
|
|
|
|
* @brief Functions for file management
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2016-01-02 12:55:38 +00:00
|
|
|
#include <wx/mimetype.h>
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/dir.h>
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
// For compilers that support precompilation, includes "wx.h".
|
2012-01-23 04:33:36 +00:00
|
|
|
#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>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2016-01-02 12:55:38 +00:00
|
|
|
#include <gestfich.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
void AddDelimiterString( wxString& string )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2016-01-01 07:51:50 +00:00
|
|
|
if( !string.StartsWith( wxT( "\"" ) ) )
|
2015-12-31 09:03:47 +00:00
|
|
|
{
|
2015-12-31 10:16:26 +00:00
|
|
|
string.Prepend ( wxT( "\"" ) );
|
|
|
|
string.Append ( wxT( "\"" ) );
|
2015-12-31 09:03:47 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-25 19:38:09 +00:00
|
|
|
bool EDA_PATH_SELECTOR( const wxString& aTitle,
|
|
|
|
wxString& aPath,
|
|
|
|
int aFlags,
|
|
|
|
wxWindow* aParent,
|
|
|
|
const wxPoint& aPosition )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
int ii;
|
2011-11-08 16:37:25 +00:00
|
|
|
bool selected = false;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
2015-09-25 19:38:09 +00:00
|
|
|
wxDirDialog* DirFrame = new wxDirDialog( aParent,
|
|
|
|
aTitle,
|
|
|
|
aPath,
|
|
|
|
aFlags,
|
|
|
|
aPosition );
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
|
|
ii = DirFrame->ShowModal();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( ii == wxID_OK )
|
|
|
|
{
|
2015-09-25 19:38:09 +00:00
|
|
|
aPath = DirFrame->GetPath();
|
2011-11-08 16:37:25 +00:00
|
|
|
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
|
|
|
|
2015-09-25 19:38:09 +00:00
|
|
|
wxString EDA_FILE_SELECTOR( const wxString& aTitle,
|
|
|
|
const wxString& aPath,
|
|
|
|
const wxString& aFileName,
|
|
|
|
const wxString& aExtension,
|
|
|
|
const wxString& aWildcard,
|
|
|
|
wxWindow* aParent,
|
|
|
|
int aStyle,
|
|
|
|
const bool aKeepWorkingDirectory,
|
|
|
|
const wxPoint& aPosition,
|
|
|
|
wxString* aMruPath )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
wxString fullfilename;
|
|
|
|
wxString curr_cwd = wxGetCwd();
|
2015-09-25 19:38:09 +00:00
|
|
|
wxString defaultname = aFileName;
|
|
|
|
wxString defaultpath = aPath;
|
|
|
|
wxString dotted_Ext = wxT(".") + aExtension;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
defaultname.Replace( wxT( "/" ), wxT( "\\" ) );
|
|
|
|
defaultpath.Replace( wxT( "/" ), wxT( "\\" ) );
|
|
|
|
#endif
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( defaultpath.IsEmpty() )
|
2015-09-25 19:38:09 +00:00
|
|
|
{
|
|
|
|
if( aMruPath == NULL )
|
|
|
|
defaultpath = wxGetCwd();
|
|
|
|
else
|
|
|
|
defaultpath = *aMruPath;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
wxSetWorkingDirectory( defaultpath );
|
|
|
|
|
2008-03-30 15:12:08 +00:00
|
|
|
#if 0 && defined (DEBUG)
|
2009-11-23 15:16:50 +00:00
|
|
|
printf( "defaultpath=\"%s\" defaultname=\"%s\" Ext=\"%s\" Mask=\"%s\" flag=%d keep_working_directory=%d\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( defaultpath ),
|
|
|
|
TO_UTF8( defaultname ),
|
2015-09-25 19:38:09 +00:00
|
|
|
TO_UTF8( aExtension ),
|
|
|
|
TO_UTF8( aWildcard ),
|
|
|
|
aStyle,
|
|
|
|
aKeepWorkingDirectory );
|
2008-02-20 19:12:36 +00:00
|
|
|
#endif
|
|
|
|
|
2015-09-25 19:38:09 +00:00
|
|
|
fullfilename = wxFileSelector( aTitle,
|
2008-12-08 15:27:13 +00:00
|
|
|
defaultpath,
|
|
|
|
defaultname,
|
2009-06-19 20:13:22 +00:00
|
|
|
dotted_Ext,
|
2015-09-25 19:38:09 +00:00
|
|
|
aWildcard,
|
|
|
|
aStyle, // open mode wxFD_OPEN, wxFD_SAVE ..
|
|
|
|
aParent,
|
|
|
|
aPosition.x, aPosition.y );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2015-09-25 19:38:09 +00:00
|
|
|
if( aKeepWorkingDirectory )
|
2007-08-18 11:43:59 +00:00
|
|
|
wxSetWorkingDirectory( curr_cwd );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2015-09-25 19:38:09 +00:00
|
|
|
if( !fullfilename.IsEmpty() && aMruPath )
|
|
|
|
{
|
|
|
|
wxFileName fn = fullfilename;
|
|
|
|
*aMruPath = fn.GetPath();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
wxString FindKicadFile( const wxString& shortname )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2014-04-14 18:49:52 +00:00
|
|
|
// Test the presence of the file in the directory shortname of
|
|
|
|
// the KiCad binary path.
|
2014-10-17 17:45:33 +00:00
|
|
|
#ifndef __WXMAC__
|
2014-04-14 18:49:52 +00:00
|
|
|
wxString fullFileName = Pgm().GetExecutablePath() + shortname;
|
2014-10-17 17:45:33 +00:00
|
|
|
#else
|
|
|
|
wxString fullFileName = Pgm().GetExecutablePath() + wxT( "Contents/MacOS/" ) + shortname;
|
|
|
|
#endif
|
2014-04-14 18:49:52 +00:00
|
|
|
if( wxFileExists( fullFileName ) )
|
|
|
|
return fullFileName;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
2014-04-14 18:49:52 +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
|
|
|
{
|
2014-04-14 18:49:52 +00:00
|
|
|
fullFileName = Pgm().GetKicadEnvVariable() + shortname;
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
if( wxFileExists( fullFileName ) )
|
|
|
|
return fullFileName;
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
// Path list for KiCad binary files
|
|
|
|
const static wxChar* possibilities[] = {
|
2014-10-17 17:45:33 +00:00
|
|
|
#if defined( __WINDOWS__ )
|
2014-04-14 18:49:52 +00:00
|
|
|
wxT( "c:/kicad/bin/" ),
|
|
|
|
wxT( "d:/kicad/bin/" ),
|
|
|
|
wxT( "c:/Program Files/kicad/bin/" ),
|
|
|
|
wxT( "d:/Program Files/kicad/bin/" ),
|
2014-10-17 17:45:33 +00:00
|
|
|
#elif defined( __WXMAC__ )
|
|
|
|
// all internal paths are relative to main bundle kicad.app
|
|
|
|
wxT( "Contents/Applications/pcbnew.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/eeschema.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/gerbview.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/bitmap2component.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/pcb_calculator.app/Contents/MacOS/" ),
|
|
|
|
wxT( "Contents/Applications/pl_editor.app/Contents/MacOS/" ),
|
2014-04-14 18:49:52 +00:00
|
|
|
#else
|
|
|
|
wxT( "/usr/bin/" ),
|
|
|
|
wxT( "/usr/local/bin/" ),
|
|
|
|
wxT( "/usr/local/kicad/bin/" ),
|
|
|
|
#endif
|
|
|
|
};
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-10-17 17:45:33 +00:00
|
|
|
// find binary file from possibilities list:
|
2014-04-14 18:49:52 +00:00
|
|
|
for( unsigned i=0; i<DIM(possibilities); ++i )
|
|
|
|
{
|
2014-10-17 17:45:33 +00:00
|
|
|
#ifndef __WXMAC__
|
2014-04-14 18:49:52 +00:00
|
|
|
fullFileName = possibilities[i] + shortname;
|
2014-10-17 17:45:33 +00:00
|
|
|
#else
|
|
|
|
// make relative paths absolute
|
|
|
|
fullFileName = Pgm().GetExecutablePath() + possibilities[i] + shortname;
|
|
|
|
#endif
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
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
|
|
|
|
2013-01-18 10:42:23 +00:00
|
|
|
int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param,
|
|
|
|
wxProcess *callback )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2014-10-17 17:45:33 +00:00
|
|
|
wxString fullFileName = FindKicadFile( ExecFile );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2014-10-17 17:45:33 +00:00
|
|
|
if( wxFileExists( fullFileName ) )
|
2012-01-26 19:48:45 +00:00
|
|
|
{
|
2014-10-17 17:45:33 +00:00
|
|
|
if( !param.IsEmpty() )
|
|
|
|
fullFileName += wxT( " " ) + param;
|
|
|
|
|
|
|
|
return ProcessExecute( fullFileName, wxEXEC_ASYNC, callback );
|
2013-01-18 10:42:23 +00:00
|
|
|
}
|
2014-10-17 17:45:33 +00:00
|
|
|
#ifdef __WXMAC__
|
2013-01-18 10:42:23 +00:00
|
|
|
else
|
2007-08-18 11:43:59 +00:00
|
|
|
{
|
2015-12-31 10:16:26 +00:00
|
|
|
AddDelimiterString( fullFileName );
|
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( !param.IsEmpty() )
|
2014-04-14 18:49:52 +00:00
|
|
|
fullFileName += wxT( " " ) + param;
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-10-17 17:45:33 +00:00
|
|
|
return ProcessExecute( wxT( "/usr/bin/open -a " ) + fullFileName, wxEXEC_ASYNC, callback );
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
2012-01-26 19:48:45 +00:00
|
|
|
#endif
|
2014-10-17 17:45:33 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
wxString msg;
|
2017-12-15 11:37:46 +00:00
|
|
|
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
|
|
|
{
|
2014-04-14 18:49:52 +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();
|
2014-04-14 18:49:52 +00:00
|
|
|
found = true;
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
else // Path of executables.
|
2007-08-18 11:43:59 +00:00
|
|
|
{
|
2014-10-17 17:45:33 +00:00
|
|
|
#ifndef __WXMAC__
|
* 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();
|
2007-07-09 09:29:53 +00:00
|
|
|
#ifdef __WINDOWS__
|
2007-08-18 11:43:59 +00:00
|
|
|
tmp.MakeLower();
|
2007-07-09 09:29:53 +00:00
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
if( tmp.Contains( wxT( "kicad" ) ) )
|
|
|
|
{
|
2007-07-09 09:29:53 +00:00
|
|
|
#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();
|
2007-07-09 09:29:53 +00:00
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
if( tmp.Last() == '/' )
|
|
|
|
tmp.RemoveLast();
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
data_path = tmp.BeforeLast( '/' ); // id cd ../
|
|
|
|
data_path += UNIX_STRING_DIR_SEP;
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Old versions of KiCad use kicad/ as default for data
|
2008-06-22 08:54:05 +00:00
|
|
|
// and last versions kicad/share/
|
|
|
|
// So we search for kicad/share/ first
|
|
|
|
wxString old_path = data_path;
|
2008-12-08 15:27:13 +00:00
|
|
|
data_path += wxT( "share/" );
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( wxDirExists( data_path ) )
|
2011-11-08 16:37:25 +00:00
|
|
|
{
|
2014-04-14 18:49:52 +00:00
|
|
|
found = true;
|
2011-11-08 16:37:25 +00:00
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
else if( wxDirExists( old_path ) )
|
2008-06-22 08:54:05 +00:00
|
|
|
{
|
|
|
|
data_path = old_path;
|
2014-04-14 18:49:52 +00:00
|
|
|
found = true;
|
2008-06-22 08:54:05 +00:00
|
|
|
}
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
if( !found )
|
2007-08-18 11:43:59 +00:00
|
|
|
{
|
2014-04-14 18:49:52 +00:00
|
|
|
// find KiCad from possibilities list:
|
|
|
|
// /usr/local/kicad/ or c:/kicad/
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
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];
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
if( wxDirExists( data_path ) )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-10-17 17:45:33 +00:00
|
|
|
#else
|
|
|
|
// On OSX point to Contents/SharedSupport folder of main bundle
|
|
|
|
data_path = GetOSXKicadDataDir();
|
|
|
|
found = true;
|
|
|
|
#endif
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 18:49:52 +00:00
|
|
|
if( found )
|
2007-08-18 11:43:59 +00:00
|
|
|
{
|
|
|
|
data_path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( data_path.Last() != '/' )
|
|
|
|
data_path += UNIX_STRING_DIR_SEP;
|
|
|
|
}
|
|
|
|
else
|
2011-09-06 14:09:40 +00:00
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
data_path.Empty();
|
2011-09-06 14:09:40 +00:00
|
|
|
}
|
2007-08-18 11:43:59 +00:00
|
|
|
|
|
|
|
return data_path;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-31 10:16:26 +00:00
|
|
|
bool OpenPDF( const wxString& file )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
wxString command;
|
2015-12-31 10:16:26 +00:00
|
|
|
wxString filename = file;
|
2007-08-18 11:43:59 +00:00
|
|
|
|
2017-06-07 16:41:04 +00:00
|
|
|
// Quote in case there are spaces in the file name.
|
|
|
|
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
|
|
|
Pgm().ReadPdfBrowserInfos();
|
2011-11-08 16:37:25 +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
|
|
|
if( !Pgm().UseSystemPdfBrowser() ) // Run the preferred PDF Browser
|
2007-08-18 11:43:59 +00:00
|
|
|
{
|
2015-12-31 10:16:26 +00:00
|
|
|
command = Pgm().GetPdfBrowserName() + wxT( " " ) + filename;
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-07 16:41:04 +00:00
|
|
|
if( wxLaunchDefaultApplication( file ) )
|
|
|
|
return true;
|
2016-01-01 07:51:50 +00:00
|
|
|
|
2017-06-07 16:41:04 +00:00
|
|
|
// If launching the system default PDF viewer fails, fall through with empty command
|
|
|
|
// string so the error message is displayed.
|
2007-08-18 11:43:59 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 07:51:50 +00:00
|
|
|
if( !command.IsEmpty() )
|
2008-06-29 18:51:38 +00:00
|
|
|
{
|
2016-01-01 07:51:50 +00:00
|
|
|
if( ProcessExecute( command ) )
|
2015-12-31 09:03:47 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
2008-06-29 18:51:38 +00:00
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
wxString msg;
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Problem while running the PDF viewer\nCommand is \"%s\"" ), command );
|
2008-06-29 18:51:38 +00:00
|
|
|
DisplayError( NULL, msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-09 17:49:01 +00:00
|
|
|
wxString msg;
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Unable to find a PDF viewer for \"%s\"" ), file );
|
2008-06-29 18:51:38 +00:00
|
|
|
DisplayError( NULL, msg );
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2015-12-31 09:03:47 +00:00
|
|
|
return false;
|
2008-06-29 18:51:38 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
void OpenFile( const wxString& file )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-08-18 11:43:59 +00:00
|
|
|
wxString command;
|
|
|
|
wxString filename = file;
|
|
|
|
|
|
|
|
wxFileName CurrentFileName( filename );
|
|
|
|
wxString ext, type;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
ext = CurrentFileName.GetExt();
|
2011-11-08 16:37:25 +00:00
|
|
|
wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
bool success = false;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
wxFileType::MessageParameters params( filename, type );
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( filetype )
|
|
|
|
success = filetype->GetOpenCommand( &command, params );
|
2011-11-08 16:37:25 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
delete filetype;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-18 11:43:59 +00:00
|
|
|
if( success && !command.IsEmpty() )
|
2008-04-24 16:55:35 +00:00
|
|
|
ProcessExecute( command );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxString QuoteFullPath( wxFileName& fn, wxPathFormat format )
|
|
|
|
{
|
2010-05-11 14:35:13 +00:00
|
|
|
return wxT( "\"" ) + fn.GetFullPath( format ) + wxT( "\"" );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|