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
89 void SetChangeOutlinesShown( bool aShown );
90
91 void SetWorldUnitLength( double aWorldUnitLength );
92
96 void SetContextPainter( std::unique_ptr<KIGFX::PAINTER> aPainter );
97
101 void SetContextItems( const std::vector<KIGFX::VIEW_ITEM*>& aItems,
102 std::shared_ptr<const void> aOwner = nullptr );
103
106 void SetItemCategories( std::map<KIGFX::VIEW_ITEM*, KICAD_DIFF::CATEGORY> aMap );
107
109 using ITEM_ID_GETTER = std::function<KIID( const EDA_ITEM& )>;
110 void SetItemIdGetter( const ITEM_ID_GETTER& aGetter ) { m_itemIdGetter = aGetter; }
111
113 using DIMMER = std::function<void( KIGFX::VIEW_ITEM*, bool aDim )>;
114 void SetItemDimmer( DIMMER aDimmer ) { m_itemDimmer = std::move( aDimmer ); }
115
120 void HighlightChange( std::optional<KIID_PATH> aChangeId );
121
124 void SetCategoryVisible( KICAD_DIFF::CATEGORY aCategory, bool aVisible );
125
126 bool IsCategoryVisible( KICAD_DIFF::CATEGORY aCategory ) const;
127
130 void SetHiddenChanges( std::set<KIID_PATH> aHidden );
131
132 bool IsChangeHidden( const KIID_PATH& aChangeId ) const;
133
136 void SetLayerVisible( PCB_LAYER_ID aLayer, bool aVisible );
137
138 bool IsLayerVisible( PCB_LAYER_ID aLayer ) const;
139
143 void BeginUpdate();
144 void EndUpdate();
145
149 void ZoomToFit();
150
152 void ZoomToBBox( const BOX2I& aBBox );
153
156 void CenterOnHighlight();
157
161 using PICK_HANDLER = std::function<void( const std::optional<KIID_PATH>& )>;
162
163 void SetPickHandler( PICK_HANDLER aHandler ) { m_pickHandler = std::move( aHandler ); }
164
165 using ITEM_HANDLER = std::function<void( KIGFX::VIEW_ITEM* )>;
166 void SetDoubleClickHandler( ITEM_HANDLER aHandler ) { m_dclickHandler = std::move( aHandler ); }
167
169 void SetLeftDragPans( bool aPan ) { m_leftDragPans = aPan; }
170
173 void SetFocusBox( std::optional<BOX2I> aBox ) { m_focusBox = std::move( aBox ); }
174
175private:
179 void rebuildOverlay( bool aOverlayOnly = false );
180
184 void buildRenderScene();
185
187 void refreshItemDimming();
188
189 KIID getItemId( const EDA_ITEM& aItem ) const;
190
192 const KICAD_DIFF::SCENE_SHAPE* shapeAt( const wxPoint& aScreenPoint ) const;
193
196 std::optional<BOX2I> highlightedBBox() const;
197
198 void onLeftDown( wxMouseEvent& aEvent );
199 void onLeftUp( wxMouseEvent& aEvent );
200 void onDoubleClick( wxMouseEvent& aEvent );
201 void onMotion( wxMouseEvent& aEvent );
202 void onLeave( wxMouseEvent& aEvent );
203 void onChar( wxKeyEvent& aEvent );
204 void onSize( wxSizeEvent& aEvent );
205
206 struct HIGHLIGHT_BOX_ITEM;
207
210 std::optional<KIID_PATH> m_highlight;
211 std::optional<KIID_PATH> m_hover;
216 std::unique_ptr<HIGHLIGHT_BOX_ITEM> m_highlightBox;
217 std::unique_ptr<HIGHLIGHT_BOX_ITEM> m_hoverBox;
218
219 std::array<bool, KICAD_DIFF::CATEGORY_COUNT> m_categoryVisible{ { true, true, true, true } };
220
221 std::set<KIID_PATH> m_hiddenChanges;
222
224 bool m_holdRebuild = false;
225
227
229
230 bool m_hasNativeContext = false;
231 std::unique_ptr<KIGFX::VIEW_GROUP> m_contextGroup;
232 std::vector<KIGFX::VIEW_ITEM*> m_contextGroupItems;
233 std::shared_ptr<const void> m_contextOwner;
234 std::map<KIGFX::VIEW_ITEM*, KICAD_DIFF::CATEGORY> m_itemCategories;
235 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
236
239 std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> m_galOptions;
240
243 bool m_zoomToFitPending = false;
244
245 bool m_leftDragPans = false;
246 bool m_leftPanning = false;
248
249 std::optional<BOX2I> m_focusBox;
250};
251
252#endif // KICAD_WIDGET_DIFF_CANVAS_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
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 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 ...
std::shared_ptr< const void > m_contextOwner
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 SetFocusBox(std::optional< BOX2I > aBox)
Make ZoomToFit frame this box instead of the whole document, or everything again when cleared.
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, zooming in first when it woul...
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
void SetContextItems(const std::vector< KIGFX::VIEW_ITEM * > &aItems, std::shared_ptr< const void > aOwner=nullptr)
Replace source document context items.
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)
void SetLeftDragPans(bool aPan)
Let a left drag pan the view, for a canvas with nothing to select by dragging.
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 SetChangeOutlinesShown(bool aShown)
Draw the scene's change outlines or keep them for picking only.
void onChar(wxKeyEvent &aEvent)
void onLeftUp(wxMouseEvent &aEvent)
std::optional< BOX2I > m_focusBox
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
VECTOR2< double > VECTOR2D
Definition vector2d.h:707