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 =
119 [&]( DOWNGRADE_BUCKET aBucket, const wxString& aLabel )
120 {
121 text += wxString::Format( wxS( "\n%s: %d\n" ), aLabel, Count( aBucket ) );
122
123 for( const COMPAT_ENTRY& entry : m_entries )
124 {
125 if( entry.m_bucket != aBucket )
126 continue;
127
128 text += wxString::Format( wxS( " %s (%d)\n" ), entry.m_feature, entry.m_count );
129
130 if( !entry.m_detail.IsEmpty() )
131 text += wxString::Format( wxS( " %s\n" ), entry.m_detail );
132 }
133 };
134
135 addSection( DOWNGRADE_BUCKET::KEEP, _( "Keep" ) );
136 addSection( DOWNGRADE_BUCKET::LOWER, _( "Approximate" ) );
137 addSection( DOWNGRADE_BUCKET::DROP, _( "Drop" ) );
138 addSection( DOWNGRADE_BUCKET::BLOCK, _( "Cannot export" ) );
139
140 return text;
141 }
142
143 void Print( REPORTER* aReporter ) const
144 {
145 for( const COMPAT_ENTRY& entry : m_entries )
146 {
147 wxString label;
148
149 switch( entry.m_bucket )
150 {
151 case DOWNGRADE_BUCKET::KEEP: label = _( "keep" ); break;
152 case DOWNGRADE_BUCKET::LOWER: label = _( "approximate" ); break;
153 case DOWNGRADE_BUCKET::DROP: label = _( "drop" ); break;
154 case DOWNGRADE_BUCKET::BLOCK: label = _( "block" ); break;
155 }
156
157 aReporter->Report( wxString::Format( wxT( " [%s] %s (%d): %s\n" ),
158 label,
159 entry.m_feature,
160 entry.m_count,
161 entry.m_detail ),
163 }
164 }
165
166private:
167 bool Has( DOWNGRADE_BUCKET aBucket ) const
168 {
169 for( const COMPAT_ENTRY& entry : m_entries )
170 {
171 if( entry.m_bucket == aBucket )
172 return true;
173 }
174
175 return false;
176 }
177
178 std::vector<COMPAT_ENTRY> m_entries;
179};
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