KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_grid_helper.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 (C) 2014 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef PCB_GRID_HELPER_H
23#define PCB_GRID_HELPER_H
24
25#include <initializer_list>
26#include <set>
27#include <vector>
28
30#include <tool/grid_helper.h>
31#include <snap/snap_resolver.h>
33#include <geometry/nearest.h>
34
35#include <board.h>
36
37
38class LSET;
39class PCB_ARC;
40class SHAPE_ARC;
41class TOOL_MANAGER;
44
46{
48public:
49
51 PCB_GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings );
52 ~PCB_GRID_HELPER() override;
53
61 BOARD_ITEM* GetSnapped() const;
62
65
66 VECTOR2I Align( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const override;
67
68 VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
69
70 VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem,
72 const PCB_SELECTION_FILTER_OPTIONS* aSelectionFilter = nullptr );
73
74 VECTOR2I AlignToArc ( const VECTOR2I& aPoint, const SHAPE_ARC& aSeg );
75
76 VECTOR2I SnapToPad( const VECTOR2I& aMousePos, std::deque<PAD*>& aPads );
77
78 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aRemovedItem ) override;
79
80 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
81
90 SNAP_RESULT ResolveSnap( const VECTOR2I& aOrigin, BOARD_ITEM* aReferenceItem,
92 SNAP_RESULT ResolveSnap( const VECTOR2I& aOrigin, const LSET& aLayers,
94 const std::vector<BOARD_ITEM*>& aSkip = {},
95 std::optional<VECTOR2I> aMovingReferencePoint = std::nullopt );
96 void ClearSnapFeedback();
97
105
112 void SetSuppressedSnapSubtypes( std::set<SNAP_CANDIDATE_SUBTYPE> aSubtypes )
113 {
114 m_suppressedSnapSubtypes = std::move( aSubtypes );
115 }
116
117 GRID_HELPER_GRIDS GetItemGrid( const EDA_ITEM* aItem ) const override;
118
119 VECTOR2D GetGridSize( GRID_HELPER_GRIDS aGrid ) const override;
120
130 void AddConstructionItems( std::vector<BOARD_ITEM*> aItems, bool aExtensionOnly,
131 bool aIsPersistent );
132
135 {
137 int flags;
139 };
140
151 static std::vector<ANCHOR_SPEC> GetArcAnchors( const PCB_ARC& aArc, bool aFrom );
152
153private:
154 static BOX2I layoutBounds( const BOARD_ITEM& aItem );
155
163 bool editingInsideFootprint() const;
164
167
168 std::vector<BOARD_ITEM*> queryVisible( std::initializer_list<BOX2I> aAreas,
169 const std::vector<BOARD_ITEM*>& aSkip ) const;
170
176 ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags );
177
183 void computeAnchors( const std::vector<BOARD_ITEM*>& aItems, const VECTOR2I& aRefPos,
184 bool aFrom, const PCB_SELECTION_FILTER_OPTIONS* aSelectionFilter,
185 const LSET* aLayers, bool aForDrag );
186
195 void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom,
196 const PCB_SELECTION_FILTER_OPTIONS* aSelectionFilter );
197
198private:
200
201 std::vector<NEARABLE_GEOM> m_pointOnLineCandidates;
202
204
205 std::set<SNAP_CANDIDATE_SUBTYPE> m_suppressedSnapSubtypes;
206};
207
208#endif
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual VECTOR2I Align(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
virtual VECTOR2I AlignGrid(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
std::vector< NEARABLE_GEOM > m_pointOnLineCandidates
void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aRemovedItem) override
std::vector< BOARD_ITEM * > queryVisible(std::initializer_list< BOX2I > aAreas, const std::vector< BOARD_ITEM * > &aSkip) const
static std::vector< ANCHOR_SPEC > GetArcAnchors(const PCB_ARC &aArc, bool aFrom)
Return the snap/drag anchor points that a track arc contributes.
SNAP_RESULT ResolveSnap(const VECTOR2I &aOrigin, BOARD_ITEM *aReferenceItem, GRID_HELPER_GRIDS aGrid=GRID_HELPER_GRIDS::GRID_CURRENT)
Chooses the "best" snap anchor around the given point, optionally taking layers from the reference it...
SNAP_INFERENCE_SETTINGS snapInferenceSettings() const
Snap inference settings for whichever editor owns this helper.
~PCB_GRID_HELPER() override
VECTOR2I Align(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const override
VECTOR2I AlignToArc(const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
VECTOR2I SnapToPad(const VECTOR2I &aMousePos, std::deque< PAD * > &aPads)
void OnBoardItemsRemoved(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
BOARD_ITEM * GetSnapped() const
Function GetSnapped If the PCB_GRID_HELPER has highlighted a snap point (target shown),...
VECTOR2D GetGridSize(GRID_HELPER_GRIDS aGrid) const override
Return the size of the specified grid.
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, std::vector< BOARD_ITEM * > &aItem, GRID_HELPER_GRIDS aGrid=GRID_HELPER_GRIDS::GRID_CURRENT, const PCB_SELECTION_FILTER_OPTIONS *aSelectionFilter=nullptr)
bool editingInsideFootprint() const
True when the footprint's own contents are the layout objects.
void AddConstructionItems(std::vector< BOARD_ITEM * > aItems, bool aExtensionOnly, bool aIsPersistent)
Add construction geometry for a set of board items.
ANCHOR * nearestAnchor(const VECTOR2I &aPos, int aFlags)
Find the nearest anchor point to the given position with matching flags.
void SetSuppressedSnapSubtypes(std::set< SNAP_CANDIDATE_SUBTYPE > aSubtypes)
Drop snap candidates of these kinds before anything is ranked.
friend class PCBGridHelperTestFixture
static BOX2I layoutBounds(const BOARD_ITEM &aItem)
MAGNETIC_SETTINGS * m_magneticSettings
GRID_HELPER_GRIDS GetItemGrid(const EDA_ITEM *aItem) const override
Get the coarsest grid that applies to an item.
VECTOR2I AlignToSegment(const VECTOR2I &aPoint, const SEG &aSeg)
bool m_constructionGeometryEnabled
void SetConstructionGeometryEnabled(bool aEnable)
Turn off the geometry the snap system draws across the canvas to explain itself.
void computeAnchors(const std::vector< BOARD_ITEM * > &aItems, const VECTOR2I &aRefPos, bool aFrom, const PCB_SELECTION_FILTER_OPTIONS *aSelectionFilter, const LSET *aLayers, bool aForDrag)
computeAnchors inserts the local anchor points in to the grid helper for the specified container of b...
std::set< SNAP_CANDIDATE_SUBTYPE > m_suppressedSnapSubtypes
Definition seg.h:38
Master controller class:
GRID_HELPER_GRIDS
Definition grid_helper.h:55
@ GRID_CURRENT
Definition grid_helper.h:57
A single anchor point contributed by an item, before it is registered with the helper.
This file contains data structures that are saved in the project file or project local settings file ...
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682