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.

131 lines
4.1 KiB

  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( "IO_ERROR: " ) + Problem() + "\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. where.Printf( _( "from %s : %s() line %d" ),
  51. srcname.AfterLast( '/' ),
  52. wxString( aThrowersFunction ),
  53. aThrowersLineNumber );
  54. }
  55. void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
  56. const char* aThrowersFunction, int aThrowersLineNumber,
  57. const wxString& aSource, const char* aInputLine, int aLineNumber,
  58. int aByteIndex )
  59. {
  60. parseProblem = aProblem;
  61. problem.Printf( _( "%s in '%s', line %d, offset %d." ),
  62. aProblem,
  63. aSource,
  64. aLineNumber,
  65. aByteIndex );
  66. inputLine = aInputLine;
  67. lineNumber = aLineNumber;
  68. byteIndex = aByteIndex;
  69. // The throwers filename is a full filename, depending on Kicad source location.
  70. // a short filename will be printed (it is better for user, the full filename has no meaning).
  71. wxString srcname = aThrowersFile;
  72. where.Printf( _( "from %s : %s() line:%d" ),
  73. srcname.AfterLast( '/' ),
  74. wxString( aThrowersFunction ),
  75. aThrowersLineNumber );
  76. }
  77. void FUTURE_FORMAT_ERROR::init( const wxString& aRequiredVersion )
  78. {
  79. requiredVersion = aRequiredVersion;
  80. problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
  81. "recent version than the one you are running.\n\n"
  82. "To open it you will need to upgrade KiCad to a version dated %s or "
  83. "later." ),
  84. aRequiredVersion );
  85. }
  86. FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion ) :
  87. PARSE_ERROR()
  88. {
  89. init( aRequiredVersion );
  90. lineNumber = 0;
  91. byteIndex = 0;
  92. }
  93. FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError,
  94. const wxString& aRequiredVersion ) :
  95. PARSE_ERROR()
  96. {
  97. init( aRequiredVersion );
  98. if( !aParseError.Problem().IsEmpty() )
  99. problem += wxS( "\n\n" ) + _( "Full error text:" ) + wxS( "\n" ) + aParseError.Problem();
  100. lineNumber = aParseError.lineNumber;
  101. byteIndex = aParseError.byteIndex;
  102. inputLine = aParseError.inputLine;
  103. }