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.

123 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef RC_JSON_SCHEMA_H
  20. #define RC_JSON_SCHEMA_H
  21. #include <nlohmann/json.hpp>
  22. #include <wx/string.h>
  23. #include <vector>
  24. #include <json_conversions.h>
  25. /**
  26. * Contains the json serialization structs for DRC and ERC reports
  27. * If you are trying to change the output schema
  28. * Please update the schemas located in /resources/schemas/ as both documentation
  29. * and use by end user implementations
  30. */
  31. namespace RC_JSON
  32. {
  33. struct COORDINATE
  34. {
  35. double x;
  36. double y;
  37. };
  38. NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( COORDINATE, x, y )
  39. struct AFFECTED_ITEM
  40. {
  41. wxString uuid;
  42. wxString description;
  43. COORDINATE pos;
  44. };
  45. NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( AFFECTED_ITEM, uuid, description, pos )
  46. struct VIOLATION
  47. {
  48. wxString type;
  49. wxString description;
  50. wxString severity;
  51. std::vector<AFFECTED_ITEM> items;
  52. bool excluded;
  53. };
  54. inline void to_json( nlohmann::json& aJson, const VIOLATION& aViolation )
  55. {
  56. aJson["type"] = aViolation.type;
  57. aJson["description"] = aViolation.description;
  58. aJson["severity"] = aViolation.severity;
  59. aJson["items"] = aViolation.items;
  60. if( aViolation.excluded )
  61. aJson["excluded"] = aViolation.excluded;
  62. }
  63. inline void from_json( const nlohmann::json& aJson, VIOLATION& aViolation )
  64. {
  65. aJson.at( "type" ).get_to( aViolation.type );
  66. aJson.at( "description" ).get_to( aViolation.description );
  67. aJson.at( "severity" ).get_to( aViolation.severity );
  68. aJson.at( "items" ).get_to( aViolation.items );
  69. aJson.at( "excluded" ).get_to( aViolation.excluded );
  70. }
  71. struct REPORT_BASE
  72. {
  73. wxString $schema;
  74. wxString source;
  75. wxString date;
  76. wxString kicad_version;
  77. wxString type;
  78. wxString coordinate_units;
  79. };
  80. struct DRC_REPORT : REPORT_BASE
  81. {
  82. DRC_REPORT() { type = wxS( "drc" ); }
  83. std::vector<VIOLATION> violations;
  84. std::vector<VIOLATION> unconnected_items;
  85. std::vector<VIOLATION> schematic_parity;
  86. };
  87. NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( DRC_REPORT, $schema, source, date, kicad_version, violations,
  88. unconnected_items, schematic_parity, coordinate_units )
  89. struct ERC_SHEET
  90. {
  91. wxString uuid_path;
  92. wxString path;
  93. std::vector<VIOLATION> violations;
  94. };
  95. NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( ERC_SHEET, uuid_path, path, violations )
  96. struct ERC_REPORT : REPORT_BASE
  97. {
  98. ERC_REPORT() { type = wxS( "erc" ); }
  99. std::vector<ERC_SHEET> sheets;
  100. };
  101. NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( ERC_REPORT, $schema, source, date, kicad_version, sheets,
  102. coordinate_units )
  103. } // namespace RC_JSON
  104. #endif