KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_grid_item.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 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef PCB_GRIDITEM_H
25#define PCB_GRIDITEM_H
26
27#include <board_item.h>
29
30
31class EDA_ANGLE;
33
34
35enum class PCB_GRID_TYPE
36{
39};
40
41
43{
44 bool cursor = true;
45 bool routing = true;
46 bool placement = true;
47
48 bool All() const { return cursor && routing && placement; }
49 void SetAll( bool aState ) { cursor = routing = placement = aState; }
50
51 bool operator==( const PCB_GRID_AFFECTS& aOther ) const
52 {
53 return cursor == aOther.cursor && routing == aOther.routing && placement == aOther.placement;
54 }
55};
56
57
64
65
67{
68public:
69 PCB_GRID_ITEM( BOARD_ITEM* aParent );
70
71 static inline bool ClassOf( const EDA_ITEM* aItem ) { return aItem && PCB_GRID_ITEM_T == aItem->Type(); }
72
73 wxString GetClass() const override { return wxT( "PCB_GRIDITEM" ); }
74
75 void Serialize( google::protobuf::Any& aContainer ) const override;
76 bool Deserialize( const google::protobuf::Any& aContainer ) override;
77
78 void SetPosition( const VECTOR2I& aPos ) override { m_pos = aPos; }
79 VECTOR2I GetPosition() const override { return m_pos; }
80
82 void SetOrientation( const EDA_ANGLE& aAngle ) { m_orientation = aAngle; }
83 double GetOrientationDegrees() const { return m_orientation.AsDegrees(); }
84 void SetOrientationDegrees( double aDeg ) { m_orientation = EDA_ANGLE( aDeg, DEGREES_T ); }
85
91 EDA_ANGLE GetOrientationAt( const VECTOR2I& aPos ) const;
92
93 void SetGridItemType( PCB_GRID_TYPE aType ) { m_type = aType; }
95
96 PCB_LAYER_ID GetLayer() const override
97 {
98 wxFAIL_MSG( wxT( "Grids don't have layers. Calling this has no meaning." ) );
99 return UNDEFINED_LAYER;
100 }
101
102 // Half-extent: distance from centre to edge. The grid is symmetric about the centre,
103 // so extents are stored as magnitudes - a negative input describes the same box.
104 void SetExtent( const VECTOR2I& aExtent ) { m_extent = { std::abs( aExtent.x ), std::abs( aExtent.y ) }; }
105 VECTOR2I GetExtent() const { return m_extent; }
106 void SetSpacing( const VECTOR2I& aSpacing )
107 {
108 m_spacing = { std::max( aSpacing.x, 1 ), std::max( aSpacing.y, 1 ) };
109 }
110 VECTOR2I GetSpacing() const { return m_spacing; }
111
112 // Property-panel accessors - 2x to show total width to the user.
113 int GetExtentX() const { return m_extent.x * 2; }
114 void SetExtentX( int aX ) { m_extent.x = std::abs( aX / 2 ); }
115 int GetExtentY() const { return m_extent.y * 2; }
116 void SetExtentY( int aY ) { m_extent.y = std::abs( aY / 2 ); }
117
118 int GetSpacingX() const { return m_spacing.x; }
119 void SetSpacingX( int aX ) { m_spacing.x = std::max( aX, 1 ); }
120 int GetSpacingY() const { return m_spacing.y; }
121 void SetSpacingY( int aY ) { m_spacing.y = std::max( aY, 1 ); }
122
123 int GetRadiusExtent() const { return m_extent.x; }
124 void SetRadiusExtent( int aR ) { m_extent.x = std::abs( aR ); }
125 int GetRadiusSpacing() const { return m_spacing.x; }
126 void SetRadiusSpacing( int aR ) { m_spacing.x = std::max( aR, 1 ); }
127
130 double GetPhiExtentDegrees() const { return m_phiExtent.AsDegrees(); }
131 void SetPhiExtentDegrees( double aDeg )
132 {
133 m_phiExtent = EDA_ANGLE( std::max( std::abs( aDeg ), 0.001 ), DEGREES_T );
134 }
135 double GetPhiSpacingDegrees() const { return m_phiSpacing.AsDegrees(); }
136 void SetPhiSpacingDegrees( double aDeg )
137 {
138 m_phiSpacing = EDA_ANGLE( std::max( std::abs( aDeg ), 0.001 ), DEGREES_T );
139 }
140
143 void SetAssignedPriority( unsigned aPriority ) { m_priority = aPriority ? aPriority : 1u; }
144 unsigned GetAssignedPriority() const { return m_priority; }
145
146 // Every Nth line drawn as a major tick. 0 = no subdivisions.
147 void SetTickInterval( unsigned aInterval ) { m_tickInterval = aInterval; }
148 unsigned GetTickInterval() const { return m_tickInterval; }
149
151 const PCB_GRID_AFFECTS& Affects() const { return m_affects; }
152
153 void SetAffectsCursor( bool aOn ) { m_affects.cursor = aOn; }
154 bool GetAffectsCursor() const { return m_affects.cursor; }
155 void SetAffectsRouting( bool aOn ) { m_affects.routing = aOn; }
156 bool GetAffectsRouting() const { return m_affects.routing; }
157 void SetAffectsPlacement( bool aOn ) { m_affects.placement = aOn; }
158 bool GetAffectsPlacement() const { return m_affects.placement; }
159
164
165 double GetCoverageArea() const { return AsGridGeometry().Area(); }
166
170 bool HitTestArea( const VECTOR2I& aPos, int aTolerance = 0 ) const
171 {
172 return AsGridGeometry().Contains( VECTOR2D( aPos ), (double) aTolerance );
173 }
174
175 LSET GetLayerSet() const override { return LSET::AllLayersMask(); }
176 void SetLayerSet( const LSET& aLayers ) override
177 {
178 // Grid items live on every layer; ignore attempts to assign a layer set.
179 }
180
181 std::vector<int> ViewGetLayers() const override;
182 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
183
184 void Move( const VECTOR2I& aMoveVector ) override { m_pos += aMoveVector; }
185
186 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
187 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
188
189 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
190 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
191
192 // Grid items have no physical footprint on any layer - silence the base-class warning.
193 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError,
194 ERROR_LOC aErrorLoc, bool ignoreLineWidth = false ) const override
195 {
196 }
197
198 const BOX2I GetBoundingBox() const override;
199
200 std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
202 DRC_CONSTRAINT_T aUsage = NULL_CONSTRAINT ) const override;
203
204 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
205 BITMAPS GetMenuImage() const override;
206 EDA_ITEM* Clone() const override;
207 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
208 double Similarity( const BOARD_ITEM& aOther ) const override;
209
210 bool operator==( const PCB_GRID_ITEM& aOther ) const;
211 bool operator==( const BOARD_ITEM& aOther ) const override;
212
213#if defined( DEBUG )
214 void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
215#endif
216
217protected:
218 void swapData( BOARD_ITEM* aImage ) override;
219
220private:
223 SHAPE_LINE_CHAIN buildOutlineWorld() const;
224
227 VECTOR2I m_extent; // cartesian half (x, y); polar (rMax, unused)
228 VECTOR2I m_spacing; // cartesian (dx, dy); polar (dr, unused)
230 EDA_ANGLE m_phiExtent; // polar only
231 EDA_ANGLE m_phiSpacing; // polar only
232
234 unsigned m_priority = 1;
235 unsigned m_tickInterval = 0;
237};
238
239
240class BOARD;
241
248PCB_GRID_ITEM* FindActiveGridAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole );
249
250
254EDA_ANGLE GridFrameAngleAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole );
255
256
261EDA_ANGLE GridFrameRotationDelta( const EDA_ANGLE& aFrom, const EDA_ANGLE& aTo, const EDA_ANGLE& aRotationStep );
262
263
264#endif
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
BITMAPS
A list of all bitmap identifiers.
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
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
The SIMULATOR_FRAME holds the main user-interface for running simulations.
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllLayersMask()
Definition lset.cpp:637
EDA_ANGLE GetOrientationAt(const VECTOR2I &aPos) const
World-space angle of this grid's local-x axis at aPos.
EDA_ANGLE GetPhiExtent() const
double GetPhiExtentDegrees() const
EDA_ANGLE m_phiSpacing
VECTOR2I GetSpacing() const
void SetRadiusExtent(int aR)
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
void SetAffectsRouting(bool aOn)
void SetExtentY(int aY)
void SetPosition(const VECTOR2I &aPos) override
void SetRadiusSpacing(int aR)
static bool ClassOf(const EDA_ITEM *aItem)
VECTOR2I m_extent
double GetCoverageArea() const
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void SetOrientation(const EDA_ANGLE &aAngle)
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
void SetGridItemType(PCB_GRID_TYPE aType)
bool GetAffectsRouting() const
void SetExtent(const VECTOR2I &aExtent)
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
VECTOR2I GetExtent() const
unsigned GetAssignedPriority() const
void SetTickInterval(unsigned aInterval)
bool HitTestArea(const VECTOR2I &aPos, int aTolerance=0) const
unsigned GetTickInterval() const
void SetOrientationDegrees(double aDeg)
VECTOR2I GetPosition() const override
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
int GetExtentX() const
unsigned m_priority
Higher wins in overlap resolution; 0 reserved for global grid.
int GetRadiusSpacing() const
VECTOR2I m_spacing
GRID_GEOMETRY AsGridGeometry() const
Project this grid into a GRID_GEOMETRY (doubles, radians) for shared math.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void SetSpacingX(int aX)
void SetSpacing(const VECTOR2I &aSpacing)
int GetSpacingY() const
PCB_GRID_TYPE m_type
void SetPhiExtentDegrees(double aDeg)
EDA_ANGLE m_orientation
void SetAffectsPlacement(bool aOn)
bool operator==(const PCB_GRID_ITEM &aOther) const
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
void SetSpacingY(int aY)
double GetPhiSpacingDegrees() const
EDA_ANGLE GetOrientation() const
bool GetAffectsCursor() const
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the item shape to a closed polygon.
int GetExtentY() const
double GetOrientationDegrees() const
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
void swapData(BOARD_ITEM *aImage) override
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
EDA_ANGLE GetPhiSpacing() const
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
wxString GetClass() const override
Return the class name.
void SetExtentX(int aX)
void SetPhiSpacingDegrees(double aDeg)
void Move(const VECTOR2I &aMoveVector) override
Move this object.
PCB_GRID_ITEM(BOARD_ITEM *aParent)
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
PCB_GRID_AFFECTS m_affects
PCB_GRID_AFFECTS & Affects()
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
void SetAssignedPriority(unsigned aPriority)
Priority 0 is reserved for the global background grid; user-assigned 0 is bumped to 1.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void SetLayerSet(const LSET &aLayers) override
bool GetAffectsPlacement() const
int GetSpacingX() const
EDA_ANGLE m_phiExtent
SHAPE_LINE_CHAIN buildOutlineWorld() const
Build a closed world-space outline polygon (rect or wedge).
void SetAffectsCursor(bool aOn)
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
int GetRadiusExtent() const
const PCB_GRID_AFFECTS & Affects() const
PCB_GRID_TYPE GetGridItemType() const
unsigned m_tickInterval
0 = no major ticks; N = every Nth line is major.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
DRC_CONSTRAINT_T
Definition drc_rule.h:49
@ NULL_CONSTRAINT
Definition drc_rule.h:50
@ DEGREES_T
Definition eda_angle.h:31
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:181
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
FLIP_DIRECTION
Definition mirror.h:23
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:411
PCB_GRID_TYPE
EDA_ANGLE GridFrameAngleAt(const BOARD &aBoard, const VECTOR2I &aPos, PCB_GRID_ROLE aRole)
World frame angle of the grid active for aRole at aPos; ANGLE_0 when no grid applies.
PCB_GRID_ITEM * FindActiveGridAt(const BOARD &aBoard, const VECTOR2I &aPos, PCB_GRID_ROLE aRole)
Pick the grid item active for aRole at aPos.
PCB_GRID_ROLE
EDA_ANGLE GridFrameRotationDelta(const EDA_ANGLE &aFrom, const EDA_ANGLE &aTo, const EDA_ANGLE &aRotationStep)
Minimal rotation that re-aligns an item from frame angle aFrom to aTo, reduced modulo min( aRotationS...
Geometry of a regular grid (cartesian or polar) and the math operations for snapping and coverage tes...
double Area() const
bool Contains(const VECTOR2D &aPoint, double aTolerance=0.0) const
bool operator==(const PCB_GRID_AFFECTS &aOther) const
bool routing
Used by the router as a local routing frame.
bool All() const
bool cursor
Replace the display grid for cursor snapping inside coverage.
void SetAll(bool aState)
bool placement
Used by edit/move tools for placement snap.
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682