KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_grid_item.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, 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#include <api/api_enums.h>
25#include <api/api_utils.h>
26#include <api/board/board_types.pb.h>
27#include <bitmaps.h>
28#include <board.h>
30#include <pcb_grid_item.h>
31#include <base_units.h>
34#include <trigo.h>
35#include <view/view.h>
36#include <i18n_utility.h>
39#include <geometry/geometry_utils.h> // KIGEOM::BoxHitTest
40#include <eda_draw_frame.h>
41#include <pcb_shape.h>
42#include <geometry/shape_null.h>
44#include <properties/property.h>
45
46#include <google/protobuf/any.pb.h>
47
49 BOARD_ITEM( aParent, PCB_GRID_ITEM_T ),
51{
53 m_extent = VECTOR2I( pcbIUScale.mmToIU( 5 ), pcbIUScale.mmToIU( 5 ) );
54 m_spacing = VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) );
57}
58
59
61{
63 g.origin = VECTOR2D( m_pos );
64 g.orientation = m_orientation.GetAngle().AsRadians();
66
67 switch( m_type )
68 {
71 g.pitch = VECTOR2D( m_spacing.x, m_phiSpacing.AsRadians() );
72 g.extent = VECTOR2D( m_extent.x, m_phiExtent.AsRadians() );
73 break;
74
79 break;
80
81 default: wxFAIL_MSG( wxT( "AsGridGeometry: unhandled PCB_GRIDITEM_TYPE" ) ); break;
82 }
83
84 return g;
85}
86
87
88void PCB_GRID_ITEM::Serialize( google::protobuf::Any& aContainer ) const
89{
90 using namespace kiapi::board::types;
91
92 GridItem grid;
93
94 grid.mutable_id()->set_value( m_Uuid.AsStdString() );
95
96 kiapi::common::PackVector2( *grid.mutable_position(), m_pos );
97 grid.mutable_orientation()->set_value_degrees( m_orientation.GetAngle().AsDegrees() );
98
99 switch( m_type )
100 {
102 {
103 CartesianGridItemAttributes* cartesian = grid.mutable_cartesian();
104
105 kiapi::common::PackVector2( *cartesian->mutable_extent(), m_extent );
106 kiapi::common::PackVector2( *cartesian->mutable_spacing(), m_spacing );
107 break;
108 }
109
111 {
112 PolarGridItemAttributes* polar = grid.mutable_polar();
113
114 kiapi::common::PackDistance( *polar->mutable_radius_extent(), m_extent.x );
115 kiapi::common::PackDistance( *polar->mutable_radius_spacing(), m_spacing.x );
116 polar->mutable_phi_extent()->set_value_degrees( m_phiExtent.AsDegrees() );
117 polar->mutable_phi_spacing()->set_value_degrees( m_phiSpacing.AsDegrees() );
118 break;
119 }
120
121 default: wxFAIL_MSG( wxT( "Serialize: unhandled PCB_GRIDITEM_TYPE" ) ); break;
122 }
123
124 grid.set_priority( m_priority );
125 grid.set_tick_interval( m_tickInterval );
126
127 grid.mutable_affects()->set_cursor( m_affects.cursor );
128 grid.mutable_affects()->set_routing( m_affects.routing );
129 grid.mutable_affects()->set_placement( m_affects.placement );
130
131 grid.set_locked( IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
132 : kiapi::common::types::LockedState::LS_UNLOCKED );
133
134 kiapi::common::PackCustomProperties( grid.mutable_custom_properties(), *this );
135 aContainer.PackFrom( grid );
136}
137
138
139bool PCB_GRID_ITEM::Deserialize( const google::protobuf::Any& aContainer )
140{
141 using namespace kiapi::board::types;
142
143 GridItem grid;
144
145 if( !aContainer.UnpackTo( &grid ) )
146 return false;
147
148 SetUuidDirect( KIID( grid.id().value() ) );
149
151 SetOrientationDegrees( grid.orientation().value_degrees() );
152
153 // setters enforce range sanitation
154 if( grid.has_polar() )
155 {
157 SetRadiusExtent( kiapi::common::UnpackDistance( grid.polar().radius_extent() ) );
158 SetRadiusSpacing( kiapi::common::UnpackDistance( grid.polar().radius_spacing() ) );
159 SetPhiExtentDegrees( grid.polar().phi_extent().value_degrees() );
160 SetPhiSpacingDegrees( grid.polar().phi_spacing().value_degrees() );
161 }
162 else
163 {
165 SetExtent( kiapi::common::UnpackVector2( grid.cartesian().extent() ) );
166 SetSpacing( kiapi::common::UnpackVector2( grid.cartesian().spacing() ) );
167 }
168
169 SetAssignedPriority( grid.priority() );
170 SetTickInterval( grid.tick_interval() );
171
172 if( grid.has_affects() )
173 {
174 m_affects.cursor = grid.affects().cursor();
175 m_affects.routing = grid.affects().routing();
176 m_affects.placement = grid.affects().placement();
177 }
178
179 SetLocked( grid.locked() == kiapi::common::types::LockedState::LS_LOCKED );
180 kiapi::common::UnpackCustomProperties( grid.custom_properties(), *this );
181
182 return true;
183}
184
185
186std::vector<int> PCB_GRID_ITEM::ViewGetLayers() const
187{
188 if( IsLocked() )
190
191 return { LAYER_SUBGRIDS };
192}
193
194
195double PCB_GRID_ITEM::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
196{
197 // Hide the locked shadow when grid items themselves are not shown
199 return LOD_HIDE;
200
201 return LOD_SHOW;
202}
203
204
205void PCB_GRID_ITEM::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
206{
207 RotatePoint( m_pos, aRotCentre, aAngle );
208 m_orientation += aAngle;
209}
210
211
212void PCB_GRID_ITEM::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
213{
214 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
215 {
216 m_pos.x = aCentre.x - ( m_pos.x - aCentre.x );
218 }
219 else
220 {
221 m_pos.y = aCentre.y - ( m_pos.y - aCentre.y );
223 }
224}
225
226
227bool PCB_GRID_ITEM::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
228{
229 // Use the rotated shape (rect/wedge) rather than the axis-aligned bounding box.
230 return AsGridGeometry().Contains( VECTOR2D( aPosition ), (double) aAccuracy );
231}
232
233
235{
237 return m_orientation.GetAngle();
238
239 // Polar: local-X is the radial spoke from this grid's centre through aPos. The
240 // grid's own rotation maps spokes onto spokes, so the world radial does not
241 // depend on m_orientation.
242 VECTOR2I local = aPos - m_pos;
243
244 if( local.x == 0 && local.y == 0 )
245 return m_orientation.GetAngle();
246
247 // std::atan2 is math-CCW (y-up); EDA_ANGLE is screen-CCW (y-down) — negate.
248 return EDA_ANGLE( -std::atan2( (double) local.y, (double) local.x ), RADIANS_T );
249}
250
251
253{
254 SHAPE_LINE_CHAIN outline;
255
256 auto pushWorld = [&]( VECTOR2I aLocal )
257 {
258 RotatePoint( aLocal, m_orientation.GetAngle() );
259 outline.Append( m_pos + aLocal );
260 };
261
262 switch( m_type )
263 {
265 {
266 const int r = m_extent.x;
267 const double phiMax = m_phiExtent.AsRadians();
268
269 if( phiMax + 1e-9 < 2 * M_PI )
270 pushWorld( VECTOR2I( 0, 0 ) ); // wedge apex
271
272 constexpr int kArcSegments = 32;
273
274 for( int i = 0; i <= kArcSegments; ++i )
275 {
276 const double phi = phiMax * i / kArcSegments;
277 pushWorld( VECTOR2I( KiROUND( r * std::cos( phi ) ), KiROUND( r * std::sin( phi ) ) ) );
278 }
279 break;
280 }
281
283 pushWorld( VECTOR2I( -m_extent.x, -m_extent.y ) );
284 pushWorld( VECTOR2I( m_extent.x, -m_extent.y ) );
285 pushWorld( VECTOR2I( m_extent.x, m_extent.y ) );
286 pushWorld( VECTOR2I( -m_extent.x, m_extent.y ) );
287 break;
288
289 default:
290 wxFAIL_MSG( wxT( "buildOutlineWorld: unhandled PCB_GRIDITEM_TYPE" ) );
291 break;
292 }
293
294 outline.SetClosed( true );
295 return outline;
296}
297
298
299bool PCB_GRID_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
300{
301 BOX2I arect = aRect;
302 arect.Inflate( aAccuracy );
303
304 const SHAPE_LINE_CHAIN outline = buildOutlineWorld();
305
306 // polygon inside an axis-aligned box <=> polygon.BBox inside the box.
307 if( aContained )
308 return arect.Contains( outline.BBox() );
309
310 return KIGEOM::BoxHitTest( outline, arect, false );
311}
312
313
315{
316 return buildOutlineWorld().BBox();
317}
318
319
321{
322 // No board geometry - return a null shape.
323 return std::make_shared<SHAPE_NULL>();
324}
325
326
327wxString PCB_GRID_ITEM::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
328{
329 return _( "Grid Item" );
330}
331
332
337
338
340{
341 return new PCB_GRID_ITEM( *this );
342}
343
344
345void PCB_GRID_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
346{
347 aList.emplace_back( _( "Grid Item" ), wxEmptyString );
348
349 wxString typeStr;
350
351 switch( GetGridItemType() )
352 {
353 case PCB_GRID_TYPE::CARTESIAN: typeStr = wxT( "xy" ); break;
354 case PCB_GRID_TYPE::POLAR: typeStr = wxT( "polar" ); break;
355 default: wxFAIL_MSG( wxT( "GetMsgPanelInfo: unhandled PCB_GRIDITEM_TYPE" ) ); break;
356 }
357
358 aList.emplace_back( _( "Type" ), typeStr );
359}
360
361
362double PCB_GRID_ITEM::Similarity( const BOARD_ITEM& aOther ) const
363{
364 if( aOther.Type() != Type() )
365 return 0.0;
366
367 const PCB_GRID_ITEM& other = static_cast<const PCB_GRID_ITEM&>( aOther );
368
369 double similarity = 1.0;
370
371 if( m_type != other.m_type )
372 similarity *= 0.9;
373 if( m_pos != other.m_pos )
374 similarity *= 0.9;
375 if( m_orientation != other.m_orientation )
376 similarity *= 0.9;
377 if( m_extent != other.m_extent )
378 similarity *= 0.9;
379 if( m_spacing != other.m_spacing )
380 similarity *= 0.9;
381 if( m_phiExtent != other.m_phiExtent )
382 similarity *= 0.9;
383 if( m_phiSpacing != other.m_phiSpacing )
384 similarity *= 0.9;
385 if( m_priority != other.m_priority )
386 similarity *= 0.9;
387 if( m_tickInterval != other.m_tickInterval )
388 similarity *= 0.9;
389 if( !( m_affects == other.m_affects ) )
390 similarity *= 0.9;
391
392 return similarity;
393}
394
395
396bool PCB_GRID_ITEM::operator==( const PCB_GRID_ITEM& aOther ) const
397{
398 return m_type == aOther.m_type && m_pos == aOther.m_pos && m_orientation == aOther.m_orientation
399 && m_extent == aOther.m_extent && m_spacing == aOther.m_spacing && m_phiExtent == aOther.m_phiExtent
400 && m_phiSpacing == aOther.m_phiSpacing && m_priority == aOther.m_priority
401 && m_tickInterval == aOther.m_tickInterval && m_affects == aOther.m_affects;
402}
403
404
405bool PCB_GRID_ITEM::operator==( const BOARD_ITEM& aOther ) const
406{
407 if( aOther.Type() != Type() )
408 return false;
409
410 return *this == static_cast<const PCB_GRID_ITEM&>( aOther );
411}
412
413
415{
416 assert( aImage->Type() == PCB_GRID_ITEM_T );
417
418 std::swap( *( (PCB_GRID_ITEM*) this ), *( (PCB_GRID_ITEM*) aImage ) );
419}
420
421
422PCB_GRID_ITEM* FindActiveGridAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole )
423{
424 PCB_GRID_ITEM* best = nullptr;
425 GRID_GEOMETRY bestGeom;
426
427 for( BOARD_ITEM* item : aBoard.Drawings() )
428 {
429 if( item->Type() != PCB_GRID_ITEM_T )
430 continue;
431
432 PCB_GRID_ITEM* grid = static_cast<PCB_GRID_ITEM*>( item );
433
434 // Selected = edit mode; exclude to avoid self-snap.
435 if( grid->IsSelected() )
436 continue;
437
438 bool applies = false;
439
440 switch( aRole )
441 {
442 case PCB_GRID_ROLE::CURSOR: applies = grid->Affects().cursor; break;
443 case PCB_GRID_ROLE::ROUTING: applies = grid->Affects().routing; break;
444 case PCB_GRID_ROLE::PLACEMENT: applies = grid->Affects().placement; break;
445 }
446
447 if( !applies )
448 continue;
449
450 if( !grid->HitTestArea( aPos ) )
451 continue;
452
453 const GRID_GEOMETRY geom = grid->AsGridGeometry();
454
455 if( !best || geom.TakesPrecedenceOver( bestGeom ) )
456 {
457 best = grid;
458 bestGeom = geom;
459 }
460 }
461
462 return best;
463}
464
465
466EDA_ANGLE GridFrameAngleAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole )
467{
468 if( PCB_GRID_ITEM* grid = FindActiveGridAt( aBoard, aPos, aRole ) )
469 return grid->GetOrientationAt( aPos );
470
471 return ANGLE_0;
472}
473
474
475EDA_ANGLE GridFrameRotationDelta( const EDA_ANGLE& aFrom, const EDA_ANGLE& aTo, const EDA_ANGLE& aRotationStep )
476{
477 if( aTo == aFrom )
478 return ANGLE_0;
479
480 // Cartesian grids repeat every quarter turn, so never rotate by more than that.
481 EDA_ANGLE period = std::min( aRotationStep, ANGLE_90 );
482 EDA_ANGLE raw = aTo - aFrom;
483
484 return raw - raw.Snapped( period );
485}
486
487
489
490
491static struct PCB_GRIDITEM_DESC
492{
494 {
496
497 if( gridTypeEnum.Choices().GetCount() == 0 )
498 {
499 gridTypeEnum.Map( PCB_GRID_TYPE::CARTESIAN, _HKI( "Cartesian" ) )
500 .Map( PCB_GRID_TYPE::POLAR, _HKI( "Polar" ) );
501 }
502
506
507 // Grid items live on every layer; the inherited Layer property is meaningless.
509 []( INSPECTABLE* )
510 {
511 return false;
512 } );
513
514 const auto isCartesian =
515 []( INSPECTABLE* aItem ) -> bool
516 {
517 if( PCB_GRID_ITEM* g = dynamic_cast<PCB_GRID_ITEM*>( aItem ) )
518 return g->GetGridItemType() == PCB_GRID_TYPE::CARTESIAN;
519
520 return false;
521 };
522
523 const auto isPolar =
524 []( INSPECTABLE* aItem ) -> bool
525 {
526 if( PCB_GRID_ITEM* g = dynamic_cast<PCB_GRID_ITEM*>( aItem ) )
527 return g->GetGridItemType() == PCB_GRID_TYPE::POLAR;
528
529 return false;
530 };
531
534
535 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Orientation" ),
538
539 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Extent X" ),
541 .SetAvailableFunc( isCartesian );
542
543 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Extent Y" ),
545 .SetAvailableFunc( isCartesian );
546
547 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Spacing X" ),
549 .SetAvailableFunc( isCartesian );
550
551 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Spacing Y" ),
553 .SetAvailableFunc( isCartesian );
554
555 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Radius Extent" ),
557 .SetAvailableFunc( isPolar );
558
559 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Radius Spacing" ),
561 .SetAvailableFunc( isPolar );
562
563 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Phi Extent" ),
566 .SetAvailableFunc( isPolar );
567
568 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Phi Spacing" ),
571 .SetAvailableFunc( isPolar );
572
573 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, unsigned>( _HKI( "Priority" ),
575
576 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, unsigned>( _HKI( "Tick Interval" ),
578
579 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Cursor Snap" ),
581
582 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Routing" ),
584
585 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Placement" ),
587 }
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:982
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
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void SetLocked(bool aLocked) override
Definition board_item.h:418
bool IsLocked() const override
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
const DRAWINGS & Drawings() const
Definition board.h:466
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:553
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:165
EDA_ANGLE Snapped(const EDA_ANGLE &aStep) const
Snap to the nearest integer multiple of aStep (returns *this if aStep <= 0).
Definition eda_angle.h:300
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:599
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
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:789
static ENUM_MAP< T > & Instance()
Definition property.h:783
wxPGChoices & Choices()
Definition property.h:834
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:176
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:181
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
bool IsLayerVisibleCached(int aLayer) const
Definition view.h:441
Definition kiid.h:46
EDA_ANGLE GetOrientationAt(const VECTOR2I &aPos) const
World-space angle of this grid's local-x axis at aPos.
double GetPhiExtentDegrees() const
EDA_ANGLE m_phiSpacing
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)
VECTOR2I m_extent
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
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.
unsigned GetAssignedPriority() const
EDA_ORIENTATION m_orientation
void SetTickInterval(unsigned aInterval)
unsigned GetTickInterval() const
void SetOrientationDegrees(double aDeg)
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)
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
bool GetAffectsCursor() const
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.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void SetExtentX(int aX)
void SetPhiSpacingDegrees(double aDeg)
PCB_GRID_ITEM(BOARD_ITEM *aParent)
PCB_GRID_AFFECTS m_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.
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)
int GetRadiusExtent() const
PCB_GRID_TYPE GetGridItemType() const
unsigned m_tickInterval
0 = no major ticks; N = every Nth line is major.
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:263
Provide class metadata.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
DRC_CONSTRAINT_T
Definition drc_rule.h:49
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:448
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:450
@ RADIANS_T
Definition eda_angle.h:31
@ DEGREES_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:452
a few functions useful in geometry calculations.
Some functions to handle hotkeys in KiCad.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:303
@ LAYER_SUBGRIDS
Routing/placement subgrids (PCB_GRID_ITEM) visibility and color.
Definition layer_ids.h:323
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
FLIP_DIRECTION
Definition mirror.h:23
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:24
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
#define _HKI(x)
Definition page_info.cpp:40
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.
static struct PCB_GRIDITEM_DESC _PCB_GRIDITEM_DESC
PCB_GRID_ITEM * FindActiveGridAt(const BOARD &aBoard, const VECTOR2I &aPos, PCB_GRID_ROLE aRole)
Pick the grid item active for aRole at aPos.
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...
PCB_GRID_TYPE
PCB_GRID_ROLE
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define ENUM_TO_WXANY(type)
Definition property.h:890
@ PT_DEGREE
Angle expressed in degrees.
Definition property.h:66
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
Geometry of a regular grid (cartesian or polar) and the math operations for snapping and coverage tes...
unsigned priority
Higher wins where grids overlap.
double orientation
Rotation about origin, radians CCW.
VECTOR2D extent
Cartesian: (dx, dy) = size/2 from origin.
VECTOR2D pitch
Cartesian: (dx, dy); polar: (dr, dPhi rad).
bool TakesPrecedenceOver(const GRID_GEOMETRY &aOther) const
bool Contains(const VECTOR2D &aPoint, double aTolerance=0.0) const
VECTOR2D origin
#define M_PI
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707