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.

115 lines
3.9 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/wx.h>
  25. #include <ki_exception.h>
  26. #define THROWERS_WHERE _( "from %s : %s() line:%d" )
  27. #define PARSE_PROBLEM _( "%s in input/source\n\"%s\"\nline %d, offset %d" )
  28. const wxString IO_ERROR::What() const
  29. {
  30. #ifdef DEBUG
  31. return wxString( "IO_ERROR: " ) + Problem() + "\n\n" + Where();
  32. #else
  33. return Problem();
  34. #endif
  35. }
  36. const wxString IO_ERROR::Where() const
  37. {
  38. return where;
  39. }
  40. const wxString IO_ERROR::Problem() const
  41. {
  42. return problem;
  43. }
  44. void IO_ERROR::init( const wxString& aProblem, const char* aThrowersFile, 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( THROWERS_WHERE, srcname.AfterLast( '/' ).GetData(),
  51. wxString( aThrowersFunction ).GetData(), aThrowersLineNumber );
  52. }
  53. void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
  54. const char* aThrowersFunction, int aThrowersLineNumber,
  55. const wxString& aSource,
  56. const char* aInputLine,
  57. int aLineNumber, int aByteIndex )
  58. {
  59. problem.Printf( PARSE_PROBLEM, aProblem.GetData(), aSource.GetData(), aLineNumber, aByteIndex );
  60. inputLine = aInputLine;
  61. lineNumber = aLineNumber;
  62. byteIndex = aByteIndex;
  63. // The throwers filename is a full filename, depending on Kicad source location.
  64. // a short filename will be printed (it is better for user, the full filename has no meaning).
  65. wxString srcname = aThrowersFile;
  66. where.Printf( THROWERS_WHERE, srcname.AfterLast( '/' ).GetData(),
  67. wxString( aThrowersFunction ).GetData(), aThrowersLineNumber );
  68. }
  69. FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError,
  70. const wxString& aRequiredVersion ) :
  71. PARSE_ERROR(), requiredVersion( aRequiredVersion )
  72. {
  73. // Avoid double-printing the error message
  74. bool wrapped_same_type = !!( dynamic_cast<const FUTURE_FORMAT_ERROR *>( &aParseError ) );
  75. if( wrapped_same_type )
  76. {
  77. problem = aParseError.Problem();
  78. }
  79. else
  80. {
  81. problem.Printf( _(
  82. "KiCad was unable to open this file, as it was created with\n"
  83. "a more recent version than the one you are running.\n"
  84. "To open it, you'll need to upgrade KiCad to a more recent version.\n\n"
  85. "Date of KiCad version required (or newer): %s\n\n"
  86. "Full error text:\n%s" ),
  87. requiredVersion, aParseError.Problem() );
  88. }
  89. lineNumber = aParseError.lineNumber;
  90. byteIndex = aParseError.byteIndex;
  91. inputLine = aParseError.inputLine;
  92. }