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 )
50{
52 m_extent = VECTOR2I( pcbIUScale.mmToIU( 5 ), pcbIUScale.mmToIU( 5 ) );
53 m_spacing = VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) );
57}
58
59
61{
63 g.origin = VECTOR2D( m_pos );
64 g.orientation = m_orientation.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.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 m_orientation.Normalize();
210}
211
212
213void PCB_GRID_ITEM::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
214{
215 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
216 {
217 m_pos.x = aCentre.x - ( m_pos.x - aCentre.x );
219 }
220 else
221 {
222 m_pos.y = aCentre.y - ( m_pos.y - aCentre.y );
224 }
225
226 m_orientation.Normalize();
227}
228
229
230bool PCB_GRID_ITEM::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
231{
232 // Use the rotated shape (rect/wedge) rather than the axis-aligned bounding box.
233 return AsGridGeometry().Contains( VECTOR2D( aPosition ), (double) aAccuracy );
234}
235
236
238{
240 return m_orientation;
241
242 // Polar: local-X is the radial spoke from this grid's centre through aPos. The
243 // grid's own rotation maps spokes onto spokes, so the world radial does not
244 // depend on m_orientation.
245 VECTOR2I local = aPos - m_pos;
246
247 if( local.x == 0 && local.y == 0 )
248 return m_orientation;
249
250 // std::atan2 is math-CCW (y-up); EDA_ANGLE is screen-CCW (y-down) — negate.
251 return EDA_ANGLE( -std::atan2( (double) local.y, (double) local.x ), RADIANS_T );
252}
253
254
256{
257 SHAPE_LINE_CHAIN outline;
258
259 auto pushWorld = [&]( VECTOR2I aLocal )
260 {
261 RotatePoint( aLocal, m_orientation );
262 outline.Append( m_pos + aLocal );
263 };
264
265 switch( m_type )
266 {
268 {
269 const int r = m_extent.x;
270 const double phiMax = m_phiExtent.AsRadians();
271
272 if( phiMax + 1e-9 < 2 * M_PI )
273 pushWorld( VECTOR2I( 0, 0 ) ); // wedge apex
274
275 constexpr int kArcSegments = 32;
276
277 for( int i = 0; i <= kArcSegments; ++i )
278 {
279 const double phi = phiMax * i / kArcSegments;
280 pushWorld( VECTOR2I( KiROUND( r * std::cos( phi ) ), KiROUND( r * std::sin( phi ) ) ) );
281 }
282 break;
283 }
284
286 pushWorld( VECTOR2I( -m_extent.x, -m_extent.y ) );
287 pushWorld( VECTOR2I( m_extent.x, -m_extent.y ) );
288 pushWorld( VECTOR2I( m_extent.x, m_extent.y ) );
289 pushWorld( VECTOR2I( -m_extent.x, m_extent.y ) );
290 break;
291
292 default:
293 wxFAIL_MSG( wxT( "buildOutlineWorld: unhandled PCB_GRIDITEM_TYPE" ) );
294 break;
295 }
296
297 outline.SetClosed( true );
298 return outline;
299}
300
301
302bool PCB_GRID_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
303{
304 BOX2I arect = aRect;
305 arect.Inflate( aAccuracy );
306
307 const SHAPE_LINE_CHAIN outline = buildOutlineWorld();
308
309 // polygon inside an axis-aligned box <=> polygon.BBox inside the box.
310 if( aContained )
311 return arect.Contains( outline.BBox() );
312
313 return KIGEOM::BoxHitTest( outline, arect, false );
314}
315
316
318{
319 return buildOutlineWorld().BBox();
320}
321
322
324{
325 // No board geometry - return a null shape.
326 return std::make_shared<SHAPE_NULL>();
327}
328
329
330wxString PCB_GRID_ITEM::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
331{
332 return _( "Grid Item" );
333}
334
335
340
341
343{
344 return new PCB_GRID_ITEM( *this );
345}
346
347
348void PCB_GRID_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
349{
350 aList.emplace_back( _( "Grid Item" ), wxEmptyString );
351
352 wxString typeStr;
353
354 switch( GetGridItemType() )
355 {
356 case PCB_GRID_TYPE::CARTESIAN: typeStr = wxT( "xy" ); break;
357 case PCB_GRID_TYPE::POLAR: typeStr = wxT( "polar" ); break;
358 default: wxFAIL_MSG( wxT( "GetMsgPanelInfo: unhandled PCB_GRIDITEM_TYPE" ) ); break;
359 }
360
361 aList.emplace_back( _( "Type" ), typeStr );
362}
363
364
365double PCB_GRID_ITEM::Similarity( const BOARD_ITEM& aOther ) const
366{
367 if( aOther.Type() != Type() )
368 return 0.0;
369
370 const PCB_GRID_ITEM& other = static_cast<const PCB_GRID_ITEM&>( aOther );
371
372 double similarity = 1.0;
373
374 if( m_type != other.m_type )
375 similarity *= 0.9;
376 if( m_pos != other.m_pos )
377 similarity *= 0.9;
378 if( m_orientation != other.m_orientation )
379 similarity *= 0.9;
380 if( m_extent != other.m_extent )
381 similarity *= 0.9;
382 if( m_spacing != other.m_spacing )
383 similarity *= 0.9;
384 if( m_phiExtent != other.m_phiExtent )
385 similarity *= 0.9;
386 if( m_phiSpacing != other.m_phiSpacing )
387 similarity *= 0.9;
388 if( m_priority != other.m_priority )
389 similarity *= 0.9;
390 if( m_tickInterval != other.m_tickInterval )
391 similarity *= 0.9;
392 if( !( m_affects == other.m_affects ) )
393 similarity *= 0.9;
394
395 return similarity;
396}
397
398
399bool PCB_GRID_ITEM::operator==( const PCB_GRID_ITEM& aOther ) const
400{
401 return m_type == aOther.m_type && m_pos == aOther.m_pos && m_orientation == aOther.m_orientation
402 && m_extent == aOther.m_extent && m_spacing == aOther.m_spacing && m_phiExtent == aOther.m_phiExtent
403 && m_phiSpacing == aOther.m_phiSpacing && m_priority == aOther.m_priority
404 && m_tickInterval == aOther.m_tickInterval && m_affects == aOther.m_affects;
405}
406
407
408bool PCB_GRID_ITEM::operator==( const BOARD_ITEM& aOther ) const
409{
410 if( aOther.Type() != Type() )
411 return false;
412
413 return *this == static_cast<const PCB_GRID_ITEM&>( aOther );
414}
415
416
418{
419 assert( aImage->Type() == PCB_GRID_ITEM_T );
420
421 std::swap( *( (PCB_GRID_ITEM*) this ), *( (PCB_GRID_ITEM*) aImage ) );
422}
423
424
425PCB_GRID_ITEM* FindActiveGridAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole )
426{
427 PCB_GRID_ITEM* best = nullptr;
428 GRID_GEOMETRY bestGeom;
429
430 for( BOARD_ITEM* item : aBoard.Drawings() )
431 {
432 if( item->Type() != PCB_GRID_ITEM_T )
433 continue;
434
435 PCB_GRID_ITEM* grid = static_cast<PCB_GRID_ITEM*>( item );
436
437 // Selected = edit mode; exclude to avoid self-snap.
438 if( grid->IsSelected() )
439 continue;
440
441 bool applies = false;
442
443 switch( aRole )
444 {
445 case PCB_GRID_ROLE::CURSOR: applies = grid->Affects().cursor; break;
446 case PCB_GRID_ROLE::ROUTING: applies = grid->Affects().routing; break;
447 case PCB_GRID_ROLE::PLACEMENT: applies = grid->Affects().placement; break;
448 }
449
450 if( !applies )
451 continue;
452
453 if( !grid->HitTestArea( aPos ) )
454 continue;
455
456 const GRID_GEOMETRY geom = grid->AsGridGeometry();
457
458 if( !best || geom.TakesPrecedenceOver( bestGeom ) )
459 {
460 best = grid;
461 bestGeom = geom;
462 }
463 }
464
465 return best;
466}
467
468
469EDA_ANGLE GridFrameAngleAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole )
470{
471 if( PCB_GRID_ITEM* grid = FindActiveGridAt( aBoard, aPos, aRole ) )
472 return grid->GetOrientationAt( aPos );
473
474 return ANGLE_0;
475}
476
477
478EDA_ANGLE GridFrameRotationDelta( const EDA_ANGLE& aFrom, const EDA_ANGLE& aTo, const EDA_ANGLE& aRotationStep )
479{
480 if( aTo == aFrom )
481 return ANGLE_0;
482
483 // Cartesian grids repeat every quarter turn, so never rotate by more than that.
484 EDA_ANGLE period = std::min( aRotationStep, ANGLE_90 );
485 EDA_ANGLE raw = aTo - aFrom;
486
487 return raw - raw.Snapped( period );
488}
489
490
492
493
494static struct PCB_GRIDITEM_DESC
495{
497 {
499
500 if( gridTypeEnum.Choices().GetCount() == 0 )
501 {
502 gridTypeEnum.Map( PCB_GRID_TYPE::CARTESIAN, _HKI( "Cartesian" ) )
503 .Map( PCB_GRID_TYPE::POLAR, _HKI( "Polar" ) );
504 }
505
509
510 // Grid items live on every layer; the inherited Layer property is meaningless.
512 []( INSPECTABLE* )
513 {
514 return false;
515 } );
516
517 const auto isCartesian =
518 []( INSPECTABLE* aItem ) -> bool
519 {
520 if( PCB_GRID_ITEM* g = dynamic_cast<PCB_GRID_ITEM*>( aItem ) )
521 return g->GetGridItemType() == PCB_GRID_TYPE::CARTESIAN;
522
523 return false;
524 };
525
526 const auto isPolar =
527 []( INSPECTABLE* aItem ) -> bool
528 {
529 if( PCB_GRID_ITEM* g = dynamic_cast<PCB_GRID_ITEM*>( aItem ) )
530 return g->GetGridItemType() == PCB_GRID_TYPE::POLAR;
531
532 return false;
533 };
534
537
538 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Orientation" ),
541
542 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Extent X" ),
544 .SetAvailableFunc( isCartesian );
545
546 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Extent Y" ),
548 .SetAvailableFunc( isCartesian );
549
550 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Spacing X" ),
552 .SetAvailableFunc( isCartesian );
553
554 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Spacing Y" ),
556 .SetAvailableFunc( isCartesian );
557
558 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Radius Extent" ),
560 .SetAvailableFunc( isPolar );
561
562 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Radius Spacing" ),
564 .SetAvailableFunc( isPolar );
565
566 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Phi Extent" ),
569 .SetAvailableFunc( isPolar );
570
571 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Phi Spacing" ),
574 .SetAvailableFunc( isPolar );
575
576 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, unsigned>( _HKI( "Priority" ),
578
579 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, unsigned>( _HKI( "Tick Interval" ),
581
582 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Cursor Snap" ),
584
585 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Routing" ),
587
588 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Placement" ),
590 }
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
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:417
bool IsLocked() const override
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
const DRAWINGS & Drawings() const
Definition board.h:465
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:291
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:597
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:776
static ENUM_MAP< T > & Instance()
Definition property.h:770
wxPGChoices & Choices()
Definition property.h:821
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:439
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
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)
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
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.Helper macro to map type hashes to names.
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:422
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:424
@ RADIANS_T
Definition eda_angle.h:32
@ DEGREES_T
Definition eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:426
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)
Definition property.h:74
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition property.h:877
@ 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)
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:225
@ 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