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 "pcb_grid_item.h"
25
26#include <api/api_enums.h>
27#include <api/api_utils.h>
28#include <api/board/board_types.pb.h>
29#include <bitmaps.h>
30#include <board.h>
32#include <core/mirror.h>
33#include <base_units.h>
36#include <trigo.h>
37#include <view/view.h>
38#include <i18n_utility.h>
41#include <geometry/geometry_utils.h> // KIGEOM::BoxHitTest
42#include <eda_draw_frame.h>
43#include <pcb_shape.h>
44#include <geometry/shape_null.h>
46#include <properties/property.h>
47
48#include <google/protobuf/any.pb.h>
49
51 BOARD_ITEM( aParent, PCB_GRID_ITEM_T ),
53{
55 m_extent = VECTOR2I( pcbIUScale.mmToIU( 5 ), pcbIUScale.mmToIU( 5 ) );
56 m_spacing = VECTOR2I( pcbIUScale.mmToIU( 1 ), pcbIUScale.mmToIU( 1 ) );
59}
60
61
63{
65 g.origin = VECTOR2D( m_pos );
66 g.orientation = m_orientation.GetAngle().AsRadians();
68
69 switch( m_type )
70 {
73 g.pitch = VECTOR2D( m_spacing.x, m_phiSpacing.AsRadians() );
74 g.extent = VECTOR2D( m_extent.x, m_phiExtent.AsRadians() );
75 break;
76
81 break;
82
83 default: wxFAIL_MSG( wxT( "AsGridGeometry: unhandled PCB_GRIDITEM_TYPE" ) ); break;
84 }
85
86 return g;
87}
88
89
90void PCB_GRID_ITEM::Serialize( google::protobuf::Any& aContainer ) const
91{
92 using namespace kiapi::board::types;
93
94 GridItem grid;
95
96 grid.mutable_id()->set_value( m_Uuid.AsStdString() );
97
98 kiapi::common::PackVector2( *grid.mutable_position(), m_pos );
99 grid.mutable_orientation()->set_value_degrees( m_orientation.GetAngle().AsDegrees() );
100
101 switch( m_type )
102 {
104 {
105 CartesianGridItemAttributes* cartesian = grid.mutable_cartesian();
106
107 kiapi::common::PackVector2( *cartesian->mutable_extent(), m_extent );
108 kiapi::common::PackVector2( *cartesian->mutable_spacing(), m_spacing );
109 break;
110 }
111
113 {
114 PolarGridItemAttributes* polar = grid.mutable_polar();
115
116 kiapi::common::PackDistance( *polar->mutable_radius_extent(), m_extent.x );
117 kiapi::common::PackDistance( *polar->mutable_radius_spacing(), m_spacing.x );
118 polar->mutable_phi_extent()->set_value_degrees( m_phiExtent.AsDegrees() );
119 polar->mutable_phi_spacing()->set_value_degrees( m_phiSpacing.AsDegrees() );
120 break;
121 }
122
123 default: wxFAIL_MSG( wxT( "Serialize: unhandled PCB_GRIDITEM_TYPE" ) ); break;
124 }
125
126 grid.set_priority( m_priority );
127 grid.set_tick_interval( m_tickInterval );
128
129 grid.mutable_affects()->set_cursor( m_affects.cursor );
130 grid.mutable_affects()->set_routing( m_affects.routing );
131 grid.mutable_affects()->set_placement( m_affects.placement );
132
133 grid.set_locked( IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
134 : kiapi::common::types::LockedState::LS_UNLOCKED );
135
136 kiapi::common::PackCustomProperties( grid.mutable_custom_properties(), *this );
137
138 if( !aContainer.PackFrom( grid ) )
139 wxFAIL_MSG( wxT( "Failed to pack PCB_GRID_ITEM" ) );
140}
141
142
143bool PCB_GRID_ITEM::Deserialize( const google::protobuf::Any& aContainer )
144{
145 using namespace kiapi::board::types;
146
147 GridItem grid;
148
149 if( !aContainer.UnpackTo( &grid ) )
150 return false;
151
152 SetUuidDirect( KIID( grid.id().value() ) );
153
155 SetOrientationDegrees( grid.orientation().value_degrees() );
156
157 // setters enforce range sanitation
158 if( grid.has_polar() )
159 {
161 SetRadiusExtent( kiapi::common::UnpackDistance( grid.polar().radius_extent() ) );
162 SetRadiusSpacing( kiapi::common::UnpackDistance( grid.polar().radius_spacing() ) );
163 SetPhiExtentDegrees( grid.polar().phi_extent().value_degrees() );
164 SetPhiSpacingDegrees( grid.polar().phi_spacing().value_degrees() );
165 }
166 else
167 {
169 SetExtent( kiapi::common::UnpackVector2( grid.cartesian().extent() ) );
170 SetSpacing( kiapi::common::UnpackVector2( grid.cartesian().spacing() ) );
171 }
172
173 SetAssignedPriority( grid.priority() );
174 SetTickInterval( grid.tick_interval() );
175
176 if( grid.has_affects() )
177 {
178 m_affects.cursor = grid.affects().cursor();
179 m_affects.routing = grid.affects().routing();
180 m_affects.placement = grid.affects().placement();
181 }
182
183 SetLocked( grid.locked() == kiapi::common::types::LockedState::LS_LOCKED );
184 kiapi::common::UnpackCustomProperties( grid.custom_properties(), *this );
185
186 return true;
187}
188
189
190std::vector<int> PCB_GRID_ITEM::ViewGetLayers() const
191{
192 if( IsLocked() )
194
195 return { LAYER_SUBGRIDS };
196}
197
198
199double PCB_GRID_ITEM::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
200{
201 // Hide the locked shadow when grid items themselves are not shown
203 return LOD_HIDE;
204
205 return LOD_SHOW;
206}
207
208
209void PCB_GRID_ITEM::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
210{
211 RotatePoint( m_pos, aRotCentre, aAngle );
212 m_orientation += aAngle;
213}
214
215
216void PCB_GRID_ITEM::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
217{
218 const EDA_ANGLE axis = MIRROR_AXIS( aFlipDirection );
219
220 // Move the location and adjust rotation for the flip.
221 MIRROR( m_pos, aCentre, aFlipDirection );
222 m_orientation = m_orientation.Reflect( axis );
223}
224
225
226void PCB_GRID_ITEM::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
227{
228 Mirror( MIRROR_AXIS( aCentre, aFlipDirection ) );
229}
230
231
232void PCB_GRID_ITEM::Mirror( const SEG& aAxis )
233{
234 m_pos = aAxis.ReflectPoint( m_pos );
235 m_orientation = m_orientation.Reflect( -EDA_ANGLE( aAxis.B - aAxis.A ) );
236}
237
238
239bool PCB_GRID_ITEM::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
240{
241 // Use the rotated shape (rect/wedge) rather than the axis-aligned bounding box.
242 return AsGridGeometry().Contains( VECTOR2D( aPosition ), (double) aAccuracy );
243}
244
245
247{
249 return m_orientation.GetAngle();
250
251 // Polar: local-X is the radial spoke from this grid's centre through aPos. The
252 // grid's own rotation maps spokes onto spokes, so the world radial does not
253 // depend on m_orientation.
254 VECTOR2I local = aPos - m_pos;
255
256 if( local.x == 0 && local.y == 0 )
257 return m_orientation.GetAngle();
258
259 // std::atan2 is math-CCW (y-up); EDA_ANGLE is screen-CCW (y-down) — negate.
260 return EDA_ANGLE( -std::atan2( (double) local.y, (double) local.x ), RADIANS_T );
261}
262
263
265{
266 SHAPE_LINE_CHAIN outline;
267
268 auto pushWorld = [&]( VECTOR2I aLocal )
269 {
270 RotatePoint( aLocal, m_orientation.GetAngle() );
271 outline.Append( m_pos + aLocal );
272 };
273
274 switch( m_type )
275 {
277 {
278 const int r = m_extent.x;
279 const double phiMax = m_phiExtent.AsRadians();
280
281 if( phiMax + 1e-9 < 2 * M_PI )
282 pushWorld( VECTOR2I( 0, 0 ) ); // wedge apex
283
284 constexpr int kArcSegments = 32;
285
286 for( int i = 0; i <= kArcSegments; ++i )
287 {
288 const double phi = phiMax * i / kArcSegments;
289 pushWorld( VECTOR2I( KiROUND( r * std::cos( phi ) ), KiROUND( r * std::sin( phi ) ) ) );
290 }
291 break;
292 }
293
295 pushWorld( VECTOR2I( -m_extent.x, -m_extent.y ) );
296 pushWorld( VECTOR2I( m_extent.x, -m_extent.y ) );
297 pushWorld( VECTOR2I( m_extent.x, m_extent.y ) );
298 pushWorld( VECTOR2I( -m_extent.x, m_extent.y ) );
299 break;
300
301 default:
302 wxFAIL_MSG( wxT( "buildOutlineWorld: unhandled PCB_GRIDITEM_TYPE" ) );
303 break;
304 }
305
306 outline.SetClosed( true );
307 return outline;
308}
309
310
311bool PCB_GRID_ITEM::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
312{
313 BOX2I arect = aRect;
314 arect.Inflate( aAccuracy );
315
316 const SHAPE_LINE_CHAIN outline = buildOutlineWorld();
317
318 // polygon inside an axis-aligned box <=> polygon.BBox inside the box.
319 if( aContained )
320 return arect.Contains( outline.BBox() );
321
322 return KIGEOM::BoxHitTest( outline, arect, false );
323}
324
325
327{
328 return buildOutlineWorld().BBox();
329}
330
331
333{
334 // No board geometry - return a null shape.
335 return std::make_shared<SHAPE_NULL>();
336}
337
338
339wxString PCB_GRID_ITEM::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
340{
341 return _( "Grid Item" );
342}
343
344
349
350
352{
353 return new PCB_GRID_ITEM( *this );
354}
355
356
357void PCB_GRID_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
358{
359 aList.emplace_back( _( "Grid Item" ), wxEmptyString );
360
361 wxString typeStr;
362
363 switch( GetGridItemType() )
364 {
365 case PCB_GRID_TYPE::CARTESIAN: typeStr = wxT( "xy" ); break;
366 case PCB_GRID_TYPE::POLAR: typeStr = wxT( "polar" ); break;
367 default: wxFAIL_MSG( wxT( "GetMsgPanelInfo: unhandled PCB_GRIDITEM_TYPE" ) ); break;
368 }
369
370 aList.emplace_back( _( "Type" ), typeStr );
371}
372
373
374double PCB_GRID_ITEM::Similarity( const BOARD_ITEM& aOther ) const
375{
376 if( aOther.Type() != Type() )
377 return 0.0;
378
379 const PCB_GRID_ITEM& other = static_cast<const PCB_GRID_ITEM&>( aOther );
380
381 double similarity = 1.0;
382
383 if( m_type != other.m_type )
384 similarity *= 0.9;
385 if( m_pos != other.m_pos )
386 similarity *= 0.9;
387 if( m_orientation != other.m_orientation )
388 similarity *= 0.9;
389 if( m_extent != other.m_extent )
390 similarity *= 0.9;
391 if( m_spacing != other.m_spacing )
392 similarity *= 0.9;
393 if( m_phiExtent != other.m_phiExtent )
394 similarity *= 0.9;
395 if( m_phiSpacing != other.m_phiSpacing )
396 similarity *= 0.9;
397 if( m_priority != other.m_priority )
398 similarity *= 0.9;
399 if( m_tickInterval != other.m_tickInterval )
400 similarity *= 0.9;
401 if( !( m_affects == other.m_affects ) )
402 similarity *= 0.9;
403
404 return similarity;
405}
406
407
408bool PCB_GRID_ITEM::operator==( const PCB_GRID_ITEM& aOther ) const
409{
410 return m_type == aOther.m_type && m_pos == aOther.m_pos && m_orientation == aOther.m_orientation
411 && m_extent == aOther.m_extent && m_spacing == aOther.m_spacing && m_phiExtent == aOther.m_phiExtent
412 && m_phiSpacing == aOther.m_phiSpacing && m_priority == aOther.m_priority
413 && m_tickInterval == aOther.m_tickInterval && m_affects == aOther.m_affects;
414}
415
416
417bool PCB_GRID_ITEM::operator==( const BOARD_ITEM& aOther ) const
418{
419 if( aOther.Type() != Type() )
420 return false;
421
422 return *this == static_cast<const PCB_GRID_ITEM&>( aOther );
423}
424
425
427{
428 assert( aImage->Type() == PCB_GRID_ITEM_T );
429
430 std::swap( *( (PCB_GRID_ITEM*) this ), *( (PCB_GRID_ITEM*) aImage ) );
431}
432
433
434PCB_GRID_ITEM* FindActiveGridAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole )
435{
436 PCB_GRID_ITEM* best = nullptr;
437 GRID_GEOMETRY bestGeom;
438
439 for( BOARD_ITEM* item : aBoard.Drawings() )
440 {
441 if( item->Type() != PCB_GRID_ITEM_T )
442 continue;
443
444 PCB_GRID_ITEM* grid = static_cast<PCB_GRID_ITEM*>( item );
445
446 // Selected = edit mode; exclude to avoid self-snap.
447 if( grid->IsSelected() )
448 continue;
449
450 bool applies = false;
451
452 switch( aRole )
453 {
454 case PCB_GRID_ROLE::CURSOR: applies = grid->Affects().cursor; break;
455 case PCB_GRID_ROLE::ROUTING: applies = grid->Affects().routing; break;
456 case PCB_GRID_ROLE::PLACEMENT: applies = grid->Affects().placement; break;
457 }
458
459 if( !applies )
460 continue;
461
462 if( !grid->HitTestArea( aPos ) )
463 continue;
464
465 const GRID_GEOMETRY geom = grid->AsGridGeometry();
466
467 if( !best || geom.TakesPrecedenceOver( bestGeom ) )
468 {
469 best = grid;
470 bestGeom = geom;
471 }
472 }
473
474 return best;
475}
476
477
478EDA_ANGLE GridFrameAngleAt( const BOARD& aBoard, const VECTOR2I& aPos, PCB_GRID_ROLE aRole )
479{
480 if( PCB_GRID_ITEM* grid = FindActiveGridAt( aBoard, aPos, aRole ) )
481 return grid->GetOrientationAt( aPos );
482
483 return ANGLE_0;
484}
485
486
487EDA_ANGLE GridFrameRotationDelta( const EDA_ANGLE& aFrom, const EDA_ANGLE& aTo, const EDA_ANGLE& aRotationStep )
488{
489 if( aTo == aFrom )
490 return ANGLE_0;
491
492 // Cartesian grids repeat every quarter turn, so never rotate by more than that.
493 EDA_ANGLE period = std::min( aRotationStep, ANGLE_90 );
494 EDA_ANGLE raw = aTo - aFrom;
495
496 return raw - raw.Snapped( period );
497}
498
499
501
502
503static struct PCB_GRIDITEM_DESC
504{
506 {
508
509 if( gridTypeEnum.Choices().GetCount() == 0 )
510 {
511 gridTypeEnum.Map( PCB_GRID_TYPE::CARTESIAN, _HKI( "Cartesian" ) )
512 .Map( PCB_GRID_TYPE::POLAR, _HKI( "Polar" ) );
513 }
514
518
519 // Grid items live on every layer; the inherited Layer property is meaningless.
521 []( INSPECTABLE* )
522 {
523 return false;
524 } );
525
526 const auto isCartesian =
527 []( INSPECTABLE* aItem ) -> bool
528 {
529 if( PCB_GRID_ITEM* g = dynamic_cast<PCB_GRID_ITEM*>( aItem ) )
530 return g->GetGridItemType() == PCB_GRID_TYPE::CARTESIAN;
531
532 return false;
533 };
534
535 const auto isPolar =
536 []( INSPECTABLE* aItem ) -> bool
537 {
538 if( PCB_GRID_ITEM* g = dynamic_cast<PCB_GRID_ITEM*>( aItem ) )
539 return g->GetGridItemType() == PCB_GRID_TYPE::POLAR;
540
541 return false;
542 };
543
546
547 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Orientation" ),
550
551 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Extent X" ),
553 .SetAvailableFunc( isCartesian );
554
555 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Extent Y" ),
557 .SetAvailableFunc( isCartesian );
558
559 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Spacing X" ),
561 .SetAvailableFunc( isCartesian );
562
563 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Spacing Y" ),
565 .SetAvailableFunc( isCartesian );
566
567 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Radius Extent" ),
569 .SetAvailableFunc( isPolar );
570
571 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, int>( _HKI( "Radius Spacing" ),
573 .SetAvailableFunc( isPolar );
574
575 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Phi Extent" ),
578 .SetAvailableFunc( isPolar );
579
580 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, double>( _HKI( "Phi Spacing" ),
583 .SetAvailableFunc( isPolar );
584
585 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, unsigned>( _HKI( "Priority" ),
587
588 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, unsigned>( _HKI( "Tick Interval" ),
590
591 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Cursor Snap" ),
593
594 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Routing" ),
596
597 propMgr.AddProperty( new PROPERTY<PCB_GRID_ITEM, bool>( _HKI( "Affects Placement" ),
599 }
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BITMAPS
A list of all bitmap identifiers.
SEG MIRROR_AXIS(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Definition board_item.h:85
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:101
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void SetLocked(bool aLocked) override
Definition board_item.h:441
bool IsLocked() const override
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const DRAWINGS & Drawings() const
Definition board.h:467
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
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:817
static ENUM_MAP< T > & Instance()
Definition property.h:811
wxPGChoices & Choices()
Definition property.h:862
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:68
bool IsLayerVisibleCached(int aLayer) const
Definition view.h:472
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)
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
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:275
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.
Definition seg.h:38
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
Definition seg.cpp:630
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
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.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
@ RADIANS_T
Definition eda_angle.h:31
@ DEGREES_T
Definition eda_angle.h:30
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
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:44
FLIP_DIRECTION
Definition mirror.h:26
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:918
@ 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