KiCad PCB EDA Suite
Loading...
Searching...
No Matches
block_drag_capability.cpp
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
21
22#include <algorithm>
23#include <functional>
24#include <unordered_set>
25
26#include <board.h>
27#include <footprint.h>
28#include <pcb_base_frame.h>
29#include <pcbnew_settings.h>
30#include <pcb_generator.h>
34#include <pcb_group.h>
35#include <pcb_shape.h>
38
39
41{
42 PCBNEW_SETTINGS* cfg = aFrame ? aFrame->GetPcbNewSettings() : nullptr;
43
44 return cfg && cfg->m_AreaAnchorPointSelection;
45}
46
47
49{
50 const BOARD* board = aItem.GetBoard();
51
52 if( !board )
53 return false;
54
55 for( const PCB_CONSTRAINT* constraint : CollectResolvedConstraints( board ) )
56 {
57 for( const CONSTRAINT_MEMBER& member : constraint->GetMembers() )
58 {
59 if( member.m_item == aItem.m_Uuid )
60 return true;
61 }
62 }
63
64 return false;
65}
66
67
69{
70 const BOARD* board = aItem.GetBoard();
71 bool footprintHolder = board && board->IsFootprintHolder();
72
73 switch( aItem.Type() )
74 {
75 case PCB_TRACE_T:
76 case PCB_ARC_T:
77 case PCB_VIA_T:
79
81
82 case PCB_ZONE_T:
83 // A zone inside a footprint belongs to that footprint. Reshaping it from the
84 // board editor would edit the footprint from outside its own editor.
85 if( !footprintHolder && aItem.GetParentFootprint() )
87
89
90 case PCB_SHAPE_T:
91 {
92 // Same reason as a zone inside a footprint.
93 if( !footprintHolder && aItem.GetParentFootprint() )
95
96 switch( static_cast<const PCB_SHAPE&>( aItem ).GetShape() )
97 {
99 case SHAPE_T::POLY:
101 case SHAPE_T::ELLIPSE:
103
104 case SHAPE_T::ARC:
105 case SHAPE_T::CIRCLE:
107
109 }
110 }
111
112 case PCB_GENERATOR_T:
113 {
114 // Safe to carry only when Move() takes every member along. A via stitch is an
115 // outline like a zone's. Its vias are re-placed by the regeneration that follows
116 // the drag, so it can be reshaped.
117 wxString genType = static_cast<const PCB_GENERATOR&>( aItem ).GetGeneratorType();
118
119 if( genType == PCB_VIA_STITCH::GENERATOR_TYPE )
121
124
126 }
127
128 case PCB_TABLECELL_T:
129 // A cell's rectangle belongs to the table, which lays its cells out. Carrying the cell
130 // on its own takes it out of the table, and the move tool refuses a lone cell for the
131 // same reason, so say so instead
133
134 case PCB_TEXT_T:
135 case PCB_FIELD_T:
136 case PCB_TEXTBOX_T:
137 case PCB_TABLE_T:
139 case PCB_BARCODE_T:
141 case PCB_DIM_LEADER_T:
142 case PCB_DIM_CENTER_T:
143 case PCB_DIM_RADIAL_T:
145 case PCB_TARGET_T:
146 case PCB_POINT_T:
147 case PCB_GRID_ITEM_T:
150
152 }
153}
154
155
156std::vector<BOARD_ITEM*> BlockDragExpandSelection( const std::vector<BOARD_ITEM*>& aSelection )
157{
158 std::vector<BOARD_ITEM*> expanded;
159 std::unordered_set<const BOARD_ITEM*> seen;
160
161 std::function<void( BOARD_ITEM* )> add = [&]( BOARD_ITEM* aItem )
162 {
163 if( !aItem || !seen.insert( aItem ).second )
164 return;
165
166 // A DRC marker is not board content, so there is nothing here to edit.
167 if( aItem->Type() == PCB_MARKER_T )
168 return;
169
170 if( aItem->Type() == PCB_GROUP_T )
171 {
172 for( BOARD_ITEM* member : static_cast<PCB_GROUP*>( aItem )->GetBoardItems() )
173 {
174 add( member );
175 }
176
177 return;
178 }
179
180 expanded.push_back( aItem );
181 };
182
183 for( BOARD_ITEM* item : aSelection )
184 add( item );
185
186 // A footprint moves its own children, so a child selected alongside its parent would
187 // take the displacement once from the parent and once from itself
188 std::erase_if( expanded,
189 [&]( const BOARD_ITEM* aItem )
190 {
191 FOOTPRINT* parent = aItem->GetParentFootprint();
192
193 return parent && seen.count( parent );
194 } );
195
196 return expanded;
197}
bool BlockDragIsConstraintMember(const BOARD_ITEM &aItem)
True when the item belongs to any geometric constraint on its board or inside one of its footprints.
BLOCK_DRAG_CAPABILITY BlockDragCapability(const BOARD_ITEM &aItem)
Classify one board item for a block drag.
std::vector< BOARD_ITEM * > BlockDragExpandSelection(const std::vector< BOARD_ITEM * > &aSelection)
Replace group containers with their members, through nested groups, and drop duplicates.
bool BlockDragAnchorEditingEnabled(const PCB_BASE_FRAME *aFrame)
Whether the user has turned on editing anchor points on a multi-selection.
BLOCK_DRAG_CAPABILITY
How one selected item takes part in a block drag.
@ UNSUPPORTED
Stops the drag with a message before anything moves.
@ DEFORMABLE
Shows handles, and reshapes as the user drags the ones they picked.
@ ROUTER
Moves with the block through the router, which repairs the copper at the edge of the block.
@ RIGID
Moves with the block using its own move operation.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
Definition board.h:441
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCBNEW_SETTINGS * GetPcbNewSettings() const
A geometric constraint between board items (issue #2329).
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
static const wxString GENERATOR_TYPE
static const wxString GENERATOR_TYPE
static const wxString GENERATOR_TYPE
std::vector< PCB_CONSTRAINT * > CollectResolvedConstraints(const BOARD *aBoard)
The constraints the editor resolves on aBoard.
@ ELLIPSE
Definition eda_shape.h:63
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ ELLIPSE_ARC
Definition eda_shape.h:64
Class to handle a set of BOARD_ITEMs.
One participant in a constraint: a referenced board item plus the feature of that item that participa...
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
Definition typeinfo.h:240
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:91
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:99
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:105
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
Definition typeinfo.h:239