26#include <magic_enum.hpp>
28#include <unordered_set>
61#include <google/protobuf/any.pb.h>
62#include <api/board/board_types.pb.h>
71 m_boundingBoxCacheTimeStamp( 0 ),
72 m_textExcludedBBoxCacheTimeStamp( 0 ),
73 m_hullCacheTimeStamp( 0 ),
74 m_initial_comments( nullptr ),
75 m_componentClass( nullptr )
145 std::map<BOARD_ITEM*, BOARD_ITEM*> ptrMap;
156 ptrMap[field] = newField;
157 Add( newField, ADD_MODE::APPEND );
168 PAD* newPad =
static_cast<PAD*
>(
pad->Clone() );
169 ptrMap[
pad ] = newPad;
170 Add( newPad, ADD_MODE::APPEND );
176 ZONE* newZone =
static_cast<ZONE*
>( zone->Clone() );
177 ptrMap[ zone ] = newZone;
178 Add( newZone, ADD_MODE::APPEND );
191 ptrMap[ item ] = newItem;
192 Add( newItem, ADD_MODE::APPEND );
199 ptrMap[
group ] = newGroup;
200 Add( newGroup, ADD_MODE::APPEND );
212 if( ptrMap.count( member ) )
213 newGroup->
AddItem( ptrMap[ member ] );
236 *
this = std::move( aFootprint );
246 item->SetParentGroup(
nullptr );
278 board->IncrementTimeStamp();
285 types::FootprintInstance footprint;
288 footprint.mutable_position()->set_x_nm(
GetPosition().x );
289 footprint.mutable_position()->set_y_nm(
GetPosition().y );
291 footprint.set_layer( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>(
GetLayer() ) );
292 footprint.set_locked(
IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
293 : kiapi::common::types::LockedState::LS_UNLOCKED );
295 google::protobuf::Any buf;
297 buf.UnpackTo( footprint.mutable_reference_field() );
299 buf.UnpackTo( footprint.mutable_value_field() );
301 buf.UnpackTo( footprint.mutable_datasheet_field() );
303 buf.UnpackTo( footprint.mutable_description_field() );
305 types::FootprintAttributes* attrs = footprint.mutable_attributes();
311 attrs->set_do_not_populate(
IsDNP() );
314 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_THROUGH_HOLE );
316 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_SMD );
318 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_UNSPECIFIED );
320 types::Footprint* def = footprint.mutable_definition();
325 def->mutable_attributes()->set_keywords(
GetKeywords().ToStdString() );
329 types::FootprintDesignRuleOverrides* overrides = def->mutable_overrides();
343 overrides->set_zone_connection(
348 types::NetTieDefinition* netTie = def->add_net_ties();
349 wxStringTokenizer tokenizer(
group,
" " );
351 while( tokenizer.HasMoreTokens() )
352 netTie->add_pad_number( tokenizer.GetNextToken().ToStdString() );
356 def->add_private_layers( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>( layer ) );
360 if( !item || item->IsMandatory() )
363 google::protobuf::Any* itemMsg = def->add_items();
364 item->Serialize( *itemMsg );
367 for(
const PAD* item :
Pads() )
369 google::protobuf::Any* itemMsg = def->add_items();
370 item->Serialize( *itemMsg );
375 google::protobuf::Any* itemMsg = def->add_items();
376 item->Serialize( *itemMsg );
381 google::protobuf::Any* itemMsg = def->add_items();
382 item->Serialize( *itemMsg );
387 google::protobuf::Any* itemMsg = def->add_items();
388 types::Footprint3DModel modelMsg;
389 modelMsg.set_filename( model.m_Filename.ToUTF8() );
393 modelMsg.set_visible( model.m_Show );
394 modelMsg.set_opacity( model.m_Opacity );
395 itemMsg->PackFrom( modelMsg );
398 aContainer.PackFrom( footprint );
405 types::FootprintInstance footprint;
407 if( !aContainer.UnpackTo( &footprint ) )
413 SetLayer( FromProtoEnum<PCB_LAYER_ID, types::BoardLayer>( footprint.layer() ) );
414 SetLocked( footprint.locked() == kiapi::common::types::LockedState::LS_LOCKED );
416 google::protobuf::Any buf;
417 types::Field mandatoryField;
419 if( footprint.has_reference_field() )
421 mandatoryField = footprint.reference_field();
423 buf.PackFrom( mandatoryField );
427 if( footprint.has_value_field() )
429 mandatoryField = footprint.value_field();
430 mandatoryField.mutable_id()->set_id(
VALUE_FIELD );
431 buf.PackFrom( mandatoryField );
435 if( footprint.has_datasheet_field() )
437 mandatoryField = footprint.datasheet_field();
439 buf.PackFrom( mandatoryField );
443 if( footprint.has_description_field() )
445 mandatoryField = footprint.description_field();
447 buf.PackFrom( mandatoryField );
453 switch( footprint.attributes().mounting_style() )
455 case types::FootprintMountingStyle::FMS_THROUGH_HOLE:
459 case types::FootprintMountingStyle::FMS_SMD:
467 SetBoardOnly( footprint.attributes().not_in_schematic() );
471 SetDNP( footprint.attributes().do_not_populate() );
477 SetKeywords( footprint.definition().attributes().keywords() );
479 const types::FootprintDesignRuleOverrides& overrides = footprint.overrides();
481 if( overrides.has_copper_clearance() )
486 if( overrides.has_solder_mask() && overrides.solder_mask().has_solder_mask_margin() )
491 if( overrides.has_solder_paste() )
493 const types::SolderPasteOverrides& pasteSettings = overrides.solder_paste();
495 if( pasteSettings.has_solder_paste_margin() )
500 if( pasteSettings.has_solder_paste_margin_ratio() )
508 for(
const types::NetTieDefinition& netTieMsg : footprint.definition().net_ties() )
512 for(
const std::string&
pad : netTieMsg.pad_number() )
513 group.Append( wxString::Format( wxT(
"%s " ),
pad ) );
521 for(
int layerMsg : footprint.definition().private_layers() )
523 auto layer =
static_cast<types::BoardLayer
>( layerMsg );
524 privateLayers.
set( FromProtoEnum<PCB_LAYER_ID, types::BoardLayer>( layer ) );
532 if( field && !field->IsMandatory() )
542 for(
const google::protobuf::Any& itemMsg : footprint.definition().items() )
550 if( itemMsg.type_url() ==
"type.googleapis.com/kiapi.board.types.Footprint3DModel" )
552 types::Footprint3DModel modelMsg;
554 if( !itemMsg.UnpackTo( &modelMsg ) )
559 model.
m_Filename = wxString::FromUTF8( modelMsg.filename() );
560 model.
m_Show = modelMsg.visible();
566 Models().push_back( model );
570 wxLogTrace(
traceApi, wxString::Format( wxS(
"Attempting to unpack unknown type %s "
571 "from footprint message, skipping" ),
572 itemMsg.type_url() ) );
580 if( item && item->Deserialize( itemMsg ) )
581 Add( item.release(), ADD_MODE::APPEND );
591 wxASSERT_MSG( field, wxT(
"Requesting a null field (likely FOOTPRINT)" ) );
600 wxASSERT_MSG( field, wxT(
"Requesting a null field (likely FOOTPRINT)" ) );
610 if( field && field->GetId() == aFieldId )
621 if( field && field->GetCanonicalName() == aFieldName )
630 if( aFieldName.empty() )
635 if( field && field->GetName() == aFieldName )
647 if( field && ( aFieldName == field->GetName() || aFieldName == field->GetCanonicalName() ) )
648 return field->GetText();
651 return wxEmptyString;
657 std::vector<PCB_FIELD*> fields;
669 if( !field->IsVisible() || field->GetText().IsEmpty() )
673 fields.push_back( field );
697 for(
unsigned i = 0; i <
m_fields.size(); ++i )
702 if( aFieldName ==
m_fields[i]->GetName(
false ) )
725 switch( item->Type() )
735 if( aStyleShapes && !item->IsOnCopperLayer() )
750 std::vector< BOARD_ITEM* > item_list;
755 item_list.push_back( field );
759 item_list.push_back(
pad );
762 item_list.push_back( gr_item );
767 item_list.push_back(
group );
771 item_list.push_back( zone );
773 bool changed =
false;
779 const_cast<KIID&
>( item->m_Uuid ) =
KIID();
792 m_pos = aOther.m_pos;
821 for(
PCB_FIELD* field : aOther.m_fields )
835 for(
PAD*
pad : aOther.Pads() )
838 aOther.Pads().clear();
843 for(
ZONE* item : aOther.Zones() )
851 item->SetNetCode( -1 );
854 aOther.Zones().clear();
859 for(
BOARD_ITEM* item : aOther.GraphicalItems() )
862 aOther.GraphicalItems().clear();
872 aOther.Groups().clear();
883 aOther.m_fields.clear();
884 aOther.Pads().clear();
885 aOther.Zones().clear();
886 aOther.GraphicalItems().clear();
887 aOther.m_initial_comments =
nullptr;
922 std::map<BOARD_ITEM*, BOARD_ITEM*> ptrMap;
932 ptrMap[field] = newField;
947 ptrMap[
pad ] = newPad;
956 ZONE* newZone =
static_cast<ZONE*
>( zone->Clone() );
957 ptrMap[ zone ] = newZone;
973 ptrMap[ item ] = newItem;
986 newGroup->
AddItem( ptrMap[ member ] );
1014 aVars->push_back( wxT(
"REFERENCE" ) );
1015 aVars->push_back( wxT(
"VALUE" ) );
1016 aVars->push_back( wxT(
"LAYER" ) );
1017 aVars->push_back( wxT(
"FOOTPRINT_LIBRARY" ) );
1018 aVars->push_back( wxT(
"FOOTPRINT_NAME" ) );
1019 aVars->push_back( wxT(
"SHORT_NET_NAME(<pad_number>)" ) );
1020 aVars->push_back( wxT(
"NET_NAME(<pad_number>)" ) );
1021 aVars->push_back( wxT(
"NET_CLASS(<pad_number>)" ) );
1022 aVars->push_back( wxT(
"PIN_NAME(<pad_number>)" ) );
1031 if( token->IsSameAs( wxT(
"REFERENCE" ) ) )
1036 else if( token->IsSameAs( wxT(
"VALUE" ) ) )
1041 else if( token->IsSameAs( wxT(
"LAYER" ) ) )
1046 else if( token->IsSameAs( wxT(
"FOOTPRINT_LIBRARY" ) ) )
1051 else if( token->IsSameAs( wxT(
"FOOTPRINT_NAME" ) ) )
1056 else if( token->StartsWith( wxT(
"SHORT_NET_NAME(" ) )
1057 || token->StartsWith( wxT(
"NET_NAME(" ) )
1058 || token->StartsWith( wxT(
"NET_CLASS(" ) )
1059 || token->StartsWith( wxT(
"PIN_NAME(" ) ) )
1061 wxString padNumber = token->AfterFirst(
'(' );
1062 padNumber = padNumber.BeforeLast(
')' );
1066 if(
pad->GetNumber() == padNumber )
1068 if( token->StartsWith( wxT(
"SHORT_NET_NAME" ) ) )
1069 *token =
pad->GetShortNetname();
1070 else if( token->StartsWith( wxT(
"NET_NAME" ) ) )
1071 *token =
pad->GetNetname();
1072 else if( token->StartsWith( wxT(
"NET_CLASS" ) ) )
1073 *token =
pad->GetNetClassName();
1075 *token =
pad->GetPinFunction();
1105 switch( aBoardItem->
Type() )
1136 if( aMode == ADD_MODE::APPEND )
1143 if( aMode == ADD_MODE::APPEND )
1144 m_pads.push_back(
static_cast<PAD*
>( aBoardItem ) );
1146 m_pads.push_front(
static_cast<PAD*
>( aBoardItem ) );
1150 if( aMode == ADD_MODE::APPEND )
1151 m_zones.push_back(
static_cast<ZONE*
>( aBoardItem ) );
1157 if( aMode == ADD_MODE::APPEND )
1166 msg.Printf( wxT(
"FOOTPRINT::Add() needs work: BOARD_ITEM type (%d) not handled" ),
1167 aBoardItem->
Type() );
1181 switch( aBoardItem->
Type() )
1218 if( *it == aBoardItem )
1228 for(
auto it =
m_pads.begin(); it !=
m_pads.end(); ++it )
1230 if( *it ==
static_cast<PAD*
>( aBoardItem ) )
1242 if( *it ==
static_cast<ZONE*
>( aBoardItem ) )
1254 if( *it ==
static_cast<PCB_GROUP*
>( aBoardItem ) )
1266 msg.Printf( wxT(
"FOOTPRINT::Remove() needs work: BOARD_ITEM type (%d) not handled" ),
1267 aBoardItem->
Type() );
1298 switch(
pad->GetProperty() )
1300 case PAD_PROP::FIDUCIAL_GLBL:
1301 case PAD_PROP::FIDUCIAL_LOCAL:
1304 case PAD_PROP::HEATSINK:
1305 case PAD_PROP::CASTELLATED:
1306 case PAD_PROP::MECHANICAL:
1309 case PAD_PROP::NONE:
1311 case PAD_PROP::TESTPOINT:
1315 switch(
pad->GetAttribute() )
1317 case PAD_ATTRIB::PTH:
1321 case PAD_ATTRIB::SMD:
1322 if(
pad->IsOnCopperLayer() )
1350 return _(
"Through hole" );
1352 return _(
"Other" );
1367 if(
dummy.IsFlipped() )
1371 bbox.
Merge(
pad->GetBoundingBox() );
1374 dummy.SetParent(
nullptr );
1375 dummy.SetParentGroup(
nullptr );
1420 std::vector<PCB_TEXT*> texts;
1442 texts.push_back(
static_cast<PCB_TEXT*
>( item ) );
1460 bbox.
Merge( item->GetBoundingBox() );
1466 if( field && !field->IsReference() && !field->IsValue() )
1467 texts.push_back( field );
1471 bbox.
Merge(
pad->GetBoundingBox() );
1474 bbox.
Merge( zone->GetBoundingBox() );
1479 if( aIncludeText || noDrawItems )
1496 bool valueLayerIsVisible =
true;
1497 bool refLayerIsVisible =
true;
1515 if( (
Value().IsVisible() && valueLayerIsVisible ) || noDrawItems )
1520 if( (
Reference().IsVisible() && refLayerIsVisible ) || noDrawItems )
1528 if( aIncludeText || noDrawItems )
1546 std::vector<PCB_TEXT*> texts;
1558 if( ( aLayers & item->GetLayerSet() ).none() )
1566 bbox.
Merge( item->GetBoundingBox() );
1571 if( ( aLayers &
pad->GetLayerSet() ).none() )
1574 bbox.
Merge(
pad->GetBoundingBox() );
1579 if( ( aLayers & zone->GetLayerSet() ).none() )
1582 bbox.
Merge( zone->GetBoundingBox() );
1619 pad->Padstack().ForEachUniqueLayer(
1633 const SHAPE_POLY_SET& layerPoly = *zone->GetFilledPolysList( layer );
1660 std::vector<VECTOR2I> convex_hull;
1666 for(
const VECTOR2I& pt : convex_hull )
1690 aList.emplace_back(
_(
"Library" ),
GetFPID().GetLibNickname().wx_str() );
1692 aList.emplace_back(
_(
"Footprint Name" ),
GetFPID().GetLibItemName().wx_str() );
1694 aList.emplace_back(
_(
"Pads" ), wxString::Format( wxT(
"%zu" ), padCount ) );
1697 wxString::Format(
_(
"Keywords: %s" ),
GetKeywords() ) );
1706 case F_Cu: aList.emplace_back(
_(
"Board Side" ),
_(
"Front" ) );
break;
1707 case B_Cu: aList.emplace_back(
_(
"Board Side" ),
_(
"Back (Flipped)" ) );
break;
1711 auto addToken = []( wxString* aStr,
const wxString& aAttr )
1713 if( !aStr->IsEmpty() )
1714 *aStr += wxT(
", " );
1723 addToken( &status,
_(
"Locked" ) );
1726 addToken( &status,
_(
"autoplaced" ) );
1729 addToken( &attrs,
_(
"not in schematic" ) );
1732 addToken( &attrs,
_(
"exclude from pos files" ) );
1735 addToken( &attrs,
_(
"exclude from BOM" ) );
1738 addToken( &attrs,
_(
"DNP" ) );
1740 aList.emplace_back(
_(
"Status: " ) + status,
_(
"Attributes:" ) + wxS(
" " ) + attrs );
1742 aList.emplace_back(
_(
"Rotation" ), wxString::Format( wxT(
"%.4g" ),
1751 msg2.Printf(
_(
"3D-Shape: %s" ),
m_3D_Drawings.empty() ?
_(
"<none>" )
1753 aList.emplace_back( msg, msg2 );
1757 aList.emplace_back( msg, msg2 );
1765 if( board->IsFootprintHolder() )
1797 if(
pad->IsOnLayer( aLayer ) )
1803 if( zone->IsOnLayer( aLayer ) )
1809 if( field && field->IsOnLayer( aLayer ) )
1815 if( item->IsOnLayer( aLayer ) )
1827 if(
pad->IsOnLayer( aLayer ) &&
pad->HitTest( aPosition, aAccuracy ) )
1833 if( zone->IsOnLayer( aLayer ) && zone->HitTest( aPosition, aAccuracy ) )
1839 if( item->Type() !=
PCB_TEXT_T && item->IsOnLayer( aLayer )
1840 && item->HitTest( aPosition, aAccuracy ) )
1852 std::vector<BOARD_ITEM*> items;
1856 if(
pad->IsOnLayer( aLayer ) )
1857 items.push_back(
pad );
1862 if( zone->IsOnLayer( aLayer ) )
1863 items.push_back( zone );
1868 if( item->Type() !=
PCB_TEXT_T && item->IsOnLayer( aLayer ) )
1869 items.push_back( item );
1878 if( !aContained && item->HitTest( aRect, aContained, aAccuracy ) )
1880 else if( aContained && !item->HitTest( aRect, aContained, aAccuracy ) )
1887 return !items.empty() && aContained;
1906 BOX2I arect = aRect;
1926 if(
pad->HitTest( arect,
false, 0 ) )
1932 if( zone->HitTest( arect,
false, 0 ) )
1943 if( item->Type() !=
PCB_TEXT_T && item->HitTest( arect,
false, 0 ) )
1957 bool can_select = aSearchAfterMe ? false :
true;
1961 if( !can_select &&
pad == aSearchAfterMe )
1967 if( can_select &&
pad->GetNumber() == aPadNumber )
1980 if( !(
pad->GetLayerSet() & aLayerMask ).any() )
1983 if(
pad->HitTest( aPosition ) )
1993 std::vector<const PAD*> retv;
1997 if( ( aIgnore && aIgnore ==
pad ) || (
pad->GetNumber() != aPadNumber ) )
2000 retv.push_back(
pad );
2016 if(
pad->GetAttribute() == PAD_ATTRIB::NPTH )
2028 std::set<wxString> usedNumbers;
2040 if(
pad->GetNumber().IsEmpty() )
2046 if(
pad->GetAttribute() == PAD_ATTRIB::NPTH )
2050 usedNumbers.insert(
pad->GetNumber() );
2065 if(
nullptr == a3DModel )
2075 const std::vector<KICAD_T>& aScanTypes )
2077#if 0 && defined(DEBUG)
2078 std::cout <<
GetClass().mb_str() <<
' ';
2081 bool drawingsScanned =
false;
2083 for(
KICAD_T scanType : aScanTypes )
2088 if( inspector(
this, testData ) == INSPECT_RESULT::QUIT )
2089 return INSPECT_RESULT::QUIT;
2094 if( IterateForward<PAD*>(
m_pads, inspector, testData, { scanType } )
2095 == INSPECT_RESULT::QUIT )
2097 return INSPECT_RESULT::QUIT;
2103 if( IterateForward<ZONE*>(
m_zones, inspector, testData, { scanType } )
2104 == INSPECT_RESULT::QUIT )
2106 return INSPECT_RESULT::QUIT;
2112 if( IterateForward<PCB_FIELD*>(
m_fields, inspector, testData, { scanType } )
2113 == INSPECT_RESULT::QUIT )
2115 return INSPECT_RESULT::QUIT;
2130 if( !drawingsScanned )
2132 if( IterateForward<BOARD_ITEM*>(
m_drawings, inspector, testData, aScanTypes )
2133 == INSPECT_RESULT::QUIT )
2135 return INSPECT_RESULT::QUIT;
2138 drawingsScanned =
true;
2144 if( IterateForward<PCB_GROUP*>(
m_groups, inspector, testData, { scanType } )
2145 == INSPECT_RESULT::QUIT )
2147 return INSPECT_RESULT::QUIT;
2157 return INSPECT_RESULT::CONTINUE;
2165 if( reference.IsEmpty() )
2166 reference =
_(
"<no reference designator>" );
2168 return wxString::Format(
_(
"Footprint %s" ), reference );
2174 return BITMAPS::module;
2204 aFunction( drawing );
2206 catch( std::bad_function_call& )
2208 wxFAIL_MSG( wxT(
"Error running FOOTPRINT::RunOnChildren" ) );
2237 group->RunOnDescendants( aFunction, aDepth + 1 );
2242 aFunction( drawing );
2243 drawing->RunOnDescendants( aFunction, aDepth + 1 );
2246 catch( std::bad_function_call& )
2248 wxFAIL_MSG( wxT(
"Error running FOOTPRINT::RunOnDescendants" ) );
2255 std::vector<int> layers;
2257 layers.reserve( 6 );
2263 wxASSERT_MSG(
false, wxT(
"Illegal layer" ) );
2284 bool f_silk =
false, b_silk =
false, non_silk =
false;
2288 if( item->GetLayer() ==
F_SilkS )
2290 else if( item->GetLayer() ==
B_SilkS )
2296 if( ( f_silk || b_silk ) && !non_silk &&
m_pads.empty() )
2341 constexpr double MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY = 1.5;
2344 return MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY;
2357 int biggest_clearance = board->GetMaxClearanceValue();
2358 area.
Inflate( biggest_clearance );
2369 if( aName.find_first_of( invalids ) != std::string::npos )
2383 static const wxChar invalidChars[] = wxT(
"%$<>\t\n\r\"\\/:");
2384 static const wxChar invalidCharsReadable[] = wxT(
"% $ < > 'tab' 'return' 'line feed' \\ \" / :");
2387 return invalidCharsReadable;
2389 return invalidChars;
2395 if( aMoveVector.
x == 0 && aMoveVector.
y == 0 )
2409 EDA_ANGLE newOrientation = orientation + aAngle;
2418 field->KeepUpright();
2424 static_cast<PCB_TEXT*
>( item )->KeepUpright();
2431 wxASSERT( aLayer ==
F_Cu || aLayer ==
B_Cu );
2468 field->Flip(
m_pos, FLIP_DIRECTION::TOP_BOTTOM );
2473 pad->Flip(
m_pos, FLIP_DIRECTION::TOP_BOTTOM );
2480 zone->Flip(
m_pos, FLIP_DIRECTION::TOP_BOTTOM );
2484 item->Flip(
m_pos, FLIP_DIRECTION::TOP_BOTTOM );
2487 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
2509 field->EDA_TEXT::Offset(
delta );
2516 zone->Move(
delta );
2519 item->Move(
delta );
2553 field->Move( moveVector );
2558 pad->Move( moveVector );
2562 item->Move( moveVector );
2566 zone->Move( moveVector );
2636 switch( aItem->
Type() )
2640 PAD* new_pad =
new PAD( *
static_cast<const PAD*
>( aItem ) );
2643 if( aAddToFootprint )
2644 m_pads.push_back( new_pad );
2652 ZONE* new_zone =
new ZONE( *
static_cast<const ZONE*
>( aItem ) );
2655 if( aAddToFootprint )
2656 m_zones.push_back( new_zone );
2658 new_item = new_zone;
2680 if( aAddToFootprint )
2683 new_item = new_text;
2692 if( aAddToFootprint )
2695 new_item = new_shape;
2704 if( aAddToFootprint )
2707 new_item = new_textbox;
2719 if( aAddToFootprint )
2722 new_item = dimension;
2730 if( aAddToFootprint )
2732 group->RunOnDescendants(
2751 wxFAIL_MSG( wxT(
"Duplication not supported for items of class " ) + aItem->
GetClass() );
2761 std::set<wxString> usedNumbers;
2765 usedNumbers.insert(
pad->GetNumber() );
2772 while( usedNumbers.count( wxString::Format( wxT(
"%s%d" ), prefix, num ) ) )
2775 return wxString::Format( wxT(
"%s%d" ), prefix, num );
2826 for(
int jj = 0; jj < aPolySet.
HoleCount( ii ); jj++ )
2830 return aPolySet.
Area();
2845 return markerShape.
Area();
2849 double combinedArea = 0.0;
2854 return combinedArea;
2884 case SHAPE_T::SEGMENT:
2886 case SHAPE_T::BEZIER:
2889 case SHAPE_T::RECTANGLE:
2890 case SHAPE_T::CIRCLE:
2905 double width =
static_cast<const PCB_TRACK*
>( aItem )->GetWidth();
2906 return width * width;
2910 static_cast<const PAD*
>( aItem )->Padstack().ForEachUniqueLayer(
2942 for(
int i = 0; i < aCollector.
GetCount(); ++i )
2946 switch( item->
Type() )
2977 double footprintRegionArea =
polygonArea( footprintRegion );
2978 double uncoveredRegionArea = footprintRegionArea -
polygonArea( coveredRegion );
2979 double coveredArea = footprintRegionArea - uncoveredRegionArea;
2980 double ratio = ( coveredArea / footprintRegionArea );
2987 return std::min( ratio, 1.0 );
2993 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
3014 shape->AddShape(
pad->GetEffectiveShape( aLayer, aFlash )->Clone() );
3019 shape->AddShape( item->GetEffectiveShape( aLayer, aFlash )->Clone() );
3059 std::vector<PCB_SHAPE*> list_front;
3060 std::vector<PCB_SHAPE*> list_back;
3061 std::map<int, int> front_width_histogram;
3062 std::map<int, int> back_width_histogram;
3069 list_back.push_back( shape );
3076 list_front.push_back( shape );
3081 if( !list_front.size() && !list_back.size() )
3088 true, aErrorHandler ) )
3098 auto max = std::max_element( front_width_histogram.begin(), front_width_histogram.end(),
3099 [](
const std::pair<int, int>& a,
const std::pair<int, int>& b )
3101 return a.second < b.second;
3104 if( max != front_width_histogram.end() )
3127 auto max = std::max_element( back_width_histogram.begin(), back_width_histogram.end(),
3128 [](
const std::pair<int, int>& a,
const std::pair<int, int>& b )
3130 return a.second < b.second;
3133 if( max != back_width_histogram.end() )
3156 std::map<PCB_LAYER_ID, std::vector<PCB_SHAPE*>> layer_shapes;
3161 if( item->Type() != PCB_SHAPE_T )
3164 for( PCB_LAYER_ID layer : item->GetLayerSet() )
3165 layer_shapes[layer].push_back( static_cast<PCB_SHAPE*>( item ) );
3168 for(
size_t ii = 0; ii <
m_pads.size(); ++ii )
3171 bool has_nettie =
false;
3173 auto it = map.find(
pad->GetNumber() );
3175 if( it == map.end() || it->second < 0 )
3178 for(
size_t jj = ii + 1; jj <
m_pads.size(); ++jj )
3182 auto it2 = map.find( other->
GetNumber() );
3184 if( it2 == map.end() || it2->second < 0 )
3187 if( it2->second == it->second )
3200 for(
auto& [ layer, shapes ] : layer_shapes )
3202 auto pad_shape =
pad->GetEffectiveShape( layer );
3204 for(
auto other_shape : shapes )
3206 auto shape = other_shape->GetEffectiveShape( layer );
3208 if( pad_shape->Collide( shape.get() ) )
3211 m_netTieCache[other_shape].insert( nettie.begin(), nettie.end() );
3221 std::map<wxString, int> padNumberToGroupIdxMap;
3224 padNumberToGroupIdxMap[
pad->GetNumber() ] = -1;
3227 [&]( wxString aPad,
int aGroup )
3229 aPad.Trim(
true ).Trim(
false );
3231 if( !aPad.IsEmpty() )
3232 padNumberToGroupIdxMap[ aPad ] = aGroup;
3241 for( wxUniCharRef ch :
group )
3250 switch(
static_cast<unsigned char>( ch ) )
3257 processPad(
pad, ii );
3267 processPad(
pad, ii );
3270 return padNumberToGroupIdxMap;
3280 int groupIdx = padToNetTieGroupMap[ aPad->
GetNumber() ];
3281 std::vector<PAD*> otherPads;
3287 if( padToNetTieGroupMap[
pad->GetNumber() ] == groupIdx )
3288 otherPads.push_back(
pad );
3301 if( setAttr && likelyAttr && setAttr != likelyAttr )
3305 switch( likelyAttr )
3308 msg.Printf(
_(
"(expected 'Through hole'; actual '%s')" ),
GetTypeName() );
3311 msg.Printf(
_(
"(expected 'SMD'; actual '%s')" ),
GetTypeName() );
3316 (aErrorHandler)( msg );
3322 const std::function<
void(
const PAD*,
int,
3323 const wxString& )>& aErrorHandler )
3325 if( aErrorHandler ==
nullptr )
3330 pad->CheckPad( aUnitsProvider,
false,
3331 [&](
int errorCode,
const wxString& msg )
3333 aErrorHandler(
pad, errorCode, msg );
3341 const VECTOR2I& )>& aErrorHandler )
3343 std::unordered_map<PTR_PTR_CACHE_KEY, int> checkedPairs;
3358 if(
static_cast<void*
>( a ) >
static_cast<void*
>( b ) )
3361 if( checkedPairs.find( { a, b } ) == checkedPairs.end() )
3363 checkedPairs[ { a, b } ] = 1;
3365 if(
pad->HasDrilledHole() && other->HasDrilledHole() )
3369 if(
pad->GetPosition() == other->GetPosition() )
3375 std::shared_ptr<SHAPE_SEGMENT> holeA =
pad->GetEffectiveHoleShape();
3376 std::shared_ptr<SHAPE_SEGMENT> holeB = other->GetEffectiveHoleShape();
3378 if( holeA->Collide( holeB->GetSeg(), 0 ) )
3389 if(
pad->GetBoundingBox().Intersects( other->GetBoundingBox() ) )
3393 for(
PCB_LAYER_ID l :
pad->Padstack().RelevantShapeLayers( other->Padstack() ) )
3395 SHAPE* padShape =
pad->GetEffectiveShape( l ).get();
3396 SHAPE* otherShape = other->GetEffectiveShape( l ).get();
3398 if( padShape->
Collide( otherShape, 0,
nullptr, &pos ) )
3411 const VECTOR2I& )>& aErrorHandler )
3420 std::vector<BOARD_ITEM*> copperItems;
3424 if( item->IsOnCopperLayer() )
3425 copperItems.push_back( item );
3427 item->RunOnDescendants(
3431 copperItems.push_back( descendent );
3437 if( !zone->GetIsRuleArea() && zone->IsOnCopperLayer() )
3438 copperItems.push_back( zone );
3443 if( field && field->IsOnCopperLayer() )
3444 copperItems.push_back( field );
3454 std::map<int, std::vector<const PAD*>> outlineIdxToPadsMap;
3458 if( item->IsOnLayer( layer ) )
3460 item->TransformShapeToPolygon( copperOutlines, layer, 0,
ARC_HIGH_DEF,
3471 for(
int ii = 0; ii < copperOutlines.
OutlineCount(); ++ii )
3473 if(
pad->GetEffectiveShape( layer )->Collide( &copperOutlines.
Outline( ii ), 0 ) )
3474 outlineIdxToPadsMap[ ii ].emplace_back(
pad );
3481 for(
const auto& [ outlineIdx, pads ] : outlineIdxToPadsMap )
3483 if( pads.size() > 1 )
3485 const PAD* firstPad = pads[0];
3486 int firstGroupIdx = padNumberToGroupIdxMap[ firstPad->
GetNumber() ];
3488 for(
size_t ii = 1; ii < pads.size(); ++ii )
3490 const PAD* thisPad = pads[ii];
3491 int thisGroupIdx = padNumberToGroupIdxMap[ thisPad->
GetNumber() ];
3493 if( thisGroupIdx < 0 || thisGroupIdx != firstGroupIdx )
3502 if( item->HitTest( pos, 1 ) )
3504 shortingItem = item;
3510 aErrorHandler( shortingItem, firstPad, thisPad, pos );
3512 aErrorHandler( firstPad, thisPad,
nullptr, pos );
3523 std::set<wxString> padNumbers;
3532 msg.Printf(
_(
"(net-tie pad group contains unknown pad number %s)" ), padNumber );
3533 aErrorHandler( msg );
3535 else if( !padNumbers.insert(
pad->GetNumber() ).second )
3537 msg.Printf(
_(
"(pad %s appears in more than one net-tie pad group)" ), padNumber );
3538 aErrorHandler( msg );
3550 std::swap( *
this, *
image );
3558 image->RunOnChildren(
3570 if(
pad->GetAttribute() != PAD_ATTRIB::SMD )
3585 return *
this == other;
3594 for(
size_t ii = 0; ii <
m_pads.size(); ++ii )
3603 for(
size_t ii = 0; ii <
m_drawings.size(); ++ii )
3612 for(
size_t ii = 0; ii <
m_zones.size(); ++ii )
3621 for(
size_t ii = 0; ii <
m_fields.size(); ++ii )
3641 double similarity = 1.0;
3650 similarity *=
pad->Similarity( *otherPad );
3659 if( itemA->
Type() != itemB->
Type() )
3660 return itemA->
Type() < itemB->
Type();
3675 if( dwgA->
GetShape() != SHAPE_T::POLY )
3688 if( dwgA->
GetShape() == SHAPE_T::ARC )
3695 else if( dwgA->
GetShape() == SHAPE_T::BEZIER )
3707 else if( dwgA->
GetShape() == SHAPE_T::POLY )
3730 return itemA < itemB;
3744 std::optional<bool> padCopperMatches;
3747 const PAD* checkPad = aFirst;
3760 padCopperMatches = aFirst->
GetSize( aLayer ).
x < aSecond->
GetSize( aLayer ).
x;
3762 padCopperMatches = aFirst->
GetSize( aLayer ).
y < aSecond->
GetSize( aLayer ).
y;
3764 padCopperMatches = aFirst->
GetShape( aLayer ) < aSecond->
GetShape( aLayer );
3767 if( padCopperMatches.has_value() )
3768 return *padCopperMatches;
3776 return aFirst < aSecond;
3781bool FOOTPRINT::cmp_padstack::operator()(
const PAD* aFirst,
const PAD* aSecond )
const
3821 if( firstShape->VertexCount() != secondShape->VertexCount() )
3822 return firstShape->VertexCount() < secondShape->VertexCount();
3824 for(
int ii = 0; ii < firstShape->VertexCount(); ++ii )
3826 if( firstShape->CVertex( ii ).x != secondShape->CVertex( ii ).x )
3827 return firstShape->CVertex( ii ).x < secondShape->CVertex( ii ).x;
3828 if( firstShape->CVertex( ii ).y != secondShape->CVertex( ii ).y )
3829 return firstShape->CVertex( ii ).y < secondShape->CVertex( ii ).y;
3848 for(
int ii = 0; ii < aFirst->
Outline()->TotalVertices(); ++ii )
3859 return aFirst < aSecond;
3864 int aClearance,
int aMaxError,
ERROR_LOC aErrorLoc,
3865 bool aSkipNPTHPadsWihNoCopper,
bool aSkipPlatedPads,
3866 bool aSkipNonPlatedPads )
const
3876 if( aSkipPlatedPads &&
pad->FlashLayer(
F_Mask ) )
3879 if( aSkipNonPlatedPads && !
pad->FlashLayer(
F_Mask ) )
3885 if( aSkipPlatedPads &&
pad->FlashLayer(
B_Mask ) )
3888 if( aSkipNonPlatedPads && !
pad->FlashLayer(
B_Mask ) )
3895 clearance.x +=
pad->GetSolderMaskExpansion( padLayer );
3896 clearance.y +=
pad->GetSolderMaskExpansion( padLayer );
3915 &&
pad->GetShape( padLayer ) != PAD_SHAPE::CUSTOM )
3919 if( dummySize.
x <= 0 || dummySize.
y <= 0 )
3923 dummy.SetSize( padLayer, dummySize );
3924 dummy.TransformShapeToPolygon( aBuffer, padLayer, 0, aMaxError, aErrorLoc );
3928 pad->TransformShapeToPolygon( aBuffer, padLayer,
clearance.x, aMaxError,
3935 if( !
pad->FlashLayer( aLayer ) )
3940 pad->Padstack().ForEachUniqueLayer(
3943 processPad(
pad, l );
3948 processPad(
pad, aLayer );
3955 int aClearance,
int aError,
ERROR_LOC aErrorLoc,
3956 bool aIncludeText,
bool aIncludeShapes,
3957 bool aIncludePrivateItems )
const
3959 std::vector<const PCB_TEXT*> texts;
3966 if( item->Type() ==
PCB_TEXT_T && aIncludeText )
3971 texts.push_back(
text );
3982 textbox->PCB_SHAPE::TransformShapeToPolygon( aBuffer, aLayer, 0, aError, aErrorLoc );
3988 if( item->Type() ==
PCB_SHAPE_T && aIncludeShapes )
4001 if( field && field->GetLayer() == aLayer && field->IsVisible() )
4002 texts.push_back( field );
4007 text->TransformTextToPolySet( aBuffer, aClearance, aError, aErrorLoc );
4014 using EMBEDDING_PERMISSION = OUTLINE_FONT::EMBEDDING_PERMISSION;
4016 std::set<OUTLINE_FONT*>
fonts;
4022 if(
auto* font =
text->GetFont(); font && !font->IsStroke() )
4024 auto* outline =
static_cast<OUTLINE_FONT*
>( font );
4025 auto permission = outline->GetEmbeddingPermission();
4027 if( permission == EMBEDDING_PERMISSION::EDITABLE
4028 || permission == EMBEDDING_PERMISSION::INSTALLABLE )
4030 fonts.insert( outline );
4044 for(
auto* font :
fonts )
4059 return wxEmptyString;
4064 BOARD* aBoard,
const std::unordered_set<wxString>& aComponentClassNames )
4078 if( zcMap.
Choices().GetCount() == 0 )
4080 zcMap.
Undefined( ZONE_CONNECTION::INHERITED );
4081 zcMap.
Map( ZONE_CONNECTION::INHERITED,
_HKI(
"Inherited" ) )
4082 .
Map( ZONE_CONNECTION::NONE,
_HKI(
"None" ) )
4083 .
Map( ZONE_CONNECTION::THERMAL,
_HKI(
"Thermal reliefs" ) )
4084 .
Map( ZONE_CONNECTION::FULL,
_HKI(
"Solid" ) )
4085 .
Map( ZONE_CONNECTION::THT_THERMAL,
_HKI(
"Thermal reliefs for PTH" ) );
4090 if( layerEnum.
Choices().GetCount() == 0 )
4098 wxPGChoices fpLayers;
4111 layer->SetChoices( fpLayers );
4116 PROPERTY_DISPLAY::PT_DEGREE ) );
4118 const wxString groupFields =
_HKI(
"Fields" );
4143 const wxString groupAttributes =
_HKI(
"Attributes" );
4157 const wxString groupOverrides =
_HKI(
"Overrides" );
4160 _HKI(
"Exempt From Courtyard Requirement" ),
4164 _HKI(
"Clearance Override" ),
4166 PROPERTY_DISPLAY::PT_SIZE ),
4169 _HKI(
"Solderpaste Margin Override" ),
4171 PROPERTY_DISPLAY::PT_SIZE ),
4174 _HKI(
"Solderpaste Margin Ratio Override" ),
4177 PROPERTY_DISPLAY::PT_RATIO ),
4180 _HKI(
"Zone Connection Style" ),
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr int ARC_HIGH_DEF
constexpr EDA_IU_SCALE pcbIUScale
constexpr int ARC_LOW_DEF
BITMAPS
A list of all bitmap identifiers.
#define DEFAULT_COURTYARD_WIDTH
BASE_SET & set(size_t pos)
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
PCB_GROUP * GetParentGroup() const
virtual void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
VECTOR2I GetFPRelativePosition() const
BOARD_ITEM_CONTAINER * GetParent() const
virtual bool IsOnCopperLayer() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr size_type GetWidth() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr const Vec GetCenter() const
constexpr size_type GetHeight() const
constexpr bool Contains(const Vec &aPoint) const
constexpr void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
constexpr coord_type GetTop() const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
constexpr coord_type GetBottom() const
virtual int Accuracy() const =0
int GetCount() const
Return the number of objects in the list.
COMPONENT_CLASS * GetEffectiveComponentClass(const std::unordered_set< wxString > &classNames)
Gets an effective component class for the given constituent class names.
const wxString & GetFullName() const
Fetches the full name of this component class.
wxString GetName() const
Fetches the display name of this component class.
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual void ClearEditFlags()
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual void SetParent(EDA_ITEM *aParent)
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
virtual wxString GetClass() const =0
Return the class name.
EDA_ITEM_FLAGS GetFlags() const
const VECTOR2I & GetBezierC2() const
SHAPE_POLY_SET & GetPolyShape()
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
const VECTOR2I & GetBezierC1() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
EMBEDDED_FILES & operator=(EMBEDDED_FILES &&other) noexcept
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, EMBEDDED_FILE * > & EmbeddedFileMap() const
bool m_embedFonts
If set, fonts will be embedded in the element on save.
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
ENUM_MAP & Undefined(T aValue)
VECTOR3D m_Offset
3D model offset (mm)
VECTOR3D m_Rotation
3D model rotation (degrees)
VECTOR3D m_Scale
3D model scaling factor (dimensionless)
wxString m_Filename
The 3D shape filename in 3D library.
bool m_Show
Include model in rendering.
Used when the right click button is pressed, or when the select tool is in effect.
const COLLECTORS_GUIDE * GetGuide() const
Class OUTLINE_FONT implements outline font drawing.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
std::string AsStdString() const
wxString GetUniStringLibId() const
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const wxString GetUniStringLibNickname() const
LSET is a set of PCB_LAYER_IDs.
static LSET AllLayersMask()
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
static LSET SideSpecificMask()
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
void ForEachUniqueLayer(const std::function< void(PCB_LAYER_ID)> &aMethod) const
Runs the given callable for each active unique copper layer in this padstack, meaning F_Cu for MODE::...
@ NORMAL
Shape is the same on all layers.
@ CUSTOM
Shapes can be defined on arbitrary layers.
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
int GetDrillSizeY() const
PAD_ATTRIB GetAttribute() const
const wxString & GetNumber() const
VECTOR2I GetPosition() const override
int GetDrillSizeX() const
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
int GetSolderMaskExpansion(PCB_LAYER_ID aLayer) const
const PADSTACK & Padstack() const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
PAD_DRILL_SHAPE GetDrillShape() const
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(PCB_LAYER_ID aLayer, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
std::optional< int > GetLocalSolderMaskMargin() const
VECTOR2I GetSolderPasteMargin(PCB_LAYER_ID aLayer) const
Usually < 0 (mask shape smaller than pad)because the margin can be dependent on the pad size,...
const VECTOR2I & GetSize(PCB_LAYER_ID aLayer) const
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
A set of BOARD_ITEMs (i.e., without duplicates).
std::unordered_set< BOARD_ITEM * > & GetItems()
virtual bool RemoveItem(BOARD_ITEM *aItem)
Remove item from group.
virtual bool AddItem(BOARD_ITEM *aItem)
Add item to group.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
int GetWidth() const override
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
STROKE_PARAMS GetStroke() const override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
bool IsBorderEnabled() const
Disables the border, this is done by changing the stroke internally.
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
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.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
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.
double Area(bool aAbsolute=true) const
Return the area of this chain.
const VECTOR2I NearestPoint(const VECTOR2I &aP, bool aAllowInternalShapePoints=true) const
Find a point on the line chain that is closest to point aP.
void SetWidth(int aWidth)
Set the width of all segments in the chain.
Represent a set of closed polygons.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
virtual void CacheTriangulation(bool aPartition=true, bool aSimplify=false)
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
double Area()
Return the area of this poly set.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
int TotalVertices() const
Return total number of vertices stored in the set.
int FullPointCount() const
Return the number of points in the shape poly set.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the reference to aHole-th hole in the aIndex-th outline.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
void Mirror(const VECTOR2I &aRef, FLIP_DIRECTION aFlipDirection)
Mirror the line points about y or x (or both)
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
int OutlineCount() const
Return the number of outlines in the set.
void Move(const VECTOR2I &aVector) override
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
An abstract shape on 2D plane.
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Handle a list of polygons defining a copper zone.
SHAPE_POLY_SET * Outline()
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
unsigned GetAssignedPriority() const
This file is part of the common library.
bool ConvertOutlineToPolygon(std::vector< PCB_SHAPE * > &aShapeList, SHAPE_POLY_SET &aPolygons, int aErrorMax, int aChainingEpsilon, bool aAllowDisjoint, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons)
Build a polygon set with holes from a PCB_SHAPE list.
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const VECTOR2I &pt)> OUTLINE_ERROR_HANDLER
void BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
@ DRCE_DRILLED_HOLES_TOO_CLOSE
@ DRCE_DRILLED_HOLES_COLOCATED
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_180
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
#define COURTYARD_CONFLICT
temporary set when moving footprints having courtyard overlapping
#define MALFORMED_F_COURTYARD
#define MALFORMED_B_COURTYARD
#define STRUCT_DELETED
flag indication structures to be erased
#define MALFORMED_COURTYARDS
@ FRAME_FOOTPRINT_CHOOSER
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
Some functions to handle hotkeys in KiCad.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
@ LAYER_CONFLICTS_SHADOW
Shadow layer for items flagged conflicting.
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
KICOMMON_API VECTOR3D UnpackVector3D(const types::Vector3D &aInput)
KICOMMON_API LIB_ID LibIdFromProto(const types::LibraryIdentifier &aId)
KICOMMON_API types::LibraryIdentifier LibIdToProto(const LIB_ID &aId)
KICOMMON_API void PackVector3D(types::Vector3D &aOutput, const VECTOR3D &aInput)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Class to handle a set of BOARD_ITEMs.
#define NO_SETTER(owner, type)
Collection of utility functions for component reference designators (refdes)
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
int GetTrailingInt(const wxString &aStr)
Gets the trailing int, if any, from a string.
wxString UnescapeString(const wxString &aSource)
constexpr double IUTomm(int iu) const
constexpr int mmToIU(double mm) const
MANDATORY_FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELD_COUNT
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT, LIB_PART, and FOOTPRINT constru...
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ DESCRIPTION_FIELD
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
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.
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
VECTOR2< int32_t > VECTOR2I