33#include <nlohmann/json.hpp>
39 m_reportUnits( aReportUnits )
48 wxString msg = wxString::Format(
_(
"ERC report (%s, Encoding UTF8)\n" ),
51 std::map<KIID, EDA_ITEM*> itemMap;
65 std::map<SCH_SHEET_PATH, std::vector<ERC_ITEM*>> orderedItems;
67 for(
int i = 0; i < errors.
GetCount(); ++i )
71 if( item->MainItemHasSheetPath() )
72 orderedItems[item->GetMainItemSheetPath()].emplace_back( item );
74 orderedItems[sheetList[0]].emplace_back( item );
78 for(
unsigned i = 0; i < sheetList.size(); i++ )
80 msg << wxString::Format(
_(
"\n***** Sheet %s\n" ), sheetList[i].PathHumanReadable() );
82 for(
ERC_ITEM* item : orderedItems[sheetList[i]] )
95 msg << item->ShowReport( &unitsProvider, severity, itemMap );
99 msg << wxString::Format(
_(
"\n ** ERC messages: %d Errors %d Warnings %d\n" ), total_count,
100 err_count, warn_count );
108 wxFFile file( aFullFileName, wxT(
"wt" ) );
110 if( !file.IsOpened() )
122 std::ofstream jsonFileStream( aFullFileName.fn_str() );
125 std::map<KIID, EDA_ITEM*> itemMap;
129 reportHead.
$schema =
"https://schemas.kicad.org/erc.v1.json";
130 reportHead.
source = fn.GetFullName();
143 std::map<SCH_SHEET_PATH, std::vector<ERC_ITEM*>> orderedItems;
145 for(
int i = 0; i < errors.
GetCount(); ++i )
149 if( item->MainItemHasSheetPath() )
150 orderedItems[item->GetMainItemSheetPath()].emplace_back( item );
152 orderedItems[sheetList[0]].emplace_back( item );
156 for(
unsigned i = 0; i < sheetList.size(); i++ )
158 RC_JSON::ERC_SHEET jsonSheet;
159 jsonSheet.path = sheetList[i].PathHumanReadable();
160 jsonSheet.uuid_path = sheetList[i].Path().AsString();
162 for(
ERC_ITEM* item : orderedItems[sheetList[i]] )
167 item->GetJsonViolation( violation, &unitsProvider, severity, itemMap );
169 jsonSheet.violations.push_back( violation );
172 reportHead.
sheets.push_back( jsonSheet );
175 nlohmann::json saveJson = nlohmann::json( reportHead );
176 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
177 jsonFileStream.flush();
178 jsonFileStream.close();
constexpr EDA_IU_SCALE schIUScale
constexpr EDA_IU_SCALE pcbIUScale
wxString GetMajorMinorPatchVersion()
Get the major, minor and patch version in a string major.minor.patch This is extracted by CMake from ...
ERC_REPORT(SCHEMATIC *aSchematic, EDA_UNITS aReportUnits)
wxString GetTextReport()
Returns the ERC report in "text" (human readable) format.
bool WriteJsonReport(const wxString &aFullFileName)
Writes a JSON formatted ERC Report to the given file path.
bool WriteTextReport(const wxString &aFullFileName)
Writes the text report also available via GetTextReport directly to a given file path.
Container for ERC settings.
SEVERITY GetSeverity(int aErrorCode) const
Holds all the data relating to one schematic.
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
ERC_SETTINGS & ErcSettings() const
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
An implementation of the RC_ITEM_LIST interface which uses the global SHEETLIST to fulfill the contra...
int GetCount(int aSeverity=-1) const override
void SetSeverities(int aSeverities) override
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const override
Retrieve a RC_ITEM by index.
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API wxString GetLabel(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
wxString GetISO8601CurrentDateTime()
std::vector< ERC_SHEET > sheets
wxString coordinate_units