KiCad PCB EDA Suite
Loading...
Searching...
No Matches
widget_diff_canvas.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 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
25
27
29#include <eda_item.h>
30#include <gal/color4d.h>
33#include <layer_ids.h>
34#include <view/view.h>
35#include <view/view_group.h>
36#include <view/view_item.h>
37#include <view/view_overlay.h>
39#include <zoom_defines.h>
40
41
48
49
50WIDGET_DIFF_CANVAS::WIDGET_DIFF_CANVAS( wxWindow* aParent, GAL_TYPE aBackend, wxWindowID aId ) :
51 WIDGET_DIFF_CANVAS( aParent, aBackend, aId, std::make_unique<KIGFX::GAL_DISPLAY_OPTIONS>() )
52{
53}
54
55
56WIDGET_DIFF_CANVAS::WIDGET_DIFF_CANVAS( wxWindow* aParent, GAL_TYPE aBackend, wxWindowID aId,
57 std::unique_ptr<KIGFX::GAL_DISPLAY_OPTIONS> aGalOptions ) :
58 EDA_DRAW_PANEL_GAL( aParent, aId, wxDefaultPosition, wxDefaultSize, *aGalOptions, aBackend ),
59 m_layerVisible( LSET::AllLayersMask() ),
60 m_galOptions( std::move( aGalOptions ) )
61{
62 m_view = new KIGFX::VIEW();
63 m_view->SetGAL( m_gal );
64
66
67 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
68 m_view->SetLayerTarget( i, target );
69
70 // Until a module installs a native context painter, the canvas renders only
71 // VIEW_OVERLAY commands, which bypass the painter. Reuse the drawing-sheet
72 // pair (also used by PL_DRAW_PANEL_GAL) rather than a private stub. Force
73 // the historical near-white background the diff canvas expects;
74 // DS_RENDER_SETTINGS otherwise defaults to pure white.
75 m_painter = std::make_unique<KIGFX::DS_PAINTER>( m_gal );
76 m_painter->GetSettings()->SetBackgroundColor( KIGFX::COLOR4D( 0.97, 0.97, 0.97, 1.0 ) );
77 m_view->SetPainter( m_painter.get() );
78
80 m_view->SetMirror( false, false );
81
82 m_contextGroup = std::make_unique<KIGFX::VIEW_GROUP>();
84 m_view->Add( m_contextGroup.get(), 0 );
85
86 // The overlay needs to live on a layer the view is willing to draw.
87 // LAYER_GP_OVERLAY is a general-purpose overlay slot used elsewhere in
88 // KiCad GAL panels for non-cached annotation.
90 m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
91 m_view->SetLayerVisible( LAYER_GP_OVERLAY, true );
92
93 m_overlay = m_view->MakeOverlay();
94
95 m_highlightBox = std::make_unique<HIGHLIGHT_BOX_ITEM>();
96 m_hoverBox = std::make_unique<HIGHLIGHT_BOX_ITEM>();
97
99
100 m_gal->SetCursorEnabled( false );
101
102 // Matches DIFF_THUMBNAIL so existing dialog layouts don't collapse the
103 // canvas when sizers are tight.
104 SetMinSize( wxSize( -1, 100 ) );
105
106 Bind( wxEVT_LEFT_DOWN, &WIDGET_DIFF_CANVAS::onLeftDown, this );
107 Bind( wxEVT_LEFT_UP, &WIDGET_DIFF_CANVAS::onLeftUp, this );
108 Bind( wxEVT_LEFT_DCLICK, &WIDGET_DIFF_CANVAS::onDoubleClick, this );
109 Bind( wxEVT_MOTION, &WIDGET_DIFF_CANVAS::onMotion, this );
110 Bind( wxEVT_LEAVE_WINDOW, &WIDGET_DIFF_CANVAS::onLeave, this );
111 Bind( wxEVT_CHAR_HOOK, &WIDGET_DIFF_CANVAS::onChar, this );
112 Bind( wxEVT_SIZE, &WIDGET_DIFF_CANVAS::onSize, this );
113
114 SetEvtHandlerEnabled( true );
115 Show( true );
116 StartDrawing();
117}
118
119
121{
122 StopDrawing();
123
125 {
126 if( item )
127 m_view->Remove( item );
128 }
129
130 m_view->Remove( m_contextGroup.get() );
131 // m_view owns the overlay since MakeOverlay() — no manual Remove needed.
132}
133
134
136{
137 m_scene = std::move( aScene );
138 m_highlight = std::nullopt;
139
142 ZoomToFit();
143}
144
145
147{
148 if( m_changeOutlinesShown == aShown )
149 return;
150
151 m_changeOutlinesShown = aShown;
154}
155
156
157void WIDGET_DIFF_CANVAS::SetWorldUnitLength( double aWorldUnitLength )
158{
159 if( m_gal->GetWorldUnitLength() == aWorldUnitLength )
160 return;
161
162 m_gal->SetWorldUnitLength( aWorldUnitLength );
163 m_gal->ComputeWorldScreenMatrix();
164 ZoomToFit();
165}
166
167
168void WIDGET_DIFF_CANVAS::SetContextPainter( std::unique_ptr<KIGFX::PAINTER> aPainter )
169{
170 if( !aPainter )
171 return;
172
173 m_painter = std::move( aPainter );
174 m_view->SetPainter( m_painter.get() );
175 m_view->MarkDirty();
176 Refresh();
177}
178
179
180void WIDGET_DIFF_CANVAS::SetContextItems( const std::vector<KIGFX::VIEW_ITEM*>& aItems,
181 std::shared_ptr<const void> aOwner )
182{
183 if( !m_contextGroup )
184 return;
185
187 {
188 if( item )
189 m_view->Remove( item );
190 }
191
192 // The old items are out of the view, so whatever kept them alive may go
193 m_contextOwner = std::move( aOwner );
194 m_contextGroupItems.clear();
195 m_itemCategories.clear();
196 m_hasNativeContext = false;
197
198 for( KIGFX::VIEW_ITEM* item : aItems )
199 {
200 if( !item )
201 continue;
202
203 m_view->Add( item );
204 m_contextGroupItems.push_back( item );
205 m_hasNativeContext = true;
206 }
207
210}
211
212
213void WIDGET_DIFF_CANVAS::HighlightChange( std::optional<KIID_PATH> aChangeId )
214{
215 if( m_highlight == aChangeId )
216 return;
217
218 m_highlight = std::move( aChangeId );
219
220 const std::optional<KIID> focusKiid =
221 m_highlight && !m_highlight->empty() ? std::optional( m_highlight->back() ) : std::nullopt;
222
223 // Dimming depends only on the hidden set, not the highlight, so it does not
224 // need re-applying here. Re-running it would REPAINT every board item on
225 // each click, which is the source of the highlight lag.
226
227 m_highlightBox->shown = false;
228
229 // The committed selection takes over from any active hover so the rect
230 // doesn't double-draw on the next mouse move.
231 if( focusKiid && m_hover == m_highlight )
232 {
233 m_hover.reset();
234 m_hoverBox->shown = false;
235 }
236
237 if( focusKiid )
238 {
240
242 {
243 EDA_ITEM* eda = dynamic_cast<EDA_ITEM*>( item );
244
245 if( !eda || getItemId( *eda ) != *focusKiid )
246 continue;
247
248 const BOX2I bb = item->ViewBBox();
249
250 if( bb.GetWidth() <= 0 || bb.GetHeight() <= 0 )
251 break;
252
253 auto catIt = m_itemCategories.find( item );
254 KIGFX::COLOR4D base = catIt != m_itemCategories.end() ? KICAD_DIFF::ThemeColorFor( theme, catIt->second )
255 : theme.modified;
256
257 base.a = 0.35;
258
259 m_highlightBox->bbox = bb;
260 m_highlightBox->color = base;
261 m_highlightBox->shown = true;
262 break;
263 }
264 }
265
266 rebuildOverlay( /*aOverlayOnly=*/true );
267}
268
269
271{
272 const std::size_t idx = static_cast<std::size_t>( aCategory );
273
274 wxCHECK_RET( idx < m_categoryVisible.size(), wxS( "Invalid CATEGORY" ) );
275
276 if( m_categoryVisible[idx] == aVisible )
277 return;
278
279 m_categoryVisible[idx] = aVisible;
280
281 for( const auto& [item, cat] : m_itemCategories )
282 {
283 if( cat != aCategory )
284 continue;
285
286 m_view->SetVisible( item, aVisible );
287
288 // Force a full repaint so per-item color overrides re-apply.
289 if( aVisible )
290 m_view->Update( item, KIGFX::REPAINT );
291 }
292
294}
295
296
297void WIDGET_DIFF_CANVAS::SetItemCategories( std::map<KIGFX::VIEW_ITEM*, KICAD_DIFF::CATEGORY> aMap )
298{
299 m_itemCategories = std::move( aMap );
300
301 for( const auto& [item, cat] : m_itemCategories )
302 {
303 const std::size_t idx = static_cast<std::size_t>( cat );
304
305 if( idx < m_categoryVisible.size() )
306 m_view->SetVisible( item, m_categoryVisible[idx] );
307 }
308}
309
310
312{
313 const std::size_t idx = static_cast<std::size_t>( aCategory );
314
315 wxCHECK( idx < m_categoryVisible.size(), false );
316
317 return m_categoryVisible[idx];
318}
319
320
321void WIDGET_DIFF_CANVAS::SetHiddenChanges( std::set<KIID_PATH> aHidden )
322{
323 if( m_hiddenChanges == aHidden )
324 return;
325
326 m_hiddenChanges = std::move( aHidden );
329}
330
331
332bool WIDGET_DIFF_CANVAS::IsChangeHidden( const KIID_PATH& aChangeId ) const
333{
334 return m_hiddenChanges.count( aChangeId ) > 0;
335}
336
337
339{
340 if( !m_itemDimmer )
341 return;
342
343 // Item IDs of the hidden changes (a change id's last element is its item).
344 std::set<KIID> hiddenItems;
345
346 for( const KIID_PATH& path : m_hiddenChanges )
347 {
348 if( !path.empty() )
349 hiddenItems.insert( path.back() );
350 }
351
353 {
354 if( !item )
355 continue;
356
357 EDA_ITEM* eda = dynamic_cast<EDA_ITEM*>( item );
358 const bool hidden = eda && hiddenItems.count( getItemId( *eda ) ) > 0;
359
360 m_itemDimmer( item, hidden );
361 m_view->Update( item, KIGFX::REPAINT );
362 }
363}
364
365
367{
368 return m_itemIdGetter ? m_itemIdGetter( aItem ) : aItem.m_Uuid;
369}
370
371
373{
374 if( aLayer < 0 || aLayer >= PCB_LAYER_ID_COUNT )
375 return;
376
377 if( m_layerVisible.Contains( aLayer ) == aVisible )
378 return;
379
380 m_layerVisible.set( aLayer, aVisible );
381 m_view->SetLayerVisible( aLayer, aVisible );
384}
385
386
388{
389 return m_layerVisible.Contains( aLayer );
390}
391
392
397
398
400{
401 m_holdRebuild = false;
403
405 ZoomToFit();
406}
407
408
410{
411 if( m_holdRebuild )
412 {
413 m_zoomToFitPending = true;
414 return;
415 }
416
417 BOX2I bb = m_focusBox ? *m_focusBox : m_scene.documentBBox;
418 bool haveBox = bb.GetWidth() > 0 && bb.GetHeight() > 0;
419
420 // Also frame the context items so the whole board fits, not just the changes.
422 {
423 if( !item || m_focusBox )
424 continue;
425
426 BOX2I ib = item->ViewBBox();
427
428 if( ib.GetWidth() <= 0 || ib.GetHeight() <= 0 )
429 continue;
430
431 if( haveBox )
432 {
433 bb.Merge( ib );
434 }
435 else
436 {
437 bb = ib;
438 haveBox = true;
439 }
440 }
441
442 if( !haveBox )
443 {
444 m_zoomToFitPending = false;
445 return;
446 }
447
448 // VIEW::SetViewport silently no-ops when the GAL has no screen size, so
449 // defer the fit until we've been sized at least once.
450 const wxSize client = GetClientSize();
451
452 if( client.x <= 0 || client.y <= 0 )
453 {
454 m_zoomToFitPending = true;
455 return;
456 }
457
458 ZoomToBBox( bb );
459 m_zoomToFitPending = false;
460}
461
462
464{
465 if( !aBBox.GetWidth() || !aBBox.GetHeight() )
466 return;
467
468 // The base fit is redone on each resize until the view moves, so a fit before layout does not stay small
469 EDA_DRAW_PANEL_GAL::ZoomToFit( aBBox, 1.10 );
470}
471
472
474{
475 std::optional<BOX2I> bb = highlightedBBox();
476
477 if( !bb || bb->GetWidth() <= 0 || bb->GetHeight() <= 0 )
478 return;
479
480 BOX2I focus = *bb;
481 focus.Inflate( std::max( bb->GetWidth(), bb->GetHeight() ) );
482
483 // A part in a sheet-wide fit is too small to read, but a closer zoom the user chose is kept
484 const BOX2D viewport = m_view->GetViewport();
485
486 if( focus.GetWidth() < viewport.GetWidth() && focus.GetHeight() < viewport.GetHeight() )
487 {
488 ZoomToBBox( focus );
489 return;
490 }
491
492 const VECTOR2I center = bb->GetCenter();
493 m_view->SetCenter( VECTOR2D( center.x, center.y ) );
494 m_view->MarkDirty();
495 Refresh();
496}
497
498
500{
502
504 {
505 m_renderScene.addedShapes.clear();
506 m_renderScene.removedShapes.clear();
507 m_renderScene.modifiedShapes.clear();
508 m_renderScene.conflictShapes.clear();
509 }
510
512 {
513 m_renderScene.referenceGeometry = {};
514 m_renderScene.comparisonGeometry = {};
515 }
516 else
517 {
518 m_renderScene.referenceGeometry =
520 m_renderScene.comparisonGeometry =
522 }
523}
524
525
526void WIDGET_DIFF_CANVAS::rebuildOverlay( bool aOverlayOnly )
527{
528 if( m_holdRebuild )
529 return;
530
532
533 auto drawBox = [&]( const HIGHLIGHT_BOX_ITEM* aBox )
534 {
535 if( !aBox || !aBox->shown || aBox->bbox.GetWidth() <= 0 || aBox->bbox.GetHeight() <= 0 )
536 return;
537
538 m_overlay->SetIsFill( true );
539 m_overlay->SetIsStroke( false );
540 m_overlay->SetFillColor( aBox->color );
541 m_overlay->Rectangle( aBox->bbox.GetOrigin(), aBox->bbox.GetEnd() );
542 };
543
544 drawBox( m_hoverBox.get() );
545 drawBox( m_highlightBox.get() );
546
547 if( aOverlayOnly )
548 m_view->MarkTargetDirty( KIGFX::TARGET_OVERLAY );
549 else
550 m_view->MarkDirty();
551
552 Refresh();
553}
554
555
556const KICAD_DIFF::SCENE_SHAPE* WIDGET_DIFF_CANVAS::shapeAt( const wxPoint& aScreenPoint ) const
557{
558 if( !m_view )
559 return nullptr;
560
561 // Convert from screen to document coordinates.
562 const VECTOR2D doc = m_view->ToWorld( VECTOR2D( aScreenPoint.x, aScreenPoint.y ) );
563
564 // Walk PAINT_ORDER in reverse so topmost shape wins, mirroring the
565 // thumbnail's hit-test order.
566 for( auto it = KICAD_DIFF::PAINT_ORDER.rbegin(); it != KICAD_DIFF::PAINT_ORDER.rend(); ++it )
567 {
568 if( !IsCategoryVisible( *it ) )
569 continue;
570
571 const std::vector<KICAD_DIFF::SCENE_SHAPE>& list = KICAD_DIFF::ShapesFor( m_scene, *it );
572
573 for( auto sIt = list.rbegin(); sIt != list.rend(); ++sIt )
574 {
575 // Muted changes let clicks fall through to what is underneath.
576 if( m_hiddenChanges.count( sIt->changeId ) > 0 )
577 continue;
578
579 if( sIt->bbox.Contains( VECTOR2I( KiROUND( doc.x ), KiROUND( doc.y ) ) ) )
580 return &*sIt;
581 }
582 }
583
584 return nullptr;
585}
586
587
588void WIDGET_DIFF_CANVAS::onLeftDown( wxMouseEvent& aEvent )
589{
590 std::optional<KIID_PATH> picked;
591
592 if( const KICAD_DIFF::SCENE_SHAPE* shape = shapeAt( aEvent.GetPosition() ) )
593 picked = shape->changeId;
594
595 SetFocus();
596 aEvent.Skip();
597
598 if( m_leftDragPans )
599 {
600 m_leftPanning = true;
601 m_leftPanLast = VECTOR2D( aEvent.GetX(), aEvent.GetY() );
602 }
603
604 if( m_pickHandler )
605 m_pickHandler( picked );
606}
607
608
609void WIDGET_DIFF_CANVAS::onLeftUp( wxMouseEvent& aEvent )
610{
611 aEvent.Skip();
612 m_leftPanning = false;
613}
614
615
616void WIDGET_DIFF_CANVAS::onDoubleClick( wxMouseEvent& aEvent )
617{
618 aEvent.Skip();
619
620 if( !m_dclickHandler || m_contextGroupItems.empty() )
621 return;
622
623 const VECTOR2D world = m_view->ToWorld( VECTOR2D( aEvent.GetPosition().x, aEvent.GetPosition().y ) );
624 const VECTOR2I worldI( KiROUND( world.x ), KiROUND( world.y ) );
625
626 KIGFX::VIEW_ITEM* hit = nullptr;
627 BOX2I hitBBox;
628
629 // Reverse so the topmost item wins if bboxes overlap.
630 for( auto it = m_contextGroupItems.rbegin(); it != m_contextGroupItems.rend(); ++it )
631 {
632 KIGFX::VIEW_ITEM* item = *it;
633
634 if( !item )
635 continue;
636
637 const BOX2I bb = item->ViewBBox();
638
639 if( bb.GetWidth() <= 0 || bb.GetHeight() <= 0 )
640 continue;
641
642 if( !bb.Contains( worldI ) )
643 continue;
644
645 // Prefer the smallest matching bbox so a nested sheet wins over its parent.
646 if( !hit || bb.GetArea() < hitBBox.GetArea() )
647 {
648 hit = item;
649 hitBBox = bb;
650 }
651 }
652
653 if( hit )
654 m_dclickHandler( hit );
655}
656
657
658void WIDGET_DIFF_CANVAS::onMotion( wxMouseEvent& aEvent )
659{
660 aEvent.Skip();
661
662 // The view controls pan on the middle button only, so the left drag is done here.
663 if( m_leftPanning && aEvent.Dragging() && aEvent.LeftIsDown() )
664 {
665 VECTOR2D pos( aEvent.GetX(), aEvent.GetY() );
666 VECTOR2D delta = m_view->ToWorld( pos, false ) - m_view->ToWorld( m_leftPanLast, false );
667
668 m_view->SetCenter( m_view->GetCenter() - delta );
669 m_leftPanLast = pos;
670 Refresh();
671 return;
672 }
673
674 std::optional<KIID_PATH> hovered;
675 const KICAD_DIFF::SCENE_SHAPE* shape = shapeAt( aEvent.GetPosition() );
676
677 // Suppress hover when it would land on the already-selected change so the
678 // committed highlight stays clean.
679 if( shape && ( !m_highlight || shape->changeId != *m_highlight ) )
680 hovered = shape->changeId;
681
682 if( hovered == m_hover )
683 return;
684
685 m_hover = hovered;
686 m_hoverBox->shown = false;
687
688 if( shape && hovered )
689 {
690 KIGFX::COLOR4D base = shape->color;
691 base.a = 0.20;
692 m_hoverBox->bbox = shape->bbox;
693 m_hoverBox->color = base;
694 m_hoverBox->shown = true;
695 }
696
697 rebuildOverlay( /*aOverlayOnly=*/true );
698}
699
700
701void WIDGET_DIFF_CANVAS::onLeave( wxMouseEvent& aEvent )
702{
703 aEvent.Skip();
704 m_leftPanning = false;
705
706 if( !m_hover && !m_hoverBox->shown )
707 return;
708
709 m_hover.reset();
710 m_hoverBox->shown = false;
711 rebuildOverlay( /*aOverlayOnly=*/true );
712}
713
714
715void WIDGET_DIFF_CANVAS::onChar( wxKeyEvent& aEvent )
716{
717 switch( aEvent.GetKeyCode() )
718 {
719 case WXK_HOME:
720 if( m_scene.documentBBox.GetWidth() || m_scene.documentBBox.GetHeight() )
721 {
722 ZoomToFit();
723 return;
724 }
725
726 aEvent.Skip();
727 return;
728
729 case 'F':
730 case 'f':
731 if( std::optional<BOX2I> bbox = highlightedBBox() )
732 {
733 ZoomToBBox( *bbox );
734 return;
735 }
736
737 aEvent.Skip();
738 return;
739
740 case WXK_ESCAPE:
742 {
743 m_pickHandler( std::nullopt );
744 return;
745 }
746
747 aEvent.Skip();
748 return;
749
750 default: aEvent.Skip(); return;
751 }
752}
753
754
755void WIDGET_DIFF_CANVAS::onSize( wxSizeEvent& aEvent )
756{
757 aEvent.Skip();
758
760 ZoomToFit();
761}
762
763
764std::optional<BOX2I> WIDGET_DIFF_CANVAS::highlightedBBox() const
765{
766 if( !m_highlight.has_value() )
767 return std::nullopt;
768
770}
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
BOX2< VECTOR2D > BOX2D
Definition box2.h:918
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr ecoord_type GetArea() const
Return the area of the rectangle.
Definition box2.h:700
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
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.
static bool IsAccelerated(GAL_TYPE aCanvasType)
True for a canvas drawn on the GPU, which keeps cached layers between frames.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetFocus() override
void StartDrawing()
Begin drawing if it was stopped previously.
GAL_TYPE m_backend
Currently used GAL.
void ZoomToFit(const BOX2I &aBox, std::optional< double > aMarginScale=std::nullopt)
Scale and centre the view on aBox, and fit it again whenever the canvas changes size until something ...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double a
Alpha component.
Definition color4d.h:394
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
virtual const BOX2I ViewBBox() const =0
Return the bounding box of the item covering all its layers.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition view.h:899
An implementation of class VIEW_CONTROLS for wxWidgets library.
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 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
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::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
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::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
void onMotion(wxMouseEvent &aEvent)
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...
std::set< KIID_PATH > m_hiddenChanges
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.
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:275
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
KIGFX::COLOR4D ThemeColorFor(const DIFF_COLOR_THEME &aTheme, CATEGORY aCategory)
Map a CATEGORY to its color in a DIFF_COLOR_THEME.
std::optional< BOX2I > HighlightedBBox(const DIFF_SCENE &aScene, const KIID_PATH &aChangeId, const std::array< bool, CATEGORY_COUNT > &aCategoryVisible)
Union bbox of every visible SCENE_SHAPE whose changeId matches aChangeId.
void RenderSceneToOverlay(KIGFX::VIEW_OVERLAY &aOverlay, const DIFF_SCENE &aScene, const std::array< bool, CATEGORY_COUNT > &aVisible, const std::optional< KIID_PATH > &aHighlight, const std::set< KIID_PATH > &aHidden)
Push a DIFF_SCENE's shapes onto a VIEW_OVERLAY as filled, semi-transparent rectangles,...
CATEGORY
Visual category each ITEM_CHANGE belongs to in the scene.
Definition diff_scene.h:52
const std::vector< SCENE_SHAPE > & ShapesFor(const DIFF_SCENE &aScene, CATEGORY aCategory)
Read-only access to a DIFF_SCENE's shape list for a given category.
constexpr std::array< CATEGORY, 4 > PAINT_ORDER
Paint order.
Definition diff_scene.h:67
DOCUMENT_GEOMETRY FilterGeometryByVisibleLayers(const DOCUMENT_GEOMETRY &aGeometry, const LSET &aVisibleLayers)
Copy geometry primitives whose layer set intersects aVisibleLayers.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:34
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:33
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:35
STL namespace.
Diff colors with defaults for light backgrounds.
Definition diff_scene.h:278
Shared rendering model consumed by both the GAL renderer (interactive widget) and the plotter rendere...
Definition diff_scene.h:90
KIGFX::COLOR4D color
Definition diff_scene.h:92
KIID_PATH changeId
Stable identifier of the ITEM_CHANGE that produced this shape.
Definition diff_scene.h:99
std::string path
VECTOR2I center
int delta
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
WX_VIEW_CONTROLS class definition.
#define ZOOM_MIN_LIMIT_DIFF
#define ZOOM_MAX_LIMIT_DIFF