KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sym_diff_canvas_context.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 */
20
25
26#include <gal/painter.h>
27#include <kiid.h>
28#include <lib_symbol.h>
29#include <sch_item.h>
30#include <sch_view.h>
32
33#include <map>
34
35
36namespace KICAD_DIFF
37{
38
40 std::shared_ptr<const void> aOwner )
41{
42 if( !aBefore && !aAfter )
43 {
44 aCanvas.SetContextItems( {} );
45 return;
46 }
47
48 const DIFF_COLOR_THEME theme;
49
50 std::vector<LIB_ELEMENT> elements = DiffSymbolElements( aBefore, aAfter );
51 std::map<KIID, KIGFX::COLOR4D> overrides;
52
53 for( const LIB_ELEMENT& element : elements )
54 {
55 overrides[element.item->m_Uuid] = theme.ForKind( element.kind );
56 const_cast<EDA_ITEM*>( element.item )->SetBrightened();
57 }
58
59 std::vector<KIGFX::VIEW_ITEM*> items;
60
61 if( aAfter )
62 {
63 for( SCH_ITEM& item : aAfter->GetDrawItems() )
64 items.push_back( &item );
65 }
66
67 for( const LIB_ELEMENT& element : elements )
68 {
69 if( element.kind == CHANGE_KIND::REMOVED )
70 items.push_back( const_cast<EDA_ITEM*>( element.item ) );
71 }
72
74 aCanvas.SetContextPainter( MakeSchDiffContextPainter( aCanvas.GetGAL(), nullptr, theme.reference, overrides ) );
75 aCanvas.SetContextItems( items, std::move( aOwner ) );
76 aCanvas.ZoomToFit();
77}
78
79
81 const SYM_LIB_DIFFER::SYMBOL_MAP& aAfter, const wxString& aName )
82{
83 auto flatten = [&]( const SYM_LIB_DIFFER::SYMBOL_MAP& aSide ) -> std::unique_ptr<LIB_SYMBOL>
84 {
85 auto symbol = aSide.find( aName );
86 return symbol != aSide.end() ? symbol->second->Flatten() : nullptr;
87 };
88
89 auto pair = std::make_shared<std::pair<std::unique_ptr<LIB_SYMBOL>, std::unique_ptr<LIB_SYMBOL>>>(
90 flatten( aBefore ), flatten( aAfter ) );
91
92 ConfigureSymDiffCanvasContext( aCanvas, pair->first.get(), pair->second.get(), pair );
93}
94
95} // namespace KICAD_DIFF
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
std::map< wxString, const LIB_SYMBOL * > SYMBOL_MAP
Library content is a map of (canonical_name -> LIB_SYMBOL*).
Define a library symbol object.
Definition lib_symbol.h:114
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:845
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
GAL-backed canvas for visualizing a KICAD_DIFF::DIFF_SCENE.
void ZoomToFit()
Center the view on the scene's document bbox.
void SetWorldUnitLength(double aWorldUnitLength)
void SetContextPainter(std::unique_ptr< KIGFX::PAINTER > aPainter)
Install the native painter used for drawing source document context.
void SetContextItems(const std::vector< KIGFX::VIEW_ITEM * > &aItems, std::shared_ptr< const void > aOwner=nullptr)
Replace source document context items.
void ConfigureSymDiffCanvasContext(WIDGET_DIFF_CANVAS &aCanvas, LIB_SYMBOL *aBefore, LIB_SYMBOL *aAfter, std::shared_ptr< const void > aOwner)
Draw aBefore and aAfter, which aOwner keeps alive for as long as the canvas shows them.
std::vector< LIB_ELEMENT > DiffSymbolElements(const LIB_SYMBOL *aBefore, const LIB_SYMBOL *aAfter)
Compares the elements of two library symbols.
std::unique_ptr< KIGFX::PAINTER > MakeSchDiffContextPainter(KIGFX::GAL *aGal, SCHEMATIC *aSchematic, const KIGFX::COLOR4D &aColor, std::map< KIID, KIGFX::COLOR4D > aOverrides)
void ShowSymbolPair(WIDGET_DIFF_CANVAS &aCanvas, const SYM_LIB_DIFFER::SYMBOL_MAP &aBefore, const SYM_LIB_DIFFER::SYMBOL_MAP &aAfter, const wxString &aName)
Draw the symbol aName as it is in aBefore and aAfter.
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
Diff colors with defaults for light backgrounds.
Definition diff_scene.h:278
KIGFX::COLOR4D reference
Default color for source-document context geometry.
Definition diff_scene.h:292
const KIGFX::COLOR4D & ForKind(KICAD_DIFF::CHANGE_KIND aKind) const
Color of an added, removed or modified element.
Definition diff_scene.h:296
One changed element of a library item, such as a pin, pad, field or graphic.