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{
41 if( !aBefore && !aAfter )
42 {
43 aCanvas.SetContextItems( {} );
44 return;
45 }
46
47 const DIFF_COLOR_THEME theme;
48
49 auto colorFor = [&]( CHANGE_KIND aKind ) -> KIGFX::COLOR4D
50 {
51 switch( aKind )
52 {
53 case CHANGE_KIND::ADDED: return theme.added;
54 case CHANGE_KIND::REMOVED: return theme.removed;
55 default: return theme.modified;
56 }
57 };
58
59 std::vector<SYM_ELEMENT> elements = DiffSymbolElements( aBefore, aAfter );
60 std::map<KIID, KIGFX::COLOR4D> overrides;
61
62 for( const SYM_ELEMENT& element : elements )
63 {
64 overrides[element.item->m_Uuid] = colorFor( element.kind );
65 const_cast<EDA_ITEM*>( element.item )->SetBrightened();
66 }
67
68 std::vector<KIGFX::VIEW_ITEM*> items;
69
70 if( aAfter )
71 {
72 for( SCH_ITEM& item : aAfter->GetDrawItems() )
73 items.push_back( &item );
74 }
75
76 for( const SYM_ELEMENT& element : elements )
77 {
78 if( element.kind == CHANGE_KIND::REMOVED )
79 items.push_back( const_cast<EDA_ITEM*>( element.item ) );
80 }
81
83 aCanvas.SetContextPainter( MakeSchDiffContextPainter( aCanvas.GetGAL(), nullptr, theme.reference, overrides ) );
84 aCanvas.SetContextItems( items );
85 aCanvas.ZoomToFit();
86}
87
88} // 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:96
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Define a library symbol object.
Definition lib_symbol.h:79
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:709
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
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 SetContextItems(const std::vector< KIGFX::VIEW_ITEM * > &aItems)
Replace source document context items.
void SetContextPainter(std::unique_ptr< KIGFX::PAINTER > aPainter)
Install the native painter used for drawing source document context.
CHANGE_KIND
Coarse classification of a single item-level change between two documents.
std::vector< SYM_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 ConfigureSymDiffCanvasContext(WIDGET_DIFF_CANVAS &aCanvas, LIB_SYMBOL *aBefore, LIB_SYMBOL *aAfter)
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
KIGFX::COLOR4D reference
Default color for source-document context geometry.
Definition diff_scene.h:287