27#include <unordered_set>
112 const double maxWorldPerPx =
pcbIUScale.mmToIU( 3.0 ) / 16.0;
114 return aWorldScale > 0.0 ? std::min( 1.0 / aWorldScale, maxWorldPerPx ) : maxWorldPerPx;
122 const double discPx = 11.0;
123 const double marginPx = 3.0;
126 const double baseAngle = atan2( preferred.
y, preferred.
x );
128 const double shapeClear = ( discPx + marginPx ) * aWorldPerPx;
129 const double badgeClear = ( 2.0 * discPx + marginPx ) * aWorldPerPx;
132 static const double dirSpread[] = { 0, 30, -30, 60, -60, 90, -90, 120, -120, 150, -150, 180 };
133 static const double magSteps[] = { 1.0, 1.6, 2.3 };
135 std::vector<VECTOR2D> positions;
136 positions.reserve( aBadges.size() );
145 double d = std::numeric_limits<double>::max();
148 for(
const SEG& seg : badge.avoid )
149 d = std::min( d, seg.
Distance( p ) - shapeClear );
151 for(
const VECTOR2D& placed : positions )
152 d = std::min( d, ( placed - aPos ).EuclideanNorm() - badgeClear );
158 double bestScore = -std::numeric_limits<double>::max();
161 for(
double mag : magSteps )
163 for(
double spread : dirSpread )
165 double a = baseAngle + spread *
M_PI / 180.0;
176 if( score > bestScore )
187 positions.push_back( best );
235 const std::optional<VECTOR2I>& aAnchor )
283 COLOR4D underColor( 0.80, 0.42, 0.02, 0.9 );
284 COLOR4D wellColor( 0.18, 0.72, 0.30, 0.9 );
285 COLOR4D overColor( 0.92, 0.18, 0.18, 0.9 );
297 const double lineWidth =
pcbIUScale.mmToIU( 0.15 );
307 default:
return underColor;
357 if( pts.size() >= 2 )
368 bool showAll =
false;
374 return std::ranges::any_of( aConstraint->
GetMembers(),
395 auto constraintShown =
398 if( focusConstraint !=
niluuid )
399 return aConstraint->
m_Uuid == focusConstraint;
407 return referencesShape( aConstraint, focusShape );
412 std::set<KIID> erroredIds( diag.
errored.begin(), diag.
errored.end() );
416 std::optional<std::unordered_set<KIID>> onBoardIds;
419 [&](
const KIID& aId )
424 return onBoardIds->contains( aId );
430 if( !onBoard( aFirst.m_item ) )
440 return shape->GetBoundingBox().Centre();
447 auto appendShapeSegs = [&](
const PCB_SHAPE* aShape, std::vector<SEG>& aOut )
463 for(
int i = 0; i <= steps; ++i )
469 aOut.emplace_back( prev, p );
481 for(
size_t i = 1; i < pts.size(); ++i )
482 aOut.emplace_back( pts[i - 1], pts[i] );
493 auto walkConstraints =
498 const std::vector<CONSTRAINT_MEMBER>& members = constraint->GetMembers();
500 if( members.empty() || !constraintShown( constraint ) )
503 bool errored = erroredIds.contains( constraint->m_Uuid );
504 bool conflicting = conflictingIds.contains( constraint->m_Uuid );
507 std::optional<VECTOR2I> pos = badgePosition( first );
514 if( errored || conflicting )
521 color = colorForState( it->second );
528 std::vector<SEG> avoid;
532 if( !onBoard( member.m_item ) )
537 appendShapeSegs( shape, avoid );
542 { *pos, constraint->m_Uuid, constraint->GetConstraintType(), color, std::move( avoid ) } );
546 walkConstraints(
m_board->Constraints() );
549 walkConstraints( footprint->Constraints() );
555 const COLOR4D previewColor( 0.10, 0.85, 0.95, 0.9 );
561 outlineShape( shape, previewColor );
567 setStroke( previewColor );
578 { return aBadge.constraint == m_selected; } ) )
606 return it->second.get();
608 std::unique_ptr<BITMAP_BASE> base;
612 if( wxBitmap bmp =
KiBitmap(
id ); bmp.IsOk() )
614 base = std::make_unique<BITMAP_BASE>();
615 base->SetImage( bmp.ConvertToImage() );
619 return (
m_icons[aType] = std::move( base ) ).get();
625 uint8_t r = uint8_t( aColor.
r * 255.0 );
626 uint8_t g = uint8_t( aColor.
g * 255.0 );
627 uint8_t b = uint8_t( aColor.
b * 255.0 );
628 uint8_t a = uint8_t( aColor.
a * 255.0 );
630 uint32_t key = ( uint32_t( r ) << 24 ) | ( uint32_t( g ) << 16 ) | ( uint32_t( b ) << 8 ) | a;
633 return it->second.get();
642 for(
int y = 0; y <
S; ++y )
644 for(
int x = 0; x <
S; ++x )
646 double d = std::hypot( x + 0.5 -
center, y + 0.5 -
center );
647 double coverage = std::clamp(
radius - d + 0.5, 0.0, 1.0 );
649 img.SetRGB( x, y, r, g, b );
650 img.SetAlpha( x, y, uint8_t( a * coverage ) );
654 auto base = std::make_unique<BITMAP_BASE>();
655 base->SetImage( img );
657 return (
m_discs[key] = std::move( base ) ).get();
674 const double iconPx = 18.0;
675 const double bigIconPx = 26.0;
676 const double linePx = 1.5;
701 gal->
Scale(
VECTOR2D( aWidth / natural, aWidth / natural ) );
706 for(
size_t i = 0; i <
m_badges.size(); ++i )
715 double iconSize = ( selected ? bigIconPx : iconPx ) * worldPerPx;
716 double chipR = 0.62 * iconSize;
720 blit(
disc( badge.
color ), pos, 2.0 * chipR );
727 gal->
SetLineWidth(
static_cast<float>( linePx * worldPerPx ) );
728 gal->
DrawCircle( pos, chipR + 2.0 * linePx * worldPerPx );
731 blit( bitmap, pos, iconSize );
738 const double pxToWorld = 1.0 /
scale;
745 gal->
SetLineWidth(
static_cast<float>( linePx * pxToWorld ) );
constexpr EDA_IU_SCALE pcbIUScale
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
BITMAPS
A list of all bitmap identifiers.
CONSTRAINT_STATE
The constraint state of a shape, for the diagnostics overlay tint.
@ OVER_CONSTRAINED
In a cluster the solver reports as conflicting.
@ UNDER_CONSTRAINED
In a cluster with remaining free degrees of freedom.
@ WELL_CONSTRAINED
In a fully-determined cluster (zero free DOF).
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
This class handle bitmap images in KiCad.
VECTOR2I GetSizePixels() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
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.
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
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).
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
~CONSTRAINT_OVERLAY() override
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.
bool SetHoverShape(const KIID &aShape)
In HOVER mode, show only this shape's constraints; niluuid draws nothing.
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).
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
EDA_ANGLE GetArcAngle() const
int GetEllipseMinorRadius() const
const VECTOR2I & GetEllipseCenter() const
EDA_ANGLE GetEllipseEndAngle() const
int GetEllipseMajorRadius() const
EDA_ANGLE GetEllipseRotation() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
EDA_ANGLE GetEllipseStartAngle() const
const std::vector< VECTOR2I > & GetBezierPoints() const
static const int POINT_SIZE
Single point size in pixels.
A color representation with 4 components: red, green, blue, alpha.
Abstract interface for drawing on a 2D-surface.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void Restore()
Restore the context.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
double GetWorldUnitLength() const
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void DrawBitmap(const BITMAP_BASE &aBitmap, double alphaBlend=1.0)
Draw a bitmap image.
virtual void Save()
Save the context.
double GetWorldScale() const
Get the world scale.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
A geometric constraint between board items (issue #2329).
const std::vector< CONSTRAINT_MEMBER > & GetMembers() const
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
SHAPE_LINE_CHAIN ConvertToPolyline(int aMaxError) const
Build a polyline approximation of the ellipse or arc.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
VIEW_OVERLAY_HOLDER(KIGFX::VIEW *aView)
std::vector< CONSTRAINT_ANCHOR_POINT > ConstraintItemAnchors(const BOARD_ITEM *aItem)
The constraint anchors an item exposes.
std::unordered_set< KIID > CollectMemberCandidateIds(const BOARD *aBoard)
The ids of every item on aBoard a constraint member can resolve to (shapes, dimensions and table cell...
std::optional< VECTOR2I > ConstraintAnchorPosition(const BOARD *aBoard, const CONSTRAINT_MEMBER &aMember)
Current location of a constraint member's anchor (its shape's START/END/CENTER, or a dimension's feat...
OVERLAY_MODE
Draws the geometric-constraint diagnostics tint onto a GAL overlay (issue #2329): every constrained s...
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_360
@ LAYER_CONSTRAINT_UNDER
Under-constrained (free DOF remain).
@ LAYER_CONSTRAINT_OVER
Over-constrained / conflicting.
@ LAYER_CONSTRAINT_WELL
Fully constrained.
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
BITMAPS ConstraintTypeBitmap(PCB_CONSTRAINT_TYPE aType)
Badge icon for a constraint type; INVALID_BITMAP for UNDEFINED.
PCB_CONSTRAINT_TYPE
The geometric relationship a PCB_CONSTRAINT enforces between its members.
std::deque< PCB_CONSTRAINT * > CONSTRAINTS
Board-wide diagnostics for the constraint overlay and info bar.
std::map< KIID, CONSTRAINT_STATE > shapeStates
std::vector< KIID > errored
Invalid constraints (member missing, deleted, or of a kind incompatible with the type).
std::vector< KIID > conflicting
A selectable feature of a shape (a segment endpoint, arc centre, ...) and its location.
An on-canvas constraint badge.
One participant in a constraint: a referenced board item plus the feature of that item that participa...
KIID m_item
Referenced board item, usually a PCB_SHAPE.
static double sweep(float aStart, float aEnd)
@ NOT_USED
the 3d code uses this value
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D