You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

420 lines
12 KiB

* 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.
12 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
* 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.
12 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
* 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.
12 years ago
18 years ago
* 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.
12 years ago
18 years ago
* 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.
12 years ago
18 years ago
18 years ago
* 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.
12 years ago
18 years ago
18 years ago
* 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.
12 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
* 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.
12 years ago
* 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.
12 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file gestfich.cpp
  27. * @brief Functions for file management
  28. */
  29. #include <wx/mimetype.h>
  30. #include <wx/filename.h>
  31. #include <wx/dir.h>
  32. // For compilers that support precompilation, includes "wx.h".
  33. #include <fctsys.h>
  34. #include <pgm_base.h>
  35. #include <confirm.h>
  36. #include <common.h>
  37. #include <macros.h>
  38. #include <gestfich.h>
  39. void AddDelimiterString( wxString& string )
  40. {
  41. if( !string.StartsWith( wxT( "\"" ) ) )
  42. {
  43. string.Prepend ( wxT( "\"" ) );
  44. string.Append ( wxT( "\"" ) );
  45. }
  46. }
  47. bool EDA_PATH_SELECTOR( const wxString& aTitle,
  48. wxString& aPath,
  49. int aFlags,
  50. wxWindow* aParent,
  51. const wxPoint& aPosition )
  52. {
  53. int ii;
  54. bool selected = false;
  55. wxDirDialog* DirFrame = new wxDirDialog( aParent,
  56. aTitle,
  57. aPath,
  58. aFlags,
  59. aPosition );
  60. ii = DirFrame->ShowModal();
  61. if( ii == wxID_OK )
  62. {
  63. aPath = DirFrame->GetPath();
  64. selected = true;
  65. }
  66. DirFrame->Destroy();
  67. return selected;
  68. }
  69. wxString EDA_FILE_SELECTOR( const wxString& aTitle,
  70. const wxString& aPath,
  71. const wxString& aFileName,
  72. const wxString& aExtension,
  73. const wxString& aWildcard,
  74. wxWindow* aParent,
  75. int aStyle,
  76. const bool aKeepWorkingDirectory,
  77. const wxPoint& aPosition,
  78. wxString* aMruPath )
  79. {
  80. wxString fullfilename;
  81. wxString curr_cwd = wxGetCwd();
  82. wxString defaultname = aFileName;
  83. wxString defaultpath = aPath;
  84. wxString dotted_Ext = wxT(".") + aExtension;
  85. #ifdef __WINDOWS__
  86. defaultname.Replace( wxT( "/" ), wxT( "\\" ) );
  87. defaultpath.Replace( wxT( "/" ), wxT( "\\" ) );
  88. #endif
  89. if( defaultpath.IsEmpty() )
  90. {
  91. if( aMruPath == NULL )
  92. defaultpath = wxGetCwd();
  93. else
  94. defaultpath = *aMruPath;
  95. }
  96. wxSetWorkingDirectory( defaultpath );
  97. #if 0 && defined (DEBUG)
  98. printf( "defaultpath=\"%s\" defaultname=\"%s\" Ext=\"%s\" Mask=\"%s\" flag=%d keep_working_directory=%d\n",
  99. TO_UTF8( defaultpath ),
  100. TO_UTF8( defaultname ),
  101. TO_UTF8( aExtension ),
  102. TO_UTF8( aWildcard ),
  103. aStyle,
  104. aKeepWorkingDirectory );
  105. #endif
  106. fullfilename = wxFileSelector( aTitle,
  107. defaultpath,
  108. defaultname,
  109. dotted_Ext,
  110. aWildcard,
  111. aStyle, // open mode wxFD_OPEN, wxFD_SAVE ..
  112. aParent,
  113. aPosition.x, aPosition.y );
  114. if( aKeepWorkingDirectory )
  115. wxSetWorkingDirectory( curr_cwd );
  116. if( !fullfilename.IsEmpty() && aMruPath )
  117. {
  118. wxFileName fn = fullfilename;
  119. *aMruPath = fn.GetPath();
  120. }
  121. return fullfilename;
  122. }
  123. wxString FindKicadFile( const wxString& shortname )
  124. {
  125. // Test the presence of the file in the directory shortname of
  126. // the KiCad binary path.
  127. #ifndef __WXMAC__
  128. wxString fullFileName = Pgm().GetExecutablePath() + shortname;
  129. #else
  130. wxString fullFileName = Pgm().GetExecutablePath() + wxT( "Contents/MacOS/" ) + shortname;
  131. #endif
  132. if( wxFileExists( fullFileName ) )
  133. return fullFileName;
  134. // Test the presence of the file in the directory shortname
  135. // defined by the environment variable KiCad.
  136. if( Pgm().IsKicadEnvVariableDefined() )
  137. {
  138. fullFileName = Pgm().GetKicadEnvVariable() + shortname;
  139. if( wxFileExists( fullFileName ) )
  140. return fullFileName;
  141. }
  142. // Path list for KiCad binary files
  143. const static wxChar* possibilities[] = {
  144. #if defined( __WINDOWS__ )
  145. wxT( "c:/kicad/bin/" ),
  146. wxT( "d:/kicad/bin/" ),
  147. wxT( "c:/Program Files/kicad/bin/" ),
  148. wxT( "d:/Program Files/kicad/bin/" ),
  149. #elif defined( __WXMAC__ )
  150. // all internal paths are relative to main bundle kicad.app
  151. wxT( "Contents/Applications/pcbnew.app/Contents/MacOS/" ),
  152. wxT( "Contents/Applications/eeschema.app/Contents/MacOS/" ),
  153. wxT( "Contents/Applications/gerbview.app/Contents/MacOS/" ),
  154. wxT( "Contents/Applications/bitmap2component.app/Contents/MacOS/" ),
  155. wxT( "Contents/Applications/pcb_calculator.app/Contents/MacOS/" ),
  156. wxT( "Contents/Applications/pl_editor.app/Contents/MacOS/" ),
  157. #else
  158. wxT( "/usr/bin/" ),
  159. wxT( "/usr/local/bin/" ),
  160. wxT( "/usr/local/kicad/bin/" ),
  161. #endif
  162. };
  163. // find binary file from possibilities list:
  164. for( unsigned i=0; i<DIM(possibilities); ++i )
  165. {
  166. #ifndef __WXMAC__
  167. fullFileName = possibilities[i] + shortname;
  168. #else
  169. // make relative paths absolute
  170. fullFileName = Pgm().GetExecutablePath() + possibilities[i] + shortname;
  171. #endif
  172. if( wxFileExists( fullFileName ) )
  173. return fullFileName;
  174. }
  175. return shortname;
  176. }
  177. int ExecuteFile( wxWindow* frame, const wxString& ExecFile, const wxString& param,
  178. wxProcess *callback )
  179. {
  180. wxString fullFileName = FindKicadFile( ExecFile );
  181. if( wxFileExists( fullFileName ) )
  182. {
  183. if( !param.IsEmpty() )
  184. fullFileName += wxT( " " ) + param;
  185. return ProcessExecute( fullFileName, wxEXEC_ASYNC, callback );
  186. }
  187. #ifdef __WXMAC__
  188. else
  189. {
  190. AddDelimiterString( fullFileName );
  191. if( !param.IsEmpty() )
  192. fullFileName += wxT( " " ) + param;
  193. return ProcessExecute( wxT( "/usr/bin/open -a " ) + fullFileName, wxEXEC_ASYNC, callback );
  194. }
  195. #endif
  196. wxString msg;
  197. msg.Printf( _( "Command <%s> could not found" ), GetChars( fullFileName ) );
  198. DisplayError( frame, msg, 20 );
  199. return -1;
  200. }
  201. wxString KicadDatasPath()
  202. {
  203. bool found = false;
  204. wxString data_path;
  205. if( Pgm().IsKicadEnvVariableDefined() ) // Path defined by the KICAD environment variable.
  206. {
  207. data_path = Pgm().GetKicadEnvVariable();
  208. found = true;
  209. }
  210. else // Path of executables.
  211. {
  212. #ifndef __WXMAC__
  213. wxString tmp = Pgm().GetExecutablePath();
  214. #ifdef __WINDOWS__
  215. tmp.MakeLower();
  216. #endif
  217. if( tmp.Contains( wxT( "kicad" ) ) )
  218. {
  219. #ifdef __WINDOWS__
  220. tmp = Pgm().GetExecutablePath();
  221. #endif
  222. if( tmp.Last() == '/' )
  223. tmp.RemoveLast();
  224. data_path = tmp.BeforeLast( '/' ); // id cd ../
  225. data_path += UNIX_STRING_DIR_SEP;
  226. // Old versions of KiCad use kicad/ as default for data
  227. // and last versions kicad/share/
  228. // So we search for kicad/share/ first
  229. wxString old_path = data_path;
  230. data_path += wxT( "share/" );
  231. if( wxDirExists( data_path ) )
  232. {
  233. found = true;
  234. }
  235. else if( wxDirExists( old_path ) )
  236. {
  237. data_path = old_path;
  238. found = true;
  239. }
  240. }
  241. }
  242. if( !found )
  243. {
  244. // find KiCad from possibilities list:
  245. // /usr/local/kicad/ or c:/kicad/
  246. const static wxChar* possibilities[] = {
  247. #ifdef __WINDOWS__
  248. wxT( "c:/kicad/share/" ),
  249. wxT( "d:/kicad/share/" ),
  250. wxT( "c:/kicad/" ),
  251. wxT( "d:/kicad/" ),
  252. wxT( "c:/Program Files/kicad/share/" ),
  253. wxT( "d:/Program Files/kicad/share/" ),
  254. wxT( "c:/Program Files/kicad/" ),
  255. wxT( "d:/Program Files/kicad/" ),
  256. #else
  257. wxT( "/usr/share/kicad/" ),
  258. wxT( "/usr/local/share/kicad/" ),
  259. wxT( "/usr/local/kicad/share/" ), // default data path for "universal
  260. // tarballs" and build for a server
  261. // (new)
  262. wxT( "/usr/local/kicad/" ), // default data path for "universal
  263. // tarballs" and build for a server
  264. // (old)
  265. #endif
  266. };
  267. for( unsigned i=0; i<DIM(possibilities); ++i )
  268. {
  269. data_path = possibilities[i];
  270. if( wxDirExists( data_path ) )
  271. {
  272. found = true;
  273. break;
  274. }
  275. }
  276. #else
  277. // On OSX point to Contents/SharedSupport folder of main bundle
  278. data_path = GetOSXKicadDataDir();
  279. found = true;
  280. #endif
  281. }
  282. if( found )
  283. {
  284. data_path.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );
  285. if( data_path.Last() != '/' )
  286. data_path += UNIX_STRING_DIR_SEP;
  287. }
  288. else
  289. {
  290. data_path.Empty();
  291. }
  292. return data_path;
  293. }
  294. bool OpenPDF( const wxString& file )
  295. {
  296. wxString command;
  297. wxString filename = file;
  298. // Quote in case there are spaces in the file name.
  299. AddDelimiterString( filename );
  300. Pgm().ReadPdfBrowserInfos();
  301. if( !Pgm().UseSystemPdfBrowser() ) // Run the preferred PDF Browser
  302. {
  303. command = Pgm().GetPdfBrowserName() + wxT( " " ) + filename;
  304. }
  305. else
  306. {
  307. if( wxLaunchDefaultApplication( file ) )
  308. return true;
  309. // If launching the system default PDF viewer fails, fall through with empty command
  310. // string so the error message is displayed.
  311. }
  312. if( !command.IsEmpty() )
  313. {
  314. if( ProcessExecute( command ) )
  315. {
  316. return true;
  317. }
  318. else
  319. {
  320. wxString msg;
  321. msg.Printf( _( "Problem while running the PDF viewer\nCommand is '%s'" ), command );
  322. DisplayError( NULL, msg );
  323. }
  324. }
  325. else
  326. {
  327. wxString msg;
  328. msg.Printf( _( "Unable to find a PDF viewer for '%s'" ), file );
  329. DisplayError( NULL, msg );
  330. }
  331. return false;
  332. }
  333. void OpenFile( const wxString& file )
  334. {
  335. wxString command;
  336. wxString filename = file;
  337. wxFileName CurrentFileName( filename );
  338. wxString ext, type;
  339. ext = CurrentFileName.GetExt();
  340. wxFileType* filetype = wxTheMimeTypesManager->GetFileTypeFromExtension( ext );
  341. bool success = false;
  342. wxFileType::MessageParameters params( filename, type );
  343. if( filetype )
  344. success = filetype->GetOpenCommand( &command, params );
  345. delete filetype;
  346. if( success && !command.IsEmpty() )
  347. ProcessExecute( command );
  348. }
  349. wxString QuoteFullPath( wxFileName& fn, wxPathFormat format )
  350. {
  351. return wxT( "\"" ) + fn.GetFullPath( format ) + wxT( "\"" );
  352. }