52 m_magneticSettings( aMagneticSettings )
84 const int c_gridSnapEpsilon = 2;
104 int min_d = std::numeric_limits<int>::max();
106 for(
int i = 0; i < max_i; i++ )
108 if( pts[i] && aSeg.
Distance( *pts[i] ) <= c_gridSnapEpsilon )
132 VECTOR2I nearest(
KiROUND( ( aPoint.
x - gridOffset.
x ) / gridSize.
x ) * gridSize.
x + gridOffset.
x,
133 KiROUND( ( aPoint.
y - gridOffset.
y ) / gridSize.
y ) * gridSize.
y + gridOffset.
y );
135 int min_d = std::numeric_limits<int>::max();
137 for(
auto pt : { aArc.
GetP0(), aArc.
GetP1() } )
161 double minDist = std::numeric_limits<double>::max();
162 ANCHOR* nearestOrigin =
nullptr;
166 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( a.item );
171 if( !item->
HitTest( wxPoint( aMousePos.
x, aMousePos.
y ) ) )
174 double dist = a.Distance( aMousePos );
183 return nearestOrigin ? nearestOrigin->
pos : aMousePos;
188 std::vector<BOARD_ITEM*>& aItems )
196 double lineSnapMinCornerDistance = 50.0 / worldScale;
202 double minDist = std::numeric_limits<double>::max();
206 minDist = nearestOrigin->
Distance( aMousePos );
207 best = nearestOrigin;
212 double dist = nearestCorner->
Distance( aMousePos );
217 best = nearestCorner;
223 double dist = nearestOutline->
Distance( aMousePos );
225 if( minDist > lineSnapMinCornerDistance && dist < minDist )
226 best = nearestOutline;
229 return best ? best->
pos : aMousePos;
236 std::vector<BOARD_ITEM*> item;
241 item.push_back( aReferenceItem );
253 const std::vector<BOARD_ITEM*>& aSkip )
256 const int snapSize = 25;
264 int snapDist = snapRange;
268 bb.
SetOrigin( GetClampedCoords<double, int>(
VECTOR2D( aOrigin ) - snapRange / 2 ) );
269 bb.
SetEnd( GetClampedCoords<double, int>(
VECTOR2D( aOrigin ) + snapRange / 2 ) );
280 snapDist = nearest->
Distance( aOrigin );
285 bool snapLine =
false;
290 if( x_dist < snapRange && ( !nearest || snapDist > snapRange ) )
296 if( y_dist < snapRange && ( !nearest || snapDist > snapRange ) )
317 if( nearest->
Distance( aOrigin ) <= snapRange )
350 const std::vector<BOARD_ITEM*>& aSkip )
const 352 std::set<BOARD_ITEM*> items;
353 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
360 view->
Query( aArea, selectedItems );
364 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
375 && ( !isHighContrast || activeLayers.count( it.second ) )
378 items.insert ( item );
383 items.erase( skipItem );
396 auto handlePadShape =
405 const std::shared_ptr<SHAPE> eshape = aPad->GetEffectiveShape();
408 const std::vector<SHAPE*> shapes =
409 static_cast<const SHAPE_COMPOUND*>( eshape.get() )->Shapes();
411 for(
const SHAPE* shape : shapes )
413 switch( shape->Type() )
417 const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>( shape );
432 const SHAPE_SEGMENT* segment = static_cast<const SHAPE_SEGMENT*>( shape );
434 int offset = segment->
GetWidth() / 2;
460 const SHAPE_CIRCLE* circle = static_cast<const SHAPE_CIRCLE*>( shape );
474 const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( shape );
484 const SHAPE_SIMPLE* poly = static_cast<const SHAPE_SIMPLE*>( shape );
511 switch( aItem->
Type() )
515 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
521 &&
pad->GetBoundingBox().Contains( wxPoint( aRefPos.
x, aRefPos.
y ) )
523 && ( !isHighContrast || activeLayers.count(
pad->GetLayer() ) )
526 handlePadShape(
pad );
539 if( ( center - position ).SquaredEuclideanNorm() >
grid.SquaredEuclideanNorm() )
549 PAD*
pad = static_cast<PAD*>( aItem );
550 handlePadShape(
pad );
562 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
591 SEG first( start, point2 );
592 SEG second( point2, end );
593 SEG third( end, point3 );
594 SEG fourth( point3, start );
617 std::vector<wxPoint> poly;
620 for(
const wxPoint& p : poly )
647 PCB_TRACK* track = static_cast<PCB_TRACK*>( aItem );
709 const PCB_DIM_ALIGNED* dim = static_cast<const PCB_DIM_ALIGNED*>( aItem );
719 const PCB_DIM_CENTER* dim = static_cast<const PCB_DIM_CENTER*>( aItem );
726 for(
int i = 0; i < 2; i++ )
737 const PCB_DIM_LEADER* leader = static_cast<const PCB_DIM_LEADER*>( aItem );
768 double minDist = std::numeric_limits<double>::max();
773 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( a.item );
778 if( ( aFlags & a.flags ) != aFlags )
781 double dist = a.Distance( aPos );
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
void SetPosition(const wxPoint &aPosition) override
compound shape, consisting of multiple simple shapes
virtual const SEG GetSegment(int aIndex) const override
const std::set< unsigned int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Auxiliary items (guides, rule, etc)
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
class PCB_DIM_LEADER, a leader dimension (graphic item)
wxPoint GetPosition() const override
class FP_TEXT, text in a footprint
void addAnchor(const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
const SHAPE_LINE_CHAIN Outline() const
const wxPoint & GetCrossbarStart() const
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const wxPoint & GetEnd() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
const wxPoint & GetStart() const
Return the starting point of the graphic.
class PCB_GROUP, a set of BOARD_ITEMs
A set of BOARD_ITEMs (i.e., without duplicates).
class PCB_DIM_CENTER, a center point marking (graphic item)
KIGFX::ORIGIN_VIEWITEM m_viewAxis
VECTOR2I GetOrigin() const
const wxPoint & GetCrossbarEnd() const
CONST_ITERATOR CIterateWithHoles(int aOutline) const
void DupPolyPointsList(std::vector< wxPoint > &aBuffer) const
Duplicate the list of corners in a std::vector<wxPoint>
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
class PCB_TEXT, text on a layer
anchor of items having an anchor point (texts, footprints)
class PCB_ARC, an arc track segment on a copper layer
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
MAGNETIC_SETTINGS * m_magneticSettings
class FP_SHAPE, a footprint edge
class PAD, a pad in a footprint
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.
void SetEndPosition(const VECTOR2D &aPosition)
const VECTOR2I GetCenter() const
virtual wxPoint GetPosition() const
std::set< BOARD_ITEM * > queryVisible(const BOX2I &aArea, const std::vector< BOARD_ITEM * > &aSkip) const
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
const SEG & GetSeg() const
class PCB_TRACK, a track segment (segment on a copper layer)
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I NearestPoint(const VECTOR2I &aP, bool aAllowInternalShapePoints=true) const
Find a point on the line chain that is closest to point aP.
This file contains miscellaneous commonly used macros and functions.
For better understanding of the points that make a dimension:
bool ApproxParallel(const SEG &aSeg, int aDistanceThreshold=1) const
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
VECTOR2I AlignToArc(const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags, LSET aMatchLayers)
virtual const wxPoint & GetStart() const
The dimension's origin is the first feature point for the dimension.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
PCB_GRID_HELPER(TOOL_MANAGER *aToolMgr, MAGNETIC_SETTINGS *aMagneticSettings)
void computeAnchors(BOARD_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom=false)
computeAnchors inserts the local anchor points in to the grid helper for the specified board item,...
const wxPoint & GetEnd() const
Return the ending point of the graphic.
LSET is a set of PCB_LAYER_IDs.
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aReferenceItem)
Chooses the "best" snap anchor around the given point, optionally taking layers from the reference it...
VECTOR2< double > VECTOR2D
virtual wxPoint GetPosition() const override
OPT< VECTOR2I > OPT_VECTOR2I
double Distance(const VECTOR2I &aP) const
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
const VECTOR2I & GetP0() const
wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Mark the center of a circle or arc with a cross shape.
void SetDrawAtZero(bool aDrawFlag)
Set the draw at zero flag.
const VECTOR2I & GetArcMid() const
virtual wxPoint GetCenter() const
This defaults to the center of the bounding box if not overridden.
static LSET AllLayersMask()
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, std::vector< BOARD_ITEM * > &aItem)
class ZONE, a copper pour area
An abstract shape on 2D plane.
int SegmentCount() const
Return the number of segments in this line chain.
class PCB_TARGET, a target (graphic item)
class FOOTPRINT, a footprint
void SetEnd(coord_type x, coord_type y)
virtual size_t GetSegmentCount() const override
virtual VECTOR2I Align(const VECTOR2I &aPoint) const
wxPoint GetPosition() const override
bool GetHighContrast() const
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
VECTOR2I AlignToNearestPad(const VECTOR2I &aMousePos, PADS &aPads)
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
set of polygons (with holes, etc.)
class PCB_MARKER, a marker used to show something
a single triangle belonging to a POLY_SET triangulation
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
double DEG2RAD(double deg)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
std::pair< VIEW_ITEM *, int > LAYER_ITEM_PAIR
class ZONE, managed by a footprint
wxPoint GetArcMid() const
void SetOrigin(const Vec &pos)
empty shape (no shape...),
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
void SetColor(const KIGFX::COLOR4D &aColor)
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
BOARD_ITEM * GetSnapped() const
Function GetSnapped If the PCB_GRID_HELPER has highlighted a snap point (target shown),...
A leader is a dimension-like object pointing to a specific point.
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
class PCB_VIA, a via (like a track segment on a copper layer)
virtual const wxPoint & GetEnd() const
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
virtual int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
void SetStyle(MARKER_STYLE aStyle)
double GetWorldScale() const
Get the world scale.
std::vector< ANCHOR > m_anchors
class PCB_SHAPE, a segment not on copper layers
const VECTOR2I & GetP1() const
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
const wxPoint & GetStart() const
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Return the level of detail (LOD) of the item.
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
KICAD_T Type() const
Returns the type of object.
Position or shape has changed.
A color representation with 4 components: red, green, blue, alpha.