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.

159 lines
5.5 KiB

3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <wx/string.h>
  25. #include <wx/translation.h>
  26. #include <ki_exception.h>
  27. const wxString IO_ERROR::What() const
  28. {
  29. #ifdef DEBUG
  30. return wxString( wxS( "IO_ERROR: " ) ) + Problem() + wxS("\n\n" ) + Where();
  31. #else
  32. return Problem();
  33. #endif
  34. }
  35. const wxString IO_ERROR::Where() const
  36. {
  37. return where;
  38. }
  39. const wxString IO_ERROR::Problem() const
  40. {
  41. return problem;
  42. }
  43. void IO_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
  44. const char* aThrowersFunction, int aThrowersLineNumber )
  45. {
  46. problem = aProblem;
  47. // The throwers filename is a full filename, depending on Kicad source location.
  48. // a short filename will be printed (it is better for user, the full filename has no meaning).
  49. wxString srcname = aThrowersFile;
  50. // No need for translations of source code file/line messages (and wxWidget's translation
  51. // stuff has bitten us before. May be related to KICAD-YP.
  52. where.Printf( wxS( "from %s : %s() line %d" ),
  53. srcname.AfterLast( '/' ),
  54. wxString( aThrowersFunction ),
  55. aThrowersLineNumber );
  56. }
  57. void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
  58. const char* aThrowersFunction, int aThrowersLineNumber,
  59. const wxString& aSource, const char* aInputLine, int aLineNumber,
  60. int aByteIndex )
  61. {
  62. parseProblem = aProblem;
  63. problem.Printf( _( "%s in '%s', line %d, offset %d." ),
  64. aProblem,
  65. aSource,
  66. aLineNumber,
  67. aByteIndex );
  68. inputLine = aInputLine;
  69. lineNumber = aLineNumber;
  70. byteIndex = aByteIndex;
  71. // The throwers filename is a full filename, depending on Kicad source location.
  72. // a short filename will be printed (it is better for user, the full filename has no meaning).
  73. wxString srcname = aThrowersFile;
  74. // No need for translations of source code file/line messages (and wxWidget's translation
  75. // stuff has bitten us before. May be related to KICAD-YP.
  76. where.Printf( wxS( "from %s : %s() line %d" ),
  77. srcname.AfterLast( '/' ),
  78. wxString( aThrowersFunction ),
  79. aThrowersLineNumber );
  80. }
  81. void FUTURE_FORMAT_ERROR::init( const wxString& aRequiredVersion,
  82. const wxString& aRequiredGenerator )
  83. {
  84. requiredVersion = aRequiredVersion;
  85. requiredGenerator = aRequiredGenerator;
  86. if( requiredGenerator.IsEmpty() )
  87. {
  88. problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
  89. "recent version than the one you are running.\n\n"
  90. "To open it you will need to upgrade KiCad to a version dated %s or "
  91. "later." ),
  92. aRequiredVersion );
  93. }
  94. else
  95. {
  96. problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
  97. "recent version than the one you are running.\n\n"
  98. "To open it you will need to upgrade KiCad to version %s or "
  99. "later (file format dated %s or later)." ),
  100. aRequiredGenerator, aRequiredVersion );
  101. }
  102. }
  103. FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion,
  104. const wxString& aRequiredGenerator ) :
  105. PARSE_ERROR()
  106. {
  107. init( aRequiredVersion, aRequiredGenerator );
  108. lineNumber = 0;
  109. byteIndex = 0;
  110. }
  111. FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError,
  112. const wxString& aRequiredVersion,
  113. const wxString& aRequiredGenerator ) :
  114. PARSE_ERROR()
  115. {
  116. if( const FUTURE_FORMAT_ERROR* ffe = dynamic_cast<const FUTURE_FORMAT_ERROR*>( &aParseError ) )
  117. {
  118. requiredVersion = ffe->requiredVersion;
  119. requiredGenerator = ffe->requiredGenerator;
  120. problem = ffe->Problem();
  121. }
  122. else
  123. {
  124. init( aRequiredVersion, aRequiredGenerator );
  125. if( !aParseError.Problem().IsEmpty() )
  126. problem += wxS( "\n\n" ) + _( "Full error text:" ) + wxS( "\n" ) + aParseError.Problem();
  127. }
  128. lineNumber = aParseError.lineNumber;
  129. byteIndex = aParseError.byteIndex;
  130. inputLine = aParseError.inputLine;
  131. }