KiCad PCB EDA Suite
Loading...
Searching...
No Matches
compatibility_report.h
Go to the documentation of this file.
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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <vector>
23#include <wx/string.h>
24#include <wx/intl.h>
25
26#include <reporter.h>
27
36
37
46
47
53{
54public:
55 void Add( DOWNGRADE_BUCKET aBucket, const wxString& aFeature, const wxString& aDetail = wxEmptyString,
56 int aCount = 1 )
57 {
58 // Merge repeats, so classifying many sheets or files yields one row per feature.
59 for( COMPAT_ENTRY& entry : m_entries )
60 {
61 if( entry.m_bucket == aBucket && entry.m_feature == aFeature )
62 {
63 entry.m_count += aCount;
64
65 if( entry.m_detail.IsEmpty() )
66 entry.m_detail = aDetail;
67
68 return;
69 }
70 }
71
72 m_entries.push_back( { aBucket, aFeature, aDetail, aCount } );
73 }
74
75 void Merge( const COMPATIBILITY_REPORT& aOther )
76 {
77 for( const COMPAT_ENTRY& entry : aOther.m_entries )
78 Add( entry.m_bucket, entry.m_feature, entry.m_detail, entry.m_count );
79 }
80
81 const std::vector<COMPAT_ENTRY>& Entries() const { return m_entries; }
82
85
87 bool IsBlocked() const { return Has( DOWNGRADE_BUCKET::BLOCK ); }
88
89 int Count( DOWNGRADE_BUCKET aBucket ) const
90 {
91 int total = 0;
92
93 for( const COMPAT_ENTRY& entry : m_entries )
94 {
95 if( entry.m_bucket == aBucket )
96 total += entry.m_count;
97 }
98
99 return total;
100 }
101
103 wxString ToText( const wxString& aTargetName ) const
104 {
105 wxString text = _( "KiCad Compatibility Report" ) + wxS( "\n" );
106 text += wxString::Format( _( "Target: %s" ), aTargetName ) + wxS( "\n\n" );
107 text += _( "Compatibility preview. This report describes planned changes." ) + wxS( "\n" );
108
109 if( IsBlocked() )
110 text += _( "Export is blocked by unsupported features." );
111 else if( IsLossy() )
112 text += _( "Export requires approval for the changes below." );
113 else
114 text += _( "No compatibility changes were reported." );
115
116 text += wxS( "\n\n" ) + _( "Counts cover reported items only." ) + wxS( "\n" );
117
118 auto addSection = [&]( DOWNGRADE_BUCKET aBucket, const wxString& aLabel )
119 {
120 text += wxString::Format( wxS( "\n%s: %d\n" ), aLabel, Count( aBucket ) );
121
122 for( const COMPAT_ENTRY& entry : m_entries )
123 {
124 if( entry.m_bucket != aBucket )
125 continue;
126
127 text += wxString::Format( wxS( " %s (%d)\n" ), entry.m_feature, entry.m_count );
128
129 if( !entry.m_detail.IsEmpty() )
130 text += wxString::Format( wxS( " %s\n" ), entry.m_detail );
131 }
132 };
133
134 addSection( DOWNGRADE_BUCKET::KEEP, _( "Keep" ) );
135 addSection( DOWNGRADE_BUCKET::LOWER, _( "Approximate" ) );
136 addSection( DOWNGRADE_BUCKET::DROP, _( "Drop" ) );
137 addSection( DOWNGRADE_BUCKET::BLOCK, _( "Cannot export" ) );
138
139 return text;
140 }
141
142 void Print( REPORTER* aReporter ) const
143 {
144 for( const COMPAT_ENTRY& entry : m_entries )
145 {
146 wxString label;
147
148 switch( entry.m_bucket )
149 {
150 case DOWNGRADE_BUCKET::KEEP: label = _( "keep" ); break;
151 case DOWNGRADE_BUCKET::LOWER: label = _( "approximate" ); break;
152 case DOWNGRADE_BUCKET::DROP: label = _( "drop" ); break;
153 case DOWNGRADE_BUCKET::BLOCK: label = _( "block" ); break;
154 }
155
156 aReporter->Report( wxString::Format( wxT( " [%s] %s (%d): %s\n" ), label, entry.m_feature, entry.m_count,
157 entry.m_detail ),
159 }
160 }
161
162private:
163 bool Has( DOWNGRADE_BUCKET aBucket ) const
164 {
165 for( const COMPAT_ENTRY& entry : m_entries )
166 {
167 if( entry.m_bucket == aBucket )
168 return true;
169 }
170
171 return false;
172 }
173
174 std::vector<COMPAT_ENTRY> m_entries;
175};
What an export to a given target will keep, approximate, drop, or block.
wxString ToText(const wxString &aTargetName) const
A readable preview of the classified export, including counts and feature details.
bool Has(DOWNGRADE_BUCKET aBucket) const
std::vector< COMPAT_ENTRY > m_entries
void Add(DOWNGRADE_BUCKET aBucket, const wxString &aFeature, const wxString &aDetail=wxEmptyString, int aCount=1)
void Print(REPORTER *aReporter) const
void Merge(const COMPATIBILITY_REPORT &aOther)
bool IsLossy() const
True if anything is approximated or dropped. This is what triggers the lossy warning.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
int Count(DOWNGRADE_BUCKET aBucket) const
const std::vector< COMPAT_ENTRY > & Entries() const
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
DOWNGRADE_BUCKET
What happens to a feature when we export to an older KiCad.
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ KEEP
Exists in the target, written unchanged.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
#define _(s)
@ RPT_SEVERITY_INFO
One line in the compatibility report.
wxString m_feature
e.g. "Net chains"
int m_count
DOWNGRADE_BUCKET m_bucket
wxString m_detail
optional note, e.g. the electrical consequence