KiCad PCB EDA Suite
Loading...
Searching...
No Matches
constraint_overlay.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
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, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <cstdint>
23#include <map>
24#include <memory>
25#include <optional>
26#include <vector>
27
28#include <eda_item.h>
29#include <kiid.h>
30#include <layer_ids.h>
31#include <math/box2.h>
32#include <math/vector2d.h>
33#include <geometry/seg.h>
34#include <gal/color4d.h>
35
38
39class BOARD;
40class BITMAP_BASE;
41
42namespace KIGFX
43{
44class VIEW;
45}
46
47
52{
57 std::vector<SEG> avoid; // constrained geometry the badge stays clear of
58};
59
60
67{
68public:
70
72
73 void SetBadges( const std::vector<CONSTRAINT_BADGE>& aBadges, const KIID& aSelected )
74 {
75 m_badges = aBadges;
76 m_selected = aSelected;
77 m_layoutScale = -1.0; // invalidate the cached layout; the badge set changed
78 }
79
81 void SetPreviewAnchor( const std::optional<VECTOR2I>& aAnchor ) { m_previewAnchor = aAnchor; }
82
83 const BOX2I ViewBBox() const override
84 {
85 BOX2I bbox;
86 bbox.SetMaximum(); // Always drawn, so the per-frame screen-constant sizing stays current.
87 return bbox;
88 }
89
90 std::vector<int> ViewGetLayers() const override { return { LAYER_GP_OVERLAY }; }
91
92 void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override;
93
94 bool HitTest( const VECTOR2I&, int = 0 ) const override { return false; }
95
96 wxString GetClass() const override { return wxT( "CONSTRAINT_BADGE_ITEM" ); }
97
98#if defined( DEBUG )
99 void Show( int, std::ostream& ) const override {}
100#endif
101
102private:
104 BITMAP_BASE* icon( PCB_CONSTRAINT_TYPE aType ) const;
105
108 BITMAP_BASE* disc( const KIGFX::COLOR4D& aColor ) const;
109
110 std::vector<CONSTRAINT_BADGE> m_badges;
112 std::optional<VECTOR2I> m_previewAnchor;
113
114 mutable std::map<PCB_CONSTRAINT_TYPE, std::unique_ptr<BITMAP_BASE>> m_icons;
115 mutable std::map<uint32_t, std::unique_ptr<BITMAP_BASE>> m_discs;
116
117 // Screen-space layout cached per view scale, recomputed only when the zoom or badge set changes.
118 mutable std::vector<VECTOR2D> m_layout;
119 mutable double m_layoutScale = -1.0;
120};
121
122
133enum class OVERLAY_MODE
134{
137};
138
139
141{
142public:
143 CONSTRAINT_OVERLAY( BOARD* aBoard, KIGFX::VIEW* aView );
144 ~CONSTRAINT_OVERLAY() override;
145
147 void Update( const BOARD_CONSTRAINT_DIAGNOSTICS& aDiag );
148
150 void RefreshSelection();
151
153 void Clear();
154
157 bool SetSelected( const KIID& aConstraint );
158
159 const KIID& GetSelected() const { return m_selected; }
160
162 bool SetIsolated( const KIID& aConstraint );
163
164 const KIID& GetIsolated() const { return m_isolated; }
165
167 bool SetVisibilityMode( OVERLAY_MODE aMode );
168
170
173 bool SetHoverShape( const KIID& aShape );
174
175 const KIID& GetHoverShape() const { return m_hoverShape; }
176
179 bool SetPickPreview( const KIID& aElement, bool aWholeElement,
180 const std::optional<VECTOR2I>& aAnchor );
181
183 void ClearPickPreview();
184
186 const std::vector<CONSTRAINT_BADGE>& Badges() const { return m_badges; }
187
190 static double BadgeHitRadius();
191
195
198 static double BadgeWorldPerPixel( double aWorldScale );
199
204 static std::vector<VECTOR2D> LayoutBadges( const std::vector<CONSTRAINT_BADGE>& aBadges,
205 double aWorldPerPx );
206
207private:
209 void render();
210
213 std::vector<CONSTRAINT_BADGE> m_badges;
219
220 // Pick preview channel drawn on top of diagnostics tint while authoring a point based constraint
221 // m_previewElement is outlined shape a point pick also marks m_previewAnchor
223 bool m_previewWhole = true;
224 std::optional<VECTOR2I> m_previewAnchor;
225};
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
This class handle bitmap images in KiCad.
Definition bitmap_base.h:45
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
constexpr void SetMaximum()
Definition box2.h:76
Draws the constraint type-glyph badges at a constant on-screen size, like the edit handles.
std::optional< VECTOR2I > m_previewAnchor
std::vector< CONSTRAINT_BADGE > m_badges
void ViewDraw(int aLayer, KIGFX::VIEW *aView) const override
Draw the parts of the object belonging to layer aLayer.
bool HitTest(const VECTOR2I &, int=0) const override
Test if aPosition is inside or on the boundary of this item.
std::map< uint32_t, std::unique_ptr< BITMAP_BASE > > m_discs
BITMAP_BASE * disc(const KIGFX::COLOR4D &aColor) const
A filled disc of the given colour, built and cached on first use.
~CONSTRAINT_BADGE_ITEM() override
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
std::map< PCB_CONSTRAINT_TYPE, std::unique_ptr< BITMAP_BASE > > m_icons
std::vector< VECTOR2D > m_layout
BITMAP_BASE * icon(PCB_CONSTRAINT_TYPE aType) const
The badge icon for a constraint type, loaded and cached on first use (nullptr for UNDEFINED).
void SetBadges(const std::vector< CONSTRAINT_BADGE > &aBadges, const KIID &aSelected)
void SetPreviewAnchor(const std::optional< VECTOR2I > &aAnchor)
Pick preview anchor drawn at constant on screen size like edit handles nullopt draws none.
wxString GetClass() const override
Return the class name.
static double BadgeHitRadius()
Click hit radius in screen pixels.
bool SetPickPreview(const KIID &aElement, bool aWholeElement, const std::optional< VECTOR2I > &aAnchor)
Preview next constraint pick target while authoring a point based constraint aElement is shape or dim...
bool SetVisibilityMode(OVERLAY_MODE aMode)
Set the visibility mode (HOVER vs ALWAYS). Returns true if it changed.
void RefreshSelection()
Redraw from the last diagnosis without re-solving (for a selection-only change).
bool SetIsolated(const KIID &aConstraint)
Show only this constraint, or niluuid to show all. Returns true if it changed.
CONSTRAINT_OVERLAY(BOARD *aBoard, KIGFX::VIEW *aView)
CONSTRAINT_BADGE_ITEM m_badgeItem
const std::vector< CONSTRAINT_BADGE > & Badges() const
Badges placed by the last Update(), for canvas hit-testing.
void ClearPickPreview()
Drop any pick preview.
BOARD_CONSTRAINT_DIAGNOSTICS m_lastDiag
std::vector< CONSTRAINT_BADGE > m_badges
std::optional< VECTOR2I > m_previewAnchor
static double BadgeWorldPerPixel(double aWorldScale)
World units per screen pixel for badge sizing, capped at far zoom-out.
void render()
Redraw the tint and badges from m_lastDiag (no re-solve).
void Clear()
Hide the overlay.
static VECTOR2D BadgeScreenOffset()
Screen-pixel offset from a badge's anchor to where its glyph draws and hit-tests, keeping the glyph c...
bool SetSelected(const KIID &aConstraint)
Mark a constraint as selected so its badge draws enlarged and ringed; pass niluuid to clear.
const KIID & GetHoverShape() const
bool SetHoverShape(const KIID &aShape)
In HOVER mode, show only this shape's constraints; niluuid draws nothing.
const KIID & GetIsolated() const
OVERLAY_MODE GetVisibilityMode() const
static std::vector< VECTOR2D > LayoutBadges(const std::vector< CONSTRAINT_BADGE > &aBadges, double aWorldPerPx)
The on-screen draw position (world units) of each badge at the given scale: the anchor offset by Badg...
void Update(const BOARD_CONSTRAINT_DIAGNOSTICS &aDiag)
Redraw the tint and badges from aDiag (the caller owns the one board-wide solve).
const KIID & GetSelected() const
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
Definition kiid.h:44
VIEW_OVERLAY_HOLDER(KIGFX::VIEW *aView)
OVERLAY_MODE
Draws the geometric-constraint diagnostics tint onto a GAL overlay (issue #2329): every constrained s...
KIID niluuid(0)
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:275
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
PCB_CONSTRAINT_TYPE
The geometric relationship a PCB_CONSTRAINT enforces between its members.
Board-wide diagnostics for the constraint overlay and info bar.
An on-canvas constraint badge.
std::vector< SEG > avoid
KIGFX::COLOR4D color
PCB_CONSTRAINT_TYPE type
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682