40 std::shared_ptr<RC_ITEMS_PROVIDER> aMarkersProvider ) :
65 wxString msg = wxString::Format( wxT(
"ERC report (%s, Encoding UTF8)\n" ),
68 msg += wxString::Format( wxT(
"Report includes: %s\n" ),
71 std::map<KIID, EDA_ITEM*> itemMap;
82 std::map<SCH_SHEET_PATH, std::vector<ERC_ITEM*>> orderedItems;
88 if( item->MainItemHasSheetPath() )
89 orderedItems[item->GetMainItemSheetPath()].emplace_back( item );
90 else if( item->IsSheetSpecific() )
91 orderedItems[item->GetSpecificSheetPath()].emplace_back( item );
93 orderedItems[sheetList[0]].emplace_back( item );
97 for(
unsigned i = 0; i < sheetList.size(); i++ )
99 msg << wxString::Format( wxT(
"\n***** Sheet %s\n" ), sheetList[i].PathHumanReadable() );
101 for(
ERC_ITEM* item : orderedItems[sheetList[i]] )
114 msg << item->ShowReport( &unitsProvider, severity, itemMap );
118 msg << wxString::Format( wxT(
"\n ** ERC messages: %d Errors %d Warnings %d\n" ),
123 msg << wxT(
"\n ** Ignored checks:\n" );
125 bool hasIgnored =
false;
129 int code = item.GetErrorCode();
133 msg << wxString::Format( wxT(
" - %s\n" ), item.GetErrorMessage(
false ) );
139 msg << wxT(
" - " ) << wxT(
"None" ) << wxT(
"\n" );
147 wxFFile file( aFullFileName, wxT(
"wt" ) );
149 if( !file.IsOpened() )
161 std::ofstream jsonFileStream( aFullFileName.fn_str() );
164 std::map<KIID, EDA_ITEM*> itemMap;
167 wxFileName fn(
m_sch->GetFileName() );
168 reportHead.
$schema =
"https://schemas.kicad.org/erc.v1.json";
169 reportHead.
source = fn.GetFullName();
189 std::map<SCH_SHEET_PATH, std::vector<ERC_ITEM*>> orderedItems;
195 if( item->MainItemHasSheetPath() )
196 orderedItems[item->GetMainItemSheetPath()].emplace_back( item );
197 else if( item->IsSheetSpecific() )
198 orderedItems[item->GetSpecificSheetPath()].emplace_back( item );
200 orderedItems[sheetList[0]].emplace_back( item );
204 for(
unsigned i = 0; i < sheetList.size(); i++ )
206 RC_JSON::ERC_SHEET jsonSheet;
207 jsonSheet.path = sheetList[i].PathHumanReadable();
208 jsonSheet.uuid_path = sheetList[i].Path().AsString();
210 for(
ERC_ITEM* item : orderedItems[sheetList[i]] )
215 item->GetJsonViolation( violation, &unitsProvider, severity, itemMap );
217 jsonSheet.violations.push_back( violation );
220 reportHead.
sheets.push_back( jsonSheet );
225 int code = item.GetErrorCode();
230 ignoredCheck.
key = item.GetSettingsKey();
231 ignoredCheck.
description = item.GetErrorMessage(
false );
236 nlohmann::json saveJson = nlohmann::json( reportHead );
237 jsonFileStream << std::setw( 4 ) << saveJson << std::endl;
238 jsonFileStream.flush();
239 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 ...
static std::vector< std::reference_wrapper< RC_ITEM > > GetItemsWithSeverities()
ERC_REPORT(SCHEMATIC *aSchematic, EDA_UNITS aReportUnits, std::shared_ptr< RC_ITEMS_PROVIDER > aMarkersProvider=nullptr)
wxString GetTextReport()
Returns the ERC report in "text" (human readable) format in the C-locale.
bool WriteJsonReport(const wxString &aFullFileName)
Writes a JSON formatted ERC Report to the given file path in the c-locale.
std::shared_ptr< RC_ITEMS_PROVIDER > m_markersProvider
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
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
A holder for a rule check item, DRC in Pcbnew or ERC in Eeschema.
Holds all the data relating to one schematic.
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.
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 formatSeverities(int aSeverities)
Convert a severity mask to a human-readable comma-separated string.
wxString GetISO8601CurrentDateTime()
std::vector< wxString > included_severities
std::vector< ERC_SHEET > sheets
std::vector< IGNORED_CHECK > ignored_checks
wxString coordinate_units