KiCad PCB EDA Suite
Loading...
Searching...
No Matches
block_drag_validation.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 <board.h>
23#include <board_item.h>
26#include <layer_ids.h>
27#include <zone.h>
28
29namespace
30{
31
40bool zoneOutlineIsSound( const SHAPE_POLY_SET& aOutline )
41{
42 if( aOutline.OutlineCount() == 0 || aOutline.HasTouchingHoles() )
43 return false;
44
45 for( int ii = 0; ii < aOutline.OutlineCount(); ++ii )
46 {
47 const SHAPE_LINE_CHAIN& outline = aOutline.COutline( ii );
48
49 if( outline.PointCount() < 3 )
50 return false;
51
52 for( int jj = 0; jj < aOutline.HoleCount( ii ); ++jj )
53 {
54 const SHAPE_LINE_CHAIN& hole = aOutline.CHole( ii, jj );
55
56 // A hole dragged right out of its outline is no longer a hole
57 if( hole.PointCount() < 3 || !outline.PointInside( hole.CPoint( 0 ) ) )
58 return false;
59 }
60
61 if( aOutline.IsPolygonSelfIntersecting( ii ) )
62 return false;
63 }
64
65 return true;
66}
67
68} // namespace
69
70
72 m_board( &aBoard ),
73 m_outlineAffected( false ),
74 m_outlineWasValid( false )
75{
76}
77
78
79void BLOCK_DRAG_VALIDATION::CaptureBaseline( const std::vector<BOARD_ITEM*>& aCarriedItems )
80{
81 m_zones.clear();
82 m_outlineAffected = false;
83 m_outlineWasValid = false;
84
85 // The footprint editor's board has no outline of its own, and a footprint's
86 // Edge.Cuts shapes are content the user is meant to move.
87 const bool outlineMatters = !m_board->IsFootprintHolder();
88
89 for( BOARD_ITEM* item : aCarriedItems )
90 {
91 if( !item )
92 continue;
93
94 if( item->Type() == PCB_ZONE_T )
95 {
96 ZONE* zone = static_cast<ZONE*>( item );
97 m_zones.emplace_back( zone, zoneOutlineIsSound( *zone->Outline() ) );
98 }
99
100 if( outlineMatters && item->IsOnLayer( Edge_Cuts ) )
101 m_outlineAffected = true;
102 }
103
106}
107
108
110{
111 for( const auto& [zone, wasValid] : m_zones )
112 {
113 if( wasValid && !zoneOutlineIsSound( *zone->Outline() ) )
115 }
116
119
121}
122
123
125{
126 SHAPE_POLY_SET outlines;
127
128 return m_board->GetBoardPolygonOutlines( outlines, false );
129}
BLOCK_DRAG_VALIDATION_RESULT
@ INVALID_OUTLINE
The board outline was closed before the drag and the moved Edge.Cuts broke it.
@ INVALID_ZONE
A zone that came along lost its valid outline.
void CaptureBaseline(const std::vector< BOARD_ITEM * > &aCarriedItems)
Note whether the zones coming along, and the board outline, were valid to start with.
BLOCK_DRAG_VALIDATION_RESULT Validate() const
std::vector< std::pair< ZONE *, bool > > m_zones
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
Represent a set of closed polygons.
bool IsPolygonSelfIntersecting(int aPolygonIndex) const
Check whether the aPolygonIndex-th polygon in the set is self intersecting.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
bool HasTouchingHoles() const
Return true if the polygon set has any holes that share a vertex.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Handle a list of polygons defining a copper zone.
Definition zone.h:70
SHAPE_POLY_SET * Outline()
Definition zone.h:421
@ Edge_Cuts
Definition layer_ids.h:108
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100