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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#ifndef PCB_GRID_HELPER_H
27#define PCB_GRID_HELPER_H
28
29#include <vector>
30
31#include <pcb_item_containers.h>
32#include <tool/grid_helper.h>
33#include <board.h>
34#include <footprint.h>
36#include <geometry/nearest.h>
37
38
39class LSET;
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 AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
67
68 VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem,
70 const PCB_SELECTION_FILTER_OPTIONS* aSelectionFilter = nullptr );
71
72 VECTOR2I AlignToArc ( const VECTOR2I& aPoint, const SHAPE_ARC& aSeg );
73
74 VECTOR2I SnapToPad( const VECTOR2I& aMousePos, std::deque<PAD*>& aPads );
75
76 virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aRemovedItem ) override
77 {
78 // If the item being removed is involved in the snap, clear the snap item
79 if( m_snapItem )
80 {
81 for( EDA_ITEM* eda_item : m_snapItem->items )
82 {
83 if( eda_item->IsBOARD_ITEM() )
84 {
85 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( eda_item );
86
87 if( item == aRemovedItem || item->GetParentFootprint() == aRemovedItem )
88 {
89 m_snapItem = std::nullopt;
90 break;
91 }
92 }
93 }
94 }
95 }
96
97 virtual void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override
98 {
99 // This is a bulk-remove. Simply clearing the snap item will be the most performant.
100 m_snapItem = std::nullopt;
101 }
102
111 VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aReferenceItem,
113 VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
115 const std::vector<BOARD_ITEM*>& aSkip = {} );
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
133private:
134 std::vector<BOARD_ITEM*> queryVisible( const BOX2I& aArea,
135 const std::vector<BOARD_ITEM*>& aSkip ) const;
136
142 ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags );
143
149 void computeAnchors( const std::vector<BOARD_ITEM*>& aItems, const VECTOR2I& aRefPos,
150 bool aFrom, const PCB_SELECTION_FILTER_OPTIONS* aSelectionFilter,
151 const LSET* aLayers, bool aForDrag );
152
161 void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom,
162 const PCB_SELECTION_FILTER_OPTIONS* aSelectionFilter );
163
164private:
166
167 std::vector<NEARABLE_GEOM> m_pointOnLineCandidates;
168};
169
170#endif
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
FOOTPRINT * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
std::optional< ANCHOR > m_snapItem
virtual VECTOR2I Align(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
Definition grid_helper.h:86
virtual VECTOR2I AlignGrid(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
Definition grid_helper.h:91
bool IsBOARD_ITEM() const
Definition view_item.h:102
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
virtual void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aRemovedItem) override
std::vector< NEARABLE_GEOM > m_pointOnLineCandidates
~PCB_GRID_HELPER() override
VECTOR2I AlignToArc(const VECTOR2I &aPoint, const SHAPE_ARC &aSeg)
virtual void OnBoardItemsRemoved(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
VECTOR2I SnapToPad(const VECTOR2I &aMousePos, std::deque< PAD * > &aPads)
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 BestSnapAnchor(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...
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)
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.
friend class PCBGridHelperTestFixture
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)
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::vector< BOARD_ITEM * > queryVisible(const BOX2I &aArea, const std::vector< BOARD_ITEM * > &aSkip) const
Definition seg.h:42
Master controller class:
GRID_HELPER_GRIDS
Definition grid_helper.h:44
@ GRID_CURRENT
Definition grid_helper.h:46
This file contains data structures that are saved in the project file or project local settings file ...
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694