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
38
39namespace KIGFX
40{
42class PAINTER;
43class VIEW_ITEM;
44class VIEW_GROUP;
45}
46
47
48namespace KIGFX
49{
50class VIEW_OVERLAY;
51}
52
53
69{
70public:
71 WIDGET_DIFF_CANVAS( wxWindow* aParent, wxWindowID aId = wxID_ANY );
72
73 ~WIDGET_DIFF_CANVAS() override;
74
75private:
78 WIDGET_DIFF_CANVAS( wxWindow* aParent, wxWindowID aId, std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> aGalOptions );
79
80public:
82 void SetScene( KICAD_DIFF::DIFF_SCENE aScene );
83
84 void SetWorldUnitLength( double aWorldUnitLength );
85
89 void SetContextPainter( std::unique_ptr<KIGFX::PAINTER> aPainter );
90
94 void SetContextItems( const std::vector<KIGFX::VIEW_ITEM*>& aItems );
95
98 void SetItemCategories( std::map<KIGFX::VIEW_ITEM*, KICAD_DIFF::CATEGORY> aMap );
99
101 using DIMMER = std::function<void( KIGFX::VIEW_ITEM*, bool aDim )>;
102 void SetItemDimmer( DIMMER aDimmer ) { m_itemDimmer = std::move( aDimmer ); }
103
108 void HighlightChange( std::optional<KIID_PATH> aChangeId );
109
112 void SetCategoryVisible( KICAD_DIFF::CATEGORY aCategory, bool aVisible );
113
114 bool IsCategoryVisible( KICAD_DIFF::CATEGORY aCategory ) const;
115
118 void SetHiddenChanges( std::set<KIID_PATH> aHidden );
119
120 bool IsChangeHidden( const KIID_PATH& aChangeId ) const;
121
124 void SetLayerVisible( PCB_LAYER_ID aLayer, bool aVisible );
125
126 bool IsLayerVisible( PCB_LAYER_ID aLayer ) const;
127
131 void BeginUpdate();
132 void EndUpdate();
133
137 void ZoomToFit();
138
140 void ZoomToBBox( const BOX2I& aBBox );
141
144 void CenterOnHighlight();
145
149 using PICK_HANDLER = std::function<void( const std::optional<KIID_PATH>& )>;
150
151 void SetPickHandler( PICK_HANDLER aHandler ) { m_pickHandler = std::move( aHandler ); }
152
153 using ITEM_HANDLER = std::function<void( KIGFX::VIEW_ITEM* )>;
154 void SetDoubleClickHandler( ITEM_HANDLER aHandler ) { m_dclickHandler = std::move( aHandler ); }
155
156private:
160 void rebuildOverlay( bool aOverlayOnly = false );
161
165 void buildRenderScene();
166
168 void refreshItemDimming();
169
171 const KICAD_DIFF::SCENE_SHAPE* shapeAt( const wxPoint& aScreenPoint ) const;
172
175 std::optional<BOX2I> highlightedBBox() const;
176
177 void onLeftDown( wxMouseEvent& aEvent );
178 void onDoubleClick( wxMouseEvent& aEvent );
179 void onMotion( wxMouseEvent& aEvent );
180 void onLeave( wxMouseEvent& aEvent );
181 void onChar( wxKeyEvent& aEvent );
182 void onSize( wxSizeEvent& aEvent );
183
184 struct HIGHLIGHT_BOX_ITEM;
185
188 std::optional<KIID_PATH> m_highlight;
189 std::optional<KIID_PATH> m_hover;
193 std::unique_ptr<HIGHLIGHT_BOX_ITEM> m_highlightBox;
194 std::unique_ptr<HIGHLIGHT_BOX_ITEM> m_hoverBox;
195
196 std::array<bool, KICAD_DIFF::CATEGORY_COUNT> m_categoryVisible{ { true, true, true, true } };
197
198 std::set<KIID_PATH> m_hiddenChanges;
199
201 bool m_holdRebuild = false;
202
204
205 bool m_hasNativeContext = false;
206 std::unique_ptr<KIGFX::VIEW_GROUP> m_contextGroup;
207 std::vector<KIGFX::VIEW_ITEM*> m_contextGroupItems;
208 std::map<KIGFX::VIEW_ITEM*, KICAD_DIFF::CATEGORY> m_itemCategories;
209 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
210
213 std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> m_galOptions;
214
217 bool m_zoomToFitPending = false;
218};
219
220#endif // KICAD_WIDGET_DIFF_CANVAS_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
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.
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
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 ...
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)
void buildRenderScene()
Recompute the cached render scene (layer-filtered geometry, cleared in native-context mode).
std::unique_ptr< HIGHLIGHT_BOX_ITEM > m_hoverBox
WIDGET_DIFF_CANVAS(wxWindow *aParent, wxWindowID aId=wxID_ANY)
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.
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 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::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:29
Shared rendering model consumed by both the GAL renderer (interactive widget) and the plotter rendere...
Definition diff_scene.h:90