-
-
Notifications
You must be signed in to change notification settings - Fork 496
/
Copy pathboard.h
1413 lines (1193 loc) · 47.8 KB
/
board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007 Jean-Pierre Charras, [email protected]
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef CLASS_BOARD_H_
#define CLASS_BOARD_H_
#include <board_item_container.h>
#include <board_stackup_manager/board_stackup.h>
#include <component_class_manager.h>
#include <embedded_files.h>
#include <common.h> // Needed for stl hash extensions
#include <convert_shape_list_to_polygon.h> // for OUTLINE_ERROR_HANDLER
#include <hash.h>
#include <layer_ids.h>
#include <lset.h>
#include <netinfo.h>
#include <pcb_item_containers.h>
#include <pcb_plot_params.h>
#include <title_block.h>
#include <tools/pcb_selection.h>
#include <shared_mutex>
#include <list>
class BOARD_DESIGN_SETTINGS;
class BOARD_CONNECTED_ITEM;
class BOARD_COMMIT;
class DRC_RTREE;
class PCB_BASE_FRAME;
class PCB_EDIT_FRAME;
class PICKED_ITEMS_LIST;
class BOARD;
class FOOTPRINT;
class ZONE;
class PCB_TRACK;
class PAD;
class PCB_GROUP;
class PCB_GENERATOR;
class PCB_MARKER;
class MSG_PANEL_ITEM;
class NETLIST;
class REPORTER;
class SHAPE_POLY_SET;
class CONNECTIVITY_DATA;
class COMPONENT;
class PROJECT;
class PROGRESS_REPORTER;
namespace KIFONT
{
class OUTLINE_FONT;
}
struct ISOLATED_ISLANDS;
// The default value for m_outlinesChainingEpsilon to convert a board outlines to polygons
// It is the max dist between 2 end points to see them connected
#define DEFAULT_CHAINING_EPSILON_MM 0.01
// Forward declare endpoint from class_track.h
enum ENDPOINT_T : int;
struct PTR_PTR_CACHE_KEY
{
BOARD_ITEM* A;
BOARD_ITEM* B;
bool operator==(const PTR_PTR_CACHE_KEY& other) const
{
return A == other.A && B == other.B;
}
};
struct PTR_LAYER_CACHE_KEY
{
BOARD_ITEM* A;
PCB_LAYER_ID Layer;
bool operator==(const PTR_LAYER_CACHE_KEY& other) const
{
return A == other.A && Layer == other.Layer;
}
};
struct PTR_PTR_LAYER_CACHE_KEY
{
BOARD_ITEM* A;
BOARD_ITEM* B;
PCB_LAYER_ID Layer;
bool operator==(const PTR_PTR_LAYER_CACHE_KEY& other) const
{
return A == other.A && B == other.B && Layer == other.Layer;
}
};
namespace std
{
template <>
struct hash<PTR_PTR_CACHE_KEY>
{
std::size_t operator()( const PTR_PTR_CACHE_KEY& k ) const
{
std::size_t seed = 0xa82de1c0;
hash_combine( seed, k.A, k.B );
return seed;
}
};
template <>
struct hash<PTR_LAYER_CACHE_KEY>
{
std::size_t operator()( const PTR_LAYER_CACHE_KEY& k ) const
{
std::size_t seed = 0xa82de1c0;
hash_combine( seed, k.A, k.Layer );
return seed;
}
};
template <>
struct hash<PTR_PTR_LAYER_CACHE_KEY>
{
std::size_t operator()( const PTR_PTR_LAYER_CACHE_KEY& k ) const
{
std::size_t seed = 0xa82de1c0;
hash_combine( seed, k.A, k.B, k.Layer );
return seed;
}
};
}
/**
* The allowed types of layers, same as Specctra DSN spec.
*/
enum LAYER_T
{
LT_UNDEFINED = -1,
LT_SIGNAL,
LT_POWER,
LT_MIXED,
LT_JUMPER,
LT_AUX,
LT_FRONT,
LT_BACK
};
/**
* Container to hold information pertinent to a layer of a BOARD.
*/
struct LAYER
{
LAYER()
{
clear();
}
void clear()
{
m_type = LT_SIGNAL;
m_visible = true;
m_number = 0;
m_name.clear();
m_userName.clear();
m_opposite = m_number;
}
/*
LAYER( const wxString& aName = wxEmptyString,
LAYER_T aType = LT_SIGNAL, bool aVisible = true, int aNumber = -1 ) :
m_name( aName ),
m_type( aType ),
m_visible( aVisible ),
m_number( aNumber )
{
}
*/
wxString m_name; ///< The canonical name of the layer. @see #LSET::Name
wxString m_userName; ///< The user defined name of the layer.
LAYER_T m_type; ///< The type of the layer. @see #LAYER_T
bool m_visible;
int m_number; ///< The layer ID. @see PCB_LAYER_ID
int m_opposite; ///< Similar layer on opposite side of the board, if any.
/**
* Convert a #LAYER_T enum to a string representation of the layer type.
*
* @param aType The #LAYER_T to convert
* @return The string representation of the layer type.
*/
static const char* ShowType( LAYER_T aType );
/**
* Convert a string to a #LAYER_T
*
* @param aType The layer name to convert.
* @return The binary representation of the layer type, or
* LAYER_T(-1) if the string is invalid.
*/
static LAYER_T ParseType( const char* aType );
};
// Helper class to handle high light nets
class HIGH_LIGHT_INFO
{
protected:
std::set<int> m_netCodes; // net(s) selected for highlight (-1 when no net selected )
bool m_highLightOn; // highlight active
void Clear()
{
m_netCodes.clear();
m_highLightOn = false;
}
HIGH_LIGHT_INFO()
{
Clear();
}
private:
friend class BOARD;
};
/**
* Provide an interface to hook into board modifications and get callbacks
* on certain modifications that are made to the board. This allows updating
* auxiliary views other than the primary board editor view.
*/
class BOARD;
class BOARD_LISTENER
{
public:
virtual ~BOARD_LISTENER() { }
virtual void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) { }
virtual void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItem ) { }
virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) { }
virtual void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItem ) { }
virtual void OnBoardNetSettingsChanged( BOARD& aBoard ) { }
virtual void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) { }
virtual void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItem ) { }
virtual void OnBoardHighlightNetChanged( BOARD& aBoard ) { }
virtual void OnBoardRatsnestChanged( BOARD& aBoard ) { }
virtual void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
std::vector<BOARD_ITEM*>& aRemovedItems,
std::vector<BOARD_ITEM*>& aDeletedItems )
{
}
};
/**
* Set of BOARD_ITEMs ordered by UUID.
*/
typedef std::set<BOARD_ITEM*, CompareByUuid> BOARD_ITEM_SET;
/**
* Flags to specify how the board is being used.
*/
enum class BOARD_USE
{
NORMAL, // A normal board
FPHOLDER // A board that holds a single footprint
};
/**
* Information pertinent to a Pcbnew printed circuit board.
*/
class BOARD : public BOARD_ITEM_CONTAINER, public EMBEDDED_FILES
{
public:
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && PCB_T == aItem->Type();
}
/**
* Set what the board is going to be used for.
*
* @param aUse is the flag
*/
void SetBoardUse( BOARD_USE aUse ) { m_boardUse = aUse; }
/**
* Get what the board use is.
*
* @return what the board is being used for
*/
BOARD_USE GetBoardUse() const { return m_boardUse; }
void IncrementTimeStamp();
int GetTimeStamp() const { return m_timeStamp; }
/**
* Find out if the board is being used to hold a single footprint for editing/viewing.
*
* @return if the board is just holding a footprint
*/
bool IsFootprintHolder() const
{
return m_boardUse == BOARD_USE::FPHOLDER;
}
void SetFileName( const wxString& aFileName ) { m_fileName = aFileName; }
const wxString &GetFileName() const { return m_fileName; }
const TRACKS& Tracks() const { return m_tracks; }
const FOOTPRINTS& Footprints() const { return m_footprints; }
const DRAWINGS& Drawings() const { return m_drawings; }
const ZONES& Zones() const { return m_zones; }
const GENERATORS& Generators() const { return m_generators; }
const MARKERS& Markers() const { return m_markers; }
// SWIG requires non-const accessors for some reason to make the custom iterators in board.i
// work. It would be good to remove this if we can figure out how to fix that.
#ifdef SWIG
DRAWINGS& Drawings() { return m_drawings; }
TRACKS& Tracks() { return m_tracks; }
#endif
const BOARD_ITEM_SET GetItemSet();
/**
* The groups must maintain the following invariants. These are checked by
* GroupsSanityCheck():
* - An item may appear in at most one group
* - Each group must contain at least one item
* - If a group specifies a name, it must be unique
* - The graph of groups containing subgroups must be cyclic.
*/
const GROUPS& Groups() const { return m_groups; }
const std::vector<BOARD_CONNECTED_ITEM*> AllConnectedItems();
const std::map<wxString, wxString>& GetProperties() const { return m_properties; }
void SetProperties( const std::map<wxString, wxString>& aProps ) { m_properties = aProps; }
void GetContextualTextVars( wxArrayString* aVars ) const;
bool ResolveTextVar( wxString* token, int aDepth ) const;
/// Visibility settings stored in board prior to 6.0, only used for loading legacy files
LSET m_LegacyVisibleLayers;
GAL_SET m_LegacyVisibleItems;
/// True if the legacy board design settings were loaded from a file
bool m_LegacyDesignSettingsLoaded;
bool m_LegacyCopperEdgeClearanceLoaded;
/// True if netclasses were loaded from the file
bool m_LegacyNetclassesLoaded;
BOARD();
~BOARD();
VECTOR2I GetPosition() const override;
void SetPosition( const VECTOR2I& aPos ) override;
const VECTOR2I GetFocusPosition() const override { return GetBoundingBox().GetCenter(); }
bool IsEmpty() const
{
return m_drawings.empty() && m_footprints.empty() && m_tracks.empty() && m_zones.empty();
}
void Move( const VECTOR2I& aMoveVector ) override;
void RunOnDescendants( const std::function<void ( BOARD_ITEM* )>& aFunction,
int aDepth = 0 ) const override;
void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; }
void SetGenerator( const wxString& aGenerator ) { m_generator = aGenerator; }
const wxString& GetGenerator() const { return m_generator; }
///< @copydoc BOARD_ITEM_CONTAINER::Add()
void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
bool aSkipConnectivity = false ) override;
///< @copydoc BOARD_ITEM_CONTAINER::Remove()
void Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override;
/**
* An efficient way to remove all items of a certain type from the board.
* Because of how items are stored, this method has some limitations in order to preserve
* performance: tracks, vias, and arcs are all removed together by PCB_TRACE_T, and all graphics
* and text object types are removed together by PCB_SHAPE_T. If you need something more
* granular than that, use BOARD::Remove.
* @param aTypes is a list of one or more types to remove, or leave default to remove all
*/
void RemoveAll( std::initializer_list<KICAD_T> aTypes = { PCB_NETINFO_T, PCB_MARKER_T,
PCB_GROUP_T, PCB_ZONE_T,
PCB_GENERATOR_T, PCB_FOOTPRINT_T,
PCB_TRACE_T, PCB_SHAPE_T } );
/**
* Must be used if Add() is used using a BULK_x ADD_MODE to generate a change event for
* listeners.
*/
void FinalizeBulkAdd( std::vector<BOARD_ITEM*>& aNewItems );
/**
* Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event
* for listeners.
*/
void FinalizeBulkRemove( std::vector<BOARD_ITEM*>& aRemovedItems );
/**
* After loading a file from disk, the footprints do not yet contain the full
* data for their embedded files, only a reference. This iterates over all footprints
* in the board and updates them with the full embedded data.
*/
void FixupEmbeddedData();
void CacheTriangulation( PROGRESS_REPORTER* aReporter = nullptr,
const std::vector<ZONE*>& aZones = {} );
/**
* Get the first footprint on the board or nullptr.
*
* This is used primarily by the footprint editor which knows there is only one.
*
* @return first footprint or null pointer
*/
FOOTPRINT* GetFirstFootprint() const
{
return m_footprints.empty() ? nullptr : m_footprints.front();
}
/**
* Remove all footprints from the deque and free the memory associated with them.
*/
void DeleteAllFootprints();
/**
* @return null if aID is null. Returns an object of Type() == NOT_USED if the aID is not found.
*/
BOARD_ITEM* GetItem( const KIID& aID ) const;
void FillItemMap( std::map<KIID, EDA_ITEM*>& aMap );
/**
* Convert cross-references back and forth between ${refDes:field} and ${kiid:field}
*/
wxString ConvertCrossReferencesToKIIDs( const wxString& aSource ) const;
wxString ConvertKIIDsToCrossReferences( const wxString& aSource ) const;
/**
* Return a list of missing connections between components/tracks.
* @return an object that contains information about missing connections.
*/
std::shared_ptr<CONNECTIVITY_DATA> GetConnectivity() const { return m_connectivity; }
/**
* Build or rebuild the board connectivity database for the board,
* especially the list of connected items, list of nets and rastnest data
* Needed after loading a board to have the connectivity database updated.
*/
bool BuildConnectivity( PROGRESS_REPORTER* aReporter = nullptr );
/**
* Delete all MARKERS from the board.
*/
void DeleteMARKERs();
void DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions );
PROJECT* GetProject() const { return m_project; }
/**
* Link a board to a given project.
*
* Should be called immediately after loading board in order for everything to work.
*
* @param aProject is a loaded project to link to.
* @param aReferenceOnly avoids taking ownership of settings stored in project if true
*/
void SetProject( PROJECT* aProject, bool aReferenceOnly = false );
void ClearProject();
/**
* Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS.
*
* @param aCreateMarkers if true, create markers from serialized data; if false only
* use serialized data to set existing markers to excluded.
* The former is used on board load; the later after a DRC.
*/
std::vector<PCB_MARKER*> ResolveDRCExclusions( bool aCreateMarkers );
/**
* Scan existing markers and record data from any that are Excluded.
*/
void RecordDRCExclusions();
/**
* Update the visibility flags on the current unconnected ratsnest lines.
*/
void UpdateRatsnestExclusions();
/**
* Reset all high light data to the init state
*/
void ResetNetHighLight();
/**
* @return the set of net codes that should be highlighted
*/
const std::set<int>& GetHighLightNetCodes() const
{
return m_highLight.m_netCodes;
}
/**
* Select the netcode to be highlighted.
*
* @param aNetCode is the net to highlight.
* @param aMulti is true if you want to add a highlighted net without clearing the old one.
*/
void SetHighLightNet( int aNetCode, bool aMulti = false );
/**
* @return true if a net is currently highlighted
*/
bool IsHighLightNetON() const { return m_highLight.m_highLightOn; }
/**
* Enable or disable net highlighting.
*
* If a netcode >= 0 has been set with SetHighLightNet and aValue is true, the net will be
* highlighted. If aValue is false, net highlighting will be disabled regardless of
* the highlight netcode being set.
*/
void HighLightON( bool aValue = true );
/**
* Disable net highlight.
*/
void HighLightOFF()
{
HighLightON( false );
}
/**
* @return The number of copper layers in the BOARD.
*/
int GetCopperLayerCount() const;
void SetCopperLayerCount( int aCount );
int GetUserDefinedLayerCount() const;
void SetUserDefinedLayerCount( int aCount );
/**
* @return The copper layer max PCB_LAYER_ID in the BOARD.
* similar to GetCopperLayerCount(), but returns the max PCB_LAYER_ID
*/
PCB_LAYER_ID GetCopperLayerStackMaxId() const;
PCB_LAYER_ID FlipLayer( PCB_LAYER_ID aLayer ) const;
int LayerDepth( PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer ) const;
/**
* A proxy function that calls the corresponding function in m_BoardSettings.
*
* @return the enabled layers in bit-mapped form.
*/
LSET GetEnabledLayers() const;
/**
* A proxy function that calls the correspondent function in m_BoardSettings.
*
* @param aLayerMask the new bit-mask of enabled layers.
*/
void SetEnabledLayers( LSET aLayerMask );
/**
* A proxy function that calls the correspondent function in m_BoardSettings
* tests whether a given layer is enabled
* @param aLayer = The layer to be tested
* @return true if the layer is visible.
*/
bool IsLayerEnabled( PCB_LAYER_ID aLayer ) const;
/**
* A proxy function that calls the correspondent function in m_BoardSettings
* tests whether a given layer is visible
*
* @param aLayer is the layer to be tested.
* @return true if the layer is visible otherwise false.
*/
bool IsLayerVisible( PCB_LAYER_ID aLayer ) const;
/**
* A proxy function that calls the correspondent function in m_BoardSettings.
*
* @return the visible layers in bit-mapped form.
*/
LSET GetVisibleLayers() const;
/**
* A proxy function that calls the correspondent function in m_BoardSettings
* changes the bit-mask of visible layers.
*
* @param aLayerMask is the new bit-mask of visible layers.
*/
void SetVisibleLayers( LSET aLayerMask );
// these 2 functions are not tidy at this time, since there are PCB_LAYER_IDs that
// are not stored in the bitmap.
/**
* Return a set of all the element categories that are visible.
*
* @return the set of visible GAL layers.
* @see enum GAL_LAYER_ID
*/
GAL_SET GetVisibleElements() const;
/**
* A proxy function that calls the correspondent function in m_BoardSettings.
*
* @param aMask is the new bit-mask of visible element bitmap or-ed from enum GAL_LAYER_ID
* @see enum GAL_LAYER_ID
*/
void SetVisibleElements( const GAL_SET& aMask );
/**
* Change the bit-mask of visible element categories and layers.
*
* @see enum GAL_LAYER_ID
*/
void SetVisibleAlls();
/**
* Test whether a given element category is visible.
*
* @param aLayer is from the enum by the same name.
* @return true if the element is visible otherwise false.
* @see enum GAL_LAYER_ID
*/
bool IsElementVisible( GAL_LAYER_ID aLayer ) const;
/**
* Change the visibility of an element category.
*
* @param aLayer is from the enum by the same name.
* @param aNewState is the new visibility state of the element category.
* @see enum GAL_LAYER_ID
*/
void SetElementVisibility( GAL_LAYER_ID aLayer, bool aNewState );
/**
* Expect either of the two layers on which a footprint can reside, and returns
* whether that layer is visible.
*
* @param aLayer is one of the two allowed layers for footprints: F_Cu or B_Cu
* @return true if the layer is visible, otherwise false.
*/
bool IsFootprintLayerVisible( PCB_LAYER_ID aLayer ) const;
/**
* @return the BOARD_DESIGN_SETTINGS for this BOARD
*/
BOARD_DESIGN_SETTINGS& GetDesignSettings() const;
BOARD_STACKUP GetStackupOrDefault() const;
const PAGE_INFO& GetPageSettings() const { return m_paper; }
void SetPageSettings( const PAGE_INFO& aPageSettings ) { m_paper = aPageSettings; }
const PCB_PLOT_PARAMS& GetPlotOptions() const { return m_plotOptions; }
void SetPlotOptions( const PCB_PLOT_PARAMS& aOptions ) { m_plotOptions = aOptions; }
TITLE_BLOCK& GetTitleBlock() { return m_titles; }
const TITLE_BLOCK& GetTitleBlock() const { return m_titles; }
void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; }
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
EDA_UNITS GetUserUnits() { return m_userUnits; }
void SetUserUnits( EDA_UNITS aUnits ) { m_userUnits = aUnits; }
/**
* Update any references within aItem (or its descendants) to the user units. Primarily
* for automatic-unit dimensions.
*/
void UpdateUserUnits( BOARD_ITEM* aItem, KIGFX::VIEW* aView );
/**
* Extract the board outlines and build a closed polygon from lines, arcs and circle items
* on edge cut layer.
*
* Any closed outline inside the main outline is a hole. All contours should be closed,
* i.e. have valid vertices to build a closed polygon.
*
* @param aOutlines is the #SHAPE_POLY_SET to fill in with outlines/holes.
* @param aErrorHandler is an optional DRC_ITEM error handler.
* @param aAllowUseArcsInPolygons = an optional option to allow adding arcs in
* SHAPE_LINE_CHAIN polylines/polygons when building outlines from aShapeList
* This is mainly for export to STEP files
* @param aIncludeNPTHAsOutlines = an optional option to include NPTH pad holes
* in board outlines. These holes can be seen like holes created by closed shapes
* drawn on edge cut layer inside the board main outline.
* @return true if success, false if a contour is not valid
*/
bool GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
OUTLINE_ERROR_HANDLER* aErrorHandler = nullptr,
bool aAllowUseArcsInPolygons = false,
bool aIncludeNPTHAsOutlines = false );
/**
* @return a epsilon value that is the max distance between 2 points to see them
* at the same coordinate when building the board outlines and tray to connect 2 end points
* when buildind the outlines of the board
* Too small value do not allow connecting 2 shapes (i.e. segments) not exactly connected
* Too large value do not allow safely connecting 2 shapes like very short segments.
*/
int GetOutlinesChainingEpsilon() { return( m_outlinesChainingEpsilon ); }
void SetOutlinesChainingEpsilon( int aValue) { m_outlinesChainingEpsilon = aValue; }
/**
* Build a set of polygons which are the outlines of copper items (pads, tracks, vias, texts,
* zones).
*
* Holes in vias or pads are ignored. The polygons are not merged. This is useful to
* export the shape of copper layers to dxf polygons or 3D viewer/
*
* @param aLayer is a copper layer, like B_Cu, etc.
* @param aOutlines is the SHAPE_POLY_SET to fill in with items outline.
*/
void ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aOutlines ) const;
/**
* Return the ID of a layer.
*/
PCB_LAYER_ID GetLayerID( const wxString& aLayerName ) const;
/**
* Return the name of a \a aLayer.
*
* @param aLayer is the #PCB_LAYER_ID of the layer.
* @return a string containing the name of the layer.
*/
const wxString GetLayerName( PCB_LAYER_ID aLayer ) const;
/**
* Changes the name of the layer given by aLayer.
* @param aLayer A layer, like B_Cu, etc.
* @param aLayerName The new layer name
* @return true if aLayerName was legal and unique among other layer names at other layer
* indices and aLayer was within range, else false.
*/
bool SetLayerName( PCB_LAYER_ID aLayer, const wxString& aLayerName );
/**
* Return an "English Standard" name of a PCB layer when given \a aLayerNumber.
*
* This function is static so it can be called without a BOARD instance. Use
* GetLayerName() if want the layer names of a specific BOARD, which could
* be different than the default if the user has renamed any copper layers.
*
* @param aLayerId is the layer identifier (index) to fetch.
* @return a string containing the layer name or "BAD INDEX" if aLayerId is not legal.
*/
static wxString GetStandardLayerName( PCB_LAYER_ID aLayerId )
{
// a BOARD's standard layer name is the PCB_LAYER_ID fixed name
return LayerName( aLayerId );
}
/**
* Return the type of the copper layer given by aLayer.
*
* @param aIndex A layer index in m_Layer
* @param aLayer A reference to a LAYER description.
* @return false if the index was out of range.
*/
bool SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer );
/**
* Return the type of the copper layer given by aLayer.
*
* @param aLayer A layer index, like B_Cu, etc.
* @return the layer type, or LAYER_T(-1) if the index was out of range.
*/
LAYER_T GetLayerType( PCB_LAYER_ID aLayer ) const;
/**
* Change the type of the layer given by aLayer.
*
* @param aLayer A layer index, like B_Cu, etc.
* @param aLayerType The new layer type.
* @return true if aLayerType was legal and aLayer was within range, else false.
*/
bool SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType );
/**
* @param aNet Only count nodes belonging to this net.
* @return the number of pads members of nets (i.e. with netcode > 0).
*/
unsigned GetNodesCount( int aNet = -1 ) const;
/**
* Return a reference to a list of all the pads.
*
* The returned list is not sorted and contains pointers to PADS, but those pointers do
* not convey ownership of the respective PADs.
*
* @return a full list of pads.
*/
const std::vector<PAD*> GetPads() const;
void BuildListOfNets()
{
m_NetInfo.buildListOfNets();
}
/**
* Search for a net with the given netcode.
*
* @param aNetcode A netcode to search for.
* @return the net if found or NULL if not found.
*/
NETINFO_ITEM* FindNet( int aNetcode ) const;
/**
* Search for a net with the given name.
*
* @param aNetname A Netname to search for.
* @return the net if found or NULL if not found.
*/
NETINFO_ITEM* FindNet( const wxString& aNetname ) const;
/**
* Fetch the coupled netname for a given net.
*
* This accepts netnames suffixed by 'P', 'N', '+', '-', as well as additional numbers and
* underscores following the suffix. So NET_P_123 is a valid positive net name matched to
* NET_N_123.
*
* @return the polarity of the given net (or 0 if it is not a diffpair net).
*/
int MatchDpSuffix( const wxString& aNetName, wxString& aComplementNet );
/**
* @return the coupled net for a given net. If not a diffpair, nullptr is returned.
*/
NETINFO_ITEM* DpCoupledNet( const NETINFO_ITEM* aNet );
const NETINFO_LIST& GetNetInfo() const
{
return m_NetInfo;
}
void RemoveUnusedNets( BOARD_COMMIT* aCommit )
{
m_NetInfo.RemoveUnusedNets( aCommit );
}
#ifndef SWIG
/**
* @return iterator to the first element of the NETINFO_ITEMs list.
*/
NETINFO_LIST::iterator BeginNets() const
{
return m_NetInfo.begin();
}
/**
* @return iterator to the last element of the NETINFO_ITEMs list.
*/
NETINFO_LIST::iterator EndNets() const
{
return m_NetInfo.end();
}
#endif
/**
* @return the number of nets (NETINFO_ITEM).
*/
unsigned GetNetCount() const
{
return m_NetInfo.GetNetCount();
}
/**
* Calculate the bounding box containing all board items (or board edge segments).
*
* @param aBoardEdgesOnly is true if we are interested in board edge segments only.
* @return the board's bounding box.
*/
BOX2I ComputeBoundingBox( bool aBoardEdgesOnly = false ) const;
const BOX2I GetBoundingBox() const override
{
return ComputeBoundingBox( false );
}
/**
* Return the board bounding box calculated using exclusively the board edges (graphics
* on Edge.Cuts layer).
*
* If there are items outside of the area limited by Edge.Cuts graphics, the items will
* not be taken into account.
*
* @return bounding box calculated using exclusively the board edges.
*/
const BOX2I GetBoardEdgesBoundingBox() const
{
return ComputeBoundingBox( true );
}
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
/**
* May be re-implemented for each derived class in order to handle
* all the types given by its member data. Implementations should call
* inspector->Inspect() on types in scanTypes[], and may use IterateForward()
* to do so on lists of such data.
* @param inspector An INSPECTOR instance to use in the inspection.
* @param testData Arbitrary data used by the inspector.
* @param scanTypes Which KICAD_T types are of interest and the order to process them in.
* @return SEARCH_QUIT if the Iterator is to stop the scan, else SCAN_CONTINUE, and
* determined by the inspector.
*/
INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
const std::vector<KICAD_T>& scanTypes ) override;
/**
* Search for a FOOTPRINT within this board with the given reference designator.
*
* Finds only the first one, if there is more than one such FOOTPRINT.
*
* @param aReference The reference designator of the FOOTPRINT to find.
* @return If found the FOOTPRINT having the given reference designator, else nullptr.
*/
FOOTPRINT* FindFootprintByReference( const wxString& aReference ) const;
/**
* Search for a FOOTPRINT within this board with the given path.
*
* @param aPath The path ([sheetUUID, .., symbolUUID]) to search for.
* @return If found, the FOOTPRINT having the given uuid, else NULL.
*/
FOOTPRINT* FindFootprintByPath( const KIID_PATH& aPath ) const;
/**
* Return the set of netname candidates for netclass assignment.
*/
std::set<wxString> GetNetClassAssignmentCandidates() const;
/**
* Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
*
* Must be called after a Design Rules edit, or after reading a netlist (or editing
* the list of nets) Also this function removes the non existing nets in netclasses
* and add net nets in default netclass (this happens after reading a netlist)
*/
void SynchronizeNetsAndNetClasses( bool aResetTrackAndViaSizes );
/**
* Copy the current project's text variables into the boards property cache.
*/
void SynchronizeProperties();
/**
* Return the Similarity. Because we compare board to board, we just return 1.0 here
*/