KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fp_lib_differ.cpp
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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include "fp_lib_differ.h"
25
26#include <footprint.h>
27#include <io/io_utils.h>
28#include <io/io_base.h>
30#include <richio.h>
31#include <trace_helpers.h>
32
33#include <wx/log.h>
34
35
36namespace KICAD_DIFF
37{
38
39FP_LIB_DIFFER::FP_LIB_DIFFER( const FOOTPRINT_MAP& aBefore, const FOOTPRINT_MAP& aAfter, const wxString& aPath ) :
40 m_before( aBefore ),
41 m_after( aAfter ),
42 m_path( aPath )
43{
44}
45
46
48
49
50std::pair<std::vector<std::unique_ptr<FOOTPRINT>>, FP_LIB_DIFFER::FOOTPRINT_MAP>
51FP_LIB_DIFFER::LoadLibrary( const wxString& aPrettyPath )
52{
53 std::vector<std::unique_ptr<FOOTPRINT>> owners;
54 FOOTPRINT_MAP map;
55
57 wxArrayString names;
58
59 // Throws on corrupt/unreadable libraries; callers distinguish failures
60 // from a deliberately-empty .pretty directory.
61 io.FootprintEnumerate( names, aPrettyPath, false, nullptr );
62
63 // Per-footprint loads propagate too; previously swallowing them let a
64 // bilaterally-corrupt footprint vanish from the diff entirely.
65 for( const wxString& name : names )
66 {
67 std::unique_ptr<FOOTPRINT> owner( io.FootprintLoad( aPrettyPath, name, false, nullptr ) );
68
69 if( !owner )
70 {
71 wxLogTrace( traceDiffMerge, wxT( "FP_LIB_DIFFER: '%s' returned null on load" ), name );
72 continue;
73 }
74
75 map[name] = owner.get();
76 owners.push_back( std::move( owner ) );
77 }
78
79 return { std::move( owners ), std::move( map ) };
80}
81
82
84{
85 return DiffLibraryByName(
86 m_before, m_after, m_path, wxS( "pretty" ), wxS( "FOOTPRINT" ), m_options,
87 []( const FOOTPRINT* aFp ) { return aFp->GetBoundingBox( false ); },
88 []( const FOOTPRINT* aA, const FOOTPRINT* aB ) { return !( *aA == *aB ); } );
89}
90
91} // namespace KICAD_DIFF
const char * name
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
static std::pair< std::vector< std::unique_ptr< FOOTPRINT > >, FOOTPRINT_MAP > LoadLibrary(const wxString &aPrettyPath)
Load a .pretty directory into a FOOTPRINT_MAP.
const FOOTPRINT_MAP & m_before
FP_LIB_DIFFER(const FOOTPRINT_MAP &aBefore, const FOOTPRINT_MAP &aAfter, const wxString &aPath=wxEmptyString)
DOCUMENT_DIFF Diff() override
Produce a DOCUMENT_DIFF of the inputs the concrete differ was constructed with.
const FOOTPRINT_MAP & m_after
std::map< wxString, const FOOTPRINT * > FOOTPRINT_MAP
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
const wxChar *const traceDiffMerge
Flag to enable diff/merge engine and renderer debugging output.
DOCUMENT_DIFF DiffLibraryByName(const MAP &aBefore, const MAP &aAfter, const wxString &aPath, const wxString &aDocType, const wxString &aTypeName, const KICAD_DIFFER::OPTIONS &aOptions, BBoxFn aBBox, ChangedFn aChanged)
Shared name-keyed library diff used by FP_LIB_DIFFER and SYM_LIB_DIFFER.
The full set of changes between two parsed documents of one type.
wxLogTrace helper definitions.