KiCad PCB EDA Suite
Loading...
Searching...
No Matches
widget_diff_canvas.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,
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#ifndef KICAD_WIDGET_DIFF_CANVAS_H
25#define KICAD_WIDGET_DIFF_CANVAS_H
26
29
30#include <array>
31#include <functional>
32#include <map>
33#include <memory>
34#include <optional>
35#include <set>
36#include <vector>
37
38class EDA_ITEM;
39
40
41namespace KIGFX
42{
44class PAINTER;
45class VIEW_ITEM;
46class VIEW_GROUP;
47}
48
49
50namespace KIGFX
51{
52class VIEW_OVERLAY;
53}
54
55
71{
72public:
73 WIDGET_DIFF_CANVAS( wxWindow* aParent, GAL_TYPE aBackend = GAL_FALLBACK, wxWindowID aId = wxID_ANY );
74
75 ~WIDGET_DIFF_CANVAS() override;
76
77private:
80 WIDGET_DIFF_CANVAS( wxWindow* aParent, GAL_TYPE aBackend, wxWindowID aId,
81 std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> aGalOptions );
82
83public:
85 void SetScene( KICAD_DIFF::DIFF_SCENE aScene );
86
87 void SetWorldUnitLength( double aWorldUnitLength );
88
92 void SetContextPainter( std::unique_ptr<KIGFX::PAINTER> aPainter );
93
97 void SetContextItems( const std::vector<KIGFX::VIEW_ITEM*>& aItems );
98
101 void SetItemCategories( std::map<KIGFX::VIEW_ITEM*, KICAD_DIFF::CATEGORY> aMap );
102
104 using ITEM_ID_GETTER = std::function<KIID( const EDA_ITEM& )>;
105 void SetItemIdGetter( const ITEM_ID_GETTER& aGetter ) { m_itemIdGetter = aGetter; }
106
108 using DIMMER = std::function<void( KIGFX::VIEW_ITEM*, bool aDim )>;
109 void SetItemDimmer( DIMMER aDimmer ) { m_itemDimmer = std::move( aDimmer ); }
110
115 void HighlightChange( std::optional<KIID_PATH> aChangeId );
116
119 void SetCategoryVisible( KICAD_DIFF::CATEGORY aCategory, bool aVisible );
120
121 bool IsCategoryVisible( KICAD_DIFF::CATEGORY aCategory ) const;
122
125 void SetHiddenChanges( std::set<KIID_PATH> aHidden );
126
127 bool IsChangeHidden( const KIID_PATH& aChangeId ) const;
128
131 void SetLayerVisible( PCB_LAYER_ID aLayer, bool aVisible );
132
133 bool IsLayerVisible( PCB_LAYER_ID aLayer ) const;
134
138 void BeginUpdate();
139 void EndUpdate();
140
144 void ZoomToFit();
145
147 void ZoomToBBox( const BOX2I& aBBox );
148
151 void CenterOnHighlight();
152
156 using PICK_HANDLER = std::function<void( const std::optional<KIID_PATH>& )>;
157
158 void SetPickHandler( PICK_HANDLER aHandler ) { m_pickHandler = std::move( aHandler ); }
159
160 using ITEM_HANDLER = std::function<void( KIGFX::VIEW_ITEM* )>;
161 void SetDoubleClickHandler( ITEM_HANDLER aHandler ) { m_dclickHandler = std::move( aHandler ); }
162
163private:
167 void rebuildOverlay( bool aOverlayOnly = false );
168
172 void buildRenderScene();
173
175 void refreshItemDimming();
176
177 KIID getItemId( const EDA_ITEM& aItem ) const;
178
180 const KICAD_DIFF::SCENE_SHAPE* shapeAt( const wxPoint& aScreenPoint ) const;
181
184 std::optional<BOX2I> highlightedBBox() const;
185
186 void onLeftDown( wxMouseEvent& aEvent );
187 void onDoubleClick( wxMouseEvent& aEvent );
188 void onMotion( wxMouseEvent& aEvent );
189 void onLeave( wxMouseEvent& aEvent );
190 void onChar( wxKeyEvent& aEvent );
191 void onSize( wxSizeEvent& aEvent );
192
193 struct HIGHLIGHT_BOX_ITEM;
194
197 std::optional<KIID_PATH> m_highlight;
198 std::optional<KIID_PATH> m_hover;
203 std::unique_ptr<HIGHLIGHT_BOX_ITEM> m_highlightBox;
204 std::unique_ptr<HIGHLIGHT_BOX_ITEM> m_hoverBox;
205
206 std::array<bool, KICAD_DIFF::CATEGORY_COUNT> m_categoryVisible{ { true, true, true, true } };
207
208 std::set<KIID_PATH> m_hiddenChanges;
209
211 bool m_holdRebuild = false;
212
214
215 bool m_hasNativeContext = false;
216 std::unique_ptr<KIGFX::VIEW_GROUP> m_contextGroup;
217 std::vector<KIGFX::VIEW_ITEM*> m_contextGroupItems;
218 std::map<KIGFX::VIEW_ITEM*, KICAD_DIFF::CATEGORY> m_itemCategories;
219 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
220
223 std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> m_galOptions;
224
227 bool m_zoomToFitPending = false;
228};
229
230#endif // KICAD_WIDGET_DIFF_CANVAS_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
static constexpr GAL_TYPE GAL_FALLBACK
EDA_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Create a drawing panel that is contained inside aParentWindow.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition painter.h:55
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition view_group.h:39
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
Definition kiid.h:46
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
void SetScene(KICAD_DIFF::DIFF_SCENE aScene)
Replace the displayed scene. Pass an empty scene to clear the canvas.
void ZoomToFit()
Center the view on the scene's document bbox.
bool IsChangeHidden(const KIID_PATH &aChangeId) const
bool m_holdRebuild
While true, rebuildOverlay()/ZoomToFit() are held so a batch renders once.
std::map< KIGFX::VIEW_ITEM *, KICAD_DIFF::CATEGORY > m_itemCategories
void ZoomToBBox(const BOX2I &aBBox)
Zoom and center on a specific document-space bbox with a small margin.
void onLeftDown(wxMouseEvent &aEvent)
void SetWorldUnitLength(double aWorldUnitLength)
void SetCategoryVisible(KICAD_DIFF::CATEGORY aCategory, bool aVisible)
Toggle whether shapes of a given change category render.
void SetHiddenChanges(std::set< KIID_PATH > aHidden)
Replace the set of muted changes.
void refreshItemDimming()
Dim context items that are hidden, or unfocused while a highlight is active.
std::unique_ptr< HIGHLIGHT_BOX_ITEM > m_highlightBox
std::optional< KIID_PATH > m_hover
void SetContextItems(const std::vector< KIGFX::VIEW_ITEM * > &aItems)
Replace source document context items.
void SetItemCategories(std::map< KIGFX::VIEW_ITEM *, KICAD_DIFF::CATEGORY > aMap)
Tag context items by change category so SetCategoryVisible can hide / show them in lockstep with the ...
WIDGET_DIFF_CANVAS(wxWindow *aParent, GAL_TYPE aBackend=GAL_FALLBACK, wxWindowID aId=wxID_ANY)
KICAD_DIFF::DIFF_SCENE m_scene
void SetLayerVisible(PCB_LAYER_ID aLayer, bool aVisible)
Toggle whether board-context geometry on a given PCB layer renders.
void onLeave(wxMouseEvent &aEvent)
ITEM_ID_GETTER m_itemIdGetter
void buildRenderScene()
Recompute the cached render scene (layer-filtered geometry, cleared in native-context mode).
std::unique_ptr< HIGHLIGHT_BOX_ITEM > m_hoverBox
const KICAD_DIFF::SCENE_SHAPE * shapeAt(const wxPoint &aScreenPoint) const
Hit test in screen coordinates → topmost SCENE_SHAPE under the cursor.
std::optional< KIID_PATH > m_highlight
void onSize(wxSizeEvent &aEvent)
KICAD_DIFF::DIFF_SCENE m_renderScene
std::function< void(KIGFX::VIEW_ITEM *, bool aDim)> DIMMER
Kiface-supplied callback that dims/undims a context item.
void SetContextPainter(std::unique_ptr< KIGFX::PAINTER > aPainter)
Install the native painter used for drawing source document context.
void CenterOnHighlight()
Pan so the currently highlighted change is at the center of the canvas.
KIID getItemId(const EDA_ITEM &aItem) const
std::function< void(const std::optional< KIID_PATH > &)> PICK_HANDLER
Register a callback to fire when the user left-clicks the canvas.
std::unique_ptr< KIGFX::VIEW_GROUP > m_contextGroup
void rebuildOverlay(bool aOverlayOnly=false)
Rebuild the overlay from the render scene + current highlight state.
bool IsCategoryVisible(KICAD_DIFF::CATEGORY aCategory) const
void SetItemIdGetter(const ITEM_ID_GETTER &aGetter)
void onDoubleClick(wxMouseEvent &aEvent)
std::unique_ptr< KIGFX::GAL_DISPLAY_OPTIONS > m_galOptions
EDA_DRAW_PANEL_GAL keeps a reference to the options struct, so it must outlive the panel.
std::vector< KIGFX::VIEW_ITEM * > m_contextGroupItems
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
std::array< bool, KICAD_DIFF::CATEGORY_COUNT > m_categoryVisible
std::function< KIID(const EDA_ITEM &)> ITEM_ID_GETTER
Override context item identity when a differ uses IDs other than the item UUID.
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
void onMotion(wxMouseEvent &aEvent)
std::function< void(KIGFX::VIEW_ITEM *)> ITEM_HANDLER
void BeginUpdate()
Hold overlay rebuilds/zoom until EndUpdate, so a batch of changes (e.g.
std::optional< BOX2I > highlightedBBox() const
Union bbox of all shapes whose changeId matches the current highlight, honoring per-category visibili...
void SetPickHandler(PICK_HANDLER aHandler)
std::set< KIID_PATH > m_hiddenChanges
void SetDoubleClickHandler(ITEM_HANDLER aHandler)
void SetItemDimmer(DIMMER aDimmer)
bool m_zoomToFitPending
True when a ZoomToFit was requested before the canvas had a real size — the next onSize will retry th...
void onChar(wxKeyEvent &aEvent)
void HighlightChange(std::optional< KIID_PATH > aChangeId)
Outline shape(s) whose SCENE_SHAPE::changeId matches the given path.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
CATEGORY
Visual category each ITEM_CHANGE belongs to in the scene.
Definition diff_scene.h:52
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
Shared rendering model consumed by both the GAL renderer (interactive widget) and the plotter rendere...
Definition diff_scene.h:90